@Test public void testSimpleMapping() { final Mapping m = new Mapping("/content:2"); final String[][] testCases = { { "/content/foo", "nt:unstructured", "foo" }, { "/content/foo/bar", "nt:unstructured", "foo" }, { "/not/content/foo/bar", "nt:unstructured", null }, { "/content/foo/bar", "nt:file", null } }; for(int i=0; i < testCases.length; i++) { final String [] tc = testCases[i]; if(tc[2] == null) { assertNull("At index " + i, m.getResourceType(tc[0], tc[1])); } else { assertEquals("At index " + i, tc[2], m.getResourceType(tc[0], tc[1])); } } }
String getResourceType(String nodePath, String nodeType) { String result = null; if(path!=null && nodePath.startsWith(path) && nodeTypeMatches(nodeType)) { final String [] paths = nodePath.split("/"); if(paths.length >= resourceTypeIndex+1) { result = paths[resourceTypeIndex]; } } return result; }
Mapping { String getResourceType(String nodePath, String nodeType) { String result = null; if(path!=null && nodePath.startsWith(path) && nodeTypeMatches(nodeType)) { final String [] paths = nodePath.split("/"); if(paths.length >= resourceTypeIndex+1) { result = paths[resourceTypeIndex]; } } return result; } }
Mapping { String getResourceType(String nodePath, String nodeType) { String result = null; if(path!=null && nodePath.startsWith(path) && nodeTypeMatches(nodeType)) { final String [] paths = nodePath.split("/"); if(paths.length >= resourceTypeIndex+1) { result = paths[resourceTypeIndex]; } } return result; } Mapping(String definition); }
Mapping { String getResourceType(String nodePath, String nodeType) { String result = null; if(path!=null && nodePath.startsWith(path) && nodeTypeMatches(nodeType)) { final String [] paths = nodePath.split("/"); if(paths.length >= resourceTypeIndex+1) { result = paths[resourceTypeIndex]; } } return result; } Mapping(String definition); @Override String toString(); }
Mapping { String getResourceType(String nodePath, String nodeType) { String result = null; if(path!=null && nodePath.startsWith(path) && nodeTypeMatches(nodeType)) { final String [] paths = nodePath.split("/"); if(paths.length >= resourceTypeIndex+1) { result = paths[resourceTypeIndex]; } } return result; } Mapping(String definition); @Override String toString(); static final String DEFAULT_NODE_TYPE; }