CndExporter { public void writeNodetypes(final @NotNull File cndFile, final @NotNull Session session, final @NotNull List<String> desiredTypeNames) throws RepositoryException, IOException, ParseException { writeNodetypes(() -> new OutputStreamWriter(new FileOutputStream(cndFile), StandardCharsets.UTF_8), session, desiredTypeNames, cndFile); } private  CndExporter(final List<Rule> scopeExportNames,
                        final List<Rule> scopeReplaceNames,
                        final boolean includeBuiltins); void writeNodetypes(final @NotNull File cndFile,
                               final @NotNull Session session,
                               final @NotNull List<String> desiredTypeNames); void writeNodetypes(final @NotNull WriterOpener writerOpener,
                               final @NotNull Session session,
                               final @NotNull List<String> desiredTypeNames,
                               final @Nullable File initialCnd); static Map<Name, NodeTypeDefinition> retrieveNodeTypes(final @NotNull Session session,
                                                                  final @NotNull Collection<Name> desiredTypeNames); static Map<Name, NodeTypeDefinition> retrieveNodeTypes(final @NotNull Session session,
                      final @NotNull Collection<Name> desiredTypeNames,
                      final @Nullable BiPredicate<NamePathResolver, NodeType> nodeTypeSelector); static final List<String> BUILTIN_NODETYPES; }
@Test public void testWriteNodetypesWithBuiltins() throws Exception { final File tempDir = new File(testBaseDir, "testWriteNodetypesWithBuiltins"); final File fromRepoDir = new File(tempDir, "fromRepo/segmentstore"); final File explicitTypesCnd = new File(tempDir, "explicitTypes.cnd"); final File allTypesCnd = new File(tempDir, "allTypes.cnd"); TestUtil.prepareRepo(fromRepoDir, session -> { final URL slingNodetypes = getClass().getResource("/sling_nodetypes.cnd"); TestUtil.installCndFromURL(session, slingNodetypes); }); if (explicitTypesCnd.exists()) { explicitTypesCnd.delete(); } if (allTypesCnd.exists()) { allTypesCnd.delete(); } TestUtil.withReadOnlyFixture(fromRepoDir, session -> { new CndExporter.Builder().withIncludeBuiltins(true).build() .writeNodetypes(explicitTypesCnd, session, Arrays.asList("sling:Folder", "nt:folder")); try (Scanner scanner = new Scanner(explicitTypesCnd, StandardCharsets.UTF_8.name())) { assertNull("nt:query should not be defined", scanner.findWithinHorizon("\\[nt:query]", 0)); } try (Scanner scanner = new Scanner(explicitTypesCnd, StandardCharsets.UTF_8.name())) { assertNull("sling:OrderedFolder should not be defined", scanner.findWithinHorizon("\\[sling:OrderedFolder]", 0)); } try (Scanner scanner = new Scanner(explicitTypesCnd, StandardCharsets.UTF_8.name())) { assertNotNull("nt:folder should be defined", scanner.findWithinHorizon("\\[nt:folder]", 0)); } try (Scanner scanner = new Scanner(explicitTypesCnd, StandardCharsets.UTF_8.name())) { assertNotNull("sling:Folder should be defined", scanner.findWithinHorizon("\\[sling:Folder]", 0)); } }); }
@Test public void testWriteNodetypes() throws Exception { final File tempDir = new File(testBaseDir, "testWriteNodetypes"); final File fromRepoDir = new File(tempDir, "fromRepo/segmentstore"); final File toRepoDir = new File(tempDir, "toRepo/segmentstore"); final File exportedCnd = new File(tempDir, "exported.cnd"); TestUtil.prepareRepo(fromRepoDir, session -> { final URL slingNodetypes = getClass().getResource("/sling_nodetypes.cnd"); TestUtil.installCndFromURL(session, slingNodetypes); }); if (exportedCnd.exists()) { exportedCnd.delete(); } TestUtil.withReadOnlyFixture(fromRepoDir, session -> { final Workspace workspace = session.getWorkspace(); NodeTypeManager ntManager = workspace.getNodeTypeManager(); assertTrue("sling:Folder should be imported", ntManager.hasNodeType("sling:Folder")); assertTrue("sling:OrderedFolder should be imported", ntManager.hasNodeType("sling:OrderedFolder")); new CndExporter.Builder().build() .writeNodetypes(exportedCnd, session, Arrays.asList("sling:Folder", "sling:OrderedFolder")); }); TestUtil.prepareRepo(toRepoDir, session -> { final URL exportedUrl = exportedCnd.toURL(); TestUtil.installCndFromURL(session, exportedUrl); }); TestUtil.withReadOnlyFixture(toRepoDir, session -> { final Workspace workspace = session.getWorkspace(); NodeTypeManager ntManager = workspace.getNodeTypeManager(); assertTrue("sling:Folder should be imported", ntManager.hasNodeType("sling:Folder")); assertTrue("sling:OrderedFolder should be imported", ntManager.hasNodeType("sling:OrderedFolder")); }); }
@Test public void testWriteNodetypesByName() throws Exception { final File tempDir = new File(testBaseDir, "testWriteNodetypesByName"); final File fromRepoDir = new File(tempDir, "fromRepo/segmentstore"); final File toRepoDir = new File(tempDir, "toRepo/segmentstore"); final File exportedCnd = new File(tempDir, "exported.cnd"); TestUtil.prepareRepo(fromRepoDir, session -> { final URL slingNodetypes = getClass().getResource("/sling_nodetypes.cnd"); TestUtil.installCndFromURL(session, slingNodetypes); }); if (exportedCnd.exists()) { exportedCnd.delete(); } TestUtil.withReadOnlyFixture(fromRepoDir, session -> { final Workspace workspace = session.getWorkspace(); NodeTypeManager ntManager = workspace.getNodeTypeManager(); assertTrue("sling:Folder should be imported", ntManager.hasNodeType("sling:Folder")); assertTrue("sling:OrderedFolder should be imported", ntManager.hasNodeType("sling:OrderedFolder")); new CndExporter.Builder().build() .writeNodetypes(exportedCnd, session, Collections.singletonList("sling:Folder")); }); TestUtil.prepareRepo(toRepoDir, session -> { final URL exportedUrl = exportedCnd.toURL(); TestUtil.installCndFromURL(session, exportedUrl); }); TestUtil.withReadOnlyFixture(toRepoDir, session -> { final Workspace workspace = session.getWorkspace(); NodeTypeManager ntManager = workspace.getNodeTypeManager(); assertTrue("sling:Folder should be imported", ntManager.hasNodeType("sling:Folder")); assertFalse("sling:OrderedFolder should NOT be imported", ntManager.hasNodeType("sling:OrderedFolder")); }); }