package au.gov.ga.geodesy.port.adapter.rest;

import au.gov.ga.geodesy.domain.model.sitelog.SiteLog;
import au.gov.ga.geodesy.domain.service.CorsSiteLogService;
import au.gov.ga.geodesy.port.adapter.geodesyml.GeodesyMLSiteLogReader;
import au.gov.ga.geodesy.support.TestResources;
import au.gov.ga.geodesy.support.spring.IntegrationTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.test.annotation.Rollback;
import org.testng.annotations.Test;

import static io.restassured.module.mockmvc.RestAssuredMockMvc.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

public class SkeletonEndpointITest extends IntegrationTest {

    @Autowired
    private CorsSiteLogService siteLogService;

    @Test
    @Rollback(false)
    public void upload() throws Exception {
        SiteLog alic = new GeodesyMLSiteLogReader(TestResources.customGeodesyMLSiteLogReader("ALIC")).getSiteLog();
        siteLogService.upload(alic);
    }

    @Test(dependsOnMethods = {"upload"})
    @Rollback(false)
    public void testFindSkeletonHeaderForALIC00AUS() throws Exception {
        String text = given()
            .when()
            .get("/skeletonFiles/ALIC00AUS.SKL")
            .then()
            .log().body()
            .statusCode(HttpStatus.OK.value())
            .contentType("text/plain")
            .extract().body().asString();

        assertThat(text, containsString("ANTENNA: DELTA"));
        assertThat(text, containsString("50137M001"));
    }

    @Test(dependsOnMethods = {"upload"})
    @Rollback(false)
    public void testFindSkeletonHeaderForALIC() throws Exception {
        String text = given()
            .when()
            .get("/skeletonFiles/alic.skl")
            .then()
            .log().body()
            .statusCode(HttpStatus.OK.value())
            .contentType("text/plain")
            .extract().body().asString();

        assertThat(text, containsString("AGENCY"));
        assertThat(text, containsString("50137M001"));
    }

    @Test
    public void testNotFound() throws Exception {
        given()
            .when()
            .get("/skeletonFiles/0000.SKL")
            .then()
            .statusCode(HttpStatus.NOT_FOUND.value());
    }

    @Test
    public void testInvalid() throws Exception {
        given()
            .when()
            .get("/skeletonFiles/123456789.xyz")
            .then()
            .statusCode(HttpStatus.NOT_FOUND.value());
    }
}

@@ -620,93 +620,31 @@
 org.
-hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.containsString
+junit.Assert.assertTrue
 ;%0A%0Ap
@@ -767,16 +767,774 @@
 rvice;%0A%0A
+    private String alicSkeleton =%0A        %22ALIC                                                        MARKER NAME%5Cn%22 +%0A        %2250137M001                                                   MARKER NUMBER%5Cn%22 +%0A        %22                    Geoscience Australia                    OBSERVER / AGENCY%5Cn%22 +%0A        %221830439             LEICA GR25          4.31.101            REC # / TYPE / VERS%5Cn%22 +%0A        %2209370001            LEIAR25.R3      NONE                    ANT # / TYPE%5Cn%22 +%0A        %22 -4052051.7670  4212836.2150 -2545106.0270                  APPROX POSITION XYZ%5Cn%22 +%0A        %22        0.0015        0.0000        0.0000                  ANTENNA: DELTA H/E/N%5Cn%22 +%0A        %22                                                            END OF HEADER%5Cn%22;%0A%0A
     @Tes
@@ -2187,104 +2187,36 @@
 ertT
-hat
+rue
 (text
-, containsString(%22ANTENNA: DELTA%22));%0A        assertThat(text, containsString(%2250137M001%22
+.equals(alicSkeleton
 ));%0A
@@ -2639,96 +2639,36 @@
 ertT
-hat
+rue
 (text
-, containsString(%22AGENCY%22));%0A        assertThat(text, containsString(%2250137M001%22
+.equals(alicSkeleton
 ));%0A

Update skeleton endpoint tests to check entire response