From d64f0964734ce11dae64fa14f93a7559b3fe29f6 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Mon, 8 Jan 2024 12:48:27 +0100 Subject: [PATCH] Add NodeManagementUseCaseDataType tests --- spine/model/nodemanagement_additions_test.go | 123 +++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 spine/model/nodemanagement_additions_test.go diff --git a/spine/model/nodemanagement_additions_test.go b/spine/model/nodemanagement_additions_test.go new file mode 100644 index 00000000..8a402eec --- /dev/null +++ b/spine/model/nodemanagement_additions_test.go @@ -0,0 +1,123 @@ +package model + +import ( + "testing" + + "github.com/enbility/eebus-go/util" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestNodeManagementUseCaseDataTypeSuite(t *testing.T) { + suite.Run(t, new(NodeManagementUseCaseDataTypeSuite)) +} + +type NodeManagementUseCaseDataTypeSuite struct { + suite.Suite +} + +func (s *NodeManagementUseCaseDataTypeSuite) SetupSuite() {} +func (s *NodeManagementUseCaseDataTypeSuite) TearDownTest() {} + +func (s *NodeManagementUseCaseDataTypeSuite) BeforeTest(suiteName, testName string) {} + +func (s *NodeManagementUseCaseDataTypeSuite) Test_AdditionsAndRemovals() { + ucs := &NodeManagementUseCaseDataType{} + assert.NotNil(s.T(), ucs) + assert.Equal(s.T(), 0, len(ucs.UseCaseInformation)) + + address := FeatureAddressType{ + Device: util.Ptr(AddressDeviceType("test")), + Entity: []AddressEntityType{1}, + } + ucs.AddUseCaseSupport( + address, + UseCaseActorTypeCEM, + UseCaseNameTypeControlOfBattery, + SpecificationVersionType(""), + "", + true, + []UseCaseScenarioSupportType{}, + ) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation)) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation[0].UseCaseSupport)) + + ucs.AddUseCaseSupport( + address, + UseCaseActorTypeCEM, + UseCaseNameTypeEVSECommissioningAndConfiguration, + SpecificationVersionType(""), + "", + true, + []UseCaseScenarioSupportType{}, + ) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation)) + assert.Equal(s.T(), 2, len(ucs.UseCaseInformation[0].UseCaseSupport)) + + ucs.AddUseCaseSupport( + address, + UseCaseActorTypeCEM, + UseCaseNameTypeEVSECommissioningAndConfiguration, + SpecificationVersionType(""), + "", + true, + []UseCaseScenarioSupportType{}, + ) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation)) + assert.Equal(s.T(), 2, len(ucs.UseCaseInformation[0].UseCaseSupport)) + + ucs.AddUseCaseSupport( + address, + UseCaseActorTypeEnergyGuard, + UseCaseNameTypeLimitationOfPowerConsumption, + SpecificationVersionType(""), + "", + true, + []UseCaseScenarioSupportType{}, + ) + assert.Equal(s.T(), 2, len(ucs.UseCaseInformation)) + assert.Equal(s.T(), 2, len(ucs.UseCaseInformation[0].UseCaseSupport)) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation[1].UseCaseSupport)) + + ucs.RemoveUseCaseSupport( + address, + UseCaseActorTypeCEM, + UseCaseNameTypeEVChargingSummary, + ) + assert.Equal(s.T(), 2, len(ucs.UseCaseInformation)) + assert.Equal(s.T(), 2, len(ucs.UseCaseInformation[0].UseCaseSupport)) + + ucs.RemoveUseCaseSupport( + address, + UseCaseActorTypeCEM, + UseCaseNameTypeControlOfBattery, + ) + assert.Equal(s.T(), 2, len(ucs.UseCaseInformation)) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation[0].UseCaseSupport)) + + ucs.RemoveUseCaseSupport( + address, + UseCaseActorTypeCEM, + UseCaseNameTypeEVSECommissioningAndConfiguration, + ) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation)) + + ucs.RemoveUseCaseSupport( + address, + "", + "", + ) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation)) + + invalidAddress := FeatureAddressType{ + Device: util.Ptr(AddressDeviceType("test")), + Entity: []AddressEntityType{2}, + } + ucs.RemoveUseCaseSupport( + invalidAddress, + UseCaseActorTypeCEM, + UseCaseNameTypeEVSECommissioningAndConfiguration, + ) + assert.Equal(s.T(), 1, len(ucs.UseCaseInformation)) + +}