Пример #1
0
  @Test
  public void testSetNsPrefix() {
    try {
      securedMapping.setNsPrefix("foo", "http://example.com/foo");
      if (!securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {

        Assert.fail("Should have thrown AccessDenied Exception");
      }
    } catch (final AccessDeniedException e) {
      if (securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {
        Assert.fail(
            String.format(
                "Should not have thrown AccessDenied Exception: %s - %s", e, e.getTriple()));
      }
    }

    try {
      securedMapping.setNsPrefixes(GraphFactory.createDefaultGraph().getPrefixMapping());
      if (!securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {
        Assert.fail("Should have thrown AccessDenied Exception");
      }
    } catch (final AccessDeniedException e) {
      if (securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {
        Assert.fail(
            String.format(
                "Should not have thrown AccessDenied Exception: %s - %s", e, e.getTriple()));
      }
    }

    try {
      securedMapping.setNsPrefixes(new HashMap<String, String>());
      if (!securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {
        Assert.fail("Should have thrown AccessDenied Exception");
      }
    } catch (final AccessDeniedException e) {
      if (securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {
        Assert.fail(
            String.format(
                "Should not have thrown AccessDenied Exception: %s - %s", e, e.getTriple()));
      }
    }
  }
Пример #2
0
 @Test
 public void testExpandPrefix() {
   try {
     securedMapping.expandPrefix("foo");
     if (!securityEvaluator.evaluate(Action.Read, securedMapping.getModelNode())) {
       Assert.fail("Should have thrown AccessDenied Exception");
     }
   } catch (final AccessDeniedException e) {
     if (securityEvaluator.evaluate(Action.Read, securedMapping.getModelNode())) {
       Assert.fail(
           String.format(
               "Should not have thrown AccessDenied Exception: %s - %s", e, e.getTriple()));
     }
   }
 }
Пример #3
0
 @Test
 public void testShortForm() {
   try {
     securedMapping.shortForm("http://example.com/foo/bar");
     if (!securityEvaluator.evaluate(Action.Read, securedMapping.getModelNode())) {
       Assert.fail("Should have thrown AccessDenied Exception");
     }
   } catch (final AccessDeniedException e) {
     if (securityEvaluator.evaluate(Action.Read, securedMapping.getModelNode())) {
       Assert.fail(
           String.format(
               "Should not have thrown AccessDenied Exception: %s - %s", e, e.getTriple()));
     }
   }
 }
Пример #4
0
 @Test
 public void testSamePrefixMappingAs() {
   try {
     securedMapping.samePrefixMappingAs(GraphFactory.createDefaultGraph().getPrefixMapping());
     if (!securityEvaluator.evaluate(Action.Read, securedMapping.getModelNode())) {
       Assert.fail("Should have thrown AccessDenied Exception");
     }
   } catch (final AccessDeniedException e) {
     if (securityEvaluator.evaluate(Action.Read, securedMapping.getModelNode())) {
       Assert.fail(
           String.format(
               "Should not have thrown AccessDenied Exception: %s - %s", e, e.getTriple()));
     }
   }
 }
Пример #5
0
 @Test
 public void testWithDefaultMappings() {
   PrefixMapping pm = new PrefixMappingImpl();
   pm.setNsPrefix("example", "http://example.com");
   try {
     // make sure that it must update
     securedMapping.withDefaultMappings(pm);
     if (!securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {
       Assert.fail("Should have thrown AccessDenied Exception");
     }
   } catch (final AccessDeniedException e) {
     if (securityEvaluator.evaluate(Action.Update, securedMapping.getModelNode())) {
       Assert.fail(
           String.format(
               "Should not have thrown AccessDenied Exception: %s - %s", e, e.getTriple()));
     }
   }
 }