From 9d7352e0873d02b868b91e314e403341321c658e Mon Sep 17 00:00:00 2001 From: Katia Aresti Date: Mon, 5 Dec 2022 17:15:11 +0100 Subject: [PATCH] ISPN-14376 Retrieve console on any cache detail --- .../java/org/infinispan/rest/RestServer.java | 2 + .../rest/resources/StaticResourceTest.java | 47 ++++++++++--------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/server/rest/src/main/java/org/infinispan/rest/RestServer.java b/server/rest/src/main/java/org/infinispan/rest/RestServer.java index 34f7efb9ff28..bf542a76e066 100644 --- a/server/rest/src/main/java/org/infinispan/rest/RestServer.java +++ b/server/rest/src/main/java/org/infinispan/rest/RestServer.java @@ -157,6 +157,8 @@ protected void startInternal() { if (!path.contains(".")) return StaticContentResource.DEFAULT_RESOURCE; return path; })); + // if the cache name contains '.' we need to retrieve the console and access to the cache detail. See ISPN-14376 + resourceManager.registerResource(rootContext, new StaticContentResource(console, "console/cache/", (path, resource) -> StaticContentResource.DEFAULT_RESOURCE)); resourceManager.registerResource(rootContext, new RedirectResource(rootContext, rootContext + "console/welcome", true)); } if (adminEndpoint) { diff --git a/server/rest/src/test/java/org/infinispan/rest/resources/StaticResourceTest.java b/server/rest/src/test/java/org/infinispan/rest/resources/StaticResourceTest.java index 94fa2bc0ab4b..ecf42ab4bc65 100644 --- a/server/rest/src/test/java/org/infinispan/rest/resources/StaticResourceTest.java +++ b/server/rest/src/test/java/org/infinispan/rest/resources/StaticResourceTest.java @@ -9,6 +9,7 @@ import static org.infinispan.commons.dataconversion.MediaType.TEXT_HTML; import static org.infinispan.commons.dataconversion.MediaType.TEXT_PLAIN; import static org.infinispan.rest.RequestHeader.IF_MODIFIED_SINCE; +import static org.infinispan.rest.assertion.ResponseAssertion.assertThat; import static org.infinispan.util.concurrent.CompletionStages.join; import static org.testng.Assert.assertEquals; import static org.testng.AssertJUnit.assertNotNull; @@ -87,7 +88,7 @@ public Object[] factory() { @Test public void testGetFile() { RestResponse response = call("/static/nonexistent.html"); - ResponseAssertion.assertThat(response).isNotFound(); + assertThat(response).isNotFound(); response = call("/static"); assertResponse(response, "static-test/index.html", "

Hello

", TEXT_HTML); @@ -107,39 +108,43 @@ public void testConsole() { RestResponse response1 = call("/console/page.htm"); RestResponse response2 = call("/console/folder/test.css"); RestResponse response3 = call("/console"); + RestResponse response4 = call("/console/cache/people"); + RestResponse response5 = call("/console/cache/peo.ple"); assertResponse(response1, "static-test/console/page.htm", "console", TEXT_HTML); assertResponse(response2, "static-test/console/folder/test.css", ".a", TEXT_CSS); - ResponseAssertion.assertThat(response2).isOk(); + assertThat(response2).isOk(); assertResponse(response3, "static-test/console/index.html", "console", TEXT_HTML); + assertThat(response4).isOk(); + assertThat(response5).isOk(); RestResponse response = call("/console/"); - ResponseAssertion.assertThat(response).isOk(); + assertThat(response).isOk(); response = call("/console/create"); - ResponseAssertion.assertThat(response).isOk(); + assertThat(response).isOk(); response = call("/notconsole/"); - ResponseAssertion.assertThat(response).isNotFound(); + assertThat(response).isNotFound(); } private void assertResponse(RestResponse response, String path, String returnedText, MediaType... possibleTypes) { - ResponseAssertion.assertThat(response).isOk(); - ResponseAssertion.assertThat(response).hasMediaType(possibleTypes); - ResponseAssertion.assertThat(response).containsReturnedText(returnedText); + assertThat(response).isOk(); + assertThat(response).hasMediaType(possibleTypes); + assertThat(response).containsReturnedText(returnedText); assertCacheHeaders(path, response); - ResponseAssertion.assertThat(response).hasValidDate(); + assertThat(response).hasValidDate(); } private void assertCacheHeaders(String path, RestResponse response) { int expireDuration = 60 * 60 * 24 * 31; File test = getTestFile(path); assertNotNull(test); - ResponseAssertion.assertThat(response).hasContentLength(test.length()); - ResponseAssertion.assertThat(response).hasLastModified(test.lastModified()); - ResponseAssertion.assertThat(response).hasCacheControlHeaders("private, max-age=" + expireDuration); - ResponseAssertion.assertThat(response).expiresAfter(expireDuration); + assertThat(response).hasContentLength(test.length()); + assertThat(response).hasLastModified(test.lastModified()); + assertThat(response).hasCacheControlHeaders("private, max-age=" + expireDuration); + assertThat(response).expiresAfter(expireDuration); } @Test @@ -149,24 +154,24 @@ public void testCacheHeaders() { RestResponse response = call(path, DateUtils.toRFC1123(lastModified)); - ResponseAssertion.assertThat(response).isNotModified(); - ResponseAssertion.assertThat(response).hasNoContent(); + assertThat(response).isNotModified(); + assertThat(response).hasNoContent(); response = call(path, "Sun, 15 Aug 1971 15:00:00 GMT"); - ResponseAssertion.assertThat(response).isOk(); - ResponseAssertion.assertThat(response).containsReturnedText("

Hello

"); + assertThat(response).isOk(); + assertThat(response).containsReturnedText("

Hello

"); response = call(path, DateUtils.toRFC1123(System.currentTimeMillis())); - ResponseAssertion.assertThat(response).isNotModified(); - ResponseAssertion.assertThat(response).hasNoContent(); + assertThat(response).isNotModified(); + assertThat(response).hasNoContent(); } @Test public void testRedirect() { RestResponse response = join(noRedirectsClient.raw().get("/")); - ResponseAssertion.assertThat(response).isRedirect(); - ResponseAssertion.assertThat(response).hasNoContent(); + assertThat(response).isRedirect(); + assertThat(response).hasNoContent(); assertEquals("/console/welcome", response.headers().get("Location").get(0)); }