Further unit tests: loading a variable.
[cfb.git] / test / net / jaekl / cfb / store / DbStoreTest.java
index f269a9cd126205bfe0a0dc2db63ff9a99fc37536..1e7802929d89c798e944c3286b21f03312967db0 100644 (file)
@@ -23,6 +23,7 @@ import net.jaekl.cfb.db.driver.ConnectionMock;
 import net.jaekl.cfb.db.driver.DbDriverMock;
 import net.jaekl.cfb.util.Command;
 import net.jaekl.cfb.xml.BugCollection;
+import net.jaekl.cfb.xml.LocalVariable;
 import net.jaekl.cfb.xml.MessagesXmlData;
 
 import org.junit.Before;
@@ -137,7 +138,7 @@ public class DbStoreTest {
        }
 
        @Test
-       public void testGetPrior_withNoEntries() throws SQLException, TypeMismatchException {
+       public void testGetPrior_withNoEntries() throws SQLException, TypeMismatchException, StoreException {
                // First test:  getPrior(null) should return null
                Analysis actual = m_store.getPrior(null);
                assertNull(actual);
@@ -236,75 +237,74 @@ public class DbStoreTest {
                assertEquals(firstAnalysis.getEnd(), priorAnalysis.getEnd());
                assertEquals(firstAnalysis.getBugCollection(), priorAnalysis.getBugCollection());
        }
-/*
-       @Test
-       public void testGetBugType() {
-               fail("Not yet implemented");
-       }
-
-       @Test
-       public void testGetCategoryName() {
-               fail("Not yet implemented");
-       }
-
-       @Test
-       public void testGetLoc() {
-               fail("Not yet implemented");
-       }
-
-       @Test
-       public void testGetLocId() {
-               fail("Not yet implemented");
-       }
-
-       @Test
-       public void testFindLocId() {
-               fail("Not yet implemented");
-       }
-
-       @Test
-       public void testStoreLoc() {
-               fail("Not yet implemented");
-       }
 
        @Test
-       public void testGetVarIdBugInstance() {
-               fail("Not yet implemented");
+       public void testGetLocId_nullReturnsNull() throws SQLException, TypeMismatchException {
+               Long locId = m_store.getLocId(null);
+               assertNull(locId);
        }
 
        @Test
-       public void testGetVar() {
-               fail("Not yet implemented");
+       public void testGetLocId_notFoundIsStored() throws SQLException, TypeMismatchException {
+               Location loc = new Location(1234567890L, 
+                                                                       "ThisClassDoesNotExist", 
+                                                                       "thisMethodDoesNotExist", 
+                                                                       "INVALID_METHOD_ROLE", 
+                                                                       0, 90909);
+               Long locId = m_store.getLocId(loc);
+               assertNotNull(locId);
+               assertTrue(locId.longValue() > 0);
+               
+               Long secondLocId = m_store.getLocId(loc);
+               assertEquals(locId, secondLocId);
        }
 
        @Test
-       public void testGetVarIdLocalVariable() {
-               fail("Not yet implemented");
+       public void testGetLoc_nullReturnsNull() throws SQLException, TypeMismatchException, StoreException {
+               Location loc = m_store.getLoc(null);
+               assertNull(loc);
        }
-
+       
        @Test
-       public void testFindVarId() {
-               fail("Not yet implemented");
+       public void testGetLoc_invalidId() throws SQLException, TypeMismatchException {
+               try {
+                       m_store.getLoc(Long.valueOf(-3));
+                       fail("Should have thrown a StoreException");
+               }
+               catch (StoreException exc) {
+                       assertEquals(StoreException.Type.INVALID_LOC_ID, exc.getType());
+               }
        }
-
+       
        @Test
-       public void testStoreVar() {
-               fail("Not yet implemented");
+       public void testGetVar_nullReturnsNull() throws SQLException, TypeMismatchException, StoreException {
+               LocalVariable var = m_store.getVar(null);
+               assertNull(var);
        }
-
+       
        @Test
-       public void testGetPriorId() {
-               fail("Not yet implemented");
+       public void testGetVar_invalidId() throws SQLException, TypeMismatchException {
+               try {
+                       m_store.getVar(Long.valueOf(-3));
+                       fail("Should have thrown a StoreException");
+               }
+               catch (StoreException exc) {
+                       assertEquals(StoreException.Type.INVALID_VAR_ID, exc.getType());
+               }
        }
 
        @Test
-       public void testGetAnalysis() {
-               fail("Not yet implemented");
-       }
+       public void testGetVarId_notFoundIsStored() throws SQLException, TypeMismatchException, StoreException {
+               LocalVariable var = new LocalVariable(2345678901L, "VariableNameDoesNotYetExist", "VARIABLE_READ");
 
-       @Test
-       public void testGetBugCollection() {
-               fail("Not yet implemented");
+               Long varId = m_store.getVarId(var);
+               assertNotNull(varId);
+               assertTrue(varId.longValue() > 0);
+               
+               Long secondVarId = m_store.getVarId(var);
+               assertEquals(varId, secondVarId);
+               
+               LocalVariable loadedVar = m_store.getVar(secondVarId);
+               assertEquals(var, loadedVar);
        }
-*/
 }