use of org.apache.jena.shared.AddDeniedException in project jena by apache.
the class SecuredModelTest method testGetAlt_Existing.
@Test
public void testGetAlt_Existing() throws Exception {
Resource r = baseModel.createAlt("http://example.com/securedModel/alt");
Triple t = new Triple(r.asNode(), RDF.type.asNode(), RDF.Bag.asNode());
try {
Alt alt = securedModel.getAlt(r);
assertEquals(securedModel, alt.getModel());
if (securedModel.canRead()) {
assertEquals("http://example.com/securedModel/alt", alt.getURI());
} else if (!securedModel.canUpdate() || !securedModel.canCreate(t)) {
fail("Should have thrown AddDeniedException ");
}
} catch (AddDeniedException e) {
if (securedModel.canUpdate() && securedModel.canCreate(t)) {
fail(String.format("Should not have thrown AddDeniedException ", e));
}
}
try {
Alt alt = securedModel.getAlt("http://example.com/securedModel/alt");
assertEquals(securedModel, alt.getModel());
if (securedModel.canRead()) {
assertEquals("http://example.com/securedModel/alt", alt.getURI());
} else if (!securedModel.canUpdate() || !securedModel.canCreate(t)) {
fail("Should have thrown AddDeniedException ");
}
} catch (AddDeniedException e) {
if (securedModel.canUpdate() && securedModel.canCreate(t)) {
fail(String.format("Should not have thrown AddDeniedException ", e));
}
}
}
use of org.apache.jena.shared.AddDeniedException in project jena by apache.
the class SecuredModelTest method testGetAlt_ResourceNotExisting.
@Test
public void testGetAlt_ResourceNotExisting() throws Exception {
Resource r = ResourceFactory.createResource("http://example.com/securedModel/alt");
Triple t = new Triple(r.asNode(), RDF.type.asNode(), RDF.Alt.asNode());
try {
Alt alt = securedModel.getAlt(r);
assertEquals(securedModel, alt.getModel());
if (securedModel.canRead()) {
assertEquals("http://example.com/securedModel/alt", alt.getURI());
} else if (!securedModel.canUpdate() || !securedModel.canCreate(t)) {
fail("Should have thrown AddDeniedException ");
}
} catch (AddDeniedException e) {
if (securedModel.canUpdate() && securedModel.canCreate(t)) {
fail(String.format("Should not have thrown AddDeniedException ", e));
}
}
}
use of org.apache.jena.shared.AddDeniedException in project jena by apache.
the class SecuredModelTest method testGetBag_ResourceNotExisting.
@Test
public void testGetBag_ResourceNotExisting() throws Exception {
Resource r = ResourceFactory.createResource("http://example.com/securedModel/bag");
Triple t = new Triple(r.asNode(), RDF.type.asNode(), RDF.Bag.asNode());
try {
Bag bag = securedModel.getBag(r);
assertEquals(securedModel, bag.getModel());
if (securedModel.canRead()) {
assertEquals("http://example.com/securedModel/bag", bag.getURI());
} else if (!securedModel.canUpdate() || !securedModel.canCreate(t)) {
fail("Should have thrown AddDeniedException ");
}
} catch (AddDeniedException e) {
if (securedModel.canUpdate() && securedModel.canCreate(t)) {
fail(String.format("Should not have thrown AddDeniedException ", e));
}
}
}
use of org.apache.jena.shared.AddDeniedException in project jena by apache.
the class SecuredModelTest method testGetAnyReifiedStmt_none.
@Test
public void testGetAnyReifiedStmt_none() {
// first with create.
try {
Resource r = securedModel.getAnyReifiedStatement(baseModel.listStatements().next());
Assert.assertNotNull(r);
if (!securityEvaluator.evaluate(Action.Update)) {
Assert.fail("Should have thrown UpdateDeniedException Exception");
}
if (!securityEvaluator.evaluate(Action.Create)) {
Assert.fail("Should have thrown AddDeniedException Exception");
}
} catch (final UpdateDeniedException e) {
if (securityEvaluator.evaluate(Action.Update)) {
Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e, e.getTriple()));
}
} catch (final AddDeniedException e) {
if (securityEvaluator.evaluate(Action.Create)) {
Assert.fail(String.format("Should not have thrown AddDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
}
use of org.apache.jena.shared.AddDeniedException in project jena by apache.
the class SecuredModelTest method testGetAlt_StringNotExisting.
@Test
public void testGetAlt_StringNotExisting() throws Exception {
Resource r = ResourceFactory.createResource("http://example.com/securedModel/alt");
Triple t = new Triple(r.asNode(), RDF.type.asNode(), RDF.Alt.asNode());
try {
Alt alt = securedModel.getAlt("http://example.com/securedModel/alt");
assertEquals(securedModel, alt.getModel());
if (securedModel.canRead()) {
assertEquals("http://example.com/securedModel/alt", alt.getURI());
} else if (!securedModel.canUpdate() || !securedModel.canCreate(t)) {
fail("Should have thrown AddDeniedException ");
}
} catch (AddDeniedException e) {
if (securedModel.canUpdate() && securedModel.canCreate(t)) {
fail(String.format("Should not have thrown AddDeniedException ", e));
}
}
}
Aggregations