use of io.cucumber.java.en.Given 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 io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theDeviceReturnsAGetConfigurationStatusWithResultOverOslp.
/**
* Setup method to set the configuration status which should be returned by the mock.
*
* @throws UnknownHostException
*/
@Given("^the device returns a get configuration status \"([^\"]*)\" over \"([^\"]*)\"$")
public void theDeviceReturnsAGetConfigurationStatusWithResultOverOslp(final String result, final String protocol, final Map<String, String> requestParameters) throws UnknownHostException {
final String osgpIpAddress = getString(requestParameters, PlatformPubliclightingKeys.OSGP_IP_ADDRESS);
final String osgpIpAddressMock;
if (StringUtils.isEmpty(osgpIpAddress)) {
osgpIpAddressMock = null;
} else {
osgpIpAddressMock = osgpIpAddress;
}
this.oslpMockServer.mockGetConfigurationResponse(this.getDeviceUid(requestParameters), Enum.valueOf(Status.class, result), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTTYPE, LightType.class, PlatformPubliclightingDefaults.DEFAULT_LIGHTTYPE), getString(requestParameters, PlatformPubliclightingKeys.DC_LIGHTS, PlatformPubliclightingDefaults.DC_LIGHTS), getString(requestParameters, PlatformPubliclightingKeys.DC_MAP, PlatformPubliclightingDefaults.DEFAULT_DC_MAP), getString(requestParameters, PlatformPubliclightingKeys.RELAY_CONF, PlatformPubliclightingDefaults.DEFAULT_RELAY_CONFIGURATION), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_PREFERRED_LINKTYPE, LinkType.class, PlatformPubliclightingDefaults.DEFAULT_PREFERRED_LINKTYPE), osgpIpAddressMock, getInteger(requestParameters, PlatformPubliclightingKeys.OSGP_PORT, PlatformPubliclightingDefaults.DEFAULT_OSLP_PORT));
}
use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method aPendingSetScheduleRequest.
@Given("^a pending set schedule request that expires within \"([^\"]*)\" minutes$")
public void aPendingSetScheduleRequest(final int expiresInMinutes, final Map<String, String> settings) {
final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
final String deviceUid = getString(settings, PlatformKeys.KEY_DEVICE_UID, PlatformDefaults.DEVICE_UID);
final String organisationIdentification = getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
final Date expireDateTime = Date.from(ZonedDateTime.now().plusMinutes(expiresInMinutes).toInstant());
// just add a dummy DeviceRequest and a dummy
// ScheduleMessageDataContainerDto
final PendingSetScheduleRequest pendingSetScheduleRequest = PendingSetScheduleRequest.builder().deviceIdentification(deviceIdentification).deviceUid(deviceUid).expiredAt(expireDateTime).deviceRequest(new DeviceRequest(organisationIdentification, deviceIdentification, null, 4)).scheduleMessageDataContainerDto(new ScheduleMessageDataContainerDto.Builder(null).build()).build();
this.pendingSetScheduleRequestRepository.save(pendingSetScheduleRequest);
}
use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class Iec60870DeviceSteps method aLightMeasurementDevice.
@Given("a light sensor")
public void aLightMeasurementDevice(final Map<String, String> deviceData) {
final Iec60870Device device = Iec60870DeviceFactory.fromSettings(this.settingsWithDeviceType(deviceData, DeviceType.LIGHT_SENSOR));
this.deviceIsKnownInTheRepository(device);
}
use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class RetrieveReceivedEventNotifications method anEvent.
@Given("^(\\d+) events?$")
public void anEvent(final int amount, final Map<String, String> data) throws Exception {
final String deviceIdentification = getString(data, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
for (int i = 0; i < amount; i++) {
final Event event = new Event(deviceIdentification, getDateTime(getString(data, PlatformKeys.TIMESTAMP, PlatformDefaults.TIMESTAMP)).toDate(), getEnum(data, PlatformKeys.EVENT_TYPE, EventType.class, EventType.ALARM_NOTIFICATION), getString(data, PlatformKeys.KEY_DESCRIPTION, PlatformDefaults.DEFAULT_EVENT_DESCRIPTION), getInteger(data, PlatformKeys.KEY_INDEX, PlatformDefaults.DEFAULT_INDEX));
this.eventRepository.save(event);
}
}
Aggregations