use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.
the class CosemDateConverterTest method testToCosemDateMapping.
/**
* Tests if mapping a byte[] to a CosemDate object succeeds.
*/
@Test
public void testToCosemDateMapping() {
// register the CosemDateConverter, since the test converts to a
// CosemDate object.
this.mapperFactory.getConverterFactory().registerConverter(new CosemDateConverter());
// actual mapping
final CosemDate cosemDate = this.mapperFactory.getMapperFacade().map(COSEMDATE_BYTE_ARRAY, CosemDate.class);
// check mapping
assertThat(cosemDate).isNotNull();
assertThat(((byte) (cosemDate.getYear() >> 8))).isEqualTo(FIRST_BYTE_FOR_YEAR);
assertThat(((byte) (cosemDate.getYear() & 0xFF))).isEqualTo(SECOND_BYTE_FOR_YEAR);
assertThat(cosemDate.getMonth()).isEqualTo(BYTE_FOR_MONTH);
assertThat(cosemDate.getDayOfMonth()).isEqualTo(BYTE_FOR_DAY_OF_MONTH);
assertThat((byte) cosemDate.getDayOfWeek()).isEqualTo(BYTE_FOR_DAY_OF_WEEK);
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.
the class CosemDateConverterTest method testWildCards.
/**
* Tests the mapping of wildcards.
*/
@Test
public void testWildCards() {
byte[] source = new byte[] { (byte) 0x07, (byte) 0xDF, 6, (byte) 0xFF, (byte) 0xFF };
final CosemDateConverter converter = new CosemDateConverter();
CosemDate date = converter.convert(source, converter.getBType(), null);
assertThat(date.getYear()).isEqualTo(2015);
assertThat(date.getMonth()).isEqualTo(6);
assertThat(date.getDayOfMonth()).isEqualTo(0xFF);
assertThat(date.getDayOfWeek()).isEqualTo(0xFF);
source = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFE, (byte) 0xFD, (byte) 0xFF };
date = converter.convert(source, converter.getBType(), null);
assertThat(date.getYear()).isEqualTo(0xFFFF);
assertThat(date.getMonth()).isEqualTo(0xFE);
assertThat(date.getDayOfMonth()).isEqualTo(0xFD);
assertThat(date.getDayOfWeek()).isEqualTo(0xFF);
source = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFE, 21, 3 };
date = converter.convert(source, converter.getBType(), null);
assertThat(date.getYear()).isEqualTo(0xFFFF);
assertThat(date.getMonth()).isEqualTo(0xFE);
assertThat(date.getDayOfMonth()).isEqualTo(21);
assertThat(date.getDayOfWeek()).isEqualTo(3);
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate 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.CosemDate in project open-smart-grid-platform by OSGP.
the class SpecialDaysRequestMappingTest method testSpecialDaysRequestMappingNonEmptyListNoCosemDate.
// To check mapping of SpecialDaysRequest, when its SpecialDaysRequestData
// has a filled List (1 value), where CosemDate is not specified.
@Test
public void testSpecialDaysRequestMappingNonEmptyListNoCosemDate() {
final String deviceIdentification = "nr1";
final int dayId = 1;
final SpecialDay specialDay = new SpecialDay(new CosemDate(), dayId);
final SpecialDaysRequestData specialDaysRequestData = new SpecialDaysRequestDataBuilder().addSpecialDay(specialDay).build();
final SpecialDaysRequest specialDaysRequestValueObject = new SpecialDaysRequest(deviceIdentification, specialDaysRequestData);
final SpecialDaysRequestDto specialDaysRequestDto = this.configurationMapper.map(specialDaysRequestValueObject, SpecialDaysRequestDto.class);
assertThat(specialDaysRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
final SpecialDaysRequestDataDto requestDataDto = specialDaysRequestDto.getSpecialDaysRequestData();
assertThat(requestDataDto).isNotNull();
assertThat(requestDataDto.getSpecialDays()).isNotNull();
assertThat(requestDataDto.getSpecialDays().size()).isEqualTo(dayId);
final SpecialDayDto specialDayDto = requestDataDto.getSpecialDays().get(0);
assertThat(specialDayDto.getDayId()).isEqualTo(dayId);
final CosemDate specialDayDate = specialDay.getSpecialDayDate();
final CosemDateDto specialDayDateDto = specialDayDto.getSpecialDayDate();
assertThat(specialDayDateDto.getYear()).isEqualTo(specialDayDate.getYear());
assertThat(specialDayDateDto.getMonth()).isEqualTo(specialDayDate.getMonth());
assertThat(specialDayDateDto.getDayOfMonth()).isEqualTo(specialDayDate.getDayOfMonth());
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate in project open-smart-grid-platform by OSGP.
the class SpecialDaysRequestMappingTest method testSpecialDaysRequestMappingNonEmptyList.
// To check mapping of SpecialDaysRequest, when its SpecialDaysRequestData
// has a filled List (1 value).
@Test
public void testSpecialDaysRequestMappingNonEmptyList() {
final String deviceIdentification = "nr1";
final int year = 2016;
final int month = 3;
final int dayOfMonth = 11;
final int dayId = 1;
final SpecialDay specialDay = new SpecialDay(new CosemDate(year, month, dayOfMonth), dayId);
final SpecialDaysRequestData specialDaysRequestData = new SpecialDaysRequestDataBuilder().addSpecialDay(specialDay).build();
final SpecialDaysRequest specialDaysRequestValueObject = new SpecialDaysRequest(deviceIdentification, specialDaysRequestData);
final SpecialDaysRequestDto specialDaysRequestDto = this.configurationMapper.map(specialDaysRequestValueObject, SpecialDaysRequestDto.class);
assertThat(specialDaysRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
final SpecialDaysRequestDataDto requestDataDto = specialDaysRequestDto.getSpecialDaysRequestData();
assertThat(requestDataDto).isNotNull();
assertThat(requestDataDto.getSpecialDays()).isNotNull();
assertThat(requestDataDto.getSpecialDays().size()).isEqualTo(dayId);
final SpecialDayDto specialDayDto = requestDataDto.getSpecialDays().get(0);
assertThat(specialDayDto.getDayId()).isEqualTo(dayId);
final CosemDateDto specialDayDateDto = specialDayDto.getSpecialDayDate();
assertThat(specialDayDateDto.getYear()).isEqualTo(year);
assertThat(specialDayDateDto.getMonth()).isEqualTo(month);
assertThat(specialDayDateDto.getDayOfMonth()).isEqualTo(dayOfMonth);
}
Aggregations