use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementService method updateDeviceOutputSettings.
private void updateDeviceOutputSettings(final Device device, final Configuration configuration) {
// Check if device output settings can/should be updated
if (device == null || configuration == null || configuration.getRelayConfiguration() == null) {
// Nothing to update
return;
}
if (configuration.getRelayConfiguration().getRelayMap() == null || configuration.getRelayConfiguration().getRelayMap().isEmpty()) {
// Nothing to update
return;
}
final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
outputSettings.add(new DeviceOutputSetting(rm.getAddress(), rm.getIndex(), rm.getRelayType(), rm.getAlias()));
}
final Ssld ssld = this.findSsldForDevice(device);
ssld.updateOutputSettings(outputSettings);
this.ssldRepository.save(ssld);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceInstallationMapperTest method createSsld.
private Ssld createSsld() {
final Address containerAddress = this.createAddress();
final GpsCoordinates gps = new GpsCoordinates(GPS_LATITUDE, GPS_LONGITUDE);
final Ssld ssld = new Ssld(DEVICE_IDENTIFICATION, ALIAS, containerAddress, gps, null);
ssld.setPublicKeyPresent(PUBLIC_KEY_PRESENT);
return ssld;
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementServiceTest method testHandleGetConfigurationResponse.
@Test
void testHandleGetConfigurationResponse() {
this.exception = null;
when(this.ssldRepository.findByDeviceIdentification("deviceIdentification")).thenReturn(new Ssld());
this.configurationManagementService.handleGetConfigurationResponse(this.configurationDto, this.correlationIds, MESSAGE_TYPE, MESSAGE_PRIORITY, ResponseMessageResultType.OK, this.exception);
verify(this.webServiceResponseMessageSender).send(this.responseMessageArgumentCaptor.capture());
this.checkResponseMessageArgumentCaptor();
assertThat(this.responseMessageArgumentCaptor.getValue().getResult()).isEqualTo(ResponseMessageResultType.OK);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method handlesOneSsldPendingFirmwareUpdateRetrievingFirmwareVersion.
@Test
void handlesOneSsldPendingFirmwareUpdateRetrievingFirmwareVersion() throws Exception {
final String deviceIdentification = "Test-SSLD-1";
final Ssld ssld = new Ssld(deviceIdentification);
final String correlationUid = "correlation-uid-pending-firmware-update";
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.anSsldPendingFirmwareUpdate(1L, new Date(), deviceIdentification, correlationUid);
final Organisation organisation = new Organisation(ssldPendingFirmwareUpdate.getOrganisationIdentification(), "Organisation", "ORG", PlatformFunctionGroup.USER);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(Collections.singletonList(ssldPendingFirmwareUpdate));
when(this.deviceDomainService.searchActiveDevice(eq(deviceIdentification), any(ComponentType.class))).thenReturn(ssld);
when(this.organisationDomainService.searchOrganisation(organisation.getOrganisationIdentification())).thenReturn(organisation);
this.firmwareManagementService.handleSsldPendingFirmwareUpdate(deviceIdentification);
verify(this.ssldPendingFirmwareUpdateRepository, never()).delete(ssldPendingFirmwareUpdate);
/*
* Verify the firmware version request is made for the device with the
* SsldPendingFirmwareUpdate and that it uses the correlation UID from
* SsldPendingFirmwareUpdate, as this is important for the way the
* firmware version response will be treated later-on in a more complete
* firmware update scenario than the fragment seen here in this unit
* test.
*/
this.assertFirmwareVersionRequested(organisation.getOrganisationIdentification(), deviceIdentification, correlationUid);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method handlesMultipleSsldPendingFirmwareUpdatesWithoutFailure.
@Test
void handlesMultipleSsldPendingFirmwareUpdatesWithoutFailure() throws Exception {
final String deviceIdentification = "Test-SSLD-1";
final Ssld ssld = new Ssld(deviceIdentification);
final String correlationUidMostRecentPendingFirmwareUpdate = "correlation-uid-most-recent";
final long mostRecentCreationMillis = System.currentTimeMillis();
final SsldPendingFirmwareUpdate olderPendingFirmwareUpdate1 = this.anSsldPendingFirmwareUpdate(134562345L, new Date(mostRecentCreationMillis - 3_000_000_000L), deviceIdentification, "correlation-uid-1");
final SsldPendingFirmwareUpdate olderPendingFirmwareUpdate2 = this.anSsldPendingFirmwareUpdate(227587L, new Date(mostRecentCreationMillis - 604_800_000L), deviceIdentification, "correlation-uid-2");
final SsldPendingFirmwareUpdate olderPendingFirmwareUpdate3 = this.anSsldPendingFirmwareUpdate(308943152L, new Date(mostRecentCreationMillis - 123L), deviceIdentification, "correlation-uid-3");
final SsldPendingFirmwareUpdate mostRecentPendingFirmwareUpdate = this.anSsldPendingFirmwareUpdate(4459483L, new Date(mostRecentCreationMillis), deviceIdentification, correlationUidMostRecentPendingFirmwareUpdate);
final Organisation organisation = new Organisation(mostRecentPendingFirmwareUpdate.getOrganisationIdentification(), "Organisation", "ORG", PlatformFunctionGroup.USER);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(Arrays.asList(olderPendingFirmwareUpdate1, olderPendingFirmwareUpdate2, mostRecentPendingFirmwareUpdate, olderPendingFirmwareUpdate3));
when(this.deviceDomainService.searchActiveDevice(eq(deviceIdentification), any(ComponentType.class))).thenReturn(ssld);
when(this.organisationDomainService.searchOrganisation(organisation.getOrganisationIdentification())).thenReturn(organisation);
this.firmwareManagementService.handleSsldPendingFirmwareUpdate(deviceIdentification);
/*
* Verify the older pending firmware updates are deleted. This appears
* to be a reasonable way to deal with multiple records being present.
* The most recent pending update should not be deleted at this point,
* as it is important for the way the firmware version response will be
* treated later-on in a more complete firmware update scenario than the
* fragment seen here in this unit test.
*
* The check is here to confirm the code works as it was meant to be
* implemented. Not so much as a definitive specification as how it
* should work.
*/
final ArgumentCaptor<SsldPendingFirmwareUpdate> pendingUpdateCaptor = ArgumentCaptor.forClass(SsldPendingFirmwareUpdate.class);
verify(this.ssldPendingFirmwareUpdateRepository, atLeastOnce()).delete(pendingUpdateCaptor.capture());
final List<SsldPendingFirmwareUpdate> deletedPendingUpdates = pendingUpdateCaptor.getAllValues();
assertThat(deletedPendingUpdates).containsExactlyInAnyOrder(olderPendingFirmwareUpdate1, olderPendingFirmwareUpdate2, olderPendingFirmwareUpdate3);
/*
* Check that a get firmware version message is sent for the most recent
* pending firmware update.
*/
this.assertFirmwareVersionRequested(organisation.getOrganisationIdentification(), deviceIdentification, correlationUidMostRecentPendingFirmwareUpdate);
}
Aggregations