package org.jboss.da.test.client.rest.reports;

import org.apache.commons.io.FileUtils;
import org.apache.http.entity.ContentType;
import org.jboss.da.test.client.AbstractRestApiTest;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
import org.junit.Ignore;
import org.junit.Test;

import javax.ws.rs.core.MediaType;
import java.io.File;

import static org.apache.commons.io.FileUtils.readFileToString;
import static org.apache.http.entity.ContentType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;

public class RestApiReportsTest extends AbstractRestApiTest {

    @Test
    public void testGav() throws Exception {
        String path = "/reports/gav";
        ContentType contentType = APPLICATION_JSON;
        File jsonRequestFile = new RequestFilenameBuilder(restApiRequestFolder, path).getFile();
        String jsonRequest = FileUtils.readFileToString(jsonRequestFile, "utf-8");
        ClientRequest request = new ClientRequest(restApiURL + path);
        request.header("Content-Type", contentType);
        request.body(MediaType.APPLICATION_JSON_TYPE, jsonRequest);

        ClientResponse<String> response = request.post(String.class);

        File expectedResponseFile = new ExpectedResponseFilenameBuilder(
                restApiExpectedResponseFolder, path, contentType).getFile();
        assertEquals(readFileToString(expectedResponseFile), response.getEntity(String.class));
    }

    @Test
    @Ignore
    // FIXME server side throws NPE - have to be handled
    public void testNonexistingGav() throws Exception {
        String path = "/reports/gav";
        ContentType contentType = APPLICATION_JSON;
        String variant = "nonexisting";
        File jsonRequestFile = new RequestFilenameBuilder(restApiRequestFolder, path, contentType,
                variant).getFile();
        String jsonRequest = FileUtils.readFileToString(jsonRequestFile, "utf-8");
        ClientRequest request = new ClientRequest(restApiURL + path);
        request.header("Content-Type", contentType);
        request.body(MediaType.APPLICATION_JSON_TYPE, jsonRequest);

        ClientResponse<String> response = request.post(String.class);

        File expectedResponseFile = new ExpectedResponseFilenameBuilder(
                restApiExpectedResponseFolder, path, contentType, variant).getFile();
        assertEquals(readFileToString(expectedResponseFile), response.getEntity(String.class));
    }
}

@@ -1475,77 +1475,8 @@
 est%0A
-    @Ignore%0A    // FIXME server side throws NPE - have to be handled%0A
     
@@ -2150,251 +2150,45 @@
     
-File expectedResponseFile = new ExpectedResponseFilenameBuilder(%0A                restApiExpectedResponseFolder, path, contentType, variant).getFile();%0A        assertEquals(readFileToString(expectedResponseFile), response.getEntity(String.class
+assertEquals(404, response.getStatus(
 ));%0A

Fix test of non existing GAV