Search in sources :

Example 1 with Message

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);
}
Also used : Message(org.opensmartgridplatform.oslp.Oslp.Message) Then(io.cucumber.java.en.Then)

Example 2 with Message

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));
}
Also used : EventNotification(org.opensmartgridplatform.oslp.Oslp.EventNotification) Message(org.opensmartgridplatform.oslp.Oslp.Message) When(io.cucumber.java.en.When)

Example 3 with 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));
}
Also used : Message(org.opensmartgridplatform.oslp.Oslp.Message) EventNotificationResponse(org.opensmartgridplatform.oslp.Oslp.EventNotificationResponse) Then(io.cucumber.java.en.Then)

Example 4 with Message

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();
}
Also used : Message(org.opensmartgridplatform.oslp.Oslp.Message) Then(io.cucumber.java.en.Then)

Example 5 with Message

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]));
                }
            }
        }
    }
}
Also used : SetScheduleRequest(org.opensmartgridplatform.oslp.Oslp.SetScheduleRequest) ActionTime(org.opensmartgridplatform.oslp.Oslp.ActionTime) ReadSettingsHelper.getInteger(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getInteger) Weekday(org.opensmartgridplatform.oslp.Oslp.Weekday) Message(org.opensmartgridplatform.oslp.Oslp.Message) Schedule(org.opensmartgridplatform.oslp.Oslp.Schedule) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) ByteString(com.google.protobuf.ByteString)

Aggregations

Message (org.opensmartgridplatform.oslp.Oslp.Message)28 Then (io.cucumber.java.en.Then)18 ByteString (com.google.protobuf.ByteString)5 IOException (java.io.IOException)4 Oslp (org.opensmartgridplatform.oslp.Oslp)4 ParseException (java.text.ParseException)3 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 OslpEnvelope (org.opensmartgridplatform.oslp.OslpEnvelope)3 UnknownHostException (java.net.UnknownHostException)2 Test (org.junit.jupiter.api.Test)2 DeviceSimulatorException (org.opensmartgridplatform.cucumber.platform.publiclighting.mocks.oslpdevice.DeviceSimulatorException)2 EventNotificationResponse (org.opensmartgridplatform.oslp.Oslp.EventNotificationResponse)2 Given (io.cucumber.java.en.Given)1 When (io.cucumber.java.en.When)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 Sharable (io.netty.channel.ChannelHandler.Sharable)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelId (io.netty.channel.ChannelId)1