BundleService { public String enqueueBundleRequest(final String organisationIdentification, final String deviceIdentification, final List<ActionRequest> actionList, final int messagePriority, final boolean bypassRetry) throws FunctionalException { final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification); final Device device = this.domainHelperService.findActiveDevice(deviceIdentification); LOGGER.info("Bundle request called with organisation {}", organisationIdentification); this.checkIfBundleIsAllowed(actionList, organisation, device); final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification); final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceIdentification, organisationIdentification, correlationUid, MessageType.HANDLE_BUNDLED_ACTIONS.name(), messagePriority); deviceMessageMetadata.setBypassRetry(bypassRetry); final SmartMeteringRequestMessage message = new SmartMeteringRequestMessage.Builder() .deviceMessageMetadata(deviceMessageMetadata).request(new BundleMessageRequest(actionList)).build(); this.smartMeteringRequestMessageSender.send(message); return correlationUid; } BundleService(); String enqueueBundleRequest(final String organisationIdentification, final String deviceIdentification,
            final List<ActionRequest> actionList, final int messagePriority, final boolean bypassRetry);  }
@Test public void testAllOperationsAreAllowed() throws FunctionalException { this.bundleService.enqueueBundleRequest(ORGANISATION_IDENTIFICATION, DEVICE_IDENTIFICATION, this.actionRequestMockList, MESSAGE_PRIORITY, BYPASS_RETRY); final ArgumentCaptor<SmartMeteringRequestMessage> message = ArgumentCaptor .forClass(SmartMeteringRequestMessage.class); verify(this.smartMeteringRequestMessageSender).send(message.capture()); assertEquals(message.getValue().getOrganisationIdentification(), ORGANISATION_IDENTIFICATION); assertEquals(message.getValue().getDeviceIdentification(), DEVICE_IDENTIFICATION); final BundleMessageRequest requestMessage = (BundleMessageRequest) message.getValue().getRequest(); final List<ActionRequest> actionList = requestMessage.getBundleList(); assertEquals(actionList.size(), this.actionRequestMockList.size()); for (int i = 0; i < actionList.size(); i++) { assertEquals(this.actionRequestMockList.get(i), actionList.get(i)); } }
@Test public void testExceptionWhenOperationNotAllowed() throws FunctionalException { final FunctionalException fe = new FunctionalException(FunctionalExceptionType.UNAUTHORIZED, ComponentType.WS_SMART_METERING); doThrow(fe).when(this.domainHelperService).isAllowed(this.organisation, this.device, DeviceFunction.REQUEST_PERIODIC_METER_DATA); try { this.bundleService.enqueueBundleRequest(ORGANISATION_IDENTIFICATION, DEVICE_IDENTIFICATION, this.actionRequestMockList, MESSAGE_PRIORITY, BYPASS_RETRY); fail(); } catch (final FunctionalException e) { assertEquals(fe, e); } }
@Test public void testExceptionWhenBundleIsNotAllowed() throws FunctionalException { final FunctionalException fe = new FunctionalException(FunctionalExceptionType.UNAUTHORIZED, ComponentType.WS_SMART_METERING); doThrow(fe).when(this.domainHelperService).isAllowed(this.organisation, this.device, DeviceFunction.HANDLE_BUNDLED_ACTIONS); try { this.bundleService.enqueueBundleRequest(ORGANISATION_IDENTIFICATION, DEVICE_IDENTIFICATION, this.actionRequestMockList, MESSAGE_PRIORITY, BYPASS_RETRY); } catch (final FunctionalException e) { assertEquals(fe, e); } }