1 package net.jaekl.cfb.store;
3 import static org.junit.Assert.*;
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;
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;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.xml.sax.InputSource;
24 import org.xml.sax.SAXException;
26 public class DbStoreTest {
27 private DbStore m_store;
30 public void setUp() throws SQLException, FileNotFoundException, UnsupportedEncodingException, IOException, SAXException
32 MessageMap msgMap = new MessageMap();
33 msgMap.parse(new InputSource(new ByteArrayInputStream(MessagesXmlData.XML.getBytes("UTF-8"))));
35 DbDriverMock driver = new DbDriverMock();
36 CfbSchema schema = new CfbSchema(driver);
37 ConnectionMock con = new ConnectionMock();
39 schema.setMessageMap(msgMap);
40 schema.ensureDbInitialized(con);
42 MessageCollection msgColl = new MessageCollection();
43 m_store = new DbStore(con, driver, msgColl);
47 public void testGetPrior_withNoEntries() throws SQLException, TypeMismatchException {
48 // First test: getPrior(null) should return null
49 Analysis actual = m_store.getPrior(null);
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);
60 actual = m_store.getPrior(current);
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);
74 boolean result = m_store.put(firstAnalysis);
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);
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());
94 public void testGetBugType() {
95 fail("Not yet implemented");
99 public void testGetCategoryName() {
100 fail("Not yet implemented");
104 public void testGetLoc() {
105 fail("Not yet implemented");
109 public void testGetLocId() {
110 fail("Not yet implemented");
114 public void testFindLocId() {
115 fail("Not yet implemented");
119 public void testStoreLoc() {
120 fail("Not yet implemented");
124 public void testGetVarIdBugInstance() {
125 fail("Not yet implemented");
129 public void testGetVar() {
130 fail("Not yet implemented");
134 public void testGetVarIdLocalVariable() {
135 fail("Not yet implemented");
139 public void testFindVarId() {
140 fail("Not yet implemented");
144 public void testStoreVar() {
145 fail("Not yet implemented");
149 public void testGetPriorId() {
150 fail("Not yet implemented");
154 public void testGetAnalysis() {
155 fail("Not yet implemented");
159 public void testGetBugCollection() {
160 fail("Not yet implemented");