### Question:
BucketNodeFactory { public Node getBucketNode() throws RepositoryException { final String[] pathArray = getPathArray(); Node targetNode = cacheRoot; for(String path : pathArray){ Node childNode = JcrUtils.getOrCreateByPath(targetNode, path,false,OAK_UNSTRUCTURED, OAK_UNSTRUCTURED,false); if(!childNode.hasProperty(PN_ISBUCKETNODE)){ childNode.setProperty(PN_ISBUCKETNODE, true); } targetNode = childNode; } return targetNode; } BucketNodeFactory(Session session, String cacheRootPath, CacheKey key, Integer cacheKeySplitDepth); Node getBucketNode(); static final double HASHCODE_LENGTH; }### Answer:
@Test(expected = BucketNodeFactoryException.class) public void testInvalidPath() throws BucketNodeFactoryException, RepositoryException { final MockSettings settings = new MockSettings(); settings.cacheRootPath = "/some/non/existing/path"; settings.cacheKeyHashCode = 1002021887; settings.bucketNodeDepth = 3; final BucketNodeFactory factory = buildNodeFactoryWithMocks(settings); factory.getBucketNode(); }
@Test public void test3() throws RepositoryException, BucketNodeFactoryException { final MockSettings settings = new MockSettings(); settings.cacheKeyHashCode = 1002021887; settings.bucketNodeDepth = 3; settings.cacheRootPath = MockSettings.VALID_ROOT_PATH; final BucketNodeFactory factory = buildNodeFactoryWithMocks(settings); final Node bucketNode = factory.getBucketNode(); assertEquals("00087", bucketNode.getName()); assertEquals("00218", bucketNode.getParent().getName()); assertEquals("01002", bucketNode.getParent().getParent().getName()); }
@Test public void test4() throws RepositoryException, BucketNodeFactoryException { final MockSettings settings = new MockSettings(); settings.cacheKeyHashCode = 1002021887; settings.bucketNodeDepth = 4; settings.cacheRootPath = MockSettings.VALID_ROOT_PATH; final BucketNodeFactory factory = buildNodeFactoryWithMocks(settings); final Node bucketNode = factory.getBucketNode(); assertEquals("00007", bucketNode.getName()); assertEquals("00188", bucketNode.getParent().getName()); assertEquals("00202", bucketNode.getParent().getParent().getName()); assertEquals("00100", bucketNode.getParent().getParent().getParent().getName()); }
@Test public void test10() throws RepositoryException, BucketNodeFactoryException { final MockSettings settings = new MockSettings(); settings.cacheKeyHashCode = 1002021887; settings.bucketNodeDepth = 10; settings.cacheRootPath = MockSettings.VALID_ROOT_PATH; final BucketNodeFactory factory = buildNodeFactoryWithMocks(settings); final Node bucketNode = factory.getBucketNode(); assertEquals("00007", bucketNode.getName()); assertEquals("00008", bucketNode.getParent().getName()); assertEquals("00008", bucketNode.getParent().getParent().getName()); assertEquals("00001", bucketNode.getParent().getParent().getParent().getName()); assertEquals("00002", bucketNode.getParent().getParent().getParent().getParent().getName()); assertEquals("00000", bucketNode.getParent().getParent().getParent().getParent().getParent().getName()); assertEquals("00002", bucketNode.getParent().getParent().getParent().getParent().getParent().getParent().getName()); assertEquals("00000", bucketNode.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getName()); assertEquals("00000", bucketNode.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getName()); assertEquals("00001", bucketNode.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getName()); }