package votorola.a.diff.harvest.cache; // Copyright 2012. Christian Weilbach. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import votorola.a.VoteServer; import votorola.a.diff.DiffKey; import votorola.a.diff.DiffKey1; import votorola.a.diff.DraftPair; import votorola.a.diff.harvest.Message; import votorola.a.diff.harvest.cache.AuthDiffMessage; import votorola.a.diff.harvest.cache.DiffMessage; import votorola.a.diff.harvest.cache.DiffMessageTable; import java.io.IOException; import java.net.URISyntaxException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import java.util.Date; import java.util.List; import javax.mail.internet.AddressException; import javax.script.ScriptException; import javax.xml.stream.XMLStreamException; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; /** * Unit test for DiffMessageTable. */ public class DiffMessageTableTest { private volatile DiffMessageTable dmTable; // dummy data and object creation final private String baseUrl = "http://some.base.url/path/"; final private String path = "http://some.base.url/path/post.html"; final private List diffUrls = new LinkedList(); final private Date sentDate = new Date(); final private Message msg = Message.create("Summary", "Sender", baseUrl, path, diffUrls, sentDate); private final String pollname = "G/p/vohall"; private final String sender = "4consensus@" + "web.de"; private final String addressee = "mike@" + "zelea.com"; final private DiffKey key = new DiffKey1(5941, -1, 5273, -1); private volatile DraftPair dPair; @Before public void setup() throws IOException, ScriptException, SQLException, URISyntaxException, XMLStreamException { final VoteServer.Run vsr = new VoteServer( System.getProperty("user.name")).new Run(false); assert (vsr.database() != null); dmTable = new DiffMessageTable(vsr.database()); // error dPair = DraftPair.newDraftPair( key.a(), key.aR(), key.b(), key.bR(), vsr.voteServer()); if(dmTable.exists()) { dmTable.drop(); } dmTable.create(); } @Test public void testPutAndGet() throws SQLException, AddressException { final DiffMessage dmsg = new DiffMessage( msg, dPair ); final AuthDiffMessage admsg = AuthDiffMessage.create(dmsg, sender, addressee, "a"); dmTable.put(admsg); synchronized(dmTable.getDatabase()) { ResultSet rs = dmTable.get(null, null, 0); assertEquals(rs.getString(2), sender); assertEquals(rs.getString(3), addressee); assertEquals(rs.getString(4), pollname); assertEquals(rs.getString(5), "Summary"); assertEquals(new DiffKey1(rs.getInt(6),rs.getInt(7),rs.getInt(8),rs.getInt(9)), key); assertEquals(rs.getString(10), baseUrl); assertEquals(rs.getString(11), path); assertEquals(rs.getTimestamp(12).getTime(), sentDate.getTime()); } } }