import nl.uvt.commons.lang.InvalidSettingException; import java.io.*; import java.net.*; import java.util.UUID; import org.junit.*; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import static org.junit.Assert.*; import nl.uvt.commons.oai.*; public class FilesAdminDAOTest { private String dir; @Before public void initialize() throws URISyntaxException { File f = new File(this.getClass().getClassLoader().getResource("uvt-swup.repository").toURI()); this.dir = f.getParentFile().getAbsolutePath(); } @Test public void canLoadRepositoryFromFile() throws URISyntaxException, InvalidSettingException { FilesAdminDAO dao = new FilesAdminDAO(); dao.setProperty("configurationDirectory", this.dir); dao.loadDriver(); UUID handle = dao.getConnectionHandle(); Repository repository = dao.getRepository(handle, "uvt-swup"); assertNotNull("Repository loaded", repository); URL baseURL = repository.getBaseURL(); assertNotNull("BaseURL not null", baseURL); assertEquals("BaseURL", "http://arno.uvt.nl/oai/swup.uvt.nl.cgi", baseURL.toExternalForm()); dao.closeConnection(handle); } @Test public void canLoadFeedFromFile() throws URISyntaxException, InvalidSettingException { FilesAdminDAO dao = new FilesAdminDAO(); dao.setProperty("configurationDirectory", this.dir); dao.setProperty("statusDirectory", this.dir); dao.loadDriver(); UUID handle = dao.getConnectionHandle(); Feed feed = dao.getFeed(handle, "uvt-swup"); assertNotNull("Feed loaded", feed); URL baseURL = feed.getRepository().getBaseURL(); assertNotNull("BaseURL not null", baseURL); assertEquals("BaseURL", "http://arno.uvt.nl/oai/swup.uvt.nl.cgi", baseURL.toExternalForm()); assertEquals("MetadataPrefix", "swup", feed.getMetadataPrefix()); assertNull("Set", feed.getSet()); DateTime from = new DateTime(feed.getFrom()); DateTime compareWith = new DateTime(2009, 10, 29, 0, 0, 0, 0, DateTimeZone.UTC); assertEquals("From = 2009-10-29", compareWith.getMillis(), from.getMillis()); dao.closeConnection(handle); } }