1 package com.sri.emo.wizard.completion; 2 3 import junit.framework.*; 4 import com.jcorporate.expresso.core.security.SuperUser; 5 import com.jcorporate.expresso.services.test.TestSystemInitializer; 6 import com.jcorporate.expresso.core.registry.MutableRequestRegistry; 7 import com.sri.emo.wizard.completion.persistence.CompletionDBObjConverterImpl; 8 import com.sri.emo.wizard.completion.persistence.ExpressoCompletionRepository; 9 import com.sri.emo.test.DatabaseTestFixture; 10 import com.sri.emo.test.EmoTestSuite; 11 import com.sri.emo.wizard.completion.model.CompletionBean; 12 import java.util.Iterator; 13 import com.sri.emo.wizard.completion.model.CompletionPartsBean; 14 import com.sri.emo.wizard.completion.model.FieldCompletion; 15 import com.sri.emo.wizard.completion.model.CompletionWizardTestBean; 16 17 /*** 18 * Tests the database data. Doesn't really do anything other than verify 19 * the model for our use. So technically it isn't even a test case. 20 * @author Michael Rimov 21 * @version 1.0 22 */ 23 public class TestEmoCompletionWizardTestModel extends TestCase { 24 25 private DatabaseTestFixture databaseFixture = null; 26 27 public TestEmoCompletionWizardTestModel() throws Exception { 28 super(); 29 try { 30 TestSystemInitializer.setUp(); 31 new MutableRequestRegistry(TestSystemInitializer.getTestContext(), SuperUser.INSTANCE); 32 } catch (Exception ex) { 33 throw new RuntimeException("Error setting things up",ex); 34 } 35 } 36 37 38 protected void setUp() throws Exception { 39 super.setUp(); 40 databaseFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(), 41 EmoTestSuite.class.getResourceAsStream("WizardTestData.xml")); 42 databaseFixture.setUp(); 43 } 44 45 protected void tearDown() throws Exception { 46 databaseFixture.tearDown(); 47 databaseFixture = null; 48 super.tearDown(); 49 } 50 51 private static final int TEST_ID = 15; 52 public void testFieldCompletionInModel() throws Exception { 53 CompletionRepository repo = new ExpressoCompletionRepository(new CompletionDBObjConverterImpl()); 54 CompletionBean cb = repo.findById(TEST_ID); 55 56 for (Iterator i = cb.getCompletionParts().iterator(); i.hasNext();) { 57 CompletionPartsBean partsbean = (CompletionPartsBean) i.next(); 58 59 switch (new Integer(partsbean.getPart().getId()).intValue()) { 60 case 4: 61 assertEquals(FieldCompletion.WIZARD, partsbean.getFieldCompletion()); 62 break; 63 64 case 5: 65 assertEquals(FieldCompletion.FIXED, partsbean.getFieldCompletion()); 66 break; 67 68 case 6: 69 assertEquals(FieldCompletion.WIZARD, partsbean.getFieldCompletion()); 70 break; 71 72 case 7: 73 assertEquals(FieldCompletion.WIZARD, partsbean.getFieldCompletion()); 74 break; 75 76 case CompletionWizardTestBean.CRITIQUES: 77 assertEquals(FieldCompletion.WIZARD, partsbean.getFieldCompletion()); 78 break; 79 80 81 default: 82 fail("Found unexpected part in test model. Id: " + partsbean.getPart().getId()); 83 } 84 } 85 } 86 87 }