package org.collectionspace.services.client;\r
\r
+import java.io.File;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.List;\r
import javax.ws.rs.core.MultivaluedMap;\r
import javax.ws.rs.core.Response;\r
\r
+import org.apache.commons.io.FileUtils;\r
import org.collectionspace.services.LocationJAXBSchema;\r
import org.collectionspace.services.client.test.ServiceRequestType;\r
import org.collectionspace.services.location.LocationsCommon;\r
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
+import org.testng.Assert;\r
\r
public class LocationAuthorityClientUtils {\r
private static final Logger logger =\r
LoggerFactory.getLogger(LocationAuthorityClientUtils.class);\r
\r
+ /**\r
+ * Creates a new Location Authority\r
+ * @param displayName The displayName used in UI, etc.\r
+ * @param refName The proper refName for this authority\r
+ * @param headerLabel The common part label\r
+ * @return The MultipartOutput payload for the create call\r
+ */\r
public static MultipartOutput createLocationAuthorityInstance(\r
String displayName, String refName, String headerLabel ) {\r
LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon();\r
return multipart;\r
}\r
\r
+ /**\r
+ * @param inAuthority CSID of the authority to create a new location in\r
+ * @param locationRefName The proper refName for this authority\r
+ * @param locationInfo the properties for the new Location\r
+ * @param headerLabel The common part label\r
+ * @return The MultipartOutput payload for the create call\r
+ */\r
public static MultipartOutput createLocationInstance(String inAuthority, \r
String locationRefName, Map<String, String> locationInfo, String headerLabel){\r
LocationsCommon location = new LocationsCommon();\r
return multipart;\r
}\r
\r
+ /**\r
+ * @param vcsid CSID of the authority to create a new location in\r
+ * @param locationAuthorityRefName The refName for the authority\r
+ * @param locationMap the properties for the new Location\r
+ * @param client the service client\r
+ * @return the CSID of the new item\r
+ */\r
public static String createItemInAuthority(String vcsid, \r
String locationAuthorityRefName, Map<String,String> locationMap,\r
LocationAuthorityClient client ) {\r
return extractId(res);\r
}\r
\r
+ public static MultipartOutput createLocationInstance(\r
+ String commonPartXML, String headerLabel){\r
+ MultipartOutput multipart = new MultipartOutput();\r
+ OutputPart commonPart = multipart.addPart(commonPartXML,\r
+ MediaType.APPLICATION_XML_TYPE);\r
+ commonPart.getHeaders().add("label", headerLabel);\r
+\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("to be created, location common ", commonPartXML);\r
+ }\r
+\r
+ return multipart;\r
+ }\r
+ \r
+ public static String createItemInAuthority(String vcsid,\r
+ String commonPartXML,\r
+ LocationAuthorityClient client ) {\r
+ // Expected status code: 201 Created\r
+ int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
+ \r
+ MultipartOutput multipart = \r
+ createLocationInstance( commonPartXML, client.getItemCommonPartName() );\r
+ ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
+\r
+ int statusCode = res.getStatus();\r
+\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not create Item: \""+commonPartXML\r
+ +"\" in locationAuthority: \"" + vcsid\r
+ +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML\r
+ +"\" in locationAuthority: \"" + vcsid +"\", Status:"+ statusCode);\r
+ }\r
+\r
+ return extractId(res);\r
+ }\r
+ \r
+ /**\r
+ * Creates the from xml file.\r
+ *\r
+ * @param fileName the file name\r
+ * @return new CSID as string\r
+ * @throws Exception the exception\r
+ */\r
+ private String createItemInAuthorityFromXmlFile(String vcsid, String commonPartFileName, \r
+ LocationAuthorityClient client) throws Exception {\r
+ byte[] b = FileUtils.readFileToByteArray(new File(commonPartFileName));\r
+ String commonPartXML = new String(b);\r
+ return createItemInAuthority(vcsid, commonPartXML, client );\r
+ } \r
+\r
public static String createLocationAuthRefName(String locationAuthorityName, boolean withDisplaySuffix) {\r
String refName = "urn:cspace:org.collectionspace.demo:locationauthority:name("\r
+locationAuthorityName+")";\r