Search in sources :

Example 1 with SetScheduleRequest

use of org.opensmartgridplatform.oslp.Oslp.SetScheduleRequest 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

ByteString (com.google.protobuf.ByteString)1 ReadSettingsHelper.getInteger (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getInteger)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 ActionTime (org.opensmartgridplatform.oslp.Oslp.ActionTime)1 Message (org.opensmartgridplatform.oslp.Oslp.Message)1 Schedule (org.opensmartgridplatform.oslp.Oslp.Schedule)1 SetScheduleRequest (org.opensmartgridplatform.oslp.Oslp.SetScheduleRequest)1 Weekday (org.opensmartgridplatform.oslp.Oslp.Weekday)1