use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method aSetLightOslpMessageWithLightValuesIsSentToSpecificDevice.
/**
* Verify that a set light OSLP message is sent to specific device.
*
* @param nofLightValues The parameters expected in the message of the device.
*/
@Then("^a set light \"([^\"]*)\" message with \"([^\"]*)\" lightvalues is sent to the device with deviceUid \"([^\"]*)\"$")
public void aSetLightOslpMessageWithLightValuesIsSentToSpecificDevice(final String protocol, final int nofLightValues, final String deviceUid) throws DeviceSimulatorException {
final Message message = this.oslpMockServer.waitForRequest(deviceUid, MessageType.SET_LIGHT);
assertThat(message).isNotNull();
assertThat(message.hasSetLightRequest()).isTrue();
assertThat(message.getSetLightRequest().getValuesList().size()).isEqualTo(nofLightValues);
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method receivingAnOslpEventNotificationMessage.
/**
* Simulates sending an OSLP EventNotification message to the OSLP Protocol adapter.
*
* @throws DeviceSimulatorException
* @throws IOException
* @throws ParseException
*/
@When("^receiving an \"([^\"]*)\" event notification message$")
public void receivingAnOslpEventNotificationMessage(final String protocol, final Map<String, String> settings) throws DeviceSimulatorException, IOException, ParseException {
final EventNotification eventNotification = EventNotification.newBuilder().setDescription(getString(settings, PlatformPubliclightingKeys.KEY_DESCRIPTION, "")).setEvent(getEnum(settings, PlatformPubliclightingKeys.KEY_EVENT, Event.class)).build();
final Message message = Oslp.Message.newBuilder().setEventNotificationRequest(EventNotificationRequest.newBuilder().addNotifications(eventNotification)).build();
// Save the OSLP response for later validation.
ScenarioContext.current().put(PlatformPubliclightingKeys.RESPONSE, this.oslpMockServer.sendRequest(this.getDeviceUid(settings), message));
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theOslpEventNotificationResponseContains.
@Then("^the \"([^\"]*)\" event notification response contains$")
public void theOslpEventNotificationResponseContains(final String protocol, final Map<String, String> expectedResponse) {
final Message responseMessage = (Message) ScenarioContext.current().get(PlatformPubliclightingKeys.RESPONSE);
final EventNotificationResponse response = responseMessage.getEventNotificationResponse();
assertThat(response.getStatus()).isEqualTo(getString(expectedResponse, PlatformPubliclightingKeys.KEY_STATUS));
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method aSetEventNotificationOslpMessageIsSentToSpecificDevice.
/**
* Verify that an event notification OSLP message is sent to specific device.
*
* @param deviceIdentification The device identification expected in the message to the device.
*/
@Then("^a set event notification \"([^\"]*)\" message is sent to device \"([^\"]*)\" with deviceUid \"([^\"]*)\"")
public void aSetEventNotificationOslpMessageIsSentToSpecificDevice(final String protocol, final String deviceIdentification, final String deviceUid) throws DeviceSimulatorException {
final Message message = this.oslpMockServer.waitForRequest(deviceUid, MessageType.SET_EVENT_NOTIFICATIONS);
assertThat(message).isNotNull();
assertThat(message.hasSetEventNotificationsRequest()).isTrue();
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method checkAndValidateRequest.
private void checkAndValidateRequest(final MessageType type, final Map<String, String> expectedRequest) throws DeviceSimulatorException {
final Message message = this.oslpMockServer.waitForRequest(this.getDeviceUid(expectedRequest), type);
assertThat(message).isNotNull();
assertThat(message.hasSetScheduleRequest()).isTrue();
final SetScheduleRequest request = message.getSetScheduleRequest();
for (final Schedule schedule : request.getSchedulesList()) {
if (type == MessageType.SET_LIGHT_SCHEDULE) {
assertThat(schedule.getWeekday()).isEqualTo(getEnum(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_WEEKDAY, Weekday.class));
}
if (StringUtils.isNotBlank(expectedRequest.get(PlatformPubliclightingKeys.SCHEDULE_STARTDAY))) {
final String startDay = getDate(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_STARTDAY).toDateTime(DateTimeZone.UTC).toString("yyyyMMdd");
assertThat(schedule.getStartDay()).isEqualTo(startDay);
}
if (StringUtils.isNotBlank(expectedRequest.get(PlatformPubliclightingKeys.SCHEDULE_ENDDAY))) {
final String endDay = getDate(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_ENDDAY).toDateTime(DateTimeZone.UTC).toString("yyyyMMdd");
assertThat(schedule.getEndDay()).isEqualTo(endDay);
}
if (type == MessageType.SET_LIGHT_SCHEDULE) {
assertThat(schedule.getActionTime()).isEqualTo(getEnum(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_ACTIONTIME, ActionTime.class));
}
if (StringUtils.isNotBlank(expectedRequest.get(PlatformPubliclightingKeys.SCHEDULE_TIME))) {
String expectedTime = getString(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_TIME).replace(":", "");
if (expectedTime.contains(".")) {
expectedTime = expectedTime.substring(0, expectedTime.indexOf("."));
}
assertThat(schedule.getTime()).isEqualTo(expectedTime);
}
final String scheduleLightValue = getString(expectedRequest, (type == MessageType.SET_LIGHT_SCHEDULE) ? PlatformPubliclightingKeys.SCHEDULE_LIGHTVALUES : PlatformPubliclightingKeys.SCHEDULE_TARIFFVALUES);
final String[] scheduleLightValues = scheduleLightValue.split(";");
assertThat(schedule.getValueCount()).isEqualTo(scheduleLightValues.length);
for (int i = 0; i < scheduleLightValues.length; i++) {
final Integer index = OslpUtils.byteStringToInteger(schedule.getValue(i).getIndex()), dimValue = OslpUtils.byteStringToInteger(schedule.getValue(i).getDimValue());
if (type == MessageType.SET_LIGHT_SCHEDULE) {
assertThat(String.format("%s,%s,%s", (index != null) ? index : "", schedule.getValue(i).getOn(), (dimValue != null) ? dimValue : "")).isEqualTo(scheduleLightValues[i]);
} else if (type == MessageType.SET_TARIFF_SCHEDULE) {
assertThat(String.format("%s,%s", (index != null) ? index : "", !schedule.getValue(i).getOn())).isEqualTo(scheduleLightValues[i]);
}
}
if (type == MessageType.SET_LIGHT_SCHEDULE) {
assertThat(schedule.getTriggerType()).isEqualTo((!getString(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_TRIGGERTYPE).isEmpty()) ? getEnum(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_TRIGGERTYPE, TriggerType.class) : TriggerType.TT_NOT_SET);
if (StringUtils.isNotBlank(expectedRequest.get(PlatformPubliclightingKeys.SCHEDULE_TRIGGERWINDOW))) {
final String[] windowTypeValues = getString(expectedRequest, PlatformPubliclightingKeys.SCHEDULE_TRIGGERWINDOW).split(",");
if (windowTypeValues.length == 2) {
assertThat(schedule.getWindow().getMinutesBefore()).isEqualTo(Integer.parseInt(windowTypeValues[0]));
assertThat(schedule.getWindow().getMinutesAfter()).isEqualTo(Integer.parseInt(windowTypeValues[1]));
}
}
}
}
}
Aggregations