/** * Perform a OPTIONS request to a <code>uri</code>. * * @param uri The uri to send the request to. * @return The response of the request. */ public static Response options(URI uri) { return given().options(uri); }
/** * Perform a OPTIONS request to the statically configured path (by default <code>http://localhost:8080</code>). * * @return The response of the request. */ public static Response options() { return given().options(); }
/** * Perform a OPTIONS request to a <code>path</code>. Normally the path doesn't have to be fully-qualified e.g. you don't need to * specify the path as <tt>http://localhost:8080/path</tt>. In this case it's enough to use <tt>/path</tt>. * * @param path The path to send the request to. * @param pathParams The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do <code>head("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);</code>. * @return The response of the request. */ public static Response options(String path, Object... pathParams) { return given().options(path, pathParams); }
/** * Perform a OPTIONS request to a <code>path</code>. Normally the path doesn't have to be fully-qualified e.g. you don't need to * specify the path as <tt>http://localhost:8080/path</tt>. In this case it's enough to use <tt>/path</tt>. * * @param path The path to send the request to. * @param pathParams The path parameters. * @return The response of the request. */ public static Response options(String path, Map<String, ?> pathParams) { return given().options(path, pathParams); }
/** * Perform a OPTIONS request to a <code>url</code>. * * @param url The url to send the request to. * @return The response of the request. */ public static Response options(URL url) { return given().options(url); }
@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(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(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(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(29) public void testNonStandardUnitsJSON() { Header wantJSONFormat = new Header("Accept", APPLICATION_JSON); given().header(wantJSONFormat).options("/metrics/application/jellybeanHistogram").then().statusCode(200) .body("jellybeanHistogram.unit", equalTo("jellybeans")); }
@Test @RunAsClient @InSequence(21) public void testApplicationTagJson() { JsonPath jsonPath = given().header("Accept", APPLICATION_JSON) .when() .options("/metrics/application/purple").jsonPath(); String tags = jsonPath.getString("purple.tags"); assertNotNull(tags); assertTrue(tags.contains("app=myShop")); assertTrue(tags.contains("tier=integration")); }
@Test @RunAsClient @InSequence(27) public void testPrometheus406ForOptions() { given() .header("Accept", TEXT_PLAIN) .when() .options("/metrics/application/metricTest.test1.histogram2") .then() .statusCode(406); }
@Test @RunAsClient @InSequence(16) public void testApplicationMetadataOkJson() { Header wantJson = new Header("Accept", APPLICATION_JSON); Response response = given().header(wantJson).options("/metrics/application"); int code = response.getStatusCode(); assertTrue(code == 200 || code == 204); }
@Test @RunAsClient @InSequence(12) public void testBaseMetadataTypeAndUnit() { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath(); Map<String, Map<String, Object>> elements = jsonPath.getMap("."); Map<String, MiniMeta> expectedMetadata = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE); checkMetadataPresent(elements, expectedMetadata); }
@Test @RunAsClient @InSequence(10) public void testBaseMetadata() { Header wantJson = new Header("Accept", APPLICATION_JSON); given().header(wantJson).options("/metrics/base").then().statusCode(200).and() .contentType(MpMetricTest.APPLICATION_JSON); }
@Test @RunAsClient @InSequence(20) public void testApplicationMetadataTypeAndUnit() { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).options("/metrics/application").jsonPath(); Map<String, Map<String, Object>> elements = jsonPath.getMap("."); Map<String, MiniMeta> expectedMetadata = getExpectedMetadataFromXmlFile(MetricRegistry.Type.APPLICATION); checkMetadataPresent(elements, expectedMetadata); }