import javax.ws.rs.*;\r
import javax.ws.rs.core.*;\r
\r
+import java.util.HashMap;\r
import java.util.List;\r
+import java.util.Map;\r
\r
/**\r
* $LastChangedRevision: $\r
throws Exception, DocumentNotFoundException {\r
return getDocModelForAuthorityItem(repoSession, RefName.AuthorityItem.parse(refName));\r
}\r
+ \r
+ // FIXME: For authority items, we will need to return an array / collection of uriTemplate objects,\r
+ // since there are two different doctypes, with associated uriTemplates, to insert into the registry.\r
+ // The following is a placeholder to test proof of concept, adding a single item from each resource\r
+ // to the registry.\r
+ \r
+ public String getDocType() {\r
+ // FIXME: Proof of concept placeholder\r
+ return getServiceName();\r
+ }\r
+ \r
+\r
+ public StoredValuesUriTemplate getUriTemplate() {\r
+ Map<String,String> storedValuesMap = new HashMap<String,String>();\r
+ storedValuesMap.put(UriTemplateFactory.SERVICENAME_VAR, getServiceName());\r
+ StoredValuesUriTemplate template =\r
+ UriTemplateFactory.getURITemplate(UriTemplateFactory.UriTemplateType.RESOURCE,\r
+ storedValuesMap);\r
+ return template;\r
+ }\r
\r
}\r
* provided template type.\r
*/\r
public class UriTemplateFactory {\r
+ \r
+ public final static String SERVICENAME_VAR = "servicename";\r
+ public final static String IDENTIFIER_VAR = "identifier";\r
+ public final static String ITEM_IDENTIFIER_VAR = "itemIdentifier";\r
+ public final static String CONTACT_IDENTIFIER_VAR = "contactIdentifier";\r
\r
public final static String RESOURCE_PATH_PATTERN =\r
- "/{servicename}/{identifier}";\r
+ "/ +"\r
+ + "{" + SERVICENAME_VAR + "}"\r
+ + "/"\r
+ + "{" + IDENTIFIER_VAR + "}";\r
// FIXME: Get static strings below (e.g. "items", "contacts") from\r
// already-declared constants elsewhere\r
public final static String ITEM_PATH_PATTERN =\r
- "/{servicename}/{identifier}/items/{itemIdentifier}";\r
+ RESOURCE_PATH_PATTERN\r
+ + "/items/"\r
+ + "{" + ITEM_IDENTIFIER_VAR + "}";\r
public final static String CONTACT_PATH_PATTERN =\r
- "/{servicename}/{identifier}/items/{itemIdentifier}/contacts/{contactIdentifier}";\r
+ ITEM_PATH_PATTERN\r
+ + "/contacts/"\r
+ + "{" + CONTACT_IDENTIFIER_VAR + "}";\r
\r
public static StoredValuesUriTemplate getURITemplate(UriTemplateType type) {\r
return new StoredValuesUriTemplate(getUriPathPattern(type));\r
}\r
\r
public static StoredValuesUriTemplate getURITemplate(UriTemplateType type, Map<String,String> storedValuesMap) {\r
- StoredValuesUriTemplate template = new StoredValuesUriTemplate(getUriPathPattern(type));\r
- template.setStoredValuesMap(storedValuesMap);\r
- return template;\r
+ return new StoredValuesUriTemplate(getUriPathPattern(type), storedValuesMap);\r
}\r
\r
private static String getUriPathPattern(UriTemplateType type) {\r
\r
public class UriTemplateTest {\r
\r
- final static String EXAMPLE_SERVICE_NAME = "examples";\r
- final static String EXAMPLE_CSID = "a87f6616-4146-4c17-a41a-048597cc12aa";\r
- final static HashMap<String, String> EMPTY_VALUES_MAP = new HashMap<String, String>();\r
+ private final static String EXAMPLE_SERVICE_NAME = "examples";\r
+ private final static String EXAMPLE_CSID = "a87f6616-4146-4c17-a41a-048597cc12aa";\r
+ private final static String EXAMPLE_ITEM_CSID = "5d1c2f45-6d02-4376-8852-71893eaf8b1b";\r
+ private final static HashMap<String, String> EMPTY_VALUES_MAP = new HashMap<String, String>();\r
private static final Logger logger = LoggerFactory.getLogger(UriTemplateTest.class);\r
\r
private void testBanner(String msg) {\r
resourceUriVars.put("servicename", EXAMPLE_SERVICE_NAME);\r
resourceUriVars.put("identifier", EXAMPLE_CSID);\r
String uriStr = resourceTemplate.buildUri(resourceUriVars);\r
+ logger.debug("Generated URI string = " + uriStr);\r
Assert.assertFalse(Tools.isBlank(uriStr), "Generated URI string is null or blank.");\r
Assert.assertTrue(uriStr.contains(EXAMPLE_SERVICE_NAME), "Generated URI string does not contain expected value: " + EXAMPLE_SERVICE_NAME);\r
Assert.assertTrue(uriStr.contains(EXAMPLE_CSID), "Generated URI string does not contain expected value: " + EXAMPLE_CSID);\r
- logger.debug("Generated URI string = " + uriStr);\r
}\r
\r
@Test(dependsOnMethods = {"buildResourceUri"})\r
Map<String, String> additionalValues = new HashMap<String, String>();\r
additionalValues.put("identifier", EXAMPLE_CSID);\r
String uriStr = storedValuesResourceTemplate.buildUri(additionalValues);\r
- Assert.assertFalse(Tools.isBlank(uriStr), "Generated URI string is null or blank.");\r
+ logger.debug("Generated URI string = " + uriStr);\r
+ Assert.assertTrue(Tools.notBlank(uriStr), "Generated URI string is null or blank.");\r
Assert.assertTrue(uriStr.contains(EXAMPLE_SERVICE_NAME), "Generated URI string does not contain expected value: " + EXAMPLE_SERVICE_NAME);\r
Assert.assertTrue(uriStr.contains(EXAMPLE_CSID), "Generated URI string does not contain expected value: " + EXAMPLE_CSID);\r
+ }\r
+\r
+ @Test(dependsOnMethods = {"buildResourceUri"})\r
+ public void buildItemUri() {\r
+ testBanner("buildItemUri");\r
+ Map<String, String> storedValuesMap = new HashMap<String, String>();\r
+ storedValuesMap.put("servicename", EXAMPLE_SERVICE_NAME);\r
+ StoredValuesUriTemplate itemTemplate =\r
+ UriTemplateFactory.getURITemplate(UriTemplateFactory.UriTemplateType.ITEM, storedValuesMap);\r
+ Map<String, String> additionalValues = new HashMap<String, String>();\r
+ additionalValues.put("identifier", EXAMPLE_CSID);\r
+ additionalValues.put("itemIdentifier", EXAMPLE_ITEM_CSID);\r
+ String uriStr = itemTemplate.buildUri(additionalValues);\r
logger.debug("Generated URI string = " + uriStr);\r
+ Assert.assertTrue(Tools.notBlank(uriStr), "Generated URI string is null or blank.");\r
+ Assert.assertTrue(uriStr.contains(EXAMPLE_SERVICE_NAME), "Generated URI string does not contain expected value: " + EXAMPLE_SERVICE_NAME);\r
+ Assert.assertTrue(uriStr.contains(EXAMPLE_CSID), "Generated URI string does not contain expected value: " + EXAMPLE_CSID);\r
+ Assert.assertTrue(uriStr.contains(EXAMPLE_ITEM_CSID), "Generated URI string does not contain expected item value: " + EXAMPLE_ITEM_CSID);\r
}\r
+ \r
+ // Negative tests: errors are anticipated and checked for in each of the following tests\r
\r
@Test(dependsOnMethods = {"buildResourceUri"})\r
public void buildResourceUriWithMissingValue() {\r
// The required 'identifier' value is missing from the Map from which the URI will be built\r
logger.debug("This is a negative test, and an error message is expected here:");\r
String uriStr = resourceTemplate.buildUri(resourceUriVars);\r
- Assert.assertTrue(Tools.isBlank(uriStr), "Generated URI string was not blank, but should have been.");\r
logger.debug("Generated URI string = " + uriStr);\r
+ Assert.assertTrue(Tools.isBlank(uriStr), "Generated URI string was not blank, but should have been.");\r
}\r
\r
@Test(dependsOnMethods = {"buildResourceUri"})\r
resourceUriVars.put("identifier", null);\r
logger.debug("This is a negative test, and an error message is expected here:");\r
String uriStr = resourceTemplate.buildUri(resourceUriVars);\r
- Assert.assertTrue(Tools.isBlank(uriStr), "Generated URI string was not blank, but should have been.");\r
logger.debug("Generated URI string = " + uriStr);\r
+ Assert.assertTrue(Tools.isBlank(uriStr), "Generated URI string was not blank, but should have been.");\r
}\r
\r
@Test(dependsOnMethods = {"buildResourceUri"})\r
UriTemplate resourceTemplate = UriTemplateFactory.getURITemplate(UriTemplateFactory.UriTemplateType.RESOURCE);\r
logger.debug("This is a negative test, and an error message is expected here:");\r
String uriStr = resourceTemplate.buildUri(EMPTY_VALUES_MAP);\r
- Assert.assertTrue(Tools.isBlank(uriStr), "Generated URI string was not blank, but should have been.");\r
logger.debug("Generated URI string = " + uriStr);\r
+ Assert.assertTrue(Tools.isBlank(uriStr), "Generated URI string was not blank, but should have been.");\r
}\r
}\r