@Test void load() throws UnsupportedEncodingException { Document doc = DocumentTools.INSTANCE.getDocumentBuilder().newDocument(); Bundle bundle = new Bundle(); loader.load(bundle, createFolderXml(doc, Folder.ROOT_FOLDER_NAME, Folder.ROOT_FOLDER_ID, null)); loader.load(bundle, createFolderXml(doc, TEST_FOLDER_1, TEST_FOLDER_1, Folder.ROOT_FOLDER_ID)); loader.load(bundle, createFolderXml(doc, TEST_FOLDER_2, TEST_FOLDER_2, TEST_FOLDER_1)); assertFalse(bundle.getFolders().isEmpty()); assertEquals(3, bundle.getFolders().size()); final String encodedRoot = URLEncoder.encode(Folder.ROOT_FOLDER_NAME, "UTF-8"); Folder root = bundle.getFolders().get(encodedRoot); assertNotNull(root); Assertions.assertEquals(Folder.ROOT_FOLDER_ID, root.getId()); Assertions.assertEquals(encodedRoot, root.getName()); assertNull(root.getParentFolder()); Assertions.assertEquals(encodedRoot, root.getPath()); Folder folder1 = bundle.getFolders().get(TEST_FOLDER_1); assertNotNull(folder1); assertEquals(TEST_FOLDER_1, folder1.getId()); assertEquals(TEST_FOLDER_1, folder1.getName()); assertEquals(root, folder1.getParentFolder()); assertEquals(TEST_FOLDER_1, folder1.getPath()); String f2Path = Paths.get(TEST_FOLDER_1, TEST_FOLDER_2).toString(); Folder folder2 = bundle.getFolders().get(f2Path); assertNotNull(folder2); assertEquals(TEST_FOLDER_2, folder2.getId()); assertEquals(TEST_FOLDER_2, folder2.getName()); assertEquals(folder1, folder2.getParentFolder()); assertEquals(f2Path, folder2.getPath()); }
@Override public void load(Bundle bundle, Element element) { final Element folderElement = getSingleChildElement(getSingleChildElement(element, RESOURCE), FOLDER); String name = getSingleChildElementTextContent(folderElement, NAME); final String id = folderElement.getAttribute(ATTRIBUTE_ID); final String parentFolderID = folderElement.getAttribute(ATTRIBUTE_FOLDER_ID); final Folder parentFolder; if (ROOT_FOLDER_ID.equals(id)) { parentFolder = null; } else { parentFolder = ServiceAndPolicyLoaderUtil.getFolder(bundle, parentFolderID); } name = CharacterBlacklistUtil.encodeName(name); Folder folder = new Folder(); folder.setId(id); folder.setName(name); folder.setParentFolder(parentFolder); folder.setPath(getPath(folder).toString()); bundle.getFolders().put(folder.getPath(), folder); }
FolderLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element folderElement = getSingleChildElement(getSingleChildElement(element, RESOURCE), FOLDER); String name = getSingleChildElementTextContent(folderElement, NAME); final String id = folderElement.getAttribute(ATTRIBUTE_ID); final String parentFolderID = folderElement.getAttribute(ATTRIBUTE_FOLDER_ID); final Folder parentFolder; if (ROOT_FOLDER_ID.equals(id)) { parentFolder = null; } else { parentFolder = ServiceAndPolicyLoaderUtil.getFolder(bundle, parentFolderID); } name = CharacterBlacklistUtil.encodeName(name); Folder folder = new Folder(); folder.setId(id); folder.setName(name); folder.setParentFolder(parentFolder); folder.setPath(getPath(folder).toString()); bundle.getFolders().put(folder.getPath(), folder); } }
FolderLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element folderElement = getSingleChildElement(getSingleChildElement(element, RESOURCE), FOLDER); String name = getSingleChildElementTextContent(folderElement, NAME); final String id = folderElement.getAttribute(ATTRIBUTE_ID); final String parentFolderID = folderElement.getAttribute(ATTRIBUTE_FOLDER_ID); final Folder parentFolder; if (ROOT_FOLDER_ID.equals(id)) { parentFolder = null; } else { parentFolder = ServiceAndPolicyLoaderUtil.getFolder(bundle, parentFolderID); } name = CharacterBlacklistUtil.encodeName(name); Folder folder = new Folder(); folder.setId(id); folder.setName(name); folder.setParentFolder(parentFolder); folder.setPath(getPath(folder).toString()); bundle.getFolders().put(folder.getPath(), folder); }  }
FolderLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element folderElement = getSingleChildElement(getSingleChildElement(element, RESOURCE), FOLDER); String name = getSingleChildElementTextContent(folderElement, NAME); final String id = folderElement.getAttribute(ATTRIBUTE_ID); final String parentFolderID = folderElement.getAttribute(ATTRIBUTE_FOLDER_ID); final Folder parentFolder; if (ROOT_FOLDER_ID.equals(id)) { parentFolder = null; } else { parentFolder = ServiceAndPolicyLoaderUtil.getFolder(bundle, parentFolderID); } name = CharacterBlacklistUtil.encodeName(name); Folder folder = new Folder(); folder.setId(id); folder.setName(name); folder.setParentFolder(parentFolder); folder.setPath(getPath(folder).toString()); bundle.getFolders().put(folder.getPath(), folder); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType(); }
FolderLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element folderElement = getSingleChildElement(getSingleChildElement(element, RESOURCE), FOLDER); String name = getSingleChildElementTextContent(folderElement, NAME); final String id = folderElement.getAttribute(ATTRIBUTE_ID); final String parentFolderID = folderElement.getAttribute(ATTRIBUTE_FOLDER_ID); final Folder parentFolder; if (ROOT_FOLDER_ID.equals(id)) { parentFolder = null; } else { parentFolder = ServiceAndPolicyLoaderUtil.getFolder(bundle, parentFolderID); } name = CharacterBlacklistUtil.encodeName(name); Folder folder = new Folder(); folder.setId(id); folder.setName(name); folder.setParentFolder(parentFolder); folder.setPath(getPath(folder).toString()); bundle.getFolders().put(folder.getPath(), folder); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType();  }