use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class FeederSteps method givenAFeeder.
@Given("a feeder")
public void givenAFeeder(final Map<String, String> settings) {
final Feeder feeder = new Feeder();
final String substationIdentification = ReadSettingsHelper.getString(settings, PlatformDistributionAutomationKeys.SUBSTATION_IDENTIFICATION, PlatformDistributionAutomationDefaults.SUBSTATION_IDENTIFICATION);
final Location location = this.locationSteps.findLocation(substationIdentification);
feeder.setLocation(location);
feeder.setFeederNumber(ReadSettingsHelper.getInteger(settings, PlatformDistributionAutomationKeys.FEEDER_NUMBER, PlatformDistributionAutomationDefaults.FEEDER_NUMBER));
feeder.setFieldCode(ReadSettingsHelper.getString(settings, PlatformDistributionAutomationKeys.FEEDER_FIELD_CODE));
feeder.setName(ReadSettingsHelper.getString(settings, PlatformDistributionAutomationKeys.FEEDER_NAME, PlatformDistributionAutomationDefaults.FEEDER_NAME));
feeder.setAssetLabel(ReadSettingsHelper.getString(settings, PlatformDistributionAutomationKeys.FEEDER_ASSET_LABEL));
this.feederRepository.save(feeder);
}
use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class WsMicrogridsResponseDataSteps method aResponseDataRecord.
@Given("^a response data record$")
@Transactional("txMgrWsMicrogrids")
public ResponseData aResponseDataRecord(final Map<String, String> settings) {
ResponseData responseData = new ResponseDataBuilder().fromSettings(settings).build();
responseData = this.microgridsResponseDataRepository.save(responseData);
ScenarioContext.current().put(PlatformKeys.KEY_CORRELATION_UID, responseData.getCorrelationUid());
try {
// (as it will be overridden on first save)
if (settings.containsKey(PlatformKeys.KEY_CREATION_TIME)) {
final Field fld = responseData.getClass().getSuperclass().getDeclaredField("creationTime");
fld.setAccessible(true);
fld.set(responseData, DateTimeHelper.getDateTime(settings.get(PlatformKeys.KEY_CREATION_TIME)).toDate());
this.microgridsResponseDataRepository.saveAndFlush(responseData);
}
} catch (final Exception e) {
LOGGER.error("Exception", e);
Assertions.fail("Failed to create response data record.");
}
return responseData;
}
use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class LocationSteps method givenALocation.
@Given("a location")
public void givenALocation(final Map<String, String> settings) {
final Location location = new Location();
location.setSubstationIdentification(ReadSettingsHelper.getString(settings, PlatformDistributionAutomationKeys.SUBSTATION_IDENTIFICATION, PlatformDistributionAutomationKeys.SUBSTATION_IDENTIFICATION));
location.setName(ReadSettingsHelper.getString(settings, PlatformDistributionAutomationKeys.SUBSTATION_NAME, PlatformDistributionAutomationDefaults.SUBSTATION_NAME));
this.locationRepository.save(location);
}
use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class FirmwareFileSteps method aFirmware.
/**
* Generic method which adds a firmware using the settings.
*
* @param settings The settings for the firmware to be used.
* @throws IOException
*/
@Given("^a firmware$")
public void aFirmware(final Map<String, String> settings) throws IOException {
/*
* Model code does not uniquely identify a device model, which is why
* deviceModelRepository is changed to return a list of device models.
* In the test data that is set up, there probably is only one device
* model for the given model code, and just selecting the first device
* model returned should work.
*
* A better solution might be to add the manufacturer in the scenario
* data and do a lookup by manufacturer and model code, which should
* uniquely define the device model.
*/
final List<DeviceModel> deviceModels = this.deviceModelRepository.findByModelCode(getString(settings, PlatformKeys.DEVICEMODEL_MODELCODE));
final DeviceModel deviceModel;
if (deviceModels.isEmpty()) {
deviceModel = this.deviceModelSteps.aDeviceModel(settings);
} else {
deviceModel = deviceModels.get(0);
}
final boolean isForSmartMeters = getBoolean(settings, "FirmwareIsForSmartMeters", false);
final Map<FirmwareModule, String> versionsByModule = this.deviceFirmwareModuleSteps.getFirmwareModuleVersions(settings, isForSmartMeters);
/*
* Using the filename as firmware identification is necessary as long as
* the DLMS protocol adapter expects the filename to identify a
* firmware. As soon as the protocol adapter accepts the newer
* identification, it is no longer necessary to do this and the default
* random identification should do fine for the tests. (The
* identification then no longer needs to be added to the constructor
* used to create the firmware.)
*/
String identification = getString(settings, PlatformKeys.FIRMWARE_FILE_FILENAME, UUID.randomUUID().toString().replace("-", ""));
/*
* To enable tests for Firmware File upload the FirmwareFileIdentification
* as actually used to uniquely identify the Firmware File. In these scenario's
* the FirmwareFileIdentification is added and will overrule the filename as identification.
*/
identification = getString(settings, PlatformKeys.FIRMWARE_FILE_IDENTIFICATION, identification);
/*
* The File contents can either be present in the Scenario parameters under label FirmwareFile
* The File Content is than provided in hexadecimal
* or the File contents can be read into a byte array using Firmware File's Filename
*/
final String filename = getString(settings, PlatformKeys.FIRMWARE_FILE_FILENAME, "");
byte[] file = null;
if (settings.containsKey(PlatformKeys.FIRMWARE_FILE)) {
file = getHexDecoded(settings, PlatformKeys.FIRMWARE_FILE, null);
} else {
final boolean fileExists = getBoolean(settings, PlatformKeys.FIRMWARE_FILE_EXISTS, PlatformDefaults.FIRMWARE_FILE_EXISTS);
if (fileExists) {
file = this.readFile(deviceModel, filename, isForSmartMeters);
}
}
final byte[] imageIdentifier = getHexDecoded(settings, PlatformKeys.FIRMWARE_FILE_IMAGE_IDENTIFIER, null);
FirmwareFile firmwareFile = new FirmwareFile.Builder().withIdentification(identification).withFilename(filename).withDescription(getString(settings, PlatformKeys.FIRMWARE_DESCRIPTION, PlatformDefaults.FIRMWARE_DESCRIPTION)).withPushToNewDevices(getBoolean(settings, PlatformKeys.FIRMWARE_PUSH_TO_NEW_DEVICES, PlatformDefaults.FIRMWARE_PUSH_TO_NEW_DEVICE)).withActive(getBoolean(settings, PlatformKeys.FIRMWARE_ACTIVE, PlatformDefaults.FIRMWARE_ACTIVE)).withFile(file).withImageIdentifier(imageIdentifier).build();
if (!isForSmartMeters) {
// Create file on disk
this.createFile(deviceModel.getManufacturer().getCode(), deviceModel.getModelCode(), filename);
}
/*
* Save the firmware file before adding the device model and updating
* the firmware module data. Trying to save a new firmware file with the
* related entities that were persisted earlier causes Hibernate
* exceptions referring to persistent entities in detached state.
*/
firmwareFile = this.firmwareFileRepository.save(firmwareFile);
firmwareFile.addDeviceModel(deviceModel);
firmwareFile.updateFirmwareModuleData(versionsByModule);
this.firmwareFileRepository.save(firmwareFile);
}
use of io.cucumber.java.en.Given in project open-smart-grid-platform by OSGP.
the class RelayStatusSteps method aDeviceRelayStatus.
@Given("^a device relay status$")
public void aDeviceRelayStatus(final Map<String, String> settings) {
final Ssld ssld = this.ssldDeviceSteps.findByDeviceIdentification(settings);
final RelayStatus relayStatus = this.relayStatusFactory.fromMap(ssld, settings);
ssld.addOrUpdateRelayStatus(relayStatus);
this.ssldDeviceSteps.saveSsld(ssld);
}
Aggregations