1 package com.sri.emo.wizard.completion; 2 3 import com.jcorporate.expresso.services.test.TestSystemInitializer; 4 import com.sri.emo.test.DatabaseTestFixture; 5 import com.sri.emo.test.EmoTestSuite; 6 import com.sri.emo.wizard.Wizard; 7 import com.sri.emo.wizard.WizardException; 8 import com.sri.emo.wizard.WizardPage; 9 import com.sri.emo.wizard.completion.persistence.CompletionDBObjConverterImpl; 10 import com.sri.emo.wizard.completion.persistence.ExpressoCompletionRepository; 11 import com.sri.emo.wizard.defaults.EmoWizardPage; 12 import junit.framework.TestCase; 13 import com.jcorporate.expresso.core.security.SuperUser; 14 import com.jcorporate.expresso.core.registry.MutableRequestRegistry; 15 import com.sri.emo.wizard.PageMetadata; 16 17 /*** 18 * Tests all the various parts of the Emo Completion Factory. 19 * @author Michael Rimov 20 * @version 1.0 21 */ 22 public class TestEmoCompletionFactory extends TestCase { 23 24 private DatabaseTestFixture databaseFixture = null; 25 26 27 private EmoCompletionFactory factory; 28 29 30 public TestEmoCompletionFactory() { 31 super(); 32 try { 33 TestSystemInitializer.setUp(); 34 new MutableRequestRegistry(TestSystemInitializer.getTestContext(), SuperUser.INSTANCE); 35 } catch (Exception ex) { 36 throw new RuntimeException("Error setting things up",ex); 37 } 38 } 39 40 41 protected void setUp() throws Exception { 42 super.setUp(); 43 44 databaseFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(), 45 EmoTestSuite.class.getResourceAsStream("WizardTestData.xml")); 46 databaseFixture.setUp(); 47 48 factory = new EmoCompletionFactory(new ExpressoCompletionRepository(new CompletionDBObjConverterImpl())); 49 50 } 51 52 protected void tearDown() throws Exception { 53 databaseFixture.tearDown(); 54 databaseFixture = null; 55 factory = null; 56 super.tearDown(); 57 } 58 59 public static final int PLAY_GEORGE_LUCAS = 15; 60 61 private static final Integer PAGE_WITH_PICKLIST = new Integer(6); 62 public void testBuildWizardStepWithPickListGetsMenu() throws WizardException { 63 factory.setWizardId(PLAY_GEORGE_LUCAS); 64 Wizard wiz = factory.buildWizard(); 65 assertNotNull(wiz); 66 WizardPage onePage = wiz.getPageById(PAGE_WITH_PICKLIST); 67 assertNotNull(onePage.getMenu()); 68 assertTrue(onePage.getMenu().length > 0); 69 assertTrue(onePage.getMetadata().isEntryRequired() == false); 70 } 71 72 73 private static final Integer PAGE_WITH_FREETEXT = new Integer(4); 74 public void testBuildWizardStepWithFreeEntryGetsTextBox() throws WizardException { 75 factory.setWizardId(PLAY_GEORGE_LUCAS); 76 Wizard wiz = factory.buildWizard(); 77 assertNotNull(wiz); 78 WizardPage onePage = wiz.getPageById(PAGE_WITH_FREETEXT); 79 assertNull(onePage.getMenu()); 80 assertTrue(onePage.getMetadata().isEntryRequired() == false); 81 assertTrue(onePage instanceof EmoWizardPage); 82 } 83 84 85 private static final Integer PAGE_WITH_RELATIONS = new Integer(7); 86 public void testBuildWizardStepWithRelationsGetsCheckboxes() throws WizardException { 87 factory.setWizardId(PLAY_GEORGE_LUCAS); 88 Wizard wiz = factory.buildWizard(); 89 WizardPage onePage = wiz.getPageById(PAGE_WITH_RELATIONS); 90 assertNotNull(onePage); 91 assertNull(onePage.getMenu()); 92 assertTrue (onePage instanceof RelationWizardPage); 93 94 RelationWizardPage relationPage = (RelationWizardPage)onePage; 95 RelationPageMetadata metadata = relationPage.getRelationPageMetadata(); 96 assertNotNull(metadata); 97 assertNotNull(metadata.getMinEntries()); 98 assertNotNull(metadata.getMaxEntries()); 99 assertEquals(1, metadata.getMinEntries().intValue()); 100 assertEquals(3, metadata.getMaxEntries().intValue()); 101 } 102 103 private static final Integer PAGE_WITH_MULTI_ATTRIBUTES = new Integer(8); 104 public void testBuildWizardStepWtihMultipleAttributes() throws WizardException { 105 factory.setWizardId(PLAY_GEORGE_LUCAS); 106 Wizard wiz = factory.buildWizard(); 107 WizardPage onePage = wiz.getPageById(PAGE_WITH_MULTI_ATTRIBUTES); 108 109 assertNotNull(onePage); 110 assertTrue(onePage instanceof EmoWizardPage); 111 PageMetadata pageMetadata = onePage.getMetadata(); 112 assertTrue(pageMetadata instanceof MultiEntryMetadata); 113 assertEquals("MultiAttributeWizardEntry", pageMetadata.getViewId()); 114 assertEquals(true, pageMetadata.isHasEntry()); 115 MultiEntryMetadata multiMeta = (MultiEntryMetadata)pageMetadata; 116 assertEquals(multiMeta.getMinEntries().intValue(),1); 117 assertEquals(multiMeta.getMaxEntries().intValue(),7); 118 119 120 } 121 122 }