use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class SmartMeterServiceTest method testNonExistingSmartMeter.
@Test
void testNonExistingSmartMeter() {
final String deviceIdentification = "device-1";
when(this.smartMeterRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(new SmartMeter());
FunctionalException exception = Assertions.assertThrows(FunctionalException.class, () -> {
this.smartMeterService.validateSmartMeterDoesNotExist(deviceIdentification);
});
assertThat(exception.getExceptionType()).isEqualTo(FunctionalExceptionType.EXISTING_DEVICE);
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class BundleResponseMessageProcessorTest method technicalExceptionDetailsAreIncludedInFaultResponse.
@Test
public void technicalExceptionDetailsAreIncludedInFaultResponse() throws Exception {
final FunctionalExceptionType functionalException = FunctionalExceptionType.UNSUPPORTED_DEVICE_ACTION;
final ComponentType component = ComponentType.PROTOCOL_DLMS;
final String message = "java.net.ConnectException: Connection refused";
final Throwable cause = new RuntimeException(message);
final Exception exception = new FunctionalException(functionalException, component, cause);
this.parameters.add(new FaultResponseParameterDto("deviceIdentification", "ESIM9999999999999"));
final FaultResponseDto faultResponse = this.processor.faultResponseForException(exception, this.parameters, this.defaultMessage);
this.assertResponse(faultResponse, functionalException.getCode(), functionalException.name(), component.name(), cause.getClass().getName(), message, this.parameters);
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class BundleServiceTest method testExceptionWhenOperationNotAllowed.
/**
* tests that a {@link FunctionalException} is thrown when the caller is not allowed to execute
* DeviceFunction.REQUEST_PERIODIC_METER_DATA {@link ActionRequest} in the bundle
*
* @throws FunctionalException should not be thrown in this test
*/
// @Test
public void testExceptionWhenOperationNotAllowed() throws FunctionalException {
// Prepare test
final FunctionalException fe = new FunctionalException(FunctionalExceptionType.UNAUTHORIZED, ComponentType.WS_SMART_METERING);
doThrow(fe).when(this.domainHelperService).checkAllowed(this.organisation, this.device, DeviceFunction.REQUEST_PERIODIC_METER_DATA);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withOrganisationIdentification(ORGANISATION_IDENTIFICATION).withDeviceIdentification(DEVICE_IDENTIFICATION).withMessageType(MessageType.HANDLE_BUNDLED_ACTIONS.name()).withMessagePriority(MESSAGE_PRIORITY).withBypassRetry(BYPASS_RETRY).build();
// Run the test
try {
this.bundleService.enqueueBundleRequest(messageMetadata, this.actionRequestMockList);
fail();
} catch (final FunctionalException e) {
// Verify the test
assertThat(e).isEqualTo(fe);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class DetailSoapFaultMappingExceptionResolver method customizeFault.
@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
final SoapFaultDetail detail = fault.addFaultDetail();
final Result result = detail.getResult();
FunctionalException fex = null;
TechnicalException tex = null;
if (ex instanceof FunctionalException) {
fex = (FunctionalException) ex;
} else if (ex instanceof TechnicalException) {
tex = (TechnicalException) ex;
}
if (fex != null) {
try {
this.marshalFunctionalException(fex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Functional Exception", e);
}
}
if (tex != null) {
try {
this.marshalTechnicalException(tex, result);
} catch (final JAXBException e) {
LOGGER.error("Unable to marshal the Technical Exception", e);
}
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class TariffSwitchingAdHocManagementEndpoint method getDevices.
@PayloadRoot(localPart = "GetDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public GetDevicesResponse getDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetDevicesRequest request) throws OsgpException {
LOGGER.info("Get Devices Request received from organisation: {}.", organisationIdentification);
final GetDevicesResponse response = new GetDevicesResponse();
try {
final Page<Device> page = this.adHocManagementService.findAllDevices(organisationIdentification, request.getPage());
final DevicePage devicePage = new DevicePage();
devicePage.setTotalPages(page.getTotalPages());
devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(page.getContent(), org.opensmartgridplatform.adapter.ws.schema.tariffswitching.adhocmanagement.Device.class));
response.setDevicePage(devicePage);
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_TARIFF_SWITCHING, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
Aggregations