use of org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.DeviceStatus 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();
}
}
}
Aggregations