package uk.ac.ebi.subs.api;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.boot.test.json.ObjectContent;
import org.springframework.test.context.junit4.SpringRunner;
import uk.ac.ebi.subs.ApiApplication;
import uk.ac.ebi.subs.data.FullSubmission;
import uk.ac.ebi.subs.data.Submission;
import uk.ac.ebi.subs.repository.model.Sample;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ApiApplication.class)
@JsonTest
public class SubmissionSerialisationTest {

    @Autowired
    private JacksonTester<FullSubmission> json;

    @Test
    public void testSerialize() throws Exception {
        assertThat(this.json.write(sub)).isEqualToJson(exampleJson);
    }

    String exampleJson;
    FullSubmission sub;

    @Before
    public void setUp() throws IOException {
        sub = new FullSubmission();
        sub.getTeam().setName("exampleTeam");
        sub.getSubmitter().setEmail("test@example.ac.uk");
        sub.getSamples().add(new Sample());

        exampleJson = "{\"submitter\":{\"email\":\"test@example.ac.uk\"},\"team\":{\"name\":\"exampleTeam\"}, \"samples\": [{}]}";
    }

    @Test
    public void testDeserialize() throws Exception {

        ObjectContent<FullSubmission> deserializedSub = this.json.parse(exampleJson);
        Submission actualSub = sub;

        assertThat(actualSub.getTeam())
                .isEqualTo(sub.getTeam());
        assertThat(actualSub.getSubmitter())
                .isEqualTo(sub.getSubmitter());
        assertThat(actualSub.getSubmissionDate()).isEqualTo(sub.getSubmissionDate());
    }


}

@@ -533,20 +533,16 @@
 bs.data.
-Full
 Submissi
@@ -559,36 +559,42 @@
  uk.ac.ebi.subs.
-data
+processing
 .Submission;%0Aimp
@@ -580,32 +580,40 @@
 ssing.Submission
+Envelope
 ;%0Aimport uk.ac.e
@@ -906,20 +906,16 @@
 nTester%3C
-Full
 Submissi
@@ -933,120 +933,15 @@
     
-@Test%0A    public void testSerialize() throws Exception %7B%0A        assertThat(this.json.write(sub)).isEqualToJson(
+String 
 exam
@@ -951,51 +951,34 @@
 Json
-)
 ;%0A    
-%7D%0A%0A    String exampleJson;%0A    FullS
+SubmissionEnvelope s
 ubmi
@@ -982,20 +982,24 @@
 bmission
- sub
+Envelope
 ;%0A%0A    @
@@ -1065,19 +1065,53 @@
  sub
- = new Full
+missionEnvelope = new SubmissionEnvelope(new 
 Subm
@@ -1118,16 +1118,17 @@
 ission()
+)
 ;%0A      
@@ -1128,24 +1128,55 @@
 %0A        sub
+missionEnvelope.getSubmission()
 .getTeam().s
@@ -1205,24 +1205,55 @@
 %0A        sub
+missionEnvelope.getSubmission()
 .getSubmitte
@@ -1291,52 +1291,8 @@
 k%22);
-%0A        sub.getSamples().add(new Sample());
 %0A%0A  
@@ -1401,29 +1401,178 @@
 m%5C%22%7D
-, %5C%22samples%5C%22: %5B%7B%7D%5D%7D%22
+%7D%22;%0A    %7D%0A%0A    @Test%0A    public void testSerialize() throws Exception %7B%0A        assertThat(this.json.write(submissionEnvelope.getSubmission())).isEqualToJson(exampleJson)
 ;%0A  
@@ -1666,12 +1666,8 @@
 ent%3C
-Full
 Subm
@@ -1754,14 +1754,45 @@
 lSub
- = sub
+mission = deserializedSub.getObject()
 ;%0A%0A 
@@ -1814,24 +1814,31 @@
 at(actualSub
+mission
 .getTeam())%0A
@@ -1863,24 +1863,55 @@
 sEqualTo(sub
+missionEnvelope.getSubmission()
 .getTeam());
@@ -1931,32 +1931,39 @@
 rtThat(actualSub
+mission
 .getSubmitter())
@@ -1985,32 +1985,63 @@
   .isEqualTo(sub
+missionEnvelope.getSubmission()
 .getSubmitter())
@@ -2070,16 +2070,23 @@
 ctualSub
+mission
 .getSubm
@@ -2098,30 +2098,78 @@
 nDate())
-.isEqualTo(sub
+%0A                .isEqualTo(submissionEnvelope.getSubmission()
 .getSubm
@@ -2189,12 +2189,10 @@
 ;%0A    %7D%0A
-%0A%0A
 %7D%0A

Move the functionality from FullSubmission to SubmissionEnvelope