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);
});
}
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);
});
}
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);
}
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);
}
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);
}
Aggregations