JsonCnd { public static List<Result<NodeTypeSet>> readNodeTypes(final @NotNull NamespaceMapping mapping, final @NotNull List<URL> cndUrls) { final List<Result<NodeTypeSet>> results = new ArrayList<>(); for (URL cndUrl : cndUrls) { final CNDReader cndReader = new DefaultCNDReader(); try (Reader reader = new InputStreamReader(cndUrl.openStream(), StandardCharsets.UTF_8)) { cndReader.read(reader, cndUrl.toExternalForm(), mapping); results.add(Result.success(cndReader)); } catch (IOException e) { results.add(Result.failure(new RuntimeException(cndUrl.toExternalForm(), e))); } } return results; } private  JsonCnd(); @SuppressWarnings("WeakerAccess") static List<QNodeTypeDefinition> getQTypesFromJson(final @NotNull JsonObject json,
                      final @NotNull NamespaceMapping mapping); @SuppressWarnings("WeakerAccess") static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json,
                          final @NotNull NamespaceMapping mapping); static JsonObject toJson(final @NotNull List<QNodeTypeDefinition> ntDefs,
                                    final @NotNull NamespaceMapping mapping); static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs,
                                             final @NotNull NamespaceMapping mapping); static List<JcrNs> toJcrNsList(final @NotNull NamespaceMapping mapping,
                                          final @NotNull NamespaceMappingRequest request); static Function<NodeTypeDefinition, QNodeTypeDefinition> adaptToQ(final @NotNull Session session); static Stream<Name> namedBy(final @NotNull QNodeTypeDefinition def); static Stream<Name> namedBy(final @NotNull PrivilegeDefinition def); static NamespaceMapping toNamespaceMapping(final List<JcrNs> jcrNsList); static @NotNull Stream<String> streamNsPrefix(final @NotNull String name); static List<Result<NodeTypeSet>> readNodeTypes(final @NotNull NamespaceMapping mapping,
                                                          final @NotNull List<URL> cndUrls); static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping,
                                                 final @NotNull List<NodeTypeSet> nodeTypeSets); static final NamespaceMapping BUILTIN_MAPPINGS; static final List<String> BUILTIN_NODETYPES; static final List<String> BUILTIN_PRIVILEGES; }
@Test public void testReadNodeTypes() { List<URL> cnds = Stream.of("a", "b", "c", "d", "e", "f") .map(letter -> new File(baseDir, letter + ".cnd")) .map(compose1(File::toURI, uncheck1(URI::toURL))) .collect(Collectors.toList()); final List<Result<NodeTypeSet>> sets = JsonCnd.readNodeTypes(getMapping(), cnds); assertEquals("sets should have n sets", cnds.size(), sets.size()); assertTrue("all are successful", sets.stream().allMatch(Result::isSuccess)); assertTrue("all are successful", sets.stream() .map(result -> result .map(compose1(NodeTypeSet::getNodeTypes, Map::size)) .getOrDefault(0)) .allMatch(size -> size == 2)); List<URL> cndsWithError = Stream.of("a", "b", "c", "error", "d", "e", "f") .map(letter -> new File(baseDir, letter + ".cnd")) .map(compose1(File::toURI, uncheck1(URI::toURL))) .collect(Collectors.toList()); final List<Result<NodeTypeSet>> setsWithError = JsonCnd.readNodeTypes(getMapping(), cndsWithError); assertEquals("setsWithError should have n sets", cndsWithError.size(), setsWithError.size()); assertFalse("not all are successful", setsWithError.stream().allMatch(Result::isSuccess)); assertEquals("setsWithError should have n successful sets", cndsWithError.size() - 1, setsWithError.stream().filter(Result::isSuccess).count()); }