@Test public void shouldRaiseAnExceptionIfTenantIsNull() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Tenant cannot be null"); subject.send(event, destinationUri, null, null); }
@Test public void shouldRaiseAnExceptionIfURIIsEmpty() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Destination URI cannot be null or empty"); subject.send(event, new URI(null, null, null, null, null), null, tenant); }
@Test public void shouldNotSendAnyEventThroughGatewayIfPayloadParsingFails() throws Exception { event.setPayload(invalidEventPayload); subject.send(event, destinationUri, null, tenant); verify(httpGateway, never()).request(any(), any(), any(), any(), any(), any()); verify(eventRepository, never()).saveIncoming(tenant, event); }
@Test public void shouldNotSendAnyEventThroughGatewayIfDestinationIsDisabled() throws Exception { destinationUri = new RESTDestinationURIDealer() {}.toRestDestinationURI( tenant.getDomainName(), REGISTERED_AND_INACTIVE_DESTINATION_GUID); subject.send(event, destinationUri, null, tenant); verify(httpGateway, never()).request(any(), any(), any(), any(), any(), any()); verify(eventRepository, never()).saveIncoming(tenant, event); }
@Test public void shouldRaiseAnExceptionIfDestinationIsUnknown() throws Exception { destinationUri = new RESTDestinationURIDealer() {}.toRestDestinationURI( tenant.getDomainName(), "unknown_guid"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage(MessageFormat.format("REST Destination is unknown : {0}", destinationUri)); subject.send(event, destinationUri, null, tenant); }
@Test public void shouldSendAnEventThroughGatewayIfDestinationIsEnabled() throws Exception { subject.send(event, destinationUri, null, tenant); InOrder inOrder = Mockito.inOrder(eventRepository, httpGateway); inOrder .verify(httpGateway) .request( eq(HttpMethod.POST), eq(URI.create(destination.getServiceURI().replaceAll("\\@\\{.*}", "value"))), eq(MediaType.APPLICATION_JSON), argLambda(objectSupplier -> objectSupplier.get().equals(event.getPayload())), eq(destination.getServiceUsername()), eq(destination.getServicePassword())); // inOrder.verify(eventRepository).saveIncoming(eq(tenant),eq(event)); }