use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform.
@Given("^the device sends a confirm register device request to the platform over \"([^\"]*)\"$")
public void theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform(final String protocol, final Map<String, String> settings) throws DeviceSimulatorException {
try {
final String deviceIdentification = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_IDENTIFICATION, PlatformPubliclightingDefaults.DEFAULT_DEVICE_IDENTIFICATION);
final String deviceUid = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_UID, PlatformPubliclightingDefaults.DEVICE_UID);
final OslpDevice oslpDevice = this.oslpDeviceRepository.findByDeviceIdentification(deviceIdentification);
final int randomDevice = oslpDevice.getRandomDevice();
final int randomPlatform = oslpDevice.getRandomPlatform();
final Oslp.ConfirmRegisterDeviceRequest confirmRegisterDeviceRequest = Oslp.ConfirmRegisterDeviceRequest.newBuilder().setRandomDevice(randomDevice).setRandomPlatform(randomPlatform).build();
final Message message = Message.newBuilder().setConfirmRegisterDeviceRequest(confirmRegisterDeviceRequest).build();
this.oslpMockServer.incrementSequenceNumber(this.getDeviceUid(settings));
final OslpEnvelope request = this.createEnvelopeBuilder(deviceUid, this.oslpMockServer.getSequenceNumber(this.getDeviceUid(settings))).withPayloadMessage(message).build();
this.send(request, settings);
} catch (final IOException | IllegalArgumentException e) {
ScenarioContext.current().put("Error", e);
}
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method aSetConfigurationOslpMessageIsSentToDevice.
/**
* Verify that a set configuration OSLP message is sent to the device.
*
* @param deviceIdentification The device identification expected in the message to the device.
*/
@Then("^a set configuration \"([^\"]*)\" message is sent to device \"([^\"]*)\"$")
public void aSetConfigurationOslpMessageIsSentToDevice(final String protocol, final String deviceIdentification, final Map<String, String> expectedResponseData) throws DeviceSimulatorException {
final Message receivedMessage = this.oslpMockServer.waitForRequest(this.getDeviceUid(expectedResponseData), MessageType.SET_CONFIGURATION);
assertThat(receivedMessage).isNotNull();
assertThat(receivedMessage.hasSetConfigurationRequest()).isTrue();
final SetConfigurationRequest receivedConfiguration = receivedMessage.getSetConfigurationRequest();
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_LIGHTTYPE)) && receivedConfiguration.getLightType() != null) {
final LightType expectedLightType = getEnum(expectedResponseData, PlatformKeys.KEY_LIGHTTYPE, LightType.class);
assertThat(receivedConfiguration.getLightType()).isEqualTo(expectedLightType);
switch(expectedLightType) {
case DALI:
final DaliConfiguration receivedDaliConfiguration = receivedConfiguration.getDaliConfiguration();
if (receivedDaliConfiguration != null) {
if (expectedResponseData.containsKey(PlatformKeys.DC_LIGHTS) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_LIGHTS))) {
assertThat(OslpUtils.byteStringToInteger(receivedDaliConfiguration.getNumberOfLights())).isEqualTo(getInteger(expectedResponseData, PlatformKeys.DC_LIGHTS));
}
if (expectedResponseData.containsKey(PlatformKeys.DC_MAP) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_MAP))) {
assertThat(receivedDaliConfiguration.getAddressMapList()).isNotNull();
final String[] expectedDcMapArray = getString(expectedResponseData, PlatformKeys.DC_MAP).split(";");
assertThat(receivedDaliConfiguration.getAddressMapList().size()).isEqualTo(expectedDcMapArray.length);
final List<IndexAddressMap> receivedIndexAddressMapList = receivedDaliConfiguration.getAddressMapList();
for (int i = 0; i < expectedDcMapArray.length; i++) {
final String[] expectedDcMapArrayElements = expectedDcMapArray[i].split(",");
assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getIndex())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[0]));
assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getAddress())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[1]));
}
}
}
break;
case RELAY:
final RelayConfiguration receivedRelayConfiguration = receivedConfiguration.getRelayConfiguration();
if (receivedRelayConfiguration != null) {
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.RELAY_CONF)) && receivedRelayConfiguration.getAddressMapList() != null) {
// Construct sorted list of received relay maps
final List<RelayMap> receivedRelayMapList = RelayMapConverter.convertIndexAddressMapListToRelayMapList(receivedRelayConfiguration.getAddressMapList());
Collections.sort(receivedRelayMapList);
// Construct sorted list of expected relay maps
final String[] expectedRelayMapArray = getString(expectedResponseData, PlatformKeys.RELAY_CONF).split(";");
final List<RelayMap> expectedRelayMapList = RelayMapConverter.convertStringsListToRelayMapList(expectedRelayMapArray);
Collections.sort(expectedRelayMapList);
assertThat(CollectionUtils.isEmpty(receivedRelayMapList)).as("Either the expected or the received relay maps are empty, but not both").isEqualTo(CollectionUtils.isEmpty(expectedRelayMapList));
if (!CollectionUtils.isEmpty(receivedRelayMapList) && !CollectionUtils.isEmpty(expectedRelayMapList)) {
assertThat(receivedRelayMapList.size()).as("Size of expected and received relay map list differs").isEqualTo(expectedRelayMapList.size());
}
// Compare the contents of each relay map
for (int i = 0; i < expectedRelayMapList.size(); i++) {
assertThat(receivedRelayMapList.get(i)).as("Expected and received relay map differs for " + i).isEqualTo(expectedRelayMapList.get(i));
}
}
}
break;
case ONE_TO_TEN_VOLT:
case ONE_TO_TEN_VOLT_REVERSE:
case LT_NOT_SET:
default:
assertThat(receivedConfiguration.getDaliConfiguration().getAddressMapList().size()).isEqualTo(0);
assertThat(receivedConfiguration.getRelayConfiguration().getAddressMapList().size()).isEqualTo(0);
}
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_PREFERRED_LINKTYPE)) && receivedConfiguration.getPreferredLinkType() != null) {
assertThat(receivedConfiguration.getPreferredLinkType()).isEqualTo(getEnum(expectedResponseData, PlatformKeys.KEY_PREFERRED_LINKTYPE, LinkType.class));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS))) {
assertThat(OslpDeviceSteps.convertIpAddress(receivedConfiguration.getOspgIpAddress())).isEqualTo(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_PORT))) {
assertThat(receivedConfiguration.getOsgpPortNumber()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.OSGP_PORT)));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET))) {
assertThat(receivedConfiguration.getAstroGateSunRiseOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET)));
}
if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET))) {
assertThat(receivedConfiguration.getAstroGateSunSetOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET)));
}
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method aStopDeviceOslpMessageIsSentToSpecificDevice.
/**
* Verify that a stop device OSLP message is sent to specific device.
*
* @param deviceIdentification The device identification expected in the message to the device.
*/
@Then("^a stop device \"([^\"]*)\" message is sent to device \"([^\"]*)\" with deviceUid \"([^\"]*)\"$")
public void aStopDeviceOslpMessageIsSentToSpecificDevice(final String protocol, final String deviceIdentification, final String deviceUid) throws DeviceSimulatorException {
final Message message = this.oslpMockServer.waitForRequest(deviceUid, MessageType.STOP_SELF_TEST);
assertThat(message).isNotNull();
assertThat(message.hasStopSelfTestRequest()).isTrue();
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theRegisterDeviceResponseContains.
/**
* Verify that we have received a response over OSLP/OSLP ELSTER
*/
@Then("^the register device response contains$")
public void theRegisterDeviceResponseContains(final Map<String, String> expectedResponse) {
final Exception e = (Exception) ScenarioContext.current().get("Error");
if (e == null || getString(expectedResponse, PlatformPubliclightingKeys.MESSAGE) == null) {
final Message responseMessage = this.oslpMockServer.waitForResponse();
final RegisterDeviceResponse response = responseMessage.getRegisterDeviceResponse();
assertThat(response.getCurrentTime()).isNotNull();
assertThat(response.getLocationInfo().getLongitude()).isNotNull();
assertThat(response.getLocationInfo().getLatitude()).isNotNull();
assertThat(response.getLocationInfo().getTimeOffset()).isNotNull();
assertThat(response.getStatus().name()).isEqualTo(getString(expectedResponse, PlatformPubliclightingKeys.KEY_STATUS));
} else {
assertThat(e).hasMessage(getString(expectedResponse, PlatformPubliclightingKeys.MESSAGE));
}
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theEventNotificationResponseContains.
/**
* Verify that we have received an event notification response over OSLP/OSLP ELSTER
*/
@Then("^the event notification response contains$")
public void theEventNotificationResponseContains(final Map<String, String> expectedResponse) {
final Message responseMessage = this.oslpMockServer.waitForResponse();
final EventNotificationResponse response = responseMessage.getEventNotificationResponse();
assertThat(response.getStatus().name()).isEqualTo(getString(expectedResponse, PlatformPubliclightingKeys.KEY_STATUS));
}
Aggregations