package org.collectionspace.services.IntegrationTests.xmlreplay;
-import org.collectionspace.services.common.XmlTools;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.common.api.FileTools;
import org.collectionspace.services.common.api.Tools;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import javax.swing.text.Style;
+
import java.io.File;
import java.util.ArrayList;
import java.util.List;
# CollectionSpace loggers and default levels - all loggers using the rootLogger if not otherwise specified
#
log4j.logger.org.collectionspace=WARN
-log4j.logger.org.collectionspace.services.nuxeo.client.java.NuxeoClientEmbedded=TRACE
-log4j.logger.org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl=DEBUG
+log4j.logger.org.collectionspace.services.nuxeo.client.java.NuxeoClientEmbedded=ERROR
+log4j.logger.org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl=ERROR
+log4j.logger.org.collectionspace.services.common.security.SecurityInterceptor=TRACE
#log4j.logger.org.collectionspace.services.nuxeo.client.java=ERROR
#log4j.logger.org.collectionspace.services.common.storage.JDBCTools=ERROR
#log4j.logger.org.collectionspace.services.common.profile.CSpaceFilter=ERROR
import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.client.workflow.WorkflowClient;
-import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.NuxeoBasedResource;
import org.collectionspace.services.common.ResourceMap;
import org.collectionspace.services.client.VocabularyClient;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.common.ResourceMap;
-import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.api.RefName.Authority;
import org.collectionspace.services.common.api.RefNameUtils;
return newID;
}
- /**
- * Read item list.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readList"})
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null);
- }
-
- /**
- * Read item list by authority name.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER);
- }
-
/**
* Read item list.
*
/** The uri path element for items in an authority */
public static String ITEMS = "items"; //used to construct uri's in service paths for authorities.
+ public static final String SHORT_IDENTIFIER = "shortIdentifier";
+ public static final String TERM_DISPLAY_NAME = "termDisplayName";
+ public static final String VOCAB_DISPLAY_NAME = "displayName";
+ public static final String REF_NAME = "refName";
/*
* Basic CRUD operations
-package org.collectionspace.services.common;
+package org.collectionspace.services.client;
import java.io.Closeable;
import java.io.File;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.PayloadInputPart;
import org.collectionspace.services.client.PayloadOutputPart;
+import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.jaxb.AbstractCommonList;
+
+import org.dom4j.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
protected String knownResourceShortIdentifer = null;
protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems" + random.nextInt(1000);
protected String knownAuthorityWithItems = null;
+ protected String knownAuthorityWithItemsIdentifier = null;
protected static final String SAS_IDENTIFIER = "SAS";
protected String knownSASAuthorityResourceId = null;
}
}
}
-
+
/**
* Sync the local with the SAS
*/
dependsOnMethods = {"createItem"})
public void createItemList(String testName) throws Exception {
knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
+ knownAuthorityWithItemsIdentifier = getShortId(knownAuthorityWithItems);
for (int j = 0; j < nItemsToCreateInList; j++) {
createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems, this.getTestAuthorityItemShortId(true));
}
}
+
+ private String getShortId(String authorityCsid) throws Exception {
+ String result = null;
+
+ // Submit the request to the service and store the response.
+ AuthorityClient client = (AuthorityClient) getClientInstance();
+ Response res = client.read(authorityCsid);
+ try {
+ int statusCode = res.getStatus();
+ result = this.extractAuthorityShortId(res);
+ } finally {
+ res.close();
+ }
+
+ return result;
+ }
/**
* Read by name.
return result;
}
+
+ /**
+ * Extracts the short ID from a service request payload
+ *
+ * @param res
+ * @return
+ * @throws Exception
+ */
+ public String extractAuthorityShortId(Response res) throws Exception {
+ String result = null;
+
+ PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
+ Document document = input.getDOMDocument();
+ result = XmlTools.getElementValue(document, "//" + AuthorityClient.SHORT_IDENTIFIER);
+
+ return result;
+ }
+
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readItem"})
}
Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
+ for (AbstractCommonList.ListItem item : items) {
+ String refName = AbstractCommonListUtils.ListItemGetElementValue(
+ item, AuthorityClient.REF_NAME);
+ Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
+ String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
+ AuthorityClient.TERM_DISPLAY_NAME);
+ String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
+ AuthorityClient.VOCAB_DISPLAY_NAME);
+ // One of these names needs to be set.
+ Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
+ }
+
if(logger.isTraceEnabled()){
AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
}
}
}
- @Test(dataProvider = "testName",
- dependsOnMethods = {"createItemList"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"createItemList"})
public void readItemList(String testName) {
readItemListInt(knownAuthorityWithItems, null, testName);
}
- @Test(dataProvider = "testName",
- dependsOnMethods = {"readItem"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"readItemList"})
public void readItemListByName(String testName) {
- readItemListInt(null, READITEMS_SHORT_IDENTIFIER, testName);
+ readItemListInt(null, knownAuthorityWithItemsIdentifier, testName);
}
@Test(dataProvider = "testName",
import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.PayloadInputPart;
+import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadIn;
+import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.TestServiceClient;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.common.api.FileTools;
* @return the object
* @throws Exception the exception
*/
- static protected Object extractPart(PoxPayloadIn input, String label, Class<?> clazz)
- throws Exception {
- Object result = null;
- PayloadInputPart payloadInputPart = input.getPart(label);
- if (payloadInputPart != null) {
- result = payloadInputPart.getBody();
- } else if (logger.isWarnEnabled() == true) {
- logger.warn("Payload part: " + label +
- " is missing from payload: " + input.getName());
- }
- return result;
- }
+ static protected Object extractPart(PoxPayloadIn input, String label, Class<?> clazz) throws Exception {
+ Object result = null;
+
+ PayloadInputPart payloadInputPart = input.getPart(label);
+ if (payloadInputPart != null) {
+ result = payloadInputPart.getBody();
+ } else if (logger.isWarnEnabled() == true) {
+ logger.warn("Payload part: " + label + " is missing from payload: " + input.getName());
+ }
+
+ return result;
+ }
+
+ static protected Object extractPart(PoxPayloadOut output, String label, Class<?> clazz) throws Exception {
+ Object result = null;
+
+ PayloadOutputPart payloadOutPart = output.getPart(label);
+ if (payloadOutPart != null) {
+ result = payloadOutPart.getBody();
+ } else if (logger.isWarnEnabled() == true) {
+ logger.warn("Payload part: " + label + " is missing from payload: " + output.getName());
+ }
+
+ return result;
+ }
+
/**
* Gets the part object.
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;
import org.collectionspace.authentication.AuthN;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.common.api.JEEServerDeployment;
import org.collectionspace.services.common.api.FileTools;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.config.types.PropertyType;
import org.collectionspace.services.nuxeo.client.java.NuxeoConnectorEmbedded;
import org.collectionspace.services.nuxeo.client.java.TenantRepository;
-
import org.apache.commons.io.FileUtils;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.dom4j.Document;
import org.collectionspace.services.client.IRelationsManager;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
-import org.collectionspace.services.common.XmlTools;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.relation.RelationResource;
import org.collectionspace.services.relation.RelationshipType;
import javax.ws.rs.core.MultivaluedMap;
+
import java.util.List;
/**
/** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(SecurityInterceptor.class);
private static final String ACCOUNT_PERMISSIONS = "accounts/*/accountperms";
+ private static final String NUXEO_ADMIN = null;
//
// Use this thread specific member instance to hold our login context with Nuxeo
//
//
// Error messages
//
- private static final String ERROR_NUXEO_LOGOUT = "Attempt to logout when Nuxeo login context was null";
+ private static final String ERROR_NUXEO_LOGOUT = "Attempt to logout when Nuxeo login context was null.";
private static final String ERROR_UNBALANCED_LOGINS = "The number of Logins vs Logouts to the Nuxeo framework was unbalanced.";
private boolean isAnonymousRequest(HttpRequest request, ResourceMethodInvoker resourceMethodInvoker) {
public ServerResponse nuxeoPreProcess(HttpRequest request, ResourceMethodInvoker resourceMethodInvoker)
throws Failure, CSWebApplicationException {
try {
- nuxeoLogin();
+ nuxeoLogin(NUXEO_ADMIN);
} catch (LoginException e) {
String msg = "Unable to login to the Nuxeo framework";
logger.error(msg, e);
logger.error(msg, e);
}
}
-
- private synchronized void nuxeoLogin() throws LoginException {
- //
- // Login as the Nuxeo system/admin user
- //
- nuxeoLogin(null);
- }
private void logLoginContext(LoginContext loginContext) {
logger.trace("CollectionSpace services now logged in to Nuxeo with LoginContext: "
}
}
+ private void logLogoutContext(LoginContext loginContext) {
+ if (loginContext != null) {
+ logger.trace("CollectionSpace services now logging out of Nuxeo with LoginContext: "
+ + loginContext);
+ Subject subject = loginContext.getSubject();
+ Set<Principal> principals = subject.getPrincipals();
+ logger.debug("Nuxeo logout performed with principals: ");
+ for (Principal principal : principals) {
+ logger.debug("[" + principal.getName() + "]");
+ }
+ } else {
+ logger.trace("Logged out.");
+ }
+ }
+
+
/*
* Login to Nuxeo and save the LoginContext instance in a thread local variable
*/
if (threadLocalLoginContext == null) {
threadLocalLoginContext = new ThreadLocal<LoginContext>();
if (logger.isTraceEnabled() == true) {
- logger.trace("Created ThreadLocal instance: "
- + threadLocalLoginContext.getClass().getCanonicalName()
- + " - "
- + threadLocalLoginContext.get());
+ logger.trace(String.format("Thread ID %s: Created new ThreadLocal instance: %s)",
+ Thread.currentThread(), threadLocalLoginContext));
}
}
frameworkLogins++;
threadLocalLoginContext.set(loginContext);
if (logger.isTraceEnabled() == true) {
- logger.trace("Setting ThreadLocal instance: "
- + threadLocalLoginContext.getClass().getCanonicalName()
- + " - "
- + threadLocalLoginContext.get());
+ logger.trace(String.format("Thread ID %s: Logged in with ThreadLocal instance %s - %s ",
+ Thread.currentThread(), threadLocalLoginContext, threadLocalLoginContext.get()));
}
//
// Debug message
if (logger.isDebugEnabled() == true) {
logLoginContext(loginContext);
}
+ } else {
+ //
+ // We're already logged in somehow? This is probably not good. It seems to mean that the LoginContext last
+ // used on this thread is still active -which is a *potential* security vulnerability. However, as of 4/2016, we
+ // use the Nuxeo default "system admin" context for ever request, regardless of the CollectionSpace user making
+ // the request. In short, there's no real security vulnerability here -just bad bookkeeping of logins.
+ //
+ logger.warn(String.format(String.format("Thread ID %s: Alreadyed logged in with ThreadLocal instance %s - %s ",
+ Thread.currentThread(), threadLocalLoginContext, threadLocalLoginContext.get())));
+ frameworkLogins++;
}
}
- public synchronized void nuxeoLogout() throws LoginException {
+ private synchronized void nuxeoLogout() throws LoginException {
LoginContext loginContext = threadLocalLoginContext != null ? threadLocalLoginContext.get() : null;
if (loginContext != null) {
+ if (logger.isDebugEnabled() == true) {
+ logLogoutContext(loginContext);
+ }
loginContext.logout();
+ threadLocalLoginContext.set(null); // We need to clear the login context from this thread, so the next request on this thread has to login again.
+ logLogoutContext(null);
frameworkLogins--;
-
+ if (logger.isDebugEnabled()) {
+ String.format("Framework logins: ", frameworkLogins);
+ }
} else {
logger.warn(ERROR_NUXEO_LOGOUT);
}
- threadLocalLoginContext = null; //Clear the ThreadLocal to void Tomcat warnings associated with thread pools.
+ if (frameworkLogins == 0) {
+ if (threadLocalLoginContext != null) {
+ logger.trace(String.format("Thread ID %s: Clearing ThreadLocal instance %s - %s ",
+ Thread.currentThread(), threadLocalLoginContext, threadLocalLoginContext.get()));
+ }
+ threadLocalLoginContext = null; //Clear the ThreadLocal to void Tomcat warnings associated with thread pools.
+ }
}
}
import org.collectionspace.services.client.PoxPayload;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.common.ReflectionMapper;
-import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.config.ServiceConfigUtils;
logger.error(errMsg);
throw new Exception(errMsg);
}
- //
- // If we couldn't find a repoSession from the service context (or the context was null) then we need to create a new one using
- // just the repo name
- //
if (repoSession == null) {
+ //
+ // If we couldn't find a repoSession from the service context (or the context was null) then we need to create a new one using
+ // just the repository name.
+ //
NuxeoClientEmbedded client = NuxeoConnectorEmbedded.getInstance().getClient();
repoSession = client.openRepository(repoName, timeoutSeconds);
} else {
- if (logger.isDebugEnabled() == true) {
- logger.warn("Reusing the current context's repository session.");
+ if (logger.isTraceEnabled() == true) {
+ logger.trace("Reusing the current context's repository session.");
}
}
log("Reindexing limited to batch: %s", batch + 1);
}
+ //
+ // Commit and close the transaction that was started by our standard request lifecycle.
+ //
boolean tx = TransactionHelper.isTransactionActive();
if (tx) {
TransactionHelper.commitOrRollbackTransaction();
}
log("Reindexing done");
+ //
+ // Start a new transaction so our standard request lifecycle can complete.
+ //
if (tx) {
TransactionHelper.startTransaction();
}
return newID;
}
-
- /**
- * Read item list.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readList"})
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null);
- }
-
- /**
- * Read item list by authority name.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER);
- }
-
+
/**
* Read item list.
*
import java.util.Map;
import java.util.UUID;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
// May at some point instead use
// org.jboss.resteasy.spi.NotFoundException
-import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.document.BadRequestException;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.context.ServiceContextFactory;
import org.collectionspace.services.client.IdClient;
-
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Namespace;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
+
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
+
+import org.collectionspace.services.client.XmlTools;
import org.collectionspace.services.common.IFragmentHandler;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.StoredValuesUriTemplate;
import org.collectionspace.services.common.UriTemplateRegistry;
import org.collectionspace.services.common.UriTemplateRegistryKey;
import org.collectionspace.services.common.XmlSaxFragmenter;
-import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.api.FileTools;
import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
import org.collectionspace.services.common.api.RefName;
}
}
}
-
- /**
- * Read item list.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readList"})
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null);
- }
-
- /**
- * Read item list by authority name.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER);
- }
- /**
- * Read item list.
- *
- * @param vcsid
- * the vcsid
- * @param name
- * the name
- */
- private void readItemList(String vcsid, String shortId) {
- String testName = "readItemList";
-
- // Perform setup.
- setupReadList();
-
- // Submit the request to the service and store the response.
- LocationAuthorityClient client = new LocationAuthorityClient();
- Response res = 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!");
- }
-
- AbstractCommonList list = null;
- try {
- assertStatusCode(res, testName);
- list = res.readEntity(AbstractCommonList.class);
- } finally {
- if (res != null) {
- res.close();
- }
- }
-
- List<AbstractCommonList.ListItem> items = list.getListItem();
- int nItemsReturned = items.size();
- // There will be 'nItemsToCreateInList'
- // items created by the createItemList test,
- // all associated with the same parent resource.
- int nExpectedItems = nItemsToCreateInList;
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": Expected " + nExpectedItems
- + " items; got: " + nItemsReturned);
- }
- Assert.assertEquals(nItemsReturned, nExpectedItems);
-
- for (AbstractCommonList.ListItem item : items) {
- String value = AbstractCommonListUtils.ListItemGetElementValue(
- item, LocationJAXBSchema.REF_NAME);
- Assert.assertTrue((null != value), "Item refName is null!");
- value = AbstractCommonListUtils.ListItemGetElementValue(item,
- LocationJAXBSchema.TERM_DISPLAY_NAME);
- Assert.assertTrue((null != value), "Item termDisplayName is null!");
- }
- if (logger.isTraceEnabled()) {
- AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger,
- testName);
- }
- }
-
@Override
public void delete(String testName) throws Exception {
// Do nothing. See localDelete(). This ensure proper test order.
}
}
- /**
- * Read item list.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readList"})
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null);
- }
-
- /**
- * Read item list by authority name.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER);
- }
-
- /**
- * Read item list.
- *
- * @param vcsid
- * the vcsid
- * @param name
- * the name
- */
- private void readItemList(String vcsid, String shortId) {
- String testName = "readItemList";
-
- // Perform setup.
- setupReadList();
-
- // Submit the request to the service and store the response.
- MaterialAuthorityClient client = new MaterialAuthorityClient();
- Response res = 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!");
- }
-
- AbstractCommonList list = null;
- try {
- assertStatusCode(res, testName);
- list = res.readEntity(AbstractCommonList.class);
- } finally {
- if (res != null) {
- res.close();
- }
- }
-
- List<AbstractCommonList.ListItem> items = list.getListItem();
- int nItemsReturned = items.size();
- // There will be 'nItemsToCreateInList'
- // items created by the createItemList test,
- // all associated with the same parent resource.
- int nExpectedItems = nItemsToCreateInList;
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": Expected " + nExpectedItems
- + " items; got: " + nItemsReturned);
- }
- Assert.assertEquals(nItemsReturned, nExpectedItems);
-
- for (AbstractCommonList.ListItem item : items) {
- String value = AbstractCommonListUtils.ListItemGetElementValue(
- item, MaterialJAXBSchema.REF_NAME);
- Assert.assertTrue((null != value), "Item refName is null!");
- value = AbstractCommonListUtils.ListItemGetElementValue(item,
- MaterialJAXBSchema.MATERIAL_TERM_DISPLAY_NAME);
- Assert.assertTrue((null != value), "Item termDisplayName is null!");
- }
- if (logger.isTraceEnabled()) {
- AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger,
- testName);
- }
- }
-
@Override
public void delete(String testName) throws Exception {
// Do nothing. See localDelete(). This ensure proper test order.
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- String csid = createPerson(personAuthCSID, "Charlie", "Orgcontact", "charlieOrgcontact", null ); // authRefName);
+ String csid = createPerson(personAuthCSID, "Charlie", "Orgcontact", "charlieOrgcontact" + System.currentTimeMillis(), null ); // authRefName);
personIdsCreated.add(csid);
organizationContactPersonRefName1 = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- csid = createPerson(personAuthCSID, "Chelsie", "Contact", "chelsieContact", null ); // authRefName);
+ csid = createPerson(personAuthCSID, "Chelsie", "Contact", "chelsieContact" + System.currentTimeMillis(), null ); // authRefName);
personIdsCreated.add(csid);
organizationContactPersonRefName2 = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
}
@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 ...");
}
- PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
- // Delete Person resource(s) (before PersonAuthority resources).
- for (String resourceId : personIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- personAuthClient.deleteItem(personAuthCSID, resourceId).close();
- }
- // Delete PersonAuthority resource(s).
- // Note: Any non-success response is ignored and not reported.
- if(personAuthCSID!=null) {
- personAuthClient.delete(personAuthCSID).close();
- }
-
+
String parentResourceId;
String itemResourceId;
OrgAuthorityClient client = new OrgAuthorityClient();
client.deleteItem(parentResourceId, itemResourceId).close();
}
+ //
+ // Delete the person authority items we created for the authRefs. Note
+ // that we needed to delete the objects/records referencing these authority items first since
+ // we can't delete authority items that still have records referencing them
+ //
+ PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
+ // Delete Person resource(s) (before PersonAuthority resources).
+ for (String resourceId : personIdsCreated) {
+ // Note: Any non-success responses are ignored and not reported.
+ personAuthClient.deleteItem(personAuthCSID, resourceId).close();
+ }
+
+ // Delete PersonAuthority resource(s).
+ // Note: Any non-success response is ignored and not reported.
+ if (personAuthCSID != null) {
+ personAuthClient.delete(personAuthCSID).close();
+ }
+
// Clean up parent resources.
for (String resourceId : allResourceIdsCreated) {
// Note: Any non-success responses from the delete operation
import org.collectionspace.services.client.PersonAuthorityClientUtils;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.PersonJAXBSchema;
-import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.person.PersonauthoritiesCommon;
import org.collectionspace.services.person.PersonTermGroup;
import org.collectionspace.services.person.PersonTermGroupList;
PoxPayloadOut multipart =
PersonAuthorityClientUtils.createPersonAuthorityInstance(
displayName, shortId, client.getCommonPartName());
+ // Extract the short ID since it might have been randomized by the createPersonAuthRefName() method
+ PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(multipart,
+ client.getCommonPartName(), PersonauthoritiesCommon.class);
+ shortId = personAuthority.getShortIdentifier();
String newID = null;
Response res = client.create(multipart);
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
- /**
- * Read item list override -see immediate superclass.
- */
- @Override
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null, testName);
- }
-
- /**
- * Read item list by authority name.
- */
- @Override
- public void readItemListByName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER, testName);
- }
-
- /**
- * Read item list.
- *
- * @param vcsid the vcsid
- * @param name the name
- */
- private void readItemList(String vcsid, String name, String testName) {
- setupReadList();
- // Submit the request to the service and store the response.
- PersonAuthorityClient client = new PersonAuthorityClient();
- Response res = null;
- if (vcsid != null) {
- res = client.readItemList(vcsid, null, null);
- } else if (name != null) {
- res = client.readItemListForNamedAuthority(name, null, null);
- } else {
- Assert.fail("readItemList passed null csid and name!");
- }
- AbstractCommonList list = null;
- try {
- assertStatusCode(res, testName);
- list = res.readEntity(AbstractCommonList.class);
- } finally {
- if (res != null) {
- res.close();
- }
- }
-
- List<AbstractCommonList.ListItem> items = list.getListItem();
- int nItemsReturned = items.size();
- // There will be 'nItemsToCreateInList'
- // items created by the createItemList test,
- // all associated with the same parent resource.
- int nExpectedItems = nItemsToCreateInList;
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": Expected "
- + nExpectedItems + " items; got: " + nItemsReturned);
- }
- Assert.assertEquals(nItemsReturned, nExpectedItems);
-
- for (AbstractCommonList.ListItem item : items) {
- String value =
- AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.REF_NAME);
- Assert.assertTrue((null != value), "Item refName is null!");
-
- // Per CSPACE-5132, lists items still return a field named displayName,
- // not termDisplayName, for backward compatibility.
- // (The format of list items will change significantly in CSPACE-5134.)
- value =
- AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
- Assert.assertTrue((null != value), "Item termDisplayName is null!");
- }
- if (logger.isTraceEnabled()) {
- AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
- }
- }
-
/**
* Read contact list.
*/
}
}
- /**
- * Read item list.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readList"})
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null);
- }
-
- /**
- * Read item list by authority name.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER);
- }
-
- /**
- * Read item list.
- *
- * @param vcsid
- * the vcsid
- * @param name
- * the name
- */
- private void readItemList(String vcsid, String shortId) {
- String testName = "readItemList";
-
- // Perform setup.
- setupReadList();
-
- // Submit the request to the service and store the response.
- PlaceAuthorityClient client = new PlaceAuthorityClient();
- Response res = 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!");
- }
-
- AbstractCommonList list = null;
- try {
- assertStatusCode(res, testName);
- list = res.readEntity(AbstractCommonList.class);
- } finally {
- if (res != null) {
- res.close();
- }
- }
-
- List<AbstractCommonList.ListItem> items = list.getListItem();
- int nItemsReturned = items.size();
- // There will be 'nItemsToCreateInList'
- // items created by the createItemList test,
- // all associated with the same parent resource.
- int nExpectedItems = nItemsToCreateInList;
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": Expected " + nExpectedItems
- + " items; got: " + nItemsReturned);
- }
- Assert.assertEquals(nItemsReturned, nExpectedItems);
-
- for (AbstractCommonList.ListItem item : items) {
- String value = AbstractCommonListUtils.ListItemGetElementValue(
- item, PlaceJAXBSchema.REF_NAME);
- Assert.assertTrue((null != value), "Item refName is null!");
- value = AbstractCommonListUtils.ListItemGetElementValue(item,
- PlaceJAXBSchema.TERM_DISPLAY_NAME);
- Assert.assertTrue((null != value), "Item termDisplayName is null!");
- }
- if (logger.isTraceEnabled()) {
- AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger,
- testName);
- }
- }
-
@Override
public void delete(String testName) throws Exception {
// Do nothing. See localDelete(). This ensure proper test order.
}
}
- /**
- * Read item list.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readList"})
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null);
- }
-
- /**
- * Read item list by authority name.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER);
- }
-
- /**
- * Read item list.
- *
- * @param vcsid the vcsid
- * @param name the name
- */
- private void readItemList(String vcsid, String shortId) {
- String testName = "readItemList";
-
- // Perform setup.
- setupReadList();
-
- // Submit the request to the service and store the response.
- TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
- Response res = 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!");
- }
- try {
- assertStatusCode(res, testName);
- AbstractCommonList list = res.readEntity(AbstractCommonList.class);
- 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(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, testExpectedStatusCode);
-
- List<AbstractCommonList.ListItem> items = list.getListItem();
- int nItemsReturned = items.size();
- // There will be 'nItemsToCreateInList'
- // items created by the createItemList test,
- // all associated with the same parent resource.
- int nExpectedItems = nItemsToCreateInList;
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": Expected "
- + nExpectedItems + " items; got: " + nItemsReturned);
- }
- Assert.assertEquals(nItemsReturned, nExpectedItems);
-
- for (AbstractCommonList.ListItem item : items) {
- String value =
- AbstractCommonListUtils.ListItemGetElementValue(item, TaxonJAXBSchema.REF_NAME);
- Assert.assertTrue((null != value), "Item refName is null!");
- value =
- AbstractCommonListUtils.ListItemGetElementValue(item, TaxonJAXBSchema.TERM_DISPLAY_NAME);
- Assert.assertTrue((null != value), "Item termDisplayName is null!");
- }
- if (logger.isTraceEnabled()) {
- AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
- }
- } finally {
- res.close();
- }
- }
-
@Override
public void delete(String testName) throws Exception {
// Do nothing. See localDelete(). This ensure proper test order.
import org.collectionspace.services.client.VocabularyClientUtils;
import org.collectionspace.services.vocabulary.VocabulariesCommon;
import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import javax.ws.rs.core.Response;
}
}
}
-
- @Override
- public void createItemList(String testName) throws Exception {
- knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
- for (int j = 0; j < nItemsToCreateInList; j++) {
- createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems, getTestAuthorityItemShortId(true));
- }
- }
-
+
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"CRUDTests"})
public void createWithNonuniqueShortId(String testName) throws Exception {
itemInfo, commonPartName);
return result;
}
+
+ @AfterClass(alwaysRun = true)
+ @Override
+ public void cleanUp() {
+ super.cleanUp();
+ }
}
}
}
- /**
- * Read item list.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readList"})
- public void readItemList(String testName) {
- readItemList(knownAuthorityWithItems, null);
- }
-
- /**
- * Read item list by authority name.
- */
- @Test(dataProvider = "testName", groups = {"readList"},
- dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName(String testName) {
- readItemList(null, READITEMS_SHORT_IDENTIFIER);
- }
-
- /**
- * Read item list.
- *
- * @param vcsid
- * the vcsid
- * @param name
- * the name
- */
- private void readItemList(String vcsid, String shortId) {
- String testName = "readItemList";
-
- // Perform setup.
- setupReadList();
-
- // Submit the request to the service and store the response.
- WorkAuthorityClient client = new WorkAuthorityClient();
- Response res = 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!");
- }
-
- AbstractCommonList list = null;
- try {
- assertStatusCode(res, testName);
- list = res.readEntity(AbstractCommonList.class);
- } finally {
- if (res != null) {
- res.close();
- }
- }
-
- List<AbstractCommonList.ListItem> items = list.getListItem();
- int nItemsReturned = items.size();
- // There will be 'nItemsToCreateInList'
- // items created by the createItemList test,
- // all associated with the same parent resource.
- int nExpectedItems = nItemsToCreateInList;
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": Expected " + nExpectedItems
- + " items; got: " + nItemsReturned);
- }
- Assert.assertEquals(nItemsReturned, nExpectedItems);
-
- for (AbstractCommonList.ListItem item : items) {
- String value = AbstractCommonListUtils.ListItemGetElementValue(
- item, WorkJAXBSchema.REF_NAME);
- Assert.assertTrue((null != value), "Item refName is null!");
- value = AbstractCommonListUtils.ListItemGetElementValue(item,
- WorkJAXBSchema.WORK_TERM_DISPLAY_NAME);
- Assert.assertTrue((null != value), "Item termDisplayName is null!");
- }
- if (logger.isTraceEnabled()) {
- AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger,
- testName);
- }
- }
-
@Override
public void delete(String testName) throws Exception {
// Do nothing. See localDelete(). This ensure proper test order.