diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/functional/exceptions/FunctionalExceptionsSteps.java b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/functional/exceptions/FunctionalExceptionsSteps.java index 3ae2fd5aa53..dbd6b425473 100644 --- a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/functional/exceptions/FunctionalExceptionsSteps.java +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/functional/exceptions/FunctionalExceptionsSteps.java @@ -10,6 +10,7 @@ import io.cucumber.java.Scenario; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; +import java.util.HashMap; import java.util.Map; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.GetSpecificAttributeValueAsyncRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.GetSpecificAttributeValueAsyncResponse; @@ -238,4 +239,9 @@ public void theBundleRequestGeneratingAnErrorIsReceivedWithHeaders( ScenarioContext.current().put(PlatformKeys.RESPONSE, exception); } } + + @When("^the bundle request generating an error is received$") + public void theBundleRequestGeneratingAnErrorIsReceived() throws Throwable { + this.theBundleRequestGeneratingAnErrorIsReceivedWithHeaders(new HashMap<>()); + } } diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/bundle/BundledGetActualMeterReads.feature b/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/bundle/BundledGetActualMeterReads.feature index dc4e15c2546..d3c46cfe41c 100644 --- a/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/bundle/BundledGetActualMeterReads.feature +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/bundle/BundledGetActualMeterReads.feature @@ -94,3 +94,36 @@ Feature: SmartMetering Bundle - GetActualMeterReads | Message | VALIDATION_ERROR | | InnerMessage | Meter for gas reads should have a channel configured. | + Scenario: Get actual meter reads of a G device without a gateway device + Given a dlms device + | DeviceIdentification | TESTG102400000001 | + | DeviceType | SMART_METER_G | + | Channel | 1 | + And a bundle request + | DeviceIdentification | TESTG102400000001 | + And the bundle request contains a get actual meter reads gas action + | DeviceIdentification | TESTG102400000001 | + When the bundle request is received + When the bundle request generating an error is received + Then a SOAP fault should have been returned + | Code | 401 | + | Message | VALIDATION_ERROR | + | Component | DOMAIN_SMART_METERING | + | InnerMessage | Bundle request is not allowed for gas meter | + + Scenario: Get actual meter reads of a G device without a gateway device and bundle device is E meter + Given a dlms device + | DeviceIdentification | TEST1024000000001 | + | DeviceType | SMART_METER_E | + And a dlms device + | DeviceIdentification | TESTG102400000001 | + | DeviceType | SMART_METER_G | + | Channel | 1 | + And a bundle request + | DeviceIdentification | TEST1024000000001 | + And the bundle request contains a get actual meter reads gas action + | DeviceIdentification | TESTG102400000001 | + When the bundle request is received + Then the bundle response should contain a fault response + | Message | VALIDATION_ERROR | + | InnerMessage | Meter for gas reads should have an energy meter as gateway device. | diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/BundleService.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/BundleService.java index 16d644ae721..afd38015eb6 100644 --- a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/BundleService.java +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/BundleService.java @@ -11,6 +11,7 @@ import org.opensmartgridplatform.adapter.domain.smartmetering.application.mapping.ConfigurationMapper; import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.core.JmsMessageSender; import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.ws.WebServiceResponseMessageSender; +import org.opensmartgridplatform.domain.core.entities.Device; import org.opensmartgridplatform.domain.core.entities.SmartMeter; import org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.BundleMessageRequest; @@ -23,7 +24,9 @@ import org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionGasResponseDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionResponseDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto; +import org.opensmartgridplatform.shared.exceptionhandling.ComponentType; import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException; +import org.opensmartgridplatform.shared.exceptionhandling.FunctionalExceptionType; import org.opensmartgridplatform.shared.exceptionhandling.OsgpException; import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; import org.opensmartgridplatform.shared.infra.jms.ResponseMessage; @@ -38,7 +41,7 @@ @Service(value = "domainSmartMeteringBundleService") @Transactional(value = "transactionManager") public class BundleService { - + private static final String SMART_METER_G = "SMART_METER_G"; private static final Logger LOGGER = LoggerFactory.getLogger(BundleService.class); @Autowired @@ -83,6 +86,8 @@ public void handleBundle( final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification()); + this.checkIfBundleRequestIsAllowed(smartMeter); + final List smartMeters = this.domainHelperService.searchMBusDevicesFor(smartMeter); final String deviceModelCodes = createDeviceModelCodes(smartMeter, smartMeters); @@ -169,4 +174,17 @@ private void checkIfAdditionalActionIsNeeded( } } } + + private void checkIfBundleRequestIsAllowed(final Device smartMeter) throws FunctionalException { + if (this.isGasMeter(smartMeter.getDeviceType())) { + throw new FunctionalException( + FunctionalExceptionType.VALIDATION_ERROR, + ComponentType.DOMAIN_SMART_METERING, + new AssertionError("Bundle request is not allowed for gas meter")); + } + } + + private boolean isGasMeter(final String deviceType) { + return SMART_METER_G.equals(deviceType); + } }