|
| 1 | +package mpc |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/enbility/eebus-go/api" |
| 5 | + "github.com/enbility/eebus-go/mocks" |
| 6 | + "github.com/enbility/eebus-go/service" |
| 7 | + "github.com/enbility/ship-go/cert" |
| 8 | + spineapi "github.com/enbility/spine-go/api" |
| 9 | + spinemocks "github.com/enbility/spine-go/mocks" |
| 10 | + "github.com/enbility/spine-go/model" |
| 11 | + "github.com/stretchr/testify/mock" |
| 12 | + "github.com/stretchr/testify/suite" |
| 13 | + "testing" |
| 14 | + "time" |
| 15 | +) |
| 16 | + |
| 17 | +const remoteSki string = "testremoteski" |
| 18 | + |
| 19 | +func TestMuMPCSuite(t *testing.T) { |
| 20 | + suite.Run(t, new(MuMPCSuite)) |
| 21 | +} |
| 22 | + |
| 23 | +type MuMPCSuite struct { |
| 24 | + suite.Suite |
| 25 | + |
| 26 | + sut *MPC |
| 27 | + |
| 28 | + service api.ServiceInterface |
| 29 | + |
| 30 | + remoteDevice spineapi.DeviceRemoteInterface |
| 31 | + mockRemoteEntity *spinemocks.EntityRemoteInterface |
| 32 | + monitoredEntity spineapi.EntityRemoteInterface |
| 33 | + loadControlFeature, |
| 34 | + deviceDiagnosisFeature, |
| 35 | + deviceConfigurationFeature spineapi.FeatureLocalInterface |
| 36 | + |
| 37 | + eventCalled bool |
| 38 | +} |
| 39 | + |
| 40 | +func (s *MuMPCSuite) Event(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) { |
| 41 | + s.eventCalled = true |
| 42 | +} |
| 43 | + |
| 44 | +func (s *MuMPCSuite) BeforeTest(suiteName, testName string) { |
| 45 | + s.eventCalled = false |
| 46 | + cert, _ := cert.CreateCertificate("test", "test", "DE", "test") |
| 47 | + configuration, _ := api.NewConfiguration( |
| 48 | + "test", "test", "test", "test", |
| 49 | + model.DeviceTypeTypeEnergyManagementSystem, |
| 50 | + []model.EntityTypeType{model.EntityTypeTypeInverter}, |
| 51 | + 9999, cert, time.Second*4) |
| 52 | + |
| 53 | + serviceHandler := mocks.NewServiceReaderInterface(s.T()) |
| 54 | + serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() |
| 55 | + |
| 56 | + s.service = service.NewService(configuration, serviceHandler) |
| 57 | + _ = s.service.Setup() |
| 58 | + |
| 59 | + mockRemoteDevice := spinemocks.NewDeviceRemoteInterface(s.T()) |
| 60 | + s.mockRemoteEntity = spinemocks.NewEntityRemoteInterface(s.T()) |
| 61 | + mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) |
| 62 | + mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() |
| 63 | + mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() |
| 64 | + s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() |
| 65 | + s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() |
| 66 | + entityAddress := &model.EntityAddressType{} |
| 67 | + s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() |
| 68 | + mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() |
| 69 | + mockRemoteFeature.EXPECT().Address().Return(&model.FeatureAddressType{}).Maybe() |
| 70 | + mockRemoteFeature.EXPECT().Operations().Return(nil).Maybe() |
| 71 | + |
| 72 | + localEntity := s.service.LocalDevice().EntityForType(model.EntityTypeTypeInverter) |
| 73 | + s.sut = NewMPC(localEntity, s.Event) |
| 74 | + s.sut.AddFeatures() |
| 75 | + s.sut.AddUseCase() |
| 76 | + |
| 77 | + //s.remoteDevice, s.monitoredEntity = setupDevices(s.service, s.T()) |
| 78 | +} |
0 commit comments