private static String toString(Headers headers) { if (!headers.exist()) { return ""; } final StringBuilder builder = new StringBuilder(); for (Header header : headers) { builder.append(header.getName()).append(HEADER_NAME_AND_VALUE_SEPARATOR).append(header.getValue()).append("\n"); } builder.deleteCharAt(builder.length() - 1); return builder.toString(); }
/** * Set a specific header * * @return The builder */ public ResponseBuilder setHeader(String name, String value) { notNull(name, "Header name"); notNull(value, "Header value"); List<Header> newHeaders = new ArrayList<Header>(restAssuredResponse.headers().asList()); newHeaders.add(new Header(name, value)); restAssuredResponse.setResponseHeaders(new Headers(newHeaders)); if (trim(name).equalsIgnoreCase(CONTENT_TYPE)) { restAssuredResponse.setContentType(value); } return this; }
protected boolean hasReturnRepresentation(List<Header> preferenceAppliedHeaders) { for (Header h : preferenceAppliedHeaders) { // Handle optional whitespace, quoted preference token values, and // other tokens in the Preference-Applied response header. if (h.getValue().matches("(^|[ ;])return *= *\"?representation\"?($|[ ;])")) { return true; } } return false; }
public boolean hasSameNameAs(Header header) { AssertParameter.notNull(header, Header.class); return this.name.equalsIgnoreCase(header.getName()); }
final String value = linkHeader.getValue();
@Test @RunAsClient @InSequence(19) public void testApplicationMetadataItems() { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).options("/metrics/application").jsonPath(); Map<String, Object> elements = jsonPath.getMap("."); List<String> missing = new ArrayList<>(); Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.APPLICATION); for (String item : names.keySet()) { if (!elements.containsKey(item)) { missing.add(item); } } assertTrue("Following application items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty()); }
@BeforeClass(alwaysRun = true) public void determineOptions() { String uri = getResourceUri(); if (StringUtils.isNotBlank(uri)) { // Use HTTP OPTIONS, which MUST be supported by LDP servers, to determine what methods are supported on this container. Response optionsResponse = buildBaseRequestSpecification().options(uri); Headers headers = optionsResponse.getHeaders(); List<Header> allowHeaders = headers.getList(ALLOW); for (Header allowHeader : allowHeaders) { String allow = allowHeader.getValue(); if (allow != null) { String[] methods = allow.split("\\s*,\\s*"); for (String method : methods) { options.add(method); } } } } }
@Test @RunAsClient @InSequence(8) public void testBaseSingularMetricsPresent() { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).get("/metrics/base").jsonPath(); Map<String, Object> elements = jsonPath.getMap("."); List<String> missing = new ArrayList<>(); Map<String, MiniMeta> baseNames = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE); for (String item : baseNames.keySet()) { if (item.startsWith("gc.")) { continue; } if (!elements.containsKey(item) && !baseNames.get(item).optional) { missing.add(item); } } assertTrue("Following base items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty()); }
@Test @RunAsClient @InSequence(11) public void testBaseMetadataSingluarItems() { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath(); Map<String, Object> elements = jsonPath.getMap("."); List<String> missing = new ArrayList<>(); Map<String, MiniMeta> baseNames = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE); for (String item : baseNames.keySet()) { if (item.startsWith("gc.") || baseNames.get(item).optional) { continue; } if (!elements.containsKey(item)) { missing.add(item); } } assertTrue("Following base items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty()); }
@Test @RunAsClient @InSequence(4) public void testListsAllJson() { Header acceptHeader = new Header("Accept", APPLICATION_JSON); Map response = given().header(acceptHeader).when().get("/metrics").as(Map.class); // all servers should have some base metrics assertTrue(response.containsKey("base")); // There may be application metrics, so check if the key exists and bail if it has no data if (response.containsKey("application")) { Map applicationData = (Map) response.get("application"); assertThat(applicationData.size(), greaterThan(0)); } // There may be vendor metrics, so check if the key exists and bail if it has no data if (response.containsKey("vendor")) { Map vendorData = (Map) response.get("vendor"); assertThat(vendorData.size(), greaterThan(0)); } }
@Test @RunAsClient @InSequence(15) public void testBaseMetadataGarbageCollection() throws Exception { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath(); int count = 0; Map<String, Object> elements = jsonPath.getMap("."); for (String name : elements.keySet()) { if (name.startsWith("gc.")) { assertTrue(name.endsWith(".count") || name.endsWith(".time")); count++; } } assertThat(count, greaterThan(0)); }
@Test @RunAsClient @InSequence(13) public void testPrometheusFormatNoBadChars() throws Exception { Header wantPrometheusFormat = new Header("Accept", TEXT_PLAIN); String data = given().header(wantPrometheusFormat).get("/metrics/base").asString(); String[] lines = data.split("\n"); for (String line : lines) { if (line.startsWith("#")) { continue; } String[] tmp = line.split(" "); assertEquals(tmp.length, 2); assertFalse("Line has illegal chars " + line, tmp[0].matches("[-.]")); assertFalse("Found __ in " + line, tmp[0].matches("__")); } }
@Test @RunAsClient @InSequence(31) public void testOptionalBaseMetrics() { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath(); Map<String, Object> elements = jsonPath.getMap("."); Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE); for (String item : names.keySet()) { if (elements.containsKey(item) && names.get(item).optional) { String prefix = names.get(item).name; String type = "\""+prefix+"\""+".type"; String unit= "\""+prefix+"\""+".unit"; given().header(wantJson).options("/metrics/base/"+prefix).then().statusCode(200) .body(type, equalTo(names.get(item).type)) .body(unit, equalTo(names.get(item).unit)); } } }
@Test @RunAsClient @InSequence(2) public void testSharedCounter() { Header acceptJson = new Header("Accept", APPLICATION_JSON); given().header(acceptJson).get("/metrics/application").then() .assertThat().body("countMe2", equalTo(1)) .assertThat().body("'org.eclipse.microprofile.metrics.test.MetricAppBean2.meterMe2'.count", equalTo(1)) .assertThat().body("timeMe2.count", equalTo(1)); }
@InSequence(14) public void testBaseMetadataSingluarItemsPrometheus() { Header wantPrometheusFormat = new Header("Accept", TEXT_PLAIN);
@Test @RunAsClient @InSequence(30) public void testNonStandardUnitsPrometheus() { String prefix = "jellybean_histogram_"; Header wantPrometheusFormat = new Header("Accept", TEXT_PLAIN); given().header(wantPrometheusFormat).get("/metrics/application/jellybeanHistogram").then().statusCode(200) .and() .body(containsString(prefix + "jellybeans_count")) .body(containsString("# TYPE application:" + prefix + "jellybeans summary")) .body(containsString(prefix + "mean_jellybeans")) .body(containsString(prefix + "min_jellybeans")) .body(containsString(prefix + "max_jellybeans")) .body(containsString(prefix + "stddev_jellybeans")) .body(containsString(prefix + "jellybeans{tier=\"integration\",quantile=\"0.5\"}")) .body(containsString(prefix + "jellybeans{tier=\"integration\",quantile=\"0.75\"}")) .body(containsString(prefix + "jellybeans{tier=\"integration\",quantile=\"0.95\"}")) .body(containsString(prefix + "jellybeans{tier=\"integration\",quantile=\"0.98\"}")) .body(containsString(prefix + "jellybeans{tier=\"integration\",quantile=\"0.99\"}")) .body(containsString(prefix + "jellybeans{tier=\"integration\",quantile=\"0.999\"}")); }
@Test @RunAsClient @InSequence(4) public void testSharedCounterAgain() { Header acceptJson = new Header("Accept", APPLICATION_JSON); given().header(acceptJson).get("/metrics/application").then() .assertThat().body("countMe2", equalTo(2)) .assertThat().body("'org.eclipse.microprofile.metrics.test.MetricAppBean2.meterMe2'.count", equalTo(2)) .assertThat().body("timeMe2.count", equalTo(2)); }
@Test @RunAsClient @InSequence(6) public void testReusedHistogram() { Header acceptJson = new Header("Accept", APPLICATION_JSON); given().header(acceptJson).get("/metrics/application").then() .assertThat().body("reusableHisto.count", equalTo(2)) .assertThat().body("reusableHisto.min", equalTo(1)) .assertThat().body("reusableHisto.max", equalTo(3)); }