示例#1
0
 @Before
 public void setUp() throws Exception {
   initMocks(this);
   when(mockResource.getPath()).thenReturn(testPath);
   when(mockResource.getNode()).thenReturn(mockNode);
   when(mockNode.getSession()).thenReturn(mockSession);
 }
  @Before
  public void setUp() throws RepositoryException {
    // Mock RDF Source
    when(mockResource.getNode()).thenReturn(mockResourceNode);
    when(mockResourceNode.getSession()).thenReturn(mockSession);
    when(mockResource.getPath()).thenReturn(RDF_PATH);

    idTranslator = new DefaultIdentifierTranslator(mockSession);
  }
 @Test
 public void verifyThatPropertiesAreExternal() throws RepositoryException {
   final Session session = repo.login();
   try {
     final FedoraResource object = nodeService.find(session, testFilePath());
     assertEquals(
         "There should be exactly as many visible nodes as actual files (ie, no hidden sidecar files).",
         fileForNode().getParentFile().list().length,
         getChildCount(object.getNode().getParent()));
   } finally {
     session.logout();
   }
 }
  @Before
  public void setUp() throws RepositoryException {

    roleProvider = new WebACRolesProvider();
    setField(roleProvider, "nodeService", mockNodeService);
    setField(roleProvider, "sessionFactory", mockSessionFactory);

    when(mockNodeService.cast(mockNode)).thenReturn(mockResource);
    when(mockNode.getSession()).thenReturn(mockSession);
    when(mockSessionFactory.getInternalSession()).thenReturn(mockSession);

    when(mockResource.getNode()).thenReturn(mockNode);
    when(mockNode.getDepth()).thenReturn(0);
  }
  @Test
  public void noAclTest() throws RepositoryException {
    final String accessTo = "/dark/archive/sunshine";

    when(mockResource.getPath()).thenReturn(accessTo);
    when(mockResource.getContainer()).thenReturn(mockParentResource);
    when(mockResource.getTriples(anyObject(), eq(PropertiesRdfContext.class)))
        .thenReturn(new RdfStream());
    when(mockNode.getDepth()).thenReturn(1);

    when(mockParentResource.getNode()).thenReturn(mockParentNode);
    when(mockParentResource.getTriples(anyObject(), eq(PropertiesRdfContext.class)))
        .thenReturn(new RdfStream());
    when(mockParentNode.getDepth()).thenReturn(0);

    final Map<String, List<String>> roles = roleProvider.getRoles(mockNode, true);

    assertTrue("There should be no agents in the roles map", roles.isEmpty());
  }
  @Test
  public void acl01ParentTest() throws RepositoryException {
    final String agent = "smith123";
    final String accessTo = "/webacl_box1";
    final String acl = "/acls/01";
    final String auth = acl + "/authorization.ttl";

    when(mockResource.getPath()).thenReturn(accessTo);
    when(mockResource.getContainer()).thenReturn(mockParentResource);
    when(mockResource.getPath()).thenReturn(accessTo + "/foo");
    when(mockResource.getTriples(anyObject(), eq(PropertiesRdfContext.class)))
        .thenReturn(new RdfStream());
    when(mockNode.getDepth()).thenReturn(1);

    when(mockParentResource.getNode()).thenReturn(mockParentNode);
    when(mockParentResource.getPath()).thenReturn(accessTo);
    when(mockParentResource.getTriples(anyObject(), eq(PropertiesRdfContext.class)))
        .thenReturn(getResourceRdfStream(accessTo, acl));
    when(mockParentNode.getDepth()).thenReturn(0);

    when(mockProperty.getString()).thenReturn(acl);
    when(mockNodeService.find(mockSession, acl)).thenReturn(mockAclResource);
    when(mockAclResource.getPath()).thenReturn(acl);

    when(mockAuthorizationResource1.getTypes()).thenReturn(Arrays.asList(WEBAC_AUTHORIZATION));
    when(mockAuthorizationResource1.getPath()).thenReturn(auth);
    when(mockAuthorizationResource1.getTriples(anyObject(), eq(PropertiesRdfContext.class)))
        .thenReturn(getRdfStreamFromResource(auth, TTL));

    when(mockAclResource.getChildren())
        .thenReturn(Arrays.asList(mockAuthorizationResource1).iterator());

    final Map<String, List<String>> roles = roleProvider.getRoles(mockNode, true);

    assertEquals("There should be exactly one agent in the role map", 1, roles.size());
    assertEquals("The agent should have exactly two modes", 2, roles.get(agent).size());
    assertTrue(
        "The agent should be able to read", roles.get(agent).contains(WEBAC_MODE_READ_VALUE));
    assertTrue(
        "The agent should be able to write", roles.get(agent).contains(WEBAC_MODE_WRITE_VALUE));
  }