Skip to content

Commit

Permalink
[WFLY-11594] Prepare tests for MicroProfile Metrics issues 32,33 and 34
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Terem authored and marekkopecky committed Feb 4, 2019
1 parent 0f8d582 commit 5b1677c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
Expand Up @@ -24,6 +24,7 @@

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpOptions;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
Expand All @@ -49,18 +50,28 @@ public class MicroProfileMetricsMetadataTestCase {
@ContainerResource
ManagementClient managementClient;

@Test
public void testJsonHeader() throws Exception {
final String endpointURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/metrics";
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpOptions request = new HttpOptions(endpointURL);
request.setHeader("Accept", String.valueOf(ContentType.APPLICATION_JSON));
CloseableHttpResponse resp = client.execute(request);
assertEquals(200, resp.getStatusLine().getStatusCode());
}
}

@Test
public void testNoJsonHeader() throws Exception {
final String endpointURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/metrics";
try (CloseableHttpClient client = HttpClients.createDefault()) {

CloseableHttpResponse resp = client.execute(new HttpOptions(endpointURL));

assertEquals(406, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'No exporter found for method OPTIONS and media type' message is expected, but was: " + content,
content.contains("No exporter found for method OPTIONS and media type"));
assertTrue("'OPTIONS method is only allowed with application/json media type.' message is expected, but was: " + content,
content.contains("OPTIONS method is only allowed with application/json media type."));
}
}

Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.apache.http.client.methods.HttpTrace;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
Expand All @@ -41,13 +42,16 @@
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(Arquillian.class)
@RunAsClient
public class MicroProfileMetricsRequestMethodsTestCase {
@ContainerResource
ManagementClient managementClient;

private static final String EXPECTED_RESPONSE_MESSAGE = "Only GET and OPTIONS methods are accepted.";

@Test
public void checkOptions() throws Exception {
final String endpointURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/metrics";
Expand All @@ -74,7 +78,7 @@ public void checkHead() throws Exception {

try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpHead(endpointURL));
assertEquals(406, resp.getStatusLine().getStatusCode());
assertEquals(405, resp.getStatusLine().getStatusCode());
}
}
@Test
Expand All @@ -83,7 +87,11 @@ public void checkPost() throws Exception {

try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpPost(endpointURL));
assertEquals(406, resp.getStatusLine().getStatusCode());
assertEquals(405, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'"+ EXPECTED_RESPONSE_MESSAGE + "' message is expected, but was: " + content,
content.contains(EXPECTED_RESPONSE_MESSAGE));
}
}
@Test
Expand All @@ -92,7 +100,11 @@ public void checkPut() throws Exception {

try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpPut(endpointURL));
assertEquals(406, resp.getStatusLine().getStatusCode());
assertEquals(405, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'"+ EXPECTED_RESPONSE_MESSAGE + "' message is expected, but was: " + content,
content.contains(EXPECTED_RESPONSE_MESSAGE));
}
}
@Test
Expand All @@ -101,7 +113,11 @@ public void checkDelete() throws Exception {

try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpDelete(endpointURL));
assertEquals(406, resp.getStatusLine().getStatusCode());
assertEquals(405, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'"+ EXPECTED_RESPONSE_MESSAGE + "' message is expected, but was: " + content,
content.contains(EXPECTED_RESPONSE_MESSAGE));
}
}
@Test
Expand All @@ -110,7 +126,11 @@ public void checkTrace() throws Exception {

try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpTrace(endpointURL));
assertEquals(406, resp.getStatusLine().getStatusCode());
assertEquals(405, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'"+ EXPECTED_RESPONSE_MESSAGE + "' message is expected, but was: " + content,
content.contains(EXPECTED_RESPONSE_MESSAGE));
}
}
@Test
Expand All @@ -119,7 +139,11 @@ public void checkPatch() throws Exception {

try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpPatch(endpointURL));
assertEquals(406, resp.getStatusLine().getStatusCode());
assertEquals(405, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'"+ EXPECTED_RESPONSE_MESSAGE + "' message is expected, but was: " + content,
content.contains(EXPECTED_RESPONSE_MESSAGE));
}
}

Expand Down

0 comments on commit 5b1677c

Please sign in to comment.