001: package com.mockrunner.test.connector;
002:
003: import java.util.List;
004:
005: import com.mockrunner.mock.connector.cci.MockIndexedRecord;
006: import com.mockrunner.mock.connector.cci.MockMappedRecord;
007: import com.mockrunner.mock.connector.cci.MockRecordFactory;
008:
009: import junit.framework.TestCase;
010:
011: public class MockRecordFactoryTest extends TestCase {
012: private MockRecordFactory recordFactory;
013:
014: protected void setUp() throws Exception {
015: recordFactory = new MockRecordFactory();
016: }
017:
018: protected void tearDown() throws Exception {
019: recordFactory = null;
020: }
021:
022: public void testCreateIndexedRecord() throws Exception {
023: assertEquals(0, recordFactory.getNumberCreatedIndexedRecords());
024: MockIndexedRecord record1 = (MockIndexedRecord) recordFactory
025: .createIndexedRecord("recordName1");
026: assertEquals("recordName1", record1.getRecordName());
027: assertEquals("recordName1", record1.getRecordShortDescription());
028: MockIndexedRecord record2 = (MockIndexedRecord) recordFactory
029: .createIndexedRecord("recordName2");
030: assertEquals("recordName2", record2.getRecordName());
031: assertEquals("recordName2", record2.getRecordShortDescription());
032: assertEquals(2, recordFactory.getNumberCreatedIndexedRecords());
033: List recordList = recordFactory.getCreatedIndexedRecords();
034: assertEquals(2, recordList.size());
035: assertSame(record1, recordList.get(0));
036: assertSame(record2, recordList.get(1));
037: recordFactory.resetIndexedRecords();
038: assertEquals(0, recordFactory.getNumberCreatedIndexedRecords());
039: assertEquals(0, recordFactory.getCreatedIndexedRecords().size());
040: }
041:
042: public void testCreateMappedRecord() throws Exception {
043: assertEquals(0, recordFactory.getNumberCreatedMappedRecords());
044: MockMappedRecord record1 = (MockMappedRecord) recordFactory
045: .createMappedRecord("recordName1");
046: assertEquals("recordName1", record1.getRecordName());
047: assertEquals("recordName1", record1.getRecordShortDescription());
048: MockMappedRecord record2 = (MockMappedRecord) recordFactory
049: .createMappedRecord("recordName2");
050: assertEquals("recordName2", record2.getRecordName());
051: assertEquals("recordName2", record2.getRecordShortDescription());
052: assertEquals(2, recordFactory.getNumberCreatedMappedRecords());
053: List recordList = recordFactory.getCreatedMappedRecords();
054: assertEquals(2, recordList.size());
055: assertSame(record1, recordList.get(0));
056: assertSame(record2, recordList.get(1));
057: recordFactory.resetMappedRecords();
058: assertEquals(0, recordFactory.getNumberCreatedMappedRecords());
059: assertEquals(0, recordFactory.getCreatedMappedRecords().size());
060: }
061:
062: public void testGetCreatedIndexedRecords() throws Exception {
063: MockIndexedRecord record1 = (MockIndexedRecord) recordFactory
064: .createIndexedRecord("recordName");
065: MockIndexedRecord record2 = (MockIndexedRecord) recordFactory
066: .createIndexedRecord(null);
067: MockIndexedRecord record3 = (MockIndexedRecord) recordFactory
068: .createIndexedRecord("recordName");
069: MockIndexedRecord record4 = (MockIndexedRecord) recordFactory
070: .createIndexedRecord("anotherRecordName");
071: MockIndexedRecord record5 = (MockIndexedRecord) recordFactory
072: .createIndexedRecord("anotherRecordName");
073: assertEquals(5, recordFactory.getCreatedIndexedRecords().size());
074: record1.setRecordName("anotherRecordName");
075: record4.setRecordName("recordName");
076: List list = recordFactory
077: .getCreatedIndexedRecords("recordName");
078: assertEquals(2, list.size());
079: assertSame(record1, list.get(0));
080: assertSame(record3, list.get(1));
081: list = recordFactory
082: .getCreatedIndexedRecords("anotherRecordName");
083: assertEquals(2, list.size());
084: assertSame(record4, list.get(0));
085: assertSame(record5, list.get(1));
086: list = recordFactory.getCreatedIndexedRecords(null);
087: assertEquals(1, list.size());
088: assertSame(record2, list.get(0));
089: recordFactory.resetIndexedRecords();
090: assertEquals(0, recordFactory.getCreatedIndexedRecords().size());
091: assertEquals(0, recordFactory.getCreatedIndexedRecords(
092: "recordName").size());
093: assertEquals(0, recordFactory.getCreatedIndexedRecords(
094: "anotherRecordName").size());
095: }
096:
097: public void testGetCreatedMappedRecords() throws Exception {
098: MockMappedRecord record1 = (MockMappedRecord) recordFactory
099: .createMappedRecord("recordName");
100: MockMappedRecord record2 = (MockMappedRecord) recordFactory
101: .createMappedRecord(null);
102: MockMappedRecord record3 = (MockMappedRecord) recordFactory
103: .createMappedRecord("recordName");
104: MockMappedRecord record4 = (MockMappedRecord) recordFactory
105: .createMappedRecord("anotherRecordName");
106: MockMappedRecord record5 = (MockMappedRecord) recordFactory
107: .createMappedRecord("anotherRecordName");
108: assertEquals(5, recordFactory.getCreatedMappedRecords().size());
109: record1.setRecordName("anotherRecordName");
110: record4.setRecordName("recordName");
111: List list = recordFactory.getCreatedMappedRecords("recordName");
112: assertEquals(2, list.size());
113: assertSame(record1, list.get(0));
114: assertSame(record3, list.get(1));
115: list = recordFactory
116: .getCreatedMappedRecords("anotherRecordName");
117: assertEquals(2, list.size());
118: assertSame(record4, list.get(0));
119: assertSame(record5, list.get(1));
120: list = recordFactory.getCreatedMappedRecords(null);
121: assertEquals(1, list.size());
122: assertSame(record2, list.get(0));
123: recordFactory.resetMappedRecords();
124: assertEquals(0, recordFactory.getCreatedMappedRecords().size());
125: assertEquals(0, recordFactory.getCreatedMappedRecords(
126: "recordName").size());
127: assertEquals(0, recordFactory.getCreatedMappedRecords(
128: "anotherRecordName").size());
129: }
130: }
|