Search in sources :

Example 1 with CosemDateTime

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

the class ActivityCalendarMappingTest method testNullCosemDateTime.

// Neither the CosemDateTime or List<SeasonProfile> of a ActivityCalendar
// may ever be null. Tests to make sure a NullPointerException is thrown
// when one is.
@Test
public void testNullCosemDateTime() {
    final String calendarName = "calendar";
    final CosemDateTime activePassiveCalendarTime = null;
    final List<SeasonProfile> seasonProfileList = new ArrayList<>();
    assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> {
        new ActivityCalendar(calendarName, activePassiveCalendarTime, seasonProfileList);
    });
}
Also used : ActivityCalendar(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActivityCalendar) ArrayList(java.util.ArrayList) CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) SeasonProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SeasonProfile) Test(org.junit.jupiter.api.Test)

Example 2 with CosemDateTime

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

the class ActivityCalendarMappingTest method testNullList.

// Neither the CosemDateTime or List<SeasonProfile> of a ActivityCalendar
// may ever be null. Tests to make sure a NullPointerException is thrown
// when one is.
@Test
public void testNullList() {
    final String calendarName = "calendar";
    final CosemDateTime activePassiveCalendarTime = new CosemDateTime();
    final List<SeasonProfile> seasonProfileList = null;
    assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> {
        new ActivityCalendar(calendarName, activePassiveCalendarTime, seasonProfileList);
    });
}
Also used : ActivityCalendar(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActivityCalendar) CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) SeasonProfile(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SeasonProfile) Test(org.junit.jupiter.api.Test)

Example 3 with CosemDateTime

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

the class CosemDateTimeConverterTest method deviationTest.

/**
 * Tests the mapping of the deviation property of a CosemDateTime object for positive and negative
 * values.
 */
@Test
public void deviationTest() {
    CosemDateTime cosemDateTime;
    // Test negative
    cosemDateTime = this.mapperFactory.getMapperFacade().map(COSEMDATETIME_BYTE_ARRAY_NORMAL, CosemDateTime.class);
    assertThat(cosemDateTime).isNotNull();
    assertThat(cosemDateTime.getDeviation()).isNotNull();
    assertThat((byte) (cosemDateTime.getDeviation() >> 8)).isEqualTo(FIRST_BYTE_FOR_DEVIATION);
    assertThat((byte) (cosemDateTime.getDeviation() & 0xFF)).isEqualTo(SECOND_BYTE_FOR_DEVIATION);
    // Test positive
    cosemDateTime = this.mapperFactory.getMapperFacade().map(COSEMDATETIME_BYTE_ARRAY_POSITIVE_DEVIATION, CosemDateTime.class);
    assertThat(cosemDateTime).isNotNull();
    assertThat(cosemDateTime.getDeviation()).isNotNull();
    assertThat((byte) (cosemDateTime.getDeviation() >> 8)).isEqualTo(FIRST_BYTE_FOR_POSITIVE_DEVIATION);
    assertThat((byte) (cosemDateTime.getDeviation() & 0xFF)).isEqualTo(SECOND_BYTE_FOR_POSITIVE_DEVIATION);
}
Also used : CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) Test(org.junit.jupiter.api.Test)

Example 4 with CosemDateTime

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime 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 5 with CosemDateTime

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

the class CosemDateTimeConverter method convert.

@Override
public CosemDateTime convert(final byte[] source, final Type<? extends CosemDateTime> destinationType, final MappingContext context) {
    final ByteBuffer bb = ByteBuffer.wrap(source);
    final int year = bb.getShort() & 0xFFFF;
    final int month = bb.get() & 0xFF;
    final int dayOfMonth = bb.get() & 0xFF;
    final int dayOfWeek = bb.get() & 0xFF;
    final int hour = bb.get() & 0xFF;
    final int minute = bb.get() & 0xFF;
    final int second = bb.get() & 0xFF;
    final int hundredths = bb.get() & 0xFF;
    final int deviation = bb.getShort();
    final ClockStatus clockStatus = new ClockStatus(bb.get());
    final CosemTime time = new CosemTime(hour, minute, second, hundredths);
    final CosemDate date = new CosemDate(year, month, dayOfMonth, dayOfWeek);
    return new CosemDateTime(date, time, deviation, clockStatus);
}
Also used : ClockStatus(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus) CosemTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime) CosemDateTime(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) ByteBuffer(java.nio.ByteBuffer)

Aggregations

CosemDateTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime)10 Test (org.junit.jupiter.api.Test)8 CosemDate (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate)5 CosemTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime)5 ClockStatus (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus)4 CosemObisCode (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObisCode)3 CosemObjectDefinition (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition)3 SeasonProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SeasonProfile)3 WindowElement (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WindowElement)3 ArrayList (java.util.ArrayList)2 ActivityCalendar (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActivityCalendar)2 PushSetupAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto)2 ByteBuffer (java.nio.ByteBuffer)1 DayProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfile)1 DayProfileAction (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfileAction)1 PushSetupAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm)1 PushSetupSms (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupSms)1 WeekProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WeekProfile)1 PushSetupSmsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupSmsDto)1