hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/test/org/apache/hivemind/conditional TestEvaluationContext.java TestNode.java TestEvaluators.java
Date Sun, 19 Dec 2004 15:42:45 GMT
hlship      2004/12/19 07:42:45

  Added:       framework/src/test/org/apache/hivemind/conditional
                        TestEvaluationContext.java TestNode.java
                        TestEvaluators.java
  Log:
  Begin adding conditional contribution support.
  
  Revision  Changes    Path
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/conditional/TestEvaluationContext.java
  
  Index: TestEvaluationContext.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed 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.hivemind.conditional;
  
  import org.apache.hivemind.condtional.EvaluationContext;
  import org.apache.hivemind.condtional.EvaluationContextImpl;
  import org.apache.hivemind.impl.DefaultClassResolver;
  import org.apache.hivemind.test.HiveMindTestCase;
  
  /**
   * Tests for {@link org.apache.hivemind.condtional.EvaluationContextImpl}.
   * 
   * @author Howard M. Lewis Ship
   */
  public class TestEvaluationContext extends HiveMindTestCase
  {
      public void testProperty()
      {
          EvaluationContext ec = new EvaluationContextImpl(new DefaultClassResolver());
  
          // Note: test will fail unless
          // -Dproperty-set-for-evaluation-context=true
          // is on JVM command line.
  
          assertEquals(true, ec.isPropertySet("property-set-for-evaluation-context"));
          assertEquals(false, ec.isPropertySet("this-property-does-not-exist"));
      }
  
      public void testClass()
      {
          EvaluationContext ec = new EvaluationContextImpl(new DefaultClassResolver());
  
          assertEquals(true, ec.doesClassExist("java.lang.Object"));
          assertEquals(true, ec.doesClassExist(EvaluationContext.class.getName()));
          assertEquals(false, ec.doesClassExist("org.apache.hivemind.NoSuchClass"));
      }
  }
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/conditional/TestNode.java
  
  Index: TestNode.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed 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.hivemind.conditional;
  
  import org.apache.hivemind.condtional.EvaluationContext;
  import org.apache.hivemind.condtional.Evaluator;
  import org.apache.hivemind.condtional.Node;
  import org.apache.hivemind.condtional.NodeImpl;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.apache.xalan.extensions.ExpressionContext;
  import org.easymock.MockControl;
  
  /**
   * Tests for the {@link org.apache.hivemind.condtional.NodeImpl}class.
   * 
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class TestNode extends HiveMindTestCase
  {
      public void testConstructorAndGetters()
      {
          Node left = (Node) newMock(Node.class);
          Node right = (Node) newMock(Node.class);
          Evaluator evaluator = (Evaluator) newMock(Evaluator.class);
  
          replayControls();
  
          Node n = new NodeImpl(left, right, evaluator);
  
          assertSame(left, n.getLeft());
          assertSame(right, n.getRight());
  
          verifyControls();
      }
  
      public void testEvaluate()
      {
          MockControl control = newControl(Evaluator.class);
          Evaluator evaluator = (Evaluator) control.getMock();
          EvaluationContext context = (EvaluationContext) newMock(EvaluationContext.class);
  
          Node n = new NodeImpl(evaluator);
  
          evaluator.evaluate(context, n);
          control.setReturnValue(false);
  
          evaluator.evaluate(context, n);
          control.setReturnValue(true);
  
          replayControls();
  
          assertEquals(false, n.evaluate(context));
          assertEquals(true, n.evaluate(context));
  
          verifyControls();
      }
  }
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/conditional/TestEvaluators.java
  
  Index: TestEvaluators.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed 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.hivemind.conditional;
  
  import org.apache.hivemind.condtional.AndEvaluator;
  import org.apache.hivemind.condtional.ClassNameEvaluator;
  import org.apache.hivemind.condtional.EvaluationContext;
  import org.apache.hivemind.condtional.Node;
  import org.apache.hivemind.condtional.NodeImpl;
  import org.apache.hivemind.condtional.NotEvaluator;
  import org.apache.hivemind.condtional.OrEvaluator;
  import org.apache.hivemind.condtional.PropertyEvaulator;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.easymock.MockControl;
  
  /**
   * Tests for {@link org.apache.hivemind.condtional.PropertyEvaulator}.
   * 
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class TestEvaluators extends HiveMindTestCase
  {
      private EvaluationContext newContext()
      {
          return (EvaluationContext) newMock(EvaluationContext.class);
      }
  
      private Node newNode(EvaluationContext context, boolean value)
      {
          MockControl control = newControl(Node.class);
          Node node = (Node) control.getMock();
  
          node.evaluate(context);
  
          control.setReturnValue(value);
  
          return node;
      }
  
      private Node newNode()
      {
          return (Node) newMock(Node.class);
      }
  
      public void testPropertyEvaluator()
      {
          MockControl control = newControl(EvaluationContext.class);
          EvaluationContext context = (EvaluationContext) control.getMock();
  
          context.isPropertySet("foo.bar");
          control.setReturnValue(true);
  
          replayControls();
  
          PropertyEvaulator pe = new PropertyEvaulator("foo.bar");
  
          assertEquals(true, pe.evaluate(context, null));
  
          verifyControls();
      }
  
      public void testClassNameEvaluator()
      {
          MockControl control = newControl(EvaluationContext.class);
          EvaluationContext context = (EvaluationContext) control.getMock();
  
          context.doesClassExist("foo.bar.Baz");
          control.setReturnValue(true);
  
          replayControls();
  
          ClassNameEvaluator e = new ClassNameEvaluator("foo.bar.Baz");
  
          assertEquals(true, e.evaluate(context, null));
  
          verifyControls();
      }
  
      public void testNotEvaluator()
      {
          EvaluationContext context = newContext();
          Node left = newNode(context, true);
  
          Node node = new NodeImpl(left, null, new NotEvaluator());
  
          replayControls();
  
          assertEquals(false, node.evaluate(context));
  
          verifyControls();
      }
  
      public void testAndEvaluatorTrue()
      {
          EvaluationContext context = newContext();
          Node left = newNode(context, true);
          Node right = newNode(context, true);
  
          Node node = new NodeImpl(left, right, new AndEvaluator());
  
          replayControls();
  
          assertEquals(true, node.evaluate(context));
  
          verifyControls();
      }
  
      public void testAndEvaluatorShortcicuit()
      {
          EvaluationContext context = newContext();
          Node left = newNode(context, false);
          Node right = newNode();
  
          Node node = new NodeImpl(left, right, new AndEvaluator());
  
          replayControls();
  
          assertEquals(false, node.evaluate(context));
  
          verifyControls();
      }
  
      public void testAndEvaluatorFalse()
      {
          EvaluationContext context = newContext();
          Node left = newNode(context, true);
          Node right = newNode(context, false);
  
          Node node = new NodeImpl(left, right, new AndEvaluator());
  
          replayControls();
  
          assertEquals(false, node.evaluate(context));
  
          verifyControls();
      }
  
      public void testOrEvaluatorTrue()
      {
          EvaluationContext context = newContext();
          Node left = newNode(context, false);
          Node right = newNode(context, true);
  
          Node node = new NodeImpl(left, right, new OrEvaluator());
  
          replayControls();
  
          assertEquals(true, node.evaluate(context));
  
          verifyControls();
      }
  
      public void testOrEvaluatorShortcicuit()
      {
          EvaluationContext context = newContext();
          Node left = newNode(context, true);
          Node right = newNode();
  
          Node node = new NodeImpl(left, right, new OrEvaluator());
  
          replayControls();
  
          assertEquals(true, node.evaluate(context));
  
          verifyControls();
      }
  
      public void testOrEvaluatorFalse()
      {
          EvaluationContext context = newContext();
          Node left = newNode(context, false);
          Node right = newNode(context, false);
  
          Node node = new NodeImpl(left, right, new OrEvaluator());
  
          replayControls();
  
          assertEquals(false, node.evaluate(context));
  
          verifyControls();
      }
  
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message