/*
 * Copyright (C) 2014  Camptocamp
 *
 * This file is part of MapFish Print
 *
 * MapFish Print is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MapFish Print is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MapFish Print.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.mapfish.print;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.net.URISyntaxException;

import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest;

/*
 * Test the servlet metrics API.
 * 
 *  To run this test make sure that the test servers are running:
 * 
 *      ./gradlew examples:jettyRun
 *      
 * Or run the tests with the following task (which automatically starts the servers):
 * 
 *      ./gradlew examples:test
 */
public class MetricsApiTest extends AbstractApiTest {

    @Test
    public void testPing() throws Exception {
        ClientHttpRequest request = getMetricsRequest("ping", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals("pong\n", getBodyAsText(response));
    }

    private ClientHttpRequest getMetricsRequest(String path, HttpMethod method) throws IOException,
            URISyntaxException {
        return getRequest("metrics/" + path, method);
    }

}

@@ -800,16 +800,103 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Aimport
@@ -954,16 +954,44 @@
 ption;%0A%0A
+import org.json.JSONObject;%0A
 import o
@@ -1093,16 +1093,59 @@
 Status;%0A
+import org.springframework.http.MediaType;%0A
 import o
@@ -1565,267 +1565,1647 @@
 test
-Ping() throws Exception %7B%0A        ClientHttpRequest request = getMetricsRequest(%22ping%22, HttpMethod.GET);%0A        response = request.execute();%0A        assertEquals(HttpStatus.OK, response.getStatusCode());%0A        assertEquals(%22pong%5Cn%22, getBodyAsText(response
+Metrics() throws Exception %7B%0A        ClientHttpRequest request = getMetricsRequest(%22metrics%22, HttpMethod.GET);%0A        response = request.execute();%0A        assertEquals(HttpStatus.OK, response.getStatusCode());%0A        assertEquals(MediaType.APPLICATION_JSON, response.getHeaders().getContentType());%0A        JSONObject sampleRequest = new JSONObject(getBodyAsText(response));%0A        assertTrue(sampleRequest.has(%22version%22));%0A    %7D%0A%0A    @Test%0A    public void testPing() throws Exception %7B%0A        ClientHttpRequest request = getMetricsRequest(%22ping%22, HttpMethod.GET);%0A        response = request.execute();%0A        assertEquals(HttpStatus.OK, response.getStatusCode());%0A        assertEquals(%22pong%5Cn%22, getBodyAsText(response));%0A    %7D%0A%0A    @Test%0A    public void testThreads() throws Exception %7B%0A        ClientHttpRequest request = getMetricsRequest(%22threads%22, HttpMethod.GET);%0A        response = request.execute();%0A        assertEquals(HttpStatus.OK, response.getStatusCode());%0A        assertEquals(MediaType.TEXT_PLAIN, response.getHeaders().getContentType());%0A        assertFalse(getBodyAsText(response).isEmpty());%0A    %7D%0A%0A    @Test%0A    public void testHealthcheck() throws Exception %7B%0A        ClientHttpRequest request = getMetricsRequest(%22healthcheck%22, HttpMethod.GET);%0A        response = request.execute();%0A        // TODO not implemented?%0A        assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());%0A//        assertEquals(HttpStatus.OK, response.getStatusCode());%0A//        assertEquals(MediaType.APPLICATION_JSON, response.getHeaders().getContentType());%0A//        assertNotNull(new JSONObject(getBodyAsText(response)
 ));%0A

Add tests for metrics API