Skip to content

Commit

Permalink
Test Tokenize language in isolation apache#2613
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed May 18, 2021
1 parent f160d50 commit b568fd0
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
5 changes: 5 additions & 0 deletions integration-test-groups/foundation/core-languages/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>

<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand All @@ -37,6 +40,10 @@ public class CoreLanguagesResource {
@Inject
ProducerTemplate template;

@Inject
@Named
AtomicInteger tokenCounter;

@Path("/header/{route}/{key}/{value}")
@POST
@Consumes(MediaType.TEXT_PLAIN)
Expand Down Expand Up @@ -73,4 +80,11 @@ public String exchangeProperty(String body, @PathParam("route") String route, @P
return template.request("direct:" + route, e -> e.getProperties().put(key, value)).getMessage().getBody(String.class);
}

@Path("/tokenCounter")
@GET
@Produces(MediaType.TEXT_PLAIN)
public int tokenCounter() {
return tokenCounter.get();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.languages.it;

import java.util.concurrent.atomic.AtomicInteger;

import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.camel.builder.RouteBuilder;

@Singleton
public class TokenizeLanguageRoutes extends RouteBuilder {

@Inject
@Named
AtomicInteger tokenCounter;

@Override
public void configure() {
from("direct:tokenizeLanguage")
.split().tokenize(",")
.process(e -> tokenCounter.incrementAndGet());
}

static class Producers {
@Produces
@Singleton
@Named
AtomicInteger tokenCounter() {
return new AtomicInteger();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.languages.it;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class TokenizeLanguageIT extends TokenizeLanguageTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.languages.it;

import java.util.concurrent.TimeUnit;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.awaitility.Awaitility;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class TokenizeLanguageTest {
@Test
public void ref() {
RestAssured.given()
.body("a,b,c,d,e")
.post("/core-languages/route/tokenizeLanguage/String")
.then()
.statusCode(200);
Awaitility.await().atMost(10, TimeUnit.SECONDS)
.until(
() -> RestAssured.given()
.get("/core-languages/tokenCounter")
.then()
.statusCode(200)
.extract()
.body().asString(),
Matchers.is("5"));
;
}

}

0 comments on commit b568fd0

Please sign in to comment.