Skip to content

Commit

Permalink
ISPN-14376 Retrieve console on any cache detail
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Dec 5, 2022
1 parent 9a7feb1 commit 9d7352e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
2 changes: 2 additions & 0 deletions server/rest/src/main/java/org/infinispan/rest/RestServer.java
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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", "<h1>Hello</h1>", TEXT_HTML);
Expand All @@ -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
Expand All @@ -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("<h1>Hello</h1>");
assertThat(response).isOk();
assertThat(response).containsReturnedText("<h1>Hello</h1>");

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));
}

Expand Down

0 comments on commit 9d7352e

Please sign in to comment.