Skip to content

Commit

Permalink
SMHE-2412: Fix unit test for GetPeriodicMeterReadsCommandExecutor wit…
Browse files Browse the repository at this point in the history
…h objectconfig

Signed-off-by: stefanermens <[email protected]>
  • Loading branch information
stefanermens committed Dec 9, 2024
1 parent f73760b commit 32787c4
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package org.opensmartgridplatform.dlms.objectconfig.dlmsclasses;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.opensmartgridplatform.dlms.interfaceclass.attribute.RegisterAttribute;
Expand Down Expand Up @@ -52,4 +55,45 @@ public String getScalerUnit() {

return scalerUnitAttribute.getValue();
}

@Override
public Register copy() {
return new Register(
this.tag,
this.description,
this.classId,
this.version,
this.obis,
this.group,
this.note,
new ArrayList<>(this.meterTypes),
this.properties == null || this.properties.isEmpty()
? null
: new EnumMap<>(this.properties),
this.attributes.stream().map(Attribute::copy).toList());
}

@Override
public Register copyWithNewObis(final String newObis) {
final Register newRegister = this.copy();
newRegister.obis = newObis;
return newRegister;
}

@Override
public Register copyWithNewAttribute(final Attribute newAttribute) {
final Register newRegister = this.copy();

// Remove attribute with same id as newAttribute
final List<Attribute> copiedAttributes =
newRegister.attributes.stream()
.filter(attr -> attr.getId() != newAttribute.getId())
.collect(Collectors.toList());
copiedAttributes.add(newAttribute);

// Add new attribute
newRegister.attributes = copiedAttributes;

return newRegister;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ protected List<MeterReadsResponseWithLogTimeDto> getPeriodicMeterReads(
.setDescription(
String.format(
this.config.getFormatDescription(),
periodicMeterReadsQuery.getChannel(),
queryPeriodType,
from,
to,
JdlmsObjectToStringUtil.describeAttributes(profileBufferAddress)));
JdlmsObjectToStringUtil.describeAttributes(profileBufferAddress),
periodicMeterReadsQuery.getChannel()));

// This is the actual request to the meter. The DlmsHelper will automatically check if the
// result is SUCCESS. Otherwise, it will throw an exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class GetPeriodicMeterReadsCommandExecutor
extends AbstractPeriodicMeterReadsCommandExecutor<
PeriodicMeterReadsRequestDto, PeriodicMeterReadsResponseDto> {

private static final String ELECTRICITY_VALUE = "eletricityValue";
private static final String ELECTRICITY_VALUE = "electricityValue";
private static final String PERIODIC_E_METER_READS = "Periodic E-Meter Reads";
private static final String FORMAT_DESCRIPTION =
"GetPeriodicMeterReads %s from %s until %s, retrieve attribute: " + "%s";
Expand Down Expand Up @@ -149,9 +149,9 @@ protected MeterReadsResponseWithLogTimeDto convertToResponseItem(
logTime = this.readClock(periodType, previousLogTime, intervalTime, bufferedObject);
}
case AMR_PROFILE_STATUS,
AMR_PROFILE_STATUS_15MIN_E,
AMR_PROFILE_STATUS_DAILY_E,
AMR_PROFILE_STATUS_MONTHLY_E ->
AMR_PROFILE_STATUS_15MIN_E,
AMR_PROFILE_STATUS_DAILY_E,
AMR_PROFILE_STATUS_MONTHLY_E ->
// The status is used in most profiles. But for some it is not used. In that case, the
// selectedObjects will not contain a status object and readStatus will return null.
status = this.readAmrProfileStatusCode(bufferedObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class GetPeriodicMeterReadsGasCommandExecutor
private static final String UNEXPECTED_VALUE =
"Unexpected null/unspecified value for Gas Capture Time";
private static final String FORMAT_DESCRIPTION =
"GetPeriodicMeterReadsGas for channel %s, %s from %s until %s, " + "retrieve attribute: %s";
"GetPeriodicMeterReadsGas %s from %s until %s, " + "retrieve attribute: %s, channel %s";

private static final PeriodicMeterReadsConfig CONFIG =
new PeriodicMeterReadsConfig(
Expand Down Expand Up @@ -151,9 +151,9 @@ protected MeterReadsResponseWithLogTimeDto convertToResponseItem(
logTime = this.readClock(periodType, previousLogTime, intervalTime, bufferedObject);
}
case AMR_PROFILE_STATUS,
AMR_PROFILE_STATUS_HOURLY_G,
AMR_PROFILE_STATUS_DAILY_G,
AMR_PROFILE_STATUS_MONTHLY_G ->
AMR_PROFILE_STATUS_HOURLY_G,
AMR_PROFILE_STATUS_DAILY_G,
AMR_PROFILE_STATUS_MONTHLY_G ->
// The status is used in most profiles. But for some it is not used. In that case, the
// selectedObjects will not contain a status object and readStatus will return null.
status = this.readAmrProfileStatusCode(bufferedObject);
Expand Down
Loading

0 comments on commit 32787c4

Please sign in to comment.