Search in sources :

Example 1 with HttpMethod

use of com.palantir.dialogue.HttpMethod in project dialogue by palantir.

the class ContentEncodingChannelTest method testChannelCreationWithTag.

@Test
void testChannelCreationWithTag() {
    EndpointChannel delegate = _req -> Futures.immediateCancelledFuture();
    EndpointChannel result = ContentEncodingChannel.of(delegate, new Endpoint() {

        @Override
        public HttpMethod httpMethod() {
            return HttpMethod.POST;
        }

        @Override
        public String serviceName() {
            return "service";
        }

        @Override
        public String endpointName() {
            return "endpoint";
        }

        @Override
        public String version() {
            return "1.2.3";
        }

        @Override
        public Set<String> tags() {
            return ImmutableSet.of("compress-request");
        }
    });
    assertThat(result).isNotSameAs(delegate);
}
Also used : OutputStream(java.io.OutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ImmutableSet(com.google.common.collect.ImmutableSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RequestBody(com.palantir.dialogue.RequestBody) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) IOException(java.io.IOException) HttpMethod(com.palantir.dialogue.HttpMethod) TestEndpoint(com.palantir.dialogue.TestEndpoint) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) OptionalLong(java.util.OptionalLong) Futures(com.google.common.util.concurrent.Futures) EndpointChannel(com.palantir.dialogue.EndpointChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteStreams(com.google.common.io.ByteStreams) Endpoint(com.palantir.dialogue.Endpoint) Request(com.palantir.dialogue.Request) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TestEndpoint(com.palantir.dialogue.TestEndpoint) Endpoint(com.palantir.dialogue.Endpoint) EndpointChannel(com.palantir.dialogue.EndpointChannel) HttpMethod(com.palantir.dialogue.HttpMethod) Test(org.junit.jupiter.api.Test)

Example 2 with HttpMethod

use of com.palantir.dialogue.HttpMethod in project dialogue by palantir.

the class EndpointDefinitions method tryParseEndpointDefinition.

public Optional<EndpointDefinition> tryParseEndpointDefinition(ExecutableElement element) {
    AnnotationReflector requestAnnotationReflector = MoreElements.getAnnotationMirror(element, Request.class).toJavaUtil().map(ImmutableAnnotationReflector::of).orElseThrow();
    EndpointName endpointName = ImmutableEndpointName.of(element.getSimpleName().toString());
    HttpMethod method = HttpMethod.valueOf(requestAnnotationReflector.getFieldMaybe("method", VariableElement.class).get().getSimpleName().toString());
    Optional<HttpPath> maybeHttpPath = httpPathParser.getHttpPath(element, requestAnnotationReflector);
    Optional<ReturnType> maybeReturnType = returnTypesResolver.getReturnType(endpointName, element, requestAnnotationReflector);
    List<Optional<ArgumentDefinition>> args = element.getParameters().stream().map(arg -> getArgumentDefinition(endpointName, arg)).collect(Collectors.toList());
    if (!args.stream().filter(Predicates.not(Optional::isPresent)).collect(Collectors.toList()).isEmpty() || maybeHttpPath.isEmpty() || maybeReturnType.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(ImmutableEndpointDefinition.builder().endpointName(endpointName).httpMethod(method).httpPath(maybeHttpPath.get()).returns(maybeReturnType.get()).addAllArguments(args.stream().map(Optional::get).collect(Collectors.toList())).build());
}
Also used : MoreElements(com.google.auto.common.MoreElements) List(java.util.List) Request(com.palantir.dialogue.annotations.Request) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Predicates(com.google.common.base.Predicates) Optional(java.util.Optional) HttpMethod(com.palantir.dialogue.HttpMethod) Types(javax.lang.model.util.Types) Collectors(java.util.stream.Collectors) Elements(javax.lang.model.util.Elements) ErrorContext(com.palantir.dialogue.annotations.processor.ErrorContext) Optional(java.util.Optional) Request(com.palantir.dialogue.annotations.Request) HttpMethod(com.palantir.dialogue.HttpMethod)

Example 3 with HttpMethod

use of com.palantir.dialogue.HttpMethod in project dialogue by palantir.

the class UserAgentEndpointChannelTest method testServiceNameIsNotValidConjureAgent.

@Test
public void testServiceNameIsNotValidConjureAgent() {
    EndpointChannel channel = UserAgentEndpointChannel.create(delegate, new Endpoint() {

        @Override
        public void renderPath(Map<String, String> _params, UrlBuilder _url) {
        }

        @Override
        public HttpMethod httpMethod() {
            return HttpMethod.GET;
        }

        @Override
        public String serviceName() {
            return "Service_Name";
        }

        @Override
        public String endpointName() {
            return "endpoint";
        }

        @Override
        public String version() {
            return "4.5.6";
        }
    }, baseAgent);
    // Special case: In IDEs, tests are run against classes (not JARs) and thus don't carry versions.
    String dialogueVersion = Optional.ofNullable(Channel.class.getPackage().getImplementationVersion()).orElse("0.0.0");
    channel.execute(request);
    verify(delegate).execute(requestCaptor.capture());
    assertThat(requestCaptor.getValue().headerParams().get("user-agent")).containsExactly("test-class/1.2.3 dialogue/" + dialogueVersion);
}
Also used : TestEndpoint(com.palantir.dialogue.TestEndpoint) Endpoint(com.palantir.dialogue.Endpoint) Channel(com.palantir.dialogue.Channel) EndpointChannel(com.palantir.dialogue.EndpointChannel) EndpointChannel(com.palantir.dialogue.EndpointChannel) UrlBuilder(com.palantir.dialogue.UrlBuilder) HttpMethod(com.palantir.dialogue.HttpMethod) Test(org.junit.jupiter.api.Test)

Aggregations

HttpMethod (com.palantir.dialogue.HttpMethod)3 Endpoint (com.palantir.dialogue.Endpoint)2 EndpointChannel (com.palantir.dialogue.EndpointChannel)2 TestEndpoint (com.palantir.dialogue.TestEndpoint)2 Test (org.junit.jupiter.api.Test)2 MoreElements (com.google.auto.common.MoreElements)1 Predicates (com.google.common.base.Predicates)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ByteStreams (com.google.common.io.ByteStreams)1 Futures (com.google.common.util.concurrent.Futures)1 Channel (com.palantir.dialogue.Channel)1 Request (com.palantir.dialogue.Request)1 RequestBody (com.palantir.dialogue.RequestBody)1 UrlBuilder (com.palantir.dialogue.UrlBuilder)1 Request (com.palantir.dialogue.annotations.Request)1 ErrorContext (com.palantir.dialogue.annotations.processor.ErrorContext)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1