@Test
public void testWriteToJson() {
final File file = new File(NamespacesJsonContext.class.getResource(nsDoc).getPath());
final String filename = file.getParent() + "/" + randomFilename();
try {
System.setProperty(NamespacesJsonContext.CONFIG_NAMESPACES_PATH, filename);
final NamespacesJsonContext svc1 = new NamespacesJsonContext();
assertEquals(15, svc1.getNamespaces().size(), "Incorrect namespace mapping count!");
assertFalse(svc1.getNamespaces().containsKey("jsonld"), "jsonld prefix unexpectedly found!");
assertTrue(svc1.setPrefix("jsonld", JSONLD.getNamespace()), "unable to set jsonld mapping!");
assertEquals(16, svc1.getNamespaces().size(), "Namespace count was not incremented!");
assertTrue(svc1.getNamespaces().containsKey("jsonld"), "jsonld prefix not found in mapping!");
final NamespacesJsonContext svc2 = new NamespacesJsonContext();
assertEquals(16, svc2.getNamespaces().size(), "Incorrect namespace count when reloading from file!");
assertFalse(svc2.setPrefix("jsonld", JSONLD.getNamespace()),
"unexpected response when trying to re-set jsonld mapping!");
} finally {
System.getProperties().remove(NamespacesJsonContext.CONFIG_NAMESPACES_PATH);
}
}