@Test public void createCachingXmlDataStore_successful() throws IOException, InterruptedException { // create temp file final File cache = folder.newFile("uas_temp.xml"); assertThat(readFile(cache)).isEqualTo(""); // create caching data store final CachingXmlDataStore store = CachingXmlDataStore.createCachingXmlDataStore( cache, DATA_URL, VERSION_URL, CHARSET, fallback); final UpdatingUserAgentStringParserImpl parser = new UpdatingUserAgentStringParserImpl(store); Thread.sleep(1000l); assertThat(readFile(cache).length() >= 721915).isTrue(); final long firstLastUpdateCheck = store.getUpdateOperation().getLastUpdateCheck(); LOG.debug("LastUpdateCheck at: " + firstLastUpdateCheck); final long originalInterval = parser.getUpdateInterval(); // reduce the interval since testing LOG.debug("Reducing the update interval during the test."); parser.setUpdateInterval(1000l); // we have to read to activate the update mechanism parser.parse("check for updates"); Thread.sleep(3000l); final long currentLastUpdateCheck = store.getUpdateOperation().getLastUpdateCheck(); LOG.debug("LastUpdateCheck at: " + currentLastUpdateCheck); assertThat(firstLastUpdateCheck < currentLastUpdateCheck).isTrue(); parser.setUpdateInterval(originalInterval); }
@Test public void createCachingXmlDataStore_defaultCacheFile_successful() throws IOException, InterruptedException { // create caching data store final CachingXmlDataStore store = CachingXmlDataStore.createCachingXmlDataStore(DATA_URL, VERSION_URL, CHARSET); final UpdatingUserAgentStringParserImpl parser = new UpdatingUserAgentStringParserImpl(store); parser.parse("test"); }