1
2
3
4
5
6
7
8
9
10 package com.sri.emo.wizard.completion.management;
11
12 import java.util.HashMap;
13 import java.util.Iterator;
14 import java.util.Map;
15 import java.util.Set;
16 import com.jcorporate.expresso.core.controller.Controller;
17 import com.jcorporate.expresso.core.controller.ControllerException;
18 import com.jcorporate.expresso.core.controller.ExpressoRequest;
19 import com.jcorporate.expresso.core.controller.ExpressoResponse;
20 import com.jcorporate.expresso.core.controller.NonHandleableException;
21 import com.jcorporate.expresso.core.db.DBException;
22 import com.sri.emo.dbobj.Part;
23 import com.sri.emo.dbobj.PartsFactory;
24 import com.sri.emo.wizard.completion.model.CompletionBean;
25 import com.sri.emo.wizard.completion.model.CompletionPartsBean;
26
27 /***
28 * Test of PromptChooseParts state handler.
29 */
30 public class TestPromptChooseParts extends ChooseCompletionTestBase {
31
32 /***
33 * Checks that all parts set up match that of PartsFactory.
34 * @throws DBException
35 * @throws ControllerException
36 * @throws NonHandleableException
37 */
38 public void testListParts() throws DBException, ControllerException, NonHandleableException {
39 Map parameters = new HashMap();
40 ExpressoRequest request = testFixture.buildControllerRequest(parameters, PromptChooseParts.STATE_NAME);
41 CompletionBean cb = new CompletionBean();
42 cb.setTargetId(2);
43 cb.initializeFromNodeId(null);
44 request.getSession().setPersistentAttribute(CompletionBeanManager.BEAN_NAME, cb);
45
46 Controller controller = testFixture.buildController(CompletionEditor.class);
47 ExpressoResponse response = testFixture.invokeState(PromptChooseParts.STATE_NAME, controller, request);
48
49 assertTrue(response != null);
50 assertTrue(response.getErrors() == null || response.getErrors().size() == 0);
51
52 cb = (CompletionBean)request.getSession().getPersistentAttribute(CompletionBeanManager.BEAN_NAME);
53 assertTrue(cb != null);
54
55 Set allParts = cb.getCompletionParts();
56 assertTrue(allParts != null);
57
58
59 Part[] moviedemoParts = PartsFactory.getParts("MOVIEDEMO");
60 assertEquals(moviedemoParts.length, allParts.size());
61
62
63
64 int index = 0;
65 for (Iterator i = allParts.iterator(); i.hasNext();) {
66 CompletionPartsBean partsBean = (CompletionPartsBean)i.next();
67 assertEquals(moviedemoParts[index].getPartNumInt(), partsBean.getPart().getPartNumInt());
68
69
70
71 index++;
72 }
73
74 }
75
76 }