Work toward improving solidity. Add a few more unit tests, and some toString()
[cfb.git] / test / net / jaekl / cfb / store / DbStoreTest.java
1 package net.jaekl.cfb.store;
2
3 import static org.junit.Assert.*;
4
5 import java.io.ByteArrayInputStream;
6 import java.io.FileNotFoundException;
7 import java.io.IOException;
8 import java.io.UnsupportedEncodingException;
9 import java.sql.SQLException;
10 import java.util.Date;
11
12 import net.jaekl.cfb.analyze.Analysis;
13 import net.jaekl.cfb.analyze.MessageMap;
14 import net.jaekl.cfb.db.CfbSchema;
15 import net.jaekl.cfb.db.TypeMismatchException;
16 import net.jaekl.cfb.db.driver.ConnectionMock;
17 import net.jaekl.cfb.db.driver.DbDriverMock;
18 import net.jaekl.cfb.xml.MessagesXmlData;
19 import net.jaekl.cfb.xml.messages.MessageCollection;
20
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.xml.sax.InputSource;
24 import org.xml.sax.SAXException;
25
26 public class DbStoreTest {
27         private DbStore m_store;
28         
29         @Before
30         public void setUp() throws SQLException, FileNotFoundException, UnsupportedEncodingException, IOException, SAXException 
31         {
32                 MessageMap msgMap = new MessageMap();
33                 msgMap.parse(new InputSource(new ByteArrayInputStream(MessagesXmlData.XML.getBytes("UTF-8"))));
34                 
35                 DbDriverMock driver = new DbDriverMock();
36                 CfbSchema schema = new CfbSchema(driver);
37                 ConnectionMock con = new ConnectionMock();
38
39                 schema.setMessageMap(msgMap);
40                 schema.ensureDbInitialized(con);                
41
42                 MessageCollection msgColl = new MessageCollection();
43                 m_store = new DbStore(con, driver, msgColl);
44         }
45
46         @Test
47         public void testGetPrior_withNoEntries() throws SQLException, TypeMismatchException {
48                 // First test:  getPrior(null) should return null
49                 Analysis actual = m_store.getPrior(null);
50                 assertNull(actual);
51                 
52                 // Second test:  getPrior(current) with no data in the DB should return null
53                 String projName = "ProjectName";
54                 String version = "1.2.3";
55                 Date start = new Date(1234567890);
56                 Date end = new Date(1234567900);
57                 Analysis current = new Analysis(projName, version);
58                 current.setStart(start);
59                 current.setEnd(end);
60                 actual = m_store.getPrior(current);
61                 assertNull(actual);
62         }
63
64         @Test
65         public void testPut_thenGetPrior() throws SQLException, TypeMismatchException {
66                 String projName = "ProjectName";
67                 String firstVersion = "1.0.1";
68                 Date firstStart = new Date(100);
69                 Date firstEnd = new Date(200);
70                 Analysis firstAnalysis = new Analysis(projName, firstVersion);
71                 firstAnalysis.setStart(firstStart);
72                 firstAnalysis.setEnd(firstEnd);
73                 
74                 boolean result = m_store.put(firstAnalysis);
75                 assertTrue(result);
76                 
77                 String secondVersion = "1.0.2";
78                 Date secondStart = new Date(2300);
79                 Date secondEnd = new Date(2400);
80                 Analysis secondAnalysis = new Analysis(projName, secondVersion);
81                 secondAnalysis.setStart(secondStart);
82                 secondAnalysis.setEnd(secondEnd);
83                 
84                 Analysis priorAnalysis = m_store.getPrior(secondAnalysis);
85                 assertNotNull(priorAnalysis);
86                 assertEquals(firstAnalysis.getProjectName(), priorAnalysis.getProjectName());
87                 assertEquals(firstAnalysis.getBuildNumber(), priorAnalysis.getBuildNumber());
88                 assertEquals(firstAnalysis.getStart(), priorAnalysis.getStart());
89                 assertEquals(firstAnalysis.getEnd(), priorAnalysis.getEnd());
90                 assertEquals(firstAnalysis.getBugCollection(), priorAnalysis.getBugCollection());
91         }
92 /*
93         @Test
94         public void testGetBugType() {
95                 fail("Not yet implemented");
96         }
97
98         @Test
99         public void testGetCategoryName() {
100                 fail("Not yet implemented");
101         }
102
103         @Test
104         public void testGetLoc() {
105                 fail("Not yet implemented");
106         }
107
108         @Test
109         public void testGetLocId() {
110                 fail("Not yet implemented");
111         }
112
113         @Test
114         public void testFindLocId() {
115                 fail("Not yet implemented");
116         }
117
118         @Test
119         public void testStoreLoc() {
120                 fail("Not yet implemented");
121         }
122
123         @Test
124         public void testGetVarIdBugInstance() {
125                 fail("Not yet implemented");
126         }
127
128         @Test
129         public void testGetVar() {
130                 fail("Not yet implemented");
131         }
132
133         @Test
134         public void testGetVarIdLocalVariable() {
135                 fail("Not yet implemented");
136         }
137
138         @Test
139         public void testFindVarId() {
140                 fail("Not yet implemented");
141         }
142
143         @Test
144         public void testStoreVar() {
145                 fail("Not yet implemented");
146         }
147
148         @Test
149         public void testGetPriorId() {
150                 fail("Not yet implemented");
151         }
152
153         @Test
154         public void testGetAnalysis() {
155                 fail("Not yet implemented");
156         }
157
158         @Test
159         public void testGetBugCollection() {
160                 fail("Not yet implemented");
161         }
162 */
163 }