ResourceHandler extends AbstractHandler { public String uriVariable(final String pathVariable) { if (StringUtils.isEmpty(this.resourceURITemplate) || StringUtils.isEmpty(this.resourceURI) || StringUtils.isEmpty(pathVariable)) { return ""; } UriTemplate template = new UriTemplate(this.resourceURITemplate); Map<String, String> match = template.match(this.resourceURI); String pathVariableValue = match.get(pathVariable); return pathVariableValue != null ? pathVariableValue : ""; } ResourceHandler(final Set<Attribute> attributeSet, final String resourceURI,
            final String resourceURLTemplate); String uriVariable(final String pathVariable);  }
@Test public void testNullAttributes() { ResourceHandler handler = new ResourceHandler(null, null, null); Assert.assertNotNull(handler); Assert.assertEquals("", handler.uriVariable("site_id")); Assert.assertEquals("", handler.uriVariable(null)); }
@Test public void testPartialNullAttributes() { ResourceHandler handler = new ResourceHandler(null, null, "a"); Assert.assertNotNull(handler); Assert.assertEquals("", handler.uriVariable("site_id")); Assert.assertEquals("", handler.uriVariable(null)); }
@Test public void testUriVariableNegative() { HashSet<Attribute> attributes = new HashSet<Attribute>( Arrays.asList(new Attribute("acs", "site", "boston"), new Attribute("acs", "department", "sales"))); ResourceHandler handler = new ResourceHandler(attributes, "", ""); Assert.assertEquals("", handler.uriVariable("")); Assert.assertEquals("", handler.uriVariable(null)); }
@Test public void testUriVariablePositive() { HashSet<Attribute> attributes = new HashSet<Attribute>( Arrays.asList(new Attribute("acs", "site", "boston"), new Attribute("acs", "department", "sales"))); ResourceHandler handler = new ResourceHandler(attributes, "http: Assert.assertEquals("boston", handler.uriVariable("site_id")); Assert.assertEquals("sales", handler.uriVariable("department_id")); Assert.assertNotEquals("hr", handler.uriVariable("department_id")); }