1   /*
2    * $Id: OperationClassTest.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.*;
15  
16  public final class OperationClassTest extends AbstractTestCase {
17  
18      /***
19       * Create the test case.
20       *
21       * @param testName name of the test case
22       */
23      public OperationClassTest(String testName) {
24          super(testName);
25      }
26  
27      /***
28       * @return the suite of tests being tested
29       */
30      public static Test suite() {
31          return new TestSuite(OperationClassTest.class);
32      }
33  
34      /***
35       *
36       * @param numberOperationCandidates
37       * @return
38       */
39      public static OperationClass example(String substring, int numberOperationCandidates) {
40          OperationClass oc = Factory.newOperationClass();
41          oc.setName(substring+"_classname");
42  
43          if (numberOperationCandidates>0) {
44              OperationCandidate[] ops = new OperationCandidate[numberOperationCandidates];
45              for (int i = 0; i < numberOperationCandidates; i++) {
46                  ops[i] = OperationCandidateTest.example(substring);
47              }
48              oc.setOperationCandidates(ops);
49          }
50          return oc;
51      }
52  
53      /***
54       * Test Operation Class
55       */
56      public void testOperationClass() {
57          OperationClass o = Factory.newOperationClass();
58  
59          Assert.assertEquals("Default operation candidates", o.getOperationCandidates(), OperationClass.DEFAULT_OPERATIONCANDIDATES);
60          Assert.assertEquals("Default operation class name", o.getName(), OperationClass.DEFAULT_OPERATIONCLASSNAME);
61          Assert.assertEquals("Abstraction level", Operation.YELLOW, o.getAbstractionLevel());
62  
63          OperationClass o2 = example("o2",4);
64          Assert.assertEquals("Operation count",4,o2.getOperationCount());
65          Assert.assertEquals("Operation Class name", "o2_classname", o2.getName());
66          Assert.assertEquals("Abstraction level", Operation.BLUE, o2.getAbstractionLevel());
67          o2.getOperationCandidates()[2].setSelected();
68          Assert.assertEquals("Abstraction level", Operation.GREEN, o2.getAbstractionLevel());
69      }
70  }