Search in sources :

Example 1 with CosemDate

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);
}
Also used : CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) Test(org.junit.jupiter.api.Test)

Example 2 with CosemDate

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);
}
Also used : CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) Test(org.junit.jupiter.api.Test)

Example 3 with CosemDate

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);
}
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 4 with CosemDate

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());
}
Also used : SpecialDaysRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest) SpecialDaysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto) SpecialDaysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData) SpecialDay(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto) Test(org.junit.jupiter.api.Test)

Example 5 with CosemDate

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);
}
Also used : SpecialDaysRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest) SpecialDaysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto) SpecialDaysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData) SpecialDay(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto) Test(org.junit.jupiter.api.Test)

Aggregations

CosemDate (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate)13 CosemTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime)8 Test (org.junit.jupiter.api.Test)7 ClockStatus (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus)7 CosemDateTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDateTime)5 CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)5 ClockStatusDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ClockStatusDto)3 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)3 ByteBuffer (java.nio.ByteBuffer)2 CosemObisCode (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObisCode)2 CosemObjectDefinition (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition)2 SpecialDay (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay)2 SpecialDaysRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest)2 SpecialDaysRequestData (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData)2 WindowElement (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.WindowElement)2 SpecialDayDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto)2 SpecialDaysRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto)2 SpecialDaysRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto)2 ArrayList (java.util.ArrayList)1 DayProfile (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DayProfile)1