Search in sources :

Example 6 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class DataObjectToEventListConverterTest method testEventsWithCodeTimeStampAndCounter.

@Test
void testEventsWithCodeTimeStampAndCounter() throws ProtocolAdapterException {
    // GIVEN
    final DateTime dateTime1 = new DateTime(2021, 9, 16, 10, 35, 10, DateTimeZone.UTC);
    final DateTime dateTime2 = new DateTime(2021, 9, 17, 11, 22, 45, DateTimeZone.UTC);
    final DataObject eventDataObject1 = this.createEventDataObject(dateTime1, 1, 11);
    final DataObject eventDataObject2 = this.createEventDataObject(dateTime2, 2, 12);
    final DataObject source = DataObject.newArrayData(Arrays.asList(eventDataObject1, eventDataObject2));
    final EventDto expectedEvent1 = new EventDto(dateTime1, 1, 11, EventLogCategoryDto.COMMUNICATION_SESSION_LOG.name());
    final EventDto expectedEvent2 = new EventDto(dateTime2, 2, 12, EventLogCategoryDto.COMMUNICATION_SESSION_LOG.name());
    // WHEN
    final List<EventDto> events = this.converter.convert(source, EventLogCategoryDto.COMMUNICATION_SESSION_LOG);
    // THEN
    assertThat(events).usingRecursiveFieldByFieldElementComparator().containsExactly(expectedEvent1, expectedEvent2);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 7 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class DataObjectToEventListConverterTest method testEventsWithCodeAndTimeStamp.

@Test
void testEventsWithCodeAndTimeStamp() throws ProtocolAdapterException {
    // GIVEN
    final DateTime dateTime1 = new DateTime(2021, 9, 16, 10, 35, 10, DateTimeZone.UTC);
    final DateTime dateTime2 = new DateTime(2021, 9, 17, 11, 22, 45, DateTimeZone.UTC);
    final DataObject eventDataObject1 = this.createEventDataObject(dateTime1, 1);
    final DataObject eventDataObject2 = this.createEventDataObject(dateTime2, 2);
    final DataObject source = DataObject.newArrayData(Arrays.asList(eventDataObject1, eventDataObject2));
    final EventDto expectedEvent1 = new EventDto(dateTime1, 1, null, EventLogCategoryDto.STANDARD_EVENT_LOG.name());
    final EventDto expectedEvent2 = new EventDto(dateTime2, 2, null, EventLogCategoryDto.STANDARD_EVENT_LOG.name());
    // WHEN
    final List<EventDto> events = this.converter.convert(source, EventLogCategoryDto.STANDARD_EVENT_LOG);
    // THEN
    assertThat(events).usingRecursiveFieldByFieldElementComparator().containsExactly(expectedEvent1, expectedEvent2);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 8 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class DataObjectToEventListConverterTest method testEventsWithEventDetails.

@Test
void testEventsWithEventDetails() throws ProtocolAdapterException {
    // GIVEN
    final DateTime dateTime1 = new DateTime(2021, 9, 16, 10, 35, 10, DateTimeZone.UTC);
    final DateTime dateTime2 = new DateTime(2021, 9, 17, 11, 22, 45, DateTimeZone.UTC);
    final DataObject eventDataObject1 = this.createEventDataObject(dateTime1, 1, 11, 21);
    final DataObject eventDataObject2 = this.createEventDataObject(dateTime2, 2, 12, 22);
    final String MAGNITUDE = "magnitude";
    final String DURATION = "duration";
    final DataObject source = DataObject.newArrayData(Arrays.asList(eventDataObject1, eventDataObject2));
    final EventDto expectedEvent1 = new EventDto(dateTime1, 1, null, EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG.name());
    expectedEvent1.addEventDetail(new EventDetailDto(MAGNITUDE, "1.1 V"));
    expectedEvent1.addEventDetail(new EventDetailDto(DURATION, "2.1 s"));
    final EventDto expectedEvent2 = new EventDto(dateTime2, 2, null, EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG.name());
    expectedEvent2.addEventDetail(new EventDetailDto(MAGNITUDE, "1.2 V"));
    expectedEvent2.addEventDetail(new EventDetailDto(DURATION, "2.2 s"));
    // WHEN
    final List<EventDto> events = this.converter.convert(source, EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG);
    // THEN
    assertThat(events).usingRecursiveFieldByFieldElementComparator().containsExactly(expectedEvent1, expectedEvent2);
}
Also used : EventDetailDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 9 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class EventMessageDataContainerMappingTest method testWithEmptyList.

// Test if mapping with an empty list succeeds
@Test
public void testWithEmptyList() {
    // build test data
    final EventMessageDataResponseDto containerDto = new EventMessageDataResponseDto(new ArrayList<EventDto>());
    // actual mapping
    final EventMessagesResponse container = this.managementMapper.map(containerDto, EventMessagesResponse.class);
    // test mapping
    assertThat(container).isNotNull();
    assertThat(container.getEvents()).isNotNull();
    assertThat(container.getEvents()).isEmpty();
}
Also used : EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) Test(org.junit.jupiter.api.Test)

Example 10 with EventDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto in project open-smart-grid-platform by OSGP.

the class EventMessageDataContainerMappingTest method testWithFilledList.

// Test if mapping with a filled List succeeds
@Test
public void testWithFilledList() {
    // build test data
    final EventDto event = new EventDto(new DateTime(), new Integer(1), new Integer(2), "STANDARD_EVENT_LOG");
    event.setEventTypeDto(EventTypeDto.POWER_FAILURE);
    final ArrayList<EventDto> events = new ArrayList<>();
    events.add(event);
    final EventMessageDataResponseDto containerDto = new EventMessageDataResponseDto(events);
    // actual mapping
    final EventMessagesResponse container = this.managementMapper.map(containerDto, EventMessagesResponse.class);
    // test mapping
    assertThat(container).isNotNull();
    assertThat(container.getEvents()).isNotNull();
    assertThat(container.getEvents().get(0).getTimestamp()).isEqualTo(containerDto.getEvents().get(0).getTimestamp());
    assertThat(container.getEvents().get(0).getEventCode()).isEqualTo(containerDto.getEvents().get(0).getEventCode());
    assertThat(container.getEvents().get(0).getEventType().name()).isEqualTo(containerDto.getEvents().get(0).getEventTypeDto().name());
    assertThat(container.getEvents().get(0).getEventCounter()).isEqualTo(containerDto.getEvents().get(0).getEventCounter());
}
Also used : EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Aggregations

EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)16 Test (org.junit.jupiter.api.Test)9 DataObject (org.openmuc.jdlms.datatypes.DataObject)8 DateTime (org.joda.time.DateTime)7 ArrayList (java.util.ArrayList)5 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)5 EventDetailDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDetailDto)4 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 FindEventsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto)3 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)2 EventDetail (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventDetail)2 EventMessagesResponse (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse)2 EventTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventTypeDto)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 MappingContext (ma.glasnost.orika.MappingContext)1 BidirectionalConverter (ma.glasnost.orika.converter.BidirectionalConverter)1 Type (ma.glasnost.orika.metadata.Type)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1