Work toward improving solidity. Add a few more unit tests, and some toString()
[cfb.git] / test / net / jaekl / cfb / store / DbStoreTest.java
diff --git a/test/net/jaekl/cfb/store/DbStoreTest.java b/test/net/jaekl/cfb/store/DbStoreTest.java
new file mode 100644 (file)
index 0000000..c4e2668
--- /dev/null
@@ -0,0 +1,163 @@
+package net.jaekl.cfb.store;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.sql.SQLException;
+import java.util.Date;
+
+import net.jaekl.cfb.analyze.Analysis;
+import net.jaekl.cfb.analyze.MessageMap;
+import net.jaekl.cfb.db.CfbSchema;
+import net.jaekl.cfb.db.TypeMismatchException;
+import net.jaekl.cfb.db.driver.ConnectionMock;
+import net.jaekl.cfb.db.driver.DbDriverMock;
+import net.jaekl.cfb.xml.MessagesXmlData;
+import net.jaekl.cfb.xml.messages.MessageCollection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class DbStoreTest {
+       private DbStore m_store;
+       
+       @Before
+       public void setUp() throws SQLException, FileNotFoundException, UnsupportedEncodingException, IOException, SAXException 
+       {
+               MessageMap msgMap = new MessageMap();
+               msgMap.parse(new InputSource(new ByteArrayInputStream(MessagesXmlData.XML.getBytes("UTF-8"))));
+               
+               DbDriverMock driver = new DbDriverMock();
+               CfbSchema schema = new CfbSchema(driver);
+               ConnectionMock con = new ConnectionMock();
+
+               schema.setMessageMap(msgMap);
+               schema.ensureDbInitialized(con);                
+
+               MessageCollection msgColl = new MessageCollection();
+               m_store = new DbStore(con, driver, msgColl);
+       }
+
+       @Test
+       public void testGetPrior_withNoEntries() throws SQLException, TypeMismatchException {
+               // First test:  getPrior(null) should return null
+               Analysis actual = m_store.getPrior(null);
+               assertNull(actual);
+               
+               // Second test:  getPrior(current) with no data in the DB should return null
+               String projName = "ProjectName";
+               String version = "1.2.3";
+               Date start = new Date(1234567890);
+               Date end = new Date(1234567900);
+               Analysis current = new Analysis(projName, version);
+               current.setStart(start);
+               current.setEnd(end);
+               actual = m_store.getPrior(current);
+               assertNull(actual);
+       }
+
+       @Test
+       public void testPut_thenGetPrior() throws SQLException, TypeMismatchException {
+               String projName = "ProjectName";
+               String firstVersion = "1.0.1";
+               Date firstStart = new Date(100);
+               Date firstEnd = new Date(200);
+               Analysis firstAnalysis = new Analysis(projName, firstVersion);
+               firstAnalysis.setStart(firstStart);
+               firstAnalysis.setEnd(firstEnd);
+               
+               boolean result = m_store.put(firstAnalysis);
+               assertTrue(result);
+               
+               String secondVersion = "1.0.2";
+               Date secondStart = new Date(2300);
+               Date secondEnd = new Date(2400);
+               Analysis secondAnalysis = new Analysis(projName, secondVersion);
+               secondAnalysis.setStart(secondStart);
+               secondAnalysis.setEnd(secondEnd);
+               
+               Analysis priorAnalysis = m_store.getPrior(secondAnalysis);
+               assertNotNull(priorAnalysis);
+               assertEquals(firstAnalysis.getProjectName(), priorAnalysis.getProjectName());
+               assertEquals(firstAnalysis.getBuildNumber(), priorAnalysis.getBuildNumber());
+               assertEquals(firstAnalysis.getStart(), priorAnalysis.getStart());
+               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");
+       }
+
+       @Test
+       public void testGetVar() {
+               fail("Not yet implemented");
+       }
+
+       @Test
+       public void testGetVarIdLocalVariable() {
+               fail("Not yet implemented");
+       }
+
+       @Test
+       public void testFindVarId() {
+               fail("Not yet implemented");
+       }
+
+       @Test
+       public void testStoreVar() {
+               fail("Not yet implemented");
+       }
+
+       @Test
+       public void testGetPriorId() {
+               fail("Not yet implemented");
+       }
+
+       @Test
+       public void testGetAnalysis() {
+               fail("Not yet implemented");
+       }
+
+       @Test
+       public void testGetBugCollection() {
+               fail("Not yet implemented");
+       }
+*/
+}