io.restassured.path.json.JsonPath Java Examples
The following examples show how to use
io.restassured.path.json.JsonPath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserQuotaRoutesTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getQuotaShouldReturnBothWhenValueSpecifiedAndEscaped(WebAdminQuotaSearchTestSystem testSystem) throws MailboxException { MaxQuotaManager maxQuotaManager = testSystem.getQuotaSearchTestSystem().getMaxQuotaManager(); UserQuotaRootResolver userQuotaRootResolver = testSystem.getQuotaSearchTestSystem().getQuotaRootResolver(); int maxStorage = 42; int maxMessage = 52; maxQuotaManager.setMaxStorage(userQuotaRootResolver.forUser(BOB), QuotaSizeLimit.size(maxStorage)); maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCountLimit.count(maxMessage)); JsonPath jsonPath = when() .get(QUOTA_USERS + "/" + ESCAPED_BOB.asString()) .then() .statusCode(HttpStatus.OK_200) .contentType(ContentType.JSON) .extract() .jsonPath(); SoftAssertions softly = new SoftAssertions(); softly.assertThat(jsonPath.getLong("user." + SIZE)).isEqualTo(maxStorage); softly.assertThat(jsonPath.getLong("user." + COUNT)).isEqualTo(maxMessage); softly.assertAll(); }
Example #2
Source File: UserQuotaRoutesTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getQuotaShouldReturnBothWhenNoSize(WebAdminQuotaSearchTestSystem testSystem) throws MailboxException { MaxQuotaManager maxQuotaManager = testSystem.getQuotaSearchTestSystem().getMaxQuotaManager(); UserQuotaRootResolver userQuotaRootResolver = testSystem.getQuotaSearchTestSystem().getQuotaRootResolver(); int maxMessage = 42; maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCountLimit.count(maxMessage)); JsonPath jsonPath = when() .get(QUOTA_USERS + "/" + BOB.asString()) .then() .statusCode(HttpStatus.OK_200) .contentType(ContentType.JSON) .extract() .jsonPath(); SoftAssertions softly = new SoftAssertions(); softly.assertThat(jsonPath.getObject("user." + SIZE, Long.class)).isNull(); softly.assertThat(jsonPath.getLong("user." + COUNT)).isEqualTo(maxMessage); softly.assertAll(); }
Example #3
Source File: GlobalQuotaRoutesTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getQuotaShouldReturnBothWhenValueSpecified() throws Exception { int maxStorage = 42; int maxMessage = 52; maxQuotaManager.setGlobalMaxStorage(QuotaSizeLimit.size(maxStorage)); maxQuotaManager.setGlobalMaxMessage(QuotaCountLimit.count(maxMessage)); JsonPath jsonPath = when() .get("/quota") .then() .statusCode(HttpStatus.OK_200) .contentType(ContentType.JSON) .extract() .jsonPath(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(jsonPath.getLong("size")).isEqualTo(maxStorage); softly.assertThat(jsonPath.getLong("count")).isEqualTo(maxMessage); }); }
Example #4
Source File: CrawlTestBase.java From fess with Apache License 2.0 | 6 votes |
protected static void deleteDocuments(final String queryString) { List<String> docIds = new ArrayList<>(); Response response = given().contentType("application/json").param("scroll", "1m").param("q", queryString) .get(getEsUrl() + "/" + DOC_INDEX_NAME + "/" + DOC_TYPE_NAME + "/_search"); JsonPath jsonPath = JsonPath.from(response.asString()); String scrollId = jsonPath.getString("_scroll_id"); while (true) { List<String> resultIds = jsonPath.getList("hits.hits._id"); if (resultIds.size() == 0) { break; } docIds.addAll(resultIds); Map<String, Object> scrollBody = new HashMap<>(); scrollBody.put("scroll", "1m"); scrollBody.put("scroll_id", scrollId); response = given().contentType("application/json").body(scrollBody).get(getEsUrl() + "/_search/scroll"); jsonPath = JsonPath.from(response.asString()); } for (String docId : docIds) { given().contentType("application/json").delete(getEsUrl() + "/" + DOC_INDEX_NAME + "/" + DOC_TYPE_NAME + "/" + docId); } }
Example #5
Source File: GlobalQuotaRoutesTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getQuotaShouldReturnNothingWhenNothingSet() { JsonPath jsonPath = when() .get("/quota") .then() .statusCode(HttpStatus.OK_200) .contentType(ContentType.JSON) .extract() .jsonPath(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(jsonPath.getObject("size", Long.class)).isNull(); softly.assertThat(jsonPath.getObject("count", Long.class)).isNull(); }); }
Example #6
Source File: FileTest.java From camel-quarkus with Apache License 2.0 | 6 votes |
private static void awaitEvent(final Path dir, final Path file, final String type) { Awaitility.await() .pollInterval(10, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .until(() -> { final ValidatableResponse response = RestAssured.given() .queryParam("path", dir.toString()) .get("/file-watch/get-events") .then(); switch (response.extract().statusCode()) { case 204: /* * the event may come with some delay through all the OS and Java layers so it is * rather normal to get 204 before getting the expected event */ return false; case 200: final JsonPath json = response .extract() .jsonPath(); return file.toString().equals(json.getString("path")) && type.equals(json.getString("type")); default: throw new RuntimeException("Unexpected status code " + response.extract().statusCode()); } }); }
Example #7
Source File: ReactiveStreamsTest.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Test public void reactiveStreamsService() { JsonPath result = RestAssured.get("/reactive-streams/inspect") .then() .statusCode(200) .extract() .body() .jsonPath(); assertThat(result.getString("reactive-streams-component-type")).isEqualTo( "org.apache.camel.quarkus.component.reactive.streams.ReactiveStreamsRecorder$QuarkusReactiveStreamsComponent"); assertThat(result.getString("reactive-streams-component-backpressure-strategy")).isEqualTo( "LATEST"); assertThat(result.getString("reactive-streams-endpoint-backpressure-strategy")).isEqualTo( "BUFFER"); assertThat(result.getString("reactive-streams-service-type")).isEqualTo( "org.apache.camel.component.reactive.streams.engine.DefaultCamelReactiveStreamsService"); assertThat(result.getString("reactive-streams-service-factory-type")).isEqualTo( "org.apache.camel.component.reactive.streams.engine.DefaultCamelReactiveStreamsServiceFactory"); }
Example #8
Source File: CoreMainXmlIoTest.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Test public void testMainInstanceWithXmlRoutes() { JsonPath p = RestAssured.given() .accept(MediaType.APPLICATION_JSON) .get("/test/main/describe") .then() .statusCode(200) .extract() .body() .jsonPath(); assertThat(p.getString("xml-loader")).isEqualTo(ModelParserXMLRoutesDefinitionLoader.class.getName()); assertThat(p.getString("xml-model-dumper")).isEqualTo(DisabledModelToXMLDumper.class.getName()); assertThat(p.getString("xml-model-factory")).isEqualTo(DisabledModelJAXBContextFactory.class.getName()); assertThat(p.getList("routeBuilders", String.class)) .isEmpty(); assertThat(p.getList("routes", String.class)) .contains("my-xml-route"); }
Example #9
Source File: GlobalQuotaRoutesTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getQuotaShouldReturnOnlyCountWhenNoSize() throws Exception { int maxMessage = 42; maxQuotaManager.setGlobalMaxMessage(QuotaCountLimit.count(maxMessage)); JsonPath jsonPath = when() .get("/quota") .then() .statusCode(HttpStatus.OK_200) .contentType(ContentType.JSON) .extract() .jsonPath(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(jsonPath.getObject("size", Long.class)).isNull(); softly.assertThat(jsonPath.getLong("count")).isEqualTo(maxMessage); }); }
Example #10
Source File: CoreMainXmlJaxbTest.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Test public void testMainInstanceWithXmlRoutes() { JsonPath p = RestAssured.given() .accept(MediaType.APPLICATION_JSON) .get("/test/main/describe") .then() .statusCode(200) .extract() .body() .jsonPath(); assertThat(p.getString("xml-loader")).isEqualTo(ModelParserXMLRoutesDefinitionLoader.class.getName()); assertThat(p.getString("xml-model-dumper")).isEqualTo(JaxbModelToXMLDumper.class.getName()); assertThat(p.getString("xml-model-factory")).isEqualTo("org.apache.camel.xml.jaxb.DefaultModelJAXBContextFactory"); assertThat(p.getList("routeBuilders", String.class)) .isEmpty(); assertThat(p.getList("routes", String.class)) .contains("my-xml-route"); }
Example #11
Source File: SearchApiTests.java From fess with Apache License 2.0 | 6 votes |
@Test public void searchTestWithSort() throws Exception { String sortField = "content_length"; Map<String, String> params = new HashMap<>(); params.put("q", "*"); params.put("sort", sortField + ".asc"); params.put("num", "100"); String response = checkMethodBase(new HashMap<>()).params(params).get("/json").asString(); assertTrue(JsonPath.from(response).getInt("response.record_count") > 10); List<Map<String, Object>> docs = JsonPath.from(response).getList("response.result"); int prevVal = 0; for (Map<String, Object> doc : docs) { int sortValue = Integer.parseInt(doc.get(sortField).toString()); assertTrue(sortValue >= prevVal); prevVal = sortValue; } }
Example #12
Source File: GatewayHealthFuncTest.java From knox with Apache License 2.0 | 6 votes |
@Test(timeout = TestUtils.MEDIUM_TIMEOUT) public void testMetricsResource() { TestUtils.LOG_ENTER(); String username = "guest"; String password = "guest-password"; String serviceUrl = clusterUrl + "/v1/metrics"; String body = given() .auth().preemptive().basic(username, password) .then() .statusCode(HttpStatus.SC_OK) .contentType(MediaType.APPLICATION_JSON) .when().get(serviceUrl).asString(); //String version = JsonPath.from(body).getString("version"); Map<String, String> hm = JsonPath.from(body).getMap(""); Assert.assertTrue(hm.size() >= 6); Assert.assertTrue(hm.keySet().containsAll(new HashSet<>(Arrays.asList(new String[]{"timers", "histograms", "counters", "gauges", "version", "meters"})))); TestUtils.LOG_EXIT(); }
Example #13
Source File: ExtensionTest.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@Test public void testServices() { JsonPath p = RestAssured.given() .accept(MediaType.APPLICATION_JSON) .get("/test/services") .then() .statusCode(200) .extract() .body() .jsonPath(); assertThat(p.getList("services", String.class)).contains( ContextConfigurer.class.getName(), RoutesConfigurer.class.getName() ); }
Example #14
Source File: ExtensionTest.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@Test public void inspect() throws IOException { JsonPath p = RestAssured.given() .contentType(MediaType.TEXT_PLAIN) .accept(MediaType.APPLICATION_JSON) .get("/test/inspect") .then() .statusCode(200) .extract() .body() .jsonPath(); assertThat(p.getMap("env-meta", String.class, String.class)) .containsEntry(Knative.KNATIVE_EVENT_TYPE, "camel.k.evt") .containsEntry(Knative.SERVICE_META_PATH, "/knative") .containsEntry("camel.endpoint.kind", "source"); }
Example #15
Source File: UserQuotaRoutesTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getQuotaShouldReturnBothEmptyWhenDefaultValues() { JsonPath jsonPath = when() .get(QUOTA_USERS + "/" + BOB.asString()) .then() .statusCode(HttpStatus.OK_200) .contentType(ContentType.JSON) .extract() .jsonPath(); SoftAssertions softly = new SoftAssertions(); softly.assertThat(jsonPath.getObject(SIZE, Long.class)).isNull(); softly.assertThat(jsonPath.getObject(COUNT, Long.class)).isNull(); softly.assertAll(); }
Example #16
Source File: UserQuotaRoutesTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void getQuotaShouldReturnGlobalValuesWhenNoUserValuesDefined(WebAdminQuotaSearchTestSystem testSystem) throws Exception { MaxQuotaManager maxQuotaManager = testSystem.getQuotaSearchTestSystem().getMaxQuotaManager(); maxQuotaManager.setGlobalMaxStorage(QuotaSizeLimit.size(1111)); maxQuotaManager.setGlobalMaxMessage(QuotaCountLimit.count(12)); JsonPath jsonPath = when() .get(QUOTA_USERS + "/" + BOB.asString()) .then() .statusCode(HttpStatus.OK_200) .contentType(ContentType.JSON) .extract() .jsonPath(); SoftAssertions softly = new SoftAssertions(); softly.assertThat(jsonPath.getLong("computed." + SIZE)).isEqualTo(1111); softly.assertThat(jsonPath.getLong("computed." + COUNT)).isEqualTo(12); softly.assertThat(jsonPath.getObject("user", Object.class)).isNull(); softly.assertThat(jsonPath.getObject("domain", Object.class)).isNull(); softly.assertThat(jsonPath.getLong("global." + SIZE)).isEqualTo(1111); softly.assertThat(jsonPath.getLong("global." + COUNT)).isEqualTo(12); softly.assertAll(); }
Example #17
Source File: ExtensionTest.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@Test public void testLoadRoutes() throws IOException { String code; try (InputStream is = ExtensionTest.class.getResourceAsStream("/routes.xml")) { code = IOHelper.loadText(is); } JsonPath p = RestAssured.given() .contentType(MediaType.TEXT_PLAIN) .accept(MediaType.APPLICATION_JSON) .body(code) .post("/test/load-routes/MyRoute") .then() .statusCode(200) .extract() .body() .jsonPath(); assertThat(p.getList("components", String.class)).contains("direct", "log"); assertThat(p.getList("routes", String.class)).contains("xml"); assertThat(p.getList("endpoints", String.class)).contains("direct://xml", "log://xml"); }
Example #18
Source File: PermissionAPIIT.java From molgenis with GNU Lesser General Public License v3.0 | 6 votes |
@Test void testCreateAcls() { given() .post(PermissionsController.BASE_URI + "/" + OBJECTS + "/entity-perm2_entity5/1") .then() .statusCode(201); given() .post(PermissionsController.BASE_URI + "/" + OBJECTS + "/entity-perm2_entity5/2") .then() .statusCode(201); Response actual = given() .get(PermissionsController.BASE_URI + "/" + OBJECTS + "/entity-perm2_entity5") .then() .statusCode(200) .extract() .response(); JsonPath path = actual.getBody().jsonPath(); assertEquals("[{id=1, label=1}, {id=2, label=2}]", path.getJsonObject("data").toString()); }
Example #19
Source File: ApiTest.java From vertx-in-action with MIT License | 6 votes |
@Test @DisplayName("Fetch the ranking over the last 24 hours") void checkRanking24Hours() { JsonPath jsonPath = given() .spec(requestSpecification) .accept(ContentType.JSON) .get("/ranking-last-24-hours") .then() .assertThat() .statusCode(200) .extract() .jsonPath(); List<HashMap<String, Object>> data = jsonPath.getList("$"); assertThat(data.size()).isEqualTo(2); assertThat(data.get(0)) .containsEntry("deviceId", "abc") .containsEntry("stepsCount", 2500); assertThat(data.get(1)) .containsEntry("deviceId", "def") .containsEntry("stepsCount", 1000); }
Example #20
Source File: SearchApiTests.java From fess with Apache License 2.0 | 6 votes |
@Test public void searchTestWithRange() throws Exception { String field = "content_length"; int from = 100; int to = 1000; Map<String, String> params = new HashMap<>(); params.put("q", field + ":[" + from + " TO " + to + "]"); params.put("num", "100"); String response = checkMethodBase(new HashMap<>()).params(params).get("/json").asString(); assertTrue(JsonPath.from(response).getInt("response.record_count") > 0); List<Map<String, Object>> docs = JsonPath.from(response).getList("response.result"); for (Map<String, Object> doc : docs) { int value = Integer.parseInt(doc.get(field).toString()); assertTrue(value >= from); assertTrue(value <= to); } }
Example #21
Source File: HttpUtils.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
public static void waitUntilServiceHasSomeTraces(String baseURI, String serviceName) { LOGGER.info("Wait untill Service {} has some traces", serviceName); TestUtils.waitFor("Service " + serviceName + " has some traces", Constants.GLOBAL_TRACING_POLL, READINESS_TIMEOUT, () -> { Response response = given() .when() .baseUri(baseURI) .relaxedHTTPSValidation() .contentType("application/json") .get("/jaeger/api/traces?service=" + serviceName); JsonPath jsonPathValidator = response.jsonPath(); Map<Object, Object> data = jsonPathValidator.getMap("$"); return data.size() > 0; }); LOGGER.info("Service {} has traces", serviceName); }
Example #22
Source File: TaskRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void verifyTaskAttachmentValues(Attachment mockTaskAttachment, String responseContent, boolean urlExist) { JsonPath path = from(responseContent); String returnedId = path.get("id"); String returnedTaskId = path.get("taskId"); String returnedName = path.get("name"); String returnedType = path.get("type"); String returnedDescription = path.get("description"); String returnedUrl = path.get("url"); Attachment mockAttachment = mockTaskAttachments.get(0); assertEquals(mockAttachment.getId(), returnedId); assertEquals(mockAttachment.getTaskId(), returnedTaskId); assertEquals(mockAttachment.getName(), returnedName); assertEquals(mockAttachment.getType(), returnedType); assertEquals(mockAttachment.getDescription(), returnedDescription); if (urlExist) { assertEquals(mockAttachment.getUrl(), returnedUrl); } }
Example #23
Source File: MpMetricTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
/** * Test that semicolons `;` in tag values are translated to underscores `_` * in the JSON output */ @Test @RunAsClient @InSequence(46) public void testTranslateSemiColonToUnderScoreJSON() { Header wantJson = new Header("Accept", APPLICATION_JSON); Response resp = given().header(wantJson).get("/metrics/application"); JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); ResponseBuilder responseBuilder = new ResponseBuilder(); responseBuilder.clone(resp); responseBuilder.setBody(filteredJSONPath.prettify()); resp = responseBuilder.build(); resp.then().statusCode(200) .body("'org.eclipse.microprofile.metrics.test.MetricAppBean.semiColonTaggedCounter;" + "scTag=semi_colons_are_bad;tier=integration'", equalTo(0)); }
Example #24
Source File: ReusedMetricsTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(4) public void testSharedCounterAgain() { Header acceptJson = new Header("Accept", APPLICATION_JSON); Response resp = given().header(acceptJson).get("/metrics/application"); JsonPath filteredJSONPath = new JsonPath(resp.jsonPath().prettify().replaceAll(JSON_APP_LABEL_REGEX, JSON_APP_LABEL_REGEXS_SUB)); ResponseBuilder responseBuilder = new ResponseBuilder(); responseBuilder.clone(resp); responseBuilder.setBody(filteredJSONPath.prettify()); resp = responseBuilder.build(); resp.then() .assertThat().body("'countMe2;tier=integration'", equalTo(2)) .assertThat().body("'org.eclipse.microprofile.metrics.test.MetricAppBean2.meterMe2'.'count;tier=integration'", equalTo(2)) .assertThat().body("'timeMe2'.'count;tier=integration'", equalTo(2)) .assertThat().body("'simplyTimeMe2'.'count;tier=integration'", equalTo(2)); }
Example #25
Source File: MpMetricTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(7) public void testBaseAttributeJson() { Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests")); Header wantJson = new Header("Accept", APPLICATION_JSON); Response resp = given().header(wantJson).get("/metrics/base/thread.max.count"); JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify())); ResponseBuilder responseBuilder = new ResponseBuilder(); responseBuilder.clone(resp); responseBuilder.setBody(filteredJSONPath.prettify()); resp = responseBuilder.build(); resp.then().statusCode(200).and() .contentType(MpMetricTest.APPLICATION_JSON).and().body(containsString("thread.max.count;tier=integration")); }
Example #26
Source File: DeploymentRestServiceInteractionTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void verifyDrdDeploymentValues(Deployment mockDeployment, String responseContent) { JsonPath path = from(responseContent); verifyStandardDeploymentValues(mockDeployment, path); Map<String, HashMap<String, Object>> deployedDecisionDefinitions = path.getMap(PROPERTY_DEPLOYED_DECISION_DEFINITIONS); Map<String, HashMap<String, Object>> deployedDecisionRequirementsDefinitions = path.getMap(PROPERTY_DEPLOYED_DECISION_REQUIREMENTS_DEFINITIONS); assertEquals(1, deployedDecisionDefinitions.size()); HashMap decisionDefinitionDto = deployedDecisionDefinitions.get(EXAMPLE_DECISION_DEFINITION_ID); assertNotNull(decisionDefinitionDto); verifyDmnDeployment(decisionDefinitionDto); assertEquals(1, deployedDecisionRequirementsDefinitions.size()); HashMap decisionRequirementsDefinitionDto = deployedDecisionRequirementsDefinitions.get(EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID); assertNotNull(decisionRequirementsDefinitionDto); verifyDrdDeployment(decisionRequirementsDefinitionDto); assertNull(path.get(PROPERTY_DEPLOYED_PROCESS_DEFINITIONS)); assertNull(path.get(PROPERTY_DEPLOYED_CASE_DEFINITIONS)); }
Example #27
Source File: MpMetricTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(11) public void testBaseMetadataSingluarItems() { Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests")); 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()); }
Example #28
Source File: MpMetricTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(31) public void testOptionalBaseMetrics() { Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests")); 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 (MiniMeta item : names.values()) { if (elements.containsKey(item.toJSONName()) && names.get(item.name).optional) { String prefix = names.get(item.name).name; String type = "'"+item.toJSONName()+"'"+".type"; String unit= "'"+item.toJSONName()+"'"+".unit"; given().header(wantJson).options("/metrics/base/"+prefix).then().statusCode(200) .body(type, equalTo(names.get(item.name).type)) .body(unit, equalTo(names.get(item.name).unit)); } } }
Example #29
Source File: MpMetricTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(15) public void testBaseMetadataGarbageCollection() { Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests")); 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(".total") || name.endsWith(".time")); count++; } } assertThat(count, greaterThan(0)); }
Example #30
Source File: MpMetricTest.java From microprofile-metrics with Apache License 2.0 | 6 votes |
@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()); }