# HG changeset patch # User Severin Gehwolf # Date 1505302377 -7200 # Node ID d4290a3f1e0344166e7994050e00d6a909f025b3 # Parent 8453ba17aa0ffcf5ae1f666222cb47eb4206af76 Fix doc auth exclusion for jvm-gc/jvm-memory. Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025009.html diff -r 8453ba17aa0f -r d4290a3f1e03 server/src/main/resources/swagger-ui/index.html --- a/server/src/main/resources/swagger-ui/index.html Mon Sep 18 16:03:05 2017 -0400 +++ b/server/src/main/resources/swagger-ui/index.html Wed Sep 13 13:32:57 2017 +0200 @@ -74,7 +74,7 @@ // Build a system const ui = SwaggerUIBundle({ // FIXME: This should eventually point to an aggregate of all our APIs - url: "../commands/v1/static/doc/commands-swagger.yaml", + url: "../commands/v1/doc/commands-swagger.yaml", dom_id: '#swagger-ui', presets: [ SwaggerUIBundle.presets.apis, diff -r 8453ba17aa0f -r d4290a3f1e03 services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/http/handlers/HtmlResourceHandler.java --- a/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/http/handlers/HtmlResourceHandler.java Mon Sep 18 16:03:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat 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 2, or (at your - * option) any later version. - * - * Thermostat 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 Thermostat; see the file COPYING. If not see - * . - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.gateway.service.commands.http.handlers; - -import java.io.IOException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import com.redhat.thermostat.gateway.common.core.servlet.BasicResourceHandler; - -@Path("{fileName: .+\\.html}") -@Produces(MediaType.TEXT_HTML) -public class HtmlResourceHandler extends BasicResourceHandler { - - @GET - public Response getPage(@PathParam("fileName") String fileName) throws IOException { - return getFileAsResponse(HtmlResourceHandler.class.getClassLoader(), fileName); - } - -} diff -r 8453ba17aa0f -r d4290a3f1e03 services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/http/handlers/StaticResourcesHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/http/handlers/StaticResourcesHandler.java Wed Sep 13 13:32:57 2017 +0200 @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * . + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gateway.service.commands.http.handlers; + +import java.io.IOException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.redhat.thermostat.gateway.common.core.servlet.BasicResourceHandler; + +@Path("{fileName: .+(\\.(yaml|html))}") +@Produces(MediaType.TEXT_PLAIN) +public class StaticResourcesHandler extends BasicResourceHandler { + + @GET + public Response getFileAsPlainText(@PathParam("fileName") String fileName) throws IOException { + return getFileAsResponse(StaticResourcesHandler.class.getClassLoader(), fileName); + } +} diff -r 8453ba17aa0f -r d4290a3f1e03 services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/http/handlers/SwaggerSpecResourceHandler.java --- a/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/http/handlers/SwaggerSpecResourceHandler.java Mon Sep 18 16:03:05 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat 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 2, or (at your - * option) any later version. - * - * Thermostat 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 Thermostat; see the file COPYING. If not see - * . - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.gateway.service.commands.http.handlers; - -import java.io.IOException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import com.redhat.thermostat.gateway.common.core.servlet.BasicResourceHandler; - -@Path("doc/{fileName: .+\\.yaml}") -@Produces(MediaType.TEXT_PLAIN) -public class SwaggerSpecResourceHandler extends BasicResourceHandler { - - @GET - public Response getFileAsPlainText(@PathParam("fileName") String fileName) throws IOException { - return getFileAsResponse(SwaggerSpecResourceHandler.class.getClassLoader(), fileName); - } -} diff -r 8453ba17aa0f -r d4290a3f1e03 services/commands/src/main/webapp/WEB-INF/web.xml --- a/services/commands/src/main/webapp/WEB-INF/web.xml Mon Sep 18 16:03:05 2017 -0400 +++ b/services/commands/src/main/webapp/WEB-INF/web.xml Wed Sep 13 13:32:57 2017 +0200 @@ -56,6 +56,10 @@ StaticResourcesServlet /v1/static/* + + StaticResourcesServlet + /v1/doc/* + com.redhat.thermostat.gateway.service.commands.servlet.SocketRegistrationListener @@ -69,7 +73,7 @@ Swagger API SPEC YAML File - /v1/static/doc/@com.redhat.thermostat.gateway.SERVICE_NAME@-swagger.yaml + /v1/doc/@com.redhat.thermostat.gateway.SERVICE_NAME@-swagger.yaml diff -r 8453ba17aa0f -r d4290a3f1e03 services/jvm-gc/src/main/resources/jvm-gc-swagger.yaml --- a/services/jvm-gc/src/main/resources/jvm-gc-swagger.yaml Mon Sep 18 16:03:05 2017 -0400 +++ b/services/jvm-gc/src/main/resources/jvm-gc-swagger.yaml Wed Sep 13 13:32:57 2017 +0200 @@ -194,11 +194,6 @@ in: path required: true type: string - jvm-id: - name: jvmId - in: path - required: true - type: string jvm-gc-stats: name: jvm-gc-stats in: body @@ -276,4 +271,4 @@ name: X-Thermostat-Realms type: string in: header - description: "Realms Header used to specify a subset of roles to use for Keycloak authorization. Attempts to specify realms that the client does not have, or no valiod realms at all will result in a 400 Bad Request response. Expects a space separated list of realms. Example 'X-Thermostat-Realms: realm-one realm-two'" \ No newline at end of file + description: "Realms Header used to specify a subset of roles to use for Keycloak authorization. Attempts to specify realms that the client does not have, or no valiod realms at all will result in a 400 Bad Request response. Expects a space separated list of realms. Example 'X-Thermostat-Realms: realm-one realm-two'" diff -r 8453ba17aa0f -r d4290a3f1e03 services/jvm-gc/src/main/webapp/WEB-INF/web.xml --- a/services/jvm-gc/src/main/webapp/WEB-INF/web.xml Mon Sep 18 16:03:05 2017 -0400 +++ b/services/jvm-gc/src/main/webapp/WEB-INF/web.xml Wed Sep 13 13:32:57 2017 +0200 @@ -81,7 +81,7 @@ Swagger API Spec File - /0.0.2/doc/@com.redhat.thermostat.gateway.SERVICE_NAME@-swagger.yaml + /0.0.3/doc/@com.redhat.thermostat.gateway.SERVICE_NAME@-swagger.yaml diff -r 8453ba17aa0f -r d4290a3f1e03 services/jvm-memory/src/main/webapp/WEB-INF/web.xml --- a/services/jvm-memory/src/main/webapp/WEB-INF/web.xml Mon Sep 18 16:03:05 2017 -0400 +++ b/services/jvm-memory/src/main/webapp/WEB-INF/web.xml Wed Sep 13 13:32:57 2017 +0200 @@ -81,7 +81,7 @@ Swagger API Spec File - /0.0.2/doc/@com.redhat.thermostat.gateway.SERVICE_NAME@-swagger.yaml + /0.0.3/doc/@com.redhat.thermostat.gateway.SERVICE_NAME@-swagger.yaml diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/commands/CommandsServiceIntegrationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/commands/CommandsServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * . + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gateway.service.commands; + +import com.redhat.thermostat.gateway.tests.integration.ServiceIntegrationTest; + +public class CommandsServiceIntegrationTest extends ServiceIntegrationTest { + + private static final String SERVICE_NAME = "commands"; + private static final String SERVICE_VERSION = "v1"; + + public CommandsServiceIntegrationTest() { + super("ignore-me"); + } + + @Override + public String getServiceVersion() { + return SERVICE_VERSION; + } + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + +} diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/compiler/JvmCompilerServiceIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/compiler/JvmCompilerServiceIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/compiler/JvmCompilerServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -40,10 +40,11 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import org.eclipse.jetty.http.HttpMethod; +import org.junit.Test; + import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; -import org.eclipse.jetty.http.HttpMethod; -import org.junit.Test; public class JvmCompilerServiceIntegrationTest extends MongoIntegrationTest { @@ -59,6 +60,16 @@ super(SERVICE_NAME + "/" + VERSION_NUMBER + "/systems/" + SYSTEM_ID + "/jvms/" + JVM_ID, SERVICE_NAME); } + @Override + public String getServiceVersion() { + return VERSION_NUMBER; + } + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + @Test public void testGetForJvms() throws InterruptedException, TimeoutException, ExecutionException { HttpTestUtil.testContentlessResponse(client, HttpMethod.GET, jvmsServiceUrl, 200, HttpTestUtil.EMPTY_RESPONSE); diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/cpu/JvmCpuServiceIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/cpu/JvmCpuServiceIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/cpu/JvmCpuServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -40,10 +40,11 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import org.eclipse.jetty.http.HttpMethod; +import org.junit.Test; + import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; -import org.eclipse.jetty.http.HttpMethod; -import org.junit.Test; public class JvmCpuServiceIntegrationTest extends MongoIntegrationTest { @@ -59,6 +60,16 @@ super(SERVICE_NAME + "/" + VERSION_NUMBER + "/systems/" + SYSTEM_ID + "/jvms/" + JVM_ID, SERVICE_NAME); } + @Override + public String getServiceVersion() { + return VERSION_NUMBER; + } + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + @Test public void testGetForJvms() throws InterruptedException, TimeoutException, ExecutionException { HttpTestUtil.testContentlessResponse(client, HttpMethod.GET, jvmsServiceUrl, 200, HttpTestUtil.EMPTY_RESPONSE); diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/gc/JvmGcServiceIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/gc/JvmGcServiceIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/gc/JvmGcServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -38,7 +38,6 @@ package com.redhat.thermostat.gateway.service.jvm.gc; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -50,13 +49,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import com.redhat.thermostat.gateway.common.core.auth.basic.BasicRealmAuthorizer; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.redhat.thermostat.gateway.common.mongodb.servlet.RequestParameters; -import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; import org.bson.Document; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; @@ -68,10 +60,17 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; import com.mongodb.Block; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; +import com.redhat.thermostat.gateway.common.core.auth.basic.BasicRealmAuthorizer; +import com.redhat.thermostat.gateway.common.mongodb.servlet.RequestParameters; +import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; public class JvmGcServiceIntegrationTest extends MongoIntegrationTest { @@ -120,6 +119,16 @@ super(serviceName + "/" + versionNumber, serviceName); } + @Override + public String getServiceVersion() { + return versionNumber; + } + + @Override + public String getServiceName() { + return serviceName; + } + private void makeHttpGetRequest(String url, String expectedResponse, int expectedStatus) throws InterruptedException, TimeoutException, ExecutionException { diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/io/JvmIoServiceIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/io/JvmIoServiceIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/io/JvmIoServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -36,12 +36,15 @@ package com.redhat.thermostat.gateway.service.jvm.io; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; -import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.util.StringContentProvider; @@ -49,14 +52,12 @@ import org.eclipse.jetty.http.HttpMethod; import org.junit.Test; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; +import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; public class JvmIoServiceIntegrationTest extends MongoIntegrationTest { @@ -101,6 +102,16 @@ this.returnedUrl = serviceUrl; } + @Override + public String getServiceVersion() { + return versionNumber; + } + + @Override + public String getServiceName() { + return serviceName; + } + @Test public void testGetUnknown() throws InterruptedException, TimeoutException, ExecutionException { getUnknown(getRandomSystemId(), getRandomJvmId()); diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryServiceIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryServiceIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvm/memory/JvmMemoryServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -36,19 +36,8 @@ package com.redhat.thermostat.gateway.service.jvm.memory; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.redhat.thermostat.gateway.service.jvm.gc.JvmGcServiceIntegrationTest; -import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; -import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; -import org.eclipse.jetty.client.api.ContentResponse; -import org.eclipse.jetty.client.api.Request; -import org.eclipse.jetty.client.util.StringContentProvider; -import org.eclipse.jetty.http.HttpHeader; -import org.eclipse.jetty.http.HttpMethod; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; @@ -56,17 +45,26 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.client.util.StringContentProvider; +import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpStatus; +import org.junit.Test; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; +import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; public class JvmMemoryServiceIntegrationTest extends MongoIntegrationTest { private static final String serviceName = "jvm-memory"; private static final String versionNumber = "0.0.3"; - private static final int HTTP_200_OK = 200; - private static final int HTTP_404_NOTFOUND = 404; - private static final String QUERY_PREFIX = "query"; private static final String LIMIT_PREFIX = "limit"; private static final String SORT_PREFIX = "sort"; @@ -94,7 +92,7 @@ private final String simpleUrl = baseUrl + "/" + serviceName + "/" + versionNumber; private final String serviceUrl = simpleUrl + "/systems/" + AGENT_ID + "/jvms/" + JVM_ID; - + private final String returnedUrl; public JvmMemoryServiceIntegrationTest() { @@ -102,6 +100,16 @@ this.returnedUrl = serviceUrl; } + @Override + public String getServiceVersion() { + return versionNumber; + } + + @Override + public String getServiceName() { + return serviceName; + } + @Test public void testGetUnknown() throws InterruptedException, TimeoutException, ExecutionException { getUnknown(getRandomSystemId(), getRandomJvmId()); @@ -608,7 +616,7 @@ final String contentStr = createJSON(ts); request.content(new StringContentProvider("{ \"set\" : " +contentStr + "}")); ContentResponse response = request.method(HttpMethod.PUT).send(); - assertEquals(HTTP_200_OK, response.getStatus()); + assertEquals(HttpStatus.OK_200, response.getStatus()); final String expected = ""; assertEquals(expected, response.getContentAsString()); return response; @@ -619,7 +627,7 @@ request.header(HttpHeader.CONTENT_TYPE, "application/json"); request.content(new StringContentProvider( '[' + createJSON() + ']')); ContentResponse response = request.method(HttpMethod.POST).send(); - assertEquals(HTTP_200_OK, response.getStatus()); + assertEquals(HttpStatus.OK_200, response.getStatus()); final String expected = ""; assertEquals(expected, response.getContentAsString()); return response; @@ -639,7 +647,7 @@ private ContentResponse get(final String systemid, final String jvmid) throws InterruptedException, ExecutionException, TimeoutException { ContentResponse response = client.newRequest(simpleUrl + "/systems/" + systemid + "/jvms/" + jvmid).method(HttpMethod.GET).send(); - assertEquals(HTTP_200_OK, response.getStatus()); + assertEquals(HttpStatus.OK_200, response.getStatus()); return response; } @@ -647,13 +655,13 @@ final Request rq = client.newRequest(simpleUrl + "/systems/" + systemid + "/jvms/" + jvmid + query); rq.method(HttpMethod.GET); ContentResponse response = rq.send(); - assertEquals(HTTP_200_OK, response.getStatus()); + assertEquals(HttpStatus.OK_200, response.getStatus()); return response; } private ContentResponse delete(final String systemid, final String jvmid) throws InterruptedException, ExecutionException, TimeoutException { ContentResponse response = client.newRequest(simpleUrl + "/systems/" + systemid + "/jvms/" + jvmid).method(HttpMethod.DELETE).send(); - assertEquals(HTTP_200_OK, response.getStatus()); + assertEquals(HttpStatus.OK_200, response.getStatus()); final String expected = ""; assertEquals(expected, response.getContentAsString()); return response; diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvms/JvmsServiceIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvms/JvmsServiceIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/jvms/JvmsServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -36,26 +36,28 @@ package com.redhat.thermostat.gateway.service.jvms; -import com.redhat.thermostat.gateway.tests.utils.ContentWrapper.Array; -import com.redhat.thermostat.gateway.tests.utils.ContentWrapper.Map; import static org.junit.Assert.assertEquals; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import com.redhat.thermostat.gateway.tests.utils.ContentWrapper; -import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; -import com.redhat.thermostat.gateway.tests.utils.ResponseSetWrapper; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.util.StringContentProvider; import org.eclipse.jetty.http.HttpMethod; import org.junit.Test; import com.redhat.thermostat.gateway.tests.integration.MongoIntegrationTest; +import com.redhat.thermostat.gateway.tests.utils.ContentWrapper; +import com.redhat.thermostat.gateway.tests.utils.ContentWrapper.Array; +import com.redhat.thermostat.gateway.tests.utils.ContentWrapper.Map; +import com.redhat.thermostat.gateway.tests.utils.HttpTestUtil; +import com.redhat.thermostat.gateway.tests.utils.ResponseSetWrapper; public class JvmsServiceIntegrationTest extends MongoIntegrationTest { - private static final String jvmsUrl = baseUrl + "/jvms/0.0.1"; + private static final String serviceName = "jvms"; + private static final String serviceVersion = "0.0.1"; + private static final String jvmsUrl = baseUrl + "/" + serviceName + "/" + serviceVersion; private static final ContentWrapper postDataWrapper = new ContentWrapper().addToResponse( Map.of("agentId", "aid", @@ -160,6 +162,16 @@ super(jvmsUrl, "jvm-info"); } + @Override + public String getServiceVersion() { + return serviceVersion; + } + + @Override + public String getServiceName() { + return serviceName; + } + @Test public void testGetEmpty() throws InterruptedException, TimeoutException, ExecutionException { String url = jvmsUrl + "/systems/1"; diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/cpu/SystemCPUIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/cpu/SystemCPUIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/cpu/SystemCPUIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -57,7 +57,8 @@ private static final String collectionName = "cpu-info"; private static final String versionString = "0.0.1"; - private static final String serviceURL = baseUrl + "/system-cpu/" + versionString; + private static final String serviceName = "system-cpu"; + private static final String serviceURL = baseUrl + "/" + serviceName + "/" + versionString; private static final String cpuInfoJSON = "{\n" + @@ -101,6 +102,16 @@ return cpuInfoJSON.replace(TIMESTAMP_TOKEN, Long.toString(ts)); } + @Override + public String getServiceVersion() { + return versionString; + } + + @Override + public String getServiceName() { + return serviceName; + } + protected List parse(ContentResponse contentResponse, final String expectedSystemId) { JsonParser parser = new JsonParser(); diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/memory/SystemMemoryIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/memory/SystemMemoryIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/memory/SystemMemoryIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -56,10 +56,11 @@ public class SystemMemoryIntegrationTest extends SystemIntegrationTestSuites { - + private static final String collectionName = "memory-info"; private static final String versionString = "0.0.1"; - private static final String serviceURL = baseUrl + "/system-memory/" + versionString; + private static final String serviceName = "system-memory"; + private static final String serviceURL = baseUrl + "/" + serviceName + "/" + versionString; private static final String TIMESTAMP_TOKEN = "$TIMESTAMP$"; private static final String AGENT_ID = getRandomSystemId(); private static final String memInfoJSON = @@ -103,6 +104,16 @@ super(serviceURL, collectionName); } + @Override + public String getServiceVersion() { + return versionString; + } + + @Override + public String getServiceName() { + return serviceName; + } + @Test public void testVersions() throws Exception { final String systemid = super.getRandomSystemId(); diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/network/SystemNetworkIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/network/SystemNetworkIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/system/network/SystemNetworkIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -57,7 +57,8 @@ private static final String collectionName = "network-info"; private static final String versionString = "0.0.1"; - private static final String serviceURL = baseUrl + "/system-network/" + versionString; + private static final String serviceName = "system-network"; + private static final String serviceURL = baseUrl + "/" + serviceName + "/" + versionString; private static final String memInfoJSON = "{\n" + " \"timeStamp\" : " + TIMESTAMP_TOKEN + ",\n" + @@ -98,6 +99,16 @@ super(serviceURL, collectionName); } + @Override + public String getServiceVersion() { + return versionString; + } + + @Override + public String getServiceName() { + return serviceName; + } + private static long getLong(JsonObject json, final String id) { JsonElement el = json.get(id); if (el.isJsonObject()) { diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/systems/SystemInfoIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/systems/SystemInfoIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/service/systems/SystemInfoIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -36,17 +36,8 @@ package com.redhat.thermostat.gateway.service.systems; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.redhat.thermostat.gateway.tests.integration.SystemIntegrationTest; -import com.redhat.thermostat.gateway.tests.integration.VersionTestUtil; -import org.eclipse.jetty.client.api.ContentResponse; -import org.eclipse.jetty.client.api.Request; -import org.eclipse.jetty.client.util.StringContentProvider; -import org.eclipse.jetty.http.HttpMethod; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; @@ -54,12 +45,22 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.client.util.StringContentProvider; +import org.eclipse.jetty.http.HttpMethod; +import org.junit.Test; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.redhat.thermostat.gateway.tests.integration.SystemIntegrationTest; +import com.redhat.thermostat.gateway.tests.integration.VersionTestUtil; public class SystemInfoIntegrationTest extends SystemIntegrationTest { - private static final String serviceName = "system-info"; + private static final String serviceName = "systems"; private static final String versionString = "0.0.1"; private static final String CPU_STRING1 = "Intel"; private static final String CPU_STRING2 = "AMD"; @@ -91,7 +92,17 @@ } public SystemInfoIntegrationTest() { - super("systems/" + versionString, serviceName); + super("systems/" + versionString, "system-info"); + } + + @Override + public String getServiceVersion() { + return versionString; + } + + @Override + public String getServiceName() { + return serviceName; } @Test diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/IntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/IntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/IntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -57,6 +57,11 @@ import com.redhat.thermostat.gateway.common.core.config.GlobalConfiguration; import com.redhat.thermostat.gateway.server.Start; +/** + * Integration tests base class. It's sole responsibility is it to start/stop + * the gateway service. + * + */ public class IntegrationTest { private static final ConfigurationFactory factory; @@ -90,7 +95,13 @@ startServer(); } - public static HttpClient createAndStartHttpClient() throws Exception { + @AfterClass + public static void afterClassIntegrationTest() throws Exception { + client.stop(); + stopServer(); + } + + static HttpClient createAndStartHttpClient() throws Exception { final HttpClient theclient; if (isTLSEnabled()) { SslContextFactory sslFactory = new SslContextFactory(); @@ -99,19 +110,11 @@ } else { theclient = new HttpClient(); } - AuthenticationStore authenticationStore = theclient.getAuthenticationStore(); - URI uri = URI.create(baseUrl); - String realmName = "Thermostat Realm"; // must match Basic login service's realm name. - authenticationStore.addAuthentication(new BasicAuthentication(uri, realmName, "agent", "agent-pwd")); + addAuthentication(theclient); theclient.start(); return theclient; } - private static boolean isTLSEnabled() { - Configuration config = factory.createGlobalConfiguration(); - return Boolean.parseBoolean((String)config.asMap().get(GlobalConfiguration.ConfigurationKey.WITH_TLS.name())); - } - private static Thread serverThread = null; private static Start serverObject = null; @@ -179,9 +182,32 @@ } } - @AfterClass - public static void afterClassIntegrationTest() throws Exception { - client.stop(); - stopServer(); + private static boolean isTLSEnabled() { + Configuration config = factory.createGlobalConfiguration(); + return Boolean.parseBoolean((String)config.asMap().get(GlobalConfiguration.ConfigurationKey.WITH_TLS.name())); + } + + /** + * Adds authentication credentials to the given client: {@code agent:agent-pwd}. + * @param theClient The HttpClient to operate on. + */ + protected static void addAuthentication(HttpClient theClient) { + AuthenticationStore authenticationStore = theClient.getAuthenticationStore(); + URI uri = URI.create(baseUrl); + String realmName = "Thermostat Realm"; // must match Basic login service's realm name. + authenticationStore.addAuthentication(new BasicAuthentication(uri, realmName, "agent", "agent-pwd")); } + + /** + * Removes authentication credentials from the given client. It also clears previous + * authentication results from it. + * + * @param theClient The HttpClient to operate on. + */ + protected static void removeAuthentication(HttpClient theClient) { + AuthenticationStore authStore = theClient.getAuthenticationStore(); + authStore.clearAuthentications(); + authStore.clearAuthenticationResults(); + } + } diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/MongoIntegrationTest.java --- a/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/MongoIntegrationTest.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/MongoIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -42,12 +42,13 @@ import java.nio.file.Path; import java.util.Objects; -import com.redhat.thermostat.gateway.tests.utils.MongodTestUtil; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -public class MongoIntegrationTest extends IntegrationTest { +import com.redhat.thermostat.gateway.tests.utils.MongodTestUtil; + +public abstract class MongoIntegrationTest extends ServiceIntegrationTest { protected static final MongodTestUtil mongodTestUtil = new MongodTestUtil(); diff -r 8453ba17aa0f -r d4290a3f1e03 tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/ServiceIntegrationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/integration-tests/src/test/java/com/redhat/thermostat/gateway/tests/integration/ServiceIntegrationTest.java Wed Sep 13 13:32:57 2017 +0200 @@ -0,0 +1,89 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * . + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gateway.tests.integration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpStatus; +import org.junit.Test; + +/** + * Base class for integration tests with swagger API docs. + * + */ +public abstract class ServiceIntegrationTest extends IntegrationTest { + + public ServiceIntegrationTest(String serviceUrl) { + super(serviceUrl); + } + + public abstract String getServiceVersion(); + + public abstract String getServiceName(); + + @Test(timeout = 5000) + public void verifySwaggerYamlAccessible() throws ExecutionException, InterruptedException, TimeoutException { + try { + removeAuthentication(client); // be sure to perform get with no authentication + String swaggerDocsUrl = getDocUrl(); + final Request request = client.newRequest(swaggerDocsUrl); + ContentResponse response = request.method(HttpMethod.GET).send(); + assertEquals("Expected OK response (no auth should be required). URL was: " + swaggerDocsUrl, HttpStatus.OK_200, response.getStatus()); + String actual = response.getContentAsString(); + assertNotNull(actual); + assertFalse(actual.isEmpty()); + assertTrue("service name expected to be part of swagger spec", actual.contains(getServiceName())); + assertTrue("service version expected to be part of swagger spec", actual.contains(getServiceVersion())); + } finally { + addAuthentication(client); + } + } + + private String getDocUrl() { + return baseUrl + "/" + getServiceName() + "/" + getServiceVersion() + "/doc/" + getServiceName() + "-swagger.yaml"; + } + +} diff -r 8453ba17aa0f -r d4290a3f1e03 tests/test-utils/src/main/java/com/redhat/thermostat/gateway/tests/utils/ContentWrapper.java --- a/tests/test-utils/src/main/java/com/redhat/thermostat/gateway/tests/utils/ContentWrapper.java Mon Sep 18 16:03:05 2017 -0400 +++ b/tests/test-utils/src/main/java/com/redhat/thermostat/gateway/tests/utils/ContentWrapper.java Wed Sep 13 13:32:57 2017 +0200 @@ -36,7 +36,7 @@ package com.redhat.thermostat.gateway.tests.utils; -import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.Arrays;