Search in sources :

Example 1 with FetcherBuilder

use of com.google.samples.apps.iosched.server.schedule.input.fetcher.RemoteFilesEntityFetcherFactory.FetcherBuilder in project iosched by google.

the class DataExtractorTest method setUp.

/**
   * @throws java.lang.Exception
   */
@Before
public void setUp() throws Exception {
    fakeFetcher = new EntityFetcher() {

        @Override
        public JsonElement fetch(Enum<?> entityType, Map<String, String> params) throws IOException {
            String filename = "sample_" + entityType.name();
            if (params != null && params.get("page") != null && Integer.parseInt(params.get("page")) > 1) {
                filename += "_page" + params.get("page");
            }
            filename += ".json";
            InputStream stream = TestHelper.openTestDataFileStream(filename);
            JsonReader reader = new JsonReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
            return new JsonParser().parse(reader);
        }
    };
    RemoteFilesEntityFetcherFactory.setBuilder(new FetcherBuilder() {

        @Override
        public FetcherBuilder setSourceFiles(String... filenames) {
            return this;
        }

        @Override
        public EntityFetcher build() {
            return fakeFetcher;
        }
    });
    sources = new ExtraInput().fetchAllDataSources();
    sources.putAll(new VendorDynamicInput(fakeFetcher).fetchAllDataSources());
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) FetcherBuilder(com.google.samples.apps.iosched.server.schedule.input.fetcher.RemoteFilesEntityFetcherFactory.FetcherBuilder) EntityFetcher(com.google.samples.apps.iosched.server.schedule.input.fetcher.EntityFetcher) JsonElement(com.google.gson.JsonElement) ExtraInput(com.google.samples.apps.iosched.server.schedule.server.input.ExtraInput) JsonReader(com.google.gson.stream.JsonReader) VendorDynamicInput(com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput) JsonParser(com.google.gson.JsonParser) Before(org.junit.Before)

Example 2 with FetcherBuilder

use of com.google.samples.apps.iosched.server.schedule.input.fetcher.RemoteFilesEntityFetcherFactory.FetcherBuilder in project iosched by google.

the class ExtraInputTest method setUp.

/**
   * @throws java.lang.Exception
   */
@Before
public void setUp() throws Exception {
    fakeFetcher = new EntityFetcher() {

        @Override
        public JsonElement fetch(Enum<?> entityType, Map<String, String> params) throws IOException {
            String filename = "sample_" + entityType.name() + ".json";
            InputStream stream = TestHelper.openTestDataFileStream(filename);
            assertNotNull("open file " + filename, stream);
            JsonReader reader = new JsonReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
            return new JsonParser().parse(reader);
        }
    };
    RemoteFilesEntityFetcherFactory.setBuilder(new FetcherBuilder() {

        @Override
        public FetcherBuilder setSourceFiles(String... filenames) {
            return this;
        }

        @Override
        public EntityFetcher build() {
            return fakeFetcher;
        }
    });
}
Also used : EntityFetcher(com.google.samples.apps.iosched.server.schedule.input.fetcher.EntityFetcher) InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) InputStream(java.io.InputStream) JsonReader(com.google.gson.stream.JsonReader) IOException(java.io.IOException) FetcherBuilder(com.google.samples.apps.iosched.server.schedule.input.fetcher.RemoteFilesEntityFetcherFactory.FetcherBuilder) JsonParser(com.google.gson.JsonParser) Before(org.junit.Before)

Aggregations

JsonElement (com.google.gson.JsonElement)2 JsonParser (com.google.gson.JsonParser)2 JsonReader (com.google.gson.stream.JsonReader)2 EntityFetcher (com.google.samples.apps.iosched.server.schedule.input.fetcher.EntityFetcher)2 FetcherBuilder (com.google.samples.apps.iosched.server.schedule.input.fetcher.RemoteFilesEntityFetcherFactory.FetcherBuilder)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Before (org.junit.Before)2 ExtraInput (com.google.samples.apps.iosched.server.schedule.server.input.ExtraInput)1 VendorDynamicInput (com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput)1