* Test storing and then updating a program (by removing two rules)
*/
@Test
public void testUpdateProgram() throws Exception {
KWRLProgramParserBase parser = new KWRLProgramParser(repository.getValueFactory(), this.getClass().getResourceAsStream("test-001.kwrl"));
Program p = parser.parseProgram();
p.setName("test-001");
KiWiReasoningConnection connection = rpersistence.getConnection();
try {
// should not throw an exception and the program should have a database ID afterwards
connection.storeProgram(p);
connection.commit();
Assert.assertNotNull("program did not get a database ID",p.getId());
// load the program by name and check if it is equal to the original program
Program p1 = connection.loadProgram("test-001");
connection.commit();
Assert.assertNotNull("load program by name: loaded program is null",p1);
Assert.assertEquals("load program by name: loaded program differs from original",p,p1);
PreparedStatement listRules1 = connection.getJDBCConnection().prepareStatement("SELECT count(*) AS count FROM reasoner_rules");
ResultSet resultListRules1 = listRules1.executeQuery();
Assert.assertTrue(resultListRules1.next());
Assert.assertEquals(5, resultListRules1.getInt("count"));
resultListRules1.close();
connection.commit();
// now remove two rules from the original and update the existing program
p.getRules().remove(p.getRules().size()-1);
p.getRules().remove(p.getRules().size()-1);
p.addNamespace("myns","http://example.com/myns");
connection.updateProgram(p);
// load the program by name and check if it is equal to the original program
Program p2 = connection.loadProgram(p.getName());
connection.commit();
Assert.assertNotNull("load program by name: loaded program is null",p2);
Assert.assertEquals("load program by name: loaded program differs from original",p,p2);