import org.testng.Assert;
public class TaxonomyAuthorityClientUtils {
+
private static final Logger logger =
- LoggerFactory.getLogger(TaxonomyAuthorityClientUtils.class);
+ LoggerFactory.getLogger(TaxonomyAuthorityClientUtils.class);
/**
* Creates a new Taxonomy Authority
* @return The PoxPayloadOut payload for the create call
*/
public static PoxPayloadOut createTaxonomyAuthorityInstance(
- String displayName, String shortIdentifier, String headerLabel ) {
+ String displayName, String shortIdentifier, String headerLabel) {
TaxonomyauthorityCommon Taxonomyauthority = new TaxonomyauthorityCommon();
Taxonomyauthority.setDisplayName(displayName);
Taxonomyauthority.setShortIdentifier(shortIdentifier);
PayloadOutputPart commonPart = multipart.addPart(Taxonomyauthority, MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(headerLabel);
- if(logger.isDebugEnabled()){
- logger.debug("to be created, Taxonomyauthority common ",
- Taxonomyauthority, TaxonomyauthorityCommon.class);
+ if (logger.isDebugEnabled()) {
+ logger.debug("to be created, Taxonomyauthority common ",
+ Taxonomyauthority, TaxonomyauthorityCommon.class);
}
return multipart;
/**
* @param taxonomyRefName The proper refName for this authority
- * @param taxonomyInfo the properties for the new Taxonomy. Can pass in one condition
+ * @param taxonInfo the properties for the new Taxonomy. Can pass in one condition
* note and date string.
* @param headerLabel The common part label
* @return The PoxPayloadOut payload for the create call
*/
- public static PoxPayloadOut createTaxonomyInstance(
- String taxonomyAuthRefName, Map<String, String> taxonomyInfo,
- String headerLabel){
- TaxonCommon taxonomy = new TaxonCommon();
- String shortId = taxonomyInfo.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER);
- String displayName = taxonomyInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME);
- taxonomy.setShortIdentifier(shortId);
- String taxonomyRefName = createTaxonomyRefName(taxonomyAuthRefName, shortId, displayName);
- taxonomy.setRefName(taxonomyRefName);
- String value = null;
- value = taxonomyInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
- boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true");
- taxonomy.setDisplayNameComputed(displayNameComputed);
- if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.NAME))!=null)
- taxonomy.setTaxonFullName(value);
- if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.RANK))!=null)
- taxonomy.setTaxonRank(value);
- if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.TERM_STATUS))!=null)
- taxonomy.setTermStatus(value);
+ public static PoxPayloadOut createTaxonInstance(
+ String taxonomyAuthRefName, Map<String, String> taxonInfo,
+ String headerLabel) {
+ TaxonCommon taxon = new TaxonCommon();
+ String shortId = taxonInfo.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER);
+ String displayName = taxonInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME);
+ taxon.setShortIdentifier(shortId);
+ String taxonomyRefName = createTaxonomyRefName(taxonomyAuthRefName, shortId, displayName);
+ taxon.setRefName(taxonomyRefName);
+ String value = null;
+ value = taxonInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
+ boolean displayNameComputed = (value == null) || value.equalsIgnoreCase("true");
+ taxon.setDisplayNameComputed(displayNameComputed);
+ if ((value = (String) taxonInfo.get(TaxonomyJAXBSchema.NAME)) != null) {
+ taxon.setTaxonFullName(value);
+ }
+ if ((value = (String) taxonInfo.get(TaxonomyJAXBSchema.RANK)) != null) {
+ taxon.setTaxonRank(value);
+ }
+ if ((value = (String) taxonInfo.get(TaxonomyJAXBSchema.TERM_STATUS)) != null) {
+ taxon.setTermStatus(value);
+ }
+ // FIXME: Add additional fields in the Taxon record here.
PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
- PayloadOutputPart commonPart = multipart.addPart(taxonomy,
- MediaType.APPLICATION_XML_TYPE);
+ PayloadOutputPart commonPart = multipart.addPart(taxon,
+ MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(headerLabel);
- if(logger.isDebugEnabled()){
- logger.debug("to be created, taxon common ", taxonomy, TaxonCommon.class);
+ if (logger.isDebugEnabled()) {
+ logger.debug("to be created, taxon common ", taxon, TaxonCommon.class);
}
return multipart;
}
-
+
/**
- * @param vcsid CSID of the authority to create a new taxonomy in
+ * @param vcsid CSID of the authority to create a new taxon in
* @param TaxonomyauthorityRefName The refName for the authority
- * @param taxonomyMap the properties for the new Taxonomy
+ * @param taxonMap the properties for the new Taxonomy
* @param client the service client
* @return the CSID of the new item
*/
- public static String createItemInAuthority(String vcsid,
- String TaxonomyauthorityRefName, Map<String,String> taxonomyMap,
- TaxonomyAuthorityClient client ) {
- // Expected status code: 201 Created
- int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
- // Type of service request being tested
- ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
-
- String displayName = taxonomyMap.get(TaxonomyJAXBSchema.DISPLAY_NAME);
- String displayNameComputedStr = taxonomyMap.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
- boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true");
- if( displayName == null ) {
- if(!displayNameComputed) {
- throw new RuntimeException(
- "CreateItem: Must supply a displayName if displayNameComputed is set to false.");
- }
- displayName =
- prepareDefaultDisplayName(
- taxonomyMap.get(TaxonomyJAXBSchema.NAME));
- }
-
- if(logger.isDebugEnabled()){
- logger.debug("Import: Create Item: \""+displayName
- +"\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName +"\"");
- }
- PoxPayloadOut multipart =
- createTaxonomyInstance( TaxonomyauthorityRefName,
- taxonomyMap, client.getItemCommonPartName() );
- String newID = null;
- ClientResponse<Response> res = client.createItem(vcsid, multipart);
+ public static String createItemInAuthority(String vcsid,
+ String TaxonomyauthorityRefName, Map<String, String> taxonMap,
+ TaxonomyAuthorityClient client) {
+ // Expected status code: 201 Created
+ int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+ // Type of service request being tested
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
+ String displayName = taxonMap.get(TaxonomyJAXBSchema.DISPLAY_NAME);
+ String displayNameComputedStr = taxonMap.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
+ boolean displayNameComputed = (displayNameComputedStr == null) || displayNameComputedStr.equalsIgnoreCase("true");
+ if (displayName == null) {
+ if (!displayNameComputed) {
+ throw new RuntimeException(
+ "CreateItem: Must supply a displayName if displayNameComputed is set to false.");
+ }
+ displayName =
+ prepareDefaultDisplayName(
+ taxonMap.get(TaxonomyJAXBSchema.NAME));
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Import: Create Item: \"" + displayName
+ + "\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName + "\"");
+ }
+ PoxPayloadOut multipart =
+ createTaxonInstance(TaxonomyauthorityRefName,
+ taxonMap, client.getItemCommonPartName());
+ String newID = null;
+ ClientResponse<Response> res = client.createItem(vcsid, multipart);
try {
- int statusCode = res.getStatus();
-
- if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
- throw new RuntimeException("Could not create Item: \""
- +taxonomyMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
- +"\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- }
- if(statusCode != EXPECTED_STATUS_CODE) {
- throw new RuntimeException("Unexpected Status when creating Item: \""
- +taxonomyMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
- +"\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName +"\", Status:"+ statusCode);
- }
- newID = extractId(res);
+ int statusCode = res.getStatus();
+
+ if (!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+ throw new RuntimeException("Could not create Item: \""
+ + taxonMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
+ + "\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName
+ + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ }
+ if (statusCode != EXPECTED_STATUS_CODE) {
+ throw new RuntimeException("Unexpected Status when creating Item: \""
+ + taxonMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
+ + "\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName + "\", Status:" + statusCode);
+ }
+ newID = extractId(res);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
- return newID;
+ return newID;
}
public static PoxPayloadOut createTaxonomyInstance(
- String commonPartXML, String headerLabel) throws DocumentException {
+ String commonPartXML, String headerLabel) throws DocumentException {
PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
PayloadOutputPart commonPart = multipart.addPart(commonPartXML,
- MediaType.APPLICATION_XML_TYPE);
+ MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(headerLabel);
- if(logger.isDebugEnabled()){
- logger.debug("to be created, Taxon common ", commonPartXML);
+ if (logger.isDebugEnabled()) {
+ logger.debug("to be created, Taxon common ", commonPartXML);
}
return multipart;
}
-
+
public static String createItemInAuthority(String vcsid,
- String commonPartXML,
- TaxonomyAuthorityClient client ) throws DocumentException {
- // Expected status code: 201 Created
- int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
- // Type of service request being tested
- ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
-
- PoxPayloadOut multipart =
- createTaxonomyInstance(commonPartXML, client.getItemCommonPartName());
- String newID = null;
- ClientResponse<Response> res = client.createItem(vcsid, multipart);
+ String commonPartXML,
+ TaxonomyAuthorityClient client) throws DocumentException {
+ // Expected status code: 201 Created
+ int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+ // Type of service request being tested
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
+ PoxPayloadOut multipart =
+ createTaxonomyInstance(commonPartXML, client.getItemCommonPartName());
+ String newID = null;
+ ClientResponse<Response> res = client.createItem(vcsid, multipart);
try {
- int statusCode = res.getStatus();
-
- if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
- throw new RuntimeException("Could not create Item: \""+commonPartXML
- +"\" in Taxonomyauthority: \"" + vcsid
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- }
- if(statusCode != EXPECTED_STATUS_CODE) {
- throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML
- +"\" in Taxonomyauthority: \"" + vcsid +"\", Status:"+ statusCode);
- }
- newID = extractId(res);
+ int statusCode = res.getStatus();
+
+ if (!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+ throw new RuntimeException("Could not create Item: \"" + commonPartXML
+ + "\" in Taxonomyauthority: \"" + vcsid
+ + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ }
+ if (statusCode != EXPECTED_STATUS_CODE) {
+ throw new RuntimeException("Unexpected Status when creating Item: \"" + commonPartXML
+ + "\" in Taxonomyauthority: \"" + vcsid + "\", Status:" + statusCode);
+ }
+ newID = extractId(res);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
- return newID;
+ return newID;
}
-
+
/**
* Creates the from xml file.
*
* @return new CSID as string
* @throws Exception the exception
*/
- private String createItemInAuthorityFromXmlFile(String vcsid, String commonPartFileName,
- TaxonomyAuthorityClient client) throws Exception {
+ private String createItemInAuthorityFromXmlFile(String vcsid, String commonPartFileName,
+ TaxonomyAuthorityClient client) throws Exception {
byte[] b = FileUtils.readFileToByteArray(new File(commonPartFileName));
String commonPartXML = new String(b);
- return createItemInAuthority(vcsid, commonPartXML, client );
- }
+ return createItemInAuthority(vcsid, commonPartXML, client);
+ }
/**
* Creates the Taxonomyauthority ref name.
* @return the string
*/
public static String createTaxonomyAuthRefName(String shortId, String displaySuffix) {
- String refName = "urn:cspace:org.collectionspace.demo:taxonomyauthority:name("
- +shortId+")";
- if(displaySuffix!=null&&!displaySuffix.isEmpty())
- refName += "'"+displaySuffix+"'";
- return refName;
+ String refName = "urn:cspace:org.collectionspace.demo:taxonomyauthority:name("
+ + shortId + ")";
+ if (displaySuffix != null && !displaySuffix.isEmpty()) {
+ refName += "'" + displaySuffix + "'";
+ }
+ return refName;
}
/**
* @return the string
*/
public static String createTaxonomyRefName(
- String taxonomyAuthRefName, String shortId, String displaySuffix) {
- String refName = taxonomyAuthRefName+":taxon:name("+shortId+")";
- if(displaySuffix!=null&&!displaySuffix.isEmpty())
- refName += "'"+displaySuffix+"'";
- return refName;
+ String taxonomyAuthRefName, String shortId, String displaySuffix) {
+ String refName = taxonomyAuthRefName + ":taxon:name(" + shortId + ")";
+ if (displaySuffix != null && !displaySuffix.isEmpty()) {
+ refName += "'" + displaySuffix + "'";
+ }
+ return refName;
}
public static 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);
+ 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);
+ if (logger.isDebugEnabled()) {
+ logger.debug("id=" + id);
}
return id;
}
-
+
/**
* 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
* @return An error message.
*/
public static String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
- return "Status code '" + statusCode + "' in response is NOT within the expected set: " +
- requestType.validStatusCodesAsString();
+ return "Status code '" + statusCode + "' in response is NOT within the expected set: "
+ + requestType.validStatusCodesAsString();
}
-
-
/**
* Produces a default displayName from the basic name and dates fields.
* @see TaxonomyDocumentModelHandler.prepareDefaultDisplayName() which
* @return
*/
public static String prepareDefaultDisplayName(
- String name ) {
- StringBuilder newStr = new StringBuilder();
- newStr.append(name);
- return newStr.toString();
+ String name) {
+ StringBuilder newStr = new StringBuilder();
+ newStr.append(name);
+ return newStr.toString();
}
-
-
-
}
private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName();
private final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityServiceTest.class);
- @Override
- public String getServicePathComponent() {
- return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT;
- }
-
- @Override
- protected String getServiceName() {
- return TaxonomyAuthorityClient.SERVICE_NAME;
- }
-
+ @Override
+ public String getServicePathComponent() {
+ return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT;
+ }
+
+ @Override
+ protected String getServiceName() {
+ return TaxonomyAuthorityClient.SERVICE_NAME;
+ }
+
public String getItemServicePathComponent() {
return AuthorityClient.ITEMS;
}
-
final String TEST_NAME = "Centaurus pleurexanthemus Green 1832-";
final String TEST_SHORTID = "CentauruspleurexanthemusGreen1832";
// TODO Make rank be a controlled vocab term, assuming that's how we'll implement it.
final String TEST_RANK = "5";
// TODO Make status type be a controlled vocab term.
final String TEST_STATUS = "Approved";
-
/** The known resource id. */
private String knownResourceId = null;
private String knownResourceShortIdentifer = null;
private String knownItemResourceId = null;
private String knownItemResourceShortIdentifer = null;
private String knownContactResourceId = null;
-
/** The n items to create in list. */
private int nItemsToCreateInList = 3;
-
/** The all resource ids created. */
private List<String> allResourceIdsCreated = new ArrayList<String>();
-
/** The all item resource ids created. */
private Map<String, String> allItemResourceIdsCreated =
- new HashMap<String, String>();
-
- protected void setKnownResource( String id, String shortIdentifer,
- String refName ) {
- knownResourceId = id;
- knownResourceShortIdentifer = shortIdentifer;
- knownResourceRefName = refName;
+ new HashMap<String, String>();
+
+ protected void setKnownResource(String id, String shortIdentifer,
+ String refName) {
+ knownResourceId = id;
+ knownResourceShortIdentifer = shortIdentifer;
+ knownResourceRefName = refName;
}
- protected void setKnownItemResource( String id, String shortIdentifer ) {
- knownItemResourceId = id;
- knownItemResourceShortIdentifer = shortIdentifer;
+ protected void setKnownItemResource(String id, String shortIdentifer) {
+ knownItemResourceId = id;
+ knownItemResourceShortIdentifer = shortIdentifer;
}
/* (non-Javadoc)
*/
@Override
protected CollectionSpaceClient getClientInstance() {
- return new TaxonomyAuthorityClient();
+ return new TaxonomyAuthorityClient();
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
*/
@Override
- protected AbstractCommonList getAbstractCommonList(
- ClientResponse<AbstractCommonList> response) {
+ protected AbstractCommonList getAbstractCommonList(
+ ClientResponse<AbstractCommonList> response) {
return response.getEntity(TaxonCommonList.class);
}
@Override
protected PoxPayloadOut createInstance(String identifier) {
- TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
+ TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
String shortId = identifier;
- String displayName = "displayName-" + shortId;
- String baseRefName =
- TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
- PoxPayloadOut multipart =
- TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
- displayName, shortId, client.getCommonPartName());
- return multipart;
+ String displayName = "displayName-" + shortId;
+ String baseRefName =
+ TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
+ PoxPayloadOut multipart =
+ TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
+ displayName, shortId, client.getCommonPartName());
+ return multipart;
}
-
+
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
* @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"create"})
public void create(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Submit the request to the service and store the response.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
String shortId = createIdentifier();
- String displayName = "displayName-" + shortId;
- String baseRefName =
- TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
-
- PoxPayloadOut multipart =
- TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
- displayName, shortId, client.getCommonPartName());
- String newID = null;
+ String displayName = "displayName-" + shortId;
+ String baseRefName =
+ TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
+
+ PoxPayloadOut multipart =
+ TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
+ displayName, shortId, client.getCommonPartName());
+ String newID = null;
ClientResponse<Response> res = client.create(multipart);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- //
- // Specifically:
- // Does it fall within the set of valid status codes?
- // Does it exactly match the expected status code?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
-
- newID = TaxonomyAuthorityClientUtils.extractId(res);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
+
+ newID = TaxonomyAuthorityClientUtils.extractId(res);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
// Store the ID returned from the first resource created
// for additional tests below.
- if (knownResourceId == null){
- setKnownResource( newID, shortId, baseRefName );
+ if (knownResourceId == null) {
+ setKnownResource(newID, shortId, baseRefName);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
*
* @param testName the test name
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"create"}, dependsOnMethods = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"create"}, dependsOnMethods = {"create"})
public void createItem(String testName) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
}
setupCreate();
*/
private String createItemInAuthority(String vcsid, String authRefName) {
- final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
- if(logger.isDebugEnabled()){
+ final String testName = "createItemInAuthority(" + vcsid + "," + authRefName + ")";
+ if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
}
// Submit the request to the service and store the response.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
- Map<String, String> shelf1Map = new HashMap<String,String>();
+ Map<String, String> taxonMap = new HashMap<String, String>();
// TODO Make loc type and status be controlled vocabs.
- shelf1Map.put(TaxonomyJAXBSchema.NAME, TEST_NAME);
- shelf1Map.put(TaxonomyJAXBSchema.RANK, TEST_RANK);
- shelf1Map.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS);
-
+ taxonMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
+ taxonMap.put(TaxonomyJAXBSchema.NAME, TEST_NAME);
+ taxonMap.put(TaxonomyJAXBSchema.RANK, TEST_RANK);
+ taxonMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS);
+ // FIXME: Add additional fields in the Taxon record here.
+
String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
- authRefName, shelf1Map, client );
+ authRefName, taxonMap, client);
// Store the ID returned from the first item resource created
// for additional tests below.
- if (knownItemResourceId == null){
- setKnownItemResource(newID, TEST_SHORTID);
+ if (knownItemResourceId == null) {
+ setKnownItemResource(newID, TEST_SHORTID);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownItemResourceId=" + newID);
}
return newID;
}
-
-
// Failure outcomes
-
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
/* (non-Javadoc)
public void createWithWrongXmlSchema(String testName) throws Exception {
}
-
// ---------------------------------------------------------------
// CRUD tests : CREATE LIST tests
// ---------------------------------------------------------------
// Success outcomes
/* (non-Javadoc)
- * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
- */
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"createList"}, dependsOnGroups = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"createList"}, dependsOnGroups = {"create"})
public void createList(String testName) throws Exception {
for (int i = 0; i < nItemsToCreateInList; i++) {
create(testName);
* @param testName the test name
* @throws Exception the exception
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"createList"}, dependsOnMethods = {"createList"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"createList"}, dependsOnMethods = {"createList"})
public void createItemList(String testName) throws Exception {
// Add items to the initially-created, known parent record.
for (int j = 0; j < nItemsToCreateInList; j++) {
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnGroups = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"read"}, dependsOnGroups = {"create"})
public void read(String testName) throws Exception {
if (logger.isDebugEnabled()) {
}
// Perform setup.
setupRead();
-
+
// Submit the request to the service and store the response.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
- String newID = null;
+ String newID = null;
ClientResponse<String> res = client.read(knownResourceId);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
- try {
- PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
- TaxonomyauthorityCommon taxonomyAuthority =
- (TaxonomyauthorityCommon) extractPart(input,
- client.getCommonPartName(), TaxonomyauthorityCommon.class);
- Assert.assertNotNull(taxonomyAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ //FIXME: remove the following try catch once Aron fixes signatures
+ try {
+ PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
+ TaxonomyauthorityCommon taxonomyAuthority =
+ (TaxonomyauthorityCommon) extractPart(input,
+ client.getCommonPartName(), TaxonomyauthorityCommon.class);
+ Assert.assertNotNull(taxonomyAuthority);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
* @param testName the test name
* @throws Exception the exception
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnGroups = {"create"})
- public void readByName(String testName) throws Exception {
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"read"}, dependsOnGroups = {"create"})
+ public void readByName(String testName) throws Exception {
if (logger.isDebugEnabled()) {
- logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
+ logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
}
// Perform setup.
setupRead();
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
- try {
- PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
- TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
- client.getCommonPartName(), TaxonomyauthorityCommon.class);
- Assert.assertNotNull(taxonomyAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ //FIXME: remove the following try catch once Aron fixes signatures
+ try {
+ PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
+ TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
+ client.getCommonPartName(), TaxonomyauthorityCommon.class);
+ Assert.assertNotNull(taxonomyAuthority);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
-
/**
- * Read item.
- *
- * @param testName the test name
- * @throws Exception the exception
- */
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"read"})
+ * Read item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"read"}, dependsOnMethods = {"read"})
public void readItem(String testName) throws Exception {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Check whether we've received a taxonomy.
- PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
- TaxonCommon taxonomy = (TaxonCommon) extractPart(input,
- client.getItemCommonPartName(), TaxonCommon.class);
- Assert.assertNotNull(taxonomy);
- boolean showFull = true;
- if(showFull && logger.isDebugEnabled()){
- logger.debug(testName + ": returned payload:");
- logger.debug(objectAsXmlString(taxonomy, TaxonCommon.class));
- }
- Assert.assertEquals(taxonomy.getInAuthority(), knownResourceId);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Check whether we've received a taxon.
+ PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
+ String xml = input.getXmlPayload(); // for debugging
+ if (logger.isDebugEnabled()) { // for debugging
+ logger.debug(testName + "#########" + xml);
+ }
+ String cpn = client.getItemCommonPartName(); // for debugging
+ TaxonCommon taxon = (TaxonCommon) extractPart(input,
+ client.getItemCommonPartName(), TaxonCommon.class);
+ Assert.assertNotNull(taxon);
+ boolean showFull = true;
+ if (showFull && logger.isDebugEnabled()) {
+ logger.debug(testName + ": returned payload:");
+ logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
+ }
+ Assert.assertEquals(taxon.getInAuthority(), knownResourceId);
+ } finally {
+ res.releaseConnection();
+ }
}
/**
* @param testName the test name
* @throws Exception the exception
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"readItem", "updateItem"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"readItem", "updateItem"})
public void verifyItemDisplayName(String testName) throws Exception {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Check whether taxonomy has expected displayName.
- PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
- TaxonCommon taxonomy = (TaxonCommon) extractPart(input,
- client.getItemCommonPartName(), TaxonCommon.class);
- Assert.assertNotNull(taxonomy);
- String displayName = taxonomy.getDisplayName();
- // Make sure displayName matches computed form
- String expectedDisplayName =
- TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
- Assert.assertNotNull(displayName, expectedDisplayName);
-
- // Update the shortName and verify the computed name is updated.
- taxonomy.setCsid(null);
- taxonomy.setDisplayNameComputed(true);
- taxonomy.setTaxonFullName("updated-" + TEST_NAME);
- expectedDisplayName =
- TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
-
- // Submit the updated resource to the service and store the response.
- PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
- PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
- commonPart.setLabel(client.getItemCommonPartName());
- res.releaseConnection();
- res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = new PoxPayloadIn(res.getEntity());
- TaxonCommon updatedTaxonomy =
- (TaxonCommon) extractPart(input,
- client.getItemCommonPartName(), TaxonCommon.class);
- Assert.assertNotNull(updatedTaxonomy);
-
- // Verify that the updated resource received the correct data.
- Assert.assertEquals(updatedTaxonomy.getTaxonFullName(), taxonomy.getTaxonFullName(),
- "Updated ForeName in Taxonomy did not match submitted data.");
- // Verify that the updated resource computes the right displayName.
- Assert.assertEquals(updatedTaxonomy.getDisplayName(), expectedDisplayName,
- "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
-
- // Now Update the displayName, not computed and verify the computed name is overriden.
- taxonomy.setDisplayNameComputed(false);
- expectedDisplayName = "TestName";
- taxonomy.setDisplayName(expectedDisplayName);
-
- // Submit the updated resource to the service and store the response.
- output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
- commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
- commonPart.setLabel(client.getItemCommonPartName());
- res.releaseConnection();
- res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = new PoxPayloadIn(res.getEntity());
- updatedTaxonomy =
- (TaxonCommon) extractPart(input,
- client.getItemCommonPartName(), TaxonCommon.class);
- Assert.assertNotNull(updatedTaxonomy);
-
- // Verify that the updated resource received the correct data.
- Assert.assertEquals(updatedTaxonomy.isDisplayNameComputed(), false,
- "Updated displayNameComputed in Taxonomy did not match submitted data.");
- // Verify that the updated resource computes the right displayName.
- Assert.assertEquals(updatedTaxonomy.getDisplayName(),
- expectedDisplayName,
- "Updated DisplayName (not computed) in Taxonomy not stored.");
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Check whether taxon has expected displayName.
+ PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
+ TaxonCommon taxon = (TaxonCommon) extractPart(input,
+ client.getItemCommonPartName(), TaxonCommon.class);
+ Assert.assertNotNull(taxon);
+ String displayName = taxon.getDisplayName();
+ // Make sure displayName matches computed form
+ String expectedDisplayName =
+ TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
+ Assert.assertNotNull(displayName, expectedDisplayName);
+
+ // Update the shortName and verify the computed name is updated.
+ taxon.setCsid(null);
+ taxon.setDisplayNameComputed(true);
+ taxon.setTaxonFullName("updated-" + TEST_NAME);
+ expectedDisplayName =
+ TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
+
+ // Submit the updated resource to the service and store the response.
+ PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
+ PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
+ commonPart.setLabel(client.getItemCommonPartName());
+ res.releaseConnection();
+ res = client.updateItem(knownResourceId, knownItemResourceId, output);
+ statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = new PoxPayloadIn(res.getEntity());
+ TaxonCommon updatedTaxon =
+ (TaxonCommon) extractPart(input,
+ client.getItemCommonPartName(), TaxonCommon.class);
+ Assert.assertNotNull(updatedTaxon);
+
+ // Verify that the updated resource received the correct data.
+ Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
+ "Updated ForeName in Taxonomy did not match submitted data.");
+ // Verify that the updated resource computes the right displayName.
+ Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
+ "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
+
+ // Now Update the displayName, not computed and verify the computed name is overriden.
+ taxon.setDisplayNameComputed(false);
+ expectedDisplayName = "TestName";
+ taxon.setDisplayName(expectedDisplayName);
+
+ // Submit the updated resource to the service and store the response.
+ output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
+ commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
+ commonPart.setLabel(client.getItemCommonPartName());
+ res.releaseConnection();
+ res = client.updateItem(knownResourceId, knownItemResourceId, output);
+ statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = new PoxPayloadIn(res.getEntity());
+ updatedTaxon =
+ (TaxonCommon) extractPart(input,
+ client.getItemCommonPartName(), TaxonCommon.class);
+ Assert.assertNotNull(updatedTaxon);
+
+ // Verify that the updated resource received the correct data.
+ Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
+ "Updated displayNameComputed in Taxonomy did not match submitted data.");
+ // Verify that the updated resource computes the right displayName.
+ Assert.assertEquals(updatedTaxon.getDisplayName(),
+ expectedDisplayName,
+ "Updated DisplayName (not computed) in Taxonomy not stored.");
+ } finally {
+ res.releaseConnection();
+ }
}
/**
* @param testName the test name
* @throws Exception the exception
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"verifyItemDisplayName"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"verifyItemDisplayName"})
public void verifyIllegalItemDisplayName(String testName) throws Exception {
if (logger.isDebugEnabled()) {
}
// Perform setup.
// FIXME: create a setup configuration for this operation.
- setupUpdateWithWrongXmlSchema();
+ setupUpdateWithWrongXmlSchema();
// Submit the request to the service and store the response.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
-
- // Check whether Taxonomy has expected displayName.
- PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
- TaxonCommon taxonomy = (TaxonCommon) extractPart(input,
- client.getItemCommonPartName(), TaxonCommon.class);
- Assert.assertNotNull(taxonomy);
- // Try to Update with computed false and no displayName
- taxonomy.setDisplayNameComputed(false);
- taxonomy.setDisplayName(null);
-
- // Submit the updated resource to the service and store the response.
- PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
- PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
- commonPart.setLabel(client.getItemCommonPartName());
- res.releaseConnection();
- res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
+
+ // Check whether Taxonomy has expected displayName.
+ PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
+ TaxonCommon taxon = (TaxonCommon) extractPart(input,
+ client.getItemCommonPartName(), TaxonCommon.class);
+ Assert.assertNotNull(taxon);
+ // Try to Update with computed false and no displayName
+ taxon.setDisplayNameComputed(false);
+ taxon.setDisplayName(null);
+
+ // Submit the updated resource to the service and store the response.
+ PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
+ PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
+ commonPart.setLabel(client.getItemCommonPartName());
+ res.releaseConnection();
+ res = client.updateItem(knownResourceId, knownItemResourceId, output);
+ statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
-
// Failure outcomes
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"read"}, dependsOnMethods = {"read"})
public void readNonExistent(String testName) {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<String> res = client.read(NON_EXISTENT_ID);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
/**
*
* @param testName the test name
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"readItem"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"read"}, dependsOnMethods = {"readItem"})
public void readItemNonExistent(String testName) {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
- }
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
+ }
// ---------------------------------------------------------------
// CRUD tests : READ_LIST tests
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"readList"}, dependsOnGroups = {"createList", "read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"readList"}, dependsOnGroups = {"createList", "read"})
public void readList(String testName) throws Exception {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
try {
- TaxonomyauthorityCommonList list = res.getEntity();
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Optionally output additional data about list members for debugging.
- boolean iterateThroughList = false;
- if (iterateThroughList && logger.isDebugEnabled()) {
- List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
- list.getTaxonomyauthorityListItem();
- int i = 0;
- for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
- String csid = item.getCsid();
- logger.debug(testName + ": list-item[" + i + "] csid=" +
- csid);
- logger.debug(testName + ": list-item[" + i + "] displayName=" +
- item.getDisplayName());
- logger.debug(testName + ": list-item[" + i + "] URI=" +
- item.getUri());
- readItemList(csid, null);
- i++;
- }
- }
- } finally {
- res.releaseConnection();
- }
+ TaxonomyauthorityCommonList list = res.getEntity();
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Optionally output additional data about list members for debugging.
+ boolean iterateThroughList = false;
+ if (iterateThroughList && logger.isDebugEnabled()) {
+ List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
+ list.getTaxonomyauthorityListItem();
+ int i = 0;
+ for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
+ String csid = item.getCsid();
+ logger.debug(testName + ": list-item[" + i + "] csid="
+ + csid);
+ logger.debug(testName + ": list-item[" + i + "] displayName="
+ + item.getDisplayName());
+ logger.debug(testName + ": list-item[" + i + "] URI="
+ + item.getUri());
+ readItemList(csid, null);
+ i++;
+ }
+ }
+ } finally {
+ res.releaseConnection();
+ }
}
/**
}
readItemList(null, knownResourceShortIdentifer);
}
-
+
/**
* Read item list.
*
// Perform setup.
setupReadList();
-
+
// Submit the request to the service and store the response.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<TaxonCommonList> res = null;
- if(vcsid!= null) {
- res = client.readItemList(vcsid, null, null);
- } else if(shortId!= null) {
- res = client.readItemListForNamedAuthority(shortId, null, null);
+ if (vcsid != null) {
+ res = client.readItemList(vcsid, null, null);
+ } else if (shortId != null) {
+ res = client.readItemListForNamedAuthority(shortId, null, null);
} else {
- Assert.fail("readItemList passed null csid and name!");
+ Assert.fail("readItemList passed null csid and name!");
}
try {
- TaxonCommonList list = res.getEntity();
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- List<TaxonCommonList.TaxonListItem> items =
- list.getTaxonListItem();
- int nItemsReturned = items.size();
- // There will be one item created, associated with a
- // known parent resource, by the createItem test.
- //
- // In addition, there will be 'nItemsToCreateInList'
- // additional items created by the createItemList test,
- // all associated with the same parent resource.
- int nExpectedItems = nItemsToCreateInList + 1;
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": Expected "
- + nExpectedItems +" items; got: "+nItemsReturned);
- }
- Assert.assertEquals(nItemsReturned, nExpectedItems);
-
- int i = 0;
- for (TaxonCommonList.TaxonListItem item : items) {
- Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
- Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
- // Optionally output additional data about list members for debugging.
- boolean showDetails = true;
- if (showDetails && logger.isDebugEnabled()) {
- logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
- item.getCsid());
- logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
- item.getRefName());
- logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
- item.getDisplayName());
- logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
- item.getUri());
- }
- i++;
- }
- } finally {
- res.releaseConnection();
- }
- }
+ TaxonCommonList list = res.getEntity();
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ List<TaxonCommonList.TaxonListItem> items =
+ list.getTaxonListItem();
+ int nItemsReturned = items.size();
+ // There will be one item created, associated with a
+ // known parent resource, by the createItem test.
+ //
+ // In addition, there will be 'nItemsToCreateInList'
+ // additional items created by the createItemList test,
+ // all associated with the same parent resource.
+ int nExpectedItems = nItemsToCreateInList + 1;
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": Expected "
+ + nExpectedItems + " items; got: " + nItemsReturned);
+ }
+ Assert.assertEquals(nItemsReturned, nExpectedItems);
+
+ int i = 0;
+ for (TaxonCommonList.TaxonListItem item : items) {
+ Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
+ Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
+ // Optionally output additional data about list members for debugging.
+ boolean showDetails = true;
+ if (showDetails && logger.isDebugEnabled()) {
+ logger.debug(" " + testName + ": list-item[" + i + "] csid="
+ + item.getCsid());
+ logger.debug(" " + testName + ": list-item[" + i + "] refName="
+ + item.getRefName());
+ logger.debug(" " + testName + ": list-item[" + i + "] displayName="
+ + item.getDisplayName());
+ logger.debug(" " + testName + ": list-item[" + i + "] URI="
+ + item.getUri());
+ }
+ i++;
+ }
+ } finally {
+ res.releaseConnection();
+ }
+ }
// Failure outcomes
// None at present.
-
// ---------------------------------------------------------------
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"update"}, dependsOnGroups = {"read", "readList"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"update"}, dependsOnGroups = {"read", "readList"})
public void update(String testName) throws Exception {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<String> res = client.read(knownResourceId);
try {
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": read status = " + res.getStatus());
- }
- Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
- if(logger.isDebugEnabled()){
- logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
- }
- PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
- TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
- client.getCommonPartName(), TaxonomyauthorityCommon.class);
- Assert.assertNotNull(taxonomyAuthority);
-
- // Update the contents of this resource.
- taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
- taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
- if(logger.isDebugEnabled()){
- logger.debug("to be updated TaxonomyAuthority");
- logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
- }
-
- // Submit the updated resource to the service and store the response.
- PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
- PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
- commonPart.setLabel(client.getCommonPartName());
- res.releaseConnection();
- res = client.update(knownResourceId, output);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = new PoxPayloadIn(res.getEntity());
- TaxonomyauthorityCommon updatedTaxonomyAuthority =
- (TaxonomyauthorityCommon) extractPart(input,
- client.getCommonPartName(), TaxonomyauthorityCommon.class);
- Assert.assertNotNull(updatedTaxonomyAuthority);
-
- // Verify that the updated resource received the correct data.
- Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
- taxonomyAuthority.getDisplayName(),
- "Data in updated object did not match submitted data.");
- } finally {
- res.releaseConnection();
- }
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
+ }
+ PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
+ TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
+ client.getCommonPartName(), TaxonomyauthorityCommon.class);
+ Assert.assertNotNull(taxonomyAuthority);
+
+ // Update the contents of this resource.
+ taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
+ taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
+ if (logger.isDebugEnabled()) {
+ logger.debug("to be updated TaxonomyAuthority");
+ logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
+ }
+
+ // Submit the updated resource to the service and store the response.
+ PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
+ PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
+ commonPart.setLabel(client.getCommonPartName());
+ res.releaseConnection();
+ res = client.update(knownResourceId, output);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = new PoxPayloadIn(res.getEntity());
+ TaxonomyauthorityCommon updatedTaxonomyAuthority =
+ (TaxonomyauthorityCommon) extractPart(input,
+ client.getCommonPartName(), TaxonomyauthorityCommon.class);
+ Assert.assertNotNull(updatedTaxonomyAuthority);
+
+ // Verify that the updated resource received the correct data.
+ Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
+ taxonomyAuthority.getDisplayName(),
+ "Data in updated object did not match submitted data.");
+ } finally {
+ res.releaseConnection();
+ }
}
/**
* @param testName the test name
* @throws Exception the exception
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"update"}, dependsOnMethods = {"update"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"update"}, dependsOnMethods = {"update"})
public void updateItem(String testName) throws Exception {
if (logger.isDebugEnabled()) {
ClientResponse<String> res =
client.readItem(knownResourceId, knownItemResourceId);
try {
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": read status = " + res.getStatus());
- }
- Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
- if(logger.isDebugEnabled()){
- logger.debug("got Taxonomy to update with ID: " +
- knownItemResourceId +
- " in TaxonomyAuthority: " + knownResourceId );
- }
- PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
- TaxonCommon taxonomy = (TaxonCommon) extractPart(input,
- client.getItemCommonPartName(), TaxonCommon.class);
- Assert.assertNotNull(taxonomy);
-
- // Update the contents of this resource.
- taxonomy.setCsid(null);
- taxonomy.setTaxonFullName("updated-" + taxonomy.getTaxonFullName());
- if(logger.isDebugEnabled()){
- logger.debug("to be updated Taxonomy");
- logger.debug(objectAsXmlString(taxonomy,
- TaxonCommon.class));
- }
-
- // Submit the updated resource to the service and store the response.
- PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
- PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
- commonPart.setLabel(client.getItemCommonPartName());
- res.releaseConnection();
- res = client.updateItem(knownResourceId, knownItemResourceId, output);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = new PoxPayloadIn(res.getEntity());
- TaxonCommon updatedTaxonomy =
- (TaxonCommon) extractPart(input,
- client.getItemCommonPartName(), TaxonCommon.class);
- Assert.assertNotNull(updatedTaxonomy);
-
- // Verify that the updated resource received the correct data.
- Assert.assertEquals(updatedTaxonomy.getTaxonFullName(), taxonomy.getTaxonFullName(),
- "Data in updated Taxonomy did not match submitted data.");
- } finally {
- res.releaseConnection();
- }
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("got Taxonomy to update with ID: "
+ + knownItemResourceId
+ + " in TaxonomyAuthority: " + knownResourceId);
+ }
+ PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
+ TaxonCommon taxon = (TaxonCommon) extractPart(input,
+ client.getItemCommonPartName(), TaxonCommon.class);
+ Assert.assertNotNull(taxon);
+
+ // Update the contents of this resource.
+ taxon.setCsid(null);
+ taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
+ if (logger.isDebugEnabled()) {
+ logger.debug("to be updated Taxonomy");
+ logger.debug(objectAsXmlString(taxon,
+ TaxonCommon.class));
+ }
+
+ // Submit the updated resource to the service and store the response.
+ PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
+ PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
+ commonPart.setLabel(client.getItemCommonPartName());
+ res.releaseConnection();
+ res = client.updateItem(knownResourceId, knownItemResourceId, output);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = new PoxPayloadIn(res.getEntity());
+ TaxonCommon updatedTaxon =
+ (TaxonCommon) extractPart(input,
+ client.getItemCommonPartName(), TaxonCommon.class);
+ Assert.assertNotNull(updatedTaxon);
+
+ // Verify that the updated resource received the correct data.
+ Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
+ "Data in updated Taxonomy did not match submitted data.");
+ } finally {
+ res.releaseConnection();
+ }
}
// Failure outcomes
/* (non-Javadoc)
- * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
- */
-@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// The only relevant ID may be the one used in update(), below.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
String displayName = "displayName-NON_EXISTENT_ID";
- PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
- displayName, "nonEx", client.getCommonPartName());
+ PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
+ displayName, "nonEx", client.getCommonPartName());
ClientResponse<String> res =
client.update(NON_EXISTENT_ID, multipart);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
/**
* @param testName the test name
* @throws Exception the exception
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
public void updateNonExistentItem(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Note: The ID used in this 'create' call may be arbitrary.
// The only relevant ID may be the one used in update(), below.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
- Map<String, String> nonexMap = new HashMap<String,String>();
+ Map<String, String> nonexMap = new HashMap<String, String>();
nonexMap.put(TaxonomyJAXBSchema.NAME, TEST_NAME);
nonexMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, "nonEx");
nonexMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS);
- PoxPayloadOut multipart =
- TaxonomyAuthorityClientUtils.createTaxonomyInstance(
- TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
- nonexMap, client.getItemCommonPartName() );
+ PoxPayloadOut multipart =
+ TaxonomyAuthorityClientUtils.createTaxonInstance(
+ TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
+ nonexMap, client.getItemCommonPartName());
ClientResponse<String> res =
client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
// ---------------------------------------------------------------
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
-
// Note: delete sub-resources in ascending hierarchical order,
// before deleting their parents.
-
- /**
- * Delete item.
- *
- * @param testName the test name
- * @throws Exception the exception
- */
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
- groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
+ /**
+ * Delete item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
+ groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
public void deleteItem(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Perform setup.
setupDelete();
- if(logger.isDebugEnabled()){
- logger.debug("parentcsid =" + knownResourceId +
- " itemcsid = " + knownItemResourceId);
+ if (logger.isDebugEnabled()) {
+ logger.debug("parentcsid =" + knownResourceId
+ + " itemcsid = " + knownItemResourceId);
}
// Submit the request to the service and store the response.
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
- ClientResponse<Response> res =
- client.deleteItem(knownResourceId, knownItemResourceId);
+ ClientResponse<Response> res =
+ client.deleteItem(knownResourceId, knownItemResourceId);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"delete"}, dependsOnMethods = {"deleteItem"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"delete"}, dependsOnMethods = {"deleteItem"})
public void delete(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Perform setup.
setupDelete();
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("parentcsid =" + knownResourceId);
}
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<Response> res = client.delete(knownResourceId);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
// Failure outcomes
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"delete"}, dependsOnMethods = {"delete"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"delete"}, dependsOnMethods = {"delete"})
public void deleteNonExistent(String testName) throws Exception {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
/**
*
* @param testName the test name
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"delete"}, dependsOnMethods = {"deleteItem"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ groups = {"delete"}, dependsOnMethods = {"deleteItem"})
public void deleteNonExistentItem(String testName) {
if (logger.isDebugEnabled()) {
TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- } finally {
- res.releaseConnection();
- }
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
}
// ---------------------------------------------------------------
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("testSubmitRequest: url=" + url +
- " status=" + statusCode);
+ if (logger.isDebugEnabled()) {
+ logger.debug("testSubmitRequest: url=" + url
+ + " status=" + statusCode);
}
Assert.assertEquals(statusCode, EXPECTED_STATUS);
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("testItemSubmitRequest: url=" + url +
- " status=" + statusCode);
+ if (logger.isDebugEnabled()) {
+ logger.debug("testItemSubmitRequest: url=" + url
+ + " status=" + statusCode);
}
Assert.assertEquals(statusCode, EXPECTED_STATUS);
// ---------------------------------------------------------------
// Cleanup of resources created during testing
// ---------------------------------------------------------------
-
/**
* Deletes all resources created by tests, after all tests have been run.
*
* at any point during testing, even if some of those resources
* may be expected to be deleted by certain tests.
*/
-
- @AfterClass(alwaysRun=true)
+ @AfterClass(alwaysRun = true)
public void cleanUp() {
String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+ if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping Cleanup phase ...");
}
return;
- }
+ }
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up temporary resources created for testing ...");
}
// Note: Any non-success responses from the delete operation
// below are ignored and not reported.
ClientResponse<Response> res =
- client.deleteItem(parentResourceId, itemResourceId);
- res.releaseConnection();
+ client.deleteItem(parentResourceId, itemResourceId);
+ res.releaseConnection();
}
// Clean up parent resources.
for (String resourceId : allResourceIdsCreated) {
// Note: Any non-success responses from the delete operation
// below are ignored and not reported.
ClientResponse<Response> res = client.delete(resourceId);
- res.releaseConnection();
+ res.releaseConnection();
}
}
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
*/
-
/**
* Returns the root URL for the item service.
*
protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
}
-
-
}