Skip to content

Commit

Permalink
SMHE-2164: Add cucumber test for Set specific attribute value
Browse files Browse the repository at this point in the history
Signed-off-by: stefanermens <[email protected]>
  • Loading branch information
stefanermens committed Feb 14, 2025
1 parent f4418ba commit 1b123ec
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,7 @@ public class PlatformSmartmeteringKeys
public static final String PUSH_OBJECT_OBIS_CODES = "PushObjectObisCodes";
public static final String PUSH_OBJECT_ATTRIBUTE_IDS = "PushObjectAttributeIds";
public static final String PUSH_OBJECT_DATA_INDEXES = "PushObjectDataIndexes";

public static final String OBJECT_TYPE = "ObjectType";
public static final String INT_VALUE = "IntValue";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0

package org.opensmartgridplatform.cucumber.platform.smartmetering.glue.steps.ws.smartmetering.smartmeteringadhoc;

import static org.assertj.core.api.Assertions.assertThat;

import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.util.Map;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncRequest;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncResponse;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueRequest;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueResponse;
import org.opensmartgridplatform.cucumber.core.ScenarioContext;
import org.opensmartgridplatform.cucumber.platform.PlatformKeys;
import org.opensmartgridplatform.cucumber.platform.smartmetering.PlatformSmartmeteringKeys;
import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc.SetSpecificAttributeValueRequestFactory;
import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc.SmartMeteringAdHocRequestClient;
import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc.SmartMeteringAdHocResponseClient;
import org.springframework.beans.factory.annotation.Autowired;

public class SetSpecificAttributeValue {

@Autowired
private SmartMeteringAdHocRequestClient<
SetSpecificAttributeValueAsyncResponse, SetSpecificAttributeValueRequest>
requestClient;

@Autowired
private SmartMeteringAdHocResponseClient<
SetSpecificAttributeValueResponse, SetSpecificAttributeValueAsyncRequest>
responseClient;

@When("^the Set Specific Attribute value request is received$")
public void whenTheSetSpecificAttributeValueRequestIsReceived(final Map<String, String> settings)
throws Throwable {

final SetSpecificAttributeValueRequest request =
SetSpecificAttributeValueRequestFactory.fromParameterMap(settings);
final SetSpecificAttributeValueAsyncResponse asyncResponse =
this.requestClient.doRequest(request);

assertThat(asyncResponse).as("AsyncResponse should not be null").isNotNull();
ScenarioContext.current()
.put(PlatformKeys.KEY_CORRELATION_UID, asyncResponse.getCorrelationUid());
}

@Then("^the Set Specific Attribute value response should be returned$")
public void thenTheValueShouldBeSetOnTheDevice(final Map<String, String> settings)
throws Throwable {

final SetSpecificAttributeValueAsyncRequest asyncRequest =
SetSpecificAttributeValueRequestFactory.fromScenarioContext();
final SetSpecificAttributeValueResponse response =
this.responseClient.getResponse(asyncRequest);

assertThat(response.getResult().name())
.as("Result is not as expected.")
.isEqualTo(settings.get(PlatformSmartmeteringKeys.RESULT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0

package org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc;

import java.math.BigInteger;
import java.util.Map;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ObjectType;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncRequest;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueRequest;
import org.opensmartgridplatform.cucumber.platform.smartmetering.PlatformSmartmeteringKeys;
import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.RequestFactoryHelper;

public class SetSpecificAttributeValueRequestFactory {

private SetSpecificAttributeValueRequestFactory() {
// Private constructor for utility class
}

public static SetSpecificAttributeValueRequest fromParameterMap(
final Map<String, String> parameters) {
final SetSpecificAttributeValueRequest request = new SetSpecificAttributeValueRequest();
request.setDeviceIdentification(
parameters.get(PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION));
request.setObjectType(
ObjectType.valueOf(parameters.get(PlatformSmartmeteringKeys.OBJECT_TYPE)));
request.setAttribute(new BigInteger(parameters.get(PlatformSmartmeteringKeys.ATTRIBUTE)));
request.setIntValue(new BigInteger(parameters.get(PlatformSmartmeteringKeys.INT_VALUE)));
return request;
}

public static SetSpecificAttributeValueAsyncRequest fromScenarioContext() {
final SetSpecificAttributeValueAsyncRequest asyncRequest =
new SetSpecificAttributeValueAsyncRequest();
asyncRequest.setCorrelationUid(RequestFactoryHelper.getCorrelationUidFromScenarioContext());
asyncRequest.setDeviceIdentification(
RequestFactoryHelper.getDeviceIdentificationFromScenarioContext());
return asyncRequest;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: Contributors to the GXF project
#
# SPDX-License-Identifier: Apache-2.0

@SmartMetering @Platform @SmartMeteringAdHoc
Feature: SmartMetering AdHoc
As a grid operator
I want to be able to set a specific attribute value in a device
So I can change the configuration of a device

Scenario Outline: Set watchdog timer for a <protocol> <version> device
Given a dlms device
| DeviceIdentification | <deviceIdentification> |
| DeviceType | SMART_METER_E |
| Protocol | <protocol> |
| ProtocolVersion | <version> |
When the Set Specific Attribute value request is received
| DeviceIdentification | <deviceIdentification> |
| ObjectType | WATCHDOG_TIMER |
| Attribute | 2 |
| IntValue | 42 |
Then the Set Specific Attribute value response should be returned
| DeviceIdentification | <deviceIdentification> |
| Result | <response> |

Examples:
| deviceIdentification | protocol | version | response |
| TEST1024000000001 | DSMR | 4.2.2 | OK |
@NightlyBuildOnly
Examples:
| deviceIdentification | protocol | version | response |
| TEST1024000000001 | DSMR | 2.2 | NOT_OK |
| TEST1031000000001 | SMR | 4.3 | OK |
| TEST1027000000001 | SMR | 5.0.0 | OK |
| TEST1028000000001 | SMR | 5.1 | OK |
| TEST1029000000001 | SMR | 5.2 | OK |
| TEST1030000000001 | SMR | 5.5 | OK |
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void setSpecificAttributeValue(

final SetSpecificAttributeValueRequestDto requestDto =
new SetSpecificAttributeValueRequestDto(
request.getDlmsObjectTag(), request.getAttributeId(), request.getIntValue());
request.getObjectType(), request.getAttribute(), request.getIntValue());

this.osgpCoreRequestMessageSender.send(
requestDto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public SetSpecificAttributeValueResponseMessageProcessor(

@Override
protected boolean hasRegularResponseObject(final ResponseMessage responseMessage) {
return responseMessage.getDataObject() instanceof String;
// Only the Result (OK/NOK/Exception) is returned, no need to check the (contents of the
// dataObject).
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public class ActionMapperService {
CLASS_MAP.put(
org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc
.SetSpecificAttributeValueRequestData.class,
SpecificAttributeValueRequestData.class);
SetSpecificAttributeValueRequestData.class);
CLASS_MAP.put(
org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration
.SetClockConfigurationRequestData.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,19 @@ public SetSpecificAttributeValueAsyncResponse setSpecificAttributeValue(
throws OsgpException {

final org.opensmartgridplatform.domain.core.valueobjects.smartmetering
.SpecificAttributeValueRequest
.SetSpecificAttributeValueRequest
setSpecificAttributeValueRequest =
this.adhocMapper.map(
request,
org.opensmartgridplatform.domain.core.valueobjects.smartmetering
.SpecificAttributeValueRequest.class);
.SetSpecificAttributeValueRequest.class);

final RequestMessageMetadata requestMessageMetadata =
RequestMessageMetadata.newBuilder()
.withOrganisationIdentification(organisationIdentification)
.withDeviceIdentification(request.getDeviceIdentification())
.withDeviceFunction(DeviceFunction.GET_SPECIFIC_ATTRIBUTE_VALUE)
.withMessageType(MessageType.GET_SPECIFIC_ATTRIBUTE_VALUE)
.withDeviceFunction(DeviceFunction.SET_SPECIFIC_ATTRIBUTE_VALUE)
.withMessageType(MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE)
.withMessagePriority(messagePriority)
.withScheduleTime(scheduleTime)
.withBypassRetry(bypassRetry)
Expand Down Expand Up @@ -382,21 +382,6 @@ public SetSpecificAttributeValueResponse setSpecificAttributeValueResponse(
request.getCorrelationUid(), ComponentType.WS_SMART_METERING);

response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
if (ResponseMessageResultType.OK == responseData.getResultType()) {
response.setAttributeValueData((String) responseData.getMessageData());
} else if (responseData.getMessageData() instanceof OsgpException) {
throw (OsgpException) responseData.getMessageData();
} else if (responseData.getMessageData() instanceof Exception) {
throw new TechnicalException(
ComponentType.WS_SMART_METERING,
"An exception occurred: Set specific attribute value",
(Exception) responseData.getMessageData());
} else {
throw new TechnicalException(
ComponentType.WS_SMART_METERING,
"An exception occurred: Set specific attribute value",
null);
}
} catch (final Exception e) {
this.handleException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class SetSpecificAttributeValueRequest extends SetSpecificAttributeValueR
private final String deviceIdentification;

public SetSpecificAttributeValueRequest(
final String dlmsObjectTag,
final int attributeId,
final String objectType,
final int attribute,
final int intValue,
final String deviceIdentification) {
super(dlmsObjectTag, attributeId, intValue);
super(objectType, attribute, intValue);
this.deviceIdentification = deviceIdentification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ public class SetSpecificAttributeValueRequestData implements Serializable, Actio

private static final long serialVersionUID = -7326169764207317011L;

private final String dlmsObjectTag;
private final int attributeId;
private final String objectType;
private final int attribute;
private final int intValue;

public SetSpecificAttributeValueRequestData(
final String dlmsObjectType, final int attributeId, final int intValue) {
final String objectType, final int attribute, final int intValue) {
super();
this.dlmsObjectTag = dlmsObjectType;
this.attributeId = attributeId;
this.objectType = objectType;
this.attribute = attribute;
this.intValue = intValue;
}

public String getDlmsObjectTag() {
return this.dlmsObjectTag;
public String getObjectType() {
return this.objectType;
}

public int getAttributeId() {
return this.attributeId;
public int getAttribute() {
return this.attribute;
}

public int getIntValue() {
Expand All @@ -45,9 +45,9 @@ public void validate() throws FunctionalException {
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.attributeId;
result = (prime * result) + this.attribute;
result = (prime * result) + this.intValue;
result = (prime * result) + this.dlmsObjectTag.hashCode();
result = (prime * result) + this.objectType.hashCode();
return result;
}

Expand All @@ -63,17 +63,17 @@ public boolean equals(final Object obj) {
return false;
}
final SetSpecificAttributeValueRequestData other = (SetSpecificAttributeValueRequestData) obj;
if (this.attributeId != other.attributeId) {
if (this.attribute != other.attribute) {
return false;
}
if (this.intValue != other.intValue) {
return false;
}
if (this.dlmsObjectTag == null) {
if (other.dlmsObjectTag != null) {
if (this.objectType == null) {
if (other.objectType != null) {
return false;
}
} else if (!this.dlmsObjectTag.equals(other.dlmsObjectTag)) {
} else if (!this.objectType.equals(other.objectType)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Void execute(
final MessageMetadata messageMetadata)
throws FunctionalException, ProtocolAdapterException {

final DlmsObjectType objectType = DlmsObjectType.valueOf(requestData.getDlmsObjectTag());
final DlmsObjectType objectType = DlmsObjectType.valueOf(requestData.getObjectType());
final CosemObject cosemObject;
try {
cosemObject =
Expand All @@ -67,7 +67,7 @@ public Void execute(
throw new ProtocolAdapterException(AbstractCommandExecutor.ERROR_IN_OBJECT_CONFIG, e);
}

final Attribute attribute = cosemObject.getAttribute(requestData.getAttributeId());
final Attribute attribute = cosemObject.getAttribute(requestData.getAttribute());

final DlmsDataType dataType = attribute.getDatatype();

Expand All @@ -90,22 +90,22 @@ public Void execute(
new AttributeAddress(
cosemObject.getClassId(),
new ObisCode(cosemObject.getObis()),
requestData.getAttributeId());
requestData.getAttribute());
final SetParameter setParameter = new SetParameter(attributeAddress, data);

log.debug(
"Set specific attribute value, class id: {}, obis code: {}, attribute id: {}, value: {}",
cosemObject.getClassId(),
cosemObject.getObis(),
requestData.getAttributeId(),
requestData.getAttribute(),
requestData.getIntValue());

final List<AccessResultCode> resultCodes =
this.dlmsHelper.setWithList(conn, device, List.of(setParameter));

if (!resultCodes.stream().allMatch(code -> code.equals(AccessResultCode.SUCCESS))) {
log.debug("Result of THD configuration is {}", resultCodes);
throw new ProtocolAdapterException("THD configuration resulted in: " + resultCodes);
log.debug("Result of Set specific value is {}", resultCodes);
throw new ProtocolAdapterException("Set specific value resulted in: " + resultCodes);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException;
import org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DeviceRequestMessageProcessor;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecificAttributeValueRequestDto;
import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException;
import org.opensmartgridplatform.shared.infra.jms.MessageMetadata;
import org.opensmartgridplatform.shared.infra.jms.MessageType;
Expand All @@ -24,7 +23,7 @@ public class SetSpecificAttributeValueRequestMessageProcessor
private final AdhocService adhocService;

protected SetSpecificAttributeValueRequestMessageProcessor(final AdhocService adhocService) {
super(MessageType.GET_SPECIFIC_ATTRIBUTE_VALUE);
super(MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE);
this.adhocService = adhocService;
}

Expand All @@ -36,7 +35,7 @@ protected Serializable handleMessage(
final MessageMetadata messageMetadata)
throws ProtocolAdapterException, FunctionalException {

this.assertRequestObjectType(SpecificAttributeValueRequestDto.class, requestObject);
this.assertRequestObjectType(SetSpecificAttributeValueRequestDto.class, requestObject);

final SetSpecificAttributeValueRequestDto request =
(SetSpecificAttributeValueRequestDto) requestObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic;
import org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.AdjacentCellInfo;
import org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.CellInfo;
import org.opensmartgridplatform.simulator.protocol.dlms.cosem.LongUnsignedData;
import org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusDailyBillingValuesPeriod1SMR5;
import org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusDriverActiveFirmwareIdentifier;
import org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusDriverActiveFirmwareSignature;
Expand Down Expand Up @@ -712,4 +713,10 @@ public GsmDiagnostic gsmGprsDiagnostic() {
adjacentCellInfos,
captureTime);
}

@Bean
public LongUnsignedData watchdogTimer() {
final String obisCode = "0.1.94.31.2.255";
return new LongUnsignedData(obisCode, 72); // Default timer is 72 hours
}
}
Loading

0 comments on commit 1b123ec

Please sign in to comment.