github.com/enbility/spine-go@v0.7.0/model/networkmanagement_additions_test.go (about)

     1  package model
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/enbility/spine-go/util"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestNetworkManagementDeviceDescriptionListDataType(t *testing.T) {
    11  	sut := NetworkManagementDeviceDescriptionListDataType{
    12  		NetworkManagementDeviceDescriptionData: []NetworkManagementDeviceDescriptionDataType{
    13  			{
    14  				DeviceAddress: &DeviceAddressType{
    15  					Device: util.Ptr(AddressDeviceType("test 1")),
    16  				},
    17  				NetworkFeatureSet: util.Ptr(NetworkManagementFeatureSetTypeSimple),
    18  			},
    19  			{
    20  				DeviceAddress: &DeviceAddressType{
    21  					Device: util.Ptr(AddressDeviceType("test 2")),
    22  				},
    23  				NetworkFeatureSet: util.Ptr(NetworkManagementFeatureSetTypeRouter),
    24  			},
    25  		},
    26  	}
    27  
    28  	newData := NetworkManagementDeviceDescriptionListDataType{
    29  		NetworkManagementDeviceDescriptionData: []NetworkManagementDeviceDescriptionDataType{
    30  			{
    31  				DeviceAddress: &DeviceAddressType{
    32  					Device: util.Ptr(AddressDeviceType("test 2")),
    33  				},
    34  				NetworkFeatureSet: util.Ptr(NetworkManagementFeatureSetTypeGateway),
    35  			},
    36  		},
    37  	}
    38  
    39  	// Act
    40  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    41  	assert.True(t, success)
    42  
    43  	data := sut.NetworkManagementDeviceDescriptionData
    44  	// check the non changing items
    45  	assert.Equal(t, 2, len(data))
    46  	item1 := data[0]
    47  	assert.Equal(t, NetworkManagementFeatureSetTypeSimple, *item1.NetworkFeatureSet)
    48  	// check properties of updated item
    49  	item2 := data[1]
    50  	assert.Equal(t, NetworkManagementFeatureSetTypeGateway, *item2.NetworkFeatureSet)
    51  }
    52  
    53  func TestNetworkManagementEntityDescriptionListDataType(t *testing.T) {
    54  	sut := NetworkManagementEntityDescriptionListDataType{
    55  		NetworkManagementEntityDescriptionData: []NetworkManagementEntityDescriptionDataType{
    56  			{
    57  				EntityAddress: &EntityAddressType{
    58  					Device: util.Ptr(AddressDeviceType("test 1")),
    59  					Entity: []AddressEntityType{1},
    60  				},
    61  				EntityType: util.Ptr(EntityTypeTypeBattery),
    62  			},
    63  			{
    64  				EntityAddress: &EntityAddressType{
    65  					Device: util.Ptr(AddressDeviceType("test 1")),
    66  					Entity: []AddressEntityType{2},
    67  				},
    68  				EntityType: util.Ptr(EntityTypeTypeCEM),
    69  			},
    70  		},
    71  	}
    72  
    73  	newData := NetworkManagementEntityDescriptionListDataType{
    74  		NetworkManagementEntityDescriptionData: []NetworkManagementEntityDescriptionDataType{
    75  			{
    76  				EntityAddress: &EntityAddressType{
    77  					Device: util.Ptr(AddressDeviceType("test 1")),
    78  					Entity: []AddressEntityType{2},
    79  				},
    80  				EntityType: util.Ptr(EntityTypeTypeEVSE),
    81  			},
    82  		},
    83  	}
    84  
    85  	// Act
    86  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    87  	assert.True(t, success)
    88  
    89  	data := sut.NetworkManagementEntityDescriptionData
    90  	// check the non changing items
    91  	assert.Equal(t, 2, len(data))
    92  	item1 := data[0]
    93  	assert.Equal(t, EntityTypeTypeBattery, *item1.EntityType)
    94  	// check properties of updated item
    95  	item2 := data[1]
    96  	assert.Equal(t, EntityTypeTypeEVSE, *item2.EntityType)
    97  }
    98  
    99  func TestNetworkManagementFeatureDescriptionListDataType(t *testing.T) {
   100  	sut := NetworkManagementFeatureDescriptionListDataType{
   101  		NetworkManagementFeatureDescriptionData: []NetworkManagementFeatureDescriptionDataType{
   102  			{
   103  				FeatureAddress: &FeatureAddressType{
   104  					Device:  util.Ptr(AddressDeviceType("test 1")),
   105  					Entity:  []AddressEntityType{1},
   106  					Feature: util.Ptr(AddressFeatureType(1)),
   107  				},
   108  				FeatureType: util.Ptr(FeatureTypeTypeActuatorLevel),
   109  			},
   110  			{
   111  				FeatureAddress: &FeatureAddressType{
   112  					Device:  util.Ptr(AddressDeviceType("test 1")),
   113  					Entity:  []AddressEntityType{1},
   114  					Feature: util.Ptr(AddressFeatureType(2)),
   115  				},
   116  				FeatureType: util.Ptr(FeatureTypeTypeAlarm),
   117  			},
   118  		},
   119  	}
   120  
   121  	newData := NetworkManagementFeatureDescriptionListDataType{
   122  		NetworkManagementFeatureDescriptionData: []NetworkManagementFeatureDescriptionDataType{
   123  			{
   124  				FeatureAddress: &FeatureAddressType{
   125  					Device:  util.Ptr(AddressDeviceType("test 1")),
   126  					Entity:  []AddressEntityType{1},
   127  					Feature: util.Ptr(AddressFeatureType(2)),
   128  				},
   129  				FeatureType: util.Ptr(FeatureTypeTypeBill),
   130  			},
   131  		},
   132  	}
   133  
   134  	// Act
   135  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   136  	assert.True(t, success)
   137  
   138  	data := sut.NetworkManagementFeatureDescriptionData
   139  	// check the non changing items
   140  	assert.Equal(t, 2, len(data))
   141  	item1 := data[0]
   142  	assert.Equal(t, FeatureTypeTypeActuatorLevel, *item1.FeatureType)
   143  	// check properties of updated item
   144  	item2 := data[1]
   145  	assert.Equal(t, FeatureTypeTypeBill, *item2.FeatureType)
   146  }