Search in sources :

Example 1 with CosemObjectDefinition

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition in project open-smart-grid-platform by OSGP.

the class PushSetupSmsMappingTest method testPushSetupSmsMappingWithLists.

// To test Mapping if lists contain values
@Test
public void testPushSetupSmsMappingWithLists() {
    // build test data
    final CosemObisCode logicalName = new CosemObisCode(new int[] { 1, 2, 3, 4, 5, 6 });
    final CosemObjectDefinition cosemObjectDefinition = new CosemObjectDefinition(1, logicalName, 2);
    final CosemDateTime startTime = new CosemDateTime(new CosemDate(2016, 3, 17), new CosemTime(11, 52, 45), 0, new ClockStatus(ClockStatus.STATUS_NOT_SPECIFIED));
    final CosemDateTime endTime = new CosemDateTime(new CosemDate(2016, 3, 17), new CosemTime(11, 52, 45), 0, new ClockStatus(ClockStatus.STATUS_NOT_SPECIFIED));
    final WindowElement windowElement = new WindowElement(startTime, endTime);
    final PushSetupSms pushSetupSms = new PushSetupSmsBuilder().withFilledLists(cosemObjectDefinition, windowElement).build();
    // actual mapping
    final PushSetupSmsDto pushSetupSmsDto = this.configurationMapper.map(pushSetupSms, PushSetupSmsDto.class);
    // check values
    this.checkCosemObisCodeMapping(pushSetupSms.getLogicalName(), pushSetupSmsDto.getLogicalName());
    this.checkSendDestinationAndMethodMapping(pushSetupSms, pushSetupSmsDto);
    this.checkIntegerMapping(pushSetupSms, pushSetupSmsDto);
    this.checkNonEmptyListMapping(pushSetupSms, pushSetupSmsDto);
}
Also used : WindowElement(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WindowElement) CosemObisCode(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObisCode) ClockStatus(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus) PushSetupSms(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupSms) CosemTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime) CosemObjectDefinition(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition) CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) PushSetupSmsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupSmsDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) Test(org.junit.jupiter.api.Test)

Example 2 with CosemObjectDefinition

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition in project open-smart-grid-platform by OSGP.

the class PushSetupAlarmMappingTest method testPushSetupAlarmMappingWithEmptyLists.

// To test if a PushSetupAlarm can be mapped if instance variables are
// initialized and lists are empty.
@Test
public void testPushSetupAlarmMappingWithEmptyLists() {
    // build test data
    final ArrayList<CosemObjectDefinition> pushObjectList = new ArrayList<>();
    final ArrayList<WindowElement> communicationWindow = new ArrayList<>();
    final PushSetupAlarm pushSetupAlarm = new PushSetupAlarmBuilder().withEmptyLists(pushObjectList, communicationWindow).build();
    // actual mapping
    final PushSetupAlarmDto pushSetupAlarmDto = this.configurationMapper.map(pushSetupAlarm, PushSetupAlarmDto.class);
    // check values
    this.checkCosemObisCodeMapping(pushSetupAlarm.getLogicalName(), pushSetupAlarmDto.getLogicalName());
    this.checkSendDestinationAndMethodMapping(pushSetupAlarm, pushSetupAlarmDto);
    this.checkIntegerMapping(pushSetupAlarm, pushSetupAlarmDto);
    assertThat(pushSetupAlarmDto.getPushObjectList()).isNotNull();
    assertThat(pushSetupAlarmDto.getCommunicationWindow()).isNotNull();
}
Also used : WindowElement(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WindowElement) PushSetupAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm) ArrayList(java.util.ArrayList) CosemObjectDefinition(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition) PushSetupAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto) Test(org.junit.jupiter.api.Test)

Example 3 with CosemObjectDefinition

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition in project open-smart-grid-platform by OSGP.

the class PushSetupAlarmDtoConverterTest method convertTest.

@Test
void convertTest() {
    final List<WindowElement> testList = Collections.singletonList(new WindowElement(new CosemDateTime(), new CosemDateTime()));
    when(this.pushSetupAlarm.getCommunicationWindow()).thenReturn(testList);
    final CosemObisCode code = new CosemObisCode(1, 2, 3, 4, 5, 6);
    when(this.pushSetupAlarm.getPushObjectList()).thenReturn(Collections.singletonList(new CosemObjectDefinition(1, code, 2)));
    final PushSetupAlarmDto result = this.pushSetupAlarmDtoConverter.convert(this.pushSetupAlarm, null, this.mappingContext);
    assertThat(result.getCommunicationWindow()).isNotNull();
    assertThat(result.getPushObjectList()).isNotNull();
}
Also used : WindowElement(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WindowElement) CosemObisCode(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObisCode) CosemObjectDefinition(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition) CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) PushSetupAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto) Test(org.junit.jupiter.api.Test)

Example 4 with CosemObjectDefinition

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition in project open-smart-grid-platform by OSGP.

the class PushSetupAlarmConverter method convertFrom.

@Override
public PushSetupAlarm convertFrom(final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm source, final Type<PushSetupAlarm> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final PushSetupAlarm.Builder builder = new PushSetupAlarm.Builder();
    if (source.getHost() != null && source.getPort() != null) {
        final String destination = source.getHost() + ":" + source.getPort();
        final SendDestinationAndMethod sendDestinationAndMethod = new SendDestinationAndMethod(TransportServiceType.TCP, destination, MessageType.A_XDR_ENCODED_X_DLMS_APDU);
        builder.withSendDestinationAndMethod(sendDestinationAndMethod);
    }
    final List<PushObject> sourcePushObjects = source.getPushObjectList();
    if (sourcePushObjects != null) {
        final List<CosemObjectDefinition> convertedPushObjectList = this.mapperFacade.mapAsList(source.getPushObjectList(), CosemObjectDefinition.class);
        builder.withPushObjectList(convertedPushObjectList);
    }
    return builder.build();
}
Also used : SendDestinationAndMethod(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod) PushSetupAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm) PushObject(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushObject) CosemObjectDefinition(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition)

Example 5 with CosemObjectDefinition

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition in project open-smart-grid-platform by OSGP.

the class PushSetupAlarmMappingTest method testPushSetupAlarmMapping.

/**
 * Tests if mapping a PushSetupAlarm object succeeds.
 */
@Test
public void testPushSetupAlarmMapping() {
    // build test data
    final PushSetupAlarm pushSetupAlarmOriginal = new PushSetupAlarm();
    pushSetupAlarmOriginal.setHost(HOST);
    pushSetupAlarmOriginal.setPort(PORT);
    pushSetupAlarmOriginal.getPushObjectList().addAll(PUSH_OBJECT_LIST);
    // actual mapping
    final org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm pushSetupAlarmMapped = this.configurationMapper.map(pushSetupAlarmOriginal, org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm.class);
    assertThat(pushSetupAlarmMapped).isNotNull();
    // port and host are combined into destination. The converter sets default values for the other
    // two variables of a SendDestinationAndMethod.
    assertThat(pushSetupAlarmMapped.getSendDestinationAndMethod().getDestination()).isEqualTo(DESTINATION);
    assertThat(pushSetupAlarmMapped.getSendDestinationAndMethod().getTransportService().name()).isEqualTo(TRANSPORTSERVICETYPE.name());
    assertThat(pushSetupAlarmMapped.getSendDestinationAndMethod().getMessage().name()).isEqualTo(MESSAGETYPE.name());
    // check mapping of PushObjectList
    assertThat(pushSetupAlarmMapped.getPushObjectList()).hasSize(1);
    final CosemObjectDefinition pushObject = pushSetupAlarmMapped.getPushObjectList().get(0);
    assertThat(pushObject.getClassId()).isEqualTo(PUSH_OBJECT_CLASS_ID);
    assertThat(pushObject.getLogicalName()).isEqualToComparingFieldByField(PUSH_OBJECT_OBIS_CODE);
    assertThat(pushObject.getAttributeIndex()).isEqualTo(PUSH_OBJECT_ATTRIBUTE_ID);
    assertThat(pushObject.getDataIndex()).isEqualTo(PUSH_OBJECT_DATA_INDEX);
    // Only SendDestinationAndMethod and PushObjectList are mapped:
    assertThat(pushSetupAlarmMapped.getLogicalName()).isNull();
    assertThat(pushSetupAlarmMapped.getCommunicationWindow()).isNull();
    assertThat(pushSetupAlarmMapped.getNumberOfRetries()).isNull();
    assertThat(pushSetupAlarmMapped.getRandomisationStartInterval()).isNull();
    assertThat(pushSetupAlarmMapped.getRepetitionDelay()).isNull();
}
Also used : PushSetupAlarm(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm) CosemObjectDefinition(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

CosemObjectDefinition (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition)9 WindowElement (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WindowElement)7 Test (org.junit.jupiter.api.Test)6 CosemDateTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime)3 CosemObisCode (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObisCode)3 PushSetupAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm)3 PushSetupAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto)3 ArrayList (java.util.ArrayList)2 ClockStatus (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus)2 CosemDate (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate)2 CosemTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime)2 PushSetupSms (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupSms)2 CosemObjectDefinitionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemObjectDefinitionDto)2 PushSetupSmsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupSmsDto)2 WindowElementDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.WindowElementDto)2 PushObject (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushObject)1 PushSetupAlarm (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm)1 SendDestinationAndMethod (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod)1