This is an automated email from the ASF dual-hosted git repository.

ppalaga pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new 8add56e  await for consumer
8add56e is described below

commit 8add56e6cbd3745cf702137c7e200e882f7dfc70
Author: Zineb Bendhiba <bendhiba.zi...@gmail.com>
AuthorDate: Fri Feb 12 15:20:48 2021 +0100

    await for consumer
---
 integration-tests/optaplanner/pom.xml              |  7 +++-
 .../quarkus/component/optaplanner/it/MyBean.java   | 48 ----------------------
 .../optaplanner/it/OptaplannerResource.java        | 12 +++---
 .../quarkus/component/optaplanner/it/Routes.java   |  6 +--
 .../component/optaplanner/it/domain/Lesson.java    |  2 +-
 .../component/optaplanner/it/domain/Room.java      |  2 +-
 .../component/optaplanner/it/domain/TimeTable.java |  9 +---
 .../component/optaplanner/it/domain/Timeslot.java  |  2 +-
 .../component/optaplanner/it/OptaplannerTest.java  | 16 ++++----
 9 files changed, 28 insertions(+), 76 deletions(-)

diff --git a/integration-tests/optaplanner/pom.xml 
b/integration-tests/optaplanner/pom.xml
index 3a16ffc..5a6870b 100644
--- a/integration-tests/optaplanner/pom.xml
+++ b/integration-tests/optaplanner/pom.xml
@@ -60,7 +60,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-bean</artifactId>
+            <artifactId>camel-quarkus-mock</artifactId>
         </dependency>
 
         <!-- test dependencies -->
@@ -74,6 +74,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>
diff --git 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/MyBean.java
 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/MyBean.java
deleted file mode 100644
index 185cda0..0000000
--- 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/MyBean.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.component.optaplanner.it;
-
-import javax.enterprise.context.ApplicationScoped;
-
-import io.quarkus.runtime.annotations.RegisterForReflection;
-import org.apache.camel.Exchange;
-import org.apache.camel.component.optaplanner.OptaPlannerConstants;
-import org.apache.camel.quarkus.component.optaplanner.it.domain.TimeTable;
-
-@RegisterForReflection
-@ApplicationScoped
-public class MyBean {
-
-    public TimeTable bestSolution;
-
-    public TimeTable getBestSolution() {
-        return bestSolution;
-    }
-
-    public void setBestSolution(TimeTable bestSolution) {
-        this.bestSolution = bestSolution;
-    }
-
-    public void updateBestSolution(Exchange exchange) {
-        if (exchange != null) {
-            TimeTable newBestSolution = 
exchange.getMessage().getHeader(OptaPlannerConstants.BEST_SOLUTION, 
TimeTable.class);
-            if (newBestSolution != null) {
-                this.bestSolution = newBestSolution;
-            }
-        }
-    }
-}
diff --git 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerResource.java
 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerResource.java
index 70f5f9c..e1f9640 100644
--- 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerResource.java
+++ 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerResource.java
@@ -26,7 +26,9 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.component.optaplanner.OptaPlannerConstants;
 import 
org.apache.camel.quarkus.component.optaplanner.it.bootstrap.DataGenerator;
 import org.apache.camel.quarkus.component.optaplanner.it.domain.TimeTable;
@@ -50,7 +52,7 @@ public class OptaplannerResource {
     ProducerTemplate producerTemplate;
 
     @Inject
-    MyBean bean;
+    CamelContext context;
 
     @GET
     @Path("solveSync")
@@ -67,8 +69,6 @@ public class OptaplannerResource {
     @GET
     @Path("solveAsync")
     public TimeTable solveAsync() throws ExecutionException, 
InterruptedException {
-        // reset best Solution
-        bean.setBestSolution(null);
         if (SolverStatus.NOT_SOLVING == 
solverManager.getSolverStatus(SINGLETON_TIME_TABLE_ID)) {
             CompletableFuture<TimeTable> response = 
producerTemplate.asyncRequestBodyAndHeader(
                     "direct:solveAsync", DataGenerator.timeTable, 
OptaPlannerConstants.SOLVER_MANAGER,
@@ -83,7 +83,9 @@ public class OptaplannerResource {
     @GET
     @Path("newBestSolution")
     public TimeTable getNewBestSolution() {
-        return bean.getBestSolution();
+        MockEndpoint mockEndpoint = context.getEndpoint("mock:best-solution", 
MockEndpoint.class);
+        return mockEndpoint.getReceivedExchanges().stream().map(
+                exchange -> 
exchange.getMessage().getHeader(OptaPlannerConstants.BEST_SOLUTION, 
TimeTable.class))
+                .findFirst().orElse(null);
     }
-
 }
diff --git 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/Routes.java
 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/Routes.java
index 8f82b9e..809cd59 100644
--- 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/Routes.java
+++ 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/Routes.java
@@ -17,15 +17,11 @@
 package org.apache.camel.quarkus.component.optaplanner.it;
 
 import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
 
 import org.apache.camel.builder.RouteBuilder;
 
 @ApplicationScoped
 public class Routes extends RouteBuilder {
-    @Inject
-    MyBean bean;
-
     @Override
     public void configure() throws Exception {
 
@@ -35,7 +31,7 @@ public class Routes extends RouteBuilder {
 
         // async consumer
         from("optaplanner:anything?useSolverManager=true&problemId=" + 
OptaplannerResource.SINGLETON_TIME_TABLE_ID)
-                .bean(bean, "updateBestSolution");
+                .to("mock:best-solution");
 
         // sync producer
         from("direct:solveSync")
diff --git 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Lesson.java
 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Lesson.java
index fb7b977..c749745 100644
--- 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Lesson.java
+++ 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Lesson.java
@@ -27,7 +27,7 @@ import 
org.optaplanner.core.api.domain.variable.PlanningVariable;
 
 /**
  * adapted from optaplanner quarkus quickstart :
- * 
https://github.com/quarkusio/quarkus-quickstarts/blob/master/optaplanner-quickstart/src/main/java/org/acme/optaplanner/domain/Lesson.java
+ * 
https://github.com/kiegroup/optaplanner-quickstarts/blob/stable/quarkus-school-timetabling/src/main/java/org/acme/schooltimetabling/domain/Lesson.java
  */
 @PlanningEntity
 public class Lesson {
diff --git 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Room.java
 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Room.java
index bd93b2d..4fed920 100644
--- 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Room.java
+++ 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Room.java
@@ -25,7 +25,7 @@ import org.optaplanner.core.api.domain.lookup.PlanningId;
 
 /**
  * adapted from optaplanner quarkus quickstart :
- * 
https://github.com/quarkusio/quarkus-quickstarts/blob/master/optaplanner-quickstart/src/main/java/org/acme/optaplanner/domain/Room.java
+ * 
https://github.com/kiegroup/optaplanner-quickstarts/blob/stable/quarkus-school-timetabling/src/main/java/org/acme/schooltimetabling/domain/Room.java
  */
 public class Room {
 
diff --git 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/TimeTable.java
 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/TimeTable.java
index 8fe3800..015f461 100644
--- 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/TimeTable.java
+++ 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/TimeTable.java
@@ -21,13 +21,13 @@ import java.util.List;
 import 
org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
 import org.optaplanner.core.api.domain.solution.PlanningScore;
 import org.optaplanner.core.api.domain.solution.PlanningSolution;
-import 
org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty;
+import org.optaplanner.core.api.domain.solution.ProblemFactCollectionProperty;
 import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
 import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;
 
 /**
  * adapted from optaplanner quarkus quickstart :
- * 
https://github.com/quarkusio/quarkus-quickstarts/blob/master/optaplanner-quickstart/src/main/java/org/acme/optaplanner/domain/Timeslot.java
+ * 
https://github.com/kiegroup/optaplanner-quickstarts/blob/stable/quarkus-school-timetabling/src/main/java/org/acme/schooltimetabling/domain/TimeTable.java
  */
 @PlanningSolution
 public class TimeTable {
@@ -64,9 +64,4 @@ public class TimeTable {
     public List<Lesson> getLessonList() {
         return lessonList;
     }
-
-    public HardSoftScore getScore() {
-        return score;
-    }
-
 }
diff --git 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Timeslot.java
 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Timeslot.java
index 57fc50f..a14a5f4 100644
--- 
a/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Timeslot.java
+++ 
b/integration-tests/optaplanner/src/main/java/org/apache/camel/quarkus/component/optaplanner/it/domain/Timeslot.java
@@ -26,7 +26,7 @@ import org.optaplanner.core.api.domain.lookup.PlanningId;
 
 /**
  * adapted from optaplanner quarkus quickstart :
- * 
https://github.com/quarkusio/quarkus-quickstarts/blob/master/optaplanner-quickstart/src/main/java/org/acme/optaplanner/domain/TimeTable.java
+ * 
https://github.com/kiegroup/optaplanner-quickstarts/blob/stable/quarkus-school-timetabling/src/main/java/org/acme/schooltimetabling/domain/Timeslot.java
  */
 public class Timeslot {
 
diff --git 
a/integration-tests/optaplanner/src/test/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerTest.java
 
b/integration-tests/optaplanner/src/test/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerTest.java
index de30a7e..a519555 100644
--- 
a/integration-tests/optaplanner/src/test/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerTest.java
+++ 
b/integration-tests/optaplanner/src/test/java/org/apache/camel/quarkus/component/optaplanner/it/OptaplannerTest.java
@@ -16,10 +16,14 @@
  */
 package org.apache.camel.quarkus.component.optaplanner.it;
 
+import java.util.concurrent.TimeUnit;
+
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
+import org.apache.camel.quarkus.component.optaplanner.it.domain.TimeTable;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.hamcrest.Matchers.notNullValue;
 
 @QuarkusTest
@@ -45,13 +49,11 @@ class OptaplannerTest {
                 .body("lessonList[0].timeslot", notNullValue(null))
                 .body("lessonList[0].room", notNullValue(null));
 
-        // test consumer data
-        RestAssured.given()
-                .get("/optaplanner/newBestSolution")
-                .then()
-                .statusCode(200)
-                .body("lessonList[0].timeslot", notNullValue(null))
-                .body("lessonList[0].room", notNullValue(null));
+        await().atMost(10L, TimeUnit.SECONDS).until(() -> {
+            TimeTable result = 
RestAssured.get("/optaplanner/newBestSolution").then().extract().body().as(TimeTable.class);
+            return result != null && 
result.getLessonList().get(0).getTimeslot() != null
+                    && result.getLessonList().get(0).getRoom() != null;
+        });
     }
 
 }

Reply via email to