|
| 1 | +package features |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/enbility/eebus-go/spine" |
| 7 | + "github.com/enbility/eebus-go/spine/model" |
| 8 | + "github.com/enbility/eebus-go/util" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + "github.com/stretchr/testify/suite" |
| 11 | +) |
| 12 | + |
| 13 | +func TestDeviceConfigurationSuite(t *testing.T) { |
| 14 | + suite.Run(t, new(DeviceConfigurationSuite)) |
| 15 | +} |
| 16 | + |
| 17 | +type DeviceConfigurationSuite struct { |
| 18 | + suite.Suite |
| 19 | + |
| 20 | + localDevice *spine.DeviceLocalImpl |
| 21 | + remoteEntity *spine.EntityRemoteImpl |
| 22 | + |
| 23 | + deviceConfiguration *DeviceConfiguration |
| 24 | + sentMessage []byte |
| 25 | +} |
| 26 | + |
| 27 | +var _ spine.SpineDataConnection = (*DeviceConfigurationSuite)(nil) |
| 28 | + |
| 29 | +func (s *DeviceConfigurationSuite) WriteSpineMessage(message []byte) { |
| 30 | + s.sentMessage = message |
| 31 | +} |
| 32 | + |
| 33 | +func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) { |
| 34 | + s.localDevice, s.remoteEntity = setupFeatures( |
| 35 | + s.T(), |
| 36 | + s, |
| 37 | + []featureFunctions{ |
| 38 | + { |
| 39 | + featureType: model.FeatureTypeTypeDeviceConfiguration, |
| 40 | + functions: []model.FunctionType{ |
| 41 | + model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, |
| 42 | + model.FunctionTypeDeviceConfigurationKeyValueListData, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + ) |
| 47 | + |
| 48 | + var err error |
| 49 | + s.deviceConfiguration, err = NewDeviceConfiguration(model.RoleTypeServer, model.RoleTypeClient, s.localDevice, s.remoteEntity) |
| 50 | + assert.Nil(s.T(), err) |
| 51 | + assert.NotNil(s.T(), s.deviceConfiguration) |
| 52 | +} |
| 53 | + |
| 54 | +func (s *DeviceConfigurationSuite) Test_Request() { |
| 55 | + err := s.deviceConfiguration.Request() |
| 56 | + assert.Nil(s.T(), err) |
| 57 | +} |
| 58 | + |
| 59 | +func (s *DeviceConfigurationSuite) Test_RequestKeyValueList() { |
| 60 | + counter, err := s.deviceConfiguration.RequestKeyValueList() |
| 61 | + assert.Nil(s.T(), err) |
| 62 | + assert.NotNil(s.T(), counter) |
| 63 | +} |
| 64 | + |
| 65 | +func (s *DeviceConfigurationSuite) Test_GetDescriptionKeyNameSupport() { |
| 66 | + exists, err := s.deviceConfiguration.GetDescriptionKeyNameSupport(model.DeviceConfigurationKeyNameTypeCommunicationsStandard) |
| 67 | + assert.NotNil(s.T(), err) |
| 68 | + assert.Equal(s.T(), false, exists) |
| 69 | + |
| 70 | + s.addDescription() |
| 71 | + |
| 72 | + exists, err = s.deviceConfiguration.GetDescriptionKeyNameSupport(model.DeviceConfigurationKeyNameTypeCommunicationsStandard) |
| 73 | + assert.Nil(s.T(), err) |
| 74 | + assert.Equal(s.T(), true, exists) |
| 75 | +} |
| 76 | + |
| 77 | +func (s *DeviceConfigurationSuite) Test_GetEVCommunicationStandard() { |
| 78 | + value, err := s.deviceConfiguration.GetEVCommunicationStandard() |
| 79 | + assert.NotNil(s.T(), err) |
| 80 | + assert.Nil(s.T(), value) |
| 81 | + |
| 82 | + s.addDescription() |
| 83 | + |
| 84 | + value, err = s.deviceConfiguration.GetEVCommunicationStandard() |
| 85 | + assert.NotNil(s.T(), err) |
| 86 | + assert.Nil(s.T(), value) |
| 87 | + |
| 88 | + s.addData() |
| 89 | + |
| 90 | + value, err = s.deviceConfiguration.GetEVCommunicationStandard() |
| 91 | + assert.Nil(s.T(), err) |
| 92 | + assert.NotNil(s.T(), value) |
| 93 | +} |
| 94 | + |
| 95 | +func (s *DeviceConfigurationSuite) Test_GetValues() { |
| 96 | + data, err := s.deviceConfiguration.GetValues() |
| 97 | + assert.NotNil(s.T(), err) |
| 98 | + assert.Nil(s.T(), data) |
| 99 | + |
| 100 | + s.addDescription() |
| 101 | + |
| 102 | + data, err = s.deviceConfiguration.GetValues() |
| 103 | + assert.NotNil(s.T(), err) |
| 104 | + assert.Nil(s.T(), data) |
| 105 | + |
| 106 | + s.addData() |
| 107 | + |
| 108 | + data, err = s.deviceConfiguration.GetValues() |
| 109 | + assert.Nil(s.T(), err) |
| 110 | + assert.NotNil(s.T(), data) |
| 111 | + |
| 112 | +} |
| 113 | + |
| 114 | +// helper |
| 115 | + |
| 116 | +func (s *DeviceConfigurationSuite) addDescription() { |
| 117 | + rF := s.remoteEntity.Feature(util.Ptr(model.AddressFeatureType(1))) |
| 118 | + fData := &model.DeviceConfigurationKeyValueDescriptionListDataType{ |
| 119 | + DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{ |
| 120 | + { |
| 121 | + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), |
| 122 | + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeCommunicationsStandard), |
| 123 | + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeString), |
| 124 | + }, |
| 125 | + { |
| 126 | + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)), |
| 127 | + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported), |
| 128 | + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeBoolean), |
| 129 | + }, |
| 130 | + { |
| 131 | + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(2)), |
| 132 | + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypePvCurtailmentLimitFactor), |
| 133 | + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeScaledNumber), |
| 134 | + }, |
| 135 | + }, |
| 136 | + } |
| 137 | + rF.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, fData, nil, nil) |
| 138 | +} |
| 139 | + |
| 140 | +func (s *DeviceConfigurationSuite) addData() { |
| 141 | + rF := s.remoteEntity.Feature(util.Ptr(model.AddressFeatureType(1))) |
| 142 | + fData := &model.DeviceConfigurationKeyValueListDataType{ |
| 143 | + DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{ |
| 144 | + { |
| 145 | + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), |
| 146 | + Value: &model.DeviceConfigurationKeyValueValueType{ |
| 147 | + String: util.Ptr(model.DeviceConfigurationKeyValueStringType("test")), |
| 148 | + }, |
| 149 | + }, |
| 150 | + { |
| 151 | + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)), |
| 152 | + Value: &model.DeviceConfigurationKeyValueValueType{ |
| 153 | + Boolean: util.Ptr(true), |
| 154 | + }, |
| 155 | + }, |
| 156 | + { |
| 157 | + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(2)), |
| 158 | + Value: &model.DeviceConfigurationKeyValueValueType{ |
| 159 | + ScaledNumber: model.NewScaledNumberType(50), |
| 160 | + }, |
| 161 | + }, |
| 162 | + }, |
| 163 | + } |
| 164 | + rF.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, fData, nil, nil) |
| 165 | +} |
0 commit comments