package au.gov.ga.geodesy.support.mapper.orika;

import static org.testng.Assert.*;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.TimeZone;

import org.testng.annotations.Test;

import au.gov.ga.geodesy.domain.model.sitelog.GnssReceiverLogItem;
import au.gov.xml.icsm.geodesyml.v_0_3.GnssReceiverType;

import net.opengis.gml.v_3_2_1.CodeType;
import net.opengis.gml.v_3_2_1.TimePositionType;

public class GnssReceiverOrikaMapperTest {

    private GnssReceiverOrikaMapper mapper = new GnssReceiverOrikaMapper();

    @Test
    public void testMappingToLogItem() {
        GnssReceiverType receiver = new GnssReceiverType();

        CodeType gps = new CodeType();
        gps.setValue("GPS");
        gps.setCodeSpace("eGeodesy/satelliteSystem");

        CodeType galileo = new CodeType();
        galileo.setValue("Galileo");
        galileo.setCodeSpace("eGeodesy/satelliteSystem");

        List<CodeType> satelliteSystems = Arrays.asList(gps, galileo);
        receiver.setSatelliteSystem(satelliteSystems);

        receiver.setFirmwareVersion("1.2");
        receiver.setManufacturerSerialNumber("123");

        String dateInstalled = "2012-03-24T02:03:23.000Z";
        receiver.setDateInstalled(timePosition(dateInstalled));

        GnssReceiverLogItem logItem = mapper.mapFromDto(receiver);
        assertEquals(logItem.getFirmwareVersion(), receiver.getFirmwareVersion());
        assertEquals(logItem.getSerialNumber(), receiver.getManufacturerSerialNumber());
        assertEquals(logItem.getSatelliteSystem(), "GPS,Galileo");
        assertEquals(dateFormat().format(logItem.getDateInstalled()), dateInstalled);

        GnssReceiverType receiverB = mapper.mapToDto(logItem);
        assertEquals(receiverB.getFirmwareVersion(), logItem.getFirmwareVersion());
        assertEquals(receiverB.getManufacturerSerialNumber(), logItem.getSerialNumber());
        assertEquals(receiverB.getSatelliteSystem(), satelliteSystems);
        assertEquals(receiverB.getDateInstalled().getValue().get(0), dateInstalled);
    }

    private TimePositionType timePosition(String date) {
        TimePositionType timePosition = new TimePositionType();
        timePosition.getValue().add(date);
        return timePosition;
    }

    private SimpleDateFormat dateFormat() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        return dateFormat;
    }
}


@@ -78,9 +78,20 @@
 ert.
-*
+assertEquals
 ;%0A%0Ai
@@ -153,31 +153,8 @@
 ys;%0A
-import java.util.List;%0A
 impo
@@ -598,24 +598,84 @@
 LogItem() %7B%0A
+        String dateInstalled = %222012-03-24T02:03:23.000Z%22;%0A%0A
         Gnss
@@ -720,18 +720,16 @@
 erType()
-;%0A
 %0A       
@@ -733,83 +733,100 @@
     
-CodeType gps = new CodeType();%0A        gps.setValue(%22GPS%22);%0A        gps.set
+    .withSatelliteSystem(Arrays.asList(%0A                new CodeType().withValue(%22GPS%22).with
 Code
@@ -850,34 +850,33 @@
 atelliteSystem%22)
-;%0A
+,
 %0A        CodeTyp
@@ -872,99 +872,56 @@
     
-CodeType galileo = new CodeType();%0A        galileo.setValue(%22Galileo%22);%0A        galileo.set
+        new CodeType().withValue(%22Galileo%22).with
 Code
@@ -953,18 +953,16 @@
 System%22)
-;%0A
 %0A       
@@ -966,147 +966,32 @@
     
-List%3CCodeType%3E satelliteSystems = Arrays.asList(gps, galileo);%0A        receiver.setSatelliteSystem(satelliteSystems);%0A%0A        receiver.set
+    ))%0A            .with
 Firm
@@ -1008,17 +1008,16 @@
 n(%221.2%22)
-;
 %0A       
@@ -1017,28 +1017,25 @@
         
-receiver.set
+    .with
 Manufact
@@ -1057,27 +1057,28 @@
 r(%22123%22)
-;%0A%0A
+%0A   
         
 String d
@@ -1073,79 +1073,57 @@
     
-String dateInstalled = %222012-03-24T02:03:23.000Z%22;%0A        receiver.set
+ .withElevationCutoffSetting(4)%0A            .with
 Date
@@ -1394,32 +1394,145 @@
 erialNumber());%0A
+        assertEquals(logItem.getElevationCutoffSetting(), String.valueOf(receiver.getElevationCutoffSetting()));%0A
         assertEq
@@ -1898,32 +1898,150 @@
 erialNumber());%0A
+        assertEquals(receiverB.getElevationCutoffSetting(), Double.parseDouble(logItem.getElevationCutoffSetting()));%0A
         assertEq
@@ -2077,17 +2077,29 @@
 stem(), 
-s
+receiver.getS
 atellite
@@ -2104,17 +2104,18 @@
 teSystem
-s
+()
 );%0A     

Use fluent style with JAXB DTOs