NamespaceMappingRequest { public List<Result<JcrNs>> resolveToJcrNs(final @NotNull NamespaceMapping mapping) { final List<Result<JcrNs>> results = new ArrayList<>(); retainPrefixes.stream() .map(result1(prefix -> JcrNs.create(prefix, mapping.getURI(prefix)))) .forEach(results::add); final Set<String> retainedUris = results.stream().flatMap(Result::stream).map(JcrNs::getUri) .collect(Collectors.toSet()); retainUris.stream() .filter(inSet(retainedUris).negate()) .map(result1(uri -> JcrNs.create(mapping.getPrefix(uri), uri))) .forEach(results::add); return results; } private  NamespaceMappingRequest(final @NotNull Set<String> retainPrefixes,
                                    final @NotNull Set<String> retainUris,
                                    final boolean retainBuiltins); List<Result<JcrNs>> resolveToJcrNs(final @NotNull NamespaceMapping mapping);  }
@Test public void testBuildWithNoRetention() { final NamespaceMappingRequest request = builder().build(); assertTrue("no retain results in empty list", request.resolveToJcrNs(mapping).isEmpty()); }
@Test public void testBuildWithRetainPrefix() { final NamespaceMappingRequest request = builder() .withRetainPrefix(NamespaceRegistry.PREFIX_JCR) .withRetainPrefix(NS_FOO_PREFIX).build(); assertTrue("foo mapping is retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals))); assertFalse("non-foo mappings are not retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals).negate())); }
@Test public void testBuildWithRetainUri() { final NamespaceMappingRequest request = builder() .withRetainUri(NamespaceRegistry.NAMESPACE_JCR) .withRetainUri(NS_FOO_URI) .build(); assertTrue("foo mapping is retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals))); assertFalse("non-foo mappings are not retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals).negate())); }
@Test public void testBuildWithRetainBuiltins() { final NamespaceMappingRequest request = builder() .withRetainBuiltins(true) .withRetainPrefix(NamespaceRegistry.PREFIX_JCR) .withRetainPrefix(NS_FOO_PREFIX) .build(); request.resolveToJcrNs(mapping).stream().filter(Result::isFailure).findFirst().map(Result::teeLogError); assertTrue("jcr mapping is retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .map(JcrNs::getPrefix) .anyMatch(inferTest1(NamespaceRegistry.PREFIX_JCR::equals))); assertTrue("foo mapping is retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals))); assertFalse("bar mapping is not retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_BAR::equals))); }
@Test public void testBuildWithQName() throws Exception { final NamespaceMappingRequest request = builder() .withQName(resolver.getQName("jcr:content")) .withQName(resolver.getQName("foo:folder")) .build(); assertTrue("foo mapping is retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals))); assertFalse("non-foo mappings are not retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals).negate())); }
@Test public void testBuildWithJCRName_prefix() { final NamespaceMappingRequest request = builder() .withJCRName("jcr:content") .withJCRName("foo:folder") .build(); assertTrue("foo mapping is retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals))); assertFalse("non-foo mappings are not retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals).negate())); }
@Test public void testBuildWithJCRName_uri() { final NamespaceMappingRequest request = builder().withJCRName(String.format("{%s}folder", NS_FOO_URI)).build(); assertTrue("foo mapping is retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals))); assertFalse("non-foo mappings are not retained", request.resolveToJcrNs(mapping).stream().flatMap(Result::stream) .anyMatch(inferTest1(NS_FOO::equals).negate())); }