/** * Get or create a node at the specified path. * * @param session the JCR session. may not be null * @param path the path of the desired node to be found or created. may not be null * @return the existing or newly created node * @throws RepositoryException * @throws IllegalArgumentException if either the session or path argument is null */ public Node findOrCreateNode( Session session, String path ) throws RepositoryException { return findOrCreateNode(session, path, null, null); }
/** * Get or create a node at the specified path. * * @param session the JCR session. may not be null * @param path the path of the desired node to be found or created. may not be null * @return the existing or newly created node * @throws RepositoryException * @throws IllegalArgumentException if either the session or path argument is null */ public Node findOrCreateNode( Session session, String path ) throws RepositoryException { return findOrCreateNode(session, path, null, null); }
/** * Get or create a node with the specified node and node type under the specified parent node. * * @param parent the parent node. may not be null * @param name the name of the child node. may not be null * @param nodeType the node type. may be null * @return the existing or newly created child node * @throws RepositoryException */ public Node findOrCreateChild( Node parent, String name, String nodeType ) throws RepositoryException { return findOrCreateNode(parent, name, nodeType, nodeType); }
/** * Get or create a node with the specified node and node type under the specified parent node. * * @param parent the parent node. may not be null * @param name the name of the child node. may not be null * @param nodeType the node type. may be null * @return the existing or newly created child node * @throws RepositoryException */ public Node findOrCreateChild( Node parent, String name, String nodeType ) throws RepositoryException { return findOrCreateNode(parent, name, nodeType, nodeType); }
@Test public void testCreateNodeSessionPath() throws RepositoryException { Node node = tools.findOrCreateNode(session, "Hobby"); assertNotNull(node); assertThat(node.getName(), is("Hobby")); }
@Test public void testFindNodeSessionPath() throws RepositoryException { Node node = tools.findOrCreateNode(session, "Person"); assertNotNull(node); assertThat(node.getName(), is("Person")); }
@Test public void shouldFailFindOrCreateNodeNodePathTypeTypeNullNode() { try { tools.findOrCreateNode(NULL_NODE, "/topNode", DEF_TYPE, DEF_TYPE); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void shouldFailFindOrCreateNodeSessionPathTypeTypeNullPath() { try { tools.findOrCreateNode(session, NULL_STRING, DEF_TYPE, DEF_TYPE); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void testCreateNodeSessionPathType() throws RepositoryException { Node node = tools.findOrCreateNode(session, "Hobby", DEF_TYPE); assertNotNull(node); assertThat(node.getName(), is("Hobby")); }
@Test public void shouldFailFindOrCreateNodeSessionPathTypeNullSession() { Session sess = null; try { tools.findOrCreateNode(sess, "Person", DEF_TYPE); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void shouldFailFindOrCreateNodeSessionPathTypeNullPath() { try { tools.findOrCreateNode(session, NULL_STRING, DEF_TYPE); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void testFindNodeSessionPathTypeType() throws RepositoryException { Node node = tools.findOrCreateNode(session, "Person", DEF_TYPE, DEF_TYPE); assertNotNull(node); assertThat(node.getName(), is("Person")); }
@Test public void shouldFindNodeParentPathTypeType() throws RepositoryException { Node node = tools.findOrCreateNode(personNode, "Address", DEF_TYPE, DEF_TYPE); assertNotNull(node); assertThat(node.getName(), is("Address")); }
@Test public void shouldFailFindOrCreateNodeSessionPathNullSession() { Session sess = null; try { tools.findOrCreateNode(sess, "Person"); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void testFindNodeSessionPathType() throws RepositoryException { Node node = tools.findOrCreateNode(session, "Person", DEF_TYPE); assertNotNull(node); assertThat(node.getName(), is("Person")); }
@Test public void testCreateNodeSessionPathTypeType() throws RepositoryException { Node node = tools.findOrCreateNode(session, "Hobby", DEF_TYPE, DEF_TYPE); assertNotNull(node); assertThat(node.getName(), is("Hobby")); }
@Test public void shouldFailFindOrCreateNodeNodePathTypeTypeNullPath() { try { tools.findOrCreateNode(personNode, NULL_STRING, DEF_TYPE, DEF_TYPE); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void shouldFailFindOrCreateNodeSessionPathNullPath() { try { tools.findOrCreateNode(session, NULL_STRING); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void shouldFailFindOrCreateNodeSessionPathTypeTypeNullSession() { Session sess = null; try { tools.findOrCreateNode(sess, "Person", DEF_TYPE, DEF_TYPE); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void shouldCreateNodeNodePathTypeType() throws RepositoryException { Node node = tools.findOrCreateNode(personNode, "Hobby", DEF_TYPE, "nt:unstructured"); assertNotNull(node); assertThat(node.getName(), is("Hobby")); }