Skip to content

Commit

Permalink
Add new test case
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Pinchuk <alexander.v.pinchuk@gmail.com>
  • Loading branch information
avpinchuk committed Mar 14, 2023
1 parent dd35598 commit 4f45ba5
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@
import jakarta.ws.rs.core.Response;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.glassfish.main.itest.tools.DomainAdminRestClient;
import org.glassfish.main.itest.tools.asadmin.AsadminResult;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN;
import static org.glassfish.main.itest.tools.GlassFishTestEnvironment.getAsadmin;
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertAll;

Expand All @@ -39,6 +43,7 @@
*/
public class LoggingRestITest extends RestTestBase {

private static final String URL_VIEW_LOG = "/domain/view-log";
private static final String URL_VIEW_LOG_DETAILS = "/domain/view-log/details";
private static final String URL_LOGNAMES = "/domain/view-log/details/lognames";

Expand All @@ -50,6 +55,26 @@ public static void fillUpLog() {
assertThat(result, asadminOK());
}

@Test
public void viewLog() {
try (ViewLogClient client = new ViewLogClient()) {
// Read entire log
Response response = client.get(URL_VIEW_LOG);
assertThat(response.getStatus(), equalTo(200));
// Should not be empty
assertThat(response.readEntity(String.class), not(emptyOrNullString()));

// Get the entire URL to return the changes since the last call
String nextUrl = response.getHeaderString("X-Text-Append-Next");
assertThat(nextUrl, not(emptyOrNullString()));

// Because log unchanged, response should be empty
response = client.get(nextUrl);
assertThat(response.getStatus(), equalTo(200));
assertThat(response.readEntity(String.class), emptyOrNullString());
}
}

@Test
public void logFileNames() throws Exception {
Response response = managementClient.get(URL_LOGNAMES, Map.of("instanceName", "server"));
Expand Down Expand Up @@ -79,4 +104,19 @@ static JSONObject readJsonObjectFrom(Response response) {
static JSONArray getJsonArrayFrom(Response response, String name) throws Exception {
return readJsonObjectFrom(response).getJSONArray(name);
}

private static final class ViewLogClient extends DomainAdminRestClient {

public ViewLogClient() {
super("", TEXT_PLAIN);
}

@Override
public Response get(String url) {
if (url.startsWith("/")) {
url = getBaseAdminUrl() + CONTEXT_ROOT_MANAGEMENT + url;
}
return super.get(url);
}
}
}

0 comments on commit 4f45ba5

Please sign in to comment.