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