ppalaga commented on a change in pull request #138: Add tests to the twitter itest project URL: https://github.com/apache/camel-quarkus/pull/138#discussion_r314426759
########## File path: integration-tests/twitter/src/main/java/org/apache/camel/quarkus/component/twitter/CamelRoute.java ########## @@ -16,25 +16,118 @@ */ package org.apache.camel.quarkus.component.twitter; -import io.quarkus.runtime.annotations.RegisterForReflection; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; -import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.apache.camel.component.twitter.TwitterConstants; -@RegisterForReflection public class CamelRoute extends RouteBuilder { - @ConfigProperty(name = "twitter.user.name") - String twitterUserName; + private static final Set<String> TWITTER_SEARCH_HEADERS = new HashSet<>( + Arrays.asList(TwitterConstants.TWITTER_COUNT, TwitterConstants.TWITTER_KEYWORDS, + TwitterConstants.TWITTER_MAXID, TwitterConstants.TWITTER_NUMBER_OF_PAGES, + TwitterConstants.TWITTER_SEARCH_LANGUAGE, TwitterConstants.TWITTER_SINCEID)); + + private final StringBuilder ownTweets = new StringBuilder(); + private final StringBuilder directMessages = new StringBuilder(); @Override public void configure() { - from("twitter-timeline:user?user=ApacheCamel&count=1") - .to("log:timeline?showAll=true"); + rest() + .get("/timeline") + /* Expose the polled messages */ + .route() + .id("get-timeline") + .setBody(() -> { + synchronized (ownTweets) { + return ownTweets.toString(); + } + }) + .endRest() + .post("/timeline") + .route() + .id("post-timeline") + .to("twitter-timeline://user") + .setHeader(Exchange.HTTP_RESPONSE_CODE, simple("201")) + .endRest() + + .get("/search") + .route() + .id("get-search") + // The servlet component does not pass the query params as camel message headers for some reason + .process(e -> { + final String query = e.getIn().getHeader("CamelHttpQuery", String.class); + for (String kv : query.split("&")) { + final String[] keyVal = kv.split("="); + if (TWITTER_SEARCH_HEADERS.contains(keyVal[0])) { + // Consider URL decoding if you copy this to production code + e.getOut().setHeader(keyVal[0], keyVal[1]); + } + } + }) + .to("twitter-search://_keywords_passed_via_CamelTwitterKeywords_header_") + .to("log:search?showAll=true") + .endRest() + + .post("/directmessage") + .route() + .id("post-directmessage") + .to("twitter-directmessage://{{camel.component.twitter-directmessage.user}}") Review comment: Tried the original `twitter.user.name` and it did not work. IIRC the PropertyBindingSupport was complaining that the prop is not available. The JavaDoc of `PropertyBindingSupport.bindProperties()` says "Binds the properties with the given prefix to the target object" so it seems to consciously ignore all other props. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services