1   /*
2    * $Id: OperationTest.java 1309 2009-05-22 18:56:38Z andreas.hoheisel@first.fraunhofer.de $
3    *
4    * Copyright (c) 2005, The K-Wf Grid Consortium
5    * Fraunhofer Institute for Computer Architecture and Software Technology
6    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
7    */
8   
9   package net.kwfgrid.gworkflowdl;
10  
11  import junit.framework.Assert;
12  import junit.framework.Test;
13  import junit.framework.TestSuite;
14  import net.kwfgrid.gworkflowdl.structure.Factory;
15  import net.kwfgrid.gworkflowdl.structure.Operation;
16  import net.kwfgrid.gworkflowdl.structure.OperationClass;
17  
18  public final class OperationTest extends AbstractTestCase {
19  
20      /***
21       * Create the test case.
22       *
23       * @param testName name of the test case
24       */
25      public OperationTest(String testName) {
26          super(testName);
27      }
28  
29      /***
30       * @return the suite of tests being tested
31       */
32      public static Test suite() {
33          return new TestSuite(OperationTest.class);
34      }
35  
36      public static Operation example(String substring, int numberOperationCandidates) {
37          Operation op = Factory.newOperation();
38          if (numberOperationCandidates > 0) {
39              op.set(OperationClassTest.example(substring, numberOperationCandidates));
40          }
41          return op;
42      }
43  
44      public void testOperation() {
45          Operation op = Factory.newOperation();
46          Assert.assertEquals("Default operation object", op.get(),Operation.DEFAULT_OBJECT);
47          Assert.assertEquals("Abstraction level", Operation.RED, op.getAbstractionLevel());
48          OperationClass opc = Factory.newOperationClass();
49          op.set(opc);
50          Assert.assertEquals("Abstraction level", Operation.YELLOW, op.getAbstractionLevel());
51  
52          Operation op2 = example("op2",2);
53          Assert.assertEquals("Abstraction level", Operation.BLUE, op2.getAbstractionLevel());
54  
55          if (op2.get() instanceof OperationClass) {
56              OperationClass oc = (OperationClass) op2.get();
57              oc.getOperationCandidates()[1].setSelected();
58              Assert.assertEquals("Abstraction level", Operation.GREEN, op2.getAbstractionLevel());
59          } else {
60              Assert.fail("Operation object is not insanceof OperationClass");
61          }
62      }
63  }