Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OC-731: Fix configuration converter and enhance acceptance tests #565

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.opensmartgridplatform.cucumber.platform.common.glue.steps.ws.core.configurationmanagement;

import static org.assertj.core.api.Assertions.assertThat;
import static org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getBoolean;
import static org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getEnum;
import static org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getInteger;
import static org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString;
Expand Down Expand Up @@ -217,6 +218,18 @@ public void thePlatformBuffersAGetConfigurationResponseMessageForDevice(final St
assertThat(configuration.getOsgpPortNumber())
.isEqualTo(getInteger(expectedResponseData, PlatformKeys.OSGP_PORT));
}

if (expectedResponseData.containsKey(PlatformKeys.KEY_DHCP_ENABLED)
&& StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.KEY_DHCP_ENABLED))) {
assertThat(configuration.isDhcpEnabled())
.isEqualTo(getBoolean(expectedResponseData, PlatformKeys.KEY_DHCP_ENABLED));
}

if (expectedResponseData.containsKey(PlatformKeys.KEY_TEST_BUTTON_ENABLED)
&& StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.KEY_TEST_BUTTON_ENABLED))) {
assertThat(configuration.isTestButtonEnabled())
.isEqualTo(getBoolean(expectedResponseData, PlatformKeys.KEY_TEST_BUTTON_ENABLED));
}
}

@Then("^the platform buffers a get configuration response message for device \"([^\"]*)\" contains soap fault$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,13 @@ public void theDeviceReturnsAGetConfigurationStatusWithResultOverOslp(final Stri
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));
osgpIpAddressMock,
getInteger(requestParameters, PlatformPubliclightingKeys.OSGP_PORT,
PlatformPubliclightingDefaults.DEFAULT_OSLP_PORT),
getBoolean(requestParameters, PlatformPubliclightingKeys.KEY_DHCP_ENABLED,
PlatformPubliclightingDefaults.DEFAULT_DHCP_ENABLED),
getBoolean(requestParameters, PlatformPubliclightingKeys.KEY_TEST_BUTTON_ENABLED,
PlatformPubliclightingDefaults.DEFAULT_TEST_BUTTON_ENABLED));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ public PrivateKey privateKey() {

public void mockGetConfigurationResponse(final String deviceUid, final Oslp.Status oslpStatus,
final LightType lightType, final String dcLights, final String dcMap, final String rcMap,
final LinkType preferredLinkType, final String osgpIpAddress, final Integer osgpPort)
throws UnknownHostException {
final LinkType preferredLinkType, final String osgpIpAddress, final Integer osgpPort,
final Boolean dhcpEnabled, final Boolean testButtonEnabled) throws UnknownHostException {

final String[] dcMapArray;
final String[] rcMapArray;
Expand Down Expand Up @@ -368,6 +368,9 @@ public void mockGetConfigurationResponse(final String deviceUid, final Oslp.Stat
builder.setOsgpPortNumber(osgpPort);
}

builder.setIsDhcpEnabled(dhcpEnabled);
builder.setIsTestButtonEnabled(testButtonEnabled);

LOGGER.info(MOCKING_MESSAGE_TYPE, deviceUid, MessageType.GET_CONFIGURATION);
this.devicesContext.getDeviceState(deviceUid)
.addMockedResponse(MessageType.GET_CONFIGURATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Feature: CoreConfigurationManagement GetConfiguration
| PreferredLinkType | <PreferredLinkType> |
| OsgpIpAddress | <OsgpIpAddress> |
| OsgpPort | <OsgpPort> |
| DhcpEnabled | <DhcpEnabled> |
| TestButtonEnabled | <TestButtonEnabled> |
When receiving a get configuration request
| DeviceIdentification | TEST1024000000001 |
Then the get configuration async response contains
Expand All @@ -33,21 +35,23 @@ Feature: CoreConfigurationManagement GetConfiguration
| PreferredLinkType | <PreferredLinkType> |
| OsgpIpAddress | <OsgpIpAddress> |
| OsgpPort | <OsgpPort> |
| DhcpEnabled | <DhcpEnabled> |
| TestButtonEnabled | <TestButtonEnabled> |

Examples:
| Protocol | LightType | DcLights | DcMap | RelayConf | PreferredLinkType | OsgpIpAddress | OsgpPort |
| OSLP ELSTER | RELAY | | | | | 10.20.30.40 | 12122 |
| OSLP ELSTER | RELAY | | | 1,1,LIGHT | | 10.20.30.40 | 12122 |
| OSLP ELSTER | ONE_TO_TEN_VOLT | | | | | 10.20.30.40 | 12122 |
| OSLP ELSTER | ONE_TO_TEN_VOLT_REVERSE | | | | | 10.20.30.40 | 12123 |
| OSLP ELSTER | DALI | 2 | 1,2;2,1 | | | 10.20.30.40 | 12123 |
| OSLP ELSTER | | | | | | 10.20.30.40 | 12123 |
| OSLP ELSTER | | | | | GPRS | 10.20.30.50 | 12122 |
| OSLP ELSTER | DALI | | | | | 10.20.30.50 | 12122 |
| OSLP ELSTER | | | | | | 10.20.30.50 | 12122 |
| OSLP ELSTER | | | | | | 10.20.30.50 | 12123 |
| OSLP ELSTER | RELAY | | | 1,1,LIGHT | CDMA | 10.20.30.50 | 12123 |
| OSLP ELSTER | RELAY | | | 1,1,LIGHT | ETHERNET | 10.20.30.50 | 12123 |
| Protocol | LightType | DcLights | DcMap | RelayConf | PreferredLinkType | OsgpIpAddress | OsgpPort | DhcpEnabled | TestButtonEnabled |
| OSLP ELSTER | RELAY | | | | | 10.20.30.40 | 12122 | false | false |
| OSLP ELSTER | RELAY | | | 1,1,LIGHT | | 10.20.30.40 | 12122 | false | true |
| OSLP ELSTER | ONE_TO_TEN_VOLT | | | | | 10.20.30.40 | 12122 | true | false |
| OSLP ELSTER | ONE_TO_TEN_VOLT_REVERSE | | | | | 10.20.30.40 | 12123 | true | true |
| OSLP ELSTER | DALI | 2 | 1,2;2,1 | | | 10.20.30.40 | 12123 | false | false |
| OSLP ELSTER | | | | | | 10.20.30.40 | 12123 | false | true |
| OSLP ELSTER | | | | | GPRS | 10.20.30.50 | 12122 | true | false |
| OSLP ELSTER | DALI | | | | | 10.20.30.50 | 12122 | true | true |
| OSLP ELSTER | | | | | | 10.20.30.50 | 12122 | false | false |
| OSLP ELSTER | | | | | | 10.20.30.50 | 12123 | false | true |
| OSLP ELSTER | RELAY | | | 1,1,LIGHT | CDMA | 10.20.30.50 | 12123 | true | false |
| OSLP ELSTER | RELAY | | | 1,1,LIGHT | ETHERNET | 10.20.30.50 | 12123 | true | true |

Scenario: Get configuration data with unknown device
When receiving a get configuration request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,7 @@ public class PlatformDefaults {
public static final String DEFAULT_LMD_CODE = "LmdCode";
public static final String DEFAULT_LMD_COLOR = "LmdColor";
public static final Short DEFAULT_LMD_DIGITAL_INPUT = 1;

public static Boolean DEFAULT_DHCP_ENABLED = false;
public static Boolean DEFAULT_TEST_BUTTON_ENABLED = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,7 @@ public class PlatformKeys extends Keys {
public static final String KEY_LMD_CODE = "LmdCode";
public static final String KEY_LMD_COLOR = "LmdColor";
public static final String KEY_LMD_DIGITAL_INPUT = "LmdDigitalInput";

public static final String KEY_DHCP_ENABLED = "DhcpEnabled";
public static final String KEY_TEST_BUTTON_ENABLED = "TestButtonEnabled";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.opensmartgridplatform.adapter.ws.core.application.mapping;

import javax.xml.datatype.XMLGregorianCalendar;

import org.joda.time.DateTime;
import org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.Configuration;
import org.opensmartgridplatform.domain.core.valueobjects.DaliConfiguration;
Expand All @@ -16,16 +18,21 @@
import org.opensmartgridplatform.domain.core.valueobjects.RelayConfiguration;
import org.opensmartgridplatform.domain.core.valueobjects.RelayMatrix;

import ma.glasnost.orika.CustomConverter;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;

public class ConfigurationConverter
extends CustomConverter<Configuration, org.opensmartgridplatform.domain.core.valueobjects.Configuration> {
public class ConfigurationConverter extends
BidirectionalConverter<Configuration, org.opensmartgridplatform.domain.core.valueobjects.Configuration> {

@Override
public org.opensmartgridplatform.domain.core.valueobjects.Configuration convert(final Configuration source,
final Type<? extends org.opensmartgridplatform.domain.core.valueobjects.Configuration> destinationType,
public org.opensmartgridplatform.domain.core.valueobjects.Configuration convertTo(final Configuration source,
final Type<org.opensmartgridplatform.domain.core.valueobjects.Configuration> destinationType,
final MappingContext mappingContext) {
if (source == null) {
return null;
}

return new org.opensmartgridplatform.domain.core.valueobjects.Configuration.Builder()
.withLightType(this.mapperFacade.map(source.getLightType(), LightType.class))
.withDaliConfiguration(this.mapperFacade.map(source.getDaliConfiguration(), DaliConfiguration.class))
Expand Down Expand Up @@ -54,4 +61,46 @@ public org.opensmartgridplatform.domain.core.valueobjects.Configuration convert(
.withWinterTimeDetails(this.mapperFacade.map(source.getWinterTimeDetails(), DateTime.class))
.build();
}

@Override
public Configuration convertFrom(final org.opensmartgridplatform.domain.core.valueobjects.Configuration source,
final Type<Configuration> destinationType, final MappingContext mappingContext) {
if (source == null) {
return null;
}
final Configuration dest = new Configuration();
dest.setLightType(this.mapperFacade.map(source.getLightType(),
org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.LightType.class));
dest.setDaliConfiguration(this.mapperFacade.map(source.getDaliConfiguration(),
org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.DaliConfiguration.class));
dest.setRelayConfiguration(this.mapperFacade.map(source.getRelayConfiguration(),
org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.RelayConfiguration.class));
dest.setPreferredLinkType(this.mapperFacade.map(source.getPreferredLinkType(),
org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.LinkType.class));
dest.setTimeSyncFrequency(source.getTimeSyncFrequency());
dest.setDeviceFixedIp(this.mapperFacade.map(source.getDeviceFixedIp(),
org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.DeviceFixedIp.class));
dest.setDhcpEnabled(source.isDhcpEnabled());
dest.setCommunicationTimeout(source.getCommunicationTimeout());
dest.setCommunicationNumberOfRetries(source.getCommunicationNumberOfRetries());
dest.setCommunicationPauseTimeBetweenConnectionTrials(
source.getCommunicationPauseTimeBetweenConnectionTrials());
dest.setOsgpIpAddress(source.getOsgpIpAddress());
dest.setOsgpPortNumber(source.getOsgpPortNumber());
dest.setNtpHost(source.getNtpHost());
dest.setNtpEnabled(source.getNtpEnabled());
dest.setNtpSyncInterval(source.getNtpSyncInterval());
dest.setTestButtonEnabled(source.isTestButtonEnabled());
dest.setAutomaticSummerTimingEnabled(source.isAutomaticSummerTimingEnabled());
dest.setAstroGateSunRiseOffset(source.getAstroGateSunRiseOffset());
dest.setAstroGateSunSetOffset(source.getAstroGateSunSetOffset());
dest.getSwitchingDelays().addAll(source.getSwitchingDelays());
dest.getRelayLinking()
.addAll(this.mapperFacade.mapAsList(source.getRelayLinking(),
org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.RelayMatrix.class));
dest.setRelayRefreshing(source.isRelayRefreshing());
dest.setSummerTimeDetails(this.mapperFacade.map(source.getSummerTimeDetails(), XMLGregorianCalendar.class));
dest.setWinterTimeDetails(this.mapperFacade.map(source.getWinterTimeDetails(), XMLGregorianCalendar.class));
return dest;
}
}