Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 090034D8D for ; Thu, 7 Jul 2011 09:55:59 +0000 (UTC) Received: (qmail 71501 invoked by uid 500); 7 Jul 2011 09:55:58 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 71027 invoked by uid 500); 7 Jul 2011 09:55:51 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 71019 invoked by uid 99); 7 Jul 2011 09:55:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 09:55:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 09:55:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1C89F2388A19 for ; Thu, 7 Jul 2011 09:55:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1143739 - /camel/trunk/camel-core/src/test/java/org/apache/camel/model/ChoiceDefinitionTest.java Date: Thu, 07 Jul 2011 09:55:23 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110707095523.1C89F2388A19@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Thu Jul 7 09:55:22 2011 New Revision: 1143739 URL: http://svn.apache.org/viewvc?rev=1143739&view=rev Log: CAMEL-4044: Added unit test for better code coverage. Added: camel/trunk/camel-core/src/test/java/org/apache/camel/model/ChoiceDefinitionTest.java Added: camel/trunk/camel-core/src/test/java/org/apache/camel/model/ChoiceDefinitionTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/model/ChoiceDefinitionTest.java?rev=1143739&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/model/ChoiceDefinitionTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/model/ChoiceDefinitionTest.java Thu Jul 7 09:55:22 2011 @@ -0,0 +1,218 @@ +/** + * 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.model; + +import org.apache.camel.TestSupport; + +/** + * + */ +public class ChoiceDefinitionTest extends TestSupport { + + public void testChoiceOutputOrder() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + OtherwiseDefinition other = new OtherwiseDefinition(); + + choice.addOutput(when1); + choice.addOutput(when2); + choice.addOutput(other); + + assertEquals(3, choice.getOutputs().size()); + assertEquals(when1, choice.getOutputs().get(0)); + assertEquals(when2, choice.getOutputs().get(1)); + assertEquals(other, choice.getOutputs().get(2)); + } + + public void testChoiceOutputOrderIterate() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + OtherwiseDefinition other = new OtherwiseDefinition(); + + choice.addOutput(when1); + choice.addOutput(when2); + choice.addOutput(other); + + assertEquals(3, choice.getOutputs().size()); + int i = 0; + for (ProcessorDefinition def : choice.getOutputs()) { + if (i == 0) { + assertEquals(when1, def); + } else if (i == 1) { + assertEquals(when2, def); + } else { + assertEquals(other, def); + } + i++; + } + } + + public void testChoiceOutputOrderNoOtherwise() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + + choice.addOutput(when1); + choice.addOutput(when2); + + assertEquals(2, choice.getOutputs().size()); + assertEquals(when1, choice.getOutputs().get(0)); + assertEquals(when2, choice.getOutputs().get(1)); + } + + public void testChoiceOutputOrderNoOtherwiseIterate() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + + choice.addOutput(when1); + choice.addOutput(when2); + + assertEquals(2, choice.getOutputs().size()); + assertEquals(when1, choice.getOutputs().get(0)); + assertEquals(when2, choice.getOutputs().get(1)); + + assertEquals(2, choice.getOutputs().size()); + int i = 0; + for (ProcessorDefinition def : choice.getOutputs()) { + if (i == 0) { + assertEquals(when1, def); + } else if (i == 1) { + assertEquals(when2, def); + } + i++; + } + } + + public void testChoiceOtherwiseAlwaysLast() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + OtherwiseDefinition other = new OtherwiseDefinition(); + + // add otherwise in between + choice.addOutput(when1); + choice.addOutput(other); + choice.addOutput(when2); + + // should ensure otherwise is last + assertEquals(3, choice.getOutputs().size()); + assertEquals(when1, choice.getOutputs().get(0)); + assertEquals(when2, choice.getOutputs().get(1)); + assertEquals(other, choice.getOutputs().get(2)); + } + + public void testChoiceOtherwiseAlwaysLastIterate() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + OtherwiseDefinition other = new OtherwiseDefinition(); + + // add otherwise in between + choice.addOutput(when1); + choice.addOutput(other); + choice.addOutput(when2); + + // should ensure otherwise is last + assertEquals(3, choice.getOutputs().size()); + assertEquals(when1, choice.getOutputs().get(0)); + assertEquals(when2, choice.getOutputs().get(1)); + assertEquals(other, choice.getOutputs().get(2)); + + assertEquals(3, choice.getOutputs().size()); + int i = 0; + for (ProcessorDefinition def : choice.getOutputs()) { + if (i == 0) { + assertEquals(when1, def); + } else if (i == 1) { + assertEquals(when2, def); + } else { + assertEquals(other, def); + } + i++; + } + } + + public void testChoiceOutputRemoveFirst() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + OtherwiseDefinition other = new OtherwiseDefinition(); + + choice.addOutput(when1); + choice.addOutput(when2); + choice.addOutput(other); + + assertEquals(3, choice.getOutputs().size()); + choice.getOutputs().remove(0); + assertEquals(2, choice.getOutputs().size()); + assertEquals(when2, choice.getOutputs().get(0)); + assertEquals(other, choice.getOutputs().get(1)); + } + + public void testChoiceOutputRemoveLast() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + OtherwiseDefinition other = new OtherwiseDefinition(); + + choice.addOutput(when1); + choice.addOutput(when2); + choice.addOutput(other); + + assertEquals(3, choice.getOutputs().size()); + choice.getOutputs().remove(2); + assertEquals(2, choice.getOutputs().size()); + assertEquals(when1, choice.getOutputs().get(0)); + assertEquals(when2, choice.getOutputs().get(1)); + } + + public void testChoiceOutputSetFirst() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + WhenDefinition when3 = new WhenDefinition(body().contains("Beer")); + OtherwiseDefinition other = new OtherwiseDefinition(); + + choice.addOutput(when1); + choice.addOutput(when2); + choice.addOutput(other); + + assertEquals(3, choice.getOutputs().size()); + choice.getOutputs().set(0, when3); + assertEquals(3, choice.getOutputs().size()); + assertEquals(when3, choice.getOutputs().get(0)); + assertEquals(when2, choice.getOutputs().get(1)); + assertEquals(other, choice.getOutputs().get(2)); + } + + public void testChoiceOutputClear() throws Exception { + ChoiceDefinition choice = new ChoiceDefinition(); + WhenDefinition when1 = new WhenDefinition(body().contains("Camel")); + WhenDefinition when2 = new WhenDefinition(body().contains("Donkey")); + + choice.addOutput(when1); + choice.addOutput(when2); + + assertEquals(2, choice.getOutputs().size()); + choice.getOutputs().clear(); + assertEquals(0, choice.getOutputs().size()); + } + +}