ResourceAttributeResolver { public ResourceAttributeResolverResult getResult(final Policy policy) { String resolvedResourceUri = resolveResourceURI(policy); boolean uriTemplateExists = true; if (null == resolvedResourceUri) { resolvedResourceUri = this.requestResourceUri; uriTemplateExists = false; } Set<Attribute> resourceAttributes = this.resourceAttributeMap.get(resolvedResourceUri); if (null == resourceAttributes) { resourceAttributes = new HashSet<>(this.resourceAttributeReader.getAttributes(resolvedResourceUri)); resourceAttributes.addAll(this.supplementalResourceAttributes); this.resourceAttributeMap.put(resolvedResourceUri, resourceAttributes); } return new ResourceAttributeResolverResult(resourceAttributes, resolvedResourceUri, uriTemplateExists); } ResourceAttributeResolver(final ResourceAttributeReader resourceAttributeReader,
            final String requestResourceUri, final Set<Attribute> supplementalResourceAttributes); ResourceAttributeResolverResult getResult(final Policy policy);  }
@Test public void testGetResourceAttributesResourceFoundWithNoAttributesAndNoSupplementalAttributes() { ResourceAttributeResolver resolver = new ResourceAttributeResolver(this.defaultResourceAttributeReader, this.testResource.getResourceIdentifier(), null); Set<Attribute> combinedResourceAttributes = resolver.getResult(getPolicy(null)).getResourceAttributes(); Assert.assertTrue(combinedResourceAttributes.isEmpty()); }
@Test public void testGetResourceAttributesResourceFoundWithAttributesAndNoSupplementalAttributes() { Set<Attribute> resourceAttributes = new HashSet<>(); resourceAttributes.add(new Attribute("https: this.testResource.setAttributes(resourceAttributes); when(this.defaultResourceAttributeReader.getAttributes(eq(this.testResource.getResourceIdentifier()))) .thenReturn(resourceAttributes); ResourceAttributeResolver resolver = new ResourceAttributeResolver(this.defaultResourceAttributeReader, this.testResource.getResourceIdentifier(), null); Set<Attribute> combinedResourceAttributes = resolver.getResult(getPolicy(null)).getResourceAttributes(); Assert.assertNotNull(combinedResourceAttributes); Assert.assertTrue(combinedResourceAttributes.containsAll(resourceAttributes)); }
@Test public void testGetResourceAttributesSupplementalAttributesOnly() { Set<Attribute> supplementalResourceAttributes = new HashSet<>(); supplementalResourceAttributes.add(new Attribute("https: ResourceAttributeResolver resolver = new ResourceAttributeResolver(this.defaultResourceAttributeReader, this.testResource.getResourceIdentifier(), supplementalResourceAttributes); Set<Attribute> combinedResourceAttributes = resolver.getResult(getPolicy(null)).getResourceAttributes(); Assert.assertNotNull(combinedResourceAttributes); Assert.assertTrue(combinedResourceAttributes.containsAll(supplementalResourceAttributes)); }