camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: camel-optaplanner test: extract local variable mockEndpoint + extract inner class RemoveComputerChange
Date Tue, 13 Oct 2015 13:58:59 GMT
Repository: camel
Updated Branches:
  refs/heads/master 1596d267e -> bd1c3957d


camel-optaplanner test: extract local variable mockEndpoint + extract inner class RemoveComputerChange


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/697e7359
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/697e7359
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/697e7359

Branch: refs/heads/master
Commit: 697e735966014d292ff84633598e9e6ffd604d62
Parents: 1596d26
Author: Geoffrey De Smet <gds.geoffrey.de.smet@gmail.com>
Authored: Tue Oct 13 11:11:11 2015 +0200
Committer: Geoffrey De Smet <gds.geoffrey.de.smet@gmail.com>
Committed: Tue Oct 13 11:11:11 2015 +0200

----------------------------------------------------------------------
 .../OptaPlannerDaemonSolverTest.java            | 73 +++++++++++---------
 1 file changed, 41 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/697e7359/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerDaemonSolverTest.java
----------------------------------------------------------------------
diff --git a/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerDaemonSolverTest.java
b/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerDaemonSolverTest.java
index 663776f..0b48eb1 100644
--- a/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerDaemonSolverTest.java
+++ b/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerDaemonSolverTest.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.commons.lang3.ObjectUtils;
 import org.junit.Test;
@@ -37,47 +38,25 @@ public class OptaPlannerDaemonSolverTest extends CamelTestSupport {
 
     @Test
     public void testAsynchronousProblemSolving() throws Exception {
-        getMockEndpoint("mock:result").setExpectedCount(1);
+        MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
+        mockEndpoint.setExpectedCount(1);
         CloudBalancingGenerator generator = new CloudBalancingGenerator(true);
         final CloudBalance planningProblem = generator.createCloudBalance(4, 12);
         assertNull(planningProblem.getScore());
         assertNull(planningProblem.getProcessList().get(0).getComputer());
 
         template.requestBody("direct:in", planningProblem);
-        getMockEndpoint("mock:result").assertIsSatisfied();
-        getMockEndpoint("mock:result").reset();
-        getMockEndpoint("mock:result").setExpectedCount(0);
+        mockEndpoint.assertIsSatisfied();
+        mockEndpoint.reset();
+        mockEndpoint.setExpectedCount(1);
 
-        template.requestBody("direct:in", new ProblemFactChange() {
-            @Override
-            public void doChange(ScoreDirector scoreDirector) {
-                CloudBalance cloudBalance = (CloudBalance) scoreDirector.getWorkingSolution();
-                CloudComputer computer = null;
-                for (CloudProcess process : cloudBalance.getProcessList()) {
-                    computer = process.getComputer();
-                    if (ObjectUtils.equals(process.getComputer(), computer)) {
-                        scoreDirector.beforeVariableChanged(process, "computer");
-                        process.setComputer(null);
-                        scoreDirector.afterVariableChanged(process, "computer");
-                    }
-                }
-                cloudBalance.setComputerList(new ArrayList<CloudComputer>(cloudBalance.getComputerList()));
-                for (Iterator<CloudComputer> it = cloudBalance.getComputerList().iterator();
it.hasNext();) {
-                    CloudComputer workingComputer = it.next();
-                    if (ObjectUtils.equals(workingComputer, computer)) {
-                        scoreDirector.beforeProblemFactRemoved(workingComputer);
-                        it.remove(); // remove from list
-                        scoreDirector.beforeProblemFactRemoved(workingComputer);
-                        break;
-                    }
-                }
-            }
-        });
+        CloudComputer firstComputer = planningProblem.getComputerList().get(0);
+        assertNotNull(firstComputer);
+        template.requestBody("direct:in", new RemoveComputerChange(firstComputer));
 
-        getMockEndpoint("mock:result").assertIsSatisfied();
+        mockEndpoint.assertIsSatisfied();
         CloudBalance bestSolution = (CloudBalance) template.requestBody("direct:in", "foo");
-
-        assertEquals(4, bestSolution.getComputerList().size());
+        assertEquals(3, bestSolution.getComputerList().size());
     }
 
     protected RouteBuilder createRouteBuilder() {
@@ -93,4 +72,34 @@ public class OptaPlannerDaemonSolverTest extends CamelTestSupport {
         };
     }
 
+    private static class RemoveComputerChange implements ProblemFactChange {
+
+        private final CloudComputer removingComputer;
+
+        public RemoveComputerChange(CloudComputer removingComputer) {
+            this.removingComputer = removingComputer;
+        }
+
+        @Override
+        public void doChange(ScoreDirector scoreDirector) {
+            CloudBalance cloudBalance = (CloudBalance) scoreDirector.getWorkingSolution();
+            for (CloudProcess process : cloudBalance.getProcessList()) {
+                if (ObjectUtils.equals(process.getComputer(), removingComputer)) {
+                    scoreDirector.beforeVariableChanged(process, "computer");
+                    process.setComputer(null);
+                    scoreDirector.afterVariableChanged(process, "computer");
+                }
+            }
+            cloudBalance.setComputerList(new ArrayList<CloudComputer>(cloudBalance.getComputerList()));
+            for (Iterator<CloudComputer> it = cloudBalance.getComputerList().iterator();
it.hasNext();) {
+                CloudComputer workingComputer = it.next();
+                if (ObjectUtils.equals(workingComputer, removingComputer)) {
+                    scoreDirector.beforeProblemFactRemoved(workingComputer);
+                    it.remove(); // remove from list
+                    scoreDirector.beforeProblemFactRemoved(workingComputer);
+                    break;
+                }
+            }
+        }
+    }
 }


Mime
View raw message