@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 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()); } }