@@ -0,0 +1,2645 @@
+package org.commcare.util.test;%0A%0Aimport org.commcare.api.persistence.UserDatabaseHelper;%0Aimport org.commcare.cases.model.Case;%0Aimport org.javarosa.core.services.storage.util.DummyIndexedStorageUtility;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.DriverManager;%0Aimport java.sql.ResultSet;%0Aimport java.sql.Statement;%0Aimport java.util.Vector;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.fail;%0A%0Apublic class CaseAPITests %7B%0A%0A    Case a, b, c, d, e;%0A    DummyIndexedStorageUtility%3CCase%3E storage;%0A    String owner;%0A    String groupOwner;%0A    String otherOwner;%0A    Vector%3CString%3E groupOwned;%0A    Vector%3CString%3E userOwned;%0A%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A%0A        storage = new DummyIndexedStorageUtility%3CCase%3E(Case.class);%0A%0A        owner = %22owner%22;%0A        otherOwner = %22otherowner%22;%0A        groupOwner = %22groupowned%22;%0A%0A        userOwned = new Vector%3CString%3E();%0A        userOwned.addElement(owner);%0A%0A        groupOwned = new Vector%3CString%3E();%0A        groupOwned.addElement(owner);%0A        groupOwned.addElement(groupOwner);%0A%0A        a = new Case(%22123%22, %22a%22);%0A        a.setCaseId(%22a%22);%0A        a.setUserId(owner);%0A        a.setID(12345);%0A        b = new Case(%22b%22, %22b%22);%0A        b.setCaseId(%22b%22);%0A        b.setUserId(owner);%0A        c = new Case(%22c%22, %22c%22);%0A        c.setCaseId(%22c%22);%0A        c.setUserId(owner);%0A        d = new Case(%22d%22, %22d%22);%0A        d.setCaseId(%22d%22);%0A        d.setUserId(owner);%0A        e = new Case(%22e%22, %22e%22);%0A        e.setCaseId(%22e%22);%0A        e.setUserId(groupOwner);%0A    %7D%0A%0A    @Test%0A    public void testOwnerPurge() %7B%0A        try %7B%0A%0A            Connection c = null;%0A            Statement stmt = null;%0A%0A            try %7B%0A                Class.forName(%22org.sqlite.JDBC%22);%0A                c = DriverManager.getConnection(%22jdbc:sqlite:test.db%22);%0A%0A                UserDatabaseHelper.dropTable(c, %22TFCase%22);%0A%0A                UserDatabaseHelper.createTable(c, %22TFCase%22, new Case());%0A%0A                UserDatabaseHelper.insertToTable(c, %22TFCase%22, a);%0A%0A                ResultSet rs = UserDatabaseHelper.selectFromTable(c, %22TFCase%22, new String%5B%5D%7B%22case_id%22%7D, new String%5B%5D%7B%22a%22%7D, new Case());%0A                String caseType = rs.getString(%22case_type%22);%0A                assertEquals(%22a%22, caseType);%0A                c.close();%0A%0A            %7D catch ( Exception e ) %7B%0A                System.err.println(e.getClass().getName() + %22: %22 + e.getMessage());%0A                System.exit(0);%0A            %7D%0A%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A            fail(%22Unexpected exception %22 + e.getMessage());%0A        %7D%0A    %7D%0A%7D

add tests