Search in sources :

Example 16 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionNotInHistory.

@Test
void testHandleGetFirmwareVersionResponseVersionNotInHistory() {
    // Arrange
    // Mock that VERSION 3 is now installed
    final FirmwareVersionDto firmwareVersionDto1 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.SECURITY, VERSION_3);
    final FirmwareVersionDto firmwareVersionDto2 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersionDto> versionsOnDeviceDtos = Arrays.asList(firmwareVersionDto1, firmwareVersionDto2);
    final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_3);
    final FirmwareVersion firmwareVersion2 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion2);
    final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
    final FirmwareModule firmwareModule1 = new FirmwareModule(FirmwareModuleType.SECURITY.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule1, VERSION_3);
    final FirmwareModule firmwareModule2 = new FirmwareModule(FirmwareModuleType.FUNCTIONAL.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule2, VERSION_3);
    when(this.domainCoreMapper.mapAsList(versionsOnDeviceDtos, FirmwareVersion.class)).thenReturn(versionsOnDevice);
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification("DVC")).thenReturn(Collections.emptyList());
    when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
    final CorrelationIds ids = new CorrelationIds("ORG", "DVC", "CORR");
    // Act
    this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
    // Validate
    verify(this.deviceFirmwareFileRepository, times(1)).save(any(DeviceFirmwareFile.class));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) Test(org.junit.jupiter.api.Test)

Example 17 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testCheckFirmwareHistoryForExistingVersion.

@Test
void testCheckFirmwareHistoryForExistingVersion() {
    // Arrange
    final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_2);
    final FirmwareVersion firmwareVersion2 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_2);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion2);
    // Act
    final List<FirmwareVersion> versionsNotInHistory = this.firmwareManagementService.checkFirmwareHistoryForVersion("DVC", versionsOnDevice);
    // Validate
    assertThat(versionsNotInHistory).withFailMessage("List should be empty").isEmpty();
}
Also used : FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Test(org.junit.jupiter.api.Test)

Example 18 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method checkSsldPendingFirmwareUpdateReturnsFalseIfPendingUpdatesAreForDifferentCorrelationUids.

@Test
void checkSsldPendingFirmwareUpdateReturnsFalseIfPendingUpdatesAreForDifferentCorrelationUids() {
    final String correlationUid = "correlation-uid-not-with-pending-updates";
    final CorrelationIds ids = new CorrelationIds(ORGANISATION_IDENTIFICATION, DEVICE_IDENTIFICATION, correlationUid);
    final List<FirmwareVersion> firmwareVersions = Arrays.asList(new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_2), new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_1));
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(Collections.singletonList(this.anSsldPendingFirmwareUpdate(4579L, new Date(), DEVICE_IDENTIFICATION, "some-other-correlation-uid")));
    final boolean hasPendingFirmwareUpdate = this.firmwareManagementService.checkSsldPendingFirmwareUpdate(ids, firmwareVersions);
    assertThat(hasPendingFirmwareUpdate).isFalse();
    verify(this.ssldPendingFirmwareUpdateRepository).findByDeviceIdentification(DEVICE_IDENTIFICATION);
    verifyNoMoreInteractions(this.ssldPendingFirmwareUpdateRepository);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 19 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testTryToAddFirmwareVersionToHistoryWhenFileIsAvailable.

@Test
void testTryToAddFirmwareVersionToHistoryWhenFileIsAvailable() {
    // Arrange
    final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
    final FirmwareModule firmwareModule = new FirmwareModule(FirmwareModuleType.SECURITY.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule, VERSION_2);
    when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
    final List<FirmwareVersion> firmwareVersions = Collections.singletonList(new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_2));
    // Act
    this.firmwareManagementService.tryToAddDeviceFirmwareFile("DVC", firmwareVersions);
    // Assert
    verify(this.deviceFirmwareFileRepository, times(1)).save(any(DeviceFirmwareFile.class));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Test(org.junit.jupiter.api.Test)

Example 20 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionAlreadyInAndLast.

@Test
void testHandleGetFirmwareVersionResponseVersionAlreadyInAndLast() {
    // Arrange
    // Mock that VERSION 2 is now installed
    final FirmwareVersionDto firmwareVersionDto1 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.SECURITY, VERSION_2);
    final FirmwareVersionDto firmwareVersionDto2 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.FUNCTIONAL, VERSION_2);
    final List<FirmwareVersionDto> versionsOnDeviceDtos = Arrays.asList(firmwareVersionDto1, firmwareVersionDto2);
    final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_2);
    final FirmwareVersion firmwareVersion2 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_2);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion2);
    final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
    final FirmwareModule firmwareModule1 = new FirmwareModule(FirmwareModuleType.SECURITY.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule1, VERSION_2);
    final FirmwareModule firmwareModule2 = new FirmwareModule(FirmwareModuleType.FUNCTIONAL.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule2, VERSION_2);
    when(this.domainCoreMapper.mapAsList(versionsOnDeviceDtos, FirmwareVersion.class)).thenReturn(versionsOnDevice);
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification("DVC")).thenReturn(Collections.emptyList());
    when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
    final CorrelationIds ids = new CorrelationIds("ORG", "DVC", "CORR");
    // Act
    this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
    // Validate
    verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) Test(org.junit.jupiter.api.Test)

Aggregations

FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)23 Test (org.junit.jupiter.api.Test)13 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)9 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)9 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)8 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)8 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)8 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)8 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)5 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)5 Date (java.util.Date)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SsldPendingFirmwareUpdate (org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate)4 FirmwareModuleType (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)3 Collection (java.util.Collection)2