001 package nl.cwi.sen1.visbase.rstorecontainer.datatypes; 002 003 import java.util.List; 004 005 import junit.framework.TestCase; 006 import nl.cwi.sen1.visbase.rstorecontainer.RStoreContainer; 007 008 import org.apache.commons.logging.Log; 009 import org.apache.commons.logging.LogFactory; 010 011 import aterm.ATermList; 012 013 /** 014 * Tests the FactInfoList code 015 * 016 * @author Ricardo Lindooren 017 * @date 2007-02-14 018 * 019 */ 020 public class FactInfoListTest extends TestCase 021 { 022 private static final Log log = LogFactory.getLog(FactInfoListTest.class); 023 024 private FactInfoList rStoreFactInfoListUnderTest; 025 026 private FactInfo rStoreFactInfoUsedForTests1; 027 028 private FactInfo rStoreFactInfoUsedForTests2; 029 030 @Override 031 protected void setUp() throws Exception 032 { 033 super.setUp(); 034 035 rStoreFactInfoListUnderTest = new FactInfoList(); 036 037 rStoreFactInfoUsedForTests1 = new FactInfo(1, FactInfoTest.getTestRTuple("FooType1")); 038 rStoreFactInfoUsedForTests2 = new FactInfo(2, FactInfoTest.getTestRTuple("FooType2")); 039 } 040 041 @Override 042 protected void tearDown() throws Exception 043 { 044 super.tearDown(); 045 046 rStoreFactInfoListUnderTest = null; 047 048 rStoreFactInfoUsedForTests1 = null; 049 } 050 051 /** 052 * Test the constructor code 053 * 054 */ 055 public void testRStoreFactIdentificationsList() 056 { 057 FactInfoList rfdl = new FactInfoList(); 058 059 assertNotNull("new RStoreFactDataList Instance should not be null", rfdl); 060 061 rfdl = null; 062 } 063 064 /** 065 * Tests the Constructor used to parse ATermList data 066 * 067 * @throws Exception 068 * 069 * @author Ricardo Lindooren 070 * @date 2007-02-14 071 */ 072 public void testConstructFromAtermList() throws Exception 073 { 074 // First dome destructive tests 075 RuntimeException rex = null; 076 try 077 { 078 new FactInfoList(null); 079 } 080 catch (RuntimeException ex) 081 { 082 rex = ex; 083 } 084 assertNotNull("Creating a new instance of FactInfoList with a null-ATermList should throw a RuntimeException", rex); 085 086 // The illegalList contains only an int 087 ATermList illegalList = RStoreContainer.getPureFactory().makeList(); 088 illegalList = illegalList.insert(RStoreContainer.getPureFactory().makeInt(6)); 089 090 ATermParseException ate = null; 091 try 092 { 093 new FactInfoList(illegalList); 094 } 095 catch (ATermParseException ex) 096 { 097 ate = ex; 098 } 099 assertNotNull("Creating a new instance of FactInfoList with a not correctly constructed ATermList should throw a ATermParseException", ate); 100 101 // Then the normal use tests 102 103 // Add two RStoreFactData objects to list 104 rStoreFactInfoListUnderTest.addFactInfoToList(rStoreFactInfoUsedForTests1); 105 rStoreFactInfoListUnderTest.addFactInfoToList(rStoreFactInfoUsedForTests2); 106 107 ATermList list = rStoreFactInfoListUnderTest.toATermList(); 108 109 assertNotNull("ATermList should not be null", list); 110 111 FactInfoList rsfdl = new FactInfoList(list); 112 113 assertNotNull("Constructed RStoreFactDataList from ATermList should not be null", rsfdl); 114 115 int sizeOfListAfterConstruction = rsfdl.getFactInfos().size(); 116 117 assertEquals("Size of list after construction not correct", sizeOfListAfterConstruction, 2); 118 119 list = null; 120 rsfdl = null; 121 } 122 123 /** 124 * Tests adding a FactInfo object to the list 125 * 126 * @author Ricardo Lindooren 127 * @date 2007-02-14 128 */ 129 public void testAddFactInfoToList() 130 { 131 // First a destructive test 132 RuntimeException rex = null; 133 try 134 { 135 rStoreFactInfoListUnderTest.addFactInfoToList(null); 136 } 137 catch (RuntimeException ex) 138 { 139 rex = ex; 140 } 141 assertNotNull("Adding a null-FactInfo should throw a RuntimeException", rex); 142 143 // Then the normal use tests 144 145 // Add first time 146 rStoreFactInfoListUnderTest.addFactInfoToList(rStoreFactInfoUsedForTests1); 147 148 List<FactInfo> internalList = rStoreFactInfoListUnderTest.getFactInfos(); 149 150 assertNotNull("List<RStoreFactData> should not be null", internalList); 151 152 assertEquals("Size of List should be 1 after one RStoreFactData has been added", 1, internalList.size()); 153 154 // Add second time 155 rStoreFactInfoListUnderTest.addFactInfoToList(rStoreFactInfoUsedForTests1); 156 157 assertEquals("Size of List should be 2 after second RStoreFactData has been added", 2, internalList.size()); 158 } 159 160 /** 161 * Simple getter test (only checks for not null) 162 * 163 * @author Ricardo Lindooren 164 * @date 2007-02-14 165 */ 166 public void testGetRStoreFactIdentificationsList() 167 { 168 List<FactInfo> internalList = rStoreFactInfoListUnderTest.getFactInfos(); 169 170 assertNotNull("List<RStoreFactData> should not be null", internalList); 171 } 172 173 /** 174 * 175 * @author Ricardo Lindooren 176 * @date 2007-02-14 177 */ 178 public void testToATermList() 179 { 180 // Add two RStoreFactData objects to list 181 rStoreFactInfoListUnderTest.addFactInfoToList(rStoreFactInfoUsedForTests1); 182 rStoreFactInfoListUnderTest.addFactInfoToList(rStoreFactInfoUsedForTests2); 183 184 ATermList list = rStoreFactInfoListUnderTest.toATermList(); 185 186 if (log.isDebugEnabled()) 187 log.debug("AtermList created from RStoreFactDataList during test: \n\n\t" 188 + list.toString() + "\n"); 189 } 190 }