use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata 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.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class ScheduledTaskExecutorService method createProtocolRequestMessage.
private ProtocolRequestMessage createProtocolRequestMessage(final ScheduledTask scheduledTask) {
final Device device = this.deviceRepository.findByDeviceIdentification(scheduledTask.getDeviceIdentification());
final MessageMetadata messageMetadata = messageMetadataFromScheduledTaskForDevice(scheduledTask, device);
return ProtocolRequestMessage.newBuilder().messageMetadata(messageMetadata).request(scheduledTask.getMessageData()).build();
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class ScheduleManagementService method enqueueSetTariffSchedule.
public String enqueueSetTariffSchedule(@Identification final String organisationIdentification, @Identification final String deviceIdentification, @NotNull @Size(min = 1, max = 50) @Valid final List<ScheduleEntry> mapAsList, final DateTime scheduledTime, final int messagePriority) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
this.domainHelperService.isAllowed(organisation, device, DeviceFunction.SET_TARIFF_SCHEDULE);
this.domainHelperService.isInMaintenance(device);
LOGGER.debug("enqueueSetTariffSchedule called with organisation {} and device {}", organisationIdentification, deviceIdentification);
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
final Schedule schedule = new Schedule(mapAsList);
final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.SET_TARIFF_SCHEDULE.name()).withMessagePriority(messagePriority).withScheduleTime(scheduledTime == null ? null : scheduledTime.getMillis()).build();
final TariffSwitchingRequestMessage message = new TariffSwitchingRequestMessage.Builder().messageMetadata(deviceMessageMetadata).request(schedule).build();
this.tariffSwitchingRequestMessageSender.send(message);
return correlationUid;
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutorIntegrationTest method testExecute.
private void testExecute(final Protocol protocol, final PeriodTypeDto type, final boolean useNullData) throws Exception {
// SETUP
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
// Reset stub
this.connectionStub.clearRequestedAttributeAddresses();
// Create device with requested protocol version
final DlmsDevice device = this.createDlmsDevice(protocol);
// Create request object
final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(type, this.timeFrom, this.timeTo);
// Get expected values
final AttributeAddress expectedAddressProfile = this.createAttributeAddress(protocol, type, this.timeFrom, this.timeTo);
final List<AttributeAddress> expectedScalerUnitAddresses = this.getScalerUnitAttributeAddresses(type);
final int expectedTotalNumberOfAttributeAddresses = expectedScalerUnitAddresses.size() + 1;
// Set response in stub
this.setResponseForProfile(expectedAddressProfile, protocol, type, useNullData);
this.setResponsesForScalerUnit(expectedScalerUnitAddresses);
// CALL
final PeriodicMeterReadsResponseDto response = this.executor.execute(this.connectionManagerStub, device, request, messageMetadata);
// VERIFY
// Get resulting requests from connection stub
final List<AttributeAddress> requestedAttributeAddresses = this.connectionStub.getRequestedAttributeAddresses();
assertThat(requestedAttributeAddresses.size()).isEqualTo(expectedTotalNumberOfAttributeAddresses);
// There should be 1 request to the buffer (id = 2) of a profile
// (class-id = 7)
final AttributeAddress actualAttributeAddressProfile = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_PROFILE).collect(Collectors.toList()).get(0);
AttributeAddressAssert.is(actualAttributeAddressProfile, expectedAddressProfile);
// Check the amount of requests to the scaler_units of the meter values
// in the registers
final List<AttributeAddress> attributeAddressesScalerUnit = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_REGISTER && a.getId() == this.ATTR_ID_SCALER_UNIT).collect(Collectors.toList());
assertThat(attributeAddressesScalerUnit.size()).isEqualTo(expectedScalerUnitAddresses.size());
// Check response
assertThat(response.getPeriodType()).isEqualTo(type);
final List<PeriodicMeterReadsResponseItemDto> periodicMeterReads = response.getPeriodicMeterReads();
assertThat(periodicMeterReads.size()).isEqualTo(this.AMOUNT_OF_PERIODS);
this.checkClockValues(periodicMeterReads, type, useNullData);
this.checkValues(periodicMeterReads, type);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceByChannelCommandExecutorTest method testHappyFlow.
@Test
public void testHappyFlow() throws ProtocolAdapterException {
final short channel = (short) 1;
final Short primaryAddress = 9;
final String manufacturerIdentification = "manufacturerIdentification";
final short version = 123;
final short deviceTypeIdentification = 456;
final String identificationNumber = "identificationNumber";
final ChannelElementValuesDto dto = new ChannelElementValuesDto(channel, primaryAddress, identificationNumber, manufacturerIdentification, version, deviceTypeIdentification);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
when(this.coupleMbusDeviceByChannelRequestDataDto.getChannel()).thenReturn(channel);
when(this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, channel)).thenReturn(dto);
final CoupleMbusDeviceByChannelResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, this.coupleMbusDeviceByChannelRequestDataDto, messageMetadata);
assertThat(responseDto).isNotNull();
assertThat(responseDto.getChannelElementValues()).isNotNull();
assertThat(responseDto.getChannelElementValues().getChannel()).isEqualTo(channel);
assertThat(responseDto.getChannelElementValues().getDeviceTypeIdentification()).isEqualTo(deviceTypeIdentification);
assertThat(responseDto.getChannelElementValues().getIdentificationNumber()).isEqualTo(identificationNumber);
assertThat(responseDto.getChannelElementValues().getManufacturerIdentification()).isEqualTo(manufacturerIdentification);
assertThat(responseDto.getChannelElementValues().getPrimaryAddress()).isEqualTo(primaryAddress);
assertThat(responseDto.getChannelElementValues().getVersion()).isEqualTo(version);
verify(this.deviceChannelsHelper, times(1)).getChannelElementValues(eq(this.conn), eq(this.device), any(Short.class));
}
Aggregations