1   /*
2    * $Id: OperationCandidateTest.java 916 2008-07-08 15:47:06Z kwfgrid.bassheide $
3    *
4    * Copyright (c) 2008, Fraunhofer FIRST
5    * Fraunhofer Institute for Computer Architecture and Software Technology
6    * See http://www.first.fraunhofer.de and http://www.gridworkflow.org/gwes for more details.
7    */
8   package net.kwfgrid.gworkflowdl;
9   
10  import junit.framework.Test;
11  import junit.framework.TestSuite;
12  import junit.framework.Assert;
13  import net.kwfgrid.gworkflowdl.structure.Factory;
14  import net.kwfgrid.gworkflowdl.structure.Operation;
15  import net.kwfgrid.gworkflowdl.structure.OperationCandidate;
16  
17  public final class OperationCandidateTest extends AbstractTestCase {
18  
19      static float quality = 0.0f;
20  
21      /***
22       * Create the test case.
23       *
24       * @param testName name of the test case
25       */
26      public OperationCandidateTest(String testName) {
27          super(testName);
28      }
29  
30      /***
31       * @return the suite of tests being tested
32       */
33      public static Test suite() {
34          return new TestSuite(OperationCandidateTest.class);
35      }
36  
37      /***
38       * Create a test OperationCandate.
39       * @param substring String used as part of attributes of this element.
40       * @return
41       */
42      public static OperationCandidate example(String substring) {
43          OperationCandidate clop = Factory.newOperationCandidate();
44          clop.setType(substring+"_type");
45          clop.setOperationName(substring+"_operationName");
46          clop.setResourceName(substring+"_resourceName");
47          clop.setQuality(quality);
48          quality += 0.1f;
49          if (quality > 1.0f) quality = 0.0f;
50          return clop;
51      }
52  
53      public void testOperationCandidate() {
54          OperationCandidate clop = Factory.newOperationCandidate();
55          Assert.assertFalse(clop.isSelected());
56          Assert.assertEquals("abstraction level", Operation.BLUE, clop.getAbstractionLevel());
57  
58          clop.setSelected(true);
59          Assert.assertTrue(clop.isSelected());
60          Assert.assertEquals("abstraction level", Operation.GREEN, clop.getAbstractionLevel());
61  
62          clop.setSelected(false);
63          Assert.assertFalse(clop.isSelected());
64          Assert.assertEquals("abstraction level", Operation.BLUE, clop.getAbstractionLevel());
65  
66          OperationCandidate clop2 = example("test0");
67          Assert.assertEquals("Type","test0_type",clop2.getType());
68          Assert.assertEquals("OperationName","test0_operationName",clop2.getOperationName());
69          Assert.assertEquals("ResourceName","test0_resourceName",clop2.getResourceName());
70          Assert.assertEquals("Quality",0.0f,clop2.getQuality(),0.01f);
71          Assert.assertFalse("isSelected",clop2.isSelected());
72      }
73  
74  }