public SubscriptionBuilder withEndpoint(String endpoint) { this.endpoint = EndpointAddress.of(endpoint); return this; }
public SubscriptionBuilder withEndpoint(String endpoint) { this.endpoint = EndpointAddress.of(endpoint); return this; }
private URI safeResolve(Message message, String url, EndpointAddressResolverMetadata metadata) { try { return delegate.resolve(EndpointAddress.of(url), message, metadata); } catch (EndpointAddressResolutionException e) { throw Throwables.propagate(e); } }
private URI safeResolve(Message message, String url, EndpointAddressResolverMetadata metadata) { try { return delegate.resolve(EndpointAddress.of(url), message, metadata); } catch (EndpointAddressResolutionException e) { throw Throwables.propagate(e); } }
public static SubscriptionBuilder subscription(String topicQualifiedName, String subscriptionName, String endpoint) { return subscription(TopicName.fromQualifiedName(topicQualifiedName), subscriptionName, EndpointAddress.of(endpoint)); }
public static SubscriptionBuilder subscription(String topicQualifiedName, String subscriptionName, String endpoint) { return subscription(TopicName.fromQualifiedName(topicQualifiedName), subscriptionName, EndpointAddress.of(endpoint)); }
@Test public void shouldValidateUriTemplateWithInvalidHostname() { // when Set<ConstraintViolation<EndpointAddress>> violations = validator.validate(EndpointAddress.of("http://host_with_invalid_chars/{variable}")); // then assertThat(violations).hasSize(1); }
@Test public void shouldValidateEndpointWithInvalidProtocol() { // when Set<ConstraintViolation<EndpointAddress>> violations = validator.validate(EndpointAddress.of("thisisstupid://some.endpoint.com")); // then assertThat(violations).hasSize(1); }
@Test public void shouldValidateEndpointAddressWithValidTemplateURI() { // when Set<ConstraintViolation<EndpointAddress>> violations = validator.validate(EndpointAddress.of("http://thisistemplate/{name}")); // then assertThat(violations).isEmpty(); }
@Test public void shouldNotReturnValidationErrorsForValidEndpoint() { // when Set<ConstraintViolation<EndpointAddress>> violations = validator.validate(EndpointAddress.of("http://some.endpoint.com")); // then assertThat(violations).isEmpty(); }
@Test public void shouldValidateEndpointAddressWithInvalidURI() { // when Set<ConstraintViolation<EndpointAddress>> violations = validator.validate(EndpointAddress.of("jms://{}invalid.endpoint.com")); // then assertThat(violations).hasSize(1); }
@Test public void shouldValidateEndpointAddressWithInvalidTemplateURI() { // when Set<ConstraintViolation<EndpointAddress>> violations = validator.validate(EndpointAddress.of("http://thisistemplate{\\}")); // then assertThat(violations).hasSize(1); }
@Test public void shouldValidateUriWithInvalidHostname() { // when Set<ConstraintViolation<EndpointAddress>> violations = validator.validate(EndpointAddress.of("http://host_with_invalid_chars.com")); // then assertThat(violations).hasSize(1); }
@Test public void willReturnURIOnEmptyEndpoint() throws InterpolationException { // given EndpointAddress endpoint = EndpointAddress.of(""); URI expectedEndpoint = URI.create(""); // when URI interpolated = new MessageBodyInterpolator().interpolate(endpoint, SAMPLE_MSG); // then assertThat(interpolated).isEqualTo(expectedEndpoint); }
@Test public void shouldUseInterpolatorToInterpolateURI() throws InterpolationException, EndpointAddressResolutionException { // given EndpointAddress address = EndpointAddress.of("http://localhost/{a}"); Message message = withTestMessage().withContent("content", StandardCharsets.UTF_8).build(); when(interpolator.interpolate(address, message)).thenReturn(URI.create("http://localhost/hello")); // when URI uri = resolver.resolve(EndpointAddress.of("http://localhost/{a}"), withTestMessage().withContent("content", StandardCharsets.UTF_8).build(), metadata); // then assertThat(uri).isEqualTo(URI.create("http://localhost/hello")); }
@Test(expected = InterpolationException.class) public void willThrowExceptionOnInvalidPayload() throws InterpolationException { // given EndpointAddress endpoint = EndpointAddress.of("http://some.endpoint.com/{some.object}"); // when new MessageBodyInterpolator().interpolate(endpoint, SAMPLE_MSG); }
@Test(expected = InterpolationException.class) public void willThrowExceptionOnInterpolationException() throws InterpolationException { // given EndpointAddress endpoint = EndpointAddress.of("http://some.endpoint.com/{some.object}?test={some.test}"); // when new MessageBodyInterpolator().interpolate(endpoint, SAMPLE_MSG); }
@Test @SuppressWarnings("unchecked") public void shouldThrowResolvingExceptionWhenInterpolationFails() throws EndpointAddressResolutionException, InterpolationException { // given EndpointAddress address = EndpointAddress.of("http://localhost/{a}"); Message message = withTestMessage().withContent("content", StandardCharsets.UTF_8).build(); when(interpolator.interpolate(address, message)).thenThrow(InterpolationException.class); // when catchException(resolver).resolve(EndpointAddress.of("http://localhost/{a}"), withTestMessage().withContent("content", StandardCharsets.UTF_8).build(), metadata); // then assertThat(CatchException.<EndpointAddressResolutionException>caughtException()).isInstanceOf(EndpointAddressResolutionException.class); }
@Test public void shouldCreateCustomProtocolMessageSender() { // given EndpointAddress endpoint = EndpointAddress.of("myProtocol://service"); Subscription subscription = subscription("group.topic", "subscription", endpoint).build(); factory.addSupportedProtocol("myProtocol", protocolMessageSenderProviderReturning(referenceMessageSender)); // when MessageSender sender = factory.create(subscription); // then assertThat(sender).isEqualTo(referenceMessageSender); }
@Test public void willReturnURIAsIsIfNoTemplate() throws InterpolationException { // given EndpointAddress endpoint = EndpointAddress.of("http://some.endpoint.com/"); // when URI interpolated = new MessageBodyInterpolator().interpolate(endpoint, SAMPLE_MSG); // then assertThat(interpolated).isEqualTo(endpoint.getUri()); }