Search in sources :

Example 1 with GetStatusResponse

use of org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusResponse in project open-smart-grid-platform by OSGP.

the class GetStatusSteps method thePlatformBuffersADeviceInstallationGetStatusResponseMessageForDevice.

@Then("the platform buffers a device installation get status response message for device {string}")
public void thePlatformBuffersADeviceInstallationGetStatusResponseMessageForDevice(final String deviceIdentification, final Map<String, String> expectedResult) throws Throwable {
    final GetStatusAsyncRequest request = new GetStatusAsyncRequest();
    final AsyncRequest asyncRequest = new AsyncRequest();
    asyncRequest.setDeviceId(deviceIdentification);
    asyncRequest.setCorrelationUid((String) ScenarioContext.current().get(PlatformKeys.KEY_CORRELATION_UID));
    request.setAsyncRequest(asyncRequest);
    final GetStatusResponse response = Wait.untilAndReturn(() -> {
        final GetStatusResponse retval = this.client.getStatusResponse(request);
        assertThat(retval).isNotNull();
        assertThat(retval.getResult()).isEqualTo(Enum.valueOf(OsgpResultType.class, expectedResult.get(PlatformKeys.KEY_RESULT)));
        return retval;
    });
    final DeviceStatus deviceStatus = response.getDeviceStatus();
    assertThat(deviceStatus.getPreferredLinkType()).isEqualTo(getEnum(expectedResult, PlatformKeys.KEY_PREFERRED_LINKTYPE, LinkType.class));
    assertThat(deviceStatus.getActualLinkType()).isEqualTo(getEnum(expectedResult, PlatformKeys.KEY_ACTUAL_LINKTYPE, LinkType.class));
    assertThat(deviceStatus.getLightType()).isEqualTo(getEnum(expectedResult, PlatformKeys.KEY_LIGHTTYPE, LightType.class));
    if (expectedResult.containsKey(PlatformKeys.KEY_EVENTNOTIFICATIONTYPES) && StringUtils.isNotBlank(expectedResult.get(PlatformKeys.KEY_EVENTNOTIFICATIONTYPES))) {
        assertThat(deviceStatus.getEventNotifications().size()).isEqualTo(getString(expectedResult, PlatformKeys.KEY_EVENTNOTIFICATIONS, PlatformDefaults.DEFAULT_EVENTNOTIFICATIONS).split(PlatformKeys.SEPARATOR_COMMA).length);
        for (final String eventNotification : getString(expectedResult, PlatformKeys.KEY_EVENTNOTIFICATIONS, PlatformDefaults.DEFAULT_EVENTNOTIFICATIONS).split(PlatformKeys.SEPARATOR_COMMA)) {
            final EventNotificationType eventNotificationType = Enum.valueOf(EventNotificationType.class, eventNotification);
            assertThat(deviceStatus.getEventNotifications().contains(eventNotificationType)).isTrue();
        }
    }
    if (expectedResult.containsKey(PlatformKeys.KEY_LIGHTVALUES) && StringUtils.isNotBlank(expectedResult.get(PlatformKeys.KEY_LIGHTVALUES))) {
        assertThat(deviceStatus.getLightValues().size()).isEqualTo(getString(expectedResult, PlatformKeys.KEY_LIGHTVALUES, PlatformDefaults.DEFAULT_LIGHTVALUES).split(PlatformKeys.SEPARATOR_COMMA).length);
        for (final String lightValues : getString(expectedResult, PlatformKeys.KEY_LIGHTVALUES, PlatformDefaults.DEFAULT_LIGHTVALUES).split(PlatformKeys.SEPARATOR_COMMA)) {
            final String[] parts = lightValues.split(PlatformKeys.SEPARATOR_SEMICOLON);
            final Integer index = Integer.parseInt(parts[0]);
            final Boolean on = Boolean.parseBoolean(parts[1]);
            final Integer dimValue = Integer.parseInt(parts[2]);
            boolean found = false;
            for (final LightValue lightValue : deviceStatus.getLightValues()) {
                if (Objects.equals(lightValue.getIndex(), index) && lightValue.isOn() == on && Objects.equals(lightValue.getDimValue(), dimValue)) {
                    found = true;
                    break;
                }
            }
            assertThat(found).isTrue();
        }
    }
}
Also used : LightType(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightType) GetStatusAsyncRequest(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusAsyncRequest) AsyncRequest(org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncRequest) GetStatusAsyncRequest(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusAsyncRequest) GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusResponse) LightValue(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightValue) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) OsgpResultType(org.opensmartgridplatform.adapter.ws.schema.core.common.OsgpResultType) DeviceStatus(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.DeviceStatus) EventNotificationType(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.EventNotificationType) LinkType(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LinkType) Then(io.cucumber.java.en.Then)

Example 2 with GetStatusResponse

use of org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusResponse in project open-smart-grid-platform by OSGP.

the class DeviceInstallationEndpoint method getGetStatusResponse.

@PayloadRoot(localPart = "GetStatusAsyncRequest", namespace = DEVICE_INSTALLATION_NAMESPACE)
@ResponsePayload
public GetStatusResponse getGetStatusResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetStatusAsyncRequest request) throws OsgpException {
    LOGGER.info("Get Status Response received from organisation: {}.", organisationIdentification);
    final GetStatusResponse response = new GetStatusResponse();
    try {
        final ResponseMessage responseMessage = this.getResponseMessage(request.getAsyncRequest());
        if (responseMessage != null) {
            throwExceptionIfResultNotOk(responseMessage, "getting status");
            response.setResult(OsgpResultType.fromValue(responseMessage.getResult().getValue()));
            final DeviceStatus deviceStatus = (DeviceStatus) responseMessage.getDataObject();
            if (deviceStatus != null) {
                response.setDeviceStatus(this.deviceInstallationMapper.map(deviceStatus, org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.DeviceStatus.class));
            }
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusResponse) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

GetStatusResponse (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusResponse)2 Then (io.cucumber.java.en.Then)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 AsyncRequest (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncRequest)1 OsgpResultType (org.opensmartgridplatform.adapter.ws.schema.core.common.OsgpResultType)1 DeviceStatus (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.DeviceStatus)1 EventNotificationType (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.EventNotificationType)1 GetStatusAsyncRequest (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.GetStatusAsyncRequest)1 LightType (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightType)1 LightValue (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightValue)1 LinkType (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LinkType)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 DeviceStatus (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1