package org.collectionspace.services.client;\r
\r
+import java.util.ArrayList;\r
import java.util.List;\r
import java.util.Map;\r
\r
import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
\r
import org.collectionspace.services.OrganizationJAXBSchema;\r
+import org.collectionspace.services.client.test.ServiceRequestType;\r
import org.collectionspace.services.organization.OrganizationsCommon;\r
import org.collectionspace.services.organization.OrgauthoritiesCommon;\r
+import org.jboss.resteasy.client.ClientResponse;\r
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
import org.slf4j.Logger;\r
return multipart;\r
}\r
\r
+ /**\r
+ * Returns an error message indicating that the status code returned by a\r
+ * specific call to a service does not fall within a set of valid status\r
+ * codes for that service.\r
+ *\r
+ * @param serviceRequestType A type of service request (e.g. CREATE, DELETE).\r
+ *\r
+ * @param statusCode The invalid status code that was returned in the response,\r
+ * from submitting that type of request to the service.\r
+ *\r
+ * @return An error message.\r
+ */\r
+ public static String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {\r
+ return "Status code '" + statusCode + "' in response is NOT within the expected set: " +\r
+ requestType.validStatusCodesAsString();\r
+ }\r
+\r
+ public static String extractId(ClientResponse<Response> res) {\r
+ MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+ String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
+ if(logger.isDebugEnabled()){\r
+ logger.info("extractId:uri=" + uri);\r
+ }\r
+ String[] segments = uri.split("/");\r
+ String id = segments[segments.length - 1];\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("id=" + id);\r
+ }\r
+ return id;\r
+ }\r
+ \r
+ public static String createRefName(String displayName) {\r
+ return displayName.replaceAll("\\W", "");\r
+ }\r
+\r
+ public static String createOrgAuthRefName(String orgAuthorityName) {\r
+ return "urn:cspace:org.collectionspace.demo:orgauthority:name("\r
+ +orgAuthorityName+")";\r
+ }\r
+\r
+ public static String createOrganizationRefName(\r
+ String orgAuthRefName, String orgName) {\r
+ return orgAuthRefName+":organization:name("+orgName+")";\r
+ }\r
+\r
}\r
if(logger.isDebugEnabled()){
logger.debug("Import: Create orgAuthority: \"" + orgAuthorityName +"\"");
}
- String baseOrgAuthRefName = createOrgAuthRefName(orgAuthorityName);
+ String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName);
String fullOrgAuthRefName = baseOrgAuthRefName+"'"+orgAuthorityName+"'";
MultipartOutput multipart =
OrgAuthorityClientUtils.createOrgAuthorityInstance(
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
throw new RuntimeException("Could not create enumeration: \""+orgAuthorityName
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
}
if(statusCode != EXPECTED_STATUS_CODE) {
throw new RuntimeException("Unexpected Status when creating enumeration: \""
// Store the ID returned from this create operation
// for additional tests below.
- String newOrgAuthorityId = extractId(res);
+ String newOrgAuthorityId = OrgAuthorityClientUtils.extractId(res);
if(logger.isDebugEnabled()){
logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:"
+newOrgAuthorityId );
// Type of service request being tested
ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
String shortName = orgInfo.get(OrganizationJAXBSchema.SHORT_NAME);
- String refName = createOrganizationRefName(
+ String refName = OrgAuthorityClientUtils.createOrganizationRefName(
orgAuthorityRefName, shortName)+"'"+shortName+"'";
if(logger.isDebugEnabled()){
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
throw new RuntimeException("Could not create Item: \""+shortName
+"\" in orgAuthority: \"" + orgAuthorityRefName
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
}
if(statusCode != EXPECTED_STATUS_CODE) {
throw new RuntimeException("Unexpected Status when creating Item: \""+shortName
+"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode);
}
- return extractId(res);
+ return OrgAuthorityClientUtils.extractId(res);
}
// ---------------------------------------------------------------
// Utility methods used by methods above
// ---------------------------------------------------------------
- /**
- * Returns an error message indicating that the status code returned by a
- * specific call to a service does not fall within a set of valid status
- * codes for that service.
- *
- * @param serviceRequestType A type of service request (e.g. CREATE, DELETE).
- *
- * @param statusCode The invalid status code that was returned in the response,
- * from submitting that type of request to the service.
- *
- * @return An error message.
- */
- protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
- return "Status code '" + statusCode + "' in response is NOT within the expected set: " +
- requestType.validStatusCodesAsString();
- }
-
- protected String extractId(ClientResponse<Response> res) {
- MultivaluedMap<String, Object> mvm = res.getMetadata();
- String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);
- if(logger.isDebugEnabled()){
- logger.debug("extractId:uri=" + uri);
- }
- String[] segments = uri.split("/");
- String id = segments[segments.length - 1];
- if(logger.isDebugEnabled()){
- logger.debug("id=" + id);
- }
- return id;
- }
-
- protected String createOrgAuthRefName(String orgAuthorityName) {
- return "urn:cspace:org.collectionspace.demo:orgauthority:name("
- +orgAuthorityName+")";
- }
-
- protected String createOrganizationRefName(
- String orgAuthRefName, String orgName) {
- return orgAuthRefName+":organization:name("+orgName+")";
- }
-
public static void main(String[] args) {
BasicConfigurator.configure();
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
throw new RuntimeException("Could not create enumeration: \""+orgAuthName\r
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
throw new RuntimeException("Unexpected Status when creating enumeration: \""\r
\r
// Store the ID returned from this create operation\r
// for additional tests below.\r
- String newOrgAuthId = extractId(res);\r
+ String newOrgAuthId = OrgAuthorityClientUtils.extractId(res);\r
logger.info("Import: Created orgAuthority: \"" + orgAuthName +"\" ID:"\r
+newOrgAuthId );\r
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
throw new RuntimeException("Could not create Item: \""+shortName\r
+"\" in orgAuthority: \"" + orgAuthorityRefName\r
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
throw new RuntimeException("Unexpected Status when creating Item: \""+shortName\r
"\", Status:"+ statusCode);\r
}\r
\r
- return extractId(res);\r
+ return OrgAuthorityClientUtils.extractId(res);\r
}\r
\r
\r
int statusCode = res.getStatus();\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
throw new RuntimeException("Could not read list of orgAuthorities: "\r
- + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
throw new RuntimeException("Unexpected Status when reading " +\r
int statusCode = res.getStatus();\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
throw new RuntimeException("Could not read orgAuthority"\r
- + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
throw new RuntimeException("Unexpected Status when reading " +\r
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
throw new RuntimeException("Could not read items in orgAuthority: "\r
- + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
throw new RuntimeException("Unexpected Status when reading " +\r
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
throw new RuntimeException("Could not delete orgAuthority: "\r
- + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
throw new RuntimeException("Unexpected Status when deleting " +\r
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
throw new RuntimeException("Could not delete orgAuthority item: "\r
- + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ + OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
throw new RuntimeException("Unexpected Status when deleting " +\r
return obj;\r
}\r
\r
- /**\r
- * Returns an error message indicating that the status code returned by a\r
- * specific call to a service does not fall within a set of valid status\r
- * codes for that service.\r
- *\r
- * @param serviceRequestType A type of service request (e.g. CREATE, DELETE).\r
- *\r
- * @param statusCode The invalid status code that was returned in the response,\r
- * from submitting that type of request to the service.\r
- *\r
- * @return An error message.\r
- */\r
- protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {\r
- return "Status code '" + statusCode + "' in response is NOT within the expected set: " +\r
- requestType.validStatusCodesAsString();\r
- }\r
-\r
- protected String extractId(ClientResponse<Response> res) {\r
- MultivaluedMap<String, Object> mvm = res.getMetadata();\r
- String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
- if(logger.isDebugEnabled()){\r
- logger.info("extractId:uri=" + uri);\r
- }\r
- String[] segments = uri.split("/");\r
- String id = segments[segments.length - 1];\r
- if(logger.isDebugEnabled()){\r
- logger.debug("id=" + id);\r
- }\r
- return id;\r
- }\r
- \r
- protected String createRefName(String displayName) {\r
- return displayName.replaceAll("\\W", "");\r
- }\r
-\r
public static void main(String[] args) {\r
\r
// Configure logging.\r