public Exercise1(){ dl = new DocumentLoader(); loadData(); }
public Builder() { valueMapper = StandardJavaValueMapper.getInstance(); documentLoader = new DocumentLoader(); STANDARD_DOCUMENTS.forEach(documentLoader::addInjectedDoc); for (Bdio.Class bdioClass : Bdio.Class.values()) { if (bdioClass.embedded()) { embeddedTypes.add(bdioClass.toString()); } } }
@Test public void contextLoadedFromJarCache() throws Exception { // RDFToManifest.makeBaseURI(); // trigger static{} block @SuppressWarnings("unchecked") Map<String, Object> context = (Map<String, Object>) new DocumentLoader() .fromURL(new URL(CONTEXT)); // FIXME: jsonld-java 0.3 and later uses DocumentLoader instead of // JSONUtils // Map<String, Object> context = (Map<String, Object>) // JSONUtils.fromURL(new URL(CONTEXT)); Object retrievedFrom = context.get("http://purl.org/pav/retrievedFrom"); assertNotNull("Did not load context from cache: " + CONTEXT, retrievedFrom); } }
@Test public void sharedHttpClient() throws Exception { // Should be the same instance unless explicitly set assertSame(documentLoader.getHttpClient(), new DocumentLoader().getHttpClient()); }
@Test public void differentHttpClient() throws Exception { // Custom http client try { documentLoader.setHttpClient(JsonUtils.createDefaultHttpClient()); assertNotSame(documentLoader.getHttpClient(), new DocumentLoader().getHttpClient()); } finally { // Use default again documentLoader.setHttpClient(null); assertSame(documentLoader.getHttpClient(), new DocumentLoader().getHttpClient()); } }
@Test public void injectContext() throws Exception { final Object jsonObject = JsonUtils.fromString( "{ \"@context\":\"http://nonexisting.example.com/thing\", \"pony\":5 }"); final JsonLdOptions options = new JsonLdOptions(); // Verify fails to find context by default try { JsonLdProcessor.expand(jsonObject, options); fail("Expected exception to occur"); } catch (final JsonLdError e) { // Success } // Inject context final DocumentLoader dl = new DocumentLoader(); dl.addInjectedDoc("http://nonexisting.example.com/thing", "{ \"@context\": { \"pony\":\"http://nonexisting.example.com/thing/pony\" } }"); options.setDocumentLoader(dl); // Execute final List<Object> expand = JsonLdProcessor.expand(jsonObject, options); // Verify result final Object v = ((Map<Object, Object>) ((List<Object>) ((Map<Object, Object>) expand .get(0)).get("http://nonexisting.example.com/thing/pony")).get(0)).get("@value"); assertEquals(5, v); }
} finally { documentLoader.setHttpClient(null); assertSame(documentLoader.getHttpClient(), new DocumentLoader().getHttpClient());