CachingXmlDataStore extends AbstractRefreshableDataStore { @Nonnull public static CachingXmlDataStore createCachingXmlDataStore(@Nonnull final URL dataUrl, @Nonnull final URL versionURL, @Nonnull final DataStore fallback) { return createCachingXmlDataStore(findOrCreateCacheFile(), dataUrl, versionURL, DEFAULT_CHARSET, fallback); } private  CachingXmlDataStore(@Nonnull final DataReader reader, @Nonnull final URL dataUrl, @Nonnull final URL versionUrl,
			@Nonnull final Charset charset, @Nonnull final File cacheFile, @Nonnull final DataStore fallback); @Nonnull static CachingXmlDataStore createCachingXmlDataStore(@Nonnull final URL dataUrl, @Nonnull final URL versionURL, @Nonnull final DataStore fallback); @Deprecated static CachingXmlDataStore createCachingXmlDataStore(@Nonnull final DataStore fallback); @Nonnull @Deprecated static CachingXmlDataStore createCachingXmlDataStore(@Nonnull final File cacheFile, @Nonnull final DataStore fallback); @Nonnull static CachingXmlDataStore createCachingXmlDataStore(@Nonnull final File cacheFile, @Nonnull final URL dataUrl,
			@Nonnull final URL versionUrl, @Nonnull final Charset charset, @Nonnull final DataStore fallback); @Nonnull static CachingXmlDataStore createCachingXmlDataStore(@Nonnull final URL dataUrl, @Nonnull final URL versionUrl,
			@Nonnull final Charset charset, @Nonnull final DataStore fallback); @Nonnull static File findOrCreateCacheFile();  }
@Test(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_charset_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(folder.newFile("uas_test.xml"), DATA_URL, VERSION_URL, null, fallback); }
@Test(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_dataUrl_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(folder.newFile("uas_test.xml"), null, VERSION_URL, CHARSET, fallback); }
@Test(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_fallback1_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(folder.newFile("uas_test.xml"), DATA_URL, VERSION_URL, CHARSET, null); }
@Test(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_fallback2_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(DATA_URL, VERSION_URL, CHARSET, null); }
@Test(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_fallback3_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(folder.newFile("uas_test.xml"), null); }
@Test(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_file2_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(null, DATA_URL, VERSION_URL, CHARSET, fallback); }
@Test(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_file3_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(null, fallback); }
@Test public void createCachingXmlDataStore_provokeFallback() throws IOException, InterruptedException { final File cache = folder.newFile("uas_temp.xml"); assertThat(readFile(cache)).isEqualTo(""); final String version = "fallback-data-version"; final DataStore fallback = new DataStore() { @Override public Charset getCharset() { return null; } @Override public Data getData() { return new DataBlueprint().version(version).build(); } @Override public DataReader getDataReader() { return null; } @Override public URL getDataUrl() { return null; } @Override public URL getVersionUrl() { return null; } }; final DataStore store = CachingXmlDataStore.createCachingXmlDataStore(cache, UNREACHABLE_URL, UNREACHABLE_URL, CHARSET, fallback); assertThat(store.getData().getVersion()).isEqualTo(version); }
@Test public void createCachingXmlDataStore_successful() throws IOException, InterruptedException { final File cache = folder.newFile("uas_temp.xml"); assertThat(readFile(cache)).isEqualTo(""); 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(); LOG.debug("Reducing the update interval during the test."); parser.setUpdateInterval(1000l); 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(expected = IllegalNullArgumentException.class) public void createCachingXmlDataStore_versionUrl_null() throws IOException { CachingXmlDataStore.createCachingXmlDataStore(folder.newFile("uas_test.xml"), DATA_URL, null, CHARSET, fallback); }