Search in sources :

Example 11 with Ssld

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);
}
Also used : ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 12 with 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;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 13 with 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);
}
Also used : Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Example 14 with Ssld

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);
}
Also used : ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Example 15 with Ssld

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);
}
Also used : ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Aggregations

Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)50 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)16 Device (org.opensmartgridplatform.domain.core.entities.Device)13 ArrayList (java.util.ArrayList)12 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)11 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 Test (org.junit.jupiter.api.Test)9 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9 Given (io.cucumber.java.en.Given)8 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)8 RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Date (java.util.Date)5 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)5 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)5 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)4 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)4 NoDeviceResponseException (org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException)4