1   package com.sri.emo.wizard.completion.model;
2   
3   import java.util.Iterator;
4   
5   import com.jcorporate.expresso.core.controller.ErrorCollection;
6   
7   
8   
9   /***
10   * This is a test model for a simple completion wizard.  The wizard allows
11   * for completing a new Star Wars original series movie by cloning Star Wars:
12   * A New Hope and allowing for different titles and lengths and user ratings, but having the
13   * same actors and parental rating.
14   *
15   * @author Michael Rimov
16   * @version 1.0
17   */
18  public class CompletionWizardTestBean {
19  
20      public static final String TITLE = "Create New Star Wars";
21  
22      public static final String SUMMARY = "This wizard allows you to play George Lucas";
23  
24      public static final int TARGET_NODE = 4; //Star Wars: A New Hope
25  
26      public static final int PART_RATING = 5;
27  
28      public static final int USER_REVIEWS = 6;
29  
30      public static final int ACTORS = 7;
31  
32      public static final int CRITIQUES = 8;
33  
34      public static final int MIN_ACTORS = 1;
35  
36      public static final int MAX_ACTORS = 10;
37  
38      public static final int MIN_CRITIQUES = 1;
39  
40      public static final int MAX_CRITIQUES = 5;
41  
42      public static final int LENGTH = 4;
43  
44      public static final String LENGTH_DIRECTIVE = "Enter the movie length in minutes";
45  
46      public static final String LENGTH_HELPTEXT = "Otherwise nobody will know if they can go to the bathroom or not";
47  
48  
49      public static final int NUMBER_OF_PARTS = 5;
50  
51  
52      private CompletionBean completionBean;
53  
54  
55  
56      public CompletionWizardTestBean() {
57          super();
58      }
59  
60      public void setUp() throws Exception {
61          completionBean = new CompletionBean();
62          completionBean.setTargetId(TARGET_NODE);
63          ErrorCollection ec = new ErrorCollection();
64          completionBean.initializeFromNodeId(ec);
65          if (ec.getErrorCount() != 0) {
66              throw new AssertionError("Errors encountered initializing from node: " + ec.getErrorStrings());
67          }
68          completionBean.setWizardTitle(TITLE);
69          completionBean.setSummary(SUMMARY);
70  
71          boolean ratingTouched = false;
72          boolean reviewsTouched = false;
73          boolean lengthTouched = false;
74          boolean actorsTouched = false;
75  
76          for (Iterator i = completionBean.getCompletionParts().iterator(); i.hasNext();) {
77              CompletionPartsBean onePart = (CompletionPartsBean)i.next();
78  
79              if (Integer.parseInt(onePart.getPart().getId()) == PART_RATING) {
80                  onePart.setFieldCompletion(FieldCompletion.FIXED);
81                  ratingTouched = true;
82  
83              } else if (Integer.parseInt(onePart.getPart().getId()) == USER_REVIEWS ) {
84                  onePart.setFieldCompletion(FieldCompletion.WIZARD);
85                  reviewsTouched = true;
86  
87              } else if (Integer.parseInt(onePart.getPart().getId()) == LENGTH ) {
88                  onePart.setFieldCompletion(FieldCompletion.WIZARD);
89                  onePart.setDirective(LENGTH_DIRECTIVE);
90                  onePart.setHelpText(LENGTH_HELPTEXT);
91                  lengthTouched = true;
92              } else if (Integer.parseInt(onePart.getPart().getId()) == ACTORS) {
93                  onePart.setFieldCompletion(FieldCompletion.FIXED);
94                  onePart.setMaxEntries(MAX_ACTORS);
95                  onePart.setMinEntries(MIN_ACTORS);
96                  actorsTouched = true;
97              } else if (Integer.parseInt(onePart.getPart().getId()) == CRITIQUES) {
98                  onePart.setFieldCompletion(FieldCompletion.WIZARD);
99                  onePart.setMaxEntries(MAX_CRITIQUES);
100                 onePart.setMinEntries(MIN_CRITIQUES);
101                 actorsTouched = true;
102 
103             } else {
104                 System.err.println("Encountered unknown part: " + onePart.getPart().getId());
105             }
106 
107         }
108 
109         if (!ratingTouched) {
110             throw new AssertionError("Didn't encounter a rating part");
111         }
112 
113         if (!reviewsTouched) {
114             throw new AssertionError("Didn't encounter a user reviews part");
115         }
116 
117 
118         if (!lengthTouched) {
119             throw new AssertionError("Didn't encounter a movie length part");
120         }
121 
122         if (!actorsTouched) {
123             throw new AssertionError("Didn't encounter an actors relation");
124         }
125 
126     }
127 
128     public void tearDown() {
129         completionBean = null;
130 
131     }
132 
133     public CompletionBean getConstructedBean() {
134         return completionBean;
135     }
136 
137 }