@Test public void hamcrestMatchers() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].name").value(equalTo("Johann Sebastian Bach"))) .andExpect(jsonPath("$.performers[1].name").value(equalTo("Yehudi Menuhin"))) .andExpect(jsonPath("$.composers[0].name", startsWith("Johann"))) .andExpect(jsonPath("$.performers[0].name", endsWith("Ashkenazy"))) .andExpect(jsonPath("$.performers[1].name", containsString("di Me"))) .andExpect(jsonPath("$.composers[1].name", isIn(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))) .andExpect(jsonPath("$.composers[:3].name", hasItem("Johannes Brahms"))) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void exists() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0]").exists()) .andExpect(jsonPath("$.composers[1]").exists()) .andExpect(jsonPath("$.composers[2]").exists()) .andExpect(jsonPath("$.composers[3]").exists()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void hamcrestMatchersWithParameterizedJsonPaths() throws Exception { String composerName = "$.composers[%s].name"; String performerName = "$.performers[%s].name"; this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath(composerName, 0).value(startsWith("Johann"))) .andExpect(jsonPath(performerName, 0).value(endsWith("Ashkenazy"))) .andExpect(jsonPath(performerName, 1).value(containsString("di Me"))) .andExpect(jsonPath(composerName, 1).value(isIn(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void doesNotExist() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[?(@.name == 'Edvard Grieeeeeeg')]").doesNotExist()) .andExpect(jsonPath("$.composers[?(@.name == 'Robert Schuuuuuuman')]").doesNotExist()) .andExpect(jsonPath("$.composers[4]").doesNotExist()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void value() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].name").value("Johann Sebastian Bach")) .andExpect(jsonPath("$.performers[1].name").value("Yehudi Menuhin")) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void testSendingMessageToEmailAddress() throws Exception { mockNotificationsServer.expect(requestTo("http://notifications.example.com/emails")) .andExpect(method(POST)) .andExpect(jsonPath("$.kind_id").value("kind-id-01")) .andExpect(jsonPath("$.to").value("user@example.com")) .andExpect(jsonPath("$.subject").value("First message")) .andExpect(jsonPath("$.html").value("<p>Message</p>")) .andRespond(withSuccess()); notificationsService.sendMessage("user@example.com", MessageType.PASSWORD_RESET, "First message", "<p>Message</p>"); mockNotificationsServer.verify(); }
@Test public void isString() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].name").isString()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void isArray() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers").isArray()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void isBoolean() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].someBoolean").isBoolean()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void isNumber() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].someDouble").isNumber()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void testSendingMessageInAnotherZoneResets() throws Exception { IdentityZone zone = MultitenancyFixture.identityZone("zone", "zone"); IdentityZoneHolder.set(zone); mockNotificationsServer.expect(requestTo("http://notifications.example.com/emails")) .andExpect(method(POST)) .andExpect(jsonPath("$.to").value("user@example.com")) .andExpect(jsonPath("$.subject").value("First message")) .andExpect(jsonPath("$.html").value("<p>Message</p>")) .andRespond(withSuccess()); notificationsService.sendMessage("user@example.com", MessageType.PASSWORD_RESET, "First message", "<p>Message</p>"); mockNotificationsServer.verify(); assertSame(zone, IdentityZoneHolder.get()); }
@Test public void testSendingMessageInAnotherZoneResetsWhenError() throws Exception { IdentityZone zone = MultitenancyFixture.identityZone("zone", "zone"); IdentityZoneHolder.set(zone); mockNotificationsServer.expect(requestTo("http://notifications.example.com/emails")) .andExpect(method(POST)) .andExpect(jsonPath("$.to").value("user@example.com")) .andExpect(jsonPath("$.subject").value("First message")) .andExpect(jsonPath("$.html").value("<p>Message</p>")) .andRespond(withBadRequest()); try { notificationsService.sendMessage("user@example.com", MessageType.PASSWORD_RESET, "First message", "<p>Message</p>"); fail(); } catch (HttpClientErrorException x) { } mockNotificationsServer.verify(); assertSame(zone, IdentityZoneHolder.get()); } }
private void verifySerialExecutionStarted(String uniqueBenchmarkName, String queryName, int executionNumber) { verifyExecutionStarted(uniqueBenchmarkName, executionNumber); restServiceServer.expect(matchAll( requestTo("http://graphite:18088/events/"), method(HttpMethod.POST), jsonPath("$.what", is("Benchmark " + uniqueBenchmarkName + ", query " + queryName + " (" + executionNumber + ") started")), jsonPath("$.tags", is("execution started TEST_ENV")), jsonPath("$.data", is("")) )).andRespond(withSuccess()); }
private void verifySerialExecutionStarted(String uniqueBenchmarkName, String queryName, int executionNumber) { verifyExecutionStarted(uniqueBenchmarkName, executionNumber); restServiceServer.expect(matchAll( requestTo("http://graphite:18088/events/"), method(HttpMethod.POST), jsonPath("$.what", is("Benchmark " + uniqueBenchmarkName + ", query " + queryName + " (" + executionNumber + ") started")), jsonPath("$.tags", is("execution started TEST_ENV")), jsonPath("$.data", is("")) )).andRespond(withSuccess()); }
private void verifySerialExecutionFinished(String uniqueBenchmarkName, String queryName, int executionNumber, List<String> measurementNames) { verifyExecutionFinished(uniqueBenchmarkName, executionNumber, measurementNames); restServiceServer.expect(matchAll( requestTo("http://graphite:18088/events/"), method(HttpMethod.POST), jsonPath("$.what", is("Benchmark " + uniqueBenchmarkName + ", query " + queryName + " (" + executionNumber + ") ended")), jsonPath("$.tags", is("execution ended TEST_ENV")), jsonPath("$.data", startsWith("duration: ")) )).andRespond(withSuccess()); }
private void verifySerialExecutionFinished(String uniqueBenchmarkName, String queryName, int executionNumber, List<String> measurementNames) { verifyExecutionFinished(uniqueBenchmarkName, executionNumber, measurementNames); restServiceServer.expect(matchAll( requestTo("http://graphite:18088/events/"), method(HttpMethod.POST), jsonPath("$.what", is("Benchmark " + uniqueBenchmarkName + ", query " + queryName + " (" + executionNumber + ") ended")), jsonPath("$.tags", is("execution ended TEST_ENV")), jsonPath("$.data", startsWith("duration: ")) )).andRespond(withSuccess()); }
private void verifyExecutionFinished(String uniqueBenchmarkName, int executionNumber, List<String> measurementNames) { restServiceServer.expect(matchAll( requestTo("http://benchmark-service:8080/v1/benchmark/" + uniqueBenchmarkName + "/BEN_SEQ_ID/execution/" + executionNumber + "/finish"), method(HttpMethod.POST), jsonPath("$.status", ENDED_STATUS_MATCHER), jsonPath("$.measurements.[*].name", containsInAnyOrder(measurementNames.toArray())) )).andRespond(withSuccess()); }
private void verifyExecutionFinished(String uniqueBenchmarkName, int executionNumber, List<String> measurementNames) { restServiceServer.expect(matchAll( requestTo("http://benchmark-service:8080/v1/benchmark/" + uniqueBenchmarkName + "/BEN_SEQ_ID/execution/" + executionNumber + "/finish"), method(HttpMethod.POST), jsonPath("$.status", ENDED_STATUS_MATCHER), jsonPath("$.measurements.[*].name", containsInAnyOrder(measurementNames.toArray())) )).andRespond(withSuccess()); }
@Test public void sendMessage() { mockServer.expect(requestTo(CommunicationTemplate.MESSAGING_URL+"?oauth2_access_token=ACCESS_TOKEN")) .andExpect(method(POST)) .andExpect(jsonPath("body", is("This is a test"))) .andExpect(jsonPath("subject", is("Test message"))) .andExpect(jsonPath("recipients.values", hasSize(1))) .andExpect(jsonPath("recipients.values[0].person._path", is("/people/~"))) .andRespond(withSuccess("", MediaType.APPLICATION_JSON)); linkedIn.communicationOperations().sendMessage("Test message", "This is a test", "~"); }