package au.gov.ga.geodesy.interfaces.rest;

import static au.gov.ga.geodesy.interfaces.rest.ResultHandlers.print;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.io.File;
import java.nio.charset.Charset;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.annotation.Rollback;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import au.gov.ga.geodesy.igssitelog.domain.model.IgsSiteLogRepository;

public class UploadIgsSiteLogRestTest extends RestTest {

    private static final Logger log = LoggerFactory.getLogger(UploadIgsSiteLogRestTest.class);

    @Autowired
    private IgsSiteLogRepository siteLogs;

    @Test
    @Rollback(false)
    public void uploadABRK_0() throws Exception {
        String content = FileUtils.readFileToString(getSiteLog("ABRK_0"), Charset.defaultCharset());
        mvc.perform(post("/siteLog/upload").contentType(MediaType.APPLICATION_XML).content(content))
            .andExpect(status().isOk());
    }

    @Rollback(false)
    @Test(dependsOnMethods = {"uploadABRK_0"})
    public void uploadABRK_1() throws Exception {
        String content = FileUtils.readFileToString(getSiteLog("ABRK_1"), Charset.defaultCharset());
        mvc.perform(post("/siteLog/upload").contentType(MediaType.APPLICATION_XML).content(content))
            .andExpect(status().isOk());
    }

    @Test(dependsOnMethods = {"uploadABRK_1"})
    public void fetchAll() throws Exception {
        mvc.perform(get("/gnssCorsSites")).andDo(print);
    }

    private File getSiteLog(String file) {
        return new File("src/test/resources/sitelog/" + file + ".xml");
    }

    @AfterClass
    public static void sleepUntilInterrupted() {
        /* log.info("Tests are done, going to sleep."); */
        /* try { */
        /*     Thread.sleep(Long.MAX_VALUE); */
        /* } catch (InterruptedException ok) {} */
    }
}

@@ -483,574 +483,185 @@
 rg.s
-lf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.http.MediaType;%0Aimport org.springframework.test.annotation.Rollback;%0Aimport org.testng.annotations.AfterClass;%0Aimport org.testng.annotations.Test;%0A%0Aimport au.gov.ga.geodesy.igssitelog.domain.model.IgsSiteLogRepository;%0A%0Apublic class UploadIgsSiteLogRestTest extends RestTest %7B%0A%0A    private static final Logger log = LoggerFactory.getLogger(UploadIgsSiteLogRestTest.class);%0A%0A    @Autowired%0A    private IgsSiteLogRepository siteLogs;
+pringframework.http.MediaType;%0Aimport org.springframework.test.annotation.Rollback;%0Aimport org.testng.annotations.Test;%0A%0Apublic class UploadIgsSiteLogRestTest extends RestTest %7B
 %0A%0A  
@@ -712,21 +712,19 @@
  uploadA
-BRK_0
+LIC
 () throw
@@ -802,21 +802,19 @@
 teLog(%22A
-BRK_0
+LIC
 %22), Char
@@ -985,37 +985,16 @@
 %0A    %7D%0A%0A
-    @Rollback(false)%0A
     @Tes
@@ -1027,13 +1027,11 @@
 oadA
-BRK_0
+LIC
 %22%7D)%0A
@@ -1046,28 +1046,25 @@
 ic void 
-uploadABRK_1
+checkALIC
 () throw
@@ -1089,199 +1089,77 @@
     
-String content = FileUtils.readFileToString(getSiteLog(%22ABRK_1%22), Charset.defaultCharset());%0A        mvc.perform(post(%22/siteLog/upload%22).contentType(MediaType.APPLICATION_XML).content(content
+mvc.perform(get(%22/gnssCorsSites/search/findByFourCharacterId?id=ALIC%22
 ))%0A 
@@ -1200,152 +1200,21 @@
 k())
-;
 %0A    
-%7D%0A%0A
     
-@Test(dependsOnMethods = %7B%22uploadABRK_1%22%7D)%0A    public void fetchAll() throws Exception %7B%0A        mvc.perform(get(%22/gnssCorsSites%22))
+    
 .and
@@ -1355,257 +1355,7 @@
    %7D
-%0A%0A    @AfterClass%0A    public static void sleepUntilInterrupted() %7B%0A        /* log.info(%22Tests are done, going to sleep.%22); */%0A        /* try %7B */%0A        /*     Thread.sleep(Long.MAX_VALUE); */%0A        /* %7D catch (InterruptedException ok) %7B%7D */%0A    %7D
 %0A%7D%0A

Simplify upload site log rest test