Search in sources :

Example 6 with Address

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

the class AddressConversionTest method shouldConvertWsAddressToAddress.

@Test
public void shouldConvertWsAddressToAddress() {
    // Arrange
    final org.opensmartgridplatform.adapter.ws.schema.core.common.Address source = this.createWsAddress();
    final Address expected = this.createAddress();
    // Act
    final Address actual = this.mapper.map(source, Address.class);
    // Assert
    assertThat(actual).isEqualTo(expected);
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) Test(org.junit.jupiter.api.Test)

Example 7 with Address

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

the class AddressConversionTest method shouldMapNullValue.

@Test
public void shouldMapNullValue() {
    // Arrange
    final org.opensmartgridplatform.adapter.ws.schema.core.common.Address source = null;
    final Address expected = null;
    // Act
    final Address actual = this.mapper.map(source, Address.class);
    // Assert
    assertThat(actual).isEqualTo(expected);
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) Test(org.junit.jupiter.api.Test)

Example 8 with Address

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

the class DeviceConverterTest method testSmartMeterConversion.

@Test
public void testSmartMeterConversion() throws UnknownHostException {
    final Device device = new SmartMeter("id", "alias", new Address("city", "postal", "street", 42, "nr", "munic"), new GpsCoordinates(12f, 13f));
    device.updateRegistrationData(InetAddress.getByName("localhost"), "type");
    final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device jaxbDevice = this.deviceManagementMapper.map(device, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device.class);
    assertThat(jaxbDevice.getDeviceIdentification()).isEqualTo("id");
    assertThat(jaxbDevice.getAlias()).isEqualTo("alias");
    assertThat(jaxbDevice.getContainerAddress().getCity()).isEqualTo("city");
    assertThat(jaxbDevice.getContainerAddress().getPostalCode()).isEqualTo("postal");
    assertThat(jaxbDevice.getContainerAddress().getStreet()).isEqualTo("street");
    assertThat(jaxbDevice.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
    assertThat(jaxbDevice.getContainerAddress().getNumberAddition()).isEqualTo("nr");
    assertThat(jaxbDevice.getContainerAddress().getMunicipality()).isEqualTo("munic");
    assertThat(jaxbDevice.getGpsLatitude()).isEqualTo("12.0");
    assertThat(jaxbDevice.getGpsLongitude()).isEqualTo("13.0");
    assertThat(jaxbDevice.getNetworkAddress()).isEqualTo("localhost/127.0.0.1");
    assertThat(jaxbDevice.getDeviceType()).isEqualTo("type");
    final SmartMeter mappedBack = this.deviceManagementMapper.map(jaxbDevice, SmartMeter.class);
    assertThat(mappedBack.getDeviceIdentification()).isEqualTo("id");
    assertThat(mappedBack.getAlias()).isEqualTo("alias");
    assertThat(mappedBack.getContainerAddress().getCity()).isEqualTo("city");
    assertThat(mappedBack.getContainerAddress().getPostalCode()).isEqualTo("postal");
    assertThat(mappedBack.getContainerAddress().getStreet()).isEqualTo("street");
    assertThat(mappedBack.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
    assertThat(mappedBack.getContainerAddress().getNumberAddition()).isEqualTo("nr");
    assertThat(mappedBack.getContainerAddress().getMunicipality()).isEqualTo("munic");
    assertThat(mappedBack.getGpsCoordinates().getLatitude()).isEqualTo(12);
    assertThat(mappedBack.getGpsCoordinates().getLongitude()).isEqualTo(13);
    // alas networkaddress in jaxb device is just a string, need parsing to
    // convert that to InetAddress
    assertThat(mappedBack.getNetworkAddress()).isEqualTo(null);
    assertThat(mappedBack.getDeviceType()).isEqualTo("type");
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) InetAddress(java.net.InetAddress) Device(org.opensmartgridplatform.domain.core.entities.Device) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Test(org.junit.jupiter.api.Test)

Example 9 with Address

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

the class DeviceConverterTest method testDeviceConversion.

@Test
public void testDeviceConversion() throws UnknownHostException {
    final Device device = new Device("id", "alias", new Address("city", "postal", "street", 42, "nr", "munic"), new GpsCoordinates(12f, 13f), null);
    device.updateRegistrationData(InetAddress.getByName("localhost"), "type");
    final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device jaxbDevice = this.deviceManagementMapper.map(device, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device.class);
    assertThat(jaxbDevice.getDeviceIdentification()).isEqualTo("id");
    assertThat(jaxbDevice.getAlias()).isEqualTo("alias");
    assertThat(jaxbDevice.getContainerAddress().getCity()).isEqualTo("city");
    assertThat(jaxbDevice.getContainerAddress().getPostalCode()).isEqualTo("postal");
    assertThat(jaxbDevice.getContainerAddress().getStreet()).isEqualTo("street");
    assertThat(jaxbDevice.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
    assertThat(jaxbDevice.getContainerAddress().getNumberAddition()).isEqualTo("nr");
    assertThat(jaxbDevice.getContainerAddress().getMunicipality()).isEqualTo("munic");
    assertThat(jaxbDevice.getGpsLatitude()).isEqualTo("12.0");
    assertThat(jaxbDevice.getGpsLongitude()).isEqualTo("13.0");
    assertThat(jaxbDevice.getNetworkAddress()).isEqualTo("localhost/127.0.0.1");
    assertThat(jaxbDevice.getDeviceType()).isEqualTo("type");
    final Device mappedBack = this.deviceManagementMapper.map(jaxbDevice, Device.class);
    assertThat(mappedBack.getDeviceIdentification()).isEqualTo("id");
    assertThat(mappedBack.getAlias()).isEqualTo("alias");
    assertThat(mappedBack.getContainerAddress().getCity()).isEqualTo("city");
    assertThat(mappedBack.getContainerAddress().getPostalCode()).isEqualTo("postal");
    assertThat(mappedBack.getContainerAddress().getStreet()).isEqualTo("street");
    assertThat(mappedBack.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
    assertThat(mappedBack.getContainerAddress().getNumberAddition()).isEqualTo("nr");
    assertThat(mappedBack.getContainerAddress().getMunicipality()).isEqualTo("munic");
    assertThat(mappedBack.getGpsCoordinates().getLatitude()).isEqualTo(12);
    assertThat(mappedBack.getGpsCoordinates().getLongitude()).isEqualTo(13);
    // alas networkaddress in jaxb device is just a string, need parsing to
    // convert that to InetAddress
    assertThat(mappedBack.getNetworkAddress()).isEqualTo(null);
    assertThat(mappedBack.getDeviceType()).isEqualTo("type");
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) InetAddress(java.net.InetAddress) Device(org.opensmartgridplatform.domain.core.entities.Device) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Test(org.junit.jupiter.api.Test)

Example 10 with Address

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

the class LmdConverter method convertFrom.

@Override
public org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice convertFrom(final LightMeasurementDevice source, final Type<org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice> destinationType, final MappingContext mappingContext) {
    final String deviceIdentification = source.getDeviceIdentification();
    final Integer containerNumber = source.getContainerNumber() == null ? null : Integer.valueOf(source.getContainerNumber());
    final Address containerAddress = new Address(source.getContainerCity(), source.getContainerPostalCode(), source.getContainerStreet(), containerNumber, null, null);
    final GpsCoordinates gpsCoordinates = new GpsCoordinates(source.getGpsLatitude(), source.getGpsLongitude());
    final org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice lmd = new org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice(deviceIdentification, null, containerAddress, gpsCoordinates, null);
    lmd.updateRegistrationData(null, source.getDeviceType());
    lmd.setDescription(source.getDescription());
    lmd.setCode(source.getCode());
    lmd.setColor(source.getColor());
    lmd.setDigitalInput(source.getDigitalInput());
    return lmd;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) LightMeasurementDevice(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)

Aggregations

Address (org.opensmartgridplatform.domain.core.valueobjects.Address)21 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)18 Test (org.junit.jupiter.api.Test)6 InetAddress (java.net.InetAddress)5 Device (org.opensmartgridplatform.domain.core.entities.Device)4 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)4 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)4 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)4 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 Given (io.cucumber.java.en.Given)2 UnknownHostException (java.net.UnknownHostException)2 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice)2 Ssld (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld)2 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Instant (java.time.Instant)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightMeasurementDevice)1