From: Richard Millet Date: Sat, 28 Jan 2012 23:32:29 +0000 (+0000) Subject: CSPACE-1685: Removed thousands AND thousands AND thousands of lines of non-DRY testin... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=533def04709beb9daad2e14d5b618913a551e230;p=tmp%2Fjakarta-migration.git CSPACE-1685: Removed thousands AND thousands AND thousands of lines of non-DRY testing code. Sadly, I could have removed more. We need to really try hard *not* to write this kind of code. It's a long-term maint. issue. We were a bit "penny wise, pound foolish" when we created this code. --- diff --git a/build.properties b/build.properties index 65be4151c..4885aef63 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ host=127.0.0.1 #cspace -release.version=2.0 +release.version=2.1 cspace.release=${release.version}-SNAPSHOT cspace.services.release=cspace-services-${cspace.release} domain.cspace=cspace-services diff --git a/pom.xml b/pom.xml index 9cc6592c3..5d8e4c320 100644 --- a/pom.xml +++ b/pom.xml @@ -302,6 +302,13 @@ slf4j-log4j12 1.5.8 + + org.testng + testng + 6.1.1 + + test + javax.ejb ejb diff --git a/services/IntegrationTests/pom.xml b/services/IntegrationTests/pom.xml index de1699a90..7886f8529 100644 --- a/services/IntegrationTests/pom.xml +++ b/services/IntegrationTests/pom.xml @@ -7,7 +7,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.IntegrationTests services.IntegrationTests jar @@ -68,12 +67,11 @@ commons-cli commons-cli - 1.2 org.testng testng - 5.6 + compile org.jboss.resteasy @@ -97,7 +95,6 @@ commons-httpclient commons-httpclient - 3.1 javax.security diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java index ecd4b2fa9..ce402cdf9 100755 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java @@ -42,10 +42,7 @@ import org.collectionspace.services.collectionobject.TitleGroupList; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.intake.IntakesCommon; import org.collectionspace.services.relation.RelationsCommon; -import org.collectionspace.services.relation.RelationshipType; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.InputPart; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; /** * The Class CollectionSpaceIntegrationTest. diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java index 8736756a8..fbc73e5d9 100755 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java @@ -35,9 +35,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java index a184cd7d5..7ef498df0 100755 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java @@ -36,12 +36,11 @@ public class XmlReplayDevTest extends XmlReplayTest { List> list = replay.runMaster(masterFile); logTestForGroup(list, "XmlReplayMasterTest"); } else { - System.out.println("XmlReplayDevTest skipping local dev test "+masterFile+" because it doesn't exist in "+replay.getBaseDir()+". This is expected behavior on a production installation."); + System.out.println("XmlReplayDevTest skipping local dev test " + + masterFile+" because it doesn't exist in " + + replay.getBaseDir() + + ". This is expected behavior on a production installation."); } - - - //used for testing load. - // bigLoop(masterFile); } private void bigLoop(String masterFile){ @@ -57,7 +56,7 @@ public class XmlReplayDevTest extends XmlReplayTest { while (!quitNow) { Thread.yield(); } - System.out.println("DONE. workers: "+MAXWORKERS+" time: "+(System.currentTimeMillis()-start)); + System.out.println("DONE. workers: " + MAXWORKERS+" time: " + (System.currentTimeMillis()-start)); for (Long l: stats){ System.out.println(""+l); } diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplaySelfTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplaySelfTest.java index 7aaac5e47..a4200fe7e 100755 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplaySelfTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplaySelfTest.java @@ -28,7 +28,6 @@ import org.collectionspace.services.IntegrationTests.xmlreplay.XmlReplay; import org.collectionspace.services.IntegrationTests.xmlreplay.XmlReplayTest; import org.testng.annotations.Test; -import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 88f7dfe7f..7cece4828 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -541,7 +541,6 @@ org.testng testng - 5.6 diff --git a/services/JaxRsServiceProvider/src/main/resources/log4j.properties b/services/JaxRsServiceProvider/src/main/resources/log4j.properties index 848dd0718..116cee8f7 100644 --- a/services/JaxRsServiceProvider/src/main/resources/log4j.properties +++ b/services/JaxRsServiceProvider/src/main/resources/log4j.properties @@ -23,11 +23,11 @@ log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n # # CollectionSpace log levels # -log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.collectionspace=INFO #log4j.logger.org.collectionspace.services.common.vocabulary.nuxeo=TRACE log4j.logger.perf.collectionspace=ERROR -log4j.logger.org.nuxeo=ERROR +log4j.logger.org.nuxeo=INFO #log4j.logger.org.nuxeo.ecm.core.storage.sql=TRACE log4j.logger.org.apache=ERROR log4j.logger.httpclient=ERROR diff --git a/services/PerformanceTests/pom.xml b/services/PerformanceTests/pom.xml index eec6d5aef..92ebab5d1 100644 --- a/services/PerformanceTests/pom.xml +++ b/services/PerformanceTests/pom.xml @@ -68,7 +68,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java index 4054a0cab..e1ec5a2c3 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java @@ -38,11 +38,11 @@ import org.slf4j.LoggerFactory; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.util.HttpResponseCodes; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; /** diff --git a/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java b/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java index 52f67e58f..9bbe68de8 100644 --- a/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java +++ b/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java @@ -27,16 +27,18 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; + import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.account.AccountsCommonList; -import org.jboss.resteasy.client.ClientResponse; /** * A AccountClient. * @version $Revision:$ */ -public class AccountClient extends AbstractServiceClientImpl { +public class AccountClient extends AbstractServiceClientImpl { public static final String SERVICE_NAME = "accounts"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; diff --git a/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleClient.java b/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleClient.java index da0cc0b0d..2b771d5b7 100644 --- a/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleClient.java +++ b/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleClient.java @@ -27,17 +27,17 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; -//import org.collectionspace.services.authorization.AccountRolesList; import org.collectionspace.services.authorization.AccountRole; -import org.jboss.resteasy.client.ClientResponse; +import org.collectionspace.services.jaxb.AbstractCommonList; /** * A AccountRoleClient. * @version $Revision:$ */ -public class AccountRoleClient extends AbstractServiceClientImpl { +public class AccountRoleClient extends AbstractServiceClientImpl { public static final String SERVICE_NAME = "accountroles"; @Override @@ -92,7 +92,16 @@ public class AccountRoleClient extends AbstractServiceClientImpl create(String csid, AccountRole accRole) { return getProxy().create(csid, accRole); } - + + /* + * + * Updates on AccountRole entities is not supported. + * + */ + @Override + public ClientResponse update(String csid, AccountRole payload) { + throw new RuntimeException("You cannot update an AccountRole object. You must delete and recreate it instead."); + } /** * @param csid @@ -103,4 +112,18 @@ public class AccountRoleClient extends AbstractServiceClientImpl delete(String csid, AccountRole accRole) { return getProxy().delete(csid, "delete", accRole); } + + /* + * Not supported. + */ + @Override + public ClientResponse create(AccountRole payload) { + // Use the create(String csid, AccountRole accRole) method instead + throw new UnsupportedOperationException(); + } + + @Override + public ClientResponse readList() { + throw new UnsupportedOperationException(); + } } diff --git a/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleProxy.java b/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleProxy.java index 4ad266d31..861612364 100644 --- a/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleProxy.java +++ b/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleProxy.java @@ -30,13 +30,14 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -//import org.collectionspace.services.authorization.AccountRolesList; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.authorization.AccountRole; import org.jboss.resteasy.client.ClientResponse; @@ -46,7 +47,7 @@ import org.jboss.resteasy.client.ClientResponse; @Path("/accounts") @Produces({"application/xml"}) @Consumes({"application/xml"}) -public interface AccountRoleProxy extends CollectionSpaceProxy { +public interface AccountRoleProxy extends CollectionSpaceProxy { //(C)reate @POST @@ -71,6 +72,11 @@ public interface AccountRoleProxy extends CollectionSpaceProxy { @QueryParam("_method") String method, AccountRole accRole); + //(U)pdate + @PUT + @Path("/{csid}/accountroles") + ClientResponse update(@PathParam("csid") String csid, AccountRole role); + //(D)elete @Override @DELETE diff --git a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java index 053da69a6..e006e29f4 100644 --- a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java +++ b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java @@ -22,17 +22,13 @@ */ package org.collectionspace.services.account.client.test; -import java.util.ArrayList; import java.util.Collection; import java.util.Hashtable; import java.util.List; -import javax.ws.rs.core.Response; -//import org.collectionspace.services.authorization.AccountRolesList; import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.account.AccountsCommonList; import org.collectionspace.services.account.AccountListItem; - import org.collectionspace.services.authorization.AccountRole; import org.collectionspace.services.authorization.AccountValue; import org.collectionspace.services.authorization.Role; @@ -46,17 +42,17 @@ import org.collectionspace.services.client.RoleClient; import org.collectionspace.services.client.RoleFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.ServiceRequestType; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; +import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; import org.testng.annotations.Test; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; /** * AccountServiceTest, carries out tests against a @@ -65,18 +61,15 @@ import org.testng.annotations.BeforeClass; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class AccountRoleServiceTest extends AbstractServiceTestImpl { +public class AccountRoleServiceTest extends AbstractServiceTestImpl { /** The Constant logger. */ private final static String CLASS_NAME = AccountRoleServiceTest.class.getName(); private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; private String prebuiltAdminCSID = null; private String prebuiltAdminUserId = "admin@core.collectionspace.org"; /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); /** The acc values. */ private Hashtable accValues = new Hashtable(); /** The role values. */ @@ -137,183 +130,58 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { return new AccountRoleClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) - */ - @Test(dataProvider = "testName") - @Override - public void readPaginatedList(String testName) throws Exception { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - } - // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - testBanner(testName, CLASS_NAME); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. + + public void createList(String testName) throws Exception { + // Do nothing. We do not support list creation in this test yet. + } + + @Override + protected AccountRole createInstance(String commonPartName, + String identifier) { + AccountRole result = null; + + // Use a known Account to associate the AccountRole instance to + AccountValue av = accValues.get("acc-role-user1"); + AccountRole accRole = createAccountRoleInstance(av, + roleValues.values(), true, true); + + result = accRole; + return result; + } + + @Override + public void create(String testName) throws Exception { + setupCreate(); AccountValue av = accValues.get("acc-role-user1"); AccountRole accRole = createAccountRoleInstance(av, roleValues.values(), true, true); AccountRoleClient client = new AccountRoleClient(); ClientResponse res = client.create(av.getAccountId(), accRole); try { - int statusCode = res.getStatus(); - + assertStatusCode(res, testName); + knownResourceId = av.getAccountId(); if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from this create operation - // for additional tests below. - //this is is not important in case of this relationship - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); + logger.debug(testName + ": Created an AccountRole instance for account with knownResourceId=" + + knownResourceId); } } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - } - - //to not cause uniqueness violation for accRole, createList is removed - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - @Override - public void createList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } + } // --------------------------------------------------------------- // CRUD tests : READ tests // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - testBanner(testName, CLASS_NAME); - } - - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - AccountRoleClient client = new AccountRoleClient(); - ClientResponse res = client.read( - accValues.get("acc-role-user1").getAccountId()); - assertStatusCode(res, testName); - try { - AccountRole output = res.getEntity(); - Assert.assertNotNull(output); - } 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) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - testBanner(testName, CLASS_NAME); - } - - // Perform setup. - setupReadNonExistent(); - // Submit the request to the service and store the response. - AccountRoleClient client = new AccountRoleClient(); - ClientResponse res = client.read(this.NON_EXISTENT_ID); - int statusCode = res.getStatus(); - try { - // 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(); - } - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void readNoRelationship(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - testBanner(testName, CLASS_NAME); - } - // Perform setup. setupRead(); @@ -321,17 +189,20 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { AccountRoleClient client = new AccountRoleClient(); ClientResponse res = client.read( accValues.get("acc-role-user2").getAccountId()); - assertStatusCode(res, testName); try { + // Check the status code of the response: does it match + // the expected response(s)? + assertStatusCode(res, testName); AccountRole output = res.getEntity(); - if(logger.isDebugEnabled()) { org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory(); String sOutput = objectAsXmlString(objectFactory.createAccountRole(output), AccountRole.class); logger.debug(testName + " received " + sOutput); } } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -340,56 +211,56 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * After we've performed this setup, our call to "/role/{csid}/accountroles" should contain an AccountRole that has * a list of 1 account -the test user account we associated during setup. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void readRoleAccounts(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - testBanner(testName, CLASS_NAME); - } - /* * Setup a temp local scope for local variables that we need to create the AccountRole for * the setup of the read tests. */ { - setupCreate(); - // Associate "acc-role-user2" with all the roles. AccountValue av = accValues.get("acc-role-user2"); AccountRole accRole = createAccountRoleInstance(av, roleValues.values(), true, true); AccountRoleClient client = new AccountRoleClient(); + setupCreate(); ClientResponse res = client.create(av.getAccountId(), accRole); - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } + } } // // Now read the list of accounts associated with the role "ROLE_CO1". // There should be just the "acc-role-user2" account. // - setupRead(); RoleClient roleClient = new RoleClient(); // Submit the request to the service and store the response. + setupRead(); ClientResponse res = roleClient.readRoleAccounts( roleValues.get("ROLE_CO1").getRoleId()); - assertStatusCode(res, testName); try { + // Check the status code of the response: does it match + // the expected response(s)? + assertStatusCode(res, testName); AccountRole output = res.getEntity(); // Now verify that the role has 2 accounts associate to it. Assert.assertEquals(output.getAccount().size(), 1); - String sOutput = objectAsXmlString(output, AccountRole.class); if(logger.isDebugEnabled()) { logger.debug(testName + " received " + sOutput); } } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -397,15 +268,20 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + // + // There is no such thing as a list of AccountRole resources + // } + + @Override + public void readPaginatedList(String testName) throws Exception { + // + // There is no such thing as a list of AccountRole resources + // + } // Failure outcomes // None at present. @@ -413,169 +289,124 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) - public void update(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + public void update(String testName) throws Exception { + // + // AccountRole entities cannot be updated. You must delete and recreate them + // } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void updateNonExistent(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + // + // AccountRole entities cannot be updated. You must delete and recreate them + // } // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - testBanner(testName, CLASS_NAME); - } - - // Perform setup. - setupDelete(); - // - // Lookup a know account, and delete all of its role relationships + // First, lookup the known account and delete all of its role relationships // AccountRoleClient client = new AccountRoleClient(); + setupRead(); ClientResponse readResponse = client.read( accValues.get("acc-role-user1").getAccountId()); AccountRole toDelete = null; try { + assertStatusCode(readResponse, testName); toDelete = readResponse.getEntity(); - } catch (Throwable e) { - e.printStackTrace(); + Assert.assertNotNull(toDelete); } finally { - readResponse.releaseConnection(); + if (readResponse != null) { + readResponse.releaseConnection(); + } } + setupDelete(); ClientResponse res = client.delete( - toDelete.getAccount().get(0).getAccountId(), toDelete); + toDelete.getAccount().get(0).getAccountId(), toDelete); // delete form #1 try { - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + assertStatusCode(readResponse, testName); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - // - // recreate 'acc-role-user1' account and roles + // Recreate 'acc-role-user1' account and roles for the next test // -// create(testName); - - /* - setupDelete(); - + create(testName); + // - // Lookup a know account, and delete all of its role relationships + // Lookup a known account and delete all of its role relationships again // + setupRead(); readResponse = client.read( - accValues.get("acc-role-user1").getAccountId()); + accValues.get("acc-role-user1").getAccountId()); toDelete = null; try { toDelete = readResponse.getEntity(); - } catch (Throwable e) { - e.printStackTrace(); } finally { - readResponse.releaseConnection(); + if (readResponse != null) { + readResponse.releaseConnection(); + } } - res = client.delete(toDelete.getAccount().get(0).getAccountId()); + setupDelete(); + res = client.delete(toDelete.getAccount().get(0).getAccountId()); // delete form #2 try { int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { res.releaseConnection(); } - */ - } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void deleteLockedAccount(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - testBanner(testName, CLASS_NAME); - } - findPrebuiltAdminAccount(); // Perform setup. - EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode(); - REQUEST_TYPE = ServiceRequestType.DELETE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + testExpectedStatusCode = Response.Status.FORBIDDEN.getStatusCode(); + testRequestType = ServiceRequestType.DELETE; + testSetup(testExpectedStatusCode, testRequestType); AccountRoleClient client = new AccountRoleClient(); ClientResponse res = client.delete(prebuiltAdminCSID); try { int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ + // + // Tests with expected failure outcomes + // + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void deleteNonExistent(String testName) throws Exception { //ignoring this test as the service side returns 200 now even if it does //not find a record in the db + + //FIXME: REM - 1/9/2012, need to find out why a 200 status code is returned and fix this. } // --------------------------------------------------------------- @@ -583,43 +414,14 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWorkflowDeleted(String testName) throws Exception { // Fixme: null test for now, overriding test in base class } - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - * @throws Exception - */ - @Test(dependsOnMethods = {"create"}) - public void testSubmitRequest() throws Exception { //FIXME: REM - This is not testing a submit /accounts/*/accountroles, but instead just to /accounts - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(accValues.get("acc-role-user1").getAccountId()); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + /** * Creates the account role instance. * @@ -665,7 +467,6 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { logger.debug("Cleaning up temporary resources created for testing ..."); } - for (AccountValue pv : accValues.values()) { deleteAccount(pv.getAccountId()); } @@ -683,46 +484,47 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @return the string */ private String createAccount(String userName, String email) { - - if (logger.isDebugEnabled()) { - testBanner("createAccount"); - } - - setupCreate(); - AccountClient accClient = new AccountClient(); AccountsCommon account = AccountFactory.createAccountInstance( userName, userName, userName, email, accClient.getTenantId(), true, false, true, true); + String result = null; + + setupCreate(); ClientResponse res = accClient.create(account); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createAccount: userName=" + userName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreateAccount"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void findPrebuiltAdminAccount() { // Search for the prebuilt admin user and then hold its CSID - if(prebuiltAdminCSID == null) { + if (prebuiltAdminCSID == null) { setupReadList(); AccountClient client = new AccountClient(); ClientResponse res = client.readSearchList(null, this.prebuiltAdminUserId, null); - assertStatusCode(res, "findPrebuiltAdminAccount"); - AccountsCommonList list = res.getEntity(); - - List items = list.getAccountListItem(); - Assert.assertEquals(1, items.size(), "Found more than one Admin account!"); - AccountListItem item = items.get(0); - prebuiltAdminCSID = item.getCsid(); - if (logger.isDebugEnabled()) { - logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID); + try { + assertStatusCode(res, "findPrebuiltAdminAccount"); + AccountsCommonList list = res.getEntity(); + List items = list.getAccountListItem(); + Assert.assertEquals(1, items.size(), "Found more than one Admin account!"); + AccountListItem item = items.get(0); + prebuiltAdminCSID = item.getCsid(); + if (logger.isDebugEnabled()) { + logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } } @@ -733,26 +535,15 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @param accId the acc id */ private void deleteAccount(String accId) { - - if (logger.isDebugEnabled()) { - testBanner("deleteAccount"); - } - - setupDelete(); - AccountClient accClient = new AccountClient(); + setupDelete(); ClientResponse res = accClient.delete(accId); - int statusCode = res.getStatus(); try { - if (logger.isDebugEnabled()) { - logger.debug("deleteAccount: delete account id=" - + accId + " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + assertStatusCode(res, "DeleteAccount"); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -763,26 +554,24 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @return the string */ private String createRole(String roleName) { - if (logger.isDebugEnabled()) { - testBanner("createRole"); - } - setupCreate(); + String result = null; + RoleClient roleClient = new RoleClient(); - Role role = RoleFactory.createRoleInstance(roleName, roleName, //the display name "role for " + roleName, true); + setupCreate(); ClientResponse res = roleClient.create(role); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createRole: name=" + roleName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreateRole"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } /** @@ -791,23 +580,15 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @param roleId the role id */ private void deleteRole(String roleId) { - if (logger.isDebugEnabled()) { - testBanner("deleteRole"); - } setupDelete(); RoleClient roleClient = new RoleClient(); ClientResponse res = roleClient.delete(roleId); - int statusCode = res.getStatus(); try { - if (logger.isDebugEnabled()) { - logger.debug("deleteRole: delete role id=" + roleId - + " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + assertStatusCode(res, "DeleteRole"); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -816,4 +597,43 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { // AccountRoles service is a sub-service of the Account service, so we return Account's service name return AccountClient.SERVICE_NAME; } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } + + @Override + protected AccountRole updateInstance(AccountRole commonPartObject) { + // + // AccountRole entities cannot be updated. You must delete and recreate them + // + return null; + } + + @Override + protected void compareReadInstances(AccountRole original, AccountRole updated) + throws Exception { + // FIXME: Should add field checks here. + } + + @Override + protected void compareUpdatedInstances(AccountRole original, + AccountRole updated) throws Exception { + // + // AccountRole entities cannot be updated. You must delete and recreate them + // + } + + @Override + protected Class getCommonListType() { + return AccountRole.class; + } } diff --git a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java index 57f97765a..28aa2aa13 100644 --- a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java +++ b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java @@ -24,6 +24,7 @@ package org.collectionspace.services.account.client.test; import java.util.List; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; import org.collectionspace.services.client.AccountClient; import org.collectionspace.services.client.CollectionSpaceClient; @@ -35,8 +36,6 @@ import org.collectionspace.services.account.Status; import org.collectionspace.services.client.AccountFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.ServiceRequestType; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; import org.testng.annotations.Test; @@ -51,14 +50,13 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class AccountServiceTest extends AbstractServiceTestImpl { +public class AccountServiceTest extends AbstractServiceTestImpl { /** The Constant logger. */ private final String CLASS_NAME = AccountServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; private String prebuiltAdminCSID = null; private String prebuiltAdminUserId = "admin@core.collectionspace.org"; private String knownUserId = "barney"; @@ -94,17 +92,16 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { + protected AccountsCommonList getCommonList( + ClientResponse response) { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 throw new UnsupportedOperationException(); } + + protected Class getCommonListType() { + return (Class) AccountsCommonList.class; + } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readList"}) @Override public void readPaginatedList(String testName) throws Exception { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 @@ -114,64 +111,16 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - AccountClient client = new AccountClient(); - // Submit the request to the service and store the response. - AccountsCommon account = - createAccountInstance(knownUserId, knownUserId, knownUserPassword, - "barney@dinoland.com", client.getTenantId(), - true, false, true, true); - ClientResponse res = client.create(account); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from this create operation - // for additional tests below. - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - + /** * Creates the for unique user. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void createForUniqueUser(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -186,8 +135,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -197,13 +146,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void createWithInvalidTenant(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -217,10 +161,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); - } /** @@ -229,13 +172,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void createWithoutUser(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -249,8 +187,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -260,13 +198,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void createWithInvalidEmail(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -280,8 +213,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -291,13 +224,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void createWithoutScreenName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -311,8 +239,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -322,13 +250,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void createWithInvalidPassword(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -342,8 +265,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -353,13 +276,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void createWithMostInvalid(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -373,23 +291,16 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } - //to not cause uniqueness violation for account, createList is removed - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ + // + // To avoid uniqueness violations for accounts, createList is removed + // @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. AccountClient client = new AccountClient(); @@ -398,9 +309,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { client.getTenantId(), true, false, true, true); ClientResponse res = client.create(account1); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); allResourceIdsCreated.add(extractId(res)); AccountsCommon account2 = @@ -408,10 +319,10 @@ public class AccountServiceTest extends AbstractServiceTestImpl { client.getTenantId(), true, false, true, true); res = client.create(account2); statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + Assert.assertEquals(statusCode, testExpectedStatusCode); allResourceIdsCreated.add(extractId(res)); AccountsCommon account3 = @@ -419,19 +330,18 @@ public class AccountServiceTest extends AbstractServiceTestImpl { client.getTenantId(), true, false, true, true); res = client.create(account3); statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + Assert.assertEquals(statusCode, testExpectedStatusCode); allResourceIdsCreated.add(extractId(res)); } - // Failure outcomes + // + // Tests with expected failure outcomes + // // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. @@ -453,93 +363,10 @@ public class AccountServiceTest extends AbstractServiceTestImpl { //FIXME: Should this test really be empty? If so, please comment accordingly. } - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - AccountClient client = new AccountClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - AccountsCommon output = (AccountsCommon) res.getEntity(); - Assert.assertNotNull(output); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - AccountClient client = new AccountClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - // --------------------------------------------------------------- // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - AccountClient client = new AccountClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AccountsCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); - } - } /** * Search screen name. @@ -547,13 +374,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void searchScreenName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); @@ -561,45 +383,55 @@ public class AccountServiceTest extends AbstractServiceTestImpl { AccountClient client = new AccountClient(); ClientResponse res = client.readSearchList("tom", null, null); - assertStatusCode(res, testName); - - AccountsCommonList list = res.getEntity(); - Assert.assertEquals(1, list.getAccountListItem().size()); - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); + try { + assertStatusCode(res, testName); + AccountsCommonList list = res.getEntity(); + Assert.assertEquals(1, list.getAccountListItem().size()); + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + printList(testName, list); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } + @Override + @Test(dataProvider = "testName") + public void searchWorkflowDeleted(String testName) throws Exception { + // Fixme: null test for now, overriding test in base class + } + /** * Search user id. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void searchUserId(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. AccountClient client = new AccountClient(); - ClientResponse res = - client.readSearchList(null, "tom", null); - assertStatusCode(res, testName); - - AccountsCommonList list = res.getEntity(); - Assert.assertEquals(1, list.getAccountListItem().size()); - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); + ClientResponse res = client.readSearchList(null, "tom", null); + try { + assertStatusCode(res, testName); + AccountsCommonList list = res.getEntity(); + Assert.assertEquals(1, list.getAccountListItem().size()); + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + printList(testName, list); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } @@ -609,28 +441,27 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void searchEmail(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. AccountClient client = new AccountClient(); - ClientResponse res = - client.readSearchList(null, null, "dinoland"); - assertStatusCode(res, testName); - - AccountsCommonList list = res.getEntity(); - Assert.assertEquals(2, list.getAccountListItem().size()); - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); + ClientResponse res = client.readSearchList(null, null, "dinoland"); + try { + assertStatusCode(res, testName); + AccountsCommonList list = res.getEntity(); + Assert.assertEquals(2, list.getAccountListItem().size()); + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + printList(testName, list); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } @@ -640,85 +471,33 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void searchScreenNameEmail(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. AccountClient client = new AccountClient(); - ClientResponse res = - client.readSearchList("tom", null, "jerry"); - assertStatusCode(res, testName); - - AccountsCommonList list = res.getEntity(); - Assert.assertEquals(1, list.getAccountListItem().size()); - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); + ClientResponse res = client.readSearchList("tom", null, "jerry"); + try { + assertStatusCode(res, testName); + AccountsCommonList list = res.getEntity(); + Assert.assertEquals(1, list.getAccountListItem().size()); + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + printList(testName, list); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } - // Failure outcomes - // None at present. // --------------------------------------------------------------- // CRUD tests : UPDATE tests // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - AccountClient client = new AccountClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - if (logger.isDebugEnabled()) { - logger.debug("got object to update with ID: " + knownResourceId); - } - AccountsCommon accountFound = - (AccountsCommon) res.getEntity(); - Assert.assertNotNull(accountFound); - - //create a new account object to test partial updates - AccountsCommon accountToUpdate = new AccountsCommon(); - accountToUpdate.setCsid(knownResourceId); - accountToUpdate.setUserId(accountFound.getUserId()); - // Update the content of this resource. - accountToUpdate.setEmail("updated-" + accountFound.getEmail()); - if (logger.isDebugEnabled()) { - logger.debug("updated object"); - logger.debug(objectAsXmlString(accountFound, - AccountsCommon.class)); - } - - // Submit the request to the service and store the response. - res = client.update(knownResourceId, accountToUpdate); - assertStatusCode(res, testName); - - AccountsCommon accountUpdated = (AccountsCommon) res.getEntity(); - Assert.assertNotNull(accountUpdated); - - Assert.assertEquals(accountUpdated.getEmail(), - accountToUpdate.getEmail(), - "Data in updated object did not match submitted data."); - } /** * Update password. @@ -726,19 +505,17 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void updatePassword(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); AccountClient client = new AccountClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); if (logger.isDebugEnabled()) { logger.debug(testName + ": got object to update password with ID: " + knownResourceId); @@ -761,7 +538,14 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. res = client.update(knownResourceId, accountToUpdate); - assertStatusCode(res, testName); + 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); AccountsCommon accountUpdated = (AccountsCommon) res.getEntity(); Assert.assertNotNull(accountUpdated); @@ -777,13 +561,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void updatePasswordWithoutUser(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); @@ -806,8 +585,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -818,18 +597,16 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void updateInvalidPassword(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); AccountClient client = new AccountClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); if (logger.isDebugEnabled()) { logger.debug(testName + ": got object to update password with ID: " + knownResourceId); @@ -856,45 +633,53 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); - } private void findPrebuiltAdminAccount() { // Search for the prebuilt admin user and then hold its CSID - if(prebuiltAdminCSID == null) { + if (prebuiltAdminCSID == null) { setupReadList(); AccountClient client = new AccountClient(); ClientResponse res = client.readSearchList(null, this.prebuiltAdminUserId, null); - assertStatusCode(res, "findPrebuiltAdminAccount"); - AccountsCommonList list = res.getEntity(); - List items = list.getAccountListItem(); - Assert.assertEquals(1, items.size(), "Found more than one Admin account!"); - AccountListItem item = items.get(0); - prebuiltAdminCSID = item.getCsid(); - if (logger.isDebugEnabled()) { - logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID); + try { + assertStatusCode(res, "findPrebuiltAdminAccount"); + AccountsCommonList list = res.getEntity(); + List items = list.getAccountListItem(); + Assert.assertEquals(1, items.size(), "Found more than one Admin account!"); + AccountListItem item = items.get(0); + prebuiltAdminCSID = item.getCsid(); + if (logger.isDebugEnabled()) { + logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void verifyMetadataProtection(String testName) throws Exception { findPrebuiltAdminAccount(); // Try to update the metadata - it should just get ignored - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); AccountClient client = new AccountClient(); ClientResponse res = client.read(prebuiltAdminCSID); - assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); + + if (logger.isDebugEnabled()) { + logger.debug("Did get on Admin Account to update with ID: " + prebuiltAdminCSID); + } AccountsCommon accountFound = (AccountsCommon) res.getEntity(); Assert.assertNotNull(accountFound); @@ -913,14 +698,15 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. res = client.update(prebuiltAdminCSID, accountToUpdate); int statusCode = res.getStatus(); - - // Comment below was not understood - but preserved in case it is - // important - during work on CSPACE-4572, which replaced several - // lines of status code checking with the call below. - // + // 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)); // Note that the error is not returned, it is just ignored - assertStatusCode(res, testName); - + Assert.assertEquals(statusCode, testExpectedStatusCode); + AccountsCommon accountUpdated = (AccountsCommon) res.getEntity(); Assert.assertNotNull(accountUpdated); @@ -929,103 +715,104 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void verifyProtectionReadOnly(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupCreate(); // Submit the request to the service and store the response. AccountClient client = new AccountClient(); - AccountsCommon account = - createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com", + AccountsCommon account = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com", client.getTenantId(), true, false, true, true); account.setMetadataProtection(AccountClient.IMMUTABLE); account.setRolesProtection(AccountClient.IMMUTABLE); ClientResponse res = client.create(account); - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from this create operation - // for additional tests below. - String testResourceId = extractId(res); - allResourceIdsCreated.add(testResourceId); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": testResourceId=" + testResourceId); + String testResourceId = null; + try { + assertStatusCode(res, testName); + // Store the ID returned from this create operation + // for additional tests below. + testResourceId = extractId(res); + allResourceIdsCreated.add(testResourceId); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": testResourceId=" + testResourceId); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } + setupRead(); // Submit the request to the service and store the response. ClientResponse accountRes = client.read(testResourceId); - assertStatusCode(accountRes, testName); - - AccountsCommon accountRead = (AccountsCommon) accountRes.getEntity(); - Assert.assertNotNull(accountRead); - String mdProtection = accountRead.getMetadataProtection(); - String rolesProtection = accountRead.getRolesProtection(); - if (logger.isTraceEnabled()) { - logger.trace(testName + ": metadataProtection=" + mdProtection); - logger.trace(testName + ": rolesProtection=" + rolesProtection); + try { + assertStatusCode(accountRes, testName); + AccountsCommon accountRead = (AccountsCommon) accountRes.getEntity(); + Assert.assertNotNull(accountRead); + String mdProtection = accountRead.getMetadataProtection(); + String rolesProtection = accountRead.getRolesProtection(); + if (logger.isTraceEnabled()) { + logger.trace(testName + ": metadataProtection=" + mdProtection); + logger.trace(testName + ": rolesProtection=" + rolesProtection); + } + Assert.assertFalse(account.getMetadataProtection().equals(mdProtection), + "Account allowed create to set the metadata protection flag."); + Assert.assertFalse(account.getRolesProtection().equals(rolesProtection), + "Account allowed create to set the perms protection flag."); + } finally { + if (accountRes != null) { + accountRes.releaseConnection(); + } } - Assert.assertFalse(account.getMetadataProtection().equals(mdProtection), - "Account allowed create to set the metadata protection flag."); - Assert.assertFalse(account.getRolesProtection().equals(rolesProtection), - "Account allowed create to set the perms protection flag."); setupUpdate(); - AccountsCommon accountToUpdate = - createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com", + AccountsCommon accountToUpdate = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com", client.getTenantId(), true, false, true, true); accountToUpdate.setMetadataProtection(AccountClient.IMMUTABLE); accountToUpdate.setRolesProtection(AccountClient.IMMUTABLE); // Submit the request to the service and store the response. accountRes = client.update(testResourceId, accountToUpdate); - assertStatusCode(accountRes, testName); - - AccountsCommon accountUpdated = (AccountsCommon) accountRes.getEntity(); - Assert.assertNotNull(accountUpdated); - if (logger.isDebugEnabled()) { - logger.debug(testName + "Updated account: "); - logger.debug(objectAsXmlString(accountUpdated,AccountsCommon.class)); - } - - Assert.assertFalse( - AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getMetadataProtection()), - "Account allowed update of the metadata protection flag."); - Assert.assertFalse( - AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getRolesProtection()), - "Account allowed update of the roles protection flag."); + try { + assertStatusCode(accountRes, testName); + AccountsCommon accountUpdated = (AccountsCommon) accountRes.getEntity(); + Assert.assertNotNull(accountUpdated); + if (logger.isDebugEnabled()) { + logger.debug(testName + "Updated account: "); + logger.debug(objectAsXmlString(accountUpdated,AccountsCommon.class)); + } + Assert.assertFalse( + AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getMetadataProtection()), + "Account allowed update of the metadata protection flag."); + Assert.assertFalse( + AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getRolesProtection()), + "Account allowed update of the roles protection flag."); + } finally { + if (accountRes != null) { + accountRes.releaseConnection(); + } + } } - - /** * Deactivate. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"updatePasswordWithoutUser"}) + @Test(dataProvider = "testName", dependsOnMethods = {"updatePasswordWithoutUser"}) public void deactivate(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); AccountClient client = new AccountClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); if (logger.isDebugEnabled()) { logger.debug("got object to update with ID: " + knownResourceId); @@ -1047,7 +834,14 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. res = client.update(knownResourceId, accountToUpdate); - assertStatusCode(res, testName); + 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); AccountsCommon accountUpdated = (AccountsCommon) res.getEntity(); Assert.assertNotNull(accountUpdated); @@ -1055,7 +849,6 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(accountUpdated.getStatus(), accountToUpdate.getStatus(), "Data in updated object did not match submitted data."); - } // Failure outcomes @@ -1085,17 +878,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { //FIXME: Should this test really be empty? If so, please comment accordingly. } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"}) + @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"}) public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdateNonExistent(); @@ -1116,9 +901,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } /** @@ -1127,13 +912,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"}) + @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"}) public void updateWrongUser(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupUpdate(); // Submit the request to the service and store the response. @@ -1142,7 +922,10 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // The only relevant ID may be the one used in updateAccount(), below. AccountClient client = new AccountClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); if (logger.isDebugEnabled()) { logger.debug("got object to update with ID: " + knownResourceId); @@ -1166,8 +949,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -1175,101 +958,23 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"testSubmitRequest", "updateWrongUser"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - AccountClient client = new AccountClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - AccountClient client = new AccountClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // Search tests - // --------------------------------------------------------------- @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void searchWorkflowDeleted(String testName) throws Exception { - // Fixme: null test for now, overriding test in base class + public void delete(String testName) throws Exception { + // Do nothing because this test is not ready to delete the "knownResourceId". + // Instead, the method localDelete() will get called later in the dependency chain. The + // method localDelete() has a dependency on the test "updateWrongUser". Once the "updateWrongUser" + // test is run, the localDelete() test/method will get run. The localDelete() test/method in turn + // calls the inherited delete() test/method. } - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - * @throws Exception - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() throws Exception { - - setupRead(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests", "updateWrongUser"}) + public void localDelete(String testName) throws Exception { + // Because of issues with TestNG not allowing @Test annotations on on override methods, + // and because we want the "updateWrongUser" to run before the "delete" test, we need + // this method. This method will call super.delete() after all the dependencies have been + // met. + super.delete(testName); } // --------------------------------------------------------------- @@ -1299,8 +1004,8 @@ public class AccountServiceTest extends AbstractServiceTestImpl { logger.debug(objectAsXmlString(account, AccountsCommon.class)); } + return account; - } @@ -1310,11 +1015,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @param list the list */ - private void printList(String testName, AccountsCommonList list) { + @Override + protected void printList(String testName, AccountsCommonList list) { + AccountsCommonList acl = (AccountsCommonList)list; List items = - list.getAccountListItem(); + acl.getAccountListItem(); int i = 0; - for (AccountListItem item : items) { logger.debug(testName + ": list-item[" + i + "] csid=" + item.getCsid()); @@ -1323,7 +1029,49 @@ public class AccountServiceTest extends AbstractServiceTestImpl { logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri()); i++; - } } + + @Override + protected AccountsCommon createInstance(String commonPartName, + String identifier) { + AccountClient client = new AccountClient(); + AccountsCommon account = + createAccountInstance(knownUserId, knownUserId, knownUserPassword, + "barney@dinoland.com", client.getTenantId(), + true, false, true, true); + return account; + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } + + @Override + protected AccountsCommon updateInstance(AccountsCommon accountsCommon) { + AccountsCommon result = new AccountsCommon(); + + result.setCsid(knownResourceId); + result.setUserId(accountsCommon.getUserId()); + // Update the content of this resource. + result.setEmail("updated-" + accountsCommon.getEmail()); + + return result; + } + + @Override + protected void compareUpdatedInstances(AccountsCommon original, + AccountsCommon updated) throws Exception { + Assert.assertEquals(original.getEmail(), updated.getEmail(), + "Data in updated object did not match submitted data."); + } + } diff --git a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java index 1f6ff4202..98d1b6463 100644 --- a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java +++ b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.UUID; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; -import javax.persistence.NoResultException; import javax.persistence.Persistence; import javax.persistence.Query; @@ -23,7 +22,6 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -42,13 +40,8 @@ public class AccountTest { @BeforeMethod public void init() { - emf = Persistence.createEntityManagerFactory("org.collectionspace.services.account"); - em = emf.createEntityManager(); -// if (logger.isDebugEnabled()) { -// logger.debug("created entity manager"); -// } } @AfterMethod @@ -58,7 +51,6 @@ public class AccountTest { } } - @SuppressWarnings("unchecked") @Test(dataProvider = "testName", dataProviderClass = AccountTest.class) public void create(String testName) throws Exception { diff --git a/services/account/jaxb/pom.xml b/services/account/jaxb/pom.xml index 048ea2106..2e6a47923 100644 --- a/services/account/jaxb/pom.xml +++ b/services/account/jaxb/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.account.jaxb services.account.jaxb @@ -35,6 +34,11 @@ org.jvnet.hyperjaxb3 hyperjaxb3-ejb-runtime + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + org.collectionspace.services org.collectionspace.services.hyperjaxb diff --git a/services/account/jaxb/src/main/resources/accounts_common.xsd b/services/account/jaxb/src/main/resources/accounts_common.xsd index eab81edd6..be8385a37 100644 --- a/services/account/jaxb/src/main/resources/accounts_common.xsd +++ b/services/account/jaxb/src/main/resources/accounts_common.xsd @@ -238,7 +238,7 @@ - + diff --git a/services/account/service/pom.xml b/services/account/service/pom.xml index cfa12508c..e46830595 100644 --- a/services/account/service/pom.xml +++ b/services/account/service/pom.xml @@ -66,7 +66,6 @@ org.testng testng - 5.6 diff --git a/services/acquisition/client/pom.xml b/services/acquisition/client/pom.xml index 7eb1d1c79..0fb156387 100644 --- a/services/acquisition/client/pom.xml +++ b/services/acquisition/client/pom.xml @@ -57,7 +57,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java index e85fad7dd..02eaa352b 100644 --- a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java +++ b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java @@ -1,14 +1,8 @@ package org.collectionspace.services.client; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; - -import org.collectionspace.services.client.workflow.WorkflowClient; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; /** * @version $Revision:$ diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java index 21042281a..a71c0297d 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; @@ -48,7 +47,6 @@ import org.collectionspace.services.acquisition.OwnerList; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -63,7 +61,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 1327 $ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ */ -public class AcquisitionAuthRefsTest extends BaseServiceTest { +public class AcquisitionAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = AcquisitionAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -93,7 +91,7 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -104,11 +102,6 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { // Success outcomes @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void createWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - }; - // Perform setup. testSetup(STATUS_CREATED, ServiceRequestType.CREATE); @@ -139,9 +132,9 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -164,8 +157,8 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); @@ -214,8 +207,8 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } @@ -224,23 +217,26 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - }; - // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. AcquisitionClient acquisitionClient = new AcquisitionClient(); ClientResponse res = acquisitionClient.read(knownResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input, - acquisitionClient.getCommonPartName(), AcquisitionsCommon.class); - Assert.assertNotNull(acquisition); + AcquisitionsCommon acquisition = null; + try { + // Check the status code of the response: does it match + // the expected response(s)? + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + acquisition = (AcquisitionsCommon) extractPart(input, + acquisitionClient.getCommonPartName(), AcquisitionsCommon.class); + Assert.assertNotNull(acquisition); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // Check a couple of fields // Scalar fields @@ -270,17 +266,24 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { for (String refName : sources) { Assert.assertTrue(acquisitionSourcesRefNames.contains(refName)); } - + // // Get the auth refs and check them - ClientResponse res2 = - acquisitionClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - - AuthorityRefList list = res2.getEntity(); + // + ClientResponse res2 = acquisitionClient.getAuthorityRefs(knownResourceId); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + Assert.assertNotNull(list); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()){ logger.debug("Expected " + NUM_AUTH_REFS_EXPECTED + " authority references, found " + numAuthRefsFound); } @@ -408,11 +411,10 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { } acquisition.setAcquisitionSources(acqSourcesList); + AcquisitionClient acquisitionClient = new AcquisitionClient(); PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME); PayloadOutputPart commonPart = - multipart.addPart(acquisition, MediaType.APPLICATION_XML_TYPE); - AcquisitionClient acquisitionClient = new AcquisitionClient(); - commonPart.setLabel(acquisitionClient.getCommonPartName()); + multipart.addPart(acquisitionClient.getCommonPartName(), acquisition); if(logger.isDebugEnabled()){ logger.debug("to be created, acquisition common"); diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java index bdd1804ea..06b8d6c3d 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java @@ -26,12 +26,12 @@ import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AcquisitionClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -54,25 +54,21 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 621 $ * $LastChangedDate: 2009-09-02 16:49:01 -0700 (Wed, 02 Sep 2009) $ */ -public class AcquisitionServiceTest extends AbstractServiceTestImpl { +public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl { /** The logger. */ private final String CLASS_NAME = AcquisitionServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; private final static String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.timestampUTC(); - @Override public String getServicePathComponent() { return AcquisitionClient.SERVICE_PATH_COMPONENT; } - @Override protected String getServiceName() { return AcquisitionClient.SERVICE_NAME; @@ -94,13 +90,8 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -124,9 +115,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -146,8 +137,8 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { for(int i = 0; i < 3; i++){ create(testName); @@ -166,11 +157,8 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // Verify that record creation occurs successfully when there is NO whitespace // between the acquisitionFunding tag and its first child element tag @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"}) + dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"}) public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } String testDataDir = System.getProperty("test-data.fileName"); String newId = createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false); @@ -185,11 +173,8 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // fixes, and also after the issue is resolved, to help detect any regressions. @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"}) + dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"}) public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } String testDataDir = System.getProperty("test-data.fileName"); String newId = createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false); @@ -293,14 +278,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupRead(); @@ -315,9 +295,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input, @@ -347,14 +327,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupReadNonExistent(); @@ -368,9 +343,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -381,28 +356,30 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupReadList(); // Submit the request to the service and store the response. AcquisitionClient client = new AcquisitionClient(); ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + try { + // Check the status code of the response: does it match + // the expected response(s)? + assertStatusCode(res, testName); + AbstractCommonList list = res.getEntity(); + + // Optionally output additional data about list members for debugging. + if (logger.isTraceEnabled() == true){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } - } // Failure outcomes @@ -417,21 +394,19 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupUpdate(); // Retrieve the contents of a resource to update. AcquisitionClient client = new AcquisitionClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); @@ -452,7 +427,13 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { res = client.update(knownResourceId, output); int statusCode = res.getStatus(); - assertStatusCode(res, testName); + // 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); input = new PoxPayloadIn(res.getEntity()); AcquisitionsCommon updatedAcquisition = @@ -615,14 +596,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"update", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupUpdateNonExistent(); @@ -640,9 +616,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -653,14 +629,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "read", "update"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"create", "read", "update"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupDelete(); @@ -674,9 +645,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // Failure outcomes @@ -684,14 +655,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) +// @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, +// dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupDeleteNonExistent(); @@ -705,54 +671,14 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- // Utility tests : tests of code used in tests above // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - * @throws Exception - */ - - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() throws Exception { - testSubmitRequest(knownResourceId); - } - - /** - * Test submit request. - * - * @param resourceId the resource id - * @throws Exception the exception - */ - private void testSubmitRequest(String resourceId) throws Exception { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(resourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- @Override protected PoxPayloadOut createInstance(String identifier) { @@ -867,9 +793,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); String newId = extractId(res); allResourceIdsCreated.add(newId); return newId; @@ -912,20 +838,60 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. AcquisitionClient client = new AcquisitionClient(); ClientResponse res = client.read(csid); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - - if (logger.isDebugEnabled()) { - logger.debug(testName + ": Reading Common part ..."); + AcquisitionsCommon acquisition = null; + try { + // Check the status code of the response: does it match + // the expected response(s)? + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + + if (logger.isDebugEnabled()) { + logger.debug(testName + ": Reading Common part ..."); + } + acquisition = (AcquisitionsCommon) extractPart(input, + client.getCommonPartName(), AcquisitionsCommon.class); + Assert.assertNotNull(acquisition); + } finally { + if (res != null) { + res.releaseConnection(); + } } - AcquisitionsCommon acquisition = - (AcquisitionsCommon) extractPart(input, - client.getCommonPartName(), AcquisitionsCommon.class); - Assert.assertNotNull(acquisition); return acquisition; } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected AcquisitionsCommon updateInstance( + AcquisitionsCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(AcquisitionsCommon original, + AcquisitionsCommon updated) throws Exception { + // TODO Auto-generated method stub + + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } } diff --git a/services/authorization-mgt/client/pom.xml b/services/authorization-mgt/client/pom.xml index 87683a93f..201c23b24 100644 --- a/services/authorization-mgt/client/pom.xml +++ b/services/authorization-mgt/client/pom.xml @@ -62,7 +62,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java index 0fc1fbe47..ba252373f 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java @@ -37,7 +37,7 @@ import org.collectionspace.services.authorization.perms.PermissionsList; * @version $Revision:$ */ -public class PermissionClient extends AbstractServiceClientImpl { +public class PermissionClient extends AbstractServiceClientImpl { public static final String SERVICE_NAME = "authorization/permissions"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java index 79dd99f82..885572ef9 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java @@ -35,7 +35,7 @@ import org.collectionspace.services.authorization.PermissionRole; * @version $Revision:$ */ -public class PermissionRoleClient extends AbstractServiceClientImpl { +public class PermissionRoleClient extends AbstractServiceClientImpl { @Override public String getServiceName() { throw new UnsupportedOperationException(); //FIXME: REM - http://issues.collectionspace.org/browse/CSPACE-3497 @@ -104,4 +104,20 @@ public class PermissionRoleClient extends AbstractServiceClientImpl delete(String csid, PermissionRole permRole) { return getProxy().delete(csid, "delete", permRole); } + + @Override + public ClientResponse create(PermissionRole payload) { + throw new UnsupportedOperationException(); //method not supported nor needed + } + + @Override + public ClientResponse update(String csid, + PermissionRole payload) { + throw new UnsupportedOperationException(); //method not supported nor needed + } + + @Override + public ClientResponse readList() { + throw new UnsupportedOperationException(); //method not supported nor needed + } } diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java index 78d1f48de..6f477b8e2 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java @@ -39,7 +39,7 @@ import org.jboss.resteasy.client.ClientResponse; * @version $Revision:$ */ -public class RoleClient extends AbstractServiceClientImpl { +public class RoleClient extends AbstractServiceClientImpl { public static final String SERVICE_NAME = "authorization/roles"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RolePermissionClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RolePermissionClient.java index ad6f536a4..2633bca5c 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RolePermissionClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RolePermissionClient.java @@ -27,14 +27,8 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; - - -import org.collectionspace.services.authorization.PermissionRole; -import org.jboss.resteasy.client.ProxyFactory; -import org.jboss.resteasy.plugins.providers.RegisterBuiltin; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor; -import org.jboss.resteasy.spi.ResteasyProviderFactory; +import org.collectionspace.services.authorization.PermissionRole; // TODO: Auto-generated Javadoc /** @@ -42,7 +36,7 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; * @version $Revision:$ */ -public class RolePermissionClient extends AbstractServiceClientImpl { +public class RolePermissionClient extends AbstractServiceClientImpl { @Override public String getServiceName() { throw new UnsupportedOperationException(); //FIXME: REM - http://issues.collectionspace.org/browse/CSPACE-3498 @@ -109,4 +103,20 @@ public class RolePermissionClient extends AbstractServiceClientImpl delete(String csid, PermissionRole permRole) { return getProxy().delete(csid, "delete", permRole); } + + @Override + public ClientResponse create(PermissionRole payload) { + throw new UnsupportedOperationException(); //method not supported nor needed + } + + @Override + public ClientResponse update(String csid, + PermissionRole payload) { + throw new UnsupportedOperationException(); //method not supported nor needed + } + + @Override + public ClientResponse readList() { + throw new UnsupportedOperationException(); //method not supported nor needed + } } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java index cf6a61760..39804c57f 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java @@ -28,7 +28,6 @@ import java.util.Hashtable; import java.util.List; import javax.ws.rs.core.Response; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.authorization.perms.EffectType; import org.collectionspace.services.authorization.perms.Permission; import org.collectionspace.services.authorization.perms.PermissionAction; @@ -65,16 +64,14 @@ import org.testng.annotations.BeforeClass; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class PermissionRoleServiceTest extends AbstractServiceTestImpl { +public class PermissionRoleServiceTest extends AbstractServiceTestImpl { /** The Constant logger. */ private final static String CLASS_NAME = PermissionRoleServiceTest.class.getName(); private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME); + // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); final private static String TEST_MARKER = "_PermissionRoleServiceTest"; final private static String TEST_SERVICE_NAME = "fakeservice"; final private static String NO_REL_SUFFIX = "-no-rel"; @@ -152,8 +149,8 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { + protected PermissionRole getCommonList( + ClientResponse response) { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 throw new UnsupportedOperationException(); } @@ -161,7 +158,6 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) */ - @Test(dataProvider = "testName") @Override public void readPaginatedList(String testName) throws Exception { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 @@ -175,13 +171,8 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -200,14 +191,11 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - // Store the ID returned from this create operation - // for additional tests below. - //this is is not important in case of this relationship - knownResourceId = extractId(res); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + knownResourceId = extractId(res); //This is meaningless in this test, see getKnowResourceId() method for details if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -223,8 +211,8 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { //Should this really be empty? } @@ -264,13 +252,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); @@ -280,7 +264,17 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { try { res = client.read( permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId()); - assertStatusCode(res, testName); + 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); + PermissionRole output = (PermissionRole) res.getEntity(); Assert.assertNotNull(output); } finally { @@ -298,10 +292,6 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadNonExistent(); @@ -317,9 +307,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { res.releaseConnection(); @@ -327,13 +317,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { } } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void readNoRelationship(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); @@ -343,8 +329,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { try { res = client.read( permValues.get(TEST_SERVICE_NAME + TEST_MARKER + NO_REL_SUFFIX).getPermissionId()); + // Check the status code of the response: does it match + // the expected response(s)? assertStatusCode(res, testName); - PermissionRole output = (PermissionRole) res.getEntity(); String sOutput = objectAsXmlString(output, PermissionRole.class); @@ -367,8 +354,8 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { //Should this really be empty? } @@ -383,8 +370,8 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read", "readList", "readNonExistent"}) public void update(String testName) throws Exception { //Should this really be empty? } @@ -420,8 +407,8 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { //Should this really be empty? } @@ -434,13 +421,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDelete(); @@ -461,9 +444,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { toDelete.getPermission().get(0).getPermissionId(), toDelete); try { int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { res.releaseConnection(); @@ -491,9 +474,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { res = client.delete(toDelete.getPermission().get(0).getPermissionId()); try { int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { res.releaseConnection(); } @@ -521,36 +504,11 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { // Fixme: null test for now, overriding test in base class } - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - * @throws Exception - */ - @Test(dependsOnMethods = {"create"}) - public void testSubmitRequest() throws Exception { //FIXME: REM - This is testing /permissions not /permissions/permroles - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId()); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - + @Override + protected String getKnowResourceId() { + return permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId(); } - + // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -613,7 +571,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { */ private String createPermission(String resName, EffectType effect) { if (logger.isDebugEnabled()) { - logger.debug(testBanner("createPermission")); + logger.debug(getTestBanner("createPermission")); } setupCreate(); PermissionClient permClient = new PermissionClient(); @@ -631,9 +589,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { logger.debug("createPermission: resName=" + resName + " status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); id = extractId(res); } finally { if (res != null) { @@ -650,7 +608,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { */ private void deletePermission(String permId) { if (logger.isDebugEnabled()) { - logger.debug(testBanner("deletePermission")); + logger.debug(getTestBanner("deletePermission")); } setupDelete(); PermissionClient permClient = new PermissionClient(); @@ -662,9 +620,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { logger.debug("deletePermission: delete permission id=" + permId + " status=" + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { res.releaseConnection(); } @@ -679,7 +637,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { */ private String createRole(String roleName) { if (logger.isDebugEnabled()) { - logger.debug(testBanner("createRole")); + logger.debug(getTestBanner("createRole")); } setupCreate(); RoleClient roleClient = new RoleClient(); @@ -696,9 +654,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { logger.debug("createRole: name=" + roleName + " status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); id = extractId(res); } finally { @@ -714,7 +672,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { */ private void deleteRole(String roleId) { if (logger.isDebugEnabled()) { - logger.debug(testBanner("deleteRole")); + logger.debug(getTestBanner("deleteRole")); } setupDelete(); RoleClient roleClient = new RoleClient(); @@ -726,12 +684,48 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { logger.debug("deleteRole: delete role id=" + roleId + " status=" + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { res.releaseConnection(); } } - + + @Override + protected PermissionRole createInstance(String commonPartName, + String identifier) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected PermissionRole updateInstance(PermissionRole commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(PermissionRole original, + PermissionRole updated) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + protected Class getCommonListType() { + return PermissionRole.class; + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java index 01fcbf700..11b044f82 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java @@ -36,7 +36,6 @@ import org.collectionspace.services.authorization.perms.PermissionsList; import org.collectionspace.services.client.PermissionFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.ServiceRequestType; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; @@ -52,15 +51,14 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class PermissionServiceTest extends AbstractServiceTestImpl { +public class PermissionServiceTest extends AbstractServiceTestImpl { /** The Constant logger. */ private final static String CLASS_NAME = PermissionServiceTest.class.getName(); private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; private String knownResource = "accounts-test"; @Override @@ -84,78 +82,20 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { return new PermissionClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); - } - /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) */ - @Test(dataProvider = "testName") +// @Test(dataProvider = "testName") @Override public void readPaginatedList(String testName) throws Exception { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 } - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - List actions = PermissionFactory.createDefaultActions(); - Permission permission = createPermissionInstance(knownResource, - "default permissions for account", - actions, - EffectType.PERMIT, - true, - true, - true); - PermissionClient client = new PermissionClient(); - ClientResponse res = client.create(permission); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from this create operation - // for additional tests below. - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } + protected String getKnowResourceIdentifier() { + return knownResource; } - + /** * Creates the without resource name. * @@ -163,12 +103,8 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + dependsOnMethods = {"CRUDTests"}) public void createWithoutResourceName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -187,265 +123,63 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } - //to not cause uniqueness violation for permission, createList is removed - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupCreate(); - // Submit the request to the service and store the response. - List actions = PermissionFactory.createDefaultActions(); - Permission permission1 = createPermissionInstance("test-objects", - "default permissions for test-objects", - actions, - EffectType.PERMIT, - true, - true, - true); - PermissionClient client = new PermissionClient(); - ClientResponse res = client.create(permission1); - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - allResourceIdsCreated.add(extractId(res)); - - Permission permission2 = createPermissionInstance("test-acquisitions", - "default permissions for test-acquisitions", - actions, - EffectType.PERMIT, - true, - true, - true); - res = client.create(permission2); - statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - allResourceIdsCreated.add(extractId(res)); - - Permission permission3 = createPermissionInstance("test-ids", - "default permissions for id service", - actions, - EffectType.PERMIT, - true, - true, - true); - res = client.create(permission3); - statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - allResourceIdsCreated.add(extractId(res)); - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - PermissionClient client = new PermissionClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - Permission output = (Permission) res.getEntity(); - Assert.assertNotNull(output); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - PermissionClient client = new PermissionClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - PermissionClient client = new PermissionClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - PermissionsList list = res.getEntity(PermissionsList.class); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); - } - } - /** * Search resource name. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void searchResourceName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. PermissionClient client = new PermissionClient(); ClientResponse res = client.readSearchList("acquisition"); - assertStatusCode(res, testName); - PermissionsList list = res.getEntity(PermissionsList.class); - int EXPECTED_ITEMS = 5; //seeded permissions - int actual = list.getPermission().size(); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": received = " + actual - + " expected=" + EXPECTED_ITEMS); - } - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if ((iterateThroughList || (EXPECTED_ITEMS != list.getPermission().size())) - && logger.isDebugEnabled()) { - printList(testName, list); + try { + assertStatusCode(res, testName); + PermissionsList list = res.getEntity(PermissionsList.class); + int EXPECTED_ITEMS = 4; //seeded permissions + int actual = list.getPermission().size(); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": received = " + actual + + " expected=" + EXPECTED_ITEMS); + } + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if ((iterateThroughList || (EXPECTED_ITEMS != list.getPermission().size())) + && logger.isDebugEnabled()) { + printList(testName, list); + } + Assert.assertEquals(list.getPermission().size(), EXPECTED_ITEMS); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertEquals(list.getPermission().size(), EXPECTED_ITEMS); - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - Permission permToUpdate = new Permission(); - permToUpdate.setCsid(knownResourceId); - permToUpdate.setResourceName(knownResource); - // Update the content of this resource. - permToUpdate.setDescription("updated description"); - if (logger.isDebugEnabled()) { - logger.debug("updated object"); - logger.debug(objectAsXmlString(permToUpdate, - Permission.class)); - } - PermissionClient client = new PermissionClient(); - // Submit the request to the service and store the response. - ClientResponse res = client.update(knownResourceId, permToUpdate); - assertStatusCode(res, testName); - Permission permUpdated = (Permission) res.getEntity(); - Assert.assertNotNull(permUpdated); - - Assert.assertEquals(permUpdated.getDescription(), - permToUpdate.getDescription(), - "Data in updated object did not match submitted data."); + public void delete(String testName) throws Exception { + //This method does nothing because we want to postpone the "delete" test until after + //the "updateNotAllowed" test gets run. Our "localDelete" test will call the real "delete" test later. + } + + @Test(dataProvider = "testName", + dependsOnMethods = {"updateNotAllowed", "updateActions"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void updateNotAllowed(String testName) throws Exception { // Perform setup. @@ -468,8 +202,8 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -481,12 +215,8 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"updateNotAllowed"}) + dependsOnMethods = {"updateNotAllowed"}) public void updateActions(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); @@ -511,7 +241,15 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { PermissionClient client = new PermissionClient(); // Submit the request to the service and store the response. ClientResponse res = client.update(knownResourceId, permToUpdate); - assertStatusCode(res, testName); + 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); + Permission permUpdated = (Permission) res.getEntity(); Assert.assertNotNull(permUpdated); int updated_actions = permToUpdate.getAction().size(); @@ -523,45 +261,14 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { updated_actions, "Data in updated object did not match submitted data."); } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - + /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdateNonExistent(); @@ -587,72 +294,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "updateActions", "testSubmitRequest"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - PermissionClient client = new PermissionClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - PermissionClient client = new PermissionClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -660,40 +304,10 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWorkflowDeleted(String testName) throws Exception { // Fixme: null test for now, overriding test in base class } - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - * @throws Exception - */ - @Test(dependsOnMethods = {"create"}) - public void testSubmitRequest() throws Exception { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -734,16 +348,84 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { * @param list the list * @return the int */ - private int printList(String testName, PermissionsList list) { - - int i = 0; - + @Override + protected void printList(String testName, PermissionsList list) { for (Permission permission : list.getPermission()) { logger.debug(testName + " permission csid=" + permission.getCsid() + " name=" + permission.getResourceName() + " desc=" + permission.getDescription()); - i++; } - return i; } + + @Override + protected Permission createInstance(String commonPartName, String identifier) { + List actions = PermissionFactory.createDefaultActions(); + Permission permission = createPermissionInstance(identifier, + "default permissions for " + identifier, + actions, + EffectType.PERMIT, + true, + true, + true); + return permission; + } + + @Override + protected Permission updateInstance(Permission original) { + Permission result = new Permission(); + + result.setCsid(original.getCsid()); + result.setResourceName(original.getResourceName()); + // Update the content of this resource. + result.setDescription("updated-" + original.getDescription()); + + return result; + } + + @Override + protected void compareUpdatedInstances(Permission original, + Permission updated) throws Exception { + Assert.assertEquals(updated.getCsid(), + original.getCsid(), + "CSID in updated object did not match submitted data."); + + Assert.assertEquals(updated.getResourceName(), + original.getResourceName(), + "Resource name in updated object did not match submitted data."); + + Assert.assertEquals(updated.getDescription(), + original.getDescription(), + "Description in updated object did not match submitted data."); + } + + @Override + protected Class getCommonListType() { + return PermissionsList.class; + } + + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } + + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public void updateWithMalformedXml(String testName) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public void updateWithWrongXmlSchema(String testName) throws Exception { + // TODO Auto-generated method stub + + } } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RolePermissionServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RolePermissionServiceTest.java index b162c81fe..40cafab47 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RolePermissionServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RolePermissionServiceTest.java @@ -45,7 +45,6 @@ import org.collectionspace.services.client.RoleClient; import org.collectionspace.services.client.RoleFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.ServiceRequestType; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; @@ -63,16 +62,13 @@ import org.testng.annotations.BeforeClass; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class RolePermissionServiceTest extends AbstractServiceTestImpl { +public class RolePermissionServiceTest extends AbstractServiceTestImpl { /** The Constant logger. */ private final static String CLASS_NAME = RolePermissionServiceTest.class.getName(); private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); final private static String TEST_MARKER = "_RolePermissionServiceTest"; final private static String TEST_ROLE_NAME = "ROLE"; final private static String NO_REL_SUFFIX = "-no-rel"; @@ -142,24 +138,15 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { return new RolePermissionClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); - } - /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) */ - @Test(dataProvider = "testName") +// @Test(dataProvider = "testName") @Override public void readPaginatedList(String testName) throws Exception { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 } + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -169,13 +156,8 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - ; // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -193,13 +175,11 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Store the ID returned from this create operation - // for additional tests below. - //this is is not important in case of this relationship - knownResourceId = extractId(res); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + knownResourceId = extractId(res); //This is meaningless in this test, see getKnowResourceId() method for details if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -215,8 +195,8 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { //Should this really be empty? } @@ -256,14 +236,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - ; // Perform setup. setupRead(); @@ -272,7 +247,17 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { ClientResponse res = null; try { res = client.read(roleValues.get(getRoleName()).getRoleId()); - assertStatusCode(res, testName); + 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); + PermissionRole output = (PermissionRole) res.getEntity(); Assert.assertNotNull(output); } finally { @@ -287,13 +272,8 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - ; // Perform setup. setupReadNonExistent(); @@ -310,9 +290,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { res.releaseConnection(); @@ -322,11 +302,6 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void readNoRelationship(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - ; setupRead(); // Submit the request to the service and store the response. RolePermissionClient client = new RolePermissionClient(); @@ -334,7 +309,16 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { try { res = client.read(roleValues.get(getRoleName() + NO_REL_SUFFIX).getRoleId()); - assertStatusCode(res, testName); + 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, Response.Status.OK.getStatusCode()); PermissionRole output = (PermissionRole) res.getEntity(); String sOutput = objectAsXmlString(output, PermissionRole.class); @@ -356,8 +340,8 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { //Should this really be empty? } @@ -372,8 +356,8 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read", "readList", "readNonExistent"}) public void update(String testName) throws Exception { //Should this really be empty? } @@ -409,8 +393,8 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { //Should this really be empty? } @@ -423,14 +407,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupDelete(); @@ -441,9 +420,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { try { delRes = client.delete(rv.getRoleId()); int statusCode = delRes.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (delRes != null) { delRes.releaseConnection(); @@ -465,9 +444,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { res = client.delete( rv.getRoleId(), toDelete); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { res.releaseConnection(); @@ -480,7 +459,7 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void deleteNonExistent(String testName) throws Exception { //ignoring this test as the service side returns 200 now even if it does //not find a record in the db @@ -491,7 +470,7 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWorkflowDeleted(String testName) throws Exception { // Fixme: null test for now, overriding test in base class } @@ -502,10 +481,10 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { /** * Tests the code for manually submitting data that is used by several * of the methods above. - * @throws Exception */ - @Test(dependsOnMethods = {"create"}) //FIXME: REM - This is not a test of a submit to the permroles service, but to just authorization/roles - public void testSubmitRequest() throws Exception { + @Override +// @Test(dependsOnMethods = {"create"}) //FIXME: REM - This is not a test of a submit to the permroles service, but to just authorization/roles + public void testSubmitRequest() { // Expected status code: 200 OK final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); @@ -522,8 +501,6 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } // --------------------------------------------------------------- @@ -601,9 +578,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { logger.debug("createPermission: resName=" + resName + " status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); id = extractId(res); } finally { if (res != null) { @@ -630,9 +607,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { logger.debug("deletePermission: delete permission id=" + permId + " status=" + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { @@ -664,9 +641,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { logger.debug("createRole: name=" + roleName + " status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); id = extractId(res); } finally { if (res != null) { @@ -692,12 +669,55 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { logger.debug("deleteRole: delete role id=" + roleId + " status=" + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { res.releaseConnection(); } } + + @Override + protected PermissionRole createInstance(String commonPartName, + String identifier) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected PermissionRole updateInstance(PermissionRole commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(PermissionRole original, + PermissionRole updated) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + protected Class getCommonListType() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected String getKnowResourceId() { + return roleValues.get(getRoleName()).getRoleId(); + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java index 1de1a5bb3..bf3720bb8 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java @@ -32,8 +32,6 @@ import org.collectionspace.services.authorization.Role; import org.collectionspace.services.authorization.RolesList; import org.collectionspace.services.client.RoleFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; -import org.collectionspace.services.client.test.ServiceRequestType; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; @@ -49,7 +47,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class RoleServiceTest extends AbstractServiceTestImpl { +public class RoleServiceTest extends AbstractServiceTestImpl { /** The logger. */ private final static String CLASS_NAME = RoleServiceTest.class.getName(); @@ -57,11 +55,10 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // Instance variables specific to this test. /** The known resource id. */ - private String knownResourceId = null; - private String knownRoleName = "ROLE_USERS_MOCK"; - private String knownRoleDisplayName = "ROLE_DISPLAYNAME_USERS_MOCK"; + private String knownRoleName = "ROLE_USERS_MOCK-1"; + private String knownRoleDisplayName = "ROLE_DISPLAYNAME_USERS_MOCK-1"; private String verifyResourceId = null; - private String verifyRoleName = "collections_manager_mock"; + private String verifyRoleName = "collections_manager_mock-1"; // private List allResourceIdsCreated = new ArrayList(); @Override @@ -82,20 +79,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { return new RoleClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); - } - /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) */ - @Test(dataProvider = "testName") @Override public void readPaginatedList(String testName) throws Exception { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 @@ -105,16 +91,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -137,9 +116,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from this create operation // for additional tests below. @@ -149,12 +128,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void createWithDisplayname(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -178,9 +154,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from this create operation // for additional tests below. @@ -198,12 +174,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void createForUniqueRole(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -220,8 +193,8 @@ public class RoleServiceTest extends AbstractServiceTestImpl { logger.debug(testName + ": status = " + statusCode); logger.debug(testName + ": " + res); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -231,12 +204,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createWithDisplayname"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createWithDisplayname"}) public void createForUniqueDisplayRole(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -254,8 +224,8 @@ public class RoleServiceTest extends AbstractServiceTestImpl { logger.debug(testName + ": status = " + statusCode); logger.debug(testName + ": " + res); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); if (statusCode != Response.Status.BAD_REQUEST.getStatusCode()) { // If the test fails then we've just created a Role that we need to delete, so // store the ID returned from this create operation. @@ -274,13 +244,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void createWithoutRoleName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -294,8 +260,8 @@ public class RoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -304,13 +270,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createWithDisplayname"}) +// @Test(dataProvider = "testName", +// dependsOnMethods = {"createWithDisplayname"}) public void createList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -322,9 +284,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { true); ClientResponse res = client.create(role1); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); verifyResourceId = extractId(res); allResourceIdsCreated.add(verifyResourceId); @@ -333,10 +295,10 @@ public class RoleServiceTest extends AbstractServiceTestImpl { true); res = client.create(role2); statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + Assert.assertEquals(statusCode, testExpectedStatusCode); allResourceIdsCreated.add(extractId(res)); Role role3 = createRoleInstance("ROLE_MOVINGIMAGE_ADMIN_TEST", @@ -344,10 +306,10 @@ public class RoleServiceTest extends AbstractServiceTestImpl { true); res = client.create(role3); statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + Assert.assertEquals(statusCode, testExpectedStatusCode); allResourceIdsCreated.add(extractId(res)); } @@ -386,35 +348,50 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createForUniqueRole"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"createForUniqueRole"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); // Submit the request to the service and store the response. RoleClient client = new RoleClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + 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); + Role output = (Role) res.getEntity(); Assert.assertNotNull(output); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void readToVerify(String testName) throws Exception { - // Perform setup. setupRead(); // Submit the request to the service and store the response. RoleClient client = new RoleClient(); ClientResponse res = client.read(verifyResourceId); - assertStatusCode(res, testName); + 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); + Role output = (Role) res.getEntity(); Assert.assertNotNull(output); @@ -431,13 +408,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadNonExistent(); @@ -451,9 +424,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -464,26 +437,29 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. RoleClient client = new RoleClient(); ClientResponse res = client.readList(); - assertStatusCode(res, testName); - RolesList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); + try { + // Check the status code of the response: does it match + // the expected response(s)? + assertStatusCode(res, testName); + RolesList list = res.getEntity(); + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + printList(testName, list); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } @@ -493,31 +469,33 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void searchRoleName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. RoleClient client = new RoleClient(); ClientResponse res = client.readSearchList("movingImage"); - assertStatusCode(res, testName); - RolesList list = res.getEntity(); - int EXPECTED_ITEMS = 1; - if (logger.isDebugEnabled()) { - logger.debug(testName + ": received = " + list.getRole().size() - + " expected=" + EXPECTED_ITEMS); - } - Assert.assertEquals(EXPECTED_ITEMS, list.getRole().size()); - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - printList(testName, list); + try { + assertStatusCode(res, testName); + RolesList list = res.getEntity(); + int EXPECTED_ITEMS = 1; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": received = " + list.getRole().size() + + " expected=" + EXPECTED_ITEMS); + } + Assert.assertEquals(EXPECTED_ITEMS, list.getRole().size()); + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + printList(testName, list); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } @@ -531,13 +509,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read", "readList", "readNonExistent"}) public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); @@ -557,7 +531,16 @@ public class RoleServiceTest extends AbstractServiceTestImpl { RoleClient client = new RoleClient(); // Submit the request to the service and store the response. ClientResponse res = client.update(knownResourceId, roleToUpdate); - assertStatusCode(res, testName); + 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); + + Role roleUpdated = (Role) res.getEntity(); Assert.assertNotNull(roleUpdated); @@ -566,15 +549,11 @@ public class RoleServiceTest extends AbstractServiceTestImpl { "Data in updated object did not match submitted data."); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void verifyProtectionReadOnly(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - - setupCreate(); + setupCreate(); // Submit the request to the service and store the response. RoleClient client = new RoleClient(); @@ -583,9 +562,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { role.setPermsProtection(RoleClient.IMMUTABLE); ClientResponse res = client.create(role); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from this create operation // for additional tests below. @@ -598,7 +577,12 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. ClientResponse roleRes = client.read(testResourceId); - assertStatusCode(roleRes, testName); + statusCode = roleRes.getStatus(); + + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + Role roleRead = (Role) roleRes.getEntity(); Assert.assertNotNull(roleRead); String mdProtection = roleRead.getMetadataProtection(); @@ -620,7 +604,16 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. roleRes = client.update(testResourceId, roleToUpdate); - assertStatusCode(roleRes, testName); + statusCode = roleRes.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); + + Role roleUpdated = (Role) roleRes.getEntity(); Assert.assertNotNull(roleUpdated); if (logger.isDebugEnabled()) { @@ -638,10 +631,8 @@ public class RoleServiceTest extends AbstractServiceTestImpl { "Role allowed update of the perms protection flag."); } - - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void updateNotAllowed(String testName) throws Exception { // Perform setup. @@ -666,8 +657,8 @@ public class RoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } @@ -702,14 +693,11 @@ public class RoleServiceTest extends AbstractServiceTestImpl { /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) */ + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdateNonExistent(); @@ -730,9 +718,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -743,29 +731,16 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"updateNotAllowed", "testSubmitRequest", "verifyProtectionReadOnly"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - RoleClient client = new RoleClient(); - ClientResponse res = client.delete(knownResourceId); - 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); + // Do nothing since other tests like "updateNotAllowed" need the "known resource" that this test + // deletes. Once all those tests get run, the "localDelete" method will call the base class' delete + // method that will delete the "known resource". + } + + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"updateNotAllowed", "createForUniqueRole", "createForUniqueDisplayRole"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } // Failure outcomes @@ -773,13 +748,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDeleteNonExistent(); @@ -793,9 +764,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -803,7 +774,7 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWorkflowDeleted(String testName) throws Exception { // Fixme: null test for now, overriding test in base class } @@ -817,27 +788,6 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @throws Exception */ - @Test(dependsOnMethods = {"create"}) - public void testSubmitRequest() throws Exception { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -873,16 +823,48 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @param list the list * @return the int */ - private int printList(String testName, RolesList list) { - - int i = 0; - + protected void printList(String testName, RolesList list) { for (Role role : list.getRole()) { logger.debug(testName + " role csid=" + role.getCsid() + " name=" + role.getRoleName() + " desc=" + role.getDescription()); - i++; } - return i; } + + @Override + protected Role createInstance(String commonPartName, String identifier) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Role updateInstance(Role commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(Role original, Role updated) + throws Exception { + // TODO Auto-generated method stub + + } + + @Override + protected Class getCommonListType() { + // TODO Auto-generated method stub + return null; + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } } diff --git a/services/authorization-mgt/import/pom.xml b/services/authorization-mgt/import/pom.xml index 8a0daee1f..8088be1c2 100644 --- a/services/authorization-mgt/import/pom.xml +++ b/services/authorization-mgt/import/pom.xml @@ -60,7 +60,6 @@ org.testng testng - 5.6 commons-cli diff --git a/services/authorization-mgt/service/pom.xml b/services/authorization-mgt/service/pom.xml index 7cb41de3a..9f48c1021 100644 --- a/services/authorization-mgt/service/pom.xml +++ b/services/authorization-mgt/service/pom.xml @@ -59,7 +59,6 @@ org.testng testng - 5.6 test diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java index 4f7b0e6f5..0a0479195 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java @@ -23,7 +23,6 @@ */ package org.collectionspace.services.authorization; -import org.collectionspace.services.authorization.perms.FooPermissionsList; import org.collectionspace.services.authorization.perms.Permission; import org.collectionspace.services.authorization.perms.PermissionsList; import org.collectionspace.services.authorization.storage.AuthorizationDelegate; @@ -109,14 +108,6 @@ public class PermissionResource extends SecurityResourceBase { return result; } - @GET - @Path("{csid}/foo") - @Produces("application/xml") - public FooPermissionsList getPermissionFooList(@Context UriInfo ui) { - FooPermissionsList result = new FooPermissionsList(); - return result; - } - @PUT @Path("{csid}") public Permission updatePermission(@PathParam("csid") String csid,Permission theUpdate) { diff --git a/services/authorization/service/pom.xml b/services/authorization/service/pom.xml index 8d4ca0f59..8ad4df4ad 100644 --- a/services/authorization/service/pom.xml +++ b/services/authorization/service/pom.xml @@ -57,7 +57,6 @@ org.testng testng - 5.6 test diff --git a/services/batch/client/pom.xml b/services/batch/client/pom.xml index 5f79eb2f9..cd0f1ea53 100644 --- a/services/batch/client/pom.xml +++ b/services/batch/client/pom.xml @@ -62,7 +62,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java b/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java index f08f6b237..e0c5962c2 100644 --- a/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java +++ b/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java @@ -25,13 +25,12 @@ package org.collectionspace.services.client.test; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.BatchClient; -import org.collectionspace.services.client.BatchProxy; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.batch.BatchCommon; @@ -50,12 +49,11 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class BatchServiceTest extends AbstractServiceTestImpl { +public class BatchServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = BatchServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); final String SERVICE_PATH_COMPONENT = "batch"; - private String knownResourceId = null; @Override public String getServicePathComponent() { @@ -72,188 +70,22 @@ public class BatchServiceTest extends AbstractServiceTestImpl { return new BatchClient(); } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupCreate(); - BatchClient client = new BatchClient(); - PoxPayloadOut multipart = createBatchInstance(createIdentifier()); - ClientResponse res = client.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) { - knownResourceId = extractId(res); // Store the ID returned from the first resource created for additional tests below. - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run. - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - for (int i = 0; i < 3; i++) { - create(testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupRead(); - BatchClient client = new BatchClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - BatchCommon batch = (BatchCommon) extractPart(input, client.getCommonPartName(), BatchCommon.class); - Assert.assertNotNull(batch); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadList(); - BatchClient client = new BatchClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - String bar = "\r\n\r\n=================================\r\n\r\n"; - System.out.println(bar+" res: "+res); - AbstractCommonList list = res.getEntity(); - System.out.println(bar+" list: "+list); - - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdate(); - BatchClient client = new BatchClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - logger.debug("got object to update with ID: " + knownResourceId); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - BatchCommon batch = (BatchCommon) extractPart(input, client.getCommonPartName(), BatchCommon.class); - Assert.assertNotNull(batch); - - batch.setName("updated-" + batch.getName()); - logger.debug("Object to be updated:"+objectAsXmlString(batch, BatchCommon.class)); - PoxPayloadOut output = new PoxPayloadOut(BatchClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(batch, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - BatchCommon updatedBatch = (BatchCommon) extractPart(input, client.getCommonPartName(), BatchCommon.class); - Assert.assertNotNull(updatedBatch); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - BatchClient client = new BatchClient(); - PoxPayloadOut multipart = createBatchInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - assertStatusCode(res, testName); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDelete(); - BatchClient client = new BatchClient(); - ClientResponse res = client.delete(knownResourceId); - assertStatusCode(res, testName); - } - - // --------------------------------------------------------------- - // Failure outcome tests : means we expect response to fail, but test to succeed - // --------------------------------------------------------------- - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadNonExistent(); - BatchClient client = new BatchClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDeleteNonExistent(); - BatchClient client = new BatchClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcomes - // Placeholders until the tests below can be implemented. See Issue CSPACE-401. - - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - } - - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode); - Assert.assertEquals(statusCode, EXPECTED_STATUS); - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @Override protected PoxPayloadOut createInstance(String identifier) { - BatchClient client = new BatchClient(); return createBatchInstance(identifier); } + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = createBatchInstance(identifier); + return result; + } + private PoxPayloadOut createBatchInstance(String exitNumber) { String identifier = "batchNumber-" + exitNumber; BatchCommon batch = new BatchCommon(); @@ -269,4 +101,33 @@ public class BatchServiceTest extends AbstractServiceTestImpl { return multipart; } + + @Override + protected BatchCommon updateInstance(BatchCommon batchCommon) { + BatchCommon result = new BatchCommon(); + + result.setName("updated-" + batchCommon.getName()); + result.setNotes("updated-" + batchCommon.getNotes()); + + return result; + } + + @Override + protected void compareUpdatedInstances(BatchCommon original, + BatchCommon updated) throws Exception { + Assert.assertEquals(updated.getName(), original.getName()); + Assert.assertEquals(updated.getNotes(), original.getNotes()); + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } } diff --git a/services/batch/service/pom.xml b/services/batch/service/pom.xml index 1c5271930..d2e347ee9 100644 --- a/services/batch/service/pom.xml +++ b/services/batch/service/pom.xml @@ -59,7 +59,6 @@ org.testng testng - 5.6 diff --git a/services/blob/client/pom.xml b/services/blob/client/pom.xml index 98e706cc6..12be2c203 100644 --- a/services/blob/client/pom.xml +++ b/services/blob/client/pom.xml @@ -59,7 +59,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java index 46a33466c..ee07f9a8e 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java @@ -44,9 +44,6 @@ import org.collectionspace.services.blob.BlobsCommon; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -59,7 +56,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class BlobAuthRefsTest extends BaseServiceTest { +public class BlobAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = BlobAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -87,39 +84,43 @@ public class BlobAuthRefsTest extends BaseServiceTest { } @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } private PoxPayloadOut createBlobInstance(String depositorRefName) { + BlobClient blobClient = new BlobClient(); this.depositorRefName = depositorRefName; this.blobName = "testblob-"+createIdentifier(); BlobsCommon blob = new BlobsCommon(); blob.setName(this.blobName); PoxPayloadOut multipart = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new BlobClient().getCommonPartName()); + PayloadOutputPart commonPart = multipart.addPart(blobClient.getCommonPartName(), blob); logger.debug("to be created, blob common: " + objectAsXmlString(blob, BlobsCommon.class)); return multipart; } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void createWithAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); testSetup(STATUS_CREATED, ServiceRequestType.CREATE); - String identifier = createIdentifier(); // Submit the request to the service and store the response. createPersonRefs();// Create all the person refs and entities // Create a new Loans In resource. One or more fields in this resource will be PersonAuthority // references, and will refer to Person resources by their refNames. BlobClient blobClient = new BlobClient(); PoxPayloadOut multipart = createBlobInstance(depositorRefName); ClientResponse res = blobClient.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. - knownResourceId = extractId(res); + try { + assertStatusCode(res, testName); + if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. + knownResourceId = extractId(res); + } + blobIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup + } finally { + if (res != null) { + res.releaseConnection(); + } } - blobIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup } protected void createPersonRefs() { @@ -127,22 +128,30 @@ public class BlobAuthRefsTest extends BaseServiceTest { // Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified. PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); - assertStatusCode(res, "createPersonRefs (not a surefire test)"); - personAuthCSID = extractId(res); - String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); - // Create temporary Person resources, and their corresponding refNames by which they can be identified. - String csid = ""; - - csid = createPerson("Owen the Cur", "Owner", "owenCurOwner", authRefName); - personIdsCreated.add(csid); - depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); - - csid = createPerson("Davenport", "Depositor", "davenportDepositor", authRefName); - personIdsCreated.add(csid); - depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + try { + assertStatusCode(res, "createPersonRefs (not a surefire test)"); + personAuthCSID = extractId(res); + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); + // Create temporary Person resources, and their corresponding refNames by which they can be identified. + String csid = ""; + + csid = createPerson("Owen the Cur", "Owner", "owenCurOwner", authRefName); + personIdsCreated.add(csid); + depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Davenport", "Depositor", "davenportDepositor", authRefName); + personIdsCreated.add(csid); + depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + } finally { + if (res != null) { + res.releaseConnection(); + } + } } protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -150,8 +159,16 @@ public class BlobAuthRefsTest extends BaseServiceTest { personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); - assertStatusCode(res, "createPerson (not a surefire test)"); - return extractId(res); + try { + assertStatusCode(res, "createPerson (not a surefire test)"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + + return result; } // @Test annotation commented out by Aron 2010-12-02 until blob payload is set to the @@ -162,36 +179,48 @@ public class BlobAuthRefsTest extends BaseServiceTest { // // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); testSetup(STATUS_OK, ServiceRequestType.READ); BlobClient blobClient = new BlobClient(); ClientResponse res = blobClient.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - BlobsCommon blob = (BlobsCommon) extractPart(input, blobClient.getCommonPartName(), BlobsCommon.class); - Assert.assertNotNull(blob); - logger.debug(objectAsXmlString(blob, BlobsCommon.class)); + BlobsCommon blob = null; + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + blob = (BlobsCommon) extractPart(input, blobClient.getCommonPartName(), BlobsCommon.class); + Assert.assertNotNull(blob); + logger.debug(objectAsXmlString(blob, BlobsCommon.class)); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // Check a couple of fields Assert.assertEquals(blob.getName(), blobName); // Get the auth refs and check them ClientResponse res2 = blobClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - AuthorityRefList list = res2.getEntity(); - List items = list.getAuthorityRefItem(); - int numAuthRefsFound = items.size(); - logger.debug("Authority references, found " + numAuthRefsFound); - //Assert.assertEquals(numAuthRefsFound, NUM_AUTH_REFS_EXPECTED, - // "Did not find all expected authority references! " + - // "Expected " + NUM_AUTH_REFS_EXPECTED + ", found " + numAuthRefsFound); - if (logger.isDebugEnabled()) { - int i = 0; - for (AuthorityRefList.AuthorityRefItem item : items) { - logger.debug(testName + ": list-item[" + i + "] Field:" + item.getSourceField() + "= " + item.getAuthDisplayName() + item.getItemDisplayName()); - logger.debug(testName + ": list-item[" + i + "] refName=" + item.getRefName()); - logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri()); - i++; + try { + assertStatusCode(res2, testName); + AuthorityRefList list = res2.getEntity(); + List items = list.getAuthorityRefItem(); + int numAuthRefsFound = items.size(); + logger.debug("Authority references, found " + numAuthRefsFound); + //Assert.assertEquals(numAuthRefsFound, NUM_AUTH_REFS_EXPECTED, + // "Did not find all expected authority references! " + + // "Expected " + NUM_AUTH_REFS_EXPECTED + ", found " + numAuthRefsFound); + if (logger.isDebugEnabled()) { + int i = 0; + for (AuthorityRefList.AuthorityRefItem item : items) { + logger.debug(testName + ": list-item[" + i + "] Field:" + item.getSourceField() + "= " + item.getAuthDisplayName() + item.getItemDisplayName()); + logger.debug(testName + ": list-item[" + i + "] refName=" + item.getRefName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri()); + i++; + } + } + } finally { + if (res2 != null) { + res2.releaseConnection(); } } } @@ -230,5 +259,4 @@ public class BlobAuthRefsTest extends BaseServiceTest { } } } - } diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobScaleTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobScaleTest.java new file mode 100644 index 000000000..3324e73b3 --- /dev/null +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobScaleTest.java @@ -0,0 +1,151 @@ +package org.collectionspace.services.client.test; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Random; + +import javax.imageio.ImageIO; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.client.BlobClient; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.common.profile.Profiler; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.jboss.resteasy.client.ClientResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + +public class BlobScaleTest extends BaseServiceTest { + + private final Logger logger = LoggerFactory.getLogger(BlobScaleTest.class); + + private static final int IMAGE_SIZE = 1000; + private static final int IMAGE_EDGE = -15; + private static final int MIN_FONTSIZE = 15; + private static final int MAX_FONTSIZE = 60; + private static final String IMAGES_TO_CREATE_PROP = "imagesToCreate"; + private static final int DEFAULT_IMAGES_TO_CREATE = 1; + private static final String GENERATED_IMAGES = "target/generated_images"; + + private static Random generator = new Random(System.currentTimeMillis()); + + @Override + protected CollectionSpaceClient getClientInstance() { + return new BlobClient(); + } + + @Override + protected String getServicePathComponent() { + return BlobClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return BlobClient.SERVICE_NAME; + } + + private int getImagesToCreate() { + int result = DEFAULT_IMAGES_TO_CREATE; + + String imagesToCreate = System.getProperty(IMAGES_TO_CREATE_PROP); + try { + result = Integer.parseInt(imagesToCreate); + } catch (NumberFormatException np) { + logger.info("No value (or a bad value) for system property '" + + IMAGES_TO_CREATE_PROP + + "' was defined, so we'll use the default instead."); + } finally { + logger.info("Testing blob scaling by creating " + + result + + " images."); + } + + return result; + } + + @Test(dataProvider = "testName") + public void scaleTest(String testName) throws MalformedURLException { + this.createDirectory(GENERATED_IMAGES); + setupCreate(); + int imagesToCreate = getImagesToCreate(); + BlobClient client = new BlobClient(); + Profiler profiler = new Profiler(this, 1); + + for (int i = 0; i < imagesToCreate; i++, profiler.reset()) { + File jpegFile = createJpeg(GENERATED_IMAGES); + URL url = jpegFile.toURI().toURL(); + + profiler.start(); + ClientResponse res = client.createBlobFromURI(url.toString()); + try { + profiler.stop(); + assertStatusCode(res, testName); + logger.debug( + i + ": Uploaded image to Nuxeo in " + + profiler.getCumulativeTime() + + " milleseconds " + + " - " + + " : " + + jpegFile.getAbsolutePath()); + + String csid = extractId(res); + allResourceIdsCreated.add(csid); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + } + } + + private void createDirectory(String dirName) { + boolean success = ( + new File(dirName)).mkdir(); + if (success) { + logger.debug("Directory: " + + dirName + " created"); + } + } + + public File createJpeg(String destDir) { + File result = null; + + BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_RGB); + Graphics g = image.getGraphics(); + for (int i = 0; i < IMAGE_SIZE; i = i + 10) { + int x = random(IMAGE_EDGE, IMAGE_SIZE); + int y = random(IMAGE_EDGE, IMAGE_SIZE); + g.drawString(Integer.toString(random(-123456789, 123456789)), x, y); + Color c = new Color(random(0, 255), random(0, 255), random(0, 255)); + g.setColor(c); + + Font currentFont = g.getFont(); + Font newFont = new Font(currentFont.getFontName(), currentFont.getStyle(), + random(MIN_FONTSIZE, MAX_FONTSIZE)); + g.setFont(newFont); + } + try { + ImageIO.write(image, "jpg", result = new File(destDir + + File.separator + + System.currentTimeMillis() + + ".jpg")); + } catch (IOException e) { + e.printStackTrace(); + } + + return result; + } + + public int random(int min, int max) { + return min + (int)(generator.nextFloat() * ((max - min) + 1)); + } + + +} diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java index 381312b3a..3bc6e801d 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java @@ -24,19 +24,15 @@ package org.collectionspace.services.client.test; import java.io.File; import java.math.BigDecimal; -import java.net.MalformedURLException; import java.net.URL; import java.util.List; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -import org.collectionspace.services.client.BlobProxy; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.BlobClient; import org.collectionspace.services.client.PayloadOutputPart; -import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.blob.BlobsCommon; @@ -58,11 +54,10 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class BlobServiceTest extends AbstractGenericServiceTestImpl { +public class BlobServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = BlobServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - private String knownResourceId = null; private final static String KNOWN_IMAGE_FILENAME = "01-03-09_1546.jpg"; private final static int WIDTH_DIMENSION_INDEX = 0; @@ -86,12 +81,12 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl } @Override - protected CollectionSpaceClient getClientInstance() { + protected CollectionSpaceClient getClientInstance() { return new BlobClient(); } @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(ClientResponse response) { return response.getEntity(AbstractCommonList.class); } @@ -113,23 +108,7 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl private boolean isBlobCleanup() { return blobCleanup; } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupCreate(); - BlobClient client = new BlobClient(); - PoxPayloadOut multipart = createBlobInstance(createIdentifier()); - ClientResponse res = client.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) { - knownResourceId = extractId(res); // Store the ID returned from the first resource created for additional tests below. - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run. - } - + /** * Looks in the .../src/test/resources/blobs directory for files from which to create Blob * instances. @@ -168,10 +147,16 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl OutputPart outputPart = form.addFormData("file", child, MediaType.valueOf(mimeType)); res = client.createBlobFromFormData(form); } - assertStatusCode(res, testName); - if (isBlobCleanup() == true) { - allResourceIdsCreated.add(extractId(res)); - } + try { + assertStatusCode(res, testName); + if (isBlobCleanup() == true) { + allResourceIdsCreated.add(extractId(res)); + } + } finally { + if (res != null) { + res.releaseConnection(); + } + } } } } else { @@ -182,9 +167,11 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl } } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createBlobWithURI"}) + /* + * For a known image file, make sure we're getting back the correct metadata about it. + */ + @Test(dataProvider = "testName", dependsOnMethods = {"createBlobWithURI"}) public void testImageDimensions(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); setupCreate(); String currentDir = this.getResourceDir(); @@ -193,23 +180,40 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl File file = new File(blobsDirPath); URL fileUrl = file.toURI().toURL(); String uri = fileUrl.toString(); - + // + // Create the blob + // BlobClient client = new BlobClient(); ClientResponse res = null; res = client.createBlobFromURI(uri); - assertStatusCode(res, testName); - - String blobCsid = extractId(res); - if (isBlobCleanup() == true) { - allResourceIdsCreated.add(blobCsid); - } - + String blobCsid = null; + try { + assertStatusCode(res, testName); + blobCsid = extractId(res); + if (isBlobCleanup() == true) { + allResourceIdsCreated.add(blobCsid); + } + } finally { + if (res != null) { + res.releaseConnection(); + } + } + // + // Read the blob back to get the new dimension data + // setupRead(); ClientResponse readResponse = client.read(blobCsid); - assertStatusCode(readResponse, testName); + BlobsCommon blobsCommon = null; + try { + assertStatusCode(readResponse, testName); + blobsCommon = this.extractCommonPartValue(readResponse); + Assert.assertNotNull(blobsCommon); + } finally { + if (readResponse != null) { + readResponse.releaseConnection(); + } + } - BlobsCommon blobsCommon = this.extractCommonPartValue(readResponse); - Assert.assertTrue(blobsCommon != null); Assert.assertEquals(blobsCommon.getLength(), KNOWN_IMAGE_SIZE, "The known image blob was not the expected size of " + KNOWN_IMAGE_SIZE); MeasuredPartGroup measuredImagePart = blobsCommon.getMeasuredPartGroupList().getMeasuredPartGroup().get(0); @@ -225,184 +229,24 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl Assert.assertTrue(heightDimension.getValue().compareTo(KNOWN_IMAGE_HEIGHT) == 0); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"CRUDTests"}) public void createBlobWithURI(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); createBlob(testName, true /*with URI*/, null); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"CRUDTests"}) public void createBlobWithURL(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); createBlob(testName, true /*with URI*/, "http://farm6.static.flickr.com/5289/5688023100_15e00cde47_o.jpg"); } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createBlobWithURI"}) public void createBlobWithPost(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); createBlob(testName, false /*with POST*/, null); } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - for (int i = 0; i < 3; i++) { - create(testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupRead(); - BlobClient client = new BlobClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - BlobsCommon blob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class); - Assert.assertNotNull(blob); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadList(); - BlobClient client = new BlobClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - if (logger.isDebugEnabled()) { - List items = - list.getListItem(); - int i = 0; - for(AbstractCommonList.ListItem item : items){ - logger.debug(testName + ": list-item[" + i + "] " + - item.toString()); - i++; - } - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdate(); - BlobClient client = new BlobClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - logger.debug("got object to update with ID: " + knownResourceId); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - BlobsCommon blob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class); - Assert.assertNotNull(blob); - - blob.setName("updated-" + blob.getName()); - logger.debug("Object to be updated:"+objectAsXmlString(blob, BlobsCommon.class)); - PoxPayloadOut output = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(blob, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - BlobsCommon updatedBlob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class); - Assert.assertNotNull(updatedBlob); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - BlobClient client = new BlobClient(); - PoxPayloadOut multipart = createBlobInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - assertStatusCode(res, testName); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDelete(); - BlobClient client = new BlobClient(); - ClientResponse res = client.delete(knownResourceId); - assertStatusCode(res, testName); - } - - // --------------------------------------------------------------- - // Failure outcome tests : means we expect response to fail, but test to succeed - // --------------------------------------------------------------- - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadNonExistent(); - BlobClient client = new BlobClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDeleteNonExistent(); - BlobClient client = new BlobClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcomes - // Placeholders until the tests below can be implemented. See Issue CSPACE-401. - - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - } - - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode); - Assert.assertEquals(statusCode, EXPECTED_STATUS); - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -413,12 +257,12 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl } private PoxPayloadOut createBlobInstance(String exitNumber) { + BlobClient client = new BlobClient(); String identifier = "blobNumber-" + exitNumber; BlobsCommon blob = new BlobsCommon(); blob.setName(identifier); PoxPayloadOut multipart = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new BlobClient().getCommonPartName()); + PayloadOutputPart commonPart = multipart.addPart(client.getCommonPartName(), blob); if (logger.isDebugEnabled()) { logger.debug("to be created, blob common"); @@ -427,4 +271,37 @@ public class BlobServiceTest extends AbstractGenericServiceTestImpl return multipart; } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return createInstance(identifier); + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } + + @Override + protected BlobsCommon updateInstance(BlobsCommon blobsCommon) { + BlobsCommon result = new BlobsCommon(); + + result.setName("updated-" + blobsCommon.getName()); + + return result; + } + + @Override + protected void compareUpdatedInstances(BlobsCommon original, + BlobsCommon updated) throws Exception { + Assert.assertEquals(updated.getName(), original.getName()); + } } diff --git a/services/blob/client/src/test/resources/log4j.properties b/services/blob/client/src/test/resources/log4j.properties index 18c510350..5b4e490b6 100644 --- a/services/blob/client/src/test/resources/log4j.properties +++ b/services/blob/client/src/test/resources/log4j.properties @@ -18,6 +18,8 @@ log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n #packages log4j.logger.org.collectionspace=DEBUG +log4j.logger.perf.collectionspace=TRACE + log4j.logger.org.apache=INFO log4j.logger.httpclient=INFO log4j.logger.org.jboss.resteasy=INFO diff --git a/services/blob/service/pom.xml b/services/blob/service/pom.xml index f589cb529..3d933d96b 100644 --- a/services/blob/service/pom.xml +++ b/services/blob/service/pom.xml @@ -40,7 +40,6 @@ org.testng testng - 5.6 diff --git a/services/client/pom.xml b/services/client/pom.xml index 8f9afc50f..8ff6556ec 100644 --- a/services/client/pom.xml +++ b/services/client/pom.xml @@ -7,7 +7,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.client services.client jar @@ -23,20 +22,17 @@ slf4j-log4j12 provided + - + org.collectionspace.services org.collectionspace.services.jaxb ${project.version} - + + org.apache.maven.plugins maven-surefire-plugin @@ -74,7 +70,7 @@ org.testng testng - 5.6 + compile diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractCommonListPoxServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractCommonListPoxServiceClientImpl.java index 507c0cf30..22cae7501 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractCommonListPoxServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractCommonListPoxServiceClientImpl.java @@ -1,31 +1,18 @@ package org.collectionspace.services.client; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; -public abstract class AbstractCommonListPoxServiceClientImpl

extends - AbstractPoxServiceClientImpl { - - /* - * Proxied service calls. - */ - - /** - * @return - * @see org.collectionspace.hello.client.IntakeProxy#getIntake() - */ - public ClientResponse readList() { - return getProxy().readList(); - } - - /** - * @param csid - * @return - * @see org.collectionspace.hello.client.IntakeProxy#getIntake(java.lang.String) - */ - @Override - public ClientResponse read(String csid) { - return getProxy().read(csid); - } +/** + * + * @author remillet + * + * All clients returning AbstractCommonList types should extend this class. + * + * @param

+ */ +public abstract class AbstractCommonListPoxServiceClientImpl

+ extends AbstractPoxServiceClientImpl { + // + // All clients returning AbstractCommonList types should extend this class. + // } diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractCommonListUtils.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractCommonListUtils.java similarity index 93% rename from services/common/src/main/java/org/collectionspace/services/common/AbstractCommonListUtils.java rename to services/client/src/main/java/org/collectionspace/services/client/AbstractCommonListUtils.java index 8430e56d3..22866cccc 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractCommonListUtils.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractCommonListUtils.java @@ -1,4 +1,4 @@ -package org.collectionspace.services.common; +package org.collectionspace.services.client; import java.util.List; diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java index 70532093b..56ad16593 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java @@ -1,17 +1,17 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; /* - * LT = List type + * CLT = List type * P = Proxy type */ -public abstract class AbstractPoxServiceClientImpl> - extends AbstractServiceClientImpl - implements CollectionSpacePoxClient { +public abstract class AbstractPoxServiceClientImpl> + extends AbstractServiceClientImpl + implements CollectionSpacePoxClient { @Override public ClientResponse create(PoxPayloadOut xmlPayload) { @@ -22,7 +22,18 @@ public abstract class AbstractPoxServiceClientImpl read(String csid) { return getProxy().read(csid); } - + + public ClientResponse readList() { + CollectionSpaceProxy proxy = (CollectionSpaceProxy)getProxy(); + return proxy.readList(); + } + + @Override + public ClientResponse readIncludeDeleted(Boolean includeDeleted) { + CollectionSpacePoxProxy proxy = getProxy(); + return proxy.readIncludeDeleted(includeDeleted.toString()); + } + @Override public ClientResponse readIncludeDeleted(String csid, Boolean includeDeleted) { return getProxy().readIncludeDeleted(csid, includeDeleted.toString()); @@ -33,21 +44,16 @@ public abstract class AbstractPoxServiceClientImpl readIncludeDeleted(Boolean includeDeleted) { - CollectionSpacePoxProxy proxy = getProxy(); - return proxy.readIncludeDeleted(includeDeleted.toString()); - } @Override - public ClientResponse keywordSearchIncludeDeleted(String keywords, Boolean includeDeleted) { - CollectionSpacePoxProxy proxy = getProxy(); + public ClientResponse keywordSearchIncludeDeleted(String keywords, Boolean includeDeleted) { + CollectionSpacePoxProxy proxy = getProxy(); return proxy.keywordSearchIncludeDeleted(keywords, includeDeleted.toString()); } @Override - public ClientResponse advancedSearchIncludeDeleted(String whereClause, Boolean includeDeleted) { - CollectionSpacePoxProxy proxy = getProxy(); + public ClientResponse advancedSearchIncludeDeleted(String whereClause, Boolean includeDeleted) { + CollectionSpacePoxProxy proxy = getProxy(); return proxy.advancedSearchIncludeDeleted(whereClause, includeDeleted.toString()); } diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java index f2a5e1d11..f898152a3 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java @@ -37,7 +37,7 @@ import org.apache.commons.httpclient.auth.AuthScope; //import org.collectionspac import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.workflow.WorkflowCommon; + import org.jboss.resteasy.client.ClientResponse; //import org.collectionspace.services.common.context.ServiceContext; import org.jboss.resteasy.client.ProxyFactory; import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor; @@ -52,9 +52,14 @@ import org.slf4j.LoggerFactory; * http://issues.collectionspace.org/browse/CSPACE-1684 * @param * @param + * + * CLT - List type + * REQUEST_PT - Request payload type + * RESPONSE_PT - Response payload type + * P - Proxy type */ -public abstract class AbstractServiceClientImpl> - implements CollectionSpaceClient { +public abstract class AbstractServiceClientImpl> + implements CollectionSpaceClient { /** The logger. */ protected final Logger logger = LoggerFactory.getLogger(AbstractServiceClientImpl.class); @@ -101,6 +106,13 @@ public abstract class AbstractServiceClientImpl getCommonListType() { + return (Class) AbstractCommonList.class; + } + /** * Gets the common part name. * @@ -427,6 +439,7 @@ public abstract class AbstractServiceClientImpl readList(Long pageSize, + public ClientResponse readList(Long pageSize, Long pageNumber) { return getProxy().readList(pageSize, pageNumber); } @@ -449,7 +462,7 @@ public abstract class AbstractServiceClientImpl readList(String sortBy, Long pageSize, + public ClientResponse readList(String sortBy, Long pageSize, Long pageNumber) { return getProxy().readList(sortBy, pageSize, pageNumber); } diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java index 486f2718c..f81c583fb 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java @@ -1,18 +1,18 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; /* * LT - List type * ILT - Authority item list type * P - Proxy type */ -public interface AuthorityClient

+public interface AuthorityClient extends CollectionSpacePoxClient { /** The uri path element for items in an authority */ @@ -23,6 +23,12 @@ public interface AuthorityClient

*/ String getItemCommonPartName(); + + // Get the inAuthorityCsid (the item's parent) + String getInAuthority(AUTHORITY_ITEM_TYPE item); + + // Get the inAuthorityCsid (the item's parent) + void setInAuthority(AUTHORITY_ITEM_TYPE item, String inAuthorityCsid); //(C)reate Item ClientResponse createItem(String vcsid, PoxPayloadOut poxPayloadOut); diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java index f77bfbf3f..fbdda135d 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java @@ -10,9 +10,9 @@ import org.collectionspace.services.jaxb.AbstractCommonList; /* * P - Proxy type */ -public abstract class AuthorityClientImpl

- extends AbstractCommonListPoxServiceClientImpl

- implements AuthorityClient

{ +public abstract class AuthorityClientImpl + extends AbstractPoxServiceClientImpl + implements AuthorityClient { private static final String INCLUDE_DELETE_TRUE = Boolean.TRUE.toString(); /* diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java index 7ffc3fc5b..52493c81e 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java @@ -10,12 +10,12 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; /* * ILT = Item list type diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java index b4f103e1e..668a8664d 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java @@ -25,15 +25,18 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; import org.apache.commons.httpclient.HttpClient; -import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.common.authorityref.AuthorityRefList; + /** * LT - List Type + * REQUEST_PT - Request payload type + * RESPONSE_PT - Response payload type * P - Proxy type */ -public interface CollectionSpaceClient> { +public interface CollectionSpaceClient> { public static final String AUTH_PROPERTY = "cspace.auth"; public static final String PASSWORD_PROPERTY = "cspace.password"; @@ -150,6 +153,12 @@ public interface CollectionSpaceClient> { * Common proxied service calls */ + public ClientResponse create(REQUEST_TYPE payload); + + public ClientResponse read(String csid); + + public ClientResponse update(String csid, REQUEST_TYPE payload); + /** * Read list. * @@ -157,9 +166,11 @@ public interface CollectionSpaceClient> { * @param pageNumber the page number * @return the client response */ - public ClientResponse readList( + public ClientResponse readList( Long pageSize, Long pageNumber); + + public ClientResponse readList(); /** * Read list. @@ -169,7 +180,7 @@ public interface CollectionSpaceClient> { * @param pageNumber the page number * @return the client response */ - public ClientResponse readList( + public ClientResponse readList( String sortBy, Long pageSize, Long pageNumber); diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java index fe3b587ed..79ac9a3fe 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java @@ -1,30 +1,21 @@ package org.collectionspace.services.client; -import javax.ws.rs.core.Response; - import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; /* * = List type + * = Payload type *

= Proxy type */ public interface CollectionSpacePoxClient> - extends CollectionSpaceClient { + extends CollectionSpaceClient { /* * Common service calls */ - public ClientResponse create(PoxPayloadOut xmlPayload); - - /* - * GET resource with workflow 'deleted' state - */ - public ClientResponse read(String csid); public ClientResponse readIncludeDeleted(String csid, Boolean includeDeleted); - public ClientResponse update(String csid, PoxPayloadOut xmlPayload); - /* * GET list with workflow 'deleted' state */ diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java index fa71d50f1..e09c6f538 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java @@ -8,10 +8,10 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; public interface CollectionSpacePoxProxy extends CollectionSpaceProxy { diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java index df3b30ade..21df5873a 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java @@ -38,7 +38,6 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -46,7 +45,7 @@ import org.jboss.resteasy.client.ClientResponse; * The Interface CollectionSpaceProxy. * FIXME: http://issues.collectionspace.org/browse/CSPACE-1684 */ -public interface CollectionSpaceProxy { +public interface CollectionSpaceProxy { //(D)elete @DELETE @@ -75,6 +74,10 @@ public interface CollectionSpaceProxy { * (R)read List operations */ + @GET + @Produces({"application/xml"}) + ClientResponse readList(); + /** * Read list. * @@ -84,7 +87,7 @@ public interface CollectionSpaceProxy { */ @GET @Produces({"application/xml"}) - ClientResponse readList( + ClientResponse readList( @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) Long pageSize, @QueryParam(IClientQueryParams.START_PAGE_PARAM) Long pageNumber); @@ -98,7 +101,7 @@ public interface CollectionSpaceProxy { */ @GET @Produces({"application/xml"}) - ClientResponse readList( + ClientResponse readList( @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortBy, @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) Long pageSize, @QueryParam(IClientQueryParams.START_PAGE_PARAM) Long pageNumber); diff --git a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java index c4e84241f..b3eb1d964 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java @@ -22,12 +22,18 @@ */ package org.collectionspace.services.client; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.client.ClientResponse; +import org.collectionspace.services.jaxb.AbstractCommonList; + /** * A CollectionObjectClient. * @version $Revision:$ */ -public class TestServiceClient extends AbstractServiceClientImpl { + +public final class TestServiceClient extends AbstractServiceClientImpl { /** * @@ -49,5 +55,25 @@ public class TestServiceClient extends AbstractServiceClientImpl getProxyClass() { // TODO Auto-generated method stub return TestServiceProxy.class; + } + + @Override + public ClientResponse create(Object payload) { + throw new UnsupportedOperationException(); + } + + @Override + public ClientResponse update(String csid, Object payload) { + throw new UnsupportedOperationException(); + } + + @Override + public ClientResponse read(String csid) { + throw new UnsupportedOperationException(); + } + + @Override + public ClientResponse readList() { + throw new UnsupportedOperationException(); } } diff --git a/services/client/src/main/java/org/collectionspace/services/client/TestServiceProxy.java b/services/client/src/main/java/org/collectionspace/services/client/TestServiceProxy.java index 2d3f53c44..0299771ca 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/TestServiceProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/TestServiceProxy.java @@ -1,5 +1,7 @@ package org.collectionspace.services.client; -public interface TestServiceProxy extends CollectionSpaceProxy { +import org.collectionspace.services.jaxb.AbstractCommonList; + +public interface TestServiceProxy extends CollectionSpaceProxy { } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java new file mode 100644 index 000000000..5bdf85193 --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java @@ -0,0 +1,540 @@ +package org.collectionspace.services.client.test; + +import java.util.List; + +import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; + +import org.collectionspace.services.client.AbstractCommonListUtils; +import org.collectionspace.services.client.AuthorityClient; +import org.collectionspace.services.client.AuthorityClientImpl; +import org.collectionspace.services.client.AuthorityProxy; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.jaxb.AbstractCommonList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * + * @author remillet + * + * @param + * @param + * + * All CRUD related authority test classes should extend this class. + * + */ +public abstract class AbstractAuthorityServiceTest + extends AbstractPoxServiceTestImpl { + + private final Logger logger = LoggerFactory.getLogger(AbstractAuthorityServiceTest.class); + + protected String knownResourceShortIdentifer = null; + protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems"; + protected String knownAuthorityWithItems = null; + + protected String knownResourceRefName = null; + protected String knownItemResourceId = null; + protected String knownItemResourceShortIdentifer = null; + protected int nItemsToCreateInList = 5; + + public abstract void authorityTests(String testName); + protected abstract String createItemInAuthority(String authorityId); + + protected abstract AUTHORITY_ITEM_TYPE updateItemInstance(final AUTHORITY_ITEM_TYPE authorityItem); + protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original, AUTHORITY_ITEM_TYPE updated) throws Exception; + + protected void setKnownItemResource(String id, String shortIdentifer ) { + knownItemResourceId = id; + knownItemResourceShortIdentifer = shortIdentifer; + } + + protected void setKnownResource(String id, String shortIdentifer, + String refName) { + knownResourceId = id; + knownResourceShortIdentifer = shortIdentifer; + knownResourceRefName = refName; + } + + /** + * Returns the root URL for a service. + * + * This URL consists of a base URL for all services, followed by + * a path component for the owning vocabulary, followed by the + * path component for the items. + * + * @return The root URL for a service. + */ + protected String getItemServiceRootURL(String parentResourceIdentifier) { + return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent(); + } + + /** + * Returns the URL of a specific resource managed by a service, and + * designated by an identifier (such as a universally unique ID, or UUID). + * + * @param resourceIdentifier An identifier (such as a UUID) for a resource. + * + * @return The URL of a specific resource managed by a service. + */ + protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) { + return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier; + } + + /** + * For authorities we override this method so we can save the shortid. + */ + @Override + protected String createWithIdentifier(String testName, String identifier) throws Exception { + String csid = createResource(testName, identifier); + // Store the ID returned from the first resource created + // for additional tests below. + if (getKnowResourceId() == null) { + setKnownResource(csid, identifier /*shortId*/, null /*refname*/ ); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": Setting knownResourceId=" + getKnowResourceId()); + } + } + + return identifier; + } + + @Test(dependsOnMethods = {"readItem", "CRUDTests"}) + public void testItemSubmitRequest() { + + // Expected status code: 200 OK + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); + + // Submit the request to the service and store the response. + String method = ServiceRequestType.READ.httpMethodName(); + String url = getItemResourceURL(knownResourceId, knownItemResourceId); + int statusCode = submitRequest(method, url); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug("testItemSubmitRequest: url=" + url + + " status=" + statusCode); + } + Assert.assertEquals(statusCode, EXPECTED_STATUS); + } + + + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"readItem"}) + public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception { + // Perform setup. + setupUpdate(); + + // Submit the request to the service and store the response. + AuthorityClientImpl client = + (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + " read authority:" + knownResourceId + "/Item:" + + knownItemResourceId + " status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + AUTHORITY_ITEM_TYPE vitem = extractItemCommonPartValue(res); + Assert.assertNotNull(vitem); + // Try to Update with new parent vocab (use self, for test). + Assert.assertEquals(client.getInAuthority(vitem), knownResourceId, + "VocabularyItem inAuthority does not match knownResourceId."); + client.setInAuthority(vitem, knownItemResourceId); + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = this.createItemRequestTypeInstance(vitem); + 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(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + // Retrieve the updated resource and verify that the parent did not change + res = client.readItem(knownResourceId, knownItemResourceId); + AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res); + Assert.assertNotNull(updatedVocabularyItem); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(client.getInAuthority(updatedVocabularyItem), + knownResourceId, + "VocabularyItem allowed update to the parent (inAuthority)."); + } + + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) + public void createItem(String testName) { + // Perform setup. + setupCreate(); + + String newID = createItemInAuthority(knownResourceId); + + // Store the ID returned from the first item resource created + // for additional tests below. + if (knownItemResourceId == null) { + knownItemResourceId = newID; + if (null != testName && logger.isDebugEnabled()) { + logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); + } + } + } + + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"createItem"}) + public void createItemList(String testName) throws Exception { + knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER); + for (int j = 0; j < nItemsToCreateInList; j++) { + createItemInAuthority(knownAuthorityWithItems); + } + } + + /** + * Read by name. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"CRUDTests"}) + public void readByName(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = client.readByName(getKnowResourceIdentifier()); + 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); + + AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res); + Assert.assertNotNull(commonPart); + } + + /** + * Extracts the common part item from a service's item payload. + * + * @param res + * @return + * @throws Exception + */ + public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(ClientResponse res) throws Exception { + AUTHORITY_ITEM_TYPE result = null; + + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName()); + if (payloadInputPart != null) { + result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody(); + } + Assert.assertNotNull(result, + "Part or body of part " + client.getCommonPartName() + " was unexpectedly null."); + + return result; + } + + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"readItem"}) + public void readItemNonExistent(String testName) { + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = client.readItem(knownResourceId, NON_EXISTENT_ID); + 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); + } + + @Test(dataProvider = "testName", + dependsOnMethods = {"createItem"}) + public void readItem(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + 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); + + AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res); + Assert.assertNotNull(itemCommonPart); + Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId); + verifyReadItemInstance(itemCommonPart); + } + + protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception; + + @Test(dataProvider = "testName", + dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"}) + public void deleteItem(String testName) throws Exception { + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug("delete: status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } + + protected void readItemListInt(String vcsid, String shortId, String testName) { + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = null; + if (vcsid != null) { + res = client.readItemList(vcsid, null, null); + } else if (shortId != null) { + res = client.readItemListForNamedAuthority(shortId, null, null); + } else { + Assert.fail("Internal Error: readItemList both vcsid and shortId are null!"); + } + AbstractCommonList 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + List items = list.getListItem(); + int nItemsReturned = items.size(); + long nItemsTotal = list.getTotalItems(); + if (logger.isDebugEnabled()) { + logger.debug(" " + testName + ": Expected " + + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal); + } + Assert.assertEquals(nItemsTotal, nItemsToCreateInList); + + if(logger.isTraceEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + } + } + + @Test(dataProvider = "testName", + dependsOnMethods = {"createItemList"}) + public void readItemList(String testName) { + readItemListInt(knownAuthorityWithItems, null, testName); + } + + @Test(dataProvider = "testName", + dependsOnMethods = {"readItem"}) + public void readItemListByName(String testName) { + readItemListInt(null, READITEMS_SHORT_IDENTIFIER, testName); + } + + @Test(dataProvider = "testName", + dependsOnMethods = {"deleteItem"}) + public void deleteNonExistentItem(String testName) { + // Perform setup. + setupDeleteNonExistent(); + + // Submit the request to the service and store the response. + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); + 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); + } + + protected String getServicePathItemsComponent() { + return AuthorityClient.ITEMS; + } + + public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) { + PoxPayloadOut result = null; + + AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent()); + PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance); + result = payloadOut; + + return result; + } + + /** + * Update an Authority item. + * + * @param testName + * @throws Exception + */ + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"}) + public void updateItem(String testName) throws Exception { + // Perform setup. + setupUpdate(); + AUTHORITY_ITEM_TYPE theUpdate = null; + + // Retrieve the contents of a resource to update. + AuthorityClientImpl client = + (AuthorityClientImpl)this.getClientInstance(); + ClientResponse res = + client.readItem(knownResourceId, knownItemResourceId); + try { + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); + + if (logger.isDebugEnabled()) { + logger.debug("got Authority item to update with ID: " + + knownItemResourceId + + " in authority: " + knownResourceId); + } + AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res); + Assert.assertNotNull(authorityItem); + + // Update the contents of this resource. + theUpdate = updateItemInstance(authorityItem); + if (logger.isDebugEnabled()) { + logger.debug("\n\nTo be updated fields: CSID = " + knownItemResourceId + "\n" + + objectAsXmlString(theUpdate)); + } + } finally { + res.releaseConnection(); + } + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + try { + int 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + // Retrieve the updated resource and verify that its contents exist. + AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res); + Assert.assertNotNull(updatedVocabularyItem); + + compareUpdatedItemInstances(theUpdate, updatedVocabularyItem); + } finally { + res.releaseConnection(); + } + } + + protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier); + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String) + */ + @Test(dataProvider = "testName", + dependsOnMethods = {"create", "update", "updateNonExistent"}) + public void updateNonExistentItem(String testName) throws Exception { + // Perform setup. + setupUpdateNonExistent(); + + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + AuthorityClientImpl client = + (AuthorityClientImpl)this.getClientInstance(); + PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID); + ClientResponse 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.releaseConnection(); + } + } + + // + // Methods to persuade TestNG to follow the correct test dependency path + // + + @Test(dataProvider = "testName", + dependsOnMethods = {"createItem"}) + public void baseAuthorityTests(String testName) { + // Do nothing. Here just to setup a test dependency chain. + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + } + +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractGenericServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractGenericServiceTestImpl.java deleted file mode 100644 index 5352d35b9..000000000 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractGenericServiceTestImpl.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.collectionspace.services.client.test; - -import org.collectionspace.services.client.CollectionSpaceClient; -import org.collectionspace.services.client.CollectionSpaceCommonListPoxProxy; -import org.collectionspace.services.client.PayloadInputPart; -import org.collectionspace.services.client.PoxPayloadIn; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; -import org.testng.Assert; - -/* - * CPT - Common Part Type - */ -public abstract class AbstractGenericServiceTestImpl extends AbstractServiceTestImpl { - public CPT getCommonTypeInstance() { - CPT result = null; - return result; - } - - public CPT extractCommonPartValue(ClientResponse res) - throws Exception { - CollectionSpaceClient client = this.getClientInstance(); - PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName()); - Object obj = null; - if (payloadInputPart != null) { - obj = payloadInputPart.getBody(); - } - Assert.assertNotNull(obj, - "Body of " + client.getCommonPartName() + " part was unexpectedly null."); - CPT commonPartTypeInstance = (CPT) obj; - Assert.assertNotNull(commonPartTypeInstance, - client.getCommonPartName() + " part was unexpectedly null."); - return commonPartTypeInstance; - } - - private PayloadInputPart extractPart(ClientResponse res, String partLabel) - throws Exception { - if (getLogger().isDebugEnabled()) { - getLogger().debug("Reading part " + partLabel + " ..."); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(partLabel); - Assert.assertNotNull(payloadInputPart, - "Part " + partLabel + " was unexpectedly null."); - return payloadInputPart; - } - - -} diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractPoxServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractPoxServiceTestImpl.java new file mode 100644 index 000000000..54d1e7136 --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractPoxServiceTestImpl.java @@ -0,0 +1,80 @@ +package org.collectionspace.services.client.test; + +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.AbstractCommonListUtils; +import org.collectionspace.services.jaxb.AbstractCommonList; + +import org.jboss.resteasy.client.ClientResponse; +import org.testng.Assert; + +/* + * - Common list type + * - Common part type + */ +public abstract class AbstractPoxServiceTestImpl + extends AbstractServiceTestImpl { + + @Override + public CPT extractCommonPartValue(ClientResponse res) throws Exception { + CPT result = null; + + CollectionSpaceClient client = getClientInstance(); + PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName()); + if (payloadInputPart != null) { + result = (CPT) payloadInputPart.getBody(); + } + Assert.assertNotNull(result, + "Part or body of part " + client.getCommonPartName() + " was unexpectedly null."); + + return result; + } + + protected void printList(String testName, CLT list) { + if (getLogger().isTraceEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName); + } + } + + @Override + public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception { + CPT result = null; + + CollectionSpaceClient client = getClientInstance(); + PayloadOutputPart payloadOutputPart = payloadOut.getPart(client.getCommonPartName()); + if (payloadOutputPart != null) { + result = (CPT) payloadOutputPart.getBody(); + } + Assert.assertNotNull(result, + "Part or body of part " + client.getCommonPartName() + " was unexpectedly null."); + + return result; + } + + @Override + public PoxPayloadOut createRequestTypeInstance(CPT commonPartTypeInstance) { + PoxPayloadOut result = null; + + CollectionSpaceClient client = this.getClientInstance(); + PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart part = payloadOut.addPart(client.getCommonPartName(), commonPartTypeInstance); + result = payloadOut; + + return result; + } + + protected PayloadInputPart extractPart(ClientResponse res, String partLabel) + throws Exception { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Reading part " + partLabel + " ..."); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(partLabel); + Assert.assertNotNull(payloadInputPart, + "Part " + partLabel + " was unexpectedly null."); + return payloadInputPart; + } +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index 8bdb47822..2a1edf9ad 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -24,14 +24,9 @@ package org.collectionspace.services.client.test; import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.workflow.WorkflowCommon; -import org.collectionspace.services.client.AbstractPoxServiceClientImpl; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.CollectionSpacePoxClient; @@ -45,12 +40,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.Test; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import javax.activation.MimetypesFileTypeMap; import javax.ws.rs.core.Response; /** @@ -61,401 +52,660 @@ import javax.ws.rs.core.Response; * * For Javadoc descriptions of this class's methods, see the ServiceTest interface. * + * - Common list type + * - Common part type + * * $LastChangedRevision$ * $LastChangedDate$ */ // FIXME: http://issues.collectionspace.org/browse/CSPACE-1685 -public abstract class AbstractServiceTestImpl extends BaseServiceTest implements ServiceTest { - +public abstract class AbstractServiceTestImpl + extends BaseServiceTest implements ServiceTest { /** The logger. */ private final Logger logger = LoggerFactory.getLogger(AbstractServiceTestImpl.class); - // A non-existent logger. - static private final Logger LOGGER_NULL = null; + /** The Constant DEFAULT_LIST_SIZE. */ static protected final int DEFAULT_LIST_SIZE = 10; static protected final int DEFAULT_PAGINATEDLIST_SIZE = 10; + + /** The path to test resources */ static protected final String RESOURCE_PATH = "src" + File.separator + "test" + File.separator + "resources"; + /** Misc constants */ protected static final String BLOBS_DIR = "blobs"; - static protected final String DEFAULT_MIME = "application/octet-stream; charset=ISO-8859-1"; - static private final String NO_TEST_CLEANUP = "noTestCleanup"; static protected final String NO_BLOB_CLEANUP = "noBlobCleanup"; static protected final String NO_MEDIA_CLEANUP = "noMediaCleanup"; - private final static String NON_EXISTENT_KEYWORD = "jlmbsoqjlmbsoq"; - - protected String getMimeType(File theFile) { - String result = null; - result = new MimetypesFileTypeMap().getContentType(theFile); - if (result == null) { - logger.debug("Could not get MIME type for file at: " + theFile.getAbsolutePath()); - result = DEFAULT_MIME; - } - - return result; - - } - - /* Use this to keep track of resources to delete */ - protected List allResourceIdsCreated = new ArrayList(); - /* Use this to track authority items */ - protected Map allResourceItemIdsCreated = new HashMap(); /* itemCsid, parentCsid */ - + private final static String NON_EXISTENT_KEYWORD = "jlmbsoqjlmbsoq" + System.currentTimeMillis(); private String EMPTY_SORT_BY_ORDER = ""; - - /** - * Gets the logger. - * - * @return the logger - */ - protected Logger getLogger() { - return this.logger; - } - + + /** Error messages */ + private final static String ERROR_WORKFLOW_TRANSITION = "Workflow transition to 'deleted' did not take place!"; + protected String getResourceDir() { String result = null; String currentDirectory = System.getProperty("user.dir"); result = currentDirectory + File.separator + RESOURCE_PATH; return result; } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) + + /* + * Use this method in TestNG "@Test" methods that need to be overridden. Because of an issue in TestNG 5.6 (and earlier), + * we can't just mark the methods as "abstract". Subclasses must override the @Test methods *without* the "@Test" annotation. */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(AbstractCommonList.class); + private void mustOverride(String testName) throws Exception { + throw new RuntimeException("This method must be implemented by a subclass."); } - - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // - // (See below for utility methods in support of create list tests.) - // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + + /* + * We use this method to force a TestNG execution order for our tests */ - @Override - public abstract void create(String testName) throws Exception; - - /** - * Sets up create tests. + public abstract void CRUDTests(String testName); + + /* + * We use this method to force a TestNG execution order for our tests + */ + @Test(dataProvider = "testName", dependsOnMethods = { + "create", "read", "update", "delete", "testSubmitRequest", "createList", "readList", "readNonExistent"}) + public void baseCRUDTests(String testName) { + // Do nothing -see "dependsOnMethods" in @Test annotation above. + } + + /* + * Sub-classes can override for the workflow tests. */ - protected void setupCreate() { - EXPECTED_STATUS_CODE = STATUS_CREATED; - REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + protected REQUEST_TYPE createInstance(String identifier) { + String commonPartName = getClientInstance().getCommonPartName(); + return createInstance(commonPartName, identifier); } - + /** - * Checks if 'theFile' is something we can turn into a Blob instance. It can't - * be read-protected, hidden, or a directory. - * - * @param theFile the the file - * @return true, if is blobable + * Sub-classes must override this method for the "Create" tests to work properly */ - protected boolean isBlobbable(File theFile) { - boolean result = true; - if (theFile.isDirectory() || theFile.isHidden() || !theFile.canRead()) { - result = false; + protected abstract REQUEST_TYPE createInstance(String commonPartName, String identifier); + + protected REQUEST_TYPE createNonExistenceInstance(String commonPartName, String identifier) { + return createInstance(commonPartName, identifier); + } + + @Override + @Test(dataProvider = "testName") + public void create(String testName) throws Exception { + String identifier = getKnowResourceIdentifier(); + createWithIdentifier(testName, identifier); + } + + protected String createWithIdentifier(String testName, String identifier) throws Exception { + String csid = createResource(testName, identifier); + // Store the ID returned from the first resource created + // for additional tests below. + if (getKnowResourceId() == null) { + knownResourceId = csid; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + getKnowResourceId()); + } } - return result; + + return identifier; } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#createList(java.lang.String) - */ + + protected String createResource(String testName, String identifier) throws Exception { + String result = null; + + setupCreate(); + CollectionSpaceClient client = this.getClientInstance(); + REQUEST_TYPE payload = createInstance(client.getCommonPartName(), identifier); + ClientResponse res = client.create(payload); + try { + int statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": HTTP status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + result = extractId(res); + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + allResourceIdsCreated.add(result); + } finally { + res.releaseConnection(); + } + + return result; + } + @Override - public abstract void createList(String testName) throws Exception; + @Test(dataProvider = "testName", dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + // Perform setup. + setupRead(); - // Note: No setup is required for createList(), as it currently - // just invokes create() multiple times. - // Failure outcomes + // Submit the request to the service and store the response. + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.read(getKnowResourceId()); + int statusCode = res.getStatus(); - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public abstract void createWithEmptyEntityBody(String testName) - throws Exception; + // 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); - /** - * Sets up create tests with empty entity body. - */ - protected void setupCreateWithEmptyEntityBody() { - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + RESPONSE_TYPE output = (RESPONSE_TYPE) res.getEntity(); + Assert.assertNotNull(output); + + // + // Now compare with the expected field values + // + REQUEST_TYPE expectedResult = createInstance("read_test"); + compareReadInstances(extractCommonPartValue(expectedResult), extractCommonPartValue(res)); } + + @Override + @Test(dataProvider = "testName", dependsOnMethods = {"create", "read", "update", "readWorkflow"}) + public void delete(String testName) throws Exception { + setupDelete(); + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.delete(getKnowResourceId()); + int statusCode = res.getStatus(); - /** - * Sets up create tests with empty entity body. - */ - protected void setupCreateWithInvalidBody() { - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + // 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); } - - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#createWithMalformedXml(java.lang.String) - */ + @Override - public abstract void createWithMalformedXml(String testName) throws Exception; + @Test(dataProvider = "testName") + public void readNonExistent(String testName) throws Exception { + // Perform setup. + setupReadNonExistent(); - /** - * Sets up create tests with malformed xml. - */ - protected void setupCreateWithMalformedXml() { - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + // Submit the request to the service and store the response. + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.read(NON_EXISTENT_ID); + int statusCode = res.getStatus(); + try { + // 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); + } finally { + res.releaseConnection(); + } } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#createWithWrongXmlSchema(java.lang.String) - */ @Override - public abstract void createWithWrongXmlSchema(String testName) throws Exception; + @Test(dataProvider = "testName", dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + // Perform setup. + setupDeleteNonExistent(); - /** - * Sets up create tests with wrong xml schema. - */ - protected void setupCreateWithWrongXmlSchema() { - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); - } + // Submit the request to the service and store the response. + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.delete(NON_EXISTENT_ID); + 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); + } + // --------------------------------------------------------------- - // CRUD tests : READ tests + // Abstract CRUD tests : TestNG requires an empty method here. De- + // claring them as "abstract" will not work. + // // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#read(java.lang.String) - */ + +// protected abstract Class getCommonPartTypeClass(); + + public CPT extractCommonPartValue(ClientResponse res) throws Exception { + CPT result = null; + result = (CPT) res.getEntity(); + return result; + } + + public CPT extractCommonPartValue(REQUEST_TYPE req) throws Exception { + return (CPT)req; + } + + public REQUEST_TYPE createRequestTypeInstance(CPT commonPartTypeInstance) { + return (REQUEST_TYPE)commonPartTypeInstance; + } + + // + // This method is called by public void update(String testName). Subclasses need + // to override this method that should update the common part -e.g., CollectionObjectsCommon, DimensionsCommon, etc) + // + protected abstract CPT updateInstance(final CPT commonPartObject); + + protected abstract void compareUpdatedInstances(CPT original, CPT updated) throws Exception; + + protected void compareReadInstances(CPT original, CPT fromRead) throws Exception { + // Do nothing by default. Subclass can override if they want other behavior. + } + @Override - public abstract void read(String testName) throws Exception; + @Test(dataProvider = "testName", dependsOnMethods = {"create", "read"}) + public void update(String testName) throws Exception { + // Perform setup. + setupUpdate(); - /** - * Sets up read tests. - */ - protected void setupRead() { - EXPECTED_STATUS_CODE = STATUS_OK; - REQUEST_TYPE = ServiceRequestType.READ; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); - } + // Retrieve the contents of a resource to update. + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.read(getKnowResourceId()); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); - // Failure outcomes + if (logger.isDebugEnabled()) { + logger.debug("Got object to update with CSID= " + getKnowResourceId()); + } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#readNonExistent(java.lang.String) - */ - @Override - public abstract void readNonExistent(String testName) throws Exception; + CPT commonPartObject = this.extractCommonPartValue(res); + Assert.assertNotNull(commonPartObject); + CPT theUpdate = updateInstance(commonPartObject); + if (logger.isDebugEnabled()) { + logger.debug("\n\nTo be updated fields: CSID = " + getKnowResourceId() + "\n" + + objectAsXmlString(theUpdate)); + } - /** - * Sets up read non existent tests. - */ - protected void setupReadNonExistent() { - EXPECTED_STATUS_CODE = STATUS_NOT_FOUND; - REQUEST_TYPE = ServiceRequestType.READ; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); - } + // Submit the request to the service and store the response. + REQUEST_TYPE output = this.createRequestTypeInstance(theUpdate); + res = client.update(getKnowResourceId(), 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + CPT updatedCommonPartObject = this.extractCommonPartValue(res); + Assert.assertNotNull(updatedCommonPartObject); + + compareUpdatedInstances(theUpdate, updatedCommonPartObject); + } + // --------------------------------------------------------------- - // CRUD tests : READ (list, or multiple) tests // - // (See below for utility methods in support of list tests.) + // Generic tests that apply to most services + // // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#readList(java.lang.String) - */ - @Override - public abstract void readList(String testName) throws Exception; /** - * Sets up read list tests. + * A non-RESTEasy HTTP request test. */ - protected void setupReadList() { - EXPECTED_STATUS_CODE = STATUS_OK; - REQUEST_TYPE = ServiceRequestType.READ_LIST; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); - } + protected void testSubmitRequest(String csid) { + // Expected status code: 200 OK + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - // Failure outcomes - // None tested at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes + // Submit the request to the service and store the response. + String method = ServiceRequestType.READ.httpMethodName(); + String url = getResourceURL(csid); + int statusCode = submitRequest(method, url); - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#update(java.lang.String) + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug("testSubmitRequest: url=" + url + + " status=" + statusCode); + } + Assert.assertEquals(statusCode, EXPECTED_STATUS); + } + + /** + * A non-RESTEasy HTTP request test. */ - @Override - public abstract void update(String testName) throws Exception; + @Test(dependsOnMethods = {"create", "read"}) + public void testSubmitRequest() { + testSubmitRequest(getKnowResourceId()); + } /** - * Sets up update tests. + * Creates the list. + * + * @param testName the test name + * @param listSize the list size + * @throws Exception the exception */ - protected void setupUpdate() { - EXPECTED_STATUS_CODE = STATUS_OK; - REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + protected void createPaginatedList(String testName, int listSize) throws Exception { + for (int i = 0; i < listSize; i++) { + String identifier = createIdentifier(); + createWithIdentifier(testName, identifier); + } } - - // Failure outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#updateWithEmptyEntityBody(java.lang.String) + + /** + * Create a list of records */ @Override - public abstract void updateWithEmptyEntityBody(String testName) throws Exception; + @Test(dataProvider = "testName", dependsOnMethods = {"create"}) + public void createList(String testName) throws Exception { + createPaginatedList(testName, DEFAULT_LIST_SIZE); + } + + protected void printList(String testName, CLT list) { + // By default, do nothing. Tests can override this method to produce additional + // output after the "readList" test has run. + } + + @Override + @Test(dataProvider = "testName", dependsOnMethods = {"read"}) + public void readList(String testName) throws Exception { + // Perform setup. + setupReadList(); + // Submit the request to the service and store the response. + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.readList(); + CLT 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + printList(testName, list); + } + } + + /** - * Sets up update tests with an empty entity body. + * Read paginated list. + * + * @param testName the test name + * @throws Exception the exception */ - protected void setupUpdateWithEmptyEntityBody() { - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + @Test(dataProvider = "testName", dependsOnMethods = {"read"}) + public void readPaginatedList(String testName) throws Exception { + // Perform setup. + setupReadList(); + CollectionSpaceClient client = this.getClientInstance(); + + // Get the current total number of items. + // If there are no items then create some + AbstractCommonList list = (AbstractCommonList) this.readList(testName, + client, + 1 /*pgSz*/, + 0 /*pgNum*/, + testExpectedStatusCode); + if (list == null || list.getTotalItems() == 0) { + this.createPaginatedList(testName, DEFAULT_PAGINATEDLIST_SIZE); + setupReadList(); + list = (AbstractCommonList) this.readList(testName, + client, + 1 /*pgSz*/, + 0 /*pgNum*/, + testExpectedStatusCode); + } + + // Print out the current list size to be paginated + Assert.assertNotNull(list); + long totalItems = list.getTotalItems(); + Assert.assertFalse(totalItems == 0); + if (getLogger().isDebugEnabled() == true) { + getLogger().debug(testName + ":" + "created list of " + + totalItems + " to be paginated."); + } + + long pageSize = totalItems / 3; //create up to 3 pages to iterate over + long pagesTotal = pageSize > 0 ? (totalItems / pageSize) : 0; + for (int i = 0; i < pagesTotal; i++) { + list = (AbstractCommonList) this.readList(testName, client, pageSize, i, testExpectedStatusCode); + assertPaginationInfo(testName, + list, + i, //expected page number + pageSize, //expected page size + pageSize, //expected num of items in page + totalItems);//expected total num of items + } + + // if there are any remainders be sure to paginate them as well + long mod = pageSize != 0 ? totalItems % pageSize : totalItems; + if (mod != 0) { + list = (AbstractCommonList) this.readList(testName, client, pageSize, pagesTotal, testExpectedStatusCode); + assertPaginationInfo(testName, + list, + pagesTotal, //expected page number + pageSize, //expected page size + mod, //expected num of items in page + totalItems);//expected total num of items + } } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#updateWithMalformedXml(java.lang.String) + /* + * This test assumes that no objects exist yet. + * + * http://localhost:8180/cspace-services/intakes?wf_deleted=false */ - @Override - public abstract void updateWithMalformedXml(String testName) throws Exception; + @Test(dataProvider = "testName", dependsOnMethods = {"update"}) + public void readWorkflow(String testName) throws Exception { + try { + // + // Get the total count of non-deleted existing records + // + long existingRecords = readIncludeDeleted(testName, Boolean.FALSE); - /** - * Sets up update tests with malformed xml. - */ - protected void setupUpdateWithMalformedXml() { - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + // + // Create 3 new objects + // + final int OBJECTS_TO_CREATE = 3; + for (int i = 0; i < OBJECTS_TO_CREATE; i++) { + this.createWorkflowTarget(testName); + } + + // + // Mark one as soft deleted + // + int existingTestCreated = allResourceIdsCreated.size(); // assumption is that no other test created records were soft deleted + String csid = allResourceIdsCreated.get(existingTestCreated - 1); //0-based index to get the last one added + this.setupUpdate(); + this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED); + // + // Read the list of existing non-deleted records + // + long updatedTotal = readIncludeDeleted(testName, Boolean.FALSE); + Assert.assertEquals(updatedTotal, existingRecords + OBJECTS_TO_CREATE - 1, "Deleted items seem to be returned in list results."); + + // + // Next, test that a GET with WorkflowClient.WORKFLOWSTATE_DELETED query param set to 'false' returns a 404 + // + int trials = 0; + int result = 0; + while (trials < 30) { + CollectionSpacePoxClient client = this.assertPoxClient(); + ClientResponse res = client.readIncludeDeleted(csid, Boolean.FALSE); + result = res.getStatus(); + if (result == STATUS_NOT_FOUND) { + logger.info("Workflow transition to 'deleted' is complete"); + break; + } else { + /* + * This should never happen, but if it does we need a full stack trace to help track it down. + */ + try { + throw new RuntimeException(ERROR_WORKFLOW_TRANSITION); + } catch (RuntimeException e) { + logger.info(ERROR_WORKFLOW_TRANSITION, e); + } + } + trials++; + } + Assert.assertEquals(result, STATUS_NOT_FOUND); + + } catch (UnsupportedOperationException e) { + logger.warn(this.getClass().getName() + " did not implement createWorkflowTarget() method. No workflow tests performed."); + return; + } } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#updateWithWrongXmlSchema(java.lang.String) + /* + * Test that searches honor the workflow deleted state. */ - @Override - public abstract void updateWithWrongXmlSchema(String testName) throws Exception; + @Test(dataProvider = "testName") + public void searchWorkflowDeleted(String testName) throws Exception { + + // FIXME: Temporarily avoid running test if client is of an authority service + CollectionSpacePoxClient client = this.assertPoxClient(); + if (isAuthorityClient(client)) { + return; + } + + try { + // + // Create 3 new objects + // + final int OBJECTS_TO_CREATE = 3; + final String KEYWORD = NON_EXISTENT_KEYWORD + createIdentifier(); + for (int i = 0; i < OBJECTS_TO_CREATE; i++) { + this.createWorkflowTarget(testName, KEYWORD); + } + + // + // Mark one as soft deleted + // + int existingTestCreated = allResourceIdsCreated.size(); // assumption is that no other test created records were soft deleted + String csid = allResourceIdsCreated.get(existingTestCreated - 1); //0-based index to get the last one added + this.setupUpdate(); + this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED); + + // + // Search for the newly-created records, excluding the soft deleted record. + // + // Send the search request and receive a response + ClientResponse res = client.keywordSearchIncludeDeleted(KEYWORD, Boolean.FALSE); + int result = res.getStatus(); + Assert.assertEquals(result, STATUS_OK); + + AbstractCommonList list = res.getEntity(); + long itemsMatchedBySearch = list.getTotalItems(); + Assert.assertEquals(itemsMatchedBySearch, OBJECTS_TO_CREATE - 1, + "The number of items marked for delete is not correct."); + // + // Search for the newly-created records, including the soft deleted record. + // + // Send the search request and receive a response + res = client.keywordSearchIncludeDeleted(KEYWORD, Boolean.TRUE); + result = res.getStatus(); + Assert.assertEquals(result, STATUS_OK); + list = res.getEntity(); + itemsMatchedBySearch = list.getTotalItems(); + Assert.assertEquals(itemsMatchedBySearch, OBJECTS_TO_CREATE, + "Deleted item was not returned in list results, even though it was requested to be included."); + + } catch (UnsupportedOperationException e) { + logger.warn(this.getClass().getName() + " did not implement createWorkflowTarget() method. No workflow tests performed."); + return; + } + } + + // --------------------------------------------------------------- + // Utility methods to support the test cases. + // + // --------------------------------------------------------------- + /** - * Sets up update tests with wrong xml schema. + * Checks if 'theFile' is something we can turn into a Blob instance. It can't + * be read-protected, hidden, or a directory. + * + * @param theFile the the file + * @return true, if is blobable */ - protected void setupUpdateWithWrongXmlSchema() { - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + protected boolean isBlobbable(File theFile) { + boolean result = true; + if (theFile.isDirectory() || theFile.isHidden() || !theFile.canRead()) { + result = false; + } + return result; } /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String) + * @see org.collectionspace.services.client.test.ServiceTest#createWithEmptyEntityBody(java.lang.String) */ @Override - public abstract void updateNonExistent(String testName) throws Exception; - - /** - * Sets up update non existent tests - */ - protected void setupUpdateNonExistent() { - EXPECTED_STATUS_CODE = STATUS_NOT_FOUND; - REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + public void createWithEmptyEntityBody(String testName) throws Exception { + //FIXME: Should this test really be empty? If so, please comment accordingly. } - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#delete(java.lang.String) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) */ @Override - public abstract void delete(String testName) throws Exception; - - /** - * Sets up delete tests. - */ - protected void setupDelete() { - EXPECTED_STATUS_CODE = STATUS_OK; - REQUEST_TYPE = ServiceRequestType.DELETE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + public void createWithMalformedXml(String testName) throws Exception { + //FIXME: Should this test really be empty? If so, please comment accordingly. } - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#deleteNonExistent(java.lang.String) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) */ @Override - public abstract void deleteNonExistent(String testName) throws Exception; + public void createWithWrongXmlSchema(String testName) throws Exception { + //FIXME: Should this test really be empty? If so, please comment accordingly. + } - /** - * Sets up delete non existent tests. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String) */ - protected void setupDeleteNonExistent() { - EXPECTED_STATUS_CODE = STATUS_NOT_FOUND; - REQUEST_TYPE = ServiceRequestType.DELETE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + @Override + @Test(dataProvider = "testName", + dependsOnMethods = {"create", "update"}) + public void updateNonExistent(String testName) throws Exception { + // Perform setup. + setupUpdateNonExistent(); + + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + CollectionSpaceClient client = this.getClientInstance(); + REQUEST_TYPE multipart = createNonExistenceInstance(client.getCommonPartName(), NON_EXISTENT_ID); + ClientResponse res = + client.update(NON_EXISTENT_ID, multipart); + 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); } - + // --------------------------------------------------------------- // Utility methods to clean up resources created during tests. // --------------------------------------------------------------- - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun = true) - public void cleanUp() { - String noTestCleanup = System.getProperty(NO_TEST_CLEANUP); - if (Boolean.TRUE.toString().equalsIgnoreCase(noTestCleanup)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - CollectionSpaceClient client = this.getClientInstance(); - // - // First, check to see if we need to cleanup any authority items - // - if (this.isAuthorityClient(client) == true) { - AuthorityClient authorityClient = (AuthorityClient) client; - for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { - String itemResourceId = entry.getKey(); - String authorityResourceId = entry.getValue(); - // Note: Any non-success responses are ignored and not reported. - authorityClient.deleteItem(authorityResourceId, itemResourceId).releaseConnection(); - } - } - // - // Next, delete all other entities include possible authorities. - // - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - client.delete(resourceId).releaseConnection(); - } - } // --------------------------------------------------------------- // Utility methods in support of list tests. @@ -470,14 +720,13 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements * @return the abstract common list * @throws Exception the exception */ - private AbstractCommonList readList(String testName, + private CLT readList(String testName, CollectionSpaceClient client, long pageSize, long pageNumber, int expectedStatus) throws Exception { return readList(testName, client, EMPTY_SORT_BY_ORDER, pageSize, pageNumber, expectedStatus); - } /** @@ -491,15 +740,15 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements * @return the abstract common list * @throws Exception the exception */ - private AbstractCommonList readList(String testName, + private CLT readList(String testName, CollectionSpaceClient client, String sortBy, long pageSize, long pageNumber, int expectedStatus) throws Exception { - ClientResponse response = + ClientResponse response = client.readList(sortBy, pageSize, pageNumber); - AbstractCommonList result = null; + CLT result = null; try { int statusCode = response.getStatus(); @@ -510,7 +759,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements } Assert.assertEquals(statusCode, expectedStatus); - result = this.getAbstractCommonList(response); + result = this.getCommonList(response); } finally { response.releaseConnection(); } @@ -518,19 +767,6 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements return result; } - /** - * Creates the list. - * - * @param testName the test name - * @param listSize the list size - * @throws Exception the exception - */ - protected void createPaginatedList(String testName, int listSize) throws Exception { - for (int i = 0; i < listSize; i++) { - create(testName); - } - } - /*@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void leafCreate(String testName) throws Exception { this.create(testName); @@ -541,97 +777,33 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements long expectedPageSize, long expectedListSize, long expectedTotalItems) { - Assert.assertNotNull(list); - - long pageNum = list.getPageNum(); - Assert.assertEquals(pageNum, expectedPageNum); - if (getLogger().isDebugEnabled() == true) { - getLogger().debug(testName + ":" + "page number is " + pageNum); - } - - long pageSizeReturned = list.getPageSize(); - Assert.assertEquals(pageSizeReturned, expectedPageSize); - if (getLogger().isDebugEnabled() == true) { - getLogger().debug(testName + ":" + "page size is " + list.getPageSize()); - } - - long itemsInPage = list.getItemsInPage(); - Assert.assertEquals(itemsInPage, expectedListSize); - if (getLogger().isDebugEnabled() == true) { - getLogger().debug(testName + ":" + "actual items in page was/were " + itemsInPage); - } - - long totalItemsReturned = list.getTotalItems(); - Assert.assertEquals(totalItemsReturned, expectedTotalItems); - if (getLogger().isDebugEnabled() == true) { - getLogger().debug(testName + ":" + "total number of items is " + list.getTotalItems()); - } - } - - /** - * Read paginated list. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName") /*, dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"leafCreate"}) */ - - public void readPaginatedList(String testName) throws Exception { - // Perform setup. - setupReadList(); - CollectionSpaceClient client = this.getClientInstance(); - - // Get the current total number of items. - // If there are no items then create some - AbstractCommonList list = (AbstractCommonList) this.readList(testName, - client, - 1 /*pgSz*/, - 0 /*pgNum*/, - EXPECTED_STATUS_CODE); - if (list == null || list.getTotalItems() == 0) { - this.createPaginatedList(testName, DEFAULT_PAGINATEDLIST_SIZE); - setupReadList(); - list = (AbstractCommonList) this.readList(testName, - client, - 1 /*pgSz*/, - 0 /*pgNum*/, - EXPECTED_STATUS_CODE); + Assert.assertNotNull(list); + + long pageNum = list.getPageNum(); + Assert.assertEquals(pageNum, expectedPageNum); + if (getLogger().isDebugEnabled() == true) { + getLogger().debug(testName + ":" + "page number is " + pageNum); } - // Print out the current list size to be paginated - Assert.assertNotNull(list); - long totalItems = list.getTotalItems(); - Assert.assertFalse(totalItems == 0); + long pageSizeReturned = list.getPageSize(); + Assert.assertEquals(pageSizeReturned, expectedPageSize); if (getLogger().isDebugEnabled() == true) { - getLogger().debug(testName + ":" + "created list of " - + totalItems + " to be paginated."); + getLogger().debug(testName + ":" + "page size is " + list.getPageSize()); } - long pageSize = totalItems / 3; //create up to 3 pages to iterate over - long pagesTotal = pageSize > 0 ? (totalItems / pageSize) : 0; - for (int i = 0; i < pagesTotal; i++) { - list = (AbstractCommonList) this.readList(testName, client, pageSize, i, EXPECTED_STATUS_CODE); - assertPaginationInfo(testName, - list, - i, //expected page number - pageSize, //expected page size - pageSize, //expected num of items in page - totalItems);//expected total num of items + long itemsInPage = list.getItemsInPage(); + Assert.assertEquals(itemsInPage, expectedListSize); + if (getLogger().isDebugEnabled() == true) { + getLogger().debug(testName + ":" + "actual items in page was/were " + itemsInPage); } - // if there are any remainders be sure to paginate them as well - long mod = pageSize != 0 ? totalItems % pageSize : totalItems; - if (mod != 0) { - list = (AbstractCommonList) this.readList(testName, client, pageSize, pagesTotal, EXPECTED_STATUS_CODE); - assertPaginationInfo(testName, - list, - pagesTotal, //expected page number - pageSize, //expected page size - mod, //expected num of items in page - totalItems);//expected total num of items + long totalItemsReturned = list.getTotalItems(); + Assert.assertEquals(totalItemsReturned, expectedTotalItems); + if (getLogger().isDebugEnabled() == true) { + getLogger().debug(testName + ":" + "total number of items is " + list.getTotalItems()); } } + @SuppressWarnings("rawtypes") protected void updateLifeCycleState(String testName, String resourceId, String lifeCycleState) throws Exception { @@ -640,11 +812,18 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements // CollectionSpaceClient client = this.getClientInstance(); ClientResponse res = client.getWorkflow(resourceId); - assertStatusCode(res, testName); - logger.debug("Got object to update life cycle state with ID: " + resourceId); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(workflowCommons); + WorkflowCommon workflowCommons = null; + try { + assertStatusCode(res, testName); + logger.debug("Got object to update life cycle state with ID: " + resourceId); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); + Assert.assertNotNull(workflowCommons); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // // Mark it for a soft delete. // @@ -655,30 +834,45 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements // // Perform the update // + WorkflowCommon updatedWorkflowCommons = null; res = client.updateWorkflow(resourceId, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(updatedWorkflowCommons); + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); + Assert.assertNotNull(updatedWorkflowCommons); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // // Read the updated object and make sure it was updated correctly. // int trials = 0; while (trials < 30) { res = client.getWorkflow(resourceId); - assertStatusCode(res, testName); - logger.debug("Got workflow state of updated object with ID: " + resourceId); - input = new PoxPayloadIn(res.getEntity()); - updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(workflowCommons); - String currentWorkflowState = updatedWorkflowCommons.getCurrentLifeCycleState(); - if (currentWorkflowState.equalsIgnoreCase(lifeCycleState)) { - logger.debug("Expected workflow state found: " + lifeCycleState); - break; + try { + assertStatusCode(res, testName); + logger.debug("Got workflow state of updated object with ID: " + resourceId); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); + Assert.assertNotNull(workflowCommons); + String currentWorkflowState = updatedWorkflowCommons.getCurrentLifeCycleState(); + if (currentWorkflowState.equalsIgnoreCase(lifeCycleState)) { + logger.debug("Expected workflow state found: " + lifeCycleState); + break; + } + } finally { + if (res != null) { + res.releaseConnection(); + } } trials++; } - + // + // Finally, assert the state change happened as expected. + // Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState); } @@ -698,35 +892,39 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements } protected long readIncludeDeleted(String testName, Boolean includeDeleted) { - long result = 0; - // Perform setup. - setupReadList(); - - // - // Ask for a list of all resources filtered by the incoming 'includeDeleted' workflow param - // - CollectionSpacePoxClient client = assertPoxClient(); - ClientResponse res = client.readIncludeDeleted(includeDeleted); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - // - // Now check that list size is correct - // - /* - List items = - list.getListItem(); - result = items.size(); - */ - result = list.getTotalItems(); + long result = 0; + // Perform setup. + setupReadList(); + + // + // Ask for a list of all resources filtered by the incoming 'includeDeleted' workflow param + // + CollectionSpacePoxClient client = assertPoxClient(); + ClientResponse res = client.readIncludeDeleted(includeDeleted); + try { + // + // Check the status code of the response: does it match + // the expected response(s)? + // + assertStatusCode(res, testName); + AbstractCommonList list = res.getEntity(); + // + // Now check that list size is correct + // + result = list.getTotalItems(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } - return result; + return result; } protected long readItemsIncludeDeleted(String testName, String parentCsid, Boolean includeDeleted) { long result = 0; // Perform setup. setupReadList(); - // // Ask for a list of all resources filtered by the incoming 'includeDeleted' workflow param // @@ -735,148 +933,32 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements null, /* partial terms */ null, /* keywords */ includeDeleted); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - result = list.getTotalItems(); - - return result; - } - - /* - * This test assumes that no objects exist yet. - * - * http://localhost:8180/cspace-services/intakes?wf_deleted=false - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void readWorkflow(String testName) throws Exception { - try { - // - // Get the total count of non-deleted existing records - // - long existingRecords = readIncludeDeleted(testName, Boolean.FALSE); - - // - // Create 3 new objects - // - final int OBJECTS_TO_CREATE = 3; - for (int i = 0; i < OBJECTS_TO_CREATE; i++) { - this.createWorkflowTarget(testName); - } - - // - // Mark one as soft deleted - // - int existingTestCreated = allResourceIdsCreated.size(); // assumption is that no other test created records were soft deleted - String csid = allResourceIdsCreated.get(existingTestCreated - 1); //0-based index to get the last one added - this.setupUpdate(); - this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED); - // - // Read the list of existing non-deleted records - // - long updatedTotal = readIncludeDeleted(testName, Boolean.FALSE); - Assert.assertEquals(updatedTotal, existingRecords + OBJECTS_TO_CREATE - 1, "Deleted items seem to be returned in list results."); - - // - // Next, test that a GET with WorkflowClient.WORKFLOWSTATE_DELETED query param set to 'false' returns a 404 - // - int trials = 0; - int result = 0; - while (trials < 30) { - CollectionSpacePoxClient client = this.assertPoxClient(); - ClientResponse res = client.readIncludeDeleted(csid, Boolean.FALSE); - result = res.getStatus(); - if (result == STATUS_NOT_FOUND) { - logger.info("Workflow transition to 'deleted' is complete"); - break; - } - trials++; - } - Assert.assertEquals(result, STATUS_NOT_FOUND); - - } catch (UnsupportedOperationException e) { - logger.warn(this.getClass().getName() + " did not implement createWorkflowTarget() method. No workflow tests performed."); - return; - } - } - - /* - * Test that searches honor the workflow deleted state. - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void searchWorkflowDeleted(String testName) throws Exception { - - // FIXME: Temporarily avoid running test if client is of an authority service - CollectionSpacePoxClient client = this.assertPoxClient(); - if (isAuthorityClient(client)) { - return; - } - try { - - // - // Create 3 new objects - // - final int OBJECTS_TO_CREATE = 3; - final String KEYWORD = NON_EXISTENT_KEYWORD + createIdentifier(); - for (int i = 0; i < OBJECTS_TO_CREATE; i++) { - this.createWorkflowTarget(testName, KEYWORD); + assertStatusCode(res, testName); + AbstractCommonList list = res.getEntity(); + result = list.getTotalItems(); + } finally { + if (res != null) { + res.releaseConnection(); } - - // - // Mark one as soft deleted - // - int existingTestCreated = allResourceIdsCreated.size(); // assumption is that no other test created records were soft deleted - String csid = allResourceIdsCreated.get(existingTestCreated - 1); //0-based index to get the last one added - this.setupUpdate(); - this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED); - - // - // Search for the newly-created records, excluding the soft deleted record. - // - // Send the search request and receive a response - ClientResponse res = client.keywordSearchIncludeDeleted(KEYWORD, Boolean.FALSE); - int result = res.getStatus(); - assertStatusCode(res, testName); - - AbstractCommonList list = res.getEntity(); - long itemsMatchedBySearch = list.getTotalItems(); - Assert.assertEquals(itemsMatchedBySearch, OBJECTS_TO_CREATE - 1, - "Deleted items seem to be returned in list results."); - - // - // Search for the newly-created records, including the soft deleted record. - // - // Send the search request and receive a response - res = client.keywordSearchIncludeDeleted(KEYWORD, Boolean.TRUE); - result = res.getStatus(); - assertStatusCode(res, testName); - - list = res.getEntity(); - itemsMatchedBySearch = list.getTotalItems(); - Assert.assertEquals(itemsMatchedBySearch, OBJECTS_TO_CREATE, - "Deleted item was not returned in list results, even though it was requested to be included."); - - } catch (UnsupportedOperationException e) { - logger.warn(this.getClass().getName() + " did not implement createWorkflowTarget() method. No workflow tests performed."); - return; } + + return result; } - protected String createTestObject(String testName) throws Exception { + protected String createTestObject() throws Exception { String identifier = createIdentifier(); - String result = createTestObject(testName, identifier); + String result = createTestObject(identifier); return result; - } - protected String createTestObject(String testName, String identifier) throws Exception { + protected String createTestObject(String identifier) throws Exception { String result = null; - CollectionSpacePoxClient client = (CollectionSpacePoxClient) getClientInstance(); - PoxPayloadOut multipart = createInstance(identifier); - ClientResponse res = client.create(multipart); + CollectionSpaceClient client = getClientInstance(); + REQUEST_TYPE payload = createInstance(identifier); + ClientResponse res = client.create(payload); int statusCode = res.getStatus(); Assert.assertEquals(statusCode, STATUS_CREATED); @@ -889,55 +971,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements protected String createWorkflowTarget(String testName) throws Exception { String result = null; - result = createTestObject(testName); + result = createTestObject(); return result; } protected String createWorkflowTarget(String testName, String keyword) throws Exception { String result = null; - result = createTestObject(testName, keyword); + result = createTestObject(keyword); return result; } - /* - * Sub-classes must override for the workflow tests. - */ - protected PoxPayloadOut createInstance(String identifier) { - logger.warn("Sub-class test clients should override this method"); - - - throw new UnsupportedOperationException(); - - - - } - - /* - * Test classes for authority services should override these method and return 'true' - */ - protected boolean isAuthorityClient(CollectionSpaceClient theClient) { - return AuthorityClient.class.isInstance(theClient); - } - protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) { logger.warn("Sub-class test clients should override this method"); - - throw new UnsupportedOperationException(); - - } final protected String createWorkflowItemTarget(String testName, String parentCsid) throws Exception { String result = null; - result = createTestItemObject(testName, parentCsid); - - - return result; - - } protected String createTestItemObject(String testName, String parentCsid) throws Exception { @@ -948,19 +1000,13 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements PoxPayloadOut multipart = createItemInstance(parentCsid, identifier); ClientResponse res = client.createItem(parentCsid, multipart); - - int statusCode = res.getStatus(); Assert.assertEquals(statusCode, STATUS_CREATED); result = extractId(res); allResourceItemIdsCreated.put(result, parentCsid); - - return result; - - } /* @@ -968,7 +1014,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements * * http://localhost:8180/cspace-services/intakes?wf_deleted=false */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void readAuthorityItemWorkflow(String testName) throws Exception { // // Run this test only if the client is an AuthorityClient //FIXME: REM - Replace this will an AuthorityServiceTest class @@ -986,27 +1032,20 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements final int OBJECTS_TO_CREATE = 3; String lastCreatedItem = null; - - for (int i = 0; i - < OBJECTS_TO_CREATE; i++) { + for (int i = 0; i < OBJECTS_TO_CREATE; i++) { lastCreatedItem = this.createWorkflowItemTarget(testName, parentCsid); - - } // // Mark one item as soft deleted // String csid = lastCreatedItem; - this.setupUpdate(); - this.updateItemLifeCycleState(testName, parentCsid, csid, WorkflowClient.WORKFLOWSTATE_DELETED); // // Read the list of existing non-deleted records // - long updatedTotal = readItemsIncludeDeleted(testName, parentCsid, Boolean.FALSE); Assert.assertEquals(updatedTotal, OBJECTS_TO_CREATE - 1, "Deleted items seem to be returned in list results."); @@ -1016,19 +1055,12 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements AuthorityClient client = (AuthorityClient) this.getClientInstance(); ClientResponse res = client.readItem(parentCsid, csid, Boolean.FALSE); - int result = res.getStatus(); Assert.assertEquals(result, STATUS_NOT_FOUND); - - } catch (UnsupportedOperationException e) { logger.warn(this.getClass().getName() + " did not implement createWorkflowTarget() method. No workflow tests performed."); - - return; - - } } } @@ -1039,27 +1071,40 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements // AuthorityClient client = (AuthorityClient) this.getClientInstance(); ClientResponse res = client.readItemWorkflow(parentCsid, itemCsid); - assertStatusCode(res, testName); - logger.debug("Got object to update life cycle state with ID: " + itemCsid); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(workflowCommons); + WorkflowCommon workflowCommons = null; + try { + assertStatusCode(res, testName); + logger.debug("Got object to update life cycle state with ID: " + itemCsid); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); + Assert.assertNotNull(workflowCommons); + logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class)); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // - // Mark it for a soft delete. + // Mark it for a state change. // - logger.debug( - "Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class)); workflowCommons.setCurrentLifeCycleState(lifeCycleState); PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME); PayloadOutputPart commonPart = output.addPart(WorkflowClient.SERVICE_COMMONPART_NAME, workflowCommons); // - // Perform the update + // Perform the state change update // res = client.updateItemWorkflow(parentCsid, itemCsid, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(updatedWorkflowCommons); + WorkflowCommon updatedWorkflowCommons = null; + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); + Assert.assertNotNull(updatedWorkflowCommons); + } finally { + if (res != null) { + res.releaseConnection(); + } + } int trials = 0; boolean passed = false; @@ -1068,23 +1113,33 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements // Read the updated object and make sure it was updated correctly. // res = client.readItemWorkflow(parentCsid, itemCsid); - assertStatusCode(res, testName); - logger.debug( - "Got workflow state of updated object with ID: " + itemCsid); - input = new PoxPayloadIn(res.getEntity()); - updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(workflowCommons); - String currentState = updatedWorkflowCommons.getCurrentLifeCycleState(); - if (currentState.equalsIgnoreCase(lifeCycleState)) { - logger.debug("Expected workflow state found: " + lifeCycleState); - break; + try { + assertStatusCode(res, testName); + logger.debug( + "Got workflow state of updated object with ID: " + itemCsid); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); + Assert.assertNotNull(workflowCommons); + String currentState = updatedWorkflowCommons.getCurrentLifeCycleState(); + if (currentState.equalsIgnoreCase(lifeCycleState)) { + logger.debug("Expected workflow state found: " + lifeCycleState); + break; + } + logger.debug("Workflow state not yet updated for object with id: " + itemCsid + " state is=" + + currentState); + } finally { + if (res != null) { + res.releaseConnection(); + } } - logger.debug("Workflow state not yet updated for object with id: " + itemCsid + " state is=" + - currentState); trials++; } + // + // Finally check to see if the state change was updated as expected. + // Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState); } + } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java index b32d6ee59..7ec701d0c 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java @@ -28,8 +28,13 @@ import java.io.File; import java.io.InputStream; import java.io.StringWriter; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Random; +import javax.activation.MimetypesFileTypeMap; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.xml.bind.JAXBContext; @@ -46,18 +51,21 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.io.FileUtils; + import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.w3c.dom.Document; +import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.TestServiceClient; - import org.collectionspace.services.jaxb.AbstractCommonList; /** @@ -71,20 +79,39 @@ import org.collectionspace.services.jaxb.AbstractCommonList; // FIXME: http://issues.collectionspace.org/browse/CSPACE-1685 -public abstract class BaseServiceTest { - +/* + * - Common list type + */ +public abstract class BaseServiceTest { + //A default MIME type result + static protected final String DEFAULT_MIME = "application/octet-stream; charset=ISO-8859-1"; //Maven's base directory -i.e., the one containing the current pom.xml protected static final String MAVEN_BASEDIR_PROPERTY = "maven.basedir"; /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class); /** The Constant serviceClient. */ protected static final TestServiceClient serviceClient = new TestServiceClient(); + + protected String knownResourceIdentifier = null; + /** Use this to keep track of a single known resource */ + protected String knownResourceId = null; + /* Use this to keep track of resources to delete */ + protected List allResourceIdsCreated = new ArrayList(); + /* Use this to track authority items */ + protected Map allResourceItemIdsCreated = new HashMap(); /* itemCsid, parentCsid */ + /* A runtime/command-line parameter to indicate if we should delete all the test related resource objects */ + static private final String NO_TEST_CLEANUP = "noTestCleanup"; + /* A random number generator */ + static private final Random random = new Random(System.currentTimeMillis()); + + /** The non-existent id. */ protected final String NON_EXISTENT_ID = createNonExistentIdentifier(); /** The expected status code. */ - protected int EXPECTED_STATUS_CODE = 0; + protected int testExpectedStatusCode = 0; /** The request type type. */ - protected ServiceRequestType REQUEST_TYPE = ServiceRequestType.NON_EXISTENT; + protected ServiceRequestType testRequestType = ServiceRequestType.NON_EXISTENT; + /** The Constant XML_DECLARATION. */ protected static final String XML_DECLARATION = ""; /** The Constant MALFORMED_XML_DATA. */ @@ -95,13 +122,11 @@ public abstract class BaseServiceTest { + "wrong schema contents"; /** The null charset. */ private static final String NULL_CHARSET = null; - - private static final String BANNER_SEPARATOR_LINE = - "==================================================="; - private static final String BANNER_PREFIX = - "\n" + BANNER_SEPARATOR_LINE + "\n"; - private static final String BANNER_SUFFIX = - "\n" + BANNER_SEPARATOR_LINE; + + /** A visual separator for our test banners */ + private static final String BANNER_SEPARATOR_LINE = "==================================================="; + private static final String BANNER_PREFIX = "\n" + BANNER_SEPARATOR_LINE + "\n"; + private static final String BANNER_SUFFIX = "\n" + BANNER_SEPARATOR_LINE; // A Unicode UTF-8 data fragment for use in test payloads: a random sequence, // unlikely to be encountered in actual collections data, and capable of @@ -116,7 +141,9 @@ public abstract class BaseServiceTest { // Ω : Greek capital letter Omega (U+03A9) private final static String UTF8_DATA_FRAGMENT = "utf-8-data-fragment:" + '\u0394' + '\u04C1' + '\u0174' +'\u03A9'; - + // + // Status constants + // protected static final int STATUS_BAD_REQUEST = Response.Status.BAD_REQUEST.getStatusCode(); protected static final int STATUS_CREATED = @@ -126,7 +153,9 @@ public abstract class BaseServiceTest { protected static final int STATUS_NOT_FOUND = Response.Status.NOT_FOUND.getStatusCode(); protected static final int STATUS_OK = - Response.Status.OK.getStatusCode(); + Response.Status.OK.getStatusCode(); + protected static final int STATUS_FORBIDDEN = + Response.Status.FORBIDDEN.getStatusCode(); /** * Instantiates a new base service test. @@ -135,6 +164,18 @@ public abstract class BaseServiceTest { super(); } + /* + * A getter for retrieving the tests logger + */ + protected Logger getLogger() { + return this.logger; + } + + @BeforeMethod + protected void beforeMethod(Method m) { + logTestBanner(getLogger(), m.getName()); + } + /** * Gets the client. * @@ -142,15 +183,18 @@ public abstract class BaseServiceTest { */ abstract protected CollectionSpaceClient getClientInstance(); - /** - * Gets the abstract common list. - * - * @param response the response - * @return the abstract common list + /* + * Subclasses can override this method to return their AbstractCommonList subclass */ - abstract protected AbstractCommonList getAbstractCommonList( - ClientResponse response); + protected Class getCommonListType() { + return (Class)AbstractCommonList.class; + } + protected CLT getCommonList( + ClientResponse response) { + return response.getEntity(getCommonListType()); + } + /** * Returns the name of the currently running test. * @@ -184,10 +228,19 @@ public abstract class BaseServiceTest { * of those values between tests. */ protected void clearSetup() { - EXPECTED_STATUS_CODE = 0; - REQUEST_TYPE = ServiceRequestType.NON_EXISTENT; + testExpectedStatusCode = 0; + testRequestType = ServiceRequestType.NON_EXISTENT; } + /** + * Sets up create tests. + */ + protected void setupCreate() { + testExpectedStatusCode = STATUS_CREATED; + testRequestType = ServiceRequestType.CREATE; + testSetup(testExpectedStatusCode, testRequestType); + } + /** * Initializes setup values for a given test. * @@ -199,8 +252,8 @@ public abstract class BaseServiceTest { int expectedStatusCode, ServiceRequestType reqType) { clearSetup(); - EXPECTED_STATUS_CODE = expectedStatusCode; - REQUEST_TYPE = reqType; + testExpectedStatusCode = expectedStatusCode; + testRequestType = reqType; } /** @@ -348,14 +401,30 @@ public abstract class BaseServiceTest { } /** - * Creates the identifier. - * - * @return the string + * Tests can override this method to customize their identifiers. */ - static protected String createIdentifier() { - long identifier = System.currentTimeMillis(); + protected String createIdentifier() { + long identifier = System.currentTimeMillis() + random.nextInt(); return Long.toString(identifier); } + + /** + * Tests can override this method to customize their identifiers. + */ + protected String getKnowResourceIdentifier() { + if (knownResourceIdentifier == null) { + knownResourceIdentifier = createIdentifier(); + } + return knownResourceIdentifier; + } + + /** + * Tests can override this method if they have a different knownResourceId + * @return + */ + protected String getKnowResourceId() { + return this.knownResourceId; + } /** * Creates the non existent identifier. @@ -440,6 +509,20 @@ public abstract class BaseServiceTest { } return sw.toString(); } + + static protected String objectAsXmlString(Object o) { + StringWriter sw = new StringWriter(); + try { + JAXBContext jc = JAXBContext.newInstance(o.getClass()); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(o, sw); + } catch (Exception e) { + e.printStackTrace(); + } + return sw.toString(); + } /** * getObjectFromFile get object of given class from given file (in classpath) @@ -520,6 +603,22 @@ public abstract class BaseServiceTest { return sb.toString(); } + /** + * Returns a 'banner', consisting of a text label inside a pair of prefix + * and suffix strings. + * + * @param label The label to be output inside the banner. + * + * @return The banner. + */ + protected static String getBannerStr(String label) { + StringBuffer sb = new StringBuffer(); + sb.append(BANNER_PREFIX); + sb.append(label); + sb.append(BANNER_SUFFIX); + return sb.toString(); + } + /** * Returns a test-specific banner. * @@ -527,10 +626,10 @@ public abstract class BaseServiceTest { * * @return A test-specific banner. */ - protected static String testBanner(String testName) { + private static String getNameBanner(String testName) { testName = (testName == null || testName.trim().isEmpty()) ? " Test = no test name specified" : " Test = " + testName; - return banner(testName); + return testName; } /** @@ -542,29 +641,26 @@ public abstract class BaseServiceTest { * * @return A test-specific banner. */ - protected static String testBanner(String testName, String testClass) { - testName = (testName == null || testName.trim().isEmpty()) ? - " Test = no test name specified" : " Test = " + testName; + private static String getBanner(String testName, String testClass) { + testName = getNameBanner(testName); testClass = (testClass == null || testClass.trim().isEmpty()) ? "Class = no test class specified" : "Class = " + classNameFromPackageName(testClass); String testLabel = testClass + "\n" + testName; - return banner(testLabel); + return getBannerStr(testLabel); } - - /** - * Returns a 'banner', consisting of a text label inside a pair of prefix - * and suffix strings. - * - * @param label The label to be output inside the banner. - * - * @return The banner. - */ - protected static String banner(String label) { - StringBuffer sb = new StringBuffer(); - sb.append(BANNER_PREFIX); - sb.append(label); - sb.append(BANNER_SUFFIX); - return sb.toString(); + + protected static String getTestBanner(String testName, String testClassName) { + return getBanner(testName, testClassName); + } + + protected String getTestBanner(String testName) { + return getTestBanner(testName, this.getClass().getCanonicalName()); + } + + protected void logTestBanner(Logger logger, String testName) { + if (logger.isDebugEnabled() == true) { + logger.debug(getTestBanner(testName)); + } } protected static String classNameFromPackageName(String className) { @@ -579,16 +675,248 @@ public abstract class BaseServiceTest { return className; } - public void assertStatusCode(ClientResponse res, String testName) { + public int assertStatusCode(ClientResponse res, String testName) { int statusCode = res.getStatus(); + // Check the status code of the response: does it match the expected response(s)? logger.debug(testName + ": status = " + statusCode); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + return statusCode; } public static String getUTF8DataFragment() { return UTF8_DATA_FRAGMENT; } + protected String getMimeType(File theFile) { + String result = null; + result = new MimetypesFileTypeMap().getContentType(theFile); + if (result == null) { + logger.debug("Could not get MIME type for file at: " + theFile.getAbsolutePath()); + result = DEFAULT_MIME; + } + + return result; + } + + /* + * Test classes for authority services should override these method and return 'true' + */ + protected boolean isAuthorityClient(CollectionSpaceClient theClient) { + return AuthorityClient.class.isInstance(theClient); + } + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + @AfterClass(alwaysRun = true) + public void cleanUp() { + String noTestCleanup = System.getProperty(NO_TEST_CLEANUP); + if (Boolean.TRUE.toString().equalsIgnoreCase(noTestCleanup)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + CollectionSpaceClient client = this.getClientInstance(); + // + // First, check to see if we need to cleanup any authority items + // + if (this.isAuthorityClient(client) == true) { + AuthorityClient authorityClient = (AuthorityClient) client; + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { + String itemResourceId = entry.getKey(); + String authorityResourceId = entry.getValue(); + // Note: Any non-success responses are ignored and not reported. + authorityClient.deleteItem(authorityResourceId, itemResourceId).releaseConnection(); + } + } + // + // Next, delete all other entities include possible authorities. + // + for (String resourceId : allResourceIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + client.delete(resourceId).releaseConnection(); + } + } + + // + // Status code setup methods for tests + // + + /** + * Sets up create tests with malformed xml. + */ + protected void setupCreateWithMalformedXml() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.CREATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up create tests with wrong xml schema. + */ + protected void setupCreateWithWrongXmlSchema() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.CREATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up read tests. + */ + protected void setupRead() { + testExpectedStatusCode = STATUS_OK; + testRequestType = ServiceRequestType.READ; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up read tests. + */ + protected void setupForbidden() { + testExpectedStatusCode = STATUS_FORBIDDEN; + testRequestType = ServiceRequestType.READ; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up read non existent tests. + */ + protected void setupReadNonExistent() { + testExpectedStatusCode = STATUS_NOT_FOUND; + testRequestType = ServiceRequestType.READ; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up read list tests. + */ + protected void setupReadList() { + testExpectedStatusCode = STATUS_OK; + testRequestType = ServiceRequestType.READ_LIST; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up update tests. + */ + protected void setupUpdate() { + testExpectedStatusCode = STATUS_OK; + testRequestType = ServiceRequestType.UPDATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up update tests with an empty entity body. + */ + protected void setupUpdateWithEmptyEntityBody() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.UPDATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up update tests with malformed xml. + */ + protected void setupUpdateWithMalformedXml() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.UPDATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up update tests with wrong xml schema. + */ + protected void setupUpdateWithWrongXmlSchema() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.UPDATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up update non existent tests + */ + protected void setupUpdateNonExistent() { + testExpectedStatusCode = STATUS_NOT_FOUND; + testRequestType = ServiceRequestType.UPDATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up delete tests. + */ + protected void setupDelete() { + testExpectedStatusCode = STATUS_OK; + testRequestType = ServiceRequestType.DELETE; + testSetup(testExpectedStatusCode, testRequestType); + } + + // Failure outcomes + + /** + * Sets up delete non existent tests. + */ + protected void setupDeleteNonExistent() { + testExpectedStatusCode = STATUS_NOT_FOUND; + testRequestType = ServiceRequestType.DELETE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up create tests with empty entity body. + */ + protected void setupCreateWithEmptyEntityBody() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.CREATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up create tests with empty entity body. + */ + protected void setupCreateWithInvalidBody() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.CREATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + /** + * Sets up create tests with empty entity body. + */ + protected void setupUpdateWithInvalidBody() { + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.UPDATE; + testSetup(testExpectedStatusCode, testRequestType); + } + + public void updateWithEmptyEntityBody(String testName) throws Exception { + //FIXME: Should this test really be empty? If so, please comment accordingly. + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ + public void updateWithMalformedXml(String testName) throws Exception { + //FIXME: Should this test really be empty? If so, please comment accordingly. + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ + public void updateWithWrongXmlSchema(String testName) throws Exception { + //FIXME: Should this test really be empty? If so, please comment accordingly. + } + } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceRequestType.java b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceRequestType.java index b6c918ae0..b28313d4b 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceRequestType.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceRequestType.java @@ -25,9 +25,6 @@ package org.collectionspace.services.client.test; import java.util.Arrays; import javax.ws.rs.core.Response; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * ServiceRequestType, identifies types of service requests * and the valid HTTP status codes that can be returned from diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java index 2958bca3d..9eeea0063 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java @@ -39,8 +39,30 @@ public interface ServiceTest { // CRUD tests : CREATE tests // --------------------------------------------------------------- + /* + * We use this method to force a TestNG execution order for our tests. The "leaf" methods + * should look something like this: + * + // + // For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + // refer to this method in their @Test annotation declarations. + // + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests() { + // Do nothing. Simply here to for a TestNG execution order for our tests + } + * + * For an example, see the CollectionObjectServiceTest class. + * + */ + public void CRUDTests(String testName); + // Success outcomes + public void searchWorkflowDeleted(String testName) throws Exception; + /** * Tests creation of a new resource. * @@ -49,7 +71,7 @@ public interface ServiceTest { * @throws Exception */ public void create(String testName) throws Exception; - + /** * Tests creation of a list of two or more new resources by repeatedly * calling create(), and relies on the latter's test assertion(s). @@ -190,7 +212,6 @@ public interface ServiceTest { */ public void updateNonExistent(String testName) throws Exception; - // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- diff --git a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java index 108009054..4e5ddc2eb 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java @@ -16,8 +16,11 @@ */ package org.collectionspace.services.client.workflow; +import javax.ws.rs.core.Response; + import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.client.AbstractPoxServiceClientImpl; +import org.collectionspace.services.client.AbstractCommonListPoxServiceClientImpl; +import org.jboss.resteasy.client.ClientResponse; /** * WorkflowClient.java @@ -26,7 +29,7 @@ import org.collectionspace.services.client.AbstractPoxServiceClientImpl; * $LastChangedDate: 2010-05-17 18:25:37 -0700 (Mon, 17 May 2010) $ * */ -public class WorkflowClient extends AbstractPoxServiceClientImpl { +public class WorkflowClient extends AbstractCommonListPoxServiceClientImpl { public static final String SERVICE_NAME = "workflow"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -53,11 +56,29 @@ public class WorkflowClient extends AbstractPoxServiceClientImpl getProxyClass() { // TODO Auto-generated method stub return WorkflowProxy.class; } + + /* + * Proxied service calls + */ + + @Override + public ClientResponse readList() { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.AbstractServiceClientImpl#delete(java.lang.String) + */ + @Override + public ClientResponse delete(String csid) { + throw new UnsupportedOperationException(); + } + } diff --git a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowProxy.java b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowProxy.java index b523d5b2d..6be4834bb 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowProxy.java @@ -1,14 +1,10 @@ package org.collectionspace.services.client.workflow; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import org.collectionspace.services.client.CollectionSpacePoxProxy; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; +import org.collectionspace.services.client.CollectionSpaceCommonListPoxProxy; /** * @version $Revision: 2108 $ @@ -16,5 +12,5 @@ import org.jboss.resteasy.client.ClientResponse; @Path(WorkflowClient.SERVICE_PATH + "/") @Produces({"application/xml"}) @Consumes({"application/xml"}) -public interface WorkflowProxy extends CollectionSpacePoxProxy { +public interface WorkflowProxy extends CollectionSpaceCommonListPoxProxy { } diff --git a/services/collectionobject/client/pom.xml b/services/collectionobject/client/pom.xml index 58edea146..789e592a4 100644 --- a/services/collectionobject/client/pom.xml +++ b/services/collectionobject/client/pom.xml @@ -65,7 +65,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java index 7732c62b9..e41e3e0de 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java @@ -61,7 +61,6 @@ public class CollectionObjectClient extends AbstractCommonListPoxServiceClientIm return CollectionObjectProxy.class; } - /** * Roundtrip. * @@ -77,19 +76,4 @@ public class CollectionObjectClient extends AbstractCommonListPoxServiceClientIm getLogger().debug("<<< - */ - /* - public ClientResponse keywordSearch(String keywords) { - return getProxy().keywordSearch(keywords); - } - * - */ } diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java index 6d4c1ec13..aaa9b193d 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java @@ -56,7 +56,6 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -71,7 +70,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 1327 $ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ */ -public class CollectionObjectAuthRefsTest extends BaseServiceTest { +public class CollectionObjectAuthRefsTest extends BaseServiceTest { @Override protected CollectionSpaceClient getClientInstance() { @@ -98,9 +97,6 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { /** The organization authority name. */ final String ORG_AUTHORITY_NAME = "TestOrgAuth"; - /** The known resource id. */ - private String knownResourceId = null; - /** The collection object ids created. */ private List collectionObjectIdsCreated = new ArrayList(); @@ -154,16 +150,7 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { /** The number of authority references expected. */ private final int NUM_AUTH_REFS_EXPECTED = 4; - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - throw new UnsupportedOperationException(); //method not supported (or needed) in this test class - } - + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -174,14 +161,8 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) - public void createWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - testSetup(STATUS_CREATED, ServiceRequestType.CREATE); - + @Test(dataProvider="testName") + public void createWithAuthRefs(String testName) throws Exception { // Create all the person refs and entities createPersonRefs(); @@ -206,27 +187,21 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + testSetup(STATUS_CREATED, ServiceRequestType.CREATE); ClientResponse res = collectionObjectClient.create(multipart); - - 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); + String newCsid = null; + try { + assertStatusCode(res, testName); + newCsid = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ - knownResourceId = extractId(res); + knownResourceId = newCsid; if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -251,8 +226,8 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); personAuthRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); @@ -278,8 +253,8 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } @@ -345,8 +320,8 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { ClientResponse res = orgAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); orgAuthCSID = extractId(res); orgAuthRefName = OrgAuthorityClientUtils.getAuthorityRefName(orgAuthCSID, null); @@ -372,8 +347,8 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { ClientResponse res = orgAuthClient.createItem(orgAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } @@ -413,31 +388,41 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); - - // Submit the request to the service and store the response. + // + // First read the object + // CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); ClientResponse res = collectionObjectClient.read(knownResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - CollectionobjectsCommon collectionObject = (CollectionobjectsCommon) extractPart(input, - collectionObjectClient.getCommonPartName(), CollectionobjectsCommon.class); - Assert.assertNotNull(collectionObject); - - // Get all of the auth refs and check that the expected number is returned + CollectionobjectsCommon collectionObject = null; + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + collectionObject = (CollectionobjectsCommon) extractPart(input, + collectionObjectClient.getCommonPartName(), CollectionobjectsCommon.class); + Assert.assertNotNull(collectionObject); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + // + // Next, get all of the auth refs and check that the expected number is returned + // ClientResponse res2 = collectionObjectClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - - AuthorityRefList list = res2.getEntity(); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java index 5afc85d2e..28df7e0fb 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java @@ -29,12 +29,12 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.CollectionObjectJAXBSchema; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -52,7 +52,7 @@ import org.testng.annotations.Test; * $LastChangedRevision: 1327 $ $LastChangedDate: 2010-02-12 10:35:11 -0800 * (Fri, 12 Feb 2010) $ */ -public class CollectionObjectSearchTest extends BaseServiceTest { +public class CollectionObjectSearchTest extends BaseServiceTest { /** The logger. */ private final String CLASS_NAME = CollectionObjectSearchTest.class @@ -125,19 +125,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { protected CollectionSpaceClient getClientInstance() { return new CollectionObjectClient(); } - - /* - * (non-Javadoc) - * - * @see org.collectionspace.services.client.test.BaseServiceTest# - * getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(AbstractCommonList.class); - } - + /** * Creates one or more resources containing a "noise" keyword, which should * NOT be retrieved by keyword searches. @@ -163,11 +151,6 @@ public class CollectionObjectSearchTest extends BaseServiceTest { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, groups = { "advancedSearch" }) public void advancedSearch(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Create one or more keyword retrievable resources, each containing // a specified keyword. String theKeyword = KEYWORD + "COW"; @@ -189,9 +172,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -202,11 +185,6 @@ public class CollectionObjectSearchTest extends BaseServiceTest { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, groups = { "oneKeyword" }) public void searchWithOneKeyword(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Create one or more keyword retrievable resources, each containing // a specified keyword. long numKeywordRetrievableResources = (long) (numNoiseWordResources * pctNonNoiseWordResources); @@ -228,9 +206,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -242,11 +220,6 @@ public class CollectionObjectSearchTest extends BaseServiceTest { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWithTwoKeywordsInSameField(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Create one or more keyword retrievable resources, each containing // two specified keywords. long numKeywordRetrievableResources = (long) (numNoiseWordResources * pctNonNoiseWordResources); @@ -272,9 +245,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -293,9 +266,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -308,11 +281,6 @@ public class CollectionObjectSearchTest extends BaseServiceTest { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWithTwoKeywordsAcrossTwoFields(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Create one or more keyword retrievable resources, each containing // two specified keywords. long numKeywordRetrievableResources = 5; @@ -338,9 +306,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -359,9 +327,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -384,11 +352,6 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, groups = { "utf8" }) public void searchWithUTF8Keyword(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Create one or more keyword retrievable resources, each containing // two specified keywords. long numKeywordRetrievableResources = 2; @@ -410,9 +373,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -426,11 +389,6 @@ public class CollectionObjectSearchTest extends BaseServiceTest { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void keywordSearchNonExistentKeyword(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Set the expected status code and group of valid status codes testSetup(STATUS_OK, ServiceRequestType.SEARCH); @@ -443,9 +401,9 @@ public class CollectionObjectSearchTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Verify that the number of resources matched by the search // is identical to the expected result @@ -506,7 +464,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { ClientResponse res = client.create(multipart); try { int statusCode = res.getStatus(); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertEquals(statusCode, testExpectedStatusCode); String id = extractId(res); allResourceIdsCreated.add(id); if (logger.isDebugEnabled()) { diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index e7713f6fb..1ab3c75d3 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -29,12 +29,11 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; //import org.collectionspace.services.client.AbstractServiceClientImpl; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.CollectionObjectFactory; 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.collectionobject.BriefDescriptionList; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; @@ -52,7 +51,6 @@ import org.collectionspace.services.collectionobject.TitleGroup; import org.collectionspace.services.collectionobject.TitleGroupList; import org.collectionspace.services.collectionobject.TitleTranslationSubGroup; import org.collectionspace.services.collectionobject.TitleTranslationSubGroupList; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -69,16 +67,12 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class CollectionObjectServiceTest extends AbstractServiceTestImpl { +public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl { /** The logger. */ private final String CLASS_NAME = CollectionObjectServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; - private final String OBJECT_NAME_VALUE = "an object name"; private final BigInteger AGE_VALUE = new BigInteger("55"); private final String MEASURED_PART = "light box frame"; @@ -108,83 +102,37 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { protected CollectionSpaceClient getClientInstance() { return new CollectionObjectClient(); } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(AbstractCommonList.class); - } - + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + // Expected success outcomes + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - CollectionObjectClient client = new CollectionObjectClient(); - String identifier = createIdentifier(); - PoxPayloadOut multipart = - createCollectionObjectInstance(client.getCommonPartName(), identifier); - ClientResponse res = client.create(multipart); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null) { - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests } - - + /* * Tests to diagnose and verify the fixed status of CSPACE-1026, * "Whitespace at certain points in payload cause failure" */ + /** * Creates the from xml cambridge. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void createFromXmlCambridge(String testName) throws Exception { String newId = createFromXmlFile(testName, "./test-data/testCambridge.xml", true); @@ -202,11 +150,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { // Verify that record creation occurs successfully when the first value instance // of a single, repeatable String scalar field is non-blank. @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2242group"}) + dependsOnMethods = {"CRUDTests"}, groups = {"cspace2242group"}) public void createFromXmlNonBlankFirstValueInstance(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } String newId = createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-nonblank.xml", true); CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId); @@ -219,11 +164,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { // Verify that record creation occurs successfully when the first value instance // of a single, repeatable String scalar field is blank. @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2242group"}) + dependsOnMethods = {"CRUDTests"}, groups = {"cspace2242group"}) public void createFromXmlBlankFirstValueInstance(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } String newId = createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-blank.xml", true); CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId); @@ -235,11 +177,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { // Verify that values are preserved when enclosed in double quote marks. @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace3237group"}) + dependsOnMethods = {"CRUDTests"}, groups = {"cspace3237group"}) public void doubleQuotesEnclosingFieldContents(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } String newId = createFromXmlFile(testName, "./test-data/cspace-3237-double-quotes.xml", true); CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId); @@ -265,7 +204,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"CRUDTests"}) public void createFromXmlRFWS1(String testName) throws Exception { String testDataDir = System.getProperty("test-data.fileName"); String newId = @@ -281,7 +220,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"CRUDTests"}) public void createFromXmlRFWS2(String testName) throws Exception { String testDataDir = System.getProperty("test-data.fileName"); String newId = @@ -297,7 +236,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"CRUDTests"}) public void createFromXmlRFWS3(String testName) throws Exception { String testDataDir = System.getProperty("test-data.fileName"); String newId = @@ -313,7 +252,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"CRUDTests"}) public void createFromXmlRFWS4(String testName) throws Exception { String testDataDir = System.getProperty("test-data.fileName"); String newId = @@ -335,7 +274,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"CRUDTests"}) public void createWithNullValueRepeatableField(String testName) throws Exception { String testDataDir = System.getProperty("test-data.fileName"); String newId = @@ -355,7 +294,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "testSubmitRequest"}, groups={"utf8-create"}) + dependsOnMethods = {"CRUDTests"}, groups={"utf8-create"}) public void createWithUTF8Data(String testName) throws Exception { String testDataDir = System.getProperty("test-data.fileName"); String newId = @@ -373,16 +312,6 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(distinguishingFeatures.equals(UTF8_DATA_SAMPLE)); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#createList() - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - this.createPaginatedList(testName, DEFAULT_LIST_SIZE); - } - // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. @@ -406,6 +335,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void createWithMalformedXml(String testName) throws Exception { + //FIXME: Should this test really be empty? } /* (non-Javadoc) @@ -523,9 +453,6 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void createWithRequiredValuesNullOrEmpty(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Build a payload with invalid content, by omitting a @@ -559,8 +486,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); // FIXME: Consider splitting off the following into its own test method. @@ -589,257 +516,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); - } - - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - CollectionObjectClient client = new CollectionObjectClient(); - ClientResponse res = client.read(knownResourceId); - 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); - - // Extract the common part. - CollectionobjectsCommon collectionobjectCommon = extractCommonPartValue(testName, res); - - // Verify the number and contents of values in repeatable fields, - // as created in the instance record used for testing. - MeasuredPartGroupList measuredPartGroupList = collectionobjectCommon.getMeasuredPartGroupList(); - Assert.assertNotNull(measuredPartGroupList, "Measured part group list was null"); - List measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup(); - Assert.assertNotNull(measuredPartGroups, "Measured part groups were null"); - Assert.assertTrue(measuredPartGroups.size() > 0, "No measured part groups were returned"); - MeasuredPartGroup mpGroup = measuredPartGroups.get(0); - Assert.assertNotNull(mpGroup.getMeasuredPart(), "Measured part was null"); - Assert.assertEquals(mpGroup.getMeasuredPart(), MEASURED_PART, - "Measured part value returned didn't match expected value"); - - DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); - Assert.assertNotNull(dimensionSubGroupList, "Dimension subgroup list was null"); - List dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup(); - Assert.assertNotNull(dimensionSubGroups, "Dimension subgroups were null"); - Assert.assertTrue(dimensionSubGroups.size() > 0, "No dimension subgroups were returned"); - DimensionSubGroup lengthDimension = dimensionSubGroups.get(0); - Assert.assertNotNull(lengthDimension, "Length dimension was null"); - Assert.assertTrue(lengthDimension.getValue().compareTo(DIMENSION_VALUE_LENGTH) == 0, - "Dimension length value returned didn't match expected value"); - - /* No longer part of the "default" domain service tests for the CollectionObject record. - if (logger.isDebugEnabled()) { - logger.debug(testName + ": Reading Natural History part ..."); - } - - // Currently checking only that the natural history part is non-null; - // can add specific field-level checks as warranted. - Object conh = extractPartValue(testName, res, getNHPartName()); - Assert.assertNotNull(conh); - */ - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - CollectionObjectClient client = new CollectionObjectClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - CollectionObjectClient client = new CollectionObjectClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - // the expected response(s)? - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - - // Read an existing resource that will be updated. - ClientResponse res = updateRetrieve(testName, knownResourceId); - - // Extract its common part. - CollectionobjectsCommon collectionObjectCommon = extractCommonPartValue(testName, res); - - // Change the content of one or more fields in the common part. - - collectionObjectCommon.setObjectNumber("updated-" + collectionObjectCommon.getObjectNumber()); - - // Change the object name in the first value instance in the - // object name repeatable group. - ObjectNameList objNameList = collectionObjectCommon.getObjectNameList(); - List objNameGroups = objNameList.getObjectNameGroup(); - Assert.assertNotNull(objNameGroups); - Assert.assertTrue(objNameGroups.size() >= 1); - String objectName = objNameGroups.get(0).getObjectName(); - Assert.assertEquals(objectName, OBJECT_NAME_VALUE); - String updatedObjectName = "updated-" + objectName; - objNameGroups.get(0).setObjectName(updatedObjectName); - collectionObjectCommon.setObjectNameList(objNameList); - - // Replace the existing value instances in the dimensions repeatable group - // with entirely new value instances, also changing the number of such instances. - MeasuredPartGroupList measuredPartGroupList = collectionObjectCommon.getMeasuredPartGroupList(); - Assert.assertNotNull(measuredPartGroupList); - List measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup(); - Assert.assertNotNull(measuredPartGroups); - Assert.assertTrue(measuredPartGroups.size() > 0); - MeasuredPartGroup mpGroup = measuredPartGroups.get(0); - Assert.assertNotNull(mpGroup.getMeasuredPart()); - - DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); - Assert.assertNotNull(dimensionSubGroupList); - List dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup(); - Assert.assertNotNull(dimensionSubGroups); - int originalDimensionSubGroupSize = dimensionSubGroups.size(); - Assert.assertTrue(dimensionSubGroups.size() > 0); - dimensionSubGroups.clear(); - - DimensionSubGroup heightDimension = new DimensionSubGroup(); - heightDimension.setDimension("height"); - heightDimension.setMeasurementUnit(UPDATED_MEASUREMENT_UNIT); - dimensionSubGroups.add(heightDimension); - - int updatedDimensionGroupSize = dimensionSubGroups.size(); - Assert.assertTrue(updatedDimensionGroupSize > 0); - Assert.assertTrue(updatedDimensionGroupSize != originalDimensionSubGroupSize); - - collectionObjectCommon.setMeasuredPartGroupList(measuredPartGroupList); - - if (logger.isDebugEnabled()) { - logger.debug("sparse update that will be sent in update request:"); - logger.debug(objectAsXmlString(collectionObjectCommon, - CollectionobjectsCommon.class)); - } - - // Send the changed resource to be updated and read the updated resource - // from the response. - res = updateSend(testName, knownResourceId, collectionObjectCommon); - - // Extract its common part. - CollectionobjectsCommon updatedCollectionobjectCommon = extractCommonPartValue(testName, res); - - // Read the updated common part and verify that the resource was correctly updated. - objNameList = updatedCollectionobjectCommon.getObjectNameList(); - Assert.assertNotNull(objNameList); - objNameGroups = objNameList.getObjectNameGroup(); - Assert.assertNotNull(objNameGroups); - Assert.assertTrue(objNameGroups.size() >= 1); - Assert.assertEquals(updatedObjectName, - objNameGroups.get(0).getObjectName(), - "Data in updated object did not match submitted data."); - - measuredPartGroupList = collectionObjectCommon.getMeasuredPartGroupList(); - Assert.assertNotNull(measuredPartGroupList); - measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup(); - Assert.assertNotNull(measuredPartGroups); - Assert.assertTrue(measuredPartGroups.size() > 0); - mpGroup = measuredPartGroups.get(0); - Assert.assertNotNull(mpGroup.getMeasuredPart()); - - dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); - Assert.assertNotNull(dimensionSubGroupList); - dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup(); - Assert.assertNotNull(dimensionSubGroups); - Assert.assertTrue(dimensionSubGroups.size() > 0); - Assert.assertTrue(dimensionSubGroups.size() == updatedDimensionGroupSize); - Assert.assertEquals(UPDATED_MEASUREMENT_UNIT, - dimensionSubGroups.get(0).getMeasurementUnit(), - "Data in updated object did not match submitted data."); - - } - /** * Update retrieve. * @@ -857,9 +538,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": read status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); if(logger.isDebugEnabled()){ logger.debug("got object to update with ID: " + knownResourceId); } @@ -887,9 +568,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": read status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); return res; } @@ -901,7 +582,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) + dependsOnMethods = {"CRUDTests"}) public void updateWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? } @@ -916,7 +597,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) + dependsOnMethods = {"CRUDTests"}) public void updateWithMalformedXml(String testName) throws Exception { //FIXME: Should this test really be empty? } @@ -926,7 +607,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) + dependsOnMethods = {"CRUDTests"}) public void updateWithWrongXmlSchema(String testName) throws Exception { //FIXME: Should this test really be empty? } @@ -1020,17 +701,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { } */ - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ -@Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) + @Override public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdateNonExistent(); @@ -1040,7 +712,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { // The only relevant ID may be the one used in updateCollectionObject(), below. CollectionObjectClient client = new CollectionObjectClient(); PoxPayloadOut multipart = - createCollectionObjectInstance(client.getCommonPartName(), NON_EXISTENT_ID); + createInstance(client.getCommonPartName(), NON_EXISTENT_ID); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); int statusCode = res.getStatus(); @@ -1049,9 +721,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } /** @@ -1066,21 +738,20 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @param testName The name of this test method. This name is supplied * automatically, via reflection, by a TestNG 'data provider' in * a base class. - * @throws Exception + * @throws Exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void updateWithRequiredValuesNullOrEmpty(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Read an existing record for updating. ClientResponse res = updateRetrieve(testName, knownResourceId); - - // Extract its common part. - CollectionobjectsCommon collectionObjectCommon = extractCommonPartValue(testName, res); + CollectionobjectsCommon collectionObjectCommon = null; + try { + // Extract its common part. + collectionObjectCommon = extractCommonPartValue(res); + } finally { + res.releaseConnection(); + } // Update the common part with invalid content, by setting a value to // the empty String, in a field that requires a non-empty value, @@ -1096,125 +767,119 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. setupUpdate(); PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE); CollectionObjectClient client = new CollectionObjectClient(); - commonPart.setLabel(client.getCommonPartName()); + output.addPart(client.getCommonPartName(), collectionObjectCommon); res = client.update(knownResourceId, output); - int statusCode = res.getStatus(); - - // Read the response and verify that the update attempt failed. - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); - + + try { + int statusCode = res.getStatus(); + // Read the response and verify that the update attempt failed. + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); + } finally { + res.releaseConnection(); + } } // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - CollectionObjectClient client = new CollectionObjectClient(); - ClientResponse res = client.delete(knownResourceId); - 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); + // + // Create an object to delete, save the current 'knownResourceId' since we don't want to delete it yet + // and temporarily set it to the csid of the resource we just created. + // + String tempCsid = knownResourceId; + // the super.delete() method uses the knownResourceId member + knownResourceId = newCollectionObject(true); + + try { + super.delete(testName); + } finally { + // reset the 'knownResourceId' + knownResourceId = tempCsid; + } } - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ + // + // Expected failure outcome tests + // + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDeleteNonExistent(); // Submit the request to the service and store the response. CollectionObjectClient client = new CollectionObjectClient(); ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // --------------------------------------------------------------- // Utility tests : tests of code used in tests above // --------------------------------------------------------------- + /** * Tests the code for manually submitting data that is used by several * of the methods above. * @throws Exception */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() throws Exception { - testSubmitRequest(knownResourceId); - } - - /** - * Test submit request. - * - * @param resourceId the resource id - * @throws Exception the exception - */ - private void testSubmitRequest(String resourceId) throws Exception { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(resourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + + private ClientResponse newCollectionObject() { + ClientResponse result = null; + + CollectionObjectClient client = new CollectionObjectClient(); + String identifier = createIdentifier(); + PoxPayloadOut multipart = + createInstance(client.getCommonPartName(), identifier); + result = client.create(multipart); + + return result; + } + + private String newCollectionObject(boolean assertStatus) { + String result = null; + + ClientResponse res = newCollectionObject(); + try { + int statusCode = res.getStatus(); + Assert.assertEquals(statusCode, STATUS_CREATED); + result = extractId(res); + } finally { + res.releaseConnection(); + } + + return result; + } + + @Override + protected PoxPayloadOut createInstance(String identifier) { + String commonPartName = CollectionObjectClient.SERVICE_COMMON_PART_NAME; + return createInstance(commonPartName, identifier); + } + /** * Creates the collection object instance. * @@ -1222,18 +887,13 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { * @param identifier the identifier * @return the multipart output */ - private PoxPayloadOut createCollectionObjectInstance(String commonPartName, + @Override + protected PoxPayloadOut createInstance(String commonPartName, String identifier) { return createCollectionObjectInstance(commonPartName, "objectNumber-" + identifier, "objectName-" + identifier); } - - @Override - protected PoxPayloadOut createInstance(String identifier) { - String commonPartName = CollectionObjectClient.SERVICE_COMMON_PART_NAME; - return createCollectionObjectInstance(commonPartName, identifier); - } /** * Creates the collection object instance. @@ -1246,11 +906,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { private PoxPayloadOut createCollectionObjectInstance(String commonPartName, String objectNumber, String objectName) { CollectionobjectsCommon collectionObject = new CollectionobjectsCommon(); - + // Scalar fields collectionObject.setObjectNumber(objectNumber); collectionObject.setAge(AGE_VALUE); //test for null string - + // Repeatable structured groups TitleGroupList titleGroupList = new TitleGroupList(); @@ -1364,8 +1024,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { CollectionobjectsNaturalhistory.class)); } } + return multipart; - } /** @@ -1393,8 +1053,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { logger.debug(objectAsXmlString(collectionObject, CollectionobjectsCommon.class)); } + return multipart; - } /** @@ -1458,9 +1118,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); String newId = extractId(res); allResourceIdsCreated.add(newId); return newId; @@ -1486,61 +1146,136 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Extract the common part. - CollectionobjectsCommon collectionObject = extractCommonPartValue(testName, res); + CollectionobjectsCommon collectionObject = extractCommonPartValue(res); Assert.assertNotNull(collectionObject); return collectionObject; } - private CollectionobjectsCommon extractCommonPartValue(String testName, ClientResponse res) - throws Exception { - CollectionObjectClient client = new CollectionObjectClient(); - PayloadInputPart payloadInputPart = extractPart(testName, res, client.getCommonPartName()); - Object obj = null; - if (payloadInputPart != null) { - obj = payloadInputPart.getBody(); - } - Assert.assertNotNull(obj, - testName + ": body of " + client.getCommonPartName() + " part was unexpectedly null."); - CollectionobjectsCommon collectionobjectCommon = (CollectionobjectsCommon) obj; - Assert.assertNotNull(collectionobjectCommon, - testName + ": " + client.getCommonPartName() + " part was unexpectedly null."); - return collectionobjectCommon; - } - -// private Object extractPartValue(String testName, ClientResponse res, String partLabel) -// throws Exception { -// Object obj = null; -// PayloadInputPart payloadInputPart = extractPart(testName, res, partLabel); -// if (payloadInputPart != null) { -// obj = payloadInputPart.getElementBody(); -// } -// Assert.assertNotNull(obj, -// testName + ": value of part " + partLabel + " was unexpectedly null."); -// return obj; -// } - - private PayloadInputPart extractPart(String testName, ClientResponse res, String partLabel) - throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testName + ": Reading part " + partLabel + " ..."); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(partLabel); - Assert.assertNotNull(payloadInputPart, - testName + ": part " + partLabel + " was unexpectedly null."); - return payloadInputPart; - } - @Override protected String getServicePathComponent() { // TODO Auto-generated method stub return CollectionObjectClient.SERVICE_PATH_COMPONENT; } + @Override + protected CollectionobjectsCommon updateInstance(CollectionobjectsCommon collectionObjectCommon) { + collectionObjectCommon.setObjectNumber("updated-" + collectionObjectCommon.getObjectNumber()); + + // Change the object name in the first value instance in the + // object name repeatable group. + ObjectNameList objNameList = collectionObjectCommon.getObjectNameList(); + List objNameGroups = objNameList.getObjectNameGroup(); + Assert.assertNotNull(objNameGroups); + Assert.assertTrue(objNameGroups.size() >= 1); + String objectName = objNameGroups.get(0).getObjectName(); + Assert.assertEquals(objectName, OBJECT_NAME_VALUE); + String updatedObjectName = "updated-" + objectName; + objNameGroups.get(0).setObjectName(updatedObjectName); + collectionObjectCommon.setObjectNameList(objNameList); + + // Replace the existing value instances in the dimensions repeatable group + // with entirely new value instances, also changing the number of such instances. + MeasuredPartGroupList measuredPartGroupList = collectionObjectCommon.getMeasuredPartGroupList(); + Assert.assertNotNull(measuredPartGroupList); + List measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup(); + Assert.assertNotNull(measuredPartGroups); + Assert.assertTrue(measuredPartGroups.size() > 0); + MeasuredPartGroup mpGroup = measuredPartGroups.get(0); + Assert.assertNotNull(mpGroup.getMeasuredPart()); + + DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); + Assert.assertNotNull(dimensionSubGroupList); + List dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup(); + Assert.assertNotNull(dimensionSubGroups); + int originalDimensionSubGroupSize = dimensionSubGroups.size(); + Assert.assertTrue(dimensionSubGroups.size() > 0); + dimensionSubGroups.clear(); + + DimensionSubGroup heightDimension = new DimensionSubGroup(); + heightDimension.setDimension("height"); + heightDimension.setMeasurementUnit(UPDATED_MEASUREMENT_UNIT); + dimensionSubGroups.add(heightDimension); + + int updatedDimensionGroupSize = dimensionSubGroups.size(); + Assert.assertTrue(updatedDimensionGroupSize > 0); + Assert.assertTrue(updatedDimensionGroupSize != originalDimensionSubGroupSize); + + collectionObjectCommon.setMeasuredPartGroupList(measuredPartGroupList); + + return collectionObjectCommon; + } + + @Override + protected void compareReadInstances(CollectionobjectsCommon original, + CollectionobjectsCommon fromRead) throws Exception { + // Verify the number and contents of values in repeatable fields, + // as created in the instance record used for testing. + MeasuredPartGroupList measuredPartGroupList = fromRead.getMeasuredPartGroupList(); + Assert.assertNotNull(measuredPartGroupList, "Measured part group list was null"); + List measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup(); + Assert.assertNotNull(measuredPartGroups, "Measured part groups were null"); + Assert.assertTrue(measuredPartGroups.size() > 0, "No measured part groups were returned"); + MeasuredPartGroup mpGroup = measuredPartGroups.get(0); + Assert.assertNotNull(mpGroup.getMeasuredPart(), "Measured part was null"); + Assert.assertEquals(mpGroup.getMeasuredPart(), MEASURED_PART, + "Measured part value returned didn't match expected value"); + + DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); + Assert.assertNotNull(dimensionSubGroupList, "Dimension subgroup list was null"); + List dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup(); + Assert.assertNotNull(dimensionSubGroups, "Dimension subgroups were null"); + Assert.assertTrue(dimensionSubGroups.size() > 0, "No dimension subgroups were returned"); + DimensionSubGroup lengthDimension = dimensionSubGroups.get(0); + Assert.assertNotNull(lengthDimension, "Length dimension was null"); + Assert.assertTrue(lengthDimension.getValue().compareTo(DIMENSION_VALUE_LENGTH) == 0, + "Dimension length value returned didn't match expected value"); + } + + @Override + protected void compareUpdatedInstances(CollectionobjectsCommon original, + CollectionobjectsCommon updated) throws Exception { + + ObjectNameList objNameList = updated.getObjectNameList(); + Assert.assertNotNull(objNameList); + List objNameGroups = objNameList.getObjectNameGroup(); + Assert.assertNotNull(objNameGroups); + Assert.assertTrue(objNameGroups.size() >= 1); + Assert.assertEquals(original.getObjectNameList().getObjectNameGroup().get(0).getObjectName(), + objNameGroups.get(0).getObjectName(), + "Data in updated object did not match submitted data."); + // + // Get the dimension group size of the original + // + MeasuredPartGroupList measuredPartGroupList = original.getMeasuredPartGroupList(); + List measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup(); + MeasuredPartGroup mpGroup = measuredPartGroups.get(0); + DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); + List dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup(); + int updatedDimensionGroupSize = dimensionSubGroups.size(); + // + // Now get the dimension group size of the updated + // + measuredPartGroupList = updated.getMeasuredPartGroupList(); + Assert.assertNotNull(measuredPartGroupList); + measuredPartGroups = measuredPartGroupList.getMeasuredPartGroup(); + Assert.assertNotNull(measuredPartGroups); + Assert.assertTrue(measuredPartGroups.size() > 0); + mpGroup = measuredPartGroups.get(0); + Assert.assertNotNull(mpGroup.getMeasuredPart()); + dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); + Assert.assertNotNull(dimensionSubGroupList); + dimensionSubGroups = dimensionSubGroupList.getDimensionSubGroup(); + Assert.assertNotNull(dimensionSubGroups); + Assert.assertTrue(dimensionSubGroups.size() == updatedDimensionGroupSize); + + Assert.assertEquals(UPDATED_MEASUREMENT_UNIT, + dimensionSubGroups.get(0).getMeasurementUnit(), + "Data in updated object did not match submitted data."); + } } diff --git a/services/collectionobject/service/pom.xml b/services/collectionobject/service/pom.xml index 523c831e9..fb0c0cdb4 100644 --- a/services/collectionobject/service/pom.xml +++ b/services/collectionobject/service/pom.xml @@ -67,7 +67,6 @@ org.testng testng - 5.6 diff --git a/services/common-api/pom.xml b/services/common-api/pom.xml index 23ecbd1a0..4ce437113 100755 --- a/services/common-api/pom.xml +++ b/services/common-api/pom.xml @@ -27,7 +27,6 @@ org.testng testng - 5.6 provided diff --git a/services/common-test/pom.xml b/services/common-test/pom.xml index 35fce7683..e3431e680 100644 --- a/services/common-test/pom.xml +++ b/services/common-test/pom.xml @@ -72,7 +72,6 @@ org.testng testng - 5.6 diff --git a/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java b/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java index 6b8f8b45d..75cfa1404 100644 --- a/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java +++ b/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java @@ -32,6 +32,7 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.OptionsMethod; import org.apache.commons.httpclient.methods.TraceMethod; +import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.TestServiceClient; import org.slf4j.Logger; @@ -61,15 +62,15 @@ public class ServiceLayerTest { logger.debug("Client properties read from the properties path;\n" + "possibly from the command line or a properties file:"); logger.debug("url = " - + serviceClient.getProperty(serviceClient.URL_PROPERTY)); + + serviceClient.getProperty(CollectionSpaceClient.URL_PROPERTY)); logger.debug("secure (SSL) = " - + serviceClient.getProperty(serviceClient.SSL_PROPERTY)); + + serviceClient.getProperty(CollectionSpaceClient.SSL_PROPERTY)); logger.debug("useAuth = " - + serviceClient.getProperty(serviceClient.AUTH_PROPERTY)); + + serviceClient.getProperty(CollectionSpaceClient.AUTH_PROPERTY)); logger.debug("user = " - + serviceClient.getProperty(serviceClient.USER_PROPERTY)); + + serviceClient.getProperty(CollectionSpaceClient.USER_PROPERTY)); logger.debug("password = " - + serviceClient.getProperty(serviceClient.PASSWORD_PROPERTY)); + + serviceClient.getProperty(CollectionSpaceClient.PASSWORD_PROPERTY)); } } @@ -77,7 +78,7 @@ public class ServiceLayerTest { public void servicesExist() { if (logger.isDebugEnabled()) { - logger.debug(BaseServiceTest.testBanner("servicesExist", CLASS_NAME)); + logger.debug(BaseServiceTest.getTestBanner("servicesExist", CLASS_NAME)); } //use ID service that should always be present in a working service layer String url = serviceClient.getBaseURL() + "idgenerators"; @@ -105,7 +106,7 @@ public class ServiceLayerTest { @Test public void methodNotAllowed() { if (logger.isDebugEnabled()) { - logger.debug(BaseServiceTest.testBanner("methodNotAllowed", CLASS_NAME)); + logger.debug(BaseServiceTest.getTestBanner("methodNotAllowed", CLASS_NAME)); } // Delete is not allowed on the root URL of the id service String url = serviceClient.getBaseURL() + "idgenerators"; @@ -132,7 +133,7 @@ public class ServiceLayerTest { @Test public void nonexistentService() { if (logger.isDebugEnabled()) { - logger.debug(BaseServiceTest.testBanner("nonexistentService", CLASS_NAME)); + logger.debug(BaseServiceTest.getTestBanner("nonexistentService", CLASS_NAME)); } String url = serviceClient.getBaseURL() + "nonexistent-service"; GetMethod method = new GetMethod(url); @@ -158,7 +159,7 @@ public class ServiceLayerTest { // @Test public void serviceSecure() { if (logger.isDebugEnabled()) { - logger.debug(BaseServiceTest.testBanner("serviceSecure", CLASS_NAME)); + logger.debug(BaseServiceTest.getTestBanner("serviceSecure", CLASS_NAME)); } String url = serviceClient.getBaseURL() + "collectionobjects"; GetMethod method = new GetMethod(url); @@ -190,7 +191,7 @@ public class ServiceLayerTest { @Test public void traceSupported() { if (logger.isDebugEnabled()) { - logger.debug(BaseServiceTest.testBanner("traceSupported", CLASS_NAME)); + logger.debug(BaseServiceTest.getTestBanner("traceSupported", CLASS_NAME)); } String url = serviceClient.getBaseURL() + "collectionobjects"; TraceMethod method = new TraceMethod(url); @@ -221,7 +222,7 @@ public class ServiceLayerTest { @Test public void headSupported() { if (logger.isDebugEnabled()) { - logger.debug(BaseServiceTest.testBanner("headSupported", CLASS_NAME)); + logger.debug(BaseServiceTest.getTestBanner("headSupported", CLASS_NAME)); } String url = serviceClient.getBaseURL() + "intakes"; HeadMethod method = new HeadMethod(url); diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index f4a5734a1..7186877de 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -13,535 +13,535 @@ - - - - - datePattern - MM/dd/yyyy - - - datePattern - MMM dd, yyyy - - - datePattern - dd.MM.yyyy - + + + + + datePattern + MM/dd/yyyy + + + datePattern + MMM dd, yyyy + + + datePattern + dd.MM.yyyy + - - localeLanguage - en - + + localeLanguage + en + - + - + - - + + - - + + - - + + - - - /collectionobjects/*/workflow/ + + + /collectionobjects/*/workflow/ - default-domain - org.collectionspace.services.collectionobject.nuxeo.CollectionObjectDocumentModelHandler - - org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler - - collectionobjects - getCollectionObjectListItem - - - objectNumber - objectNumber - - - objectName - objectNameList/[0]/objectName - - - title - titleGroupList/[0]/title - - - responsibleDepartment - responsibleDepartments/[0] - - - - - org.collectionspace.services.collectionobject.nuxeo.CollectionObjectValidatorHandler - - org.collectionspace.services.common.init.ModifyFieldDatatypes - - - collectionobjects_common_briefdescriptions - item - LARGETEXT - - - - collectionobjects_common_comments - item - LARGETEXT - - - - collectionobjects_common_objectproductionreasons - item - LARGETEXT - - - - collectionobjects_common_ownersreferences - item - LARGETEXT - - - - collectionobjects_common_viewersreferences - item - LARGETEXT - - - - - - - objectNameProperty + default-domain + org.collectionspace.services.collectionobject.nuxeo.CollectionObjectDocumentModelHandler + + org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler + + collectionobjects + getCollectionObjectListItem + + + objectNumber + objectNumber + + + objectName + objectNameList/[0]/objectName + + + title + titleGroupList/[0]/title + + + responsibleDepartment + responsibleDepartments/[0] + + + + + org.collectionspace.services.collectionobject.nuxeo.CollectionObjectValidatorHandler + + org.collectionspace.services.common.init.ModifyFieldDatatypes + + + collectionobjects_common_briefdescriptions + item + LARGETEXT + + + + collectionobjects_common_comments + item + LARGETEXT + + + + collectionobjects_common_objectproductionreasons + item + LARGETEXT + + + + collectionobjects_common_ownersreferences + item + LARGETEXT + + + + collectionobjects_common_viewersreferences + item + LARGETEXT + + + + + + + objectNameProperty objectNameList/[0]/objectName - - - objectNumberProperty - objectNumber - - - - - - - - - - + + + objectNumberProperty + objectNumber + + + + + + + + + + - - authRef - contentActivities|contentActivity - - - authRef - contentConcepts|contentConcept - - - authRef + + authRef + contentActivities|contentActivity + + + authRef + contentConcepts|contentConcept + + + authRef contentEventNameGroupList/*/contentEventName - - - authRef + + + authRef contentEventNameGroupList/*/contentEventNameType - - - authRef + + + authRef contentOrganizations|contentOrganization - - - authRef + + + authRef contentOtherGroupList/*/contentOther - - - authRef + + + authRef contentOtherGroupList/*/contentOtherType - - - authRef + + + authRef contentPeoples|contentPeople - - - authRef + + + authRef contentPersons|contentPerson - - - authRef + + + authRef contentPlaces|contentPlace - - - authRef + + + authRef measuredPartGroupList/*/dimensionSubGroupList/*/measuredBy - - - authRef + + + authRef textualInscriptionGroupList/*/inscriptionContentInscriber - - - authRef + + + authRef textualInscriptionGroupList/*/inscriptionContentMethod - - - authRef + + + authRef nonTextualInscriptionGroupList/*/inscriptionDescriptionInscriber - - - authRef + + + authRef nonTextualInscriptionGroupList/*/inscriptionDescriptionMethod - - - authRef - materialGroupList/*/material - + + + authRef + materialGroupList/*/material + - - authRef - materialGroupList/*/materialSource - - - authRef + + authRef + materialGroupList/*/materialSource + + + authRef styles|style - - - authRef - objectComponentGroupList/*/objectComponentName - + + + authRef + objectComponentGroupList/*/objectComponentName + - - authRef - objectProductionOrganizationGroupList/*/objectProductionOrganization - - - authRef - objectProductionPeopleGroupList/*/objectProductionPeople - - - authRef - objectProductionPersonGroupList/*/objectProductionPerson - - - authRef + + authRef + objectProductionOrganizationGroupList/*/objectProductionOrganization + + + authRef + objectProductionPeopleGroupList/*/objectProductionPeople + + + authRef + objectProductionPersonGroupList/*/objectProductionPerson + + + authRef objectProductionPlaceGroupList/*/objectProductionPlace authRef - techniqueGroupList/*/technique - - - authRef - techniqueGroupList/*/techniqueType - + techniqueGroupList/*/technique + + + authRef + techniqueGroupList/*/techniqueType + - - authRef - assocOrganizationGroupList/*/assocOrganization - - - authRef - assocPeopleGroupList/*/assocPeople - - - authRef - assocPersonGroupList/*/assocPerson - - - authRef - assocPlaceGroupList/*/assocPlace - + + authRef + assocOrganizationGroupList/*/assocOrganization + + + authRef + assocPeopleGroupList/*/assocPeople + + + authRef + assocPersonGroupList/*/assocPerson + + + authRef + assocPlaceGroupList/*/assocPlace + - - authRef + + authRef referenceGroupList/*/reference - + - - authRef + + authRef fieldCollectionPlace - - - authRef + + + authRef fieldCollectionSources|fieldCollectionSource - - - authRef + + + authRef fieldCollectors|fieldCollector - - - authRef + + + authRef fieldColEventNames|fieldColEventName - + - + termRef otherNumberList/*/numberType - - - termRef + + + termRef objectNameList/*/objectNameCurrency - - - termRef + + + termRef objectNameList/*/objectNameLevel - - - termRef + + + termRef objectNameList/*/objectNameSystem - - - termRef + + + termRef objectNameList/*/objectNameType - - - termRef + + + termRef objectNameList/*/objectNameLanguage - - - termRef - responsibleDepartments|responsibleDepartment - - - termRef + + + termRef + responsibleDepartments|responsibleDepartment + + + termRef collection - - - termRef + + + termRef titleGroupList/*/titleLanguage - - - termRef + + + termRef titleGroupList/*/titleTranslationSubGroupList/*/titleTranslationLanguage - - - termRef + + + termRef titleGroupList/*/titleType - - - termRef + + + termRef recordStatus - + - - termRef + + termRef ageUnit - - - termRef + + + termRef contentLanguages|contentLanguage - - - termRef + + + termRef contentObjectGroupList/*/contentObjectType - - - termRef + + + termRef contentPositions|contentPosition - - - termRef + + + termRef contentScripts|contentScript - - - termRef + + + termRef measuredPartGroupList/*/measuredPart - - - termRef + + + termRef measuredPartGroupList/*/dimensionSubGroupList/*/dimension - - - termRef + + + termRef measuredPartGroupList/*/dimensionSubGroupList/*/measurementUnit - - - termRef + + + termRef measuredPartGroupList/*/dimensionSubGroupList/*/measurementMethod - - - termRef + + + termRef forms|form - - - termRef + + + termRef textualInscriptionGroupList/*/inscriptionContentLanguage - - - termRef + + + termRef textualInscriptionGroupList/*/inscriptionContentPosition - - - termRef + + + termRef textualInscriptionGroupList/*/inscriptionContentScript - - - termRef + + + termRef textualInscriptionGroupList/*/inscriptionContentType - - - termRef + + + termRef nonTextualInscriptionGroupList/*/inscriptionDescriptionPosition - - - termRef + + + termRef nonTextualInscriptionGroupList/*/inscriptionDescriptionType - - - termRef + + + termRef objectStatusList|objectStatus - - - termRef + + + termRef phase - - - termRef + + + termRef sex - - - termRef - technicalAttributeGroupList/*/technicalAttribute - - - termRef - technicalAttributeGroupList/*/technicalAttributeMeasurement - - - termRef - technicalAttributeGroupList/*/technicalAttributeMeasurementUnit - - - termRef + + + termRef + technicalAttributeGroupList/*/technicalAttribute + + + termRef + technicalAttributeGroupList/*/technicalAttributeMeasurement + + + termRef + technicalAttributeGroupList/*/technicalAttributeMeasurementUnit + + + termRef objectComponentGroupList/*/objectComponentInformation - + - - termRef + + termRef assocActivityGroupList/*/assocActivity - - - termRef + + + termRef assocConceptGroupList/*/assocConcept - - - termRef + + + termRef assocCulturalContextGroupList/*/assocCulturalContext - + - - termRef + + --> + + termRef assocObjectGroupList/*/assocObject - - - termRef + + + termRef assocObjectGroupList/*/assocObjectType - + + + termRef + ownerGroupList/*/ownershipAccess + + + termRef + ownerGroupList/*/ownershipCategory + + + termRef + ownerGroupList/*/ownershipExchangeMethod + + --> termRef usageGroupList/*/usage @@ -557,410 +557,410 @@ termRef fieldCollectionMethods|fieldCollectionMethod - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - /blobs/*/workflow/ - default-domain - org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler - - - - - name - name - - - mimeType - mimeType - - - encoding - encoding - - - length - length - - - - - org.collectionspace.services.blob.nuxeo.BlobValidatorHandler - - - - - - - - - + + + + /blobs/*/workflow/ + default-domain + org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler + + + + + name + name + + + mimeType + mimeType + + + encoding + encoding + + + length + length + + + + + org.collectionspace.services.blob.nuxeo.BlobValidatorHandler + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - /intakes/*/workflow/ + + + /intakes/*/workflow/ - default-domain - org.collectionspace.services.intake.nuxeo.IntakeDocumentModelHandler - - org.collectionspace.services.group.nuxeo.IntakeDocumentModelHandler - - intakes - intakes - entryNumber|depositor|currentOwner|uri|csid - - - getIntakeListItem - - - entryNumber - entryNumber - - - depositor - depositor - - - currentOwner - currentOwner - - - - - org.collectionspace.services.intake.nuxeo.IntakeValidatorHandler - - + default-domain + org.collectionspace.services.intake.nuxeo.IntakeDocumentModelHandler + + org.collectionspace.services.group.nuxeo.IntakeDocumentModelHandler + + intakes + intakes + entryNumber|depositor|currentOwner|uri|csid + + + getIntakeListItem + + + entryNumber + entryNumber + + + depositor + depositor + + + currentOwner + currentOwner + + + + + org.collectionspace.services.intake.nuxeo.IntakeValidatorHandler + + objectNameProperty currentOwner - objectNumberProperty - entryNumber - - - - - - - - - - + objectNumberProperty + entryNumber + + + + + + + + + + - - authRef - currentOwner - - - authRef - depositor - - - authRef + + authRef + currentOwner + + + authRef + depositor + + + authRef fieldCollectionPlace - - - authRef + + + authRef fieldCollectionSources|fieldCollectionSource - - - authRef - fieldCollectors|fieldCollector - - - authRef + + + authRef + fieldCollectors|fieldCollector + + + authRef fieldCollectionEventNames|fieldCollectionEventName authRef - valuer - - - authRef - insurers|insurer - - - authRef + valuer + + + authRef + insurers|insurer + + + authRef currentLocationGroupList/*/currentLocation - - - authRef + + + authRef normalLocation - - - authRef + + + authRef conditionCheckersOrAssessors|conditionCheckerOrAssessor - + - - termRef - entryMethods|entryMethod - - - termRef - entryReason - - - termRef - fieldCollectionMethods|fieldCollectionMethod - - - termRef + + termRef + entryMethods|entryMethod + + + termRef + entryReason + + + termRef + fieldCollectionMethods|fieldCollectionMethod + + + termRef currentLocationGroupList/*/currentLocationFitness - - - termRef + + + termRef conditionCheckMethods|conditionCheckMethod - - - termRef + + + termRef conditionCheckReasons|conditionCheckReason - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - /loansin/*/workflow/ + + + /loansin/*/workflow/ - default-domain - org.collectionspace.services.loanin.nuxeo.LoaninDocumentModelHandler - - org.collectionspace.services.loanin.nuxeo.LoaninDocumentModelHandler - - loansin - loansin - loanInNumber|lenderList|loanReturnDate|uri|csid - - - getLoaninListItem - - - loanInNumber - loanInNumber - - - lender - lenderGroupList/[0]/lender - - - loanReturnDate - loanReturnDate - - - - - org.collectionspace.services.loanin.nuxeo.LoaninValidatorHandler - - - org.collectionspace.services.common.init.InitHandler - - - mytable - mycol - mytpe - myparam, myparamB - - - mytable2 - mycol2 - mytpe2 - myparam, myparam2B - - - my key - my value - - - my key 2 - my value 2 - - - - - - - datePattern - MMM dd, yyyy - - - datePattern - dd.MM.yyyy - + default-domain + org.collectionspace.services.loanin.nuxeo.LoaninDocumentModelHandler + + org.collectionspace.services.loanin.nuxeo.LoaninDocumentModelHandler + + loansin + loansin + loanInNumber|lenderList|loanReturnDate|uri|csid + + + getLoaninListItem + + + loanInNumber + loanInNumber + + + lender + lenderGroupList/[0]/lender + + + loanReturnDate + loanReturnDate + + + + + org.collectionspace.services.loanin.nuxeo.LoaninValidatorHandler + + + org.collectionspace.services.common.init.InitHandler + + + mytable + mycol + mytpe + myparam, myparamB + + + mytable2 + mycol2 + mytpe2 + myparam, myparam2B + + + my key + my value + + + my key 2 + my value 2 + + + + + + + datePattern + MMM dd, yyyy + + + datePattern + dd.MM.yyyy + - - localeLanguage - en - + + localeLanguage + en + - - - + + + objectNameProperty lenderGroupList/[0]/lender - objectNumberProperty - loanInNumber - - - - - - - - - - + objectNumberProperty + loanInNumber + + + + + + + + + + - - authRef + + authRef lenderGroupList/*/lender - - - authRef + + + authRef lenderGroupList/*/lendersAuthorizer - - - authRef + + + authRef lenderGroupList/*/lendersContact - - - authRef + + + authRef borrowersAuthorizer - - - authRef + + + authRef borrowersContact - - - authRef + + + authRef loanInContact - + - + termRef loanPurpose termRef - loanStatusGroupList/*/loanStatus - - - - - - - - - - - - - - + loanStatusGroupList/*/loanStatus + + + + + + + + + + + + + + - - - /loansout/*/workflow/ + + + /loansout/*/workflow/ - default-domain - org.collectionspace.services.loanout.nuxeo.LoanoutDocumentModelHandler - - - - - loanOutNumber - loanOutNumber - - - borrower - borrower - - - loanReturnDate - loanReturnDate - - - - - org.collectionspace.services.loanout.nuxeo.LoanoutValidatorHandler + default-domain + org.collectionspace.services.loanout.nuxeo.LoanoutDocumentModelHandler + + + + + loanOutNumber + loanOutNumber + + + borrower + borrower + + + loanReturnDate + loanReturnDate + + + + + org.collectionspace.services.loanout.nuxeo.LoanoutValidatorHandler objectNameProperty @@ -971,294 +971,294 @@ loanOutNumber - - - - - - - - + + + + + + + + - - authRef - borrower - - - authRef - borrowersContact - - - authRef - lendersAuthorizer - - - authRef - lendersContact - + + authRef + borrower + + + authRef + borrowersContact + + + authRef + lendersAuthorizer + + + authRef + lendersContact + - - termRef - loanPurpose - - - termRef - loanStatusGroupList/*/loanStatus - - - - - - - - - - - - - - + + termRef + loanPurpose + + + termRef + loanStatusGroupList/*/loanStatus + + + + + + + + + + + + + + - - - /objectexit/*/workflow/ - default-domain - org.collectionspace.services.objectexit.nuxeo.ObjectExitDocumentModelHandler - - org.collectionspace.services.objectexit.nuxeo.ObjectExitDocumentModelHandler - - - - exitNumber - exitNumber - setExitNumber - - - currentOwner - currentOwner - setCurrentOwner - - - - - org.collectionspace.services.objectexit.nuxeo.ObjectExitValidatorHandler - - - objectNameProperty - currentOwner - - - objectNumberProperty - exitNumber - - - - - - - - - - + + + /objectexit/*/workflow/ + default-domain + org.collectionspace.services.objectexit.nuxeo.ObjectExitDocumentModelHandler + + org.collectionspace.services.objectexit.nuxeo.ObjectExitDocumentModelHandler + + + + exitNumber + exitNumber + setExitNumber + + + currentOwner + currentOwner + setCurrentOwner + + + + + org.collectionspace.services.objectexit.nuxeo.ObjectExitValidatorHandler + + + objectNameProperty + currentOwner + + + objectNumberProperty + exitNumber + + + + + + + + + + - - authRef - currentOwner - - - authRef - depositor - + + authRef + currentOwner + + + authRef + depositor + - - termRef - exitMethods|exitMethod - - - termRef - exitReason - - - - - - - - - - - - - - + + termRef + exitMethods|exitMethod + + + termRef + exitReason + + + + + + + + + + + + + + - - - /batch/*/workflow/ - default-domain - org.collectionspace.services.batch.nuxeo.BatchDocumentModelHandler - - - - - name - name - setName - - - - - org.collectionspace.services.batch.nuxeo.BatchValidatorHandler - - - - - - - - - - - - - - - - - - - + + + /batch/*/workflow/ + default-domain + org.collectionspace.services.batch.nuxeo.BatchDocumentModelHandler + + + + + name + name + setName + + + + + org.collectionspace.services.batch.nuxeo.BatchValidatorHandler + + + + + + + + + + + + + + + + + + + - - - /groups/*/workflow/ - default-domain - org.collectionspace.services.group.nuxeo.GroupDocumentModelHandler - - - - - title - title - - - - - org.collectionspace.services.group.nuxeo.GroupValidatorHandler - - - objectNameProperty - title - - - - - - - - - - + + + /groups/*/workflow/ + default-domain + org.collectionspace.services.group.nuxeo.GroupDocumentModelHandler + + + + + title + title + + + + + org.collectionspace.services.group.nuxeo.GroupValidatorHandler + + + objectNameProperty + title + + + + + + + + + + - - authRef - owner - + + authRef + owner + - - termRef - responsibleDepartment - - - - - - - - - - - - - - + + termRef + responsibleDepartment + + + + + + + + + + + + + + - - - /imports/*/workflow/ - default-domain - org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler - - org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler - - imports - imports - importsField|uri|csid - org.collectionspace.services.imports.ImportsCommonList - org.collectionspace.services.imports.ImportsCommonList$ImportsListItem - getImportsListItem - - - importsField - importsField - setImportsField - - - - - - - - - - - - - - - - - - - - - - - + + + /imports/*/workflow/ + default-domain + org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler + + org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler + + imports + imports + importsField|uri|csid + org.collectionspace.services.imports.ImportsCommonList + org.collectionspace.services.imports.ImportsCommonList$ImportsListItem + getImportsListItem + + + importsField + importsField + setImportsField + + + + + + + + + + + + + + + + + + + + + + + - - - - /media/*/workflow/ - default-domain - org.collectionspace.services.media.nuxeo.MediaDocumentModelHandler - - - - - title - title - - - source - source - - - filename - filename - - - identificationNumber - identificationNumber - - - blobCsid - blobCsid - - - - - org.collectionspace.services.media.nuxeo.MediaValidatorHandler + + + + /media/*/workflow/ + default-domain + org.collectionspace.services.media.nuxeo.MediaDocumentModelHandler + + + + + title + title + + + source + source + + + filename + filename + + + identificationNumber + identificationNumber + + + blobCsid + blobCsid + + + + + org.collectionspace.services.media.nuxeo.MediaValidatorHandler objectNameProperty @@ -1269,109 +1269,109 @@ identificationNumber - - - - - - - - + + + + + + + + - - authRef - contributor - - - authRef - coverage - - - authRef - creator - - - authRef - publisher - - - authRef - rightsHolder - - - - authRef - subjectList|subject - - - authRef - measuredPartGroupList/*/dimensionSubGroupList/*/measuredBy - + + authRef + contributor + + + authRef + coverage + + + authRef + creator + + + authRef + publisher + + + authRef + rightsHolder + + + + authRef + subjectList|subject + + + authRef + measuredPartGroupList/*/dimensionSubGroupList/*/measuredBy + - - termRef - languageList|language - - - termRef - typeList|type - - - termRef + + termRef + languageList|language + + + termRef + typeList|type + + + termRef measuredPartGroupList/*/dimensionSubGroupList/*/dimension - - - termRef + + + termRef measuredPartGroupList/*/dimensionSubGroupList/*/measurementUnit - - - termRef + + + termRef measuredPartGroupList/*/dimensionSubGroupList/*/measurementMethod - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - /movements/*/workflow/ + + + /movements/*/workflow/ - default-domain - org.collectionspace.services.movement.nuxeo.MovementDocumentModelHandler - - - - - movementReferenceNumber - movementReferenceNumber - - - currentLocation - currentLocation - - - locationDate - locationDate - - - - - org.collectionspace.services.movement.nuxeo.MovementValidatorHandler + default-domain + org.collectionspace.services.movement.nuxeo.MovementDocumentModelHandler + + + + + movementReferenceNumber + movementReferenceNumber + + + currentLocation + currentLocation + + + locationDate + locationDate + + + + + org.collectionspace.services.movement.nuxeo.MovementValidatorHandler objectNameProperty @@ -1382,331 +1382,331 @@ movementReferenceNumber - - - - - - - - + + + + + + + + - - authRef - currentLocation - - - authRef - normalLocation - + + authRef + currentLocation + + + authRef + normalLocation + - - authRef - movementContact - + + authRef + movementContact + - - termRef - currentLocationFitness - + + termRef + currentLocationFitness + - - termRef + + termRef movementMethods|movementMethod - - - termRef + + + termRef reasonForMove - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - default-domain - org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler - org.collectionspace.services.workflow.nuxeo.WorkflowValidatorHandler - - - - - - - - - - - - - - + + + default-domain + org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler + org.collectionspace.services.workflow.nuxeo.WorkflowValidatorHandler + + + + + + + + + + + + + + - - - /reports/*/workflow/ + + + /reports/*/workflow/ - default-domain - org.collectionspace.services.report.nuxeo.ReportDocumentModelHandler - - - - - name - name - - - - - org.collectionspace.services.report.nuxeo.ReportValidatorHandler - - org.collectionspace.services.report.nuxeo.ReportPostInitHandler - - - readerRoleName - reader - - - - - - - - - - - - - - - - - - - - - - + default-domain + org.collectionspace.services.report.nuxeo.ReportDocumentModelHandler + + + + + name + name + + + + + org.collectionspace.services.report.nuxeo.ReportValidatorHandler + + org.collectionspace.services.report.nuxeo.ReportPostInitHandler + + + readerRoleName + reader + + + + + + + + + + + + + + + + + + + + + + - - - /vocabularies/*/workflow/ - /vocabularies/*/items/*/workflow/ + + + /vocabularies/*/workflow/ + /vocabularies/*/items/*/workflow/ - default-domain - org.collectionspace.services.vocabulary.nuxeo.VocabularyDocumentModelHandler - org.collectionspace.services.vocabulary.nuxeo.VocabularyValidatorHandler - - - - - displayName - displayName - - - refName - refName - - - shortIdentifier - shortIdentifier - - - vocabType - vocabType - - - - - - org.collectionspace.services.common.init.AddIndices - - - vocabularies_common - displayname - - - vocabularies_common - shortidentifier - - - - - - - - - - - - - - - - - - - - - - + default-domain + org.collectionspace.services.vocabulary.nuxeo.VocabularyDocumentModelHandler + org.collectionspace.services.vocabulary.nuxeo.VocabularyValidatorHandler + + + + + displayName + displayName + + + refName + refName + + + shortIdentifier + shortIdentifier + + + vocabType + vocabType + + + + + + org.collectionspace.services.common.init.AddIndices + + + vocabularies_common + displayname + + + vocabularies_common + shortidentifier + + + + + + + + + + + + + + + + + + + + + + - - - /vocabularyitems/*/workflow/ + + /vocabularyitems/*/workflow/ - - default-domain - org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler - - - - - - order - order - - - - - org.collectionspace.services.vocabulary.nuxeo.VocabularyItemValidatorHandler - - org.collectionspace.services.common.init.AddIndices - - - vocabularyitems_common - inauthority - - - vocabularyitems_common - displayname - - - vocabularyitems_common - shortidentifier - - - - - - - - - - - - - - - - - - - - - - + --> + default-domain + org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler + + + + + + order + order + + + + + org.collectionspace.services.vocabulary.nuxeo.VocabularyItemValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + vocabularyitems_common + inauthority + + + vocabularyitems_common + displayname + + + vocabularyitems_common + shortidentifier + + + + + + + + + + + + + + + + + + + + + + - - - /orgauthorities/*/workflow/ - /orgauthorities/*/items/*/workflow/ + + + /orgauthorities/*/workflow/ + /orgauthorities/*/items/*/workflow/ - default-domain - org.collectionspace.services.organization.nuxeo.OrgAuthorityDocumentModelHandler - - - - - displayName - displayName - - - refName - refName - - - shortIdentifier - shortIdentifier - - - vocabType - vocabType - - - - - org.collectionspace.services.organization.nuxeo.OrgAuthorityValidatorHandler - - org.collectionspace.services.common.init.AddIndices - - - orgauthorities_common - displayname - - - orgauthorities_common - shortidentifier - - - - - - - - - - - - - - - - - - - - - - + default-domain + org.collectionspace.services.organization.nuxeo.OrgAuthorityDocumentModelHandler + + + + + displayName + displayName + + + refName + refName + + + shortIdentifier + shortIdentifier + + + vocabType + vocabType + + + + + org.collectionspace.services.organization.nuxeo.OrgAuthorityValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + orgauthorities_common + displayname + + + orgauthorities_common + shortidentifier + + + + + + + + + + + + + + + + + + + + + + - - + - default-domain - org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler - - - - - - - - org.collectionspace.services.organization.nuxeo.OrganizationValidatorHandler - - org.collectionspace.services.common.init.AddIndices - - - organizations_common - inauthority - - - organizations_common - displayname - - - organizations_common - shortidentifier - - - - - - objectNameProperty - displayName - - - objectNumberProperty - shortIdentifier - - - - - - - - - - + default-domain + org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler + + + + + + + + org.collectionspace.services.organization.nuxeo.OrganizationValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + organizations_common + inauthority + + + organizations_common + displayname + + + organizations_common + shortidentifier + + + + + + objectNameProperty + displayName + + + objectNumberProperty + shortIdentifier + + + + + + + + + + - - authRef - contactNames|contactName - - - authRef - foundingPlace - - - authRef - groups|group - - - authRef - functions|function - + + authRef + contactNames|contactName + + + authRef + foundingPlace + + + authRef + groups|group + + + authRef + functions|function + - - termRef - termStatus - - - - - - - - - - - - - - + + termRef + termStatus + + + + + + + + + + + + + + - - - /personauthorities/*/workflow/ - /personauthorities/*/items/*/workflow/ + + + /personauthorities/*/workflow/ + /personauthorities/*/items/*/workflow/ - default-domain - org.collectionspace.services.person.nuxeo.PersonAuthorityDocumentModelHandler - - - - - displayName - displayName - - - refName - refName - - - shortIdentifier - shortIdentifier - - - vocabType - vocabType - - - - - org.collectionspace.services.person.nuxeo.PersonAuthorityValidatorHandler - - org.collectionspace.services.common.init.AddIndices - - - personauthorities_common - displayname - - - personauthorities_common - shortidentifier - - - - - - - - - - - - - - - - - - - - - - + default-domain + org.collectionspace.services.person.nuxeo.PersonAuthorityDocumentModelHandler + + + + + displayName + displayName + + + refName + refName + + + shortIdentifier + shortIdentifier + + + vocabType + vocabType + + + + + org.collectionspace.services.person.nuxeo.PersonAuthorityValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + personauthorities_common + displayname + + + personauthorities_common + shortidentifier + + + + + + + + + + + + + + + + + + + + + + - - + - default-domain - org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler - - - - - - - - org.collectionspace.services.person.nuxeo.PersonValidatorHandler - - org.collectionspace.services.common.init.AddIndices - - - persons_common - inauthority - - - persons_common - displayname - - - persons_common - shortidentifier - - - - - - objectNameProperty - displayName - - - - objectNumberProperty - shortIdentifier - - - - - - - - - - - - - + default-domain + org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler + + + + + + + + org.collectionspace.services.person.nuxeo.PersonValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + persons_common + inauthority + + + persons_common + displayname + + + persons_common + shortidentifier + + + + + + objectNameProperty + displayName + + + + objectNumberProperty + shortIdentifier + + + + + + + + + + + + + - - authRef - birthPlace - - - authRef - deathPlace - - - authRef - groups|group - - - authRef - nationalities|nationality - - - authRef - occupations|occupation - - - authRef - schoolsOrStyles|schoolOrStyle - + + authRef + birthPlace + + + authRef + deathPlace + + + authRef + groups|group + + + authRef + nationalities|nationality + + + authRef + occupations|occupation + + + authRef + schoolsOrStyles|schoolOrStyle + - + termRef - salutation - - + salutation + + termRef - title - - + title + + termRef - gender - - + gender + + termRef termStatus - - - - - - - - - - - + + + + + + + + + + + - - - /locationauthorities/*/workflow/ - /locationauthorities/*/items/*/workflow/ + + + /locationauthorities/*/workflow/ + /locationauthorities/*/items/*/workflow/ - default-domain - org.collectionspace.services.location.nuxeo.LocationAuthorityDocumentModelHandler - - - - - displayName - displayName - - - refName - refName - - - shortIdentifier - shortIdentifier - - - vocabType - vocabType - - - - - - org.collectionspace.services.common.init.AddIndices - - - locationauthorities_common - displayname - - - locationauthorities_common - shortidentifier - - - - - - - - - - - - - - - - - - - - - - + default-domain + org.collectionspace.services.location.nuxeo.LocationAuthorityDocumentModelHandler + + + + + displayName + displayName + + + refName + refName + + + shortIdentifier + shortIdentifier + + + vocabType + vocabType + + + + + + org.collectionspace.services.common.init.AddIndices + + + locationauthorities_common + displayname + + + locationauthorities_common + shortidentifier + + + + + + + + + + + + + + + + + + + + + + - - - default-domain - org.collectionspace.services.location.nuxeo.LocationDocumentModelHandler - - - - - - - - org.collectionspace.services.location.nuxeo.LocationValidatorHandler - - org.collectionspace.services.common.init.AddIndices - - - locations_common - inauthority - - - locations_common - displayname - - - locations_common - shortidentifier - - - - - - objectNameProperty - displayName - - - objectNumberProperty - shortIdentifier - - - - - - - - - - + + default-domain + org.collectionspace.services.location.nuxeo.LocationDocumentModelHandler + + + + + + + + org.collectionspace.services.location.nuxeo.LocationValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + locations_common + inauthority + + + locations_common + displayname + + + locations_common + shortidentifier + + + + + + objectNameProperty + displayName + + + objectNumberProperty + shortIdentifier + + + + + + + + + + - - termRef + + termRef locationType - - - termRef + + + termRef termStatus - + - - - - - - - - - - - - + + + + + + + + + + + + - - - /taxonomyauthority/*/workflow/ - /taxonomyauthority/*/items/*/workflow/ + + + /taxonomyauthority/*/workflow/ + /taxonomyauthority/*/items/*/workflow/ - default-domain - org.collectionspace.services.taxonomy.nuxeo.TaxonomyAuthorityDocumentModelHandler - - - - - displayName - displayName - - - refName - refName - - - shortIdentifier - shortIdentifier - - - vocabType - vocabType - - - - - - org.collectionspace.services.common.init.AddIndices - - - taxonomyauthority_common - displayname - - - taxonomyauthority_common - shortidentifier - - - - - - - - - - - - - - - - - - - - - - + default-domain + org.collectionspace.services.taxonomy.nuxeo.TaxonomyAuthorityDocumentModelHandler + + + + + displayName + displayName + + + refName + refName + + + shortIdentifier + shortIdentifier + + + vocabType + vocabType + + + + + + org.collectionspace.services.common.init.AddIndices + + + taxonomyauthority_common + displayname + + + taxonomyauthority_common + shortidentifier + + + + + + + + + + + + + + + + + + + + + + - - - default-domain - org.collectionspace.services.taxonomy.nuxeo.TaxonDocumentModelHandler - - - - - - - - org.collectionspace.services.taxonomy.nuxeo.TaxonValidatorHandler - - org.collectionspace.services.common.init.AddIndices - - - taxon_common - inauthority - - - taxon_common - displayname - - - taxon_common - shortidentifier - - - - - - objectNameProperty - displayName - - - objectNumberProperty - shortIdentifier - - - - - - - - - - + + default-domain + org.collectionspace.services.taxonomy.nuxeo.TaxonDocumentModelHandler + + + + + + + + org.collectionspace.services.taxonomy.nuxeo.TaxonValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + taxon_common + inauthority + + + taxon_common + displayname + + + taxon_common + shortidentifier + + + + + + objectNameProperty + displayName + + + objectNumberProperty + shortIdentifier + + + + + + + + + + - - authRef - taxonAuthorGroupList/*/taxonAuthor - + + authRef + taxonAuthorGroupList/*/taxonAuthor + - - termRef + + termRef taxonRank - - - termRef + + + termRef taxonCurrency - - - termRef + + + termRef taxonAuthorGroupList/*/taxonAuthorType - - - termRef - taxonomicStatus - - - termRef - taxonNameSource - - - termRef + + + termRef + taxonomicStatus + + + termRef + taxonNameSource + + + termRef termStatus - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - /acquisitions/*/workflow/ + + + /acquisitions/*/workflow/ - default-domain - org.collectionspace.services.acquisition.nuxeo.AcquisitionDocumentModelHandler - - - - - acquisitionReferenceNumber - acquisitionReferenceNumber - - - acquisitionSource - acquisitionSources/[0] - - - owner - owners/[0] - - - - - org.collectionspace.services.acquisition.nuxeo.AcquisitionValidatorHandler - - + default-domain + org.collectionspace.services.acquisition.nuxeo.AcquisitionDocumentModelHandler + + + + + acquisitionReferenceNumber + acquisitionReferenceNumber + + + acquisitionSource + acquisitionSources/[0] + + + owner + owners/[0] + + + + + org.collectionspace.services.acquisition.nuxeo.AcquisitionValidatorHandler + + objectNameProperty acquisitionSources/[0] - objectNumberProperty - acquisitionReferenceNumber - - - - - - - - - - + objectNumberProperty + acquisitionReferenceNumber + + + + + + + + + + - - authRef - acquisitionAuthorizer - - - authRef + + authRef + acquisitionAuthorizer + + + authRef acquisitionFundingList/*/acquisitionFundingSource authRef - owners|owner - - - authRef - acquisitionSources|acquisitionSource - - - authRef - fieldCollectionEventNames|fieldCollectionEventName - + owners|owner + + + authRef + acquisitionSources|acquisitionSource + + + authRef + fieldCollectionEventNames|fieldCollectionEventName + - + termRef acquisitionFundingList/*/acquisitionFundingCurrency - - - termRef - acquisitionMethod - - - termRef - groupPurchasePriceCurrency - - - termRef - objectOfferPriceCurrency - - - termRef - objectPurchaseOfferPriceCurrency - - - termRef - objectPurchasePriceCurrency - - - termRef + + + termRef + acquisitionMethod + + + termRef + groupPurchasePriceCurrency + + + termRef + objectOfferPriceCurrency + + + termRef + objectPurchaseOfferPriceCurrency + + + termRef + objectPurchasePriceCurrency + + + termRef originalObjectPurchasePriceCurrency - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - /relations/*/workflow/ + + + /relations/*/workflow/ - default-domain - org.collectionspace.services.relation.nuxeo.RelationDocumentModelHandler - - - - - org.collectionspace.services.relation.nuxeo.RelationValidatorHandler - - - objectNameProperty - subjectCsid - - - objectNumberProperty - predicateDisplayName - - - - org.collectionspace.services.common.init.AddIndices - - - - - - collectionspace_core - updatedat - - - relations_common - subjectcsid,objectcsid - - - - - - - - - - - - - - - - - - - - - - + default-domain + org.collectionspace.services.relation.nuxeo.RelationDocumentModelHandler + + + + + org.collectionspace.services.relation.nuxeo.RelationValidatorHandler + + + objectNameProperty + subjectCsid + + + objectNumberProperty + predicateDisplayName + + + + org.collectionspace.services.common.init.AddIndices + + + + + + collectionspace_core + updatedat + + + relations_common + subjectcsid,objectcsid + + + + + + + + + + + + + + + + + + + + + + - - + + - org.collectionspace.services.account.storage.AccountDocumentHandler - - - - - screenName - screenName - - - personRefName - personRefName - - - email - email - - - status - status - - - - - org.collectionspace.services.account.storage.AccountValidatorHandler - - - - - - - - - - - - - - - - - - - + org.collectionspace.services.account.storage.AccountDocumentHandler + + + + + screenName + screenName + + + personRefName + personRefName + + + email + email + + + status + status + + + + + org.collectionspace.services.account.storage.AccountValidatorHandler + + + + + + + + + + + + + + + + + + + - - + + - /dimensions/*/workflow/ - default-domain - org.collectionspace.services.dimension.nuxeo.DimensionDocumentModelHandler - - - - - - - - - - - - - - - - - - - + /dimensions/*/workflow/ + default-domain + org.collectionspace.services.dimension.nuxeo.DimensionDocumentModelHandler + + + + + + + + + + + + + + + + + + + - - + + - default-domain - org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler - - - - - displayName - displayName - - - - - - - - - - - - + default-domain + org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler + + + + + displayName + displayName + + + + + + + + + + + + - - authRef - addressGroupList/*/addressMunicipality - - - authRef - addressGroupList/*/addressStateOrProvince - - - authRef - addressGroupList/*/addressCountry - + + authRef + addressGroupList/*/addressMunicipality + + + authRef + addressGroupList/*/addressStateOrProvince + + + authRef + addressGroupList/*/addressCountry + - - termRef - emailGroupList/*/emailType - - - termRef + + termRef + emailGroupList/*/emailType + + + termRef telephoneNumberGroupList/*/telephoneNumberType - - - termRef + + + termRef faxNumberGroupList/*/faxNumberType - - - termRef + + + termRef webAddressGroupList/*/webAddressType - - - termRef - addressGroupList/*/addressType - - - - - - - - - - - - - - + + + termRef + addressGroupList/*/addressType + + + + + + + + + + + + + + - - - default-domain - org.collectionspace.services.note.nuxeo.NoteDocumentModelHandler - - - - - - - - - - - - - - - - - - + + + /notes/*/workflow/ + default-domain + org.collectionspace.services.note.nuxeo.NoteDocumentModelHandler + + + + + + + + + + + + + + + + + + - + - org.collectionspace.services.authorization.storage.RoleDocumentHandler - org.collectionspace.services.authorization.storage.RoleValidatorHandler - - - - - - - - - - - - - - + org.collectionspace.services.authorization.storage.RoleDocumentHandler + org.collectionspace.services.authorization.storage.RoleValidatorHandler + + + + + + + + + + + + + + - - + + - org.collectionspace.services.authorization.storage.PermissionDocumentHandler - org.collectionspace.services.authorization.storage.PermissionValidatorHandler - - - - - - - - - - - - - - + org.collectionspace.services.authorization.storage.PermissionDocumentHandler + org.collectionspace.services.authorization.storage.PermissionValidatorHandler + + + + + + + + + + + + + + - - - - + + + + - org.collectionspace.services.authorization.storage.PermissionRoleDocumentHandler + org.collectionspace.services.authorization.storage.PermissionRoleDocumentHandler - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - + + - org.collectionspace.services.account.storage.AccountRoleDocumentHandler + org.collectionspace.services.account.storage.AccountRoleDocumentHandler - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - org.collectionspace.services.authorization.storage.PermissionRoleDocumentHandler + org.collectionspace.services.authorization.storage.PermissionRoleDocumentHandler - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - org.collectionspace.services.account.storage.AccountRoleDocumentHandler + org.collectionspace.services.account.storage.AccountRoleDocumentHandler - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java index 2ccf7c99d..0f663c429 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java @@ -725,10 +725,14 @@ public class NuxeoImageUtils { String digestAlgorithm = getFileManagerService() .getDigestAlgorithm(); // Need some way on initializing the // FileManager with a call. + + logger.debug("Start --> Calling Nuxeo to create an image blob."); DocumentModel documentModel = getFileManagerService() .createDocumentFromBlob(nuxeoSession, fileBlob, blobLocation.getPathAsString(), true, file.getName()); + logger.debug("Stop --> Calling Nuxeo to create an image blob."); + result = createBlobsCommon(documentModel, fileBlob); } catch (Exception e) { result = null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java b/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java index d7ea17363..4f82e784f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java @@ -113,6 +113,12 @@ public class Profiler { setStartTime(currentTime()); } + private void stopTimer() { + setStopTime(currentTime()); + setElapsedTime(getStopTime() - getStartTime()); + addToCumulativeTime(getElapsedTime()); + } + /** * Stores and logs the stop time, and the elapsed and cumulative timings * from one or more cycles of start and stop. @@ -120,12 +126,8 @@ public class Profiler { * Logs using a default message. */ public void stop() { - // FIXME: Need to store values before constructing default stop message, - // hence has some redundant code with stop(msg) below. Perhaps can be consolidated. - setStopTime(currentTime()); - setElapsedTime(elapsedTime()); - addToCumulativeTime(elapsedTime()); - stop(defaultStopMessage()); + stopTimer(); + log(defaultStopMessage()); } /** @@ -135,9 +137,7 @@ public class Profiler { * @param msg the message to log. */ public void stop(String msg) { - setStopTime(currentTime()); - setElapsedTime(elapsedTime()); - addToCumulativeTime(elapsedTime()); + stopTimer(); log(msg); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java index b421640d8..73838db01 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java @@ -5,7 +5,7 @@ import java.util.List; import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; -import org.collectionspace.services.hyperjaxb.AbstractCommonList; +import org.collectionspace.services.jaxb.AbstractCommonList; public abstract class JpaDocumentHandler extends AbstractDocumentHandlerImpl{ diff --git a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java index 71ae9c1b7..59b334800 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java @@ -131,9 +131,14 @@ public class WorkflowDocumentModelHandler result = TRANSITION_APPROVE; } else if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_PROJECT)) { result = TRANSITION_UNDELETE; - } + } else { + logger.warn("An attempt was made to transition a document to an unknown workflow state = " + + state); + } + return result; } + /* * Handle Update (PUT) */ @@ -143,8 +148,22 @@ public class WorkflowDocumentModelHandler ObjectPartType partMeta, Action action, ServiceContext ctx) throws Exception { - WorkflowCommon workflowsCommon = (WorkflowCommon) part.getBody(); - docModel.followTransition(getTransitionFromState(workflowsCommon.getCurrentLifeCycleState())); + String toState = null; + + try { + WorkflowCommon workflowsCommon = (WorkflowCommon) part.getBody(); + toState = getTransitionFromState(workflowsCommon.getCurrentLifeCycleState()); + docModel.followTransition(toState); + } catch (Exception e) { + String msg = "Unable to follow workflow transition to state = " + + toState; + if (logger.isDebugEnabled() == true) { + logger.debug(msg, e); + } + ClientException ce = new ClientException("Unable to follow workflow transition to state = " + + toState); + throw ce; + } } } diff --git a/services/contact/client/pom.xml b/services/contact/client/pom.xml index 05756cf1a..5d1958199 100644 --- a/services/contact/client/pom.xml +++ b/services/contact/client/pom.xml @@ -49,7 +49,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java index ee7955802..d5ffa928f 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java @@ -10,8 +10,8 @@ import org.jboss.resteasy.client.ClientResponse; * ILT - Authority item list type * P - Proxy type */ -public interface AuthorityWithContactsClient

- extends AuthorityClient

{ +public interface AuthorityWithContactsClient + extends AuthorityClient { /** * Creates the contact. * diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java index 9dd97a070..9f55df44b 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java @@ -10,9 +10,9 @@ import org.collectionspace.services.jaxb.AbstractCommonList; * ILT - Authority item list type * P - Proxy type */ -public abstract class AuthorityWithContactsClientImpl

- extends AuthorityClientImpl

- implements AuthorityWithContactsClient

{ +public abstract class AuthorityWithContactsClientImpl + extends AuthorityClientImpl + implements AuthorityWithContactsClient { @Override public ClientResponse createContact(String parentcsid, diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java index 2471a8e8e..2d25618ec 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java @@ -21,6 +21,7 @@ package org.collectionspace.services.client; * * $LastChangedRevision: $ * $LastChangedDate: $ + * */ public class ContactClient extends AbstractCommonListPoxServiceClientImpl { diff --git a/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java index 66629c3da..2d0025aee 100644 --- a/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java +++ b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java @@ -26,13 +26,13 @@ import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.ContactClient; import org.collectionspace.services.client.ContactClientUtils; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.contact.AddressGroup; import org.collectionspace.services.contact.AddressGroupList; import org.collectionspace.services.contact.ContactsCommon; @@ -43,7 +43,6 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; -import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,13 +54,12 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class ContactServiceTest extends AbstractServiceTestImpl { +public class ContactServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = ContactServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(ContactServiceTest.class); // Instance variables specific to this test. // final String SERVICE_PATH_COMPONENT = "contacts"; - private String knownResourceId = null; @Override public String getServicePathComponent() { @@ -85,7 +83,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { return response.getEntity(AbstractCommonList.class); } @@ -101,13 +99,10 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -131,9 +126,9 @@ public class ContactServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -150,8 +145,8 @@ public class ContactServiceTest extends AbstractServiceTestImpl { } @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { for (int i = 0; i < 3; i++) { create(testName); @@ -269,52 +264,26 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); // Submit the request to the service and store the response. ContactClient client = new ContactClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ContactsCommon contact = (ContactsCommon) extractPart(input, - client.getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(contact); - } - - // Failure outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - ContactClient client = new ContactClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + ContactsCommon contact = (ContactsCommon) extractPart(input, + client.getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // --------------------------------------------------------------- @@ -322,28 +291,29 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. ContactClient client = new ContactClient(); ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + try { + assertStatusCode(res, testName); + AbstractCommonList list = res.getEntity(); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } - } // Failure outcomes @@ -353,28 +323,32 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); - - // Submit the request to the service and store the response. + // + // First read the object that will be updated + // ContactClient client = new ContactClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - if (logger.isDebugEnabled()) { - logger.debug("got object to update with ID: " + knownResourceId); + ContactsCommon contact = null; + try { + assertStatusCode(res, testName); + + if (logger.isDebugEnabled()) { + logger.debug("got object to update with ID: " + knownResourceId); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + contact = (ContactsCommon) extractPart(input, + client.getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + } finally { + if (res != null) { + res.releaseConnection(); + } } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ContactsCommon contact = (ContactsCommon) extractPart(input, - client.getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(contact); if(logger.isDebugEnabled()){ logger.debug("contact common before updating"); @@ -412,20 +386,25 @@ public class ContactServiceTest extends AbstractServiceTestImpl { logger.debug("to be updated object"); logger.debug(BaseServiceTest.objectAsXmlString(contact, ContactsCommon.class)); } - - // Submit the request to the service and store the response. + // + // Next, send the update to the server + // PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), contact); res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - input = new PoxPayloadIn(res.getEntity()); - ContactsCommon updatedContact = - (ContactsCommon) extractPart(input, - client.getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(updatedContact); + ContactsCommon updatedContact = null; + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + updatedContact = (ContactsCommon) extractPart(input, + client.getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(updatedContact); + } finally { + if (res != null) { + res.releaseConnection(); + } + } if (logger.isDebugEnabled()) { logger.debug("object after update"); @@ -549,13 +528,9 @@ public class ContactServiceTest extends AbstractServiceTestImpl { } */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"update", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdateNonExistent(); @@ -574,9 +549,9 @@ public class ContactServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -584,13 +559,9 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDelete(); @@ -604,20 +575,16 @@ public class ContactServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // Failure outcomes @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDeleteNonExistent(); @@ -631,9 +598,9 @@ public class ContactServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -643,7 +610,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { * Tests the code for manually submitting data that is used by several * of the methods above. */ - @Test(dependsOnMethods = {"create", "read"}) +// @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() { // Expected status code: 200 OK @@ -661,6 +628,39 @@ public class ContactServiceTest extends AbstractServiceTestImpl { + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); - } + + @Override + public void readWorkflow(String testName) throws Exception { + // Not applicable for the Contact service + } + + @Override + public void searchWorkflowDeleted(String testName) throws Exception { + // Not applicable for the Contact service + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return ContactClientUtils.createContactInstance(identifier, commonPartName); + } + + @Override + protected ContactsCommon updateInstance(ContactsCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(ContactsCommon original, + ContactsCommon updated) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + } } diff --git a/services/contact/service/pom.xml b/services/contact/service/pom.xml index 327f534c1..c7a414cc2 100644 --- a/services/contact/service/pom.xml +++ b/services/contact/service/pom.xml @@ -38,7 +38,6 @@ org.testng testng - 5.6 diff --git a/services/dimension/client/pom.xml b/services/dimension/client/pom.xml index cac291a85..f10ab8f0c 100644 --- a/services/dimension/client/pom.xml +++ b/services/dimension/client/pom.xml @@ -10,7 +10,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.dimension.client services.dimension.client @@ -51,7 +50,7 @@ org.testng testng - 5.6 + test org.jboss.resteasy diff --git a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java index e65cee363..92c041295 100644 --- a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java +++ b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java @@ -36,7 +36,7 @@ import org.jboss.resteasy.client.ClientResponse; */ public class DimensionClient extends AbstractPoxServiceClientImpl { public static final String SERVICE_NAME = "dimensions"; - public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/"; public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; diff --git a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java index 1e5c6a5dd..f8d729dc9 100644 --- a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java +++ b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java @@ -20,8 +20,8 @@ public interface DimensionProxy extends CollectionSpacePoxProxy readList(); - - @Override + + @Override @GET @Produces({"application/xml"}) ClientResponse readIncludeDeleted( diff --git a/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java b/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java index 75e8a5fe1..b7c8b2266 100644 --- a/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java +++ b/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java @@ -25,23 +25,13 @@ package org.collectionspace.services.client.test; //import java.util.ArrayList; import java.math.BigDecimal; import java.util.List; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.DimensionClient; import org.collectionspace.services.client.DimensionFactory; -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.workflow.WorkflowClient; import org.collectionspace.services.dimension.DimensionsCommon; import org.collectionspace.services.dimension.DimensionsCommonList; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.workflow.WorkflowCommon; - -import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; //import org.testng.annotations.AfterClass; @@ -57,7 +47,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class DimensionServiceTest extends AbstractServiceTestImpl { +public class DimensionServiceTest extends AbstractPoxServiceTestImpl { /** The logger. */ private final String CLASS_NAME = DimensionServiceTest.class.getName(); @@ -65,10 +55,13 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // Instance variables specific to this test. /** The SERVIC e_ pat h_ component. */ - /** The known resource id. */ - private String knownResourceId = null; private final String DIMENSION_VALUE = "78.306"; + @Override + protected Logger getLogger() { + return this.logger; + } + @Override protected String getServiceName() { return DimensionClient.SERVICE_NAME; @@ -82,109 +75,176 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { return new DimensionClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(DimensionsCommonList.class); + protected Class getCommonListType() { + return DimensionsCommonList.class; } + /* + * This method gets called by the parent's method public void readList(String testName) + */ + protected void printList(String testName, DimensionsCommonList list) { + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + List items = + list.getDimensionListItem(); + int i = 0; + for (DimensionsCommonList.DimensionListItem item : items) { + logger.debug(testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(testName + ": list-item[" + i + "] objectNumber=" + + item.getDimension()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + i++; + } + } + } + + protected void compareInstances(DimensionsCommon original, DimensionsCommon updated) throws Exception { + Assert.assertEquals(original.getValueDate(), + updated.getValueDate(), + "Data in updated object did not match submitted data."); + } + + @Override + protected DimensionsCommon updateInstance(DimensionsCommon dimensionsCommon) { + DimensionsCommon result = new DimensionsCommon(); + + // Update the content of this resource. + result.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0"))); + result.setValueDate("updated-" + dimensionsCommon.getValueDate()); + + return result; + } + // --------------------------------------------------------------- - // CRUD tests : CREATE tests + // Utility methods used by tests above // --------------------------------------------------------------- - // Success outcomes /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); + public String getServicePathComponent() { + return DimensionClient.SERVICE_PATH_COMPONENT; + } - // Submit the request to the service and store the response. - DimensionClient client = new DimensionClient(); - String identifier = createIdentifier(); - PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(), - identifier); - ClientResponse res = client.create(multipart); + @Override + protected PoxPayloadOut createInstance(String identifier) { + DimensionClient client = new DimensionClient(); + return createInstance(client.getCommonPartName(), identifier); + } + + /** + * Creates the dimension instance. + * + * @param identifier the identifier + * @return the multipart output + */ + @Override + protected PoxPayloadOut createInstance(String commonPartName, String identifier) { + return createDimensionInstance(commonPartName, + "dimensionType-" + identifier, + DIMENSION_VALUE, + "entryDate-" + identifier); + } - int statusCode = res.getStatus(); + /** + * Creates the dimension instance. + * + * @param dimensionType the dimension type + * @param entryNumber the entry number + * @param entryDate the entry date + * @return the multipart output + */ + private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) { + DimensionsCommon dimensionsCommon = new DimensionsCommon(); + dimensionsCommon.setDimension(dimensionType); + dimensionsCommon.setValue(new BigDecimal(dimensionValue)); + dimensionsCommon.setValueDate(entryDate); + PoxPayloadOut multipart = DimensionFactory.createDimensionInstance( + commonPartName, dimensionsCommon); - // 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null) { - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } + logger.debug("to be created, dimension common"); + logger.debug(objectAsXmlString(dimensionsCommon, + DimensionsCommon.class)); } - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); + return multipart; } + + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - for (int i = 0; i < 3; i++) { - create(testName); - } + public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) */ @Override - public void createWithEmptyEntityBody(String testName) throws Exception { + public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? + } + + @Override + public void createWithEmptyEntityBody(String testName) throws Exception { + //FIXME: Should this test really be empty? + } + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception { //Should this really be empty? } /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) */ @Override - public void createWithMalformedXml(String testName) throws Exception { + public void updateWithMalformedXml(String testName) throws Exception { //Should this really be empty? } /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) */ @Override - public void createWithWrongXmlSchema(String testName) throws Exception { + public void updateWithWrongXmlSchema(String testName) throws Exception { //Should this really be empty? } + @Override + protected void compareUpdatedInstances(DimensionsCommon original, + DimensionsCommon updated) throws Exception { + //Check the dimension value to see if the update happened correctly + BigDecimal expectedValue = original.getValue(); + BigDecimal actualValue = updated.getValue(); + Assert.assertTrue(actualValue.compareTo(expectedValue) == 0); + + //Next, check the date value to see if it was updated + String expectedDate = original.getValueDate(); + String actualDate = updated.getValueDate(); + Assert.assertEquals(actualDate, expectedDate); + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // Do nothing. Simply here to for a TestNG execution order for our tests + } + /* @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, @@ -272,201 +332,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } - */ - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - DimensionClient client = new DimensionClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - DimensionsCommon dimensionsCommon = null; - if (payloadInputPart != null) { - dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(dimensionsCommon); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - DimensionClient client = new DimensionClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - DimensionClient client = new DimensionClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - DimensionsCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - List items = - list.getDimensionListItem(); - int i = 0; - for (DimensionsCommonList.DimensionListItem item : items) { - logger.debug(testName + ": list-item[" + i + "] csid=" - + item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] objectNumber=" - + item.getDimension()); - logger.debug(testName + ": list-item[" + i + "] URI=" - + item.getUri()); - i++; - } - } - - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - DimensionClient client = new DimensionClient(); - ClientResponse res = - client.read(knownResourceId); - assertStatusCode(res, testName); - if (logger.isDebugEnabled()) { - logger.debug("got object to update with ID: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - DimensionsCommon dimensionsCommon = null; - if (payloadInputPart != null) { - dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(dimensionsCommon); - - // Update the content of this resource. - dimensionsCommon.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0"))); - dimensionsCommon.setValueDate("updated-" + dimensionsCommon.getValueDate()); - if (logger.isDebugEnabled()) { - logger.debug("to be updated object"); - logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class)); - } - // Submit the request to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(dimensionsCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - - res = client.update(knownResourceId, output); - int statusCode = res.getStatus(); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - DimensionsCommon updatedDimensionsCommon = - (DimensionsCommon) extractPart(input, - client.getCommonPartName(), DimensionsCommon.class); - Assert.assertNotNull(updatedDimensionsCommon); - - Assert.assertEquals(updatedDimensionsCommon.getValueDate(), - dimensionsCommon.getValueDate(), - "Data in updated object did not match submitted data."); - - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - +*/ /* @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, @@ -554,282 +420,5 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } - */ - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - DimensionClient client = new DimensionClient(); - PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(), - NON_EXISTENT_ID); - ClientResponse res = - client.update(NON_EXISTENT_ID, multipart); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "readWorkflow"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - DimensionClient client = new DimensionClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - DimensionClient client = new DimensionClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // Search tests - // --------------------------------------------------------------- - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void searchWorkflowDeleted(String testName) throws Exception { - // Fixme: null test for now, overriding test in base class - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() - */ - @Override - public String getServicePathComponent() { - return DimensionClient.SERVICE_PATH_COMPONENT; - } - - @Override - protected PoxPayloadOut createInstance(String identifier) { - DimensionClient client = new DimensionClient(); - return createDimensionInstance(client.getCommonPartName(), identifier); - } - - /** - * Creates the dimension instance. - * - * @param identifier the identifier - * @return the multipart output - */ - private PoxPayloadOut createDimensionInstance(String commonPartName, String identifier) { - return createDimensionInstance(commonPartName, - "dimensionType-" + identifier, - DIMENSION_VALUE, - "entryDate-" + identifier); - } - - /** - * Creates the dimension instance. - * - * @param dimensionType the dimension type - * @param entryNumber the entry number - * @param entryDate the entry date - * @return the multipart output - */ - private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) { - DimensionsCommon dimensionsCommon = new DimensionsCommon(); - dimensionsCommon.setDimension(dimensionType); - dimensionsCommon.setValue(new BigDecimal(dimensionValue)); - dimensionsCommon.setValueDate(entryDate); - PoxPayloadOut multipart = DimensionFactory.createDimensionInstance( - commonPartName, dimensionsCommon); - - if (logger.isDebugEnabled()) { - logger.debug("to be created, dimension common"); - logger.debug(objectAsXmlString(dimensionsCommon, - DimensionsCommon.class)); - } - - return multipart; - } - -// @Override -// protected String createTestObject(String testName) throws Exception { -// String result = null; -// -// DimensionClient client = new DimensionClient(); -// String identifier = createIdentifier(); -// PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(), -// identifier); -// ClientResponse res = client.create(multipart); -// -// int statusCode = res.getStatus(); -// Assert.assertEquals(statusCode, STATUS_CREATED); -// -// result = extractId(res); -// allResourceIdsCreated.add(result); -// -// return result; -// } - -// /* -// * This test assumes that no objects exist yet. -// * -// * http://localhost:8180/cspace-services/intakes?wf_deleted=false -// */ -// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"}) -// public void readWorkflowList(String testName) throws Exception { -// // -// // Create 3 new objects -// // -// final int OBJECTS_TOTAL = 3; -// for (int i = 0; i < OBJECTS_TOTAL; i++) { -// this.createWorkflowTarget(testName); -// } -// // -// // Mark one as soft deleted -// // -// int currentTotal = allResourceIdsCreated.size(); -// String csid = allResourceIdsCreated.get(currentTotal - 1); //0-based index to get the last one added -// this.setupUpdate(); -// this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED); -// // -// // Read the list back. The deleted item should not be in the list -// // -//// int updatedTotal = readIncludeDeleted(testName, Boolean.FALSE); -//// Assert.assertEquals(updatedTotal, currentTotal - 1, "Deleted items seem to be returned in list results."); -// } - - protected void updateLifeCycleState(String testName, String resourceId, String lifeCycleState) throws Exception { - // - // Read the existing object - // - DimensionClient client = new DimensionClient(); - ClientResponse res = client.getWorkflow(resourceId); - assertStatusCode(res, testName); - logger.debug("Got object to update life cycle state with ID: " + resourceId); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(workflowCommons); - // - // Mark it for a soft delete. - // - logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class)); - workflowCommons.setCurrentLifeCycleState(lifeCycleState); - PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(workflowCommons, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(WorkflowClient.SERVICE_COMMONPART_NAME); - // - // Perform the update - // - res = client.updateWorkflow(resourceId, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(updatedWorkflowCommons); - // - // Read the updated object and make sure it was updated correctly. - // - res = client.getWorkflow(resourceId); - assertStatusCode(res, testName); - logger.debug("Got workflow state of updated object with ID: " + resourceId); - input = new PoxPayloadIn(res.getEntity()); - updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - Assert.assertNotNull(workflowCommons); - Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState); - } - +*/ } diff --git a/services/dimension/jaxb/pom.xml b/services/dimension/jaxb/pom.xml index d2925bdc5..3bbba1b90 100644 --- a/services/dimension/jaxb/pom.xml +++ b/services/dimension/jaxb/pom.xml @@ -10,7 +10,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.dimension.jaxb services.dimension.jaxb @@ -20,6 +19,11 @@ org.collectionspace.services.jaxb ${project.version} + + org.collectionspace.services + org.collectionspace.services.hyperjaxb + ${project.version} + diff --git a/services/dimension/jaxb/src/main/resources/dimensions-common.xsd b/services/dimension/jaxb/src/main/resources/dimensions-common.xsd index a23171c41..fd46cf25d 100644 --- a/services/dimension/jaxb/src/main/resources/dimensions-common.xsd +++ b/services/dimension/jaxb/src/main/resources/dimensions-common.xsd @@ -13,8 +13,8 @@ - - + + diff --git a/services/dimension/pom.xml b/services/dimension/pom.xml index bf90df958..b1097c2c9 100644 --- a/services/dimension/pom.xml +++ b/services/dimension/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.dimension services.dimension pom diff --git a/services/dimension/service/pom.xml b/services/dimension/service/pom.xml index a5cec6693..39787294b 100644 --- a/services/dimension/service/pom.xml +++ b/services/dimension/service/pom.xml @@ -45,7 +45,6 @@ org.testng testng - 5.6 diff --git a/services/group/client/pom.xml b/services/group/client/pom.xml index 729c4e91c..a4ae3bdff 100644 --- a/services/group/client/pom.xml +++ b/services/group/client/pom.xml @@ -62,7 +62,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/group/client/src/main/java/org/collectionspace/services/client/GroupClient.java b/services/group/client/src/main/java/org/collectionspace/services/client/GroupClient.java index fce1d3404..1c820eef3 100644 --- a/services/group/client/src/main/java/org/collectionspace/services/client/GroupClient.java +++ b/services/group/client/src/main/java/org/collectionspace/services/client/GroupClient.java @@ -24,6 +24,7 @@ package org.collectionspace.services.client; * */ public class GroupClient extends AbstractCommonListPoxServiceClientImpl { + public static final String SERVICE_NAME = "groups"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -42,8 +43,6 @@ public class GroupClient extends AbstractCommonListPoxServiceClientImpl getProxyClass() { - // TODO Auto-generated method stub return GroupProxy.class; } - } diff --git a/services/group/client/src/test/java/org/collectionspace/services/client/test/GroupServiceTest.java b/services/group/client/src/test/java/org/collectionspace/services/client/test/GroupServiceTest.java index 216ee7e78..2acd4f4c6 100644 --- a/services/group/client/src/test/java/org/collectionspace/services/client/test/GroupServiceTest.java +++ b/services/group/client/src/test/java/org/collectionspace/services/client/test/GroupServiceTest.java @@ -22,17 +22,16 @@ */ package org.collectionspace.services.client.test; -import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.GroupClient; import org.collectionspace.services.client.GroupProxy; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.group.GroupsCommon; @@ -49,7 +48,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class GroupServiceTest extends AbstractServiceTestImpl { +public class GroupServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = GroupServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -67,183 +66,15 @@ public class GroupServiceTest extends AbstractServiceTestImpl { } @Override - protected CollectionSpaceClient getClientInstance() { + protected CollectionSpaceClient getClientInstance() { return new GroupClient(); } @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(ClientResponse response) { return response.getEntity(AbstractCommonList.class); } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupCreate(); - GroupClient client = new GroupClient(); - PoxPayloadOut multipart = createGroupInstance(createIdentifier()); - ClientResponse res = client.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) { - knownResourceId = extractId(res); // Store the ID returned from the first resource created for additional tests below. - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run. - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - for (int i = 0; i < 3; i++) { - create(testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupRead(); - GroupClient client = new GroupClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - GroupsCommon group = (GroupsCommon) extractPart(input, client.getCommonPartName(), GroupsCommon.class); - Assert.assertNotNull(group); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadList(); - GroupClient client = new GroupClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdate(); - GroupClient client = new GroupClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - logger.debug("got object to update with ID: " + knownResourceId); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - GroupsCommon group = (GroupsCommon) extractPart(input, client.getCommonPartName(), GroupsCommon.class); - Assert.assertNotNull(group); - - group.setTitle("updated-" + group.getTitle()); - logger.debug("Object to be updated:"+objectAsXmlString(group, GroupsCommon.class)); - PoxPayloadOut output = new PoxPayloadOut(GroupClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(group, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - GroupsCommon updatedGroup = (GroupsCommon) extractPart(input, client.getCommonPartName(), GroupsCommon.class); - Assert.assertNotNull(updatedGroup); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - GroupClient client = new GroupClient(); - PoxPayloadOut multipart = createGroupInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - assertStatusCode(res, testName); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDelete(); - GroupClient client = new GroupClient(); - ClientResponse res = client.delete(knownResourceId); - assertStatusCode(res, testName); - } - - // --------------------------------------------------------------- - // Failure outcome tests : means we expect response to fail, but test to succeed - // --------------------------------------------------------------- - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadNonExistent(); - GroupClient client = new GroupClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDeleteNonExistent(); - GroupClient client = new GroupClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcomes - // Placeholders until the tests below can be implemented. See Issue CSPACE-401. - - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - } - - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode); - Assert.assertEquals(statusCode, EXPECTED_STATUS); - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -251,9 +82,15 @@ public class GroupServiceTest extends AbstractServiceTestImpl { @Override protected PoxPayloadOut createInstance(String identifier) { GroupClient client = new GroupClient(); - return createGroupInstance(identifier); + return createInstance(client.getCommonPartName(), identifier); } + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return createGroupInstance(identifier); + } + private PoxPayloadOut createGroupInstance(String uid) { String identifier = "title-" + uid; GroupsCommon group = new GroupsCommon(); @@ -270,4 +107,25 @@ public class GroupServiceTest extends AbstractServiceTestImpl { return multipart; } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected GroupsCommon updateInstance(GroupsCommon groupsCommon) { + GroupsCommon result = new GroupsCommon(); + + result.setTitle("updated-" + groupsCommon.getTitle()); + + return result; + } + + @Override + protected void compareUpdatedInstances(GroupsCommon original, + GroupsCommon updated) throws Exception { + Assert.assertEquals(updated.getTitle(), original.getTitle()); + } } diff --git a/services/group/service/pom.xml b/services/group/service/pom.xml index d92827f97..a3464eea7 100644 --- a/services/group/service/pom.xml +++ b/services/group/service/pom.xml @@ -44,7 +44,6 @@ org.testng testng - 5.6 diff --git a/services/hyperjaxb/src/main/resources/AbstractCommonList.xsd b/services/hyperjaxb/src/main/resources/AbstractCommonList.xsd deleted file mode 100644 index b5906a88e..000000000 --- a/services/hyperjaxb/src/main/resources/AbstractCommonList.xsd +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/services/hyperjaxb/src/main/resources/permissions_list.xsd b/services/hyperjaxb/src/main/resources/permissions_list.xsd index 83234aaae..2427a84df 100644 --- a/services/hyperjaxb/src/main/resources/permissions_list.xsd +++ b/services/hyperjaxb/src/main/resources/permissions_list.xsd @@ -26,8 +26,7 @@ - + --> @@ -47,86 +46,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AccountsCommonList contains information about one or more - accounts. An instance of this type could be returned on - index and search operations. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/services/id/client/src/main/java/org/collectionspace/services/client/IdClient.java b/services/id/client/src/main/java/org/collectionspace/services/client/IdClient.java index fc1f5ebd4..a2c6d7242 100644 --- a/services/id/client/src/main/java/org/collectionspace/services/client/IdClient.java +++ b/services/id/client/src/main/java/org/collectionspace/services/client/IdClient.java @@ -9,7 +9,7 @@ import org.jboss.resteasy.client.ClientResponse; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class IdClient extends AbstractServiceClientImpl { +public class IdClient extends AbstractServiceClientImpl { /* (non-Javadoc) * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent() @@ -57,4 +57,8 @@ public class IdClient extends AbstractServiceClientImpl { public ClientResponse createId(String csid) { return getProxy().createId(csid); } + + @Override + public ClientResponse update(String csid, String payload) { + throw new UnsupportedOperationException("ID client does not support an update operation."); } } diff --git a/services/id/client/src/test/java/org/collectionspace/services/client/test/IdServiceTest.java b/services/id/client/src/test/java/org/collectionspace/services/client/test/IdServiceTest.java index 819a9be05..9f8f75001 100644 --- a/services/id/client/src/test/java/org/collectionspace/services/client/test/IdServiceTest.java +++ b/services/id/client/src/test/java/org/collectionspace/services/client/test/IdServiceTest.java @@ -66,17 +66,7 @@ public class IdServiceTest extends BaseServiceTest { */ @Override protected CollectionSpaceClient getClientInstance() { - return new IdClient(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - throw new UnsupportedOperationException( - "IdServiceTest.getAbstractCommonList method is not currently supported."); + return (CollectionSpaceClient) new IdClient(); } // --------------------------------------------------------------- @@ -87,11 +77,6 @@ public class IdServiceTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - }; - // Perform setup. testSetup(STATUS_CREATED, ServiceRequestType.CREATE); @@ -108,9 +93,9 @@ public class IdServiceTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); String newID = extractId(res); @@ -133,11 +118,6 @@ public class IdServiceTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createId(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - }; - // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -146,27 +126,37 @@ public class IdServiceTest extends BaseServiceTest { // Submit the request to the service and store the response. IdClient client = new IdClient(); ClientResponse res = client.createId(knownResourceId); - assertStatusCode(res, testName); - - String generatedId = res.getEntity(); - Assert.assertNotNull(generatedId); - Assert.assertFalse(generatedId.isEmpty()); - if (logger.isDebugEnabled()) { - logger.debug("generated ID=" + generatedId); + String generatedId = null; + try { + assertStatusCode(res, testName); + generatedId = res.getEntity(); + Assert.assertNotNull(generatedId); + Assert.assertFalse(generatedId.isEmpty()); + if (logger.isDebugEnabled()) { + logger.debug("generated ID=" + generatedId); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } - // Create a second ID. Verify that it is different from the first. // Assumes that the last part in the ID pattern generates values // that will always differ at each generation. res = client.createId(knownResourceId); - assertStatusCode(res, testName); - - String secondGeneratedId = res.getEntity(); - Assert.assertNotNull(secondGeneratedId); - Assert.assertFalse(secondGeneratedId.isEmpty()); - Assert.assertFalse(secondGeneratedId.equals(generatedId)); - if (logger.isDebugEnabled()) { - logger.debug("second generated ID=" + secondGeneratedId); + try { + assertStatusCode(res, testName); + String secondGeneratedId = res.getEntity(); + Assert.assertNotNull(secondGeneratedId); + Assert.assertFalse(secondGeneratedId.isEmpty()); + Assert.assertFalse(secondGeneratedId.equals(generatedId)); + if (logger.isDebugEnabled()) { + logger.debug("second generated ID=" + secondGeneratedId); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } } @@ -183,11 +173,6 @@ public class IdServiceTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - }; - // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); @@ -198,7 +183,17 @@ public class IdServiceTest extends BaseServiceTest { // Submit the request to the service and store the response. IdClient client = new IdClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + 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); + String entity = res.getEntity(); Assert.assertNotNull(entity); if (logger.isDebugEnabled()) { @@ -218,18 +213,32 @@ public class IdServiceTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - }; - // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ_LIST); // Submit the request to the service and store the response. IdClient client = new IdClient(); ClientResponse res = client.readList(); - assertStatusCode(res, testName); + 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); + + // 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); + String entity = res.getEntity(); Assert.assertNotNull(entity); if (logger.isDebugEnabled()) { @@ -244,11 +253,6 @@ public class IdServiceTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create", "createId", "read", "readList"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. testSetup(STATUS_OK, ServiceRequestType.DELETE); @@ -262,9 +266,9 @@ public class IdServiceTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- diff --git a/services/imports/service/pom.xml b/services/imports/service/pom.xml index 736ea830e..2363444a9 100755 --- a/services/imports/service/pom.xml +++ b/services/imports/service/pom.xml @@ -45,7 +45,6 @@ org.testng testng - 5.6 diff --git a/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java b/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java index 5b4cecb71..8242eb1d7 100755 --- a/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java +++ b/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java @@ -24,7 +24,6 @@ package org.collectionspace.services.imports; -import java.io.*; import java.util.UUID; import org.collectionspace.services.common.IFragmentHandler; @@ -37,8 +36,6 @@ import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.dom4j.Document; import org.dom4j.Element; -import org.hibernate.sql.Template; -import org.testng.annotations.Test; import org.xml.sax.InputSource; /** This class expands templates specifically for the imports service. diff --git a/services/intake/client/pom.xml b/services/intake/client/pom.xml index 90d5fa273..241e62f8f 100644 --- a/services/intake/client/pom.xml +++ b/services/intake/client/pom.xml @@ -67,7 +67,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java b/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java index f18038a73..af3ab3534 100644 --- a/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java +++ b/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java @@ -48,7 +48,6 @@ public class IntakeClient extends AbstractCommonListPoxServiceClientImpl getProxyClass() { - // TODO Auto-generated method stub return IntakeProxy.class; } } diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java index b324cc1e1..cb27abf31 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; @@ -64,7 +63,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 1327 $ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ */ -public class IntakeAuthRefsTest extends BaseServiceTest { +public class IntakeAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = IntakeAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -102,7 +101,7 @@ public class IntakeAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -113,10 +112,6 @@ public class IntakeAuthRefsTest extends BaseServiceTest { // Success outcomes @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void createWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Submit the request to the service and store the response. @@ -148,9 +143,9 @@ public class IntakeAuthRefsTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -173,8 +168,8 @@ public class IntakeAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); @@ -213,42 +208,49 @@ public class IntakeAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } // Success outcomes - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. IntakeClient intakeClient = new IntakeClient(); ClientResponse res = intakeClient.read(knownResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - IntakesCommon intake = (IntakesCommon) extractPart(input, - intakeClient.getCommonPartName(), IntakesCommon.class); - Assert.assertNotNull(intake); - // Check a couple of fields - Assert.assertEquals(intake.getCurrentOwner(), currentOwnerRefName); - Assert.assertEquals(intake.getConditionCheckersOrAssessors().getConditionCheckerOrAssessor().get(0), conditionCheckerOrAssessorRefName); - Assert.assertEquals(intake.getInsurers().getInsurer().get(0), insurerRefName); + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + IntakesCommon intake = (IntakesCommon) extractPart(input, + intakeClient.getCommonPartName(), IntakesCommon.class); + Assert.assertNotNull(intake); + // Check a couple of fields + Assert.assertEquals(intake.getCurrentOwner(), currentOwnerRefName); + Assert.assertEquals(intake.getConditionCheckersOrAssessors().getConditionCheckerOrAssessor().get(0), conditionCheckerOrAssessorRefName); + Assert.assertEquals(intake.getInsurers().getInsurer().get(0), insurerRefName); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // Get the auth refs and check them ClientResponse res2 = intakeClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - - AuthorityRefList list = res2.getEntity(); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); @@ -350,8 +352,7 @@ public class IntakeAuthRefsTest extends BaseServiceTest { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new IntakeClient().getCommonPartName()); + multipart.addPart(new IntakeClient().getCommonPartName(), intake); if(logger.isDebugEnabled()){ logger.debug("to be created, intake common"); diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java index 1f354ed37..57198ae82 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java @@ -24,7 +24,6 @@ package org.collectionspace.services.client.test; import java.util.List; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.dom4j.Element; @@ -34,7 +33,6 @@ 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.common.AbstractCommonListUtils; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.intake.EntryMethodList; import org.collectionspace.services.intake.FieldCollectionEventNameList; @@ -58,13 +56,11 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class IntakeServiceTest extends AbstractServiceTestImpl { +public class IntakeServiceTest extends AbstractPoxServiceTestImpl { /** The logger. */ private final String CLASS_NAME = IntakeServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(IntakeServiceTest.class); - /** The known resource id. */ - private String knownResourceId = null; private final static String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC(); @@ -78,86 +74,10 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { return IntakeClient.SERVICE_NAME; } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(AbstractCommonList.class); - } - // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - IntakeClient client = new IntakeClient(); - String identifier = createIdentifier(); - PoxPayloadOut multipart = createInstance(identifier); - ClientResponse res = client.create(multipart); - - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null) { - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - for (int i = 0; i < 3; i++) { - create(testName); - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) @@ -276,50 +196,20 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - IntakeClient client = new IntakeClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - IntakesCommon intakeCommons = null; - if (payloadInputPart != null) { - intakeCommons = (IntakesCommon) payloadInputPart.getBody(); - } -// IntakesCommon intake = (IntakesCommon) extractPart(input, -// client.getCommonPartName(), IntakesCommon.class); - Assert.assertNotNull(intakeCommons); - + protected void compareReadInstances(IntakesCommon original, IntakesCommon fromRead) throws Exception { // Verify the number and contents of values in repeatable fields, // as created in the instance record used for testing. List entryMethods = - intakeCommons.getEntryMethods().getEntryMethod(); + fromRead.getEntryMethods().getEntryMethod(); Assert.assertTrue(entryMethods.size() > 0); Assert.assertNotNull(entryMethods.get(0)); List fieldCollectionEventNames = - intakeCommons.getFieldCollectionEventNames().getFieldCollectionEventName(); + fromRead.getFieldCollectionEventNames().getFieldCollectionEventName(); Assert.assertTrue(fieldCollectionEventNames.size() > 0); Assert.assertNotNull(fieldCollectionEventNames.get(0)); - CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList(); + CurrentLocationGroupList currentLocationGroupList = fromRead.getCurrentLocationGroupList(); Assert.assertNotNull(currentLocationGroupList); List currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup(); Assert.assertNotNull(currentLocationGroups); @@ -331,184 +221,34 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters. if (logger.isDebugEnabled()) { logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" - + "UTF-8 data received=" + intakeCommons.getEntryNote()); + + "UTF-8 data received=" + fromRead.getEntryNote()); } - Assert.assertEquals(intakeCommons.getEntryNote(), getUTF8DataFragment(), - "UTF-8 data retrieved '" + intakeCommons.getEntryNote() + Assert.assertEquals(fromRead.getEntryNote(), getUTF8DataFragment(), + "UTF-8 data retrieved '" + fromRead.getEntryNote() + "' does not match expected data '" + getUTF8DataFragment()); - } - - // Failure outcomes + } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - IntakeClient client = new IntakeClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } + // Failure outcomes - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - IntakeClient client = new IntakeClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if (iterateThroughList && logger.isDebugEnabled()) { - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - + public void delete(String testName) throws Exception { + // Do nothing because this test is not ready to delete the "knownResourceId". + // Instead, the method localDelete() will get called later in the dependency chain. The + // method localDelete() has a dependency on the test "verifyReadOnlyCoreFields". Once the "verifyReadOnlyCoreFields" + // test is run, the localDelete() test/method will get run. The localDelete() test/method in turn + // calls the inherited delete() test/method. } - - // Failure outcomes - // None at present. - - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - IntakeClient client = new IntakeClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - if (logger.isDebugEnabled()) { - logger.debug("got object to update with ID: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - IntakesCommon intakeCommons = null; - if (payloadInputPart != null) { - intakeCommons = (IntakesCommon) payloadInputPart.getBody(); - } -// IntakesCommon intake = (IntakesCommon) extractPart(input, -// client.getCommonPartName(), IntakesCommon.class); - Assert.assertNotNull(intakeCommons); - - // Update the content of this resource. - intakeCommons.setEntryNumber("updated-" + intakeCommons.getEntryNumber()); - if (logger.isDebugEnabled()) { - logger.debug("to be updated object"); - logger.debug(objectAsXmlString(intakeCommons, IntakesCommon.class)); - } - - CurrentLocationGroupList currentLocationGroupList = intakeCommons.getCurrentLocationGroupList(); - Assert.assertNotNull(currentLocationGroupList); - List currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup(); - Assert.assertNotNull(currentLocationGroups); - Assert.assertTrue(currentLocationGroups.size() > 0); - CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0); - Assert.assertNotNull(currentLocationGroup); - String currentLocationNote = currentLocationGroup.getCurrentLocationNote(); - Assert.assertNotNull(currentLocationNote); - String updatedCurrentLocationNote = "updated-" + currentLocationNote; - currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote); - intakeCommons.setCurrentLocationGroupList(currentLocationGroupList); - - // Create an output payload to send to the service, and add teh common part - PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(intakeCommons, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - - // Submit the request to the service and store the response. - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - input = new PoxPayloadIn(res.getEntity()); - IntakesCommon updatedIntake = - (IntakesCommon) extractPart(input, - client.getCommonPartName(), IntakesCommon.class); - - Assert.assertNotNull(updatedIntake); - - Assert.assertEquals(updatedIntake.getEntryNumber(), - intakeCommons.getEntryNumber(), - "Data in updated object did not match submitted data."); - - currentLocationGroupList = updatedIntake.getCurrentLocationGroupList(); - Assert.assertNotNull(currentLocationGroupList); - currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup(); - Assert.assertNotNull(currentLocationGroups); - Assert.assertTrue(currentLocationGroups.size() > 0); - Assert.assertNotNull(currentLocationGroups.get(0)); - Assert.assertEquals(updatedCurrentLocationNote, - currentLocationGroups.get(0).getCurrentLocationNote(), - "Data in updated object did not match submitted data."); - - if (logger.isDebugEnabled()) { - logger.debug("UTF-8 data sent=" + intakeCommons.getEntryNote() + "\n" - + "UTF-8 data received=" + updatedIntake.getEntryNote()); - } - Assert.assertTrue(updatedIntake.getEntryNote().contains(getUTF8DataFragment()), - "UTF-8 data retrieved '" + updatedIntake.getEntryNote() - + "' does not contain expected data '" + getUTF8DataFragment()); - Assert.assertEquals(updatedIntake.getEntryNote(), - intakeCommons.getEntryNote(), - "Data in updated object did not match submitted data."); - + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests", "verifyReadOnlyCoreFields"}) + public void localDelete(String testName) throws Exception { + // Because of issues with TestNG not allowing @Test annotations on on override methods, + // and because we want the "updateWrongUser" to run before the "delete" test, we need + // this method. This method will call super.delete() after all the dependencies have been + // met. + super.delete(testName); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update"}) + @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void verifyReadOnlyCoreFields(String testName) throws Exception { // TODO These should be in some core client utils final String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core"; @@ -519,16 +259,16 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { final String COLLECTIONSPACE_CORE_CREATED_BY = "createdBy"; final String COLLECTIONSPACE_CORE_UPDATED_BY = "updatedBy"; - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); // Retrieve the contents of a resource to update. IntakeClient client = new IntakeClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); PayloadInputPart payloadInputPart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA); @@ -572,7 +312,14 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. res = client.update(knownResourceId, output); - assertStatusCode(res, testName); + 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); input = new PoxPayloadIn(res.getEntity()); PayloadInputPart updatedCorePart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA); @@ -718,138 +465,10 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { } */ - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - IntakeClient client = new IntakeClient(); - PoxPayloadOut multipart = createInstance(NON_EXISTENT_ID); - ClientResponse res = - client.update(NON_EXISTENT_ID, multipart); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "verifyReadOnlyCoreFields"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - IntakeClient client = new IntakeClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - // Failure outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - IntakeClient client = new IntakeClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); - } - // --------------------------------------------------------------- // Utility tests : tests of code used in tests above // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() */ @@ -925,4 +544,79 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { return multipart; } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return this.createInstance(identifier); + } + + @Override + protected IntakesCommon updateInstance(IntakesCommon intakesCommon) { + IntakesCommon result = new IntakesCommon(); + + result.setEntryNumber("updated-" + intakesCommon.getEntryNumber()); + result.setEntryNote(intakesCommon.getEntryNote()); + + CurrentLocationGroupList currentLocationGroupList = intakesCommon.getCurrentLocationGroupList(); + Assert.assertNotNull(currentLocationGroupList); + List currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup(); + Assert.assertNotNull(currentLocationGroups); + Assert.assertTrue(currentLocationGroups.size() > 0); + CurrentLocationGroup currentLocationGroup = currentLocationGroups.get(0); + Assert.assertNotNull(currentLocationGroup); + String currentLocationNote = currentLocationGroup.getCurrentLocationNote(); + Assert.assertNotNull(currentLocationNote); + String updatedCurrentLocationNote = "updated-" + currentLocationNote; + currentLocationGroups.get(0).setCurrentLocationNote(updatedCurrentLocationNote); + result.setCurrentLocationGroupList(currentLocationGroupList); + + return result; + } + + @Override + protected void compareUpdatedInstances(IntakesCommon original, + IntakesCommon updated) throws Exception { + Assert.assertEquals(updated.getEntryNumber(), + original.getEntryNumber(), + "Data in updated object did not match submitted data."); + + CurrentLocationGroupList currentLocationGroupList = updated.getCurrentLocationGroupList(); + Assert.assertNotNull(currentLocationGroupList); + List currentLocationGroups = currentLocationGroupList.getCurrentLocationGroup(); + Assert.assertNotNull(currentLocationGroups); + Assert.assertTrue(currentLocationGroups.size() > 0); + Assert.assertNotNull(currentLocationGroups.get(0)); + + String updatedCurrentLocationNote = original.getCurrentLocationGroupList() + .getCurrentLocationGroup().get(0).getCurrentLocationNote(); + Assert.assertEquals(updatedCurrentLocationNote, + currentLocationGroups.get(0).getCurrentLocationNote(), + "Data in updated object did not match submitted data."); + + Assert.assertEquals(updated.getEntryNote(), original.getEntryNote(), + "Data in updated object did not match submitted data."); + // + // UTF-8 Checks + // + if (logger.isDebugEnabled()) { + logger.debug("UTF-8 data sent=" + original.getEntryNote() + "\n" + + "UTF-8 data received=" + updated.getEntryNote()); + } + Assert.assertTrue(updated.getEntryNote().contains(getUTF8DataFragment()), + "UTF-8 data retrieved '" + updated.getEntryNote() + + "' does not contain expected data '" + getUTF8DataFragment()); + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + } } diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java index c113011d1..497389fec 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java @@ -63,7 +63,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 1327 $ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ */ -public class OrganizationAuthRefDocsTest extends BaseServiceTest { +public class OrganizationAuthRefDocsTest extends BaseServiceTest { private final String CLASS_NAME = OrganizationAuthRefDocsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -103,7 +103,7 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -114,10 +114,6 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { // Success outcomes @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void createIntakeWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Submit the request to the service and store the response. @@ -150,9 +146,9 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { res.releaseConnection(); } @@ -183,8 +179,8 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { ClientResponse res = orgAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); orgAuthCSID = extractId(res); @@ -226,8 +222,8 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { ClientResponse res = orgAuthClient.createItem(orgAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } @@ -236,10 +232,6 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createIntakeWithAuthRefs"}) public void readAndCheckAuthRefDocs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); @@ -247,9 +239,16 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); ClientResponse refDocListResp = orgAuthClient.getReferencingObjects(orgAuthCSID, currentOwnerOrgCSID); - assertStatusCode(refDocListResp, testName); - - AuthorityRefDocList list = refDocListResp.getEntity(); + AuthorityRefDocList list = null; + try { + assertStatusCode(refDocListResp, testName); + list = refDocListResp.getEntity(); + Assert.assertNotNull(list); + } finally { + if (refDocListResp != null) { + refDocListResp.releaseConnection(); + } + } // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; @@ -352,8 +351,7 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new IntakeClient().getCommonPartName()); + multipart.addPart(new IntakeClient().getCommonPartName(), intake); if(logger.isDebugEnabled()){ logger.debug("to be created, intake common"); diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java index 837177cbf..c73cf1fbd 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; @@ -63,7 +62,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 1327 $ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ */ -public class PersonAuthRefDocsTest extends BaseServiceTest { +public class PersonAuthRefDocsTest extends BaseServiceTest { private final String CLASS_NAME = PersonAuthRefDocsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -105,7 +104,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -114,12 +113,8 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void createIntakeWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Submit the request to the service and store the response. @@ -151,9 +146,9 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { res.releaseConnection(); } @@ -182,8 +177,8 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); @@ -239,31 +234,33 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } // Success outcomes - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createIntakeWithAuthRefs"}) + @Test(dataProvider = "testName", dependsOnMethods = {"createIntakeWithAuthRefs"}) public void readAndCheckAuthRefDocs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); // Get the auth ref docs and check them PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); - ClientResponse refDocListResp = + ClientResponse res = personAuthClient.getReferencingObjects(personAuthCSID, currentOwnerPersonCSID); - assertStatusCode(refDocListResp, testName); - - AuthorityRefDocList list = refDocListResp.getEntity(); + AuthorityRefDocList list = null; + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + List items = list.getAuthorityRefDocItem(); Assert.assertTrue(items != null); @@ -289,13 +286,20 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { } Assert.assertTrue(fFoundIntake, "Did not find Intake with authref!"); } - + // + // Get the referencing objects + // personAuthClient = new PersonAuthorityClient(); - refDocListResp = - personAuthClient.getReferencingObjects(personAuthCSID, depositorPersonCSID); - assertStatusCode(refDocListResp, testName); - - list = refDocListResp.getEntity(); + res = personAuthClient.getReferencingObjects(personAuthCSID, depositorPersonCSID); + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + items = list.getAuthorityRefDocItem(); Assert.assertTrue(items != null); Assert.assertTrue(items.size() > 0); @@ -327,13 +331,9 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { * Read and check the list of referencing objects, where the authRef field * is a value instance of a repeatable scalar field. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createIntakeWithAuthRefs"}, groups = {"repeatableScalar"}) + @Test(dataProvider = "testName", dependsOnMethods = {"createIntakeWithAuthRefs"}, + groups = {"repeatableScalar"}) public void readAndCheckAuthRefDocsRepeatableScalar(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); @@ -341,11 +341,18 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { // Single scalar field PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); - ClientResponse refDocListResp = + ClientResponse res = personAuthClient.getReferencingObjects(personAuthCSID, insurerPersonCSID); - assertStatusCode(refDocListResp, testName); - - AuthorityRefDocList list = refDocListResp.getEntity(); + AuthorityRefDocList list = null; + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + List items = list.getAuthorityRefDocItem(); Assert.assertTrue(items != null); @@ -449,8 +456,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new IntakeClient().getCommonPartName()); + multipart.addPart(new IntakeClient().getCommonPartName(), intake); if (logger.isDebugEnabled()) { logger.debug("to be created, intake common"); diff --git a/services/intake/service/pom.xml b/services/intake/service/pom.xml index e67f35c6c..4ecea62b7 100644 --- a/services/intake/service/pom.xml +++ b/services/intake/service/pom.xml @@ -49,7 +49,6 @@ org.testng testng - 5.6 diff --git a/services/loanin/client/pom.xml b/services/loanin/client/pom.xml index d109e5269..9e86adbdf 100644 --- a/services/loanin/client/pom.xml +++ b/services/loanin/client/pom.xml @@ -61,7 +61,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java index 69a9d1a0c..6b7c49be0 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java @@ -31,12 +31,10 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; -import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.LoaninClient; import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.client.PersonAuthorityClientUtils; -import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; @@ -63,7 +61,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class LoaninAuthRefsTest extends BaseServiceTest { +public class LoaninAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = LoaninAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -97,7 +95,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -108,10 +106,6 @@ public class LoaninAuthRefsTest extends BaseServiceTest { // Success outcomes @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void createWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Submit the request to the service and store the response. @@ -145,9 +139,9 @@ public class LoaninAuthRefsTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -176,8 +170,8 @@ public class LoaninAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); @@ -221,8 +215,8 @@ public class LoaninAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } @@ -231,39 +225,49 @@ public class LoaninAuthRefsTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. LoaninClient loaninClient = new LoaninClient(); ClientResponse res = loaninClient.read(knownResourceId); - assertStatusCode(res, testName); - - // Extract the common part from the response. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LoansinCommon loaninCommon = (LoansinCommon) extractPart(input, - loaninClient.getCommonPartName(), LoansinCommon.class); - Assert.assertNotNull(loaninCommon); - if(logger.isDebugEnabled()){ - logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); + LoansinCommon loaninCommon = null; + try { + assertStatusCode(res, testName); + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + loaninCommon = (LoansinCommon) extractPart(input, + loaninClient.getCommonPartName(), LoansinCommon.class); + Assert.assertNotNull(loaninCommon); + if(logger.isDebugEnabled()){ + logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } - + // // Check a couple of fields // Assert.assertEquals(loaninCommon.getLender(), lenderRefName); // Assert.assertEquals(loaninCommon.getLendersAuthorizer(), lendersAuthorizerRefName); // Assert.assertEquals(loaninCommon.getLendersContact(), lendersContactRefName); + // Assert.assertEquals(loaninCommon.getLoanInContact(), loanInContactRefName); Assert.assertEquals(loaninCommon.getBorrowersAuthorizer(), borrowersAuthorizerRefName); // Get the auth refs and check them - ClientResponse res2 = - loaninClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - AuthorityRefList list = res2.getEntity(); + ClientResponse res2 = loaninClient.getAuthorityRefs(knownResourceId); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + Assert.assertNotNull(list); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); @@ -357,37 +361,40 @@ public class LoaninAuthRefsTest extends BaseServiceTest { return SERVICE_PATH_COMPONENT; } - - private PoxPayloadOut createLoaninInstance(String loaninNumber, + private PoxPayloadOut createLoaninInstance(String loaninNumber, String returnDate, - String lender, - String lendersAuthorizer, - String lendersContact, - String loaninContact, - String borrowersAuthorizer) { - LoansinCommon loaninCommon = new LoansinCommon(); - loaninCommon.setLoanInNumber(loaninNumber); - loaninCommon.setLoanInNumber(returnDate); - LenderGroupList lenderGroupList = new LenderGroupList(); - LenderGroup lenderGroup = new LenderGroup(); - lenderGroup.setLender(lender); - lenderGroup.setLendersAuthorizer(lendersAuthorizer); - lenderGroup.setLendersContact(lendersContact); - lenderGroupList.getLenderGroup().add(lenderGroup); - loaninCommon.setLenderGroupList(lenderGroupList); - loaninCommon.setLoanInContact(loaninContact); - loaninCommon.setBorrowersAuthorizer(borrowersAuthorizer); - - PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = - multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new LoaninClient().getCommonPartName()); + String lender, + String lendersAuthorizer, + String lendersContact, + String loaninContact, + String borrowersAuthorizer) { + LoansinCommon loaninCommon = new LoansinCommon(); + loaninCommon.setLoanInNumber(loaninNumber); + loaninCommon.setLoanInNumber(returnDate); + LenderGroupList lenderGroupList = new LenderGroupList(); + LenderGroup lenderGroup = new LenderGroup(); + lenderGroup.setLender(lender); + lenderGroup.setLendersAuthorizer(lendersAuthorizer); + lenderGroup.setLendersContact(lendersContact); + lenderGroupList.getLenderGroup().add(lenderGroup); + loaninCommon.setLenderGroupList(lenderGroupList); + loaninCommon.setLoanInContact(loaninContact); + loaninCommon.setBorrowersAuthorizer(borrowersAuthorizer); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(new LoaninClient().getCommonPartName(), loaninCommon); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, loanin common"); + logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); + } - if(logger.isDebugEnabled()){ - logger.debug("to be created, loanin common"); - logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); - } + return multipart; + } - return multipart; + @Override + protected Class getCommonListType() { + return AbstractCommonList.class; } } diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java index d94590c83..0c6157c98 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java @@ -27,13 +27,13 @@ import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.LoaninClient; 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.common.AbstractCommonListUtils; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanin.LenderGroup; @@ -42,7 +42,6 @@ import org.collectionspace.services.loanin.LoansinCommon; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; -import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,7 +53,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class LoaninServiceTest extends AbstractServiceTestImpl { +public class LoaninServiceTest extends AbstractPoxServiceTestImpl { /** The logger. */ private final String CLASS_NAME = LoaninServiceTest.class.getName(); @@ -63,8 +62,6 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { /** The service path component. */ final String SERVICE_NAME = "loansin"; final String SERVICE_PATH_COMPONENT = "loansin"; - /** The known resource id. */ - private String knownResourceId = null; private String LENDER_REF_NAME = "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(HarryLender)'Harry Lender'"; private final static String CURRENT_DATE_UTC = @@ -82,7 +79,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { return response.getEntity(AbstractCommonList.class); } @@ -97,12 +94,8 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -126,13 +119,15 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); newID = extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the ID returned from the first resource created @@ -153,41 +148,14 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { for (int i = 0; i < 3; i++) { create(testName); } } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } /* @Override @@ -288,25 +256,23 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); // Submit the request to the service and store the response. LoaninClient client = new LoaninClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); PoxPayloadIn input = null; try { + assertStatusCode(res, testName); input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Get the common part of the response and verify that it is not null. @@ -342,13 +308,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadNonExistent(); @@ -363,11 +325,13 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -381,13 +345,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); @@ -397,9 +357,22 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.readList(); assertStatusCode(res, testName); 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + list = res.getEntity(); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Optionally output additional data about list members for debugging. @@ -423,28 +396,26 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. - setupUpdate(); + setupRead(); // Retrieve the contents of a resource to update. LoaninClient client = new LoaninClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); PoxPayloadIn input = null; try { - if (logger.isDebugEnabled()) { + assertStatusCode(res, testName); + input = new PoxPayloadIn(res.getEntity()); + if (logger.isDebugEnabled()) { logger.debug("got object to update with ID: " + knownResourceId); } - input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Extract the common part from the response. @@ -463,17 +434,28 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); } + setupUpdate(); + // Submit the updated common part in an update request to the service // and store the response. PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loaninCommon); res = client.update(knownResourceId, output); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); + 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); input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Extract the updated common part from the response. @@ -501,134 +483,10 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { "Data in updated object did not match submitted data."); } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"update", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdateNonExistent(); @@ -646,11 +504,13 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -664,13 +524,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDelete(); @@ -685,11 +541,13 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -699,13 +557,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDeleteNonExistent(); @@ -720,11 +574,13 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -736,7 +592,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * Tests the code for manually submitting data that is used by several * of the methods above. */ - @Test(dependsOnMethods = {"create", "read"}) +// @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() { // Expected status code: 200 OK @@ -814,8 +670,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new LoaninClient().getCommonPartName()); + multipart.addPart(new LoaninClient().getCommonPartName(), loaninCommon); if (logger.isDebugEnabled()) { logger.debug("to be created, loanin common"); @@ -824,4 +679,30 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { return multipart; } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = createLoaninInstance(identifier); + return result; + } + + @Override + protected LoansinCommon updateInstance(LoansinCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(LoansinCommon original, + LoansinCommon updated) throws Exception { + // TODO Auto-generated method stub + + } } diff --git a/services/loanin/service/pom.xml b/services/loanin/service/pom.xml index 1bdcec7be..1933f2dbd 100644 --- a/services/loanin/service/pom.xml +++ b/services/loanin/service/pom.xml @@ -44,7 +44,6 @@ org.testng testng - 5.6 diff --git a/services/loanout/client/pom.xml b/services/loanout/client/pom.xml index fa8b81249..da2c7d6b0 100644 --- a/services/loanout/client/pom.xml +++ b/services/loanout/client/pom.xml @@ -62,7 +62,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java index 4968940b7..657bd95ee 100644 --- a/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java +++ b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java @@ -42,7 +42,6 @@ public class LoanoutClient extends AbstractCommonListPoxServiceClientImpl getProxyClass() { - // TODO Auto-generated method stub return LoanoutProxy.class; } diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java index 862551da3..a352ee6d0 100644 --- a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; @@ -39,11 +38,9 @@ import org.collectionspace.services.client.PersonAuthorityClientUtils; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.authorityref.AuthorityRefList; -//import org.collectionspace.services.common.authorityref.AuthorityRefList.AuthorityRefItem; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanout.LoansoutCommon; -//import org.collectionspace.services.loanout.LoansoutCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -61,7 +58,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class LoanoutAuthRefsTest extends BaseServiceTest { +public class LoanoutAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = LoanoutAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -99,7 +96,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -110,10 +107,6 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { // Success outcomes @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void createWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Submit the request to the service and store the response. @@ -146,9 +139,9 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -174,8 +167,8 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); @@ -216,8 +209,8 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } @@ -226,26 +219,29 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. LoanoutClient loanoutClient = new LoanoutClient(); ClientResponse res = loanoutClient.read(knownResourceId); - assertStatusCode(res, testName); - - // Extract the common part from the response. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LoansoutCommon loanoutCommon = (LoansoutCommon) extractPart(input, - loanoutClient.getCommonPartName(), LoansoutCommon.class); - Assert.assertNotNull(loanoutCommon); - if(logger.isDebugEnabled()){ - logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); + LoansoutCommon loanoutCommon = null; + try { + assertStatusCode(res, testName); + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + loanoutCommon = (LoansoutCommon) extractPart(input, + loanoutClient.getCommonPartName(), LoansoutCommon.class); + Assert.assertNotNull(loanoutCommon); + if(logger.isDebugEnabled()){ + logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } + // Check a couple of fields Assert.assertEquals(loanoutCommon.getBorrower(), borrowerRefName); Assert.assertEquals(loanoutCommon.getBorrowersContact(), borrowersContactRefName); @@ -253,11 +249,16 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { Assert.assertEquals(loanoutCommon.getLendersContact(), lendersContactRefName); // Get the auth refs and check them - ClientResponse res2 = - loanoutClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - - AuthorityRefList list = res2.getEntity(); + ClientResponse res2 = loanoutClient.getAuthorityRefs(knownResourceId); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); @@ -343,30 +344,35 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { return SERVICE_PATH_COMPONENT; } - private PoxPayloadOut createLoanoutInstance(String loanoutNumber, + private PoxPayloadOut createLoanoutInstance(String loanoutNumber, String returnDate, - String borrower, - String borrowersContact, - String lendersAuthorizer, - String lendersContact) { - LoansoutCommon loanoutCommon = new LoansoutCommon(); - loanoutCommon.setLoanOutNumber(loanoutNumber); - loanoutCommon.setLoanReturnDate(returnDate); - loanoutCommon.setBorrower(borrower); - loanoutCommon.setBorrowersContact(borrowersContact); - loanoutCommon.setLendersAuthorizer(lendersAuthorizer); - loanoutCommon.setLendersContact(lendersContact); - - PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = - multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new LoanoutClient().getCommonPartName()); + String borrower, + String borrowersContact, + String lendersAuthorizer, + String lendersContact) { + LoansoutCommon loanoutCommon = new LoansoutCommon(); + loanoutCommon.setLoanOutNumber(loanoutNumber); + loanoutCommon.setLoanReturnDate(returnDate); + loanoutCommon.setBorrower(borrower); + loanoutCommon.setBorrowersContact(borrowersContact); + loanoutCommon.setLendersAuthorizer(lendersAuthorizer); + loanoutCommon.setLendersContact(lendersContact); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(new LoanoutClient().getCommonPartName(), loanoutCommon); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, loanout common"); + logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); + } - if(logger.isDebugEnabled()){ - logger.debug("to be created, loanout common"); - logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); - } + return multipart; + } - return multipart; + @Override + protected Class getCommonListType() { + // TODO Auto-generated method stub + return null; } } diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java index 0063f4c8c..2b0ae6c16 100644 --- a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java @@ -26,13 +26,13 @@ import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.LoanoutClient; 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.common.AbstractCommonListUtils; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanout.LoanStatusGroup; @@ -42,7 +42,6 @@ import org.collectionspace.services.loanout.LoansoutCommon; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; -import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,13 +53,12 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class LoanoutServiceTest extends AbstractServiceTestImpl { +public class LoanoutServiceTest extends AbstractPoxServiceTestImpl { /** The logger. */ private final String CLASS_NAME = LoanoutServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); /** The known resource id. */ - private String knownResourceId = null; private final static String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC(); @@ -76,7 +74,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { return response.getEntity(AbstractCommonList.class); } @@ -89,12 +87,8 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -117,9 +111,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -139,8 +133,8 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { for (int i = 0; i < 3; i++) { create(testName); @@ -270,29 +264,30 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); // Submit the request to the service and store the response. LoanoutClient client = new LoanoutClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - // Get the common part of the response and verify that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); LoansoutCommon loanoutCommon = null; - if (payloadInputPart != null) { - loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + try { + assertStatusCode(res, testName); + // Get the common part of the response and verify that it is not null. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + if (payloadInputPart != null) { + loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(loanoutCommon); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertNotNull(loanoutCommon); // Check selected fields in the common part. Assert.assertNotNull(loanoutCommon.getLoanOutNumber()); @@ -321,13 +316,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadNonExistent(); @@ -341,9 +332,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -354,25 +345,27 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. LoanoutClient client = new LoanoutClient(); ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - + AbstractCommonList list = null; + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; - if(iterateThroughList && logger.isDebugEnabled()){ + if (iterateThroughList && logger.isDebugEnabled()){ AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } @@ -388,29 +381,30 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. - setupUpdate(); + setupRead(); // Retrieve the contents of a resource to update. LoanoutClient client = new LoanoutClient(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - // Extract the common part from the response. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); LoansoutCommon loanoutCommon = null; - if (payloadInputPart != null) { - loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + try { + assertStatusCode(res, testName); + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + if (payloadInputPart != null) { + loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(loanoutCommon); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertNotNull(loanoutCommon); // Update the content of this resource. loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber()); @@ -432,21 +426,28 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { } loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote()); + setupUpdate(); + // Submit the updated resource in an update request to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loanoutCommon); - // Extract the updated common part from the response. - input = new PoxPayloadIn(res.getEntity()); - payloadInputPart = input.getPart(client.getCommonPartName()); + res = client.update(knownResourceId, output); LoansoutCommon updatedLoanoutCommon = null; - if (payloadInputPart != null) { - updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + try { + assertStatusCode(res, testName); + // Extract the updated common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + if (payloadInputPart != null) { + updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(updatedLoanoutCommon); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertNotNull(updatedLoanoutCommon); // Check selected fields in the updated resource. Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(), @@ -598,13 +599,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"update", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdateNonExistent(); @@ -621,9 +618,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -634,13 +631,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDelete(); @@ -654,9 +647,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // Failure outcomes @@ -664,13 +657,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDeleteNonExistent(); @@ -684,9 +673,9 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -696,7 +685,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * Tests the code for manually submitting data that is used by several * of the methods above. */ - @Test(dependsOnMethods = {"create", "read"}) +// @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() { // Expected status code: 200 OK @@ -773,8 +762,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new LoanoutClient().getCommonPartName()); + multipart.addPart(new LoanoutClient().getCommonPartName(), loanoutCommon); if (logger.isDebugEnabled()) { logger.debug("to be created, loanout common"); @@ -789,4 +777,30 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { protected String getServiceName() { return LoanoutClient.SERVICE_NAME; } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = createLoanoutInstance(identifier); + return result; + } + + @Override + protected LoansoutCommon updateInstance(LoansoutCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(LoansoutCommon original, + LoansoutCommon updated) throws Exception { + // TODO Auto-generated method stub + + } } diff --git a/services/loanout/service/pom.xml b/services/loanout/service/pom.xml index a6d60e172..5f80ca17d 100644 --- a/services/loanout/service/pom.xml +++ b/services/loanout/service/pom.xml @@ -39,7 +39,6 @@ org.testng testng - 5.6 diff --git a/services/location/client/pom.xml b/services/location/client/pom.xml index 8762eb921..a62213f36 100644 --- a/services/location/client/pom.xml +++ b/services/location/client/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.location.client services.location.client @@ -59,7 +58,6 @@ org.testng testng - 5.6 org.jboss.resteasy @@ -83,7 +81,6 @@ commons-httpclient commons-httpclient - 3.1 diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java index c102107de..be15359ff 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java @@ -26,10 +26,12 @@ */ package org.collectionspace.services.client; +import org.collectionspace.services.location.LocationsCommon; + /** * The Class LocationAuthorityClient. */ -public class LocationAuthorityClient extends AuthorityClientImpl { +public class LocationAuthorityClient extends AuthorityClientImpl { public static final String SERVICE_NAME = "locationauthorities"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -66,4 +68,14 @@ public class LocationAuthorityClient extends AuthorityClientImpl getProxyClass() { return LocationAuthorityProxy.class; } + + @Override + public String getInAuthority(LocationsCommon item) { + return item.getInAuthority(); + } + + @Override + public void setInAuthority(LocationsCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } } diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java index 7175c5bf5..649004550 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java @@ -2,7 +2,6 @@ package org.collectionspace.services.client; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -21,7 +20,6 @@ import org.dom4j.DocumentException; import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.Assert; public class LocationAuthorityClientUtils { private static final Logger logger = @@ -36,15 +34,16 @@ public class LocationAuthorityClientUtils { */ public static PoxPayloadOut createLocationAuthorityInstance( String displayName, String shortIdentifier, String headerLabel ) { + LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon(); locationAuthority.setDisplayName(displayName); locationAuthority.setShortIdentifier(shortIdentifier); // String refName = createLocationAuthRefName(shortIdentifier, displayName); // locationAuthority.setRefName(refName); locationAuthority.setVocabType("LocationAuthority"); //FIXME: REM - Should this really be hard-coded? + PoxPayloadOut multipart = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(headerLabel); + PayloadOutputPart commonPart = multipart.addPart(headerLabel, locationAuthority); if(logger.isDebugEnabled()){ logger.debug("to be created, locationAuthority common ", diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java index cb373ac54..a72e48426 100644 --- a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -22,18 +22,17 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.collectionspace.services.LocationJAXBSchema; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.client.LocationAuthorityClient; import org.collectionspace.services.client.LocationAuthorityClientUtils; @@ -41,8 +40,6 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.location.LocationauthoritiesCommon; import org.collectionspace.services.location.LocationsCommon; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; @@ -59,7 +56,7 @@ import org.testng.annotations.Test; * $LastChangedRevision: 753 $ * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ */ -public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class! +public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest { /** The logger. */ private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName(); @@ -107,1142 +104,316 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FI final String TEST_STATUS = "Approved"; /** The known resource id. */ - private String knownResourceId = null; private String knownResourceShortIdentifer = null; private String knownResourceRefName = null; - private String knownLocationTypeRefName = 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 allResourceIdsCreated = new ArrayList(); - - /** The all item resource ids created. */ - private Map allItemResourceIdsCreated = - new HashMap(); - - 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; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() - */ - @Override - protected CollectionSpaceClient getClientInstance() { - return new LocationAuthorityClient(); - } - - @Override - protected PoxPayloadOut createInstance(String identifier) { - LocationAuthorityClient client = new LocationAuthorityClient(); - String shortId = identifier; - String displayName = "displayName-" + shortId; - // String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null); - PoxPayloadOut multipart = - LocationAuthorityClientUtils.createLocationAuthorityInstance( - displayName, shortId, client.getCommonPartName()); - return multipart; - } - - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - String shortId = createIdentifier(); - String displayName = "displayName-" + shortId; - // String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null); - - PoxPayloadOut multipart = - LocationAuthorityClientUtils.createLocationAuthorityInstance( - displayName, shortId, client.getCommonPartName()); - String newID = null; - ClientResponse 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 = LocationAuthorityClientUtils.extractId(res); - } finally { - res.releaseConnection(); - } - // Store the ID returned from the first resource created - // for additional tests below. - final String EMPTY_REFNAME = ""; - if (knownResourceId == null){ - setKnownResource( newID, shortId, EMPTY_REFNAME ); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(newID); - } - - /** - * Creates the item. - * - * @param testName the test name - */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) - public void createItem(String testName) { - if(logger.isDebugEnabled()){ - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupCreate(); - createItemInAuthority(knownResourceId, knownResourceRefName); - } - - /** - * Creates the item in authority. - * - * @param vcsid the vcsid - * @param authRefName the auth ref name - * @return the string - */ - private String createItemInAuthority(String vcsid, String authRefName) { - - 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. - LocationAuthorityClient client = new LocationAuthorityClient(); - Map shelf1Map = new HashMap(); - // TODO Make loc type and status be controlled vocabs. - shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME); - shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); - shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE); - shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE); - shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE); - shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE); - shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS); - shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); - shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS); - - String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid, - authRefName, shelf1Map, client ); - - // Store the ID returned from the first item resource created - // for additional tests below. - if (knownItemResourceId == null){ - setKnownItemResource(newID, TEST_SHORTID); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownItemResourceId=" + newID); - } - } - - // Store the IDs from any item resources created - // by tests, along with the IDs of their parents, so these items - // can be deleted after all tests have been run. - allItemResourceIdsCreated.put(newID, vcsid); - - return newID; - } - - - - // Failure outcomes - - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - 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) - */ - @Override - @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); - } - } - - /** - * Creates the item list. - * - * @param testName the test name - * @throws Exception the exception - */ - @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++) { - createItem(testName); - } - } - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnGroups = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - String newID = null; - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - try { - //FIXME: remove the following try catch once Aron fixes signatures - try { - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LocationauthoritiesCommon locationAuthority = - (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(locationAuthority); - Assert.assertNotNull(locationAuthority.getDisplayName()); - Assert.assertNotNull(locationAuthority.getShortIdentifier()); - Assert.assertNotNull(locationAuthority.getRefName()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } finally { - res.releaseConnection(); - } - } - - /** - * Read by name. - * - * @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 { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.readByName(knownResourceShortIdentifer); - assertStatusCode(res, testName); - try { - //FIXME: remove the following try catch once Aron fixes signatures - try { - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(locationAuthority); - } catch (Exception e) { - throw new RuntimeException(e); - } - } finally { - res.releaseConnection(); - } - } - - - /** - * 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()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - try { - // Check whether we've received a location. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(location, LocationsCommon.class)); - } - Assert.assertEquals(location.getInAuthority(), knownResourceId); - } finally { - res.releaseConnection(); - } - - } - - /** - * Verify item display name. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem", "updateItem"}) - public void verifyItemDisplayName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - try { - // Check whether location has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - String displayName = location.getDisplayName(); - // Make sure displayName matches computed form - String expectedDisplayName = - LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME); - Assert.assertNotNull(displayName, expectedDisplayName); - - // Update the shortName and verify the computed name is updated. - location.setCsid(null); - location.setDisplayNameComputed(true); - location.setName("updated-" + TEST_NAME); - expectedDisplayName = - LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME); - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res.releaseConnection(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - LocationsCommon updatedLocation = - (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(updatedLocation); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocation.getName(), location.getName(), - "Updated ForeName in Location did not match submitted data."); - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName, - "Updated ForeName in Location not reflected in computed DisplayName."); - - // Now Update the displayName, not computed and verify the computed name is overriden. - location.setDisplayNameComputed(false); - expectedDisplayName = "TestName"; - location.setDisplayName(expectedDisplayName); - - // Submit the updated resource to the service and store the response. - output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res.releaseConnection(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - updatedLocation = - (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(updatedLocation); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false, - "Updated displayNameComputed in Location did not match submitted data."); - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedLocation.getDisplayName(), - expectedDisplayName, - "Updated DisplayName (not computed) in Location not stored."); - } finally { - res.releaseConnection(); - } - } - - /** - * Verify illegal item display name. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"verifyItemDisplayName"}) - public void verifyIllegalItemDisplayName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - - // Perform setup for read. - setupRead(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - // Perform setup for update. - testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE); - - try { - - // Check whether Location has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - // Try to Update with computed false and no displayName - location.setDisplayNameComputed(false); - location.setDisplayName(null); - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res.releaseConnection(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - } 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"}) - public void readNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse 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(); - } - } - - /** - * Read item non existent. - * - * @param testName the test name - */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readItem"}) - public void readItemNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse 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(); - } - } - - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnGroups = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - try { - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } finally { - res.releaseConnection(); - } - } - - /** - * Read item list. - */ - @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) - public void readItemList() { - String testName = "readItemList"; - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - readItemList(knownResourceId, null); - } - - /** - * Read item list by authority name. - */ - @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) - public void readItemListByAuthorityName() { - String testName = "readItemListByAuthorityName"; - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - readItemList(null, knownResourceShortIdentifer); - } - - /** - * 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(); - ClientResponse 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!"); - } - assertStatusCode(res, testName); - try { - AbstractCommonList list = res.getEntity(); - - List items = - list.getListItem(); - 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); - - for (AbstractCommonList.ListItem item : items) { - String value = - AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME); - Assert.assertTrue((null != value), "Item refName is null!"); - value = - AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME); - Assert.assertTrue((null != value), "Item displayName is null!"); - } - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } finally { - res.releaseConnection(); - } - } - - - // Failure outcomes - // None at present. - - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnGroups = {"read", "readList"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - try { - - if(logger.isDebugEnabled()){ - logger.debug("got LocationAuthority to update with ID: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(locationAuthority); - - // Update the contents of this resource. - locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName()); - locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated LocationAuthority"); - logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res.releaseConnection(); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - LocationauthoritiesCommon updatedLocationAuthority = - (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(updatedLocationAuthority); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocationAuthority.getDisplayName(), - locationAuthority.getDisplayName(), - "Data in updated object did not match submitted data."); - } finally { - res.releaseConnection(); - } - } - - /** - * Update item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update"}) - public void updateItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = - client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - try { - if(logger.isDebugEnabled()){ - logger.debug("got Location to update with ID: " + - knownItemResourceId + - " in LocationAuthority: " + knownResourceId ); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - - // Update the contents of this resource. - location.setCsid(null); - location.setName("updated-" + location.getName()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated Location"); - logger.debug(objectAsXmlString(location, - LocationsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res.releaseConnection(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - LocationsCommon updatedLocation = - (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(updatedLocation); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocation.getName(), location.getName(), - "Data in updated Location did not match submitted data."); - } finally { - res.releaseConnection(); - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - + + private String knownLocationTypeRefName = null; + private String knownContactResourceId = null; + /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @Override - public void updateWithMalformedXml(String testName) throws Exception { + protected CollectionSpaceClient getClientInstance() { + return new LocationAuthorityClient(); } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + + /** + * Creates the item in authority. + * + * @param vcsid the vcsid + * @param authRefName the auth ref name + * @return the string */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - + private String createItemInAuthority(String vcsid, String authRefName) { + final String testName = "createItemInAuthority("+vcsid+","+authRefName+")"; - /* (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"}) - public void updateNonExistent(String testName) throws Exception { + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + Map shelf1Map = new HashMap(); + // TODO Make loc type and status be controlled vocabs. + shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME); + shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); + shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE); + shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE); + shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE); + shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE); + shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS); + shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); + shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS); + + String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid, + authRefName, shelf1Map, client ); - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + // Store the ID returned from the first item resource created + // for additional tests below. + if (knownItemResourceId == null){ + setKnownItemResource(newID, TEST_SHORTID); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownItemResourceId=" + newID); + } } - // Perform setup. - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID(s) used when creating the request payload may be arbitrary. - // The only relevant ID may be the one used in update(), below. - LocationAuthorityClient client = new LocationAuthorityClient(); - String displayName = "displayName-NON_EXISTENT_ID"; - PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance( - displayName, "nonEx", client.getCommonPartName()); - ClientResponse 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(); - } + // Store the IDs from any item resources created + // by tests, along with the IDs of their parents, so these items + // can be deleted after all tests have been run. + allResourceItemIdsCreated.put(newID, vcsid); + + return newID; } /** - * Update non existent item. + * Verify item display name. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) - public void updateNonExistentItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } + @Test(dataProvider="testName", + dependsOnMethods = {"readItem", "updateItem"}) + public void verifyItemDisplayName(String testName) throws Exception { // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. + setupRead(); + // + // First, read our known item resource + // LocationAuthorityClient client = new LocationAuthorityClient(); - Map nonexMap = new HashMap(); - nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME); - nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx"); - nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); - nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS); - // PoxPayloadOut multipart = - // LocationAuthorityClientUtils.createLocationInstance( - // LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"), - // nonexMap, client.getItemCommonPartName() ); - final String EMPTY_REFNAME = ""; - PoxPayloadOut multipart = - LocationAuthorityClientUtils.createLocationInstance(EMPTY_REFNAME, - nonexMap, client.getItemCommonPartName() ); - ClientResponse res = - client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + LocationsCommon location = null; 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(); - } - } - - // --------------------------------------------------------------- - // 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"}) - public void deleteItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if(logger.isDebugEnabled()){ - logger.debug("parentcsid =" + knownResourceId + - " itemcsid = " + knownItemResourceId); + assertStatusCode(res, testName); + // Check whether location has expected displayName. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + } finally { + if (res != null) { + res.releaseConnection(); + } } - - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = - client.deleteItem(knownResourceId, knownItemResourceId); + // + // Now prepare an updated payload. + // + String displayName = location.getDisplayName(); + // Make sure displayName matches computed form + String expectedDisplayName = + LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME); + Assert.assertNotNull(displayName, expectedDisplayName); + + // Update the shortName and verify the computed name is updated. + location.setCsid(null); + location.setDisplayNameComputed(true); + location.setName("updated-" + TEST_NAME); + expectedDisplayName = + LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME); + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), location); + + setupUpdate(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + LocationsCommon updatedLocation = null; 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(); - } - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if(logger.isDebugEnabled()){ - logger.debug("parentcsid =" + knownResourceId); + assertStatusCode(res, testName); + // Retrieve the updated resource and verify that its contents exist. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + updatedLocation = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + } finally { + if (res != null) { + res.releaseConnection(); + } } - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.delete(knownResourceId); + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.getName(), location.getName(), + "Updated ForeName in Location did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName, + "Updated ForeName in Location not reflected in computed DisplayName."); + // + // Now Update the displayName, not computed and verify the computed name is overriden. + // + location.setDisplayNameComputed(false); + expectedDisplayName = "TestName"; + location.setDisplayName(expectedDisplayName); + + // Submit the updated resource to the service and store the response. + output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + commonPart = output.addPart(client.getItemCommonPartName(), location); + setupUpdate(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); 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(); - } - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + assertStatusCode(res, testName); + // Retrieve the updated resource and verify that its contents exist. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + updatedLocation = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + } finally { + if (res != null) { + res.releaseConnection(); + } } - // Perform setup. - setupDeleteNonExistent(); - // Submit the request to the service and store the response. - LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse 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(); - } + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false, + "Updated displayNameComputed in Location did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedLocation.getDisplayName(), + expectedDisplayName, + "Updated DisplayName (not computed) in Location not stored."); } /** - * Delete non existent item. + * Verify illegal item display name. * * @param testName the test name + * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) - public void deleteNonExistentItem(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); + @Test(dataProvider="testName", + dependsOnMethods = {"verifyItemDisplayName"}) + public void verifyIllegalItemDisplayName(String testName) throws Exception { + // Perform setup for read. + setupRead(); // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + LocationsCommon location = null; 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); + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } + + // Try to Update with computed false and no displayName + location.setDisplayNameComputed(false); + location.setDisplayName(null); + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), location); + setupUpdateWithInvalidBody(); // we expected a failure here. + res = client.updateItem(knownResourceId, knownItemResourceId, output); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } + } } - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- /** - * Tests the code for manually submitting data that is used by several - * of the methods above. + * Read item list. */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testSubmitRequest: url=" + url + - " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - + @Test(dataProvider = "testName", groups = {"readList"}, + dependsOnMethods = {"readList"}) + public void readItemList(String testName) { + readItemList(knownAuthorityWithItems, null); } /** - * Test item submit request. + * Read item list by authority name. */ - @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) - public void testItemSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getItemResourceURL(knownResourceId, knownItemResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testItemSubmitRequest: url=" + url + - " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); + @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(); + ClientResponse 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.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + + List 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, REFNAME); + Assert.assertTrue((null != value), "Item refName is null!"); + value = AbstractCommonListUtils.ListItemGetElementValue(item, + DISPLAYNAME); + Assert.assertTrue((null != value), "Item displayName 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. + } + + @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } + @Override + public void deleteItem(String testName) throws Exception { + // Do nothing. We need to wait until after the test "localDelete" gets run. When it does, + // its dependencies will get run first and then we can call the base class' delete method. + } + + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"verifyIllegalItemDisplayName"}) + public void localDeleteItem(String testName) throws Exception { + super.deleteItem(testName); + } + // --------------------------------------------------------------- // Cleanup of resources created during testing // --------------------------------------------------------------- @@ -1274,21 +445,18 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FI LocationAuthorityClient client = new LocationAuthorityClient(); parentResourceId = knownResourceId; // Clean up item resources. - for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { itemResourceId = entry.getKey(); parentResourceId = entry.getValue(); // Note: Any non-success responses from the delete operation // below are ignored and not reported. - ClientResponse res = - client.deleteItem(parentResourceId, itemResourceId); - res.releaseConnection(); + client.deleteItem(parentResourceId, itemResourceId).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 res = client.delete(resourceId); - res.releaseConnection(); + client.delete(resourceId).releaseConnection(); } } @@ -1331,5 +499,111 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FI return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier; } + @Override + public void authorityTests(String testName) { + // TODO Auto-generated method stub + + } + + // + // Location specific overrides + // + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + // Submit the request to the service and store the response. + String shortId = identifier; + String displayName = "displayName-" + shortId; + // String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null); + PoxPayloadOut result = + LocationAuthorityClientUtils.createLocationAuthorityInstance( + displayName, shortId, commonPartName); + return result; + } + + @Override + protected PoxPayloadOut createNonExistenceInstance(String commonPartName, String identifier) { + String displayName = "displayName-NON_EXISTENT_ID"; + PoxPayloadOut result = LocationAuthorityClientUtils.createLocationAuthorityInstance( + displayName, "nonEx", commonPartName); + return result; + } + + @Override + protected LocationauthoritiesCommon updateInstance(LocationauthoritiesCommon locationauthoritiesCommon) { + LocationauthoritiesCommon result = new LocationauthoritiesCommon(); + + result.setDisplayName("updated-" + locationauthoritiesCommon.getDisplayName()); + result.setVocabType("updated-" + locationauthoritiesCommon.getVocabType()); + + return result; + } + + @Override + protected void compareUpdatedInstances(LocationauthoritiesCommon original, + LocationauthoritiesCommon updated) throws Exception { + Assert.assertEquals(updated.getDisplayName(), + original.getDisplayName(), + "Display name in updated object did not match submitted data."); + } + + protected void compareReadInstances(LocationauthoritiesCommon original, + LocationauthoritiesCommon fromRead) throws Exception { + Assert.assertNotNull(fromRead.getDisplayName()); + Assert.assertNotNull(fromRead.getShortIdentifier()); + Assert.assertNotNull(fromRead.getRefName()); + } + + // + // Authority item specific overrides + // + + @Override + protected String createItemInAuthority(String authorityId) { + return createItemInAuthority(authorityId, null /*refname*/); + } + + @Override + protected LocationsCommon updateItemInstance(LocationsCommon locationsCommon) { + LocationsCommon result = new LocationsCommon(); + + result.setName("updated-" + locationsCommon.getName()); + result.setDisplayName("updated-" + locationsCommon.getDisplayName()); + + return result; + } + + @Override + protected void compareUpdatedItemInstances(LocationsCommon original, + LocationsCommon updated) throws Exception { + Assert.assertEquals(updated.getName(), original.getName(), + "Data in updated Location did not match submitted data."); + } + + @Override + protected void verifyReadItemInstance(LocationsCommon item) + throws Exception { + // TODO Auto-generated method stub + + } + @Override + protected PoxPayloadOut createNonExistenceItemInstance( + String commonPartName, String identifier) { + Map nonexMap = new HashMap(); + nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME); + nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx"); + nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); + nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS); + // PoxPayloadOut multipart = + // LocationAuthorityClientUtils.createLocationInstance( + // LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"), + // nonexMap, client.getItemCommonPartName() ); + final String EMPTY_REFNAME = ""; + PoxPayloadOut result = + LocationAuthorityClientUtils.createLocationInstance(EMPTY_REFNAME, + nonexMap, commonPartName); + return result; + } } diff --git a/services/location/service/pom.xml b/services/location/service/pom.xml index 3476c0f1c..6af233446 100644 --- a/services/location/service/pom.xml +++ b/services/location/service/pom.xml @@ -57,7 +57,6 @@ org.testng testng - 5.6 diff --git a/services/media/client/pom.xml b/services/media/client/pom.xml index 24b6342c8..066984d91 100644 --- a/services/media/client/pom.xml +++ b/services/media/client/pom.xml @@ -67,7 +67,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java index 201bc7204..48d2819a2 100644 --- a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java +++ b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java @@ -44,9 +44,6 @@ import org.collectionspace.services.media.MediaCommon; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -59,7 +56,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class MediaAuthRefsTest extends BaseServiceTest { +public class MediaAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = MediaAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(MediaAuthRefsTest.class); final String PERSON_AUTHORITY_NAME = "MediaPersonAuth"; @@ -86,7 +83,7 @@ public class MediaAuthRefsTest extends BaseServiceTest { } @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -97,15 +94,13 @@ public class MediaAuthRefsTest extends BaseServiceTest { media.setTitle(title); PoxPayloadOut multipart = new PoxPayloadOut(MediaClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(media, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new MediaClient().getCommonPartName()); + PayloadOutputPart commonPart = multipart.addPart(new MediaClient().getCommonPartName(), media); logger.debug("to be created, media common: " + objectAsXmlString(media, MediaCommon.class)); return multipart; } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void createWithAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); testSetup(STATUS_CREATED, ServiceRequestType.CREATE); String identifier = createIdentifier(); // Submit the request to the service and store the response. createPersonRefs();// Create all the person refs and entities @@ -114,11 +109,17 @@ public class MediaAuthRefsTest extends BaseServiceTest { MediaClient mediaClient = new MediaClient(); PoxPayloadOut multipart = createMediaInstance(depositorRefName, "media.title-" + identifier); ClientResponse res = mediaClient.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. - knownResourceId = extractId(res); + try { + assertStatusCode(res, testName); + if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. + knownResourceId = extractId(res); + } + mediaIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup + } finally { + if (res != null) { + res.releaseConnection(); + } } - mediaIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup } protected void createPersonRefs() { @@ -127,8 +128,14 @@ public class MediaAuthRefsTest extends BaseServiceTest { PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); - assertStatusCode(res, "createPersonRefs (not a surefire test)"); - personAuthCSID = extractId(res); + try { + assertStatusCode(res, "createPersonRefs (not a surefire test)"); + personAuthCSID = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } + } String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); // Create temporary Person resources, and their corresponding refNames by which they can be identified. String csid = ""; @@ -143,6 +150,8 @@ public class MediaAuthRefsTest extends BaseServiceTest { } protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -151,8 +160,16 @@ public class MediaAuthRefsTest extends BaseServiceTest { PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance( personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); - assertStatusCode(res, "createPerson (not a surefire test)"); - return extractId(res); + try { + assertStatusCode(res, "createPerson (not a surefire test)"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + + return result; } // @Test annotation commented out by Aron 2010-12-02 until media payload is set to the @@ -164,23 +181,39 @@ public class MediaAuthRefsTest extends BaseServiceTest { // // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); testSetup(STATUS_OK, ServiceRequestType.READ); + MediaClient mediaClient = new MediaClient(); ClientResponse res = mediaClient.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - MediaCommon media = (MediaCommon) extractPart(input, mediaClient.getCommonPartName(), MediaCommon.class); - Assert.assertNotNull(media); - logger.debug(objectAsXmlString(media, MediaCommon.class)); + PoxPayloadIn input = null; + MediaCommon media = null; + try { + assertStatusCode(res, testName); + input = new PoxPayloadIn(res.getEntity()); + media = (MediaCommon) extractPart(input, mediaClient.getCommonPartName(), MediaCommon.class); + Assert.assertNotNull(media); + logger.debug(objectAsXmlString(media, MediaCommon.class)); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // Check a couple of fields Assert.assertEquals(media.getTitle(), title); // Get the auth refs and check them ClientResponse res2 = mediaClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - AuthorityRefList list = res2.getEntity(); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } + List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); logger.debug("Authority references, found " + numAuthRefsFound); diff --git a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java index b1e08d34b..3d8a2cf5c 100644 --- a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java +++ b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java @@ -24,7 +24,6 @@ package org.collectionspace.services.client.test; import java.io.File; import java.net.URL; -import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -32,9 +31,7 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.MediaClient; import org.collectionspace.services.client.PayloadOutputPart; -import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.media.LanguageList; import org.collectionspace.services.media.MediaCommon; @@ -55,11 +52,10 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class MediaServiceTest extends AbstractServiceTestImpl { +public class MediaServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = MediaServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(MediaServiceTest.class); - private String knownResourceId = null; private boolean mediaCleanup = true; @@ -99,26 +95,10 @@ public class MediaServiceTest extends AbstractServiceTestImpl { } @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(ClientResponse response) { return response.getEntity(AbstractCommonList.class); } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupCreate(); - MediaClient client = new MediaClient(); - PoxPayloadOut multipart = createMediaInstance(createIdentifier()); - ClientResponse res = client.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) { - knownResourceId = extractId(res); // Store the ID returned from the first resource created for additional tests below. - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run. - } - /** * Looks in the .../src/test/resources/blobs directory for files from which to create Blob * instances. @@ -128,85 +108,101 @@ public class MediaServiceTest extends AbstractServiceTestImpl { * @param fromUri - if 'false' then send the service a multipart/form-data POST from which to create the blob. * @throws Exception the exception */ - public void createBlob(String testName, boolean fromUri) throws Exception { - setupCreate(); - MediaClient client = new MediaClient(); - PoxPayloadOut multipart = createMediaInstance(createIdentifier()); - ClientResponse mediaRes = null; - String mediaCsid = null; - try { - mediaRes = client.create(multipart); - assertStatusCode(mediaRes, testName); - mediaCsid = extractId(mediaRes); - } finally { - mediaRes.releaseConnection(); - } - - String currentDir = this.getResourceDir(); - String blobsDirPath = currentDir + File.separator + BLOBS_DIR; - File blobsDir = new File(blobsDirPath); - if (blobsDir != null && blobsDir.exists()) { - File[] children = blobsDir.listFiles(); - if (children != null && children.length > 0) { - File blobFile = null; - // - // Since Media records can have only a single associated blob, - // we'll stop after we find a valid candidate - // - for (File child : children) { - if (isBlobbable(child) == true) { - blobFile = child; - break; - } - } - // - // If we found a good blob candidate file, then try to create the blob record - // - if (blobFile != null) { - client = new MediaClient(); - ClientResponse res = null; - String mimeType = this.getMimeType(blobFile); - logger.debug("Processing file URI: " + blobFile.getAbsolutePath()); - logger.debug("MIME type is: " + mimeType); - try { - if (fromUri == true) { - URL childUrl = blobFile.toURI().toURL(); - res = client.createBlobFromUri(mediaCsid, childUrl.toString()); - } else { - MultipartFormDataOutput formData = new MultipartFormDataOutput(); - OutputPart outputPart = formData.addFormData("file", blobFile, MediaType.valueOf(mimeType)); - res = client.createBlobFromFormData(mediaCsid, formData); - } - } finally { - res.releaseConnection(); - } - assertStatusCode(res, testName); - if (isMediaCleanup() == true) { - allResourceIdsCreated.add(extractId(res)); - allResourceIdsCreated.add(mediaCsid); - } - } else { - logger.debug("Directory: " + blobsDirPath + " contains no readable files."); - } - } else { - logger.debug("Directory: " + blobsDirPath + " is empty or cannot be read."); - } - } else { - logger.debug("Directory: " + blobsDirPath + " is missing or cannot be read."); - } - } + public void createBlob(String testName, boolean fromUri) throws Exception { + setupCreate(); + // + // First create a media record + // + MediaClient client = new MediaClient(); + PoxPayloadOut multipart = createMediaInstance(createIdentifier()); + ClientResponse mediaRes = client.create(multipart); + String mediaCsid = null; + try { + assertStatusCode(mediaRes, testName); + mediaCsid = extractId(mediaRes); + } finally { + if (mediaRes != null) { + mediaRes.releaseConnection(); + } + } + // + // Next, create a blob record to associate with the media record + // FIXME: REM - 1/2012, This method is too large. Break it up. The code below + // could be put into a utility class that could also be used by the blob service tests. + // + String currentDir = this.getResourceDir(); + String blobsDirPath = currentDir + File.separator + BLOBS_DIR; + File blobsDir = new File(blobsDirPath); + if (blobsDir != null && blobsDir.exists()) { + File[] children = blobsDir.listFiles(); + if (children != null && children.length > 0) { + File blobFile = null; + // + // Since Media records can have only a single associated + // blob, we'll stop after we find a valid candidate. + // + for (File child : children) { + if (isBlobbable(child) == true) { + blobFile = child; + break; + } + } + // + // If we found a good blob candidate file, then try to + // create the blob record + // + if (blobFile != null) { + client = new MediaClient(); + ClientResponse res = null; + String mimeType = this.getMimeType(blobFile); + logger.debug("Processing file URI: " + blobFile.getAbsolutePath()); + logger.debug("MIME type is: " + mimeType); + if (fromUri == true) { + URL childUrl = blobFile.toURI().toURL(); + res = client.createBlobFromUri(mediaCsid, + childUrl.toString()); + } else { + MultipartFormDataOutput formData = new MultipartFormDataOutput(); + OutputPart outputPart = formData.addFormData("file", + blobFile, MediaType.valueOf(mimeType)); + res = client + .createBlobFromFormData(mediaCsid, formData); + } + try { + assertStatusCode(res, testName); + String blobCsid = extractId(res); + if (isMediaCleanup() == true) { + allResourceIdsCreated.add(blobCsid); + allResourceIdsCreated.add(mediaCsid); + } + } finally { + if (res != null) { + res.releaseConnection(); + } + } + } else { + logger.debug("Directory: " + blobsDirPath + + " contains no readable files."); + } + } else { + logger.debug("Directory: " + blobsDirPath + + " is empty or cannot be read."); + } + } else { + logger.debug("Directory: " + blobsDirPath + + " is missing or cannot be read."); + } + } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void createWithBlobUri(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); createBlob(testName, true /*with URI*/); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + @Test(dataProvider = "testName", dependsOnMethods = {"createWithBlobUri"}) public void createWithBlobPost(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); createBlob(testName, false /*with POST*/); } @@ -224,165 +220,15 @@ public class MediaServiceTest extends AbstractServiceTestImpl { // allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run. // } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - for (int i = 0; i < 3; i++) { - create(testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupRead(); - MediaClient client = new MediaClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - MediaCommon media = (MediaCommon) extractPart(input, client.getCommonPartName(), MediaCommon.class); - Assert.assertNotNull(media); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadList(); - MediaClient client = new MediaClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdate(); - MediaClient client = new MediaClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - logger.debug("got object to update with ID: " + knownResourceId); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity());; - MediaCommon media = (MediaCommon) extractPart(input, client.getCommonPartName(), MediaCommon.class); - Assert.assertNotNull(media); - - media.setTitle("updated-" + media.getTitle()); - logger.debug("Object to be updated:"+objectAsXmlString(media, MediaCommon.class)); - PoxPayloadOut output = new PoxPayloadOut(MediaClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(media, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - MediaCommon updatedMedia = (MediaCommon) extractPart(input, client.getCommonPartName(), MediaCommon.class); - Assert.assertNotNull(updatedMedia); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - MediaClient client = new MediaClient(); - PoxPayloadOut multipart = createMediaInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - assertStatusCode(res, testName); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDelete(); - MediaClient client = new MediaClient(); - ClientResponse res = client.delete(knownResourceId); - assertStatusCode(res, testName); - } - - // --------------------------------------------------------------- - // Failure outcome tests : means we expect response to fail, but test to succeed - // --------------------------------------------------------------- - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadNonExistent(); - MediaClient client = new MediaClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDeleteNonExistent(); - MediaClient client = new MediaClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcomes - // Placeholders until the tests below can be implemented. See Issue CSPACE-401. - - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - } - - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - // --------------------------------------------------------------- // Utility tests : tests of code used in tests above // --------------------------------------------------------------- - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode); - Assert.assertEquals(statusCode, EXPECTED_STATUS); - } - @Override protected PoxPayloadOut createInstance(String identifier) { return createMediaInstance(identifier); } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -414,4 +260,34 @@ public class MediaServiceTest extends AbstractServiceTestImpl { return multipart; } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return createMediaInstance(identifier); + } + + @Override + protected MediaCommon updateInstance(final MediaCommon original) { + MediaCommon result = new MediaCommon(); + + result.setTitle("updated-" + original.getTitle()); + + return result; + } + + @Override + protected void compareUpdatedInstances(MediaCommon original, + MediaCommon updated) throws Exception { + Assert.assertEquals(updated.getTitle(), original.getTitle()); + } + + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } } diff --git a/services/media/service/pom.xml b/services/media/service/pom.xml index 12eed8972..5d04019ea 100644 --- a/services/media/service/pom.xml +++ b/services/media/service/pom.xml @@ -54,7 +54,6 @@ org.testng testng - 5.6 diff --git a/services/movement/client/pom.xml b/services/movement/client/pom.xml index 52d85c548..d0de00df3 100644 --- a/services/movement/client/pom.xml +++ b/services/movement/client/pom.xml @@ -63,7 +63,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java index 16f071a9f..1d1f22e27 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java @@ -60,7 +60,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class MovementAuthRefsTest extends BaseServiceTest { +public class MovementAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = MovementAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -69,7 +69,6 @@ public class MovementAuthRefsTest extends BaseServiceTest { // Instance variables specific to this test. final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; - private String knownResourceId = null; private List movementIdsCreated = new ArrayList(); private List personIdsCreated = new ArrayList(); private String personAuthCSID = null; @@ -92,7 +91,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -101,12 +100,8 @@ public class MovementAuthRefsTest extends BaseServiceTest { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + @Test(dataProvider="testName") public void createWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Submit the request to the service and store the response. @@ -136,9 +131,9 @@ public class MovementAuthRefsTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from the first resource created // for additional tests below. @@ -164,8 +159,8 @@ public class MovementAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); @@ -190,8 +185,8 @@ public class MovementAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); } @@ -200,39 +195,45 @@ public class MovementAuthRefsTest extends BaseServiceTest { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. MovementClient movementClient = new MovementClient(); ClientResponse res = movementClient.read(knownResourceId); - assertStatusCode(res, testName); - - // Extract and return the common part of the record. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(movementClient.getCommonPartName()); MovementsCommon movementCommon = null; - if (payloadInputPart != null) { - movementCommon = (MovementsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(movementCommon); - if(logger.isDebugEnabled()){ - logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class)); + try { + assertStatusCode(res, testName); + // Extract and return the common part of the record. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(movementClient.getCommonPartName()); + if (payloadInputPart != null) { + movementCommon = (MovementsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(movementCommon); + if(logger.isDebugEnabled()){ + logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class)); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } // Check a couple of fields // FIXME Assert.assertEquals(movementCommon.getMovementContact(), movementContactRefName); // Get the auth refs and check them - ClientResponse res2 = - movementClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - - AuthorityRefList list = res2.getEntity(); + ClientResponse res2 = movementClient.getAuthorityRefs(knownResourceId); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java index b3370c00d..9dcef1204 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java @@ -22,16 +22,10 @@ */ package org.collectionspace.services.client.test; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; import java.util.List; -import java.util.TimeZone; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.MovementClient; @@ -41,6 +35,7 @@ import org.collectionspace.services.movement.MovementMethodsList; import org.jboss.resteasy.client.ClientResponse; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; @@ -52,746 +47,214 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * MovementServiceTest, carries out tests against a - * deployed and running Movement Service. - * - * $LastChangedRevision$ - * $LastChangedDate$ + * MovementServiceTest, carries out tests against a deployed and running + * Movement Service. + * + * $LastChangedRevision$ $LastChangedDate: 2011-11-14 23:26:36 -0800 + * (Mon, 14 Nov 2011) $ */ -public class MovementServiceTest extends AbstractServiceTestImpl { - - /** The logger. */ - private final String CLASS_NAME = MovementServiceTest.class.getName(); - private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - - final String SERVICE_NAME = "movements"; - final String SERVICE_PATH_COMPONENT = "movements"; - - // Instance variables specific to this test. - private String knownResourceId = null; - private final static String TIMESTAMP_UTC = - GregorianCalendarDateTimeUtils.timestampUTC(); - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() - */ - @Override - protected CollectionSpaceClient getClientInstance() { - return new MovementClient(); - } - - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - MovementClient client = new MovementClient(); - String identifier = createIdentifier(); - PoxPayloadOut multipart = createMovementInstance(identifier); - ClientResponse res = client.create(multipart); - - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null){ - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - for(int i = 0; i < 3; i++){ - create(testName); - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("createWithEmptyEntityBody url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - MovementClient client = new MovementClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - // Get the common part of the response and verify that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - MovementsCommon movementCommon = null; - if (payloadInputPart != null) { - movementCommon = (MovementsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(movementCommon); - - // Check selected fields. - - // Check the values of one or more date/time fields. - if (logger.isDebugEnabled()) { - logger.debug("locationDate=" + movementCommon.getLocationDate()); - logger.debug("TIMESTAMP_UTC=" + TIMESTAMP_UTC); - } - Assert.assertTrue(movementCommon.getLocationDate().equals(TIMESTAMP_UTC)); - Assert.assertTrue(movementCommon.getPlannedRemovalDate().equals(TIMESTAMP_UTC)); - Assert.assertNull(movementCommon.getRemovalDate()); - - // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters. - if(logger.isDebugEnabled()){ - logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" - + "UTF-8 data received=" + movementCommon.getMovementNote()); - } - Assert.assertEquals(movementCommon.getMovementNote(), getUTF8DataFragment(), - "UTF-8 data retrieved '" + movementCommon.getMovementNote() - + "' does not match expected data '" + getUTF8DataFragment()); - - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - MovementClient client = new MovementClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - MovementClient client = new MovementClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - MovementClient client = new MovementClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - assertStatusCode(res, testName); - - // Extract the common part from the response. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - MovementsCommon movementCommon = null; - if (payloadInputPart != null) { - movementCommon = (MovementsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(movementCommon); - - // Update its content. - movementCommon.setMovementReferenceNumber("updated-" + movementCommon.getMovementReferenceNumber()); - movementCommon.setMovementNote("updated movement note-" + movementCommon.getMovementNote()); - movementCommon.setNormalLocation(""); // Test deletion of existing string value - - String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC(); - movementCommon.setPlannedRemovalDate(""); // Test deletion of existing date or date/time value - movementCommon.setRemovalDate(currentTimestamp); - - if(logger.isDebugEnabled()){ - logger.debug("to be updated object"); - logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class)); - } - - // Submit the request to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - // Extract the updated common part from the response. - input = new PoxPayloadIn(res.getEntity()); - payloadInputPart = input.getPart(client.getCommonPartName()); - MovementsCommon updatedMovementCommon = null; - if (payloadInputPart != null) { - updatedMovementCommon = (MovementsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(movementCommon); - if(logger.isDebugEnabled()){ - logger.debug("updated object"); - logger.debug(objectAsXmlString(updatedMovementCommon, MovementsCommon.class)); - } - - // Check selected fields in the updated common part. - - // By submitting an empty string in the update payload, the value of this field - // in the object created from the response payload will be null. - Assert.assertNull(updatedMovementCommon.getNormalLocation(), "Data in updated object did not match submitted data."); - if(logger.isDebugEnabled()){ - logger.debug("Normal location after update=|" + updatedMovementCommon.getNormalLocation() + "|"); - } - - Assert.assertEquals(updatedMovementCommon.getMovementReferenceNumber(), - movementCommon.getMovementReferenceNumber(), - "Data in updated object did not match submitted data."); - Assert.assertEquals(updatedMovementCommon.getMovementNote(), - movementCommon.getMovementNote(), - "Data in updated object did not match submitted data."); - Assert.assertNull(updatedMovementCommon.getPlannedRemovalDate()); - Assert.assertEquals(updatedMovementCommon.getRemovalDate(), - movementCommon.getRemovalDate(), - "Data in updated object did not match submitted data."); - - if(logger.isDebugEnabled()){ - logger.debug("UTF-8 data sent=" + movementCommon.getMovementNote() + "\n" - + "UTF-8 data received=" + updatedMovementCommon.getMovementNote()); - } - Assert.assertTrue(updatedMovementCommon.getMovementNote().contains(getUTF8DataFragment()), - "UTF-8 data retrieved '" + updatedMovementCommon.getMovementNote() - + "' does not contain expected data '" + getUTF8DataFragment()); - Assert.assertEquals(updatedMovementCommon.getMovementNote(), - movementCommon.getMovementNote(), - "Data in updated object did not match submitted data."); - - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception{ - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - MovementClient client = new MovementClient(); - PoxPayloadOut multipart = createMovementInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - /* - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - MovementClient client = new MovementClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - * - */ - } - - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - MovementClient client = new MovementClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testSubmitRequest: url=" + url + - " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- - - @Override - protected String getServiceName() { - return SERVICE_NAME; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() - */ - @Override - public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; - } - - /** - * Creates the movement instance. - * - * @param identifier the identifier - * @return the multipart output - */ - private PoxPayloadOut createMovementInstance(String identifier) { - return createInstance("movementReferenceNumber-" + identifier); - } - - /** - * Creates an instance of a Movement record for testing. - * - * @param movementReferenceNumber A movement reference number. - * @return Multipart output suitable for use as a payload - * in a create or update request. - */ - @Override - public PoxPayloadOut createInstance(String movementReferenceNumber) { - MovementsCommon movementCommon = new MovementsCommon(); - // FIXME: Values of currentLocation, normalLocation, - // and movementContact should be refNames. - movementCommon.setCurrentLocation("currentLocation value"); - movementCommon.setCurrentLocationFitness("currentLocationFitness value"); - movementCommon.setCurrentLocationNote("currentLocationNote value"); - movementCommon.setLocationDate(TIMESTAMP_UTC); - movementCommon.setNormalLocation("normalLocation value"); - movementCommon.setMovementContact("movementContact value"); - MovementMethodsList movementMethodsList = new MovementMethodsList(); - List methods = movementMethodsList.getMovementMethod(); - // @TODO Use properly formatted refNames for representative movement - // methods in this example record. The values below are placeholders. - String identifier = createIdentifier(); - methods.add("First Movement Method-" + identifier); - methods.add("Second Movement Method-" + identifier); - movementCommon.setMovementMethods(movementMethodsList); - movementCommon.setMovementNote(getUTF8DataFragment()); - movementCommon.setMovementReferenceNumber(movementReferenceNumber); - movementCommon.setPlannedRemovalDate(TIMESTAMP_UTC); - movementCommon.setRemovalDate(""); // Test empty date value - movementCommon.setReasonForMove("reasonForMove value"); - - PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = - multipart.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new MovementClient().getCommonPartName()); - - if(logger.isDebugEnabled()){ - logger.debug("to be created, movement common"); - logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class)); - } - - return multipart; - } - +public class MovementServiceTest extends + AbstractPoxServiceTestImpl { + + /** The logger. */ + private final String CLASS_NAME = MovementServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + + final String SERVICE_NAME = "movements"; + final String SERVICE_PATH_COMPONENT = "movements"; + + private final static String TIMESTAMP_UTC = GregorianCalendarDateTimeUtils + .timestampUTC(); + + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.test.BaseServiceTest#getClientInstance + * () + */ + @Override + protected CollectionSpaceClient getClientInstance() { + return new MovementClient(); + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + @Override + protected String getServiceName() { + return SERVICE_NAME; + } + + /* + * (non-Javadoc) + * + * @see org.collectionspace.services.client.test.BaseServiceTest# + * getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + /** + * Creates the movement instance. + * + * @param identifier + * the identifier + * @return the multipart output + */ + private PoxPayloadOut createMovementInstance(String identifier) { + return createInstance("movementReferenceNumber-" + identifier); + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = createMovementInstance(identifier); + return result; + } + + /** + * Creates an instance of a Movement record for testing. + * + * @param movementReferenceNumber + * A movement reference number. + * @return Multipart output suitable for use as a payload in a create or + * update request. + */ + @Override + protected PoxPayloadOut createInstance(String movementReferenceNumber) { + MovementsCommon movementCommon = new MovementsCommon(); + // FIXME: Values of currentLocation, normalLocation, + // and movementContact should be refNames. + movementCommon.setCurrentLocation("currentLocation value"); + movementCommon + .setCurrentLocationFitness("currentLocationFitness value"); + movementCommon.setCurrentLocationNote("currentLocationNote value"); + movementCommon.setLocationDate(TIMESTAMP_UTC); + movementCommon.setNormalLocation("normalLocation value"); + movementCommon.setMovementContact("movementContact value"); + MovementMethodsList movementMethodsList = new MovementMethodsList(); + List methods = movementMethodsList.getMovementMethod(); + // @TODO Use properly formatted refNames for representative movement + // methods in this example record. The values below are placeholders. + String identifier = createIdentifier(); + methods.add("First Movement Method-" + identifier); + methods.add("Second Movement Method-" + identifier); + movementCommon.setMovementMethods(movementMethodsList); + movementCommon.setMovementNote(getUTF8DataFragment()); + movementCommon.setMovementReferenceNumber(movementReferenceNumber); + movementCommon.setPlannedRemovalDate(TIMESTAMP_UTC); + movementCommon.setRemovalDate(""); // Test empty date value + movementCommon.setReasonForMove("reasonForMove value"); + + PoxPayloadOut multipart = new PoxPayloadOut( + this.getServicePathComponent()); + PayloadOutputPart commonPart = multipart.addPart( + new MovementClient().getCommonPartName(), movementCommon); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, movement common"); + logger.debug(objectAsXmlString(movementCommon, + MovementsCommon.class)); + } + + return multipart; + } + + @Override + protected MovementsCommon updateInstance(MovementsCommon movementsCommon) { + MovementsCommon result = new MovementsCommon(); + + result.setMovementReferenceNumber("updated-" + + movementsCommon.getMovementReferenceNumber()); + result.setMovementNote("updated movement note-" + + movementsCommon.getMovementNote()); + result.setNormalLocation(""); // Test deletion of existing + // string value + + String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC(); + result.setPlannedRemovalDate(""); // Test deletion of existing + // date or date/time value + result.setRemovalDate(currentTimestamp); + + return result; + } + + @Override + protected void compareUpdatedInstances(MovementsCommon original, + MovementsCommon updated) throws Exception { + // By submitting an empty string in the update payload, the value of + // this field + // in the object created from the response payload will be null. + Assert.assertNull(updated.getNormalLocation(), + "Normal location in updated object did not match submitted data."); + if (logger.isDebugEnabled()) { + logger.debug("Normal location after update=|" + + updated.getNormalLocation() + "|"); + } + + Assert.assertEquals(updated.getMovementReferenceNumber(), + original.getMovementReferenceNumber(), + "Movement reference number in updated object did not match submitted data."); + Assert.assertEquals(updated.getMovementNote(), + original.getMovementNote(), + "Movement note in updated object did not match submitted data."); + Assert.assertNull(updated.getPlannedRemovalDate()); + Assert.assertEquals(updated.getRemovalDate(), + original.getRemovalDate(), + "Removal date in updated object did not match submitted data."); + + if (logger.isDebugEnabled()) { + logger.debug("UTF-8 data sent=" + original.getMovementNote() + + "\n" + "UTF-8 data received=" + + updated.getMovementNote()); + } + Assert.assertTrue( + updated.getMovementNote().contains( + getUTF8DataFragment()), "UTF-8 data retrieved '" + + updated.getMovementNote() + + "' does not contain expected data '" + + getUTF8DataFragment()); + Assert.assertEquals(updated.getMovementNote(), + original.getMovementNote(), + "Movement note in updated object did not match submitted data."); + } + + protected void compareReadInstances(MovementsCommon original, + MovementsCommon fromRead) throws Exception { + // Check the values of one or more date/time fields. + if (logger.isDebugEnabled()) { + logger.debug("locationDate=" + fromRead.getLocationDate()); + logger.debug("TIMESTAMP_UTC=" + TIMESTAMP_UTC); + } + Assert.assertTrue(fromRead.getLocationDate().equals(TIMESTAMP_UTC)); + Assert.assertTrue(fromRead.getPlannedRemovalDate().equals(TIMESTAMP_UTC)); + Assert.assertNull(fromRead.getRemovalDate()); + + // Check the values of fields containing Unicode UTF-8 (non-Latin-1) + // characters. + if (logger.isDebugEnabled()) { + logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" + + "UTF-8 data received=" + fromRead.getMovementNote()); + } + Assert.assertEquals(fromRead.getMovementNote(), + getUTF8DataFragment(), "UTF-8 data retrieved '" + + fromRead.getMovementNote() + + "' does not match expected data '" + + getUTF8DataFragment()); + } + + /* + * For convenience and terseness, this test method is the base of the test + * execution dependency chain. Other test methods may refer to this method + * in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", dependsOnMethods = { "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests" }) + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + } } diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java index 47155c635..9b4199a9c 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java @@ -27,17 +27,16 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Locale; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.MovementJAXBSchema; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.MovementClient; 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.common.AbstractCommonListUtils; import org.collectionspace.services.movement.MovementsCommon; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -58,7 +57,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 2562 $ * $LastChangedDate: 2010-06-22 23:26:51 -0700 (Tue, 22 Jun 2010) $ */ -public class MovementSortByTest extends BaseServiceTest { +public class MovementSortByTest extends BaseServiceTest { private final String CLASS_NAME = MovementSortByTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -86,7 +85,7 @@ public class MovementSortByTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -101,14 +100,9 @@ public class MovementSortByTest extends BaseServiceTest { * Tests whether a list of records, sorted by a String field in * ascending order, is returned in the expected order. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createList"}) public void sortByStringFieldAscending(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - String sortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE); if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); @@ -154,14 +148,9 @@ public class MovementSortByTest extends BaseServiceTest { * This verifies that summary list results from keyword searches, in * addition to 'read list' requests, can be returned in sorted order. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createList"}) public void sortKeywordSearchResultsByStringFieldAscending(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - String sortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE); if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); @@ -204,14 +193,9 @@ public class MovementSortByTest extends BaseServiceTest { * Tests whether a list of records, sorted by a String field in * descending order, is returned in the expected order. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createList"}) public void sortByStringFieldDescending(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - String sortFieldName = asDescendingSort(qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE)); if (logger.isDebugEnabled()) { @@ -255,14 +239,9 @@ public class MovementSortByTest extends BaseServiceTest { * Tests whether a list of records, sorted by a dateTime field in * ascending order, is returned in the expected order. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createList"}) public void sortByDateTimeFieldAscending(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - String sortFieldName = qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE); if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); @@ -294,14 +273,9 @@ public class MovementSortByTest extends BaseServiceTest { * Tests whether a list of records, sorted by a dateTime field in * descending order, is returned in the expected order. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createList"}) public void sortByDateTimeFieldDescending(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - String sortFieldName = asDescendingSort(qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE)); if (logger.isDebugEnabled()) { @@ -334,14 +308,9 @@ public class MovementSortByTest extends BaseServiceTest { * Tests whether a list of records, sorted by two different fields in * ascending order, is returned in the expected order. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createList"}) public void sortByTwoFieldsAscending(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - String firstSortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE); String secondSortFieldName = qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE); if (logger.isDebugEnabled()) { @@ -392,14 +361,9 @@ public class MovementSortByTest extends BaseServiceTest { * Tests whether a list of records, sorted by one different fields in * descending order and a second field in ascending order, is returned in the expected order. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createList"}) public void sortByOneFieldAscendingOneFieldsDescending(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - String firstSortFieldName = asDescendingSort(qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE)); String secondSortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE); @@ -453,12 +417,8 @@ public class MovementSortByTest extends BaseServiceTest { * as expected: the query parameter is simply ignored, and a list * of records is returned, unsorted, with a success result. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void sortWithEmptySortFieldName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. @@ -466,17 +426,13 @@ public class MovementSortByTest extends BaseServiceTest { final String EMPTY_SORT_FIELD_NAME = ""; ClientResponse res = client.readListSortedBy(EMPTY_SORT_FIELD_NAME); - 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); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } // Failure outcomes @@ -486,41 +442,29 @@ public class MovementSortByTest extends BaseServiceTest { * handled as expected. The field name provided in this test is valid, * but has not been qualified by being prefixed by a schema name and delimiter. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void sortWithUnqualifiedFieldName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_BAD_REQUEST, ServiceRequestType.READ); // Submit the request to the service and store the response. MovementClient client = new MovementClient(); ClientResponse res = client.readListSortedBy(MovementJAXBSchema.LOCATION_DATE); - 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); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } /* * Tests whether a request to sort by an invalid identifier for the * sort order (ascending or descending) is handled as expected. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void sortWithInvalidSortOrderIdentifier(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_BAD_REQUEST, ServiceRequestType.READ); // Submit the request to the service and store the response. @@ -529,39 +473,14 @@ public class MovementSortByTest extends BaseServiceTest { ClientResponse res = client.readListSortedBy(MovementJAXBSchema.LOCATION_DATE + " " + INVALID_SORT_ORDER_IDENTIFIER); - 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); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - } - - /* - * Tests whether a request to sort by a malformed field name is - * handled as expected. - */ -/* - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) - public void sortWithMalformedFieldName(String testName) throws Exception { - - // FIXME: Implement this stub method. - - // FIXME: Consider splitting this test into various tests, with - // different malformed field name formats that might confuse parsers - // and/or validation code. - - // FIXME: Consider fixing DocumentFilter.setSortOrder() to return - // an error response to this test case, then revise this test case - // to expect that response. - } -*/ // --------------------------------------------------------------- // Cleanup of resources created during testing @@ -590,7 +509,7 @@ public class MovementSortByTest extends BaseServiceTest { MovementClient movementClient = new MovementClient(); for (String resourceId : movementIdsCreated) { // Note: Any non-success responses are ignored and not reported. - movementClient.delete(resourceId); + movementClient.delete(resourceId).releaseConnection(); } } @@ -664,7 +583,7 @@ public class MovementSortByTest extends BaseServiceTest { String testName = "createList"; if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + logger.debug(getTestBanner(testName, CLASS_NAME)); } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); @@ -674,7 +593,8 @@ public class MovementSortByTest extends BaseServiceTest { } private void create(String movementNote, String locationDate) throws Exception { - + String result = null; + String testName = "create"; testSetup(STATUS_CREATED, ServiceRequestType.CREATE); @@ -683,42 +603,42 @@ public class MovementSortByTest extends BaseServiceTest { movementNote, locationDate); MovementClient client = new MovementClient(); ClientResponse res = client.create(multipart); - 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); + try { + assertStatusCode(res, testName); + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + + if (result != null) { + movementIdsCreated.add(result); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - movementIdsCreated.add(extractId(res)); } private MovementsCommon read(String csid) throws Exception { - String testName = "read"; testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. MovementClient client = new MovementClient(); ClientResponse res = client.read(csid); - assertStatusCode(res, testName); - - // Extract and return the common part of the record. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); MovementsCommon movementCommon = null; - if (payloadInputPart != null) { - movementCommon = (MovementsCommon) payloadInputPart.getBody(); + try { + assertStatusCode(res, testName); + // Extract and return the common part of the record. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + if (payloadInputPart != null) { + movementCommon = (MovementsCommon) payloadInputPart.getBody(); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } return movementCommon; @@ -735,8 +655,7 @@ public class MovementSortByTest extends BaseServiceTest { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new MovementClient().getCommonPartName()); + multipart.addPart(new MovementClient().getCommonPartName(), movementCommon); if (logger.isDebugEnabled()) { logger.debug("to be created, movement common"); logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class)); @@ -746,17 +665,22 @@ public class MovementSortByTest extends BaseServiceTest { } private AbstractCommonList readSortedList(String sortFieldName) throws Exception { - String testName = "readSortedList"; testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. MovementClient client = new MovementClient(); - ClientResponse res = - client.readListSortedBy(sortFieldName); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); + ClientResponse res = client.readListSortedBy(sortFieldName); + AbstractCommonList list = null; + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } return list; @@ -764,7 +688,8 @@ public class MovementSortByTest extends BaseServiceTest { private AbstractCommonList keywordSearchSortedBy(String keywords, String sortFieldName) throws Exception { - + AbstractCommonList result = null; + String testName = "keywordSearchSortedBy"; testSetup(STATUS_OK, ServiceRequestType.READ); @@ -773,11 +698,17 @@ public class MovementSortByTest extends BaseServiceTest { ClientResponse res = client.keywordSearchSortedBy(keywords, sortFieldName); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); + AbstractCommonList list = null; + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } return list; - } } diff --git a/services/movement/service/pom.xml b/services/movement/service/pom.xml index 228633295..3ebae0ddb 100644 --- a/services/movement/service/pom.xml +++ b/services/movement/service/pom.xml @@ -44,7 +44,6 @@ org.testng testng - 5.6 diff --git a/services/note/3rdparty/nuxeo-platform-cs-note/src/main/resources/META-INF/MANIFEST.MF b/services/note/3rdparty/nuxeo-platform-cs-note/src/main/resources/META-INF/MANIFEST.MF index 50d35a9dc..3ce672f4b 100644 --- a/services/note/3rdparty/nuxeo-platform-cs-note/src/main/resources/META-INF/MANIFEST.MF +++ b/services/note/3rdparty/nuxeo-platform-cs-note/src/main/resources/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Require-Bundle: org.nuxeo.runtime, org.collectionspace.collectionspace_core Provide-Package: org.collectionspace.note Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/life-cycle-contrib.xml, OSGI-INF/ecm-types-contrib.xml, OSGI-INF/layouts-contrib.xml diff --git a/services/note/3rdparty/nuxeo-platform-cs-note/src/main/resources/OSGI-INF/life-cycle-contrib.xml b/services/note/3rdparty/nuxeo-platform-cs-note/src/main/resources/OSGI-INF/life-cycle-contrib.xml new file mode 100644 index 000000000..82774c7f5 --- /dev/null +++ b/services/note/3rdparty/nuxeo-platform-cs-note/src/main/resources/OSGI-INF/life-cycle-contrib.xml @@ -0,0 +1,11 @@ + + + + + + default + + + + diff --git a/services/note/client/pom.xml b/services/note/client/pom.xml index 13678d7b8..22ca84347 100644 --- a/services/note/client/pom.xml +++ b/services/note/client/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.note.client services.note.client @@ -42,16 +41,18 @@ + + org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/note/client/src/main/java/org/collectionspace/services/client/NoteClient.java b/services/note/client/src/main/java/org/collectionspace/services/client/NoteClient.java index ac2bef72a..f38dae4ef 100644 --- a/services/note/client/src/main/java/org/collectionspace/services/client/NoteClient.java +++ b/services/note/client/src/main/java/org/collectionspace/services/client/NoteClient.java @@ -33,7 +33,7 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; * $LastChangedDate: $ */ -public class NoteClient extends AbstractServiceClientImpl { +public class NoteClient extends AbstractPoxServiceClientImpl { public static final String SERVICE_NAME = "notes"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; @@ -65,37 +65,4 @@ public class NoteClient extends AbstractServiceClientImpl readList() { return getProxy().readList(); } - - /** - * @param csid - * @return - * @see org.collectionspace.services.client.Note#getNote(java.lang.String) - */ - - public ClientResponse read(String csid) { - return getProxy().read(csid); - } - - /** - * @param multipart - * @param note - * @return - * @see org.collectionspace.services.client.Note#createNote(org.collectionspace.services.Note) - */ - public ClientResponse create(PoxPayloadOut multipart) { - String payload = multipart.toXML(); - return getProxy().create(payload); - } - - /** - * @param csid - * @param multipart - * @return - * @see org.collectionspace.services.client.Note#updateNote(java.lang.Long, org.collectionspace.services.Note) - */ - public ClientResponse update(String csid, PoxPayloadOut multipart) { - String payload = multipart.toXML(); - return getProxy().update(csid, payload); - - } } diff --git a/services/note/client/src/main/java/org/collectionspace/services/client/NoteProxy.java b/services/note/client/src/main/java/org/collectionspace/services/client/NoteProxy.java index 73e36f947..f2402c629 100644 --- a/services/note/client/src/main/java/org/collectionspace/services/client/NoteProxy.java +++ b/services/note/client/src/main/java/org/collectionspace/services/client/NoteProxy.java @@ -22,12 +22,25 @@ import org.jboss.resteasy.client.ClientResponse; @Path("/notes/") @Produces({"application/xml;charset=UTF-8"}) @Consumes({"application/xml"}) -public interface NoteProxy extends CollectionSpaceProxy { - +public interface NoteProxy extends CollectionSpacePoxProxy { @GET @Produces({"application/xml"}) ClientResponse readList(); + @Override + @GET + @Produces({"application/xml"}) + ClientResponse readIncludeDeleted( + @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); + + @Override + @GET + @Produces({"application/xml"}) + ClientResponse keywordSearchIncludeDeleted( + @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, + @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); + + /* //(C)reate @POST ClientResponse create(String payload); @@ -46,4 +59,5 @@ public interface NoteProxy extends CollectionSpaceProxy { @DELETE @Path("/{csid}") ClientResponse delete(@PathParam("csid") String csid); + */ } diff --git a/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java b/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java index 528184021..d2e2a232d 100644 --- a/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java +++ b/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java @@ -22,31 +22,16 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; -import java.util.List; - import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.NoteClient; import org.collectionspace.services.client.NoteClientUtils; -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.note.NotesCommon; import org.collectionspace.services.note.NotesCommonList; -import org.collectionspace.services.jaxb.AbstractCommonList; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.jboss.resteasy.client.ClientResponse; -import org.dom4j.DocumentException; - -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.testng.Assert; /** * NoteServiceTest, carries out tests against a @@ -55,7 +40,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class NoteServiceTest extends AbstractServiceTestImpl { +public class NoteServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = NoteServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -63,9 +48,6 @@ public class NoteServiceTest extends AbstractServiceTestImpl { private final String SERVICE_PATH_COMPONENT = "notes"; private final String SERVICE_NAME = "notes"; - // Instance variables specific to this test. - private String knownResourceId = null; - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -74,383 +56,15 @@ public class NoteServiceTest extends AbstractServiceTestImpl { return new NoteClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(NotesCommonList.class); - } - - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - NoteClient client = new NoteClient(); - String identifier = createIdentifier(); - PoxPayloadOut multipart = - NoteClientUtils.createNoteInstance("owner"+identifier, identifier, - client.getCommonPartName()); - ClientResponse res = client.create(multipart); - - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null){ - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - for(int i = 0; i < 3; i++){ - create(testName); - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty?? - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty?? - } - - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - NoteClient client = new NoteClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - // Get the common part of the response and verify that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - NotesCommon noteCommon = null; - if (payloadInputPart != null) { - noteCommon = (NotesCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(noteCommon); - } - - // Failure outcomes - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - NoteClient client = new NoteClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - NoteClient client = new NoteClient(); - ClientResponse res = client.readList(); - NotesCommonList list = res.getEntity(); - assertStatusCode(res, testName); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if(iterateThroughList && logger.isDebugEnabled()){ - List items = - list.getNoteListItem(); - int i = 0; - for(NotesCommonList.NoteListItem item : items){ - logger.debug(testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] content=" + - item.getContent()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); - i++; - } - } - - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Submit the request to the service and store the response. - NoteClient client = new NoteClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - // Get the common part of the response and verify that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - NotesCommon noteCommon = null; - if (payloadInputPart != null) { - noteCommon = (NotesCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(noteCommon); - - // Update the common part, both the subitem, and the content - noteCommon.setContent("updated-" + noteCommon.getContent()); - noteCommon.setOrder(noteCommon.getOrder()+10); - if(logger.isDebugEnabled()){ - logger.debug("to be updated object"); - logger.debug(objectAsXmlString(noteCommon, NotesCommon.class)); - } - - // Submit the common part in an update request to the service - // and store the response. - PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(noteCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - - // Check the status code of the response: does it match the expected response(s)? - int statusCode = res.getStatus(); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Extract the updated common part from the response. - payloadInputPart = input.getPart(client.getCommonPartName()); - NotesCommon updatedNoteCommon = null; - if (payloadInputPart != null) { - updatedNoteCommon = (NotesCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(updatedNoteCommon); - - // Check selected fields in the updated common part. - Assert.assertEquals(updatedNoteCommon.getContent(), noteCommon.getContent(), - "Data in updated object did not match submitted data."); - Assert.assertEquals(updatedNoteCommon.getOrder(), noteCommon.getOrder(), - "Data in updated object (subitem) did not match submitted data."); - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty?? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty?? - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty?? - } - - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - NoteClient client = new NoteClient(); - PoxPayloadOut multipart = - NoteClientUtils.createNoteInstance( - NON_EXISTENT_ID, NON_EXISTENT_ID, client.getCommonPartName()); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - NoteClient client = new NoteClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - // Failure outcomes - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - NoteClient client = new NoteClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // Search tests - // --------------------------------------------------------------- + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = + NoteClientUtils.createNoteInstance("owner"+identifier, identifier, + commonPartName); + return result; + } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void searchWorkflowDeleted(String testName) throws Exception { - // Fixme: null test for now, overriding test in base class - } - // --------------------------------------------------------------- // Utility tests : tests of code used in tests above // --------------------------------------------------------------- @@ -460,31 +74,6 @@ public class NoteServiceTest extends AbstractServiceTestImpl { return SERVICE_NAME; } - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testSubmitRequest: url=" + url + - " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -492,5 +81,36 @@ public class NoteServiceTest extends AbstractServiceTestImpl { public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } + + @Override + protected Class getCommonListType() { + return NotesCommonList.class; + } + @Override + protected NotesCommon updateInstance(NotesCommon notesCommon) { + NotesCommon result = new NotesCommon(); + + // Update the common part, both the subitem, and the content + result.setContent("updated-" + notesCommon.getContent()); + result.setOrder(notesCommon.getOrder() + 10); + + return result; + } + + @Override + protected void compareUpdatedInstances(NotesCommon original, + NotesCommon updated) throws Exception { + // Check selected fields in the updated common part. + Assert.assertEquals(updated.getContent(), original.getContent(), + "Content in updated object did not match submitted data."); + Assert.assertEquals(updated.getOrder(), original.getOrder(), + "Order in updated object (subitem) did not match submitted data."); + } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } } diff --git a/services/note/jaxb/pom.xml b/services/note/jaxb/pom.xml index 36f21a19c..417d7d003 100644 --- a/services/note/jaxb/pom.xml +++ b/services/note/jaxb/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.note.jaxb services.note.jaxb @@ -19,6 +18,11 @@ org.collectionspace.services.jaxb ${project.version} + + org.collectionspace.services + org.collectionspace.services.hyperjaxb + ${project.version} + diff --git a/services/note/jaxb/src/main/resources/notes-common.xsd b/services/note/jaxb/src/main/resources/notes-common.xsd index 9511c6b4e..aa01369f2 100644 --- a/services/note/jaxb/src/main/resources/notes-common.xsd +++ b/services/note/jaxb/src/main/resources/notes-common.xsd @@ -1,88 +1,74 @@ - - $LastChangedRevision: 1929 $ - $LastChangedDate: 2010-04-28 01:50:27 -0700 (Wed, 28 Apr 2010) $ ---> + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/services/note/service/pom.xml b/services/note/service/pom.xml index c55dff8ce..ece15b7a0 100644 --- a/services/note/service/pom.xml +++ b/services/note/service/pom.xml @@ -32,7 +32,6 @@ org.testng testng - 5.6 diff --git a/services/objectexit/client/pom.xml b/services/objectexit/client/pom.xml index 7967328d3..fafa40ba5 100644 --- a/services/objectexit/client/pom.xml +++ b/services/objectexit/client/pom.xml @@ -62,7 +62,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java index 6f55f6b10..92529ab89 100644 --- a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java @@ -32,7 +32,6 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; import org.collectionspace.services.client.CollectionSpaceClient; -import org.collectionspace.services.client.ContactClient; import org.collectionspace.services.client.ObjectExitClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PersonAuthorityClient; @@ -46,7 +45,6 @@ import org.collectionspace.services.objectexit.ObjectexitCommon; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -59,12 +57,11 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class ObjectExitAuthRefsTest extends BaseServiceTest { +public class ObjectExitAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = ObjectExitAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); final String PERSON_AUTHORITY_NAME = "ObjectexitPersonAuth"; - private String knownResourceId = null; private List objectexitIdsCreated = new ArrayList(); private List personIdsCreated = new ArrayList(); private String personAuthCSID = null; @@ -90,7 +87,7 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { } @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -104,15 +101,14 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { objectexit.setExitDate(exitDate); PoxPayloadOut multipart = new PoxPayloadOut(ObjectExitClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(objectexit, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new ObjectExitClient().getCommonPartName()); + PayloadOutputPart commonPart = multipart.addPart(new ObjectExitClient().getCommonPartName(), + objectexit); logger.debug("to be created, objectexit common: " + objectAsXmlString(objectexit, ObjectexitCommon.class)); return multipart; } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void createWithAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); testSetup(STATUS_CREATED, ServiceRequestType.CREATE); String identifier = createIdentifier(); // Submit the request to the service and store the response. createPersonRefs();// Create all the person refs and entities @@ -122,9 +118,15 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { PoxPayloadOut multipart = createObjectExitInstance(depositorRefName, "exitNumber-" + identifier, CURRENT_DATE_UTC); ClientResponse res = objectexitClient.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. - knownResourceId = extractId(res); + try { + assertStatusCode(res, testName); + if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. + knownResourceId = extractId(res); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } objectexitIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup } @@ -134,8 +136,14 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { // Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified. PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); - assertStatusCode(res, "createPersonRefs (not a surefire test)"); - personAuthCSID = extractId(res); + try { + assertStatusCode(res, "createPersonRefs (not a surefire test)"); + personAuthCSID = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } + } String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); // Create temporary Person resources, and their corresponding refNames by which they can be identified. String csid = ""; @@ -150,6 +158,8 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { } protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -157,21 +167,36 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); - assertStatusCode(res, "createPerson (not a surefire test)"); - return extractId(res); + try { + assertStatusCode(res, "createPerson (not a surefire test)"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + + return result; } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); testSetup(STATUS_OK, ServiceRequestType.READ); ObjectExitClient objectexitClient = new ObjectExitClient(); ClientResponse res = objectexitClient.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ObjectexitCommon objectexit = (ObjectexitCommon) extractPart(input, objectexitClient.getCommonPartName(), ObjectexitCommon.class); - Assert.assertNotNull(objectexit); - logger.debug(objectAsXmlString(objectexit, ObjectexitCommon.class)); + ObjectexitCommon objectexit = null; + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + objectexit = (ObjectexitCommon) extractPart(input, objectexitClient.getCommonPartName(), ObjectexitCommon.class); + Assert.assertNotNull(objectexit); + logger.debug(objectAsXmlString(objectexit, ObjectexitCommon.class)); + } finally { + if (res != null) { + res.releaseConnection(); + } + } // Check a couple of fields Assert.assertEquals(objectexit.getDepositor(), depositorRefName); @@ -179,8 +204,15 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { // Get the auth refs and check them ClientResponse res2 = objectexitClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - AuthorityRefList list = res2.getEntity(); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); logger.debug("Authority references, found " + numAuthRefsFound); @@ -233,4 +265,10 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest { } } + @Override + protected Class getCommonListType() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java index c0d4c21b9..66728a064 100644 --- a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java @@ -25,12 +25,12 @@ package org.collectionspace.services.client.test; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.ObjectExitClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.objectexit.ObjectexitCommon; @@ -41,20 +41,18 @@ import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -//import org.w3c.dom.Element; -//import org.w3c.dom.Node; + /** * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service.

* $LastChangedRevision: $ * $LastChangedDate: $ */ -public class ObjectExitServiceTest extends AbstractServiceTestImpl { +public class ObjectExitServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = ObjectExitServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); final String SERVICE_PATH_COMPONENT = "objectexit"; - private String knownResourceId = null; @Override public String getServicePathComponent() { @@ -72,185 +70,10 @@ public class ObjectExitServiceTest extends AbstractServiceTestImpl { } @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(ClientResponse response) { return response.getEntity(AbstractCommonList.class); } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupCreate(); - ObjectExitClient client = new ObjectExitClient(); - PoxPayloadOut multipart = createObjectExitInstance(createIdentifier()); - ClientResponse res = client.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) { - knownResourceId = extractId(res); // Store the ID returned from the first resource created for additional tests below. - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run. - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - for (int i = 0; i < 3; i++) { - create(testName); - } - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupRead(); - ObjectExitClient client = new ObjectExitClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ObjectexitCommon objectexit = (ObjectexitCommon) extractPart(input, client.getCommonPartName(), ObjectexitCommon.class); - Assert.assertNotNull(objectexit); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadList(); - ObjectExitClient client = new ObjectExitClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - String bar = "\r\n\r\n=================================\r\n\r\n"; - System.out.println(bar+" res: "+res); - AbstractCommonList list = res.getEntity(); - System.out.println(bar+" list: "+list); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if(iterateThroughList && logger.isDebugEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdate(); - ObjectExitClient client = new ObjectExitClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - logger.debug("got object to update with ID: " + knownResourceId); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ObjectexitCommon objectexit = (ObjectexitCommon) extractPart(input, client.getCommonPartName(), ObjectexitCommon.class); - Assert.assertNotNull(objectexit); - - objectexit.setExitNumber("updated-" + objectexit.getExitNumber()); - logger.debug("Object to be updated:"+objectAsXmlString(objectexit, ObjectexitCommon.class)); - PoxPayloadOut output = new PoxPayloadOut(ObjectExitClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(objectexit, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); - ObjectexitCommon updatedObjectExit = (ObjectexitCommon) extractPart(input, client.getCommonPartName(), ObjectexitCommon.class); - Assert.assertNotNull(updatedObjectExit); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - ObjectExitClient client = new ObjectExitClient(); - PoxPayloadOut multipart = createObjectExitInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - assertStatusCode(res, testName); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDelete(); - ObjectExitClient client = new ObjectExitClient(); - ClientResponse res = client.delete(knownResourceId); - assertStatusCode(res, testName); - } - - // --------------------------------------------------------------- - // Failure outcome tests : means we expect response to fail, but test to succeed - // --------------------------------------------------------------- - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadNonExistent(); - ObjectExitClient client = new ObjectExitClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcome - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDeleteNonExistent(); - ObjectExitClient client = new ObjectExitClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcomes - // Placeholders until the tests below can be implemented. See Issue CSPACE-401. - - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - } - - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode); - Assert.assertEquals(statusCode, EXPECTED_STATUS); - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -277,4 +100,31 @@ public class ObjectExitServiceTest extends AbstractServiceTestImpl { return multipart; } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = createObjectExitInstance(createIdentifier()); + return result; + } + + @Override + protected ObjectexitCommon updateInstance(ObjectexitCommon objectexitCommon) { + ObjectexitCommon result = new ObjectexitCommon(); + + result.setExitNumber("updated-" + objectexitCommon.getExitNumber()); + + return result; + } + + @Override + protected void compareUpdatedInstances(ObjectexitCommon original, + ObjectexitCommon updated) throws Exception { + Assert.assertEquals(updated.getExitNumber(), original.getExitNumber()); + } } diff --git a/services/objectexit/service/pom.xml b/services/objectexit/service/pom.xml index cd6b1e0b1..a0e0a1eff 100644 --- a/services/objectexit/service/pom.xml +++ b/services/objectexit/service/pom.xml @@ -44,7 +44,6 @@ org.testng testng - 5.6 diff --git a/services/organization/client/pom.xml b/services/organization/client/pom.xml index 87d9e4641..ba8bfbc3c 100644 --- a/services/organization/client/pom.xml +++ b/services/organization/client/pom.xml @@ -56,7 +56,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java index 56b375bc3..45e13eebb 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java @@ -26,10 +26,12 @@ */ package org.collectionspace.services.client; +import org.collectionspace.services.organization.OrganizationsCommon; + /** * The Class OrgAuthorityClient. */ -public class OrgAuthorityClient extends AuthorityWithContactsClientImpl { +public class OrgAuthorityClient extends AuthorityWithContactsClientImpl { public static final String SERVICE_NAME = "orgauthorities"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -66,4 +68,14 @@ public class OrgAuthorityClient extends AuthorityWithContactsClientImpl { /** The logger. */ private final String CLASS_NAME = OrgAuthorityAuthRefsTest.class.getName(); @@ -80,19 +80,10 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { return OrgAuthorityClient.SERVICE_NAME; } - private String knownResourceId = null; + protected String knownItemResourceId = null; + private String knownResourceRefName = null; - - /** The known item id. */ - private String knownItemResourceId = null; - - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); - - /** The all item resource ids created. */ - private Map allItemResourceIdsCreated = - new HashMap(); - + /** The person ids created. */ private List personIdsCreated = new ArrayList(); @@ -128,7 +119,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -143,12 +134,8 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + @Test(dataProvider="testName") public void createWithAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Create a new Organization Authority resource. @@ -173,9 +160,9 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the IDs from every resource created by tests, // so they can be deleted after tests have been run. @@ -228,7 +215,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // Store the IDs from every item created by tests, // so they can be deleted after tests have been run. - allItemResourceIdsCreated.put(knownItemResourceId, knownResourceId); + allResourceItemIdsCreated.put(knownItemResourceId, knownResourceId); } /** @@ -244,8 +231,8 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { ClientResponse res = personAuthClient.create(multipart); try { int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); } finally { @@ -291,8 +278,8 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { try { int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); result = extractId(res); } finally { @@ -310,7 +297,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // Organization authority as its parent Organization resource. String subBodyResourceId = createSubBodyOrganization("Test SubBody Organization"); - allItemResourceIdsCreated.put(subBodyResourceId, knownResourceId); + allResourceItemIdsCreated.put(subBodyResourceId, knownResourceId); subBodyRefName = OrgAuthorityClientUtils.getOrgRefName(knownResourceId, subBodyResourceId, null); } @@ -331,8 +318,8 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { ClientResponse res = orgAuthClient.createItem(knownResourceId, multipart); try { int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); result = extractId(res); } finally { @@ -349,28 +336,29 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. testSetup(STATUS_OK, ServiceRequestType.READ); // Submit the request to the service and store the response. OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); - ClientResponse res = - orgAuthClient.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - orgAuthClient.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - if(logger.isDebugEnabled()){ - logger.debug(objectAsXmlString(organization, OrganizationsCommon.class)); + ClientResponse res = orgAuthClient.readItem(knownResourceId, knownItemResourceId); + OrganizationsCommon organization = null; + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + organization = (OrganizationsCommon) extractPart(input, + orgAuthClient.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + if (logger.isDebugEnabled()){ + logger.debug(objectAsXmlString(organization, OrganizationsCommon.class)); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } // Check one or more of the authority fields in the Organization item Assert.assertEquals(organization.getContactNames().getContactName().get(0), @@ -385,9 +373,15 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // and get the ID for the organization item ClientResponse res2 = orgAuthClient.getItemAuthorityRefs(knownResourceId, knownItemResourceId); - assertStatusCode(res2, testName); - - AuthorityRefList list = res2.getEntity(); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.getEntity(); + } finally { + if (res2 != null) { + res2.releaseConnection(); + } + } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); @@ -456,7 +450,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { String itemResourceId; OrgAuthorityClient client = new OrgAuthorityClient(); // Clean up item resources. - for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { itemResourceId = entry.getKey(); parentResourceId = entry.getValue(); // Note: Any non-success responses from the delete operation diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java index 225af8b9f..fde3af062 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -30,6 +30,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.OrganizationJAXBSchema; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.ContactClient; @@ -37,7 +38,6 @@ import org.collectionspace.services.client.ContactClientUtils; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.contact.AddressGroup; import org.collectionspace.services.contact.AddressGroupList; import org.collectionspace.services.contact.ContactsCommon; @@ -64,7 +64,7 @@ import org.testng.annotations.Test; * $LastChangedRevision$ * $LastChangedDate$ */ -public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class! +public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest { /** The logger. */ private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName(); @@ -83,32 +83,19 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: } /** The test organization shortname. */ private final String TEST_ORG_SHORTNAME = "Test Org"; + /** The test organization founding place. */ private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA"; - // Hold some values for a recently created item to verify upon read. - private String knownResourceId = null; - private String knownResourceShortIdentifer = null; - private String knownResourceRefName = null; - private String knownItemResourceId = null; + private String knownItemResourceShortIdentifer = null; + /** The known contact resource id. */ private String knownContactResourceId = null; - /** The n items to create in list. */ - private int nItemsToCreateInList = 3; - /** The all item resource ids created. */ - private Map allItemResourceIdsCreated = - new HashMap(); + /** The all contact resource ids created. */ private Map allContactResourceIdsCreated = new HashMap(); - 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; @@ -122,70 +109,6 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: return new OrgAuthorityClient(); } - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create"}) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - String shortId = createIdentifier(); - String displayName = "displayName-" + shortId; - //String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null); - PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - displayName, shortId, client.getCommonPartName()); - - String newID = null; - ClientResponse 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - newID = OrgAuthorityClientUtils.extractId(res); - } finally { - res.releaseConnection(); - } - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null) { - setKnownResource(newID, shortId, null ); //baseRefName); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(newID); - } - @Override protected PoxPayloadOut createInstance(String identifier) { OrgAuthorityClient client = new OrgAuthorityClient(); @@ -209,18 +132,6 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel); } - /** - * Creates the item. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) - public void createItem(String testName) { - setupCreate(); - String newID = createItemInAuthority(knownResourceId, knownResourceRefName); - } - /** * Creates the item in authority. * @@ -273,7 +184,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Store the IDs from any item resources created // by tests, along with the IDs of their parents, so these items // can be deleted after all tests have been run. - allItemResourceIdsCreated.put(newID, vcsid); + allResourceItemIdsCreated.put(newID, vcsid); return newID; } @@ -283,8 +194,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * * @param testName the test name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"createItem"}) + @Test(dataProvider = "testName", groups = {"create"}, + dependsOnMethods = {"createItem"}) public void createContact(String testName) { setupCreate(); String newID = createContactInItem(knownResourceId, knownItemResourceId); @@ -301,7 +212,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: final String testName = "createContactInItem"; if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + logger.debug(getTestBanner(testName, CLASS_NAME)); } setupCreate(); @@ -316,19 +227,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: ClientResponse res = client.createContact(parentcsid, itemcsid, 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); - + assertStatusCode(res, testName); newID = OrgAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the ID returned from the first contact resource created @@ -348,160 +252,14 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: return newID; } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()) { - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - // --------------------------------------------------------------- - // CRUD tests : CREATE LIST tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Override - @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); - } - } - - /** - * Creates the item list. - * - * @param testName the test name - * @throws Exception the exception - */ - @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++) { - createItem(testName); - } - } - /** * Creates the contact list. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnMethods = {"createItemList"}) + @Test(dataProvider = "testName", groups = {"createList"}, + dependsOnMethods = {"createItemList"}) public void createContactList(String testName) throws Exception { // Add contacts to the initially-created, known item record. for (int j = 0; j < nItemsToCreateInList; j++) { @@ -517,8 +275,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @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 { readInternal(testName, knownResourceId, null); } @@ -529,17 +287,13 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnGroups = {"create"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// groups = {"read"}, dependsOnGroups = {"create"}) public void readByName(String testName) throws Exception { readInternal(testName, null, knownResourceShortIdentifer); } protected void readInternal(String testName, String CSID, String shortId) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); @@ -553,8 +307,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: } else { Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); } - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); //FIXME: remove the following try catch once Aron fixes signatures try { PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); @@ -568,22 +322,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: throw new RuntimeException(e); } } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } - /** - * Read item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) - public void readItem(String testName) throws Exception { - readItemInternal(testName, knownResourceId, null, knownItemResourceId, null); - } - /** * Read item in Named Auth. * @@ -598,17 +342,30 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); } */ + /** * Read named item. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readItemInNamedAuth"}) public void readNamedItem(String testName) throws Exception { readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer); } + + /** + * Read item in Named Auth. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readItem"}) + public void readItemInNamedAuth(String testName) throws Exception { + readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); + } /** * Read Named item in Named Auth. @@ -616,8 +373,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readItem"}) public void readNamedItemInNamedAuth(String testName) throws Exception { readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer); } @@ -625,10 +382,6 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: protected void readItemInternal(String testName, String authCSID, String authShortId, String itemCSID, String itemShortId) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); @@ -654,8 +407,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: } else { Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null"); } - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Check whether we've received a organization. PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, @@ -677,9 +430,18 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Assert.assertNotNull(contactNames.get(0)); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } + + @Override + protected void verifyReadItemInstance(OrganizationsCommon item) throws Exception { + List contactNames = item.getContactNames().getContactName(); + Assert.assertTrue(contactNames.size() > 0); + Assert.assertNotNull(contactNames.get(0)); + } /** * Verify item display name. @@ -687,25 +449,26 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem", "updateItem"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"}) public void verifyItemDisplayName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. - setupUpdate(); - - // Submit the request to the service and store the response. + setupRead(); + // + // First, read our known resource. + // OrgAuthorityClient client = new OrgAuthorityClient(); PoxPayloadIn input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); + // Check whether organization has expected displayName. input = new PoxPayloadIn(res.getEntity()); + Assert.assertNotNull(input); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Check whether organization has expected displayName. @@ -728,26 +491,32 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: MainBodyGroup mainBodyGroup = new MainBodyGroup(); String updatedShortName = "updated-" + TEST_ORG_SHORTNAME; mainBodyGroup.setShortName(updatedShortName); + mainBodyGroups.clear(); //clear all the elements and do a sparse update mainBodyGroups.add(mainBodyGroup); organization.setMainBodyGroupList(mainBodyList); expectedDisplayName = OrgAuthorityClientUtils.prepareDefaultDisplayName( updatedShortName, TEST_ORG_FOUNDING_PLACE); - - // Submit the updated resource to the service and store the response. + // + // Next, submit the updated resource to the service and store the response. + // + setupUpdate(); PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), organization); res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - + // + // Now verify the update was correct. + // OrganizationsCommon updatedOrganization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); @@ -763,25 +532,27 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName, "Updated ShortName in Organization not reflected in computed DisplayName."); - + // // Now Update the displayName, not computed and verify the computed name is overriden. + // organization.setDisplayNameComputed(false); expectedDisplayName = "TestName"; organization.setDisplayName(expectedDisplayName); // Submit the updated resource to the service and store the response. output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); + commonPart = output.addPart(client.getItemCommonPartName(), organization); res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); + input = null; try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - updatedOrganization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); @@ -802,43 +573,47 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"verifyItemDisplayName"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"verifyItemDisplayName"}) public void verifyIllegalItemDisplayName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup for read. setupRead(); - - // Submit the request to the service and store the response. + // + // First read our known resource. + // OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - // Perform setup for update. - testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE); - + OrganizationsCommon organization = null; try { + assertStatusCode(res, testName); // Check whether organization has expected displayName. PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + organization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); Assert.assertNotNull(organization); - // Try to Update with computed false and no displayName - organization.setDisplayNameComputed(false); - organization.setDisplayName(null); - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - } finally { - res.releaseConnection(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + // + // Try to Update with 'displayNameComputed' flag set to false and no displayName + // + organization.setDisplayNameComputed(false); + organization.setDisplayName(null); + + setupUpdateWithInvalidBody(); // we expect a failure + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), + organization); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } } @@ -848,13 +623,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readItem"}) public void readContact(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); @@ -863,8 +634,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Check whether we've received a contact. PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); ContactsCommon contact = (ContactsCommon) extractPart(input, @@ -878,28 +649,27 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Assert.assertEquals(contact.getInAuthority(), knownResourceId); Assert.assertEquals(contact.getInItem(), knownItemResourceId); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + /** + * Read contact non existent. + * + * @param testName the test name */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readContact"}) + public void readContactNonExistent(String testName) { // Perform setup. setupReadNonExistent(); // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); + ClientResponse res = + client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -908,148 +678,46 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } /** - * Read item non existent. - * - * @param testName the test name + * Read item list. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) - public void readItemNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = client.readItem(knownResourceId, NON_EXISTENT_ID); - try { - int statusCode = res.getStatus(); + @Override +// @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) + public void readItemList(String testName) { + readItemList(knownAuthorityWithItems, null); + } - // 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(); - } + /** + * Read item list by authority name. + */ + @Override +// @Test(dataProvider = "testName", +// dependsOnMethods = {"readItem"}) + public void readItemListByName(String testName) { + readItemList(null, READITEMS_SHORT_IDENTIFIER); } /** - * Read contact non existent. + * Read item list. * - * @param testName the test name + * @param vcsid the vcsid + * @param name the name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readContact"}) - public void readContactNonExistent(String testName) { + private void readItemList(String vcsid, String name) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } + final String testName = "readItemList"; // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = - client.readContact(knownResourceId, knownItemResourceId, 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(); - } - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnGroups = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - try { - AbstractCommonList list = res.getEntity(); - // Optionally output additional data about list members for debugging. - if (logger.isTraceEnabled()) { - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } finally { - res.releaseConnection(); - } - } - - /** - * Read item list. - */ - @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) - public void readItemList() { - readItemList(knownResourceId, null); - } - - /** - * Read item list by authority name. - */ - @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) - public void readItemListByAuthorityName() { - readItemList(null, knownResourceShortIdentifer); - } - - /** - * Read item list. - * - * @param vcsid the vcsid - * @param name the name - */ - private void readItemList(String vcsid, String name) { - - final String testName = "readItemList"; - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); + setupReadList(); // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); @@ -1061,45 +729,47 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: } else { Assert.fail("readItemList passed null csid and name!"); } - assertStatusCode(res, testName); + + AbstractCommonList list = null; try { - AbstractCommonList list = res.getEntity(); - List items = - list.getListItem(); - 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); - - for (AbstractCommonList.ListItem item : items) { - String value = - AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME); - Assert.assertTrue((null != value), "Item refName is null!"); - value = - AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME); - Assert.assertTrue((null != value), "Item displayName is null!"); - } - if (logger.isTraceEnabled()) { - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } + assertStatusCode(res, testName); + list = res.getEntity(); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } + } + + List 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, REFNAME); + Assert.assertTrue((null != value), "Item refName is null!"); + value = + AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME); + Assert.assertTrue((null != value), "Item displayName is null!"); + } + if (logger.isTraceEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } /** * Read contact list. */ - @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) + @Test(groups = {"readList"}, + dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItemList"}) public void readContactList() { readContactList(knownResourceId, knownItemResourceId); } @@ -1112,185 +782,43 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ private void readContactList(String parentcsid, String itemcsid) { final String testName = "readContactList"; - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); - AbstractCommonList list = null; ClientResponse res = client.readContactList(parentcsid, itemcsid); - assertStatusCode(res, testName); + AbstractCommonList list = null; try { + assertStatusCode(res, testName); list = res.getEntity(); - - List listitems = - list.getListItem(); - int nItemsReturned = listitems.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); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } } finally { - res.releaseConnection(); - } - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnGroups = {"read", "readList"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = - client.read(knownResourceId); - assertStatusCode(res, testName); - try { - if (logger.isDebugEnabled()) { - logger.debug("got OrgAuthority to update with ID: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - - // Update the contents of this resource. - orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName()); - orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType()); - if (logger.isDebugEnabled()) { - logger.debug("to be updated OrgAuthority"); - logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); + if (res != null) { + res.releaseConnection(); } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res.releaseConnection(); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - OrgauthoritiesCommon updatedOrgAuthority = - (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(updatedOrgAuthority); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedOrgAuthority.getDisplayName(), - orgAuthority.getDisplayName(), - "Data in updated object did not match submitted data."); - } finally { - res.releaseConnection(); } - } - - /** - * Update item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update"}) - public void updateItem(String testName) throws Exception { + List listitems = + list.getListItem(); + int nItemsReturned = listitems.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(testBanner(testName, CLASS_NAME)); + logger.debug(testName + ": Expected " + + nExpectedItems + " items; got: " + nItemsReturned); } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = - client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - try { - if (logger.isDebugEnabled()) { - logger.debug("got Organization to update with ID: " - + knownItemResourceId - + " in OrgAuthority: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - - // Update the contents of this resource. - organization.setCsid(null); + Assert.assertEquals(nItemsReturned, nExpectedItems); - MainBodyGroupList mainBodyList = organization.getMainBodyGroupList(); - Assert.assertNotNull(mainBodyList); - List mainBodyGroups = mainBodyList.getMainBodyGroup(); - Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); - String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName(); - mainBodyGroups.get(0).setShortName(updatedShortName); - - if (logger.isDebugEnabled()) { - logger.debug("to be updated Organization"); - logger.debug(objectAsXmlString(organization, - OrganizationsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res.releaseConnection(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon updatedOrganization = - (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(updatedOrganization); - - // Verify that the updated resource received the correct data. - mainBodyList = organization.getMainBodyGroupList(); - Assert.assertNotNull(mainBodyList); - Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); - Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), - updatedShortName, "Data in updated Organization did not match submitted data."); - } finally { - res.releaseConnection(); + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } @@ -1300,13 +828,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem"}) + @Test(dataProvider = "testName", groups = {"update"}, + dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"}) public void updateContact(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupUpdate(); @@ -1314,8 +838,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - assertStatusCode(res, testName); + ContactsCommon contact = null; try { + assertStatusCode(res, testName); if (logger.isDebugEnabled()) { logger.debug("got Contact to update with ID: " + knownContactResourceId @@ -1323,247 +848,56 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: + " in parent: " + knownResourceId); } PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ContactsCommon contact = (ContactsCommon) extractPart(input, + contact = (ContactsCommon) extractPart(input, new ContactClient().getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); - - // Verify the contents of this resource - AddressGroupList addressGroupList = contact.getAddressGroupList(); - Assert.assertNotNull(addressGroupList); - List addressGroups = addressGroupList.getAddressGroup(); - Assert.assertNotNull(addressGroups); - Assert.assertTrue(addressGroups.size() > 0); - String addressPlace1 = addressGroups.get(0).getAddressPlace1(); - Assert.assertNotNull(addressPlace1); - - // Update the contents of this resource. - addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1); - contact.setAddressGroupList(addressGroupList); - if (logger.isDebugEnabled()) { - logger.debug("to be updated Contact"); - logger.debug(objectAsXmlString(contact, - ContactsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new ContactClient().getCommonPartName()); - res.releaseConnection(); - res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - ContactsCommon updatedContact = - (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(updatedContact); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), - contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), - "Data in updated object did not match submitted data."); - } finally { - res.releaseConnection(); - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateWithWrongXmlSchema(String testName) throws Exception { - - // Perform setup. - setupUpdateWithWrongXmlSchema(testName, logger); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateWithWrongXmlSchema: url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - - /* (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"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - OrgAuthorityClient client = new OrgAuthorityClient(); - PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - NON_EXISTENT_ID, NON_EXISTENT_ID, - new OrgAuthorityClient().getCommonPartName()); - ClientResponse 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); + if (res != null) { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } finally { - res.releaseConnection(); } - } - /** - * Update non existent item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) - public void updateNonExistentItem(String testName) throws Exception { + // Verify the contents of this resource + AddressGroupList addressGroupList = contact.getAddressGroupList(); + Assert.assertNotNull(addressGroupList); + List addressGroups = addressGroupList.getAddressGroup(); + Assert.assertNotNull(addressGroups); + Assert.assertTrue(addressGroups.size() > 0); + String addressPlace1 = addressGroups.get(0).getAddressPlace1(); + Assert.assertNotNull(addressPlace1); + // Update the contents of this resource. + addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1); + contact.setAddressGroupList(addressGroupList); if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + logger.debug("to be updated Contact"); + logger.debug(objectAsXmlString(contact, + ContactsCommon.class)); } - // Perform setup. - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID(s) used when creating the request payload may be arbitrary. - // The only relevant ID may be the one used in update(), below. - OrgAuthorityClient client = new OrgAuthorityClient(); - Map nonexOrgMap = new HashMap(); - nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent"); - nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent"); - PoxPayloadOut multipart = - OrgAuthorityClientUtils.createOrganizationInstance( - knownResourceRefName, - nonexOrgMap, client.getItemCommonPartName()); - ClientResponse res = - client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); - try { - int statusCode = res.getStatus(); + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new ContactClient().getCommonPartName()); - // 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); + res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); + try { + assertStatusCode(res, testName); + // Retrieve the updated resource and verify that its contents exist. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + ContactsCommon updatedContact = + (ContactsCommon) extractPart(input, + new ContactClient().getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(updatedContact); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), + contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), + "Data in updated object did not match submitted data."); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -1573,8 +907,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) + @Test(dataProvider = "testName", groups = {"update"}, + dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) public void updateNonExistentContact(String testName) throws Exception { // Currently a no-op test } @@ -1591,13 +925,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"}) + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"updateContact"}) public void deleteContact(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDelete(); @@ -1612,178 +942,44 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); 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); + assertStatusCode(res, testName); } finally { - res.releaseConnection(); - } - } - - /** - * Delete item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) - public void deleteItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if (logger.isDebugEnabled()) { - logger.debug("parentcsid =" + knownResourceId - + " itemcsid = " + knownItemResourceId); - } - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse 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); + if (res != null) { + res.releaseConnection(); } - 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"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if (logger.isDebugEnabled()) { - logger.debug("parentcsid =" + knownResourceId); - } - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse 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(); - } + // Do nothing. See localDelete(). This ensure proper test order. } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse 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(); - } + + @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } - /** - * Delete non existent item. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) - public void deleteNonExistentItem(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse 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(); - } + @Override + public void deleteItem(String testName) throws Exception { + // Do nothing. We need to wait until after the test "localDelete" gets run. When it does, + // its dependencies will get run first and then we can call the base class' delete method. } - + + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"verifyIllegalItemDisplayName", "testContactSubmitRequest", "deleteContact"}) + public void localDeleteItem(String testName) throws Exception { + super.deleteItem(testName); + } + /** * Delete non existent contact. * * @param testName the test name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"deleteContact"}) public void deleteNonExistentContact(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDeleteNonExistent(); @@ -1792,71 +988,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, 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); + assertStatusCode(res, testName); } finally { - res.releaseConnection(); - } - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - - /** - * Test item submit request. - */ - @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) - public void testItemSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getItemResourceURL(knownResourceId, knownItemResourceId); - int statusCode = submitRequest(method, url); - - // 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 (res != null) { + res.releaseConnection(); + } } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - } /** @@ -1877,7 +1014,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Check the status code of the response: does it match // the expected response(s)? if (logger.isDebugEnabled()) { - logger.debug("testItemSubmitRequest: url=" + url + logger.debug("testContactSubmitRequest: url=" + url + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); @@ -1925,7 +1062,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: res.releaseConnection(); } // Clean up item resources. - for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { itemResourceId = entry.getKey(); parentResourceId = entry.getValue(); // Note: Any non-success responses from the delete operation @@ -2034,4 +1171,93 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: return getContactServiceRootURL(parentResourceIdentifier, itemResourceIdentifier) + "/" + contactResourceIdentifier; } + + @Override + public void authorityTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected String createItemInAuthority(String authorityId) { + return createItemInAuthority(authorityId, null /*refname*/); + } + + @Override + protected OrganizationsCommon updateItemInstance(OrganizationsCommon organizationsCommon) { + OrganizationsCommon result = organizationsCommon; //new OrganizationsCommon(); + + MainBodyGroupList mainBodyList = organizationsCommon.getMainBodyGroupList(); + Assert.assertNotNull(mainBodyList); + List mainBodyGroups = mainBodyList.getMainBodyGroup(); + Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); + String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName(); + mainBodyGroups.get(0).setShortName(updatedShortName); + + return result; + } + + @Override + protected void compareUpdatedItemInstances(OrganizationsCommon original, + OrganizationsCommon updated) throws Exception { + MainBodyGroupList mainBodyList = original.getMainBodyGroupList(); + Assert.assertNotNull(mainBodyList); + Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); + Assert.assertEquals(updated.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), + original.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), + "Short name in updated Organization did not match submitted data."); + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + String shortId = identifier; + String displayName = "displayName-" + shortId; + //String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null); + PoxPayloadOut result = OrgAuthorityClientUtils.createOrgAuthorityInstance( + displayName, shortId, commonPartName); + return result; + } + + @Override + protected PoxPayloadOut createNonExistenceInstance(String commonPartName, + String identifier) { + String shortId = identifier; + String displayName = "displayName-" + shortId; + //String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null); + PoxPayloadOut result = OrgAuthorityClientUtils.createOrgAuthorityInstance( + displayName, shortId, commonPartName); + return result; + } + + protected PoxPayloadOut createNonExistenceItemInstance(String commonPartName, + String identifier) { + Map nonexOrgMap = new HashMap(); + nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent"); + nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent"); + PoxPayloadOut result = + OrgAuthorityClientUtils.createOrganizationInstance( + knownResourceRefName, + nonexOrgMap, commonPartName); + return result; + } + + @Override + protected OrgauthoritiesCommon updateInstance(OrgauthoritiesCommon orgauthoritiesCommon) { + OrgauthoritiesCommon result = new OrgauthoritiesCommon(); + + result.setDisplayName("updated-" + orgauthoritiesCommon.getDisplayName()); + result.setVocabType("updated-" + orgauthoritiesCommon.getVocabType()); + + return result; + } + + @Override + protected void compareUpdatedInstances(OrgauthoritiesCommon original, + OrgauthoritiesCommon updated) throws Exception { + // Verify that the updated resource received the correct data. + Assert.assertEquals(updated.getDisplayName(), + original.getDisplayName(), + "Display name in updated object did not match submitted data."); + } } diff --git a/services/organization/service/pom.xml b/services/organization/service/pom.xml index c63d5f265..4208e044d 100644 --- a/services/organization/service/pom.xml +++ b/services/organization/service/pom.xml @@ -58,7 +58,6 @@ org.testng testng - 5.6 diff --git a/services/person/client/pom.xml b/services/person/client/pom.xml index 2fbf49c94..024a82e26 100644 --- a/services/person/client/pom.xml +++ b/services/person/client/pom.xml @@ -59,7 +59,6 @@ org.testng testng - 5.6 diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java index fe728bfd8..7a06e57e3 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java @@ -26,10 +26,12 @@ */ package org.collectionspace.services.client; +import org.collectionspace.services.person.PersonsCommon; + /** * The Class PersonAuthorityClient. */ -public class PersonAuthorityClient extends AuthorityWithContactsClientImpl { +public class PersonAuthorityClient extends AuthorityWithContactsClientImpl { public static final String SERVICE_NAME = "personauthorities"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -71,4 +73,14 @@ public class PersonAuthorityClient extends AuthorityWithContactsClientImpl getProxyClass() { return PersonAuthorityProxy.class; } + + @Override + public String getInAuthority(PersonsCommon item) { + return item.getInAuthority(); + } + + @Override + public void setInAuthority(PersonsCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } } diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java index 9a9e51637..226cf33ac 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java @@ -22,10 +22,8 @@ */ package org.collectionspace.services.client.test; -import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -53,7 +51,7 @@ import org.testng.annotations.Test; * $LastChangedRevision: 753 $ * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ */ -public class PersonAuthoritySearchTest extends BaseServiceTest { +public class PersonAuthoritySearchTest extends BaseServiceTest { private final String CLASS_NAME = PersonAuthoritySearchTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -157,7 +155,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { return response.getEntity(AbstractCommonList.class); } @@ -225,12 +223,8 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { /** * Reads an item list by partial term. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readListByPartialTerm"}) + @Test(dataProvider="testName", groups = {"readListByPartialTerm"}) public void partialTermMatch(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; String partialTerm = getPartialTermCommon(); if (logger.isDebugEnabled()) { @@ -249,12 +243,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * of an all-lowercase variation of the expected match, to test case-insensitive * matching. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) + @Test(dataProvider="testName", groups = {"readListByPartialTerm"}, + dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchCaseInsensitiveLowerCase(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; final String partialTerm = getPartialTermCommon().toLowerCase(); @@ -275,12 +266,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * of an all-uppercase variation of the expected match, to test case-insensitive * matching. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchCaseInsensitiveUpperCase(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; final String partialTerm = getPartialTermCommon().toUpperCase(); @@ -300,12 +288,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * Reads an item list by partial term, with a partial term that is of * the minimum character length that may be expected to be matched. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchMinimumLength(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; String partialTerm = getPartialTermMinimumLength(); if (logger.isDebugEnabled()) { @@ -324,12 +309,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * Reads an item list by partial term, with a partial term that contains * at least one Unicode UTF-8 character (outside the USASCII range). */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchUTF8(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; String partialTerm = getPartialTermUtf8(); String ptEncoded; @@ -355,12 +337,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * Reads an item list by partial term, with a partial term that contains * at least one Unicode UTF-8 character (outside the USASCII range). */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchQuote(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; String partialTerm = getPartialTermQuote(); if (logger.isDebugEnabled()) { @@ -378,12 +357,8 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { /** * Finds terms by keywords. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readListByKwdTerm"}) + @Test(dataProvider="testName", groups = {"readListByKwdTerm"}) public void keywordTermMatch(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; String kwdTerm = getKwdTerm(); if (logger.isDebugEnabled()) { @@ -400,12 +375,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { /** * Finds terms by keywords. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"}) public void keywordTermMatchUTF8(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; String kwdTerm = getKwdTermUTF8(); if (logger.isDebugEnabled()) { @@ -427,12 +399,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * Reads an item list by partial term, with a partial term that is not * expected to be matched by any term in any resource. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchOnNonexistentTerm(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; int ZERO_MATCHES_EXPECTED = 0; String partialTerm = getPartialTermNonExistent(); @@ -452,12 +421,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * Reads an item list by partial term, with a partial term that is not * expected to be matched by any term in any resource. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"}) + @Test(dataProvider="testName", groups = {"readListByKwdTerm"}, + dependsOnMethods = {"keywordTermMatch"}) public void keywordTermMatchOnNonexistentTerm(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int numMatchesFound = 0; int ZERO_MATCHES_EXPECTED = 0; String kwdTerm = getKwdTermNonExistent(); @@ -501,12 +467,14 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { } else { Assert.fail("readItemListByPartialTerm passed null csid!"); } - assertStatusCode(res, testName); AbstractCommonList list = null; try { + assertStatusCode(res, testName); list = res.getEntity(); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } List items = list.getListItem(); @@ -572,7 +540,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { String testName = "createAuthority"; if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + logger.debug(getTestBanner(testName, CLASS_NAME)); } // Perform setup. @@ -592,18 +560,12 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { String newID = null; ClientResponse res = client.create(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, this.EXPECTED_STATUS_CODE); + assertStatusCode(res, testName); newID = PersonAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the refname from the first resource created // for additional tests below. @@ -684,19 +646,11 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { String newID = null; ClientResponse res = client.createItem(authorityCsid, 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); - newID = PersonAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the ID returned from the first item resource created diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java index adc39f7fd..0e6ed2452 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java @@ -50,7 +50,7 @@ import org.testng.annotations.Test; * $LastChangedRevision: 753 $ * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ */ -public class PersonAuthorityServicePerfTest extends BaseServiceTest { +public class PersonAuthorityServicePerfTest extends BaseServiceTest { private final String CLASS_NAME = PersonAuthorityServicePerfTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -114,7 +114,7 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { return response.getEntity(AbstractCommonList.class); } @@ -163,16 +163,13 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest { String newID = null; ClientResponse res = client.create(multipart); try { - int statusCode = res.getStatus(); - // Check the status code of the response: does it match - // the expected response(s)? - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); + assertStatusCode(res, testName); newID = PersonAuthorityClientUtils.extractId(res); logger.info("{}: succeeded.", testName); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the refname from the first resource created // for additional tests below. @@ -217,16 +214,12 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest { String newID = null; ClientResponse res = client.createItem(authId, multipart); try { - int statusCode = res.getStatus(); - // Check the status code of the response: does it match - // the expected response(s)? - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - + assertStatusCode(res, "createItem"); newID = PersonAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the IDs from any item resources created @@ -264,11 +257,8 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest { /** * Reads an item list by partial term. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + @Test(dataProvider="testName") public void partialTermMatch(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } for(int i=0; i items = list.getListItem(); diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index 11101e830..61dcc1f28 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -26,9 +26,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; @@ -37,7 +37,6 @@ import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ContactClient; import org.collectionspace.services.client.ContactClientUtils; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.contact.AddressGroup; import org.collectionspace.services.contact.AddressGroupList; import org.collectionspace.services.contact.ContactsCommon; @@ -64,7 +63,7 @@ import org.testng.annotations.Test; * $LastChangedRevision: 753 $ * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ */ -public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class! +public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class! /** The logger. */ private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName(); @@ -95,21 +94,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM final String TEST_BIRTH_DATE = "May 26, 1907"; /** The test death date. */ final String TEST_DEATH_DATE = "June 11, 1979"; - // Hold some values for a recently created item to verify upon read. - private String knownResourceId = null; - private String knownResourceShortIdentifer = null; //private String knownResourceRefName = null; - private String knownItemResourceId = null; private String knownItemResourceShortIdentifer = null; // The resource ID of an item resource used for partial term matching tests. private String knownItemPartialTermResourceId = null; /** The known contact resource id. */ private String knownContactResourceId = null; - /** The n items to create in list. */ - private int nItemsToCreateInList = 3; - /** The all item resource ids created. */ - private Map allItemResourceIdsCreated = - new HashMap(); /** The all contact resource ids created. */ private Map allContactResourceIdsCreated = new HashMap(); @@ -142,13 +132,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @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()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -166,24 +152,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM String newID = null; ClientResponse 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 = PersonAuthorityClientUtils.extractId(res); + assertStatusCode(res, testName); + newID = extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Save values for additional tests if (knownResourceId == null) { @@ -220,49 +194,6 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, headerLabel); } - /** - * Creates the item. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) - public void createItem(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupCreate(); - String newID = createItemInAuthority(knownResourceId, null ); //knownResourceRefName); - } - - /** - * Creates the item with an empty short identifier. - * - * @param testName the test name - */ - /* - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) - public void createItemWithEmptyShortId(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupCreate(); - - // Fill the property map - String shortId = ""; - Map fieldProperties = new HashMap(); - fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false"); - fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, "Rod Beck"); - fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false"); - fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "RodBeck"); - - final Map NULL_REPEATABLE_FIELD_PROPERTIES = null; - String newID = createItemInAuthority(knownResourceId, knownResourceRefName, - shortId, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES); - allResourceIdsCreated.add(newID); - } - */ /** * Creates an item in an authority, using test data. * @@ -270,7 +201,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param authRefName the auth ref name * @return the string */ - private String createItemInAuthority(String vcsid, String authRefName) { + @Override + protected String createItemInAuthority(String vcsid) { final String testName = "createItemInAuthority"; if (logger.isDebugEnabled()) { @@ -330,27 +262,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(vcsid, null /*authRefName*/, itemFieldProperties, itemRepeatableFieldProperties, client.getItemCommonPartName()); - - String newID = null; + setupCreate(); ClientResponse res = client.createItem(vcsid, multipart); + String newID = null; 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); - + assertStatusCode(res, testName); newID = PersonAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the ID returned from the first item resource created @@ -368,7 +292,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Store the IDs from any item resources created // by tests, along with the IDs of their parents, so these items // can be deleted after all tests have been run. - allItemResourceIdsCreated.put(newID, vcsid); + allResourceItemIdsCreated.put(newID, vcsid); return newID; } @@ -378,12 +302,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"createItem"}) + @Test(dataProvider = "testName", groups = {"create"}, + dependsOnMethods = {"createItem"}) public void createContact(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); String newID = createContactInItem(knownResourceId, knownItemResourceId); } @@ -401,32 +322,23 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM if (logger.isDebugEnabled()) { logger.debug(testName + ":..."); } - - setupCreate(); - // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); String identifier = createIdentifier(); PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid, itemcsid, identifier, new ContactClient().getCommonPartName()); - String newID = null; + setupCreate(); ClientResponse res = client.createContact(parentcsid, itemcsid, multipart); + String newID = null; 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); - + assertStatusCode(res, testName); newID = PersonAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } // Store the ID returned from the first contact resource created @@ -446,136 +358,17 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM return newID; } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()) { - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ /** * Attempts to create an authority with an short identifier that contains * non-word characters. * * @param testName the test name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create", "nonWordCharsInShortId"}) + @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"}) public void createWithShortIdNonWordChars(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.CREATE; + testSetup(testExpectedStatusCode, testRequestType); // Create the payload to be included in the body of the request PersonAuthorityClient client = new PersonAuthorityClient(); @@ -591,17 +384,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Check the status code of the response: does it match // the expected response(s)? try { - int statusCode = res.getStatus(); - 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); + assertStatusCode(res, testName); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - } /** @@ -610,18 +398,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create", "nonWordCharsInShortId"}, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"}, + dependsOnMethods = {"org.collectionspace.services.client.test.AbstractServiceTestImpl.create"}) public void createItemWithShortIdNonWordChars(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST; - REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); + testExpectedStatusCode = STATUS_BAD_REQUEST; + testRequestType = ServiceRequestType.CREATE; + testSetup(testExpectedStatusCode, testRequestType); PersonAuthorityClient client = new PersonAuthorityClient(); - // Create the payload to be included in the body of the request String shortId = "7-Eleven"; Map fieldProperties = new HashMap(); @@ -638,22 +422,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Send the request and receive a response ClientResponse res = client.createItem(knownResourceId, multipart); - // Check the status code of the response: does it match // the expected response(s)? 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); + assertStatusCode(res, testName); } finally { - res.releaseConnection(); - + if (res != null) { + res.releaseConnection(); + } } } @@ -665,43 +441,22 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @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 { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } for (int i = 0; i < nItemsToCreateInList; i++) { create(testName); } } - /** - * Creates the item list. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnMethods = {"createList"}) - public void createItemList(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Add items to the initially-created, known parent record. - for (int j = 0; j < nItemsToCreateInList; j++) { - createItem(testName); - } - } - /** * Creates the contact list. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnMethods = {"createItemList"}) + @Test(dataProvider = "testName", groups = {"createList"}, + dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.createItemList"}) public void createContactList(String testName) throws Exception { // Add contacts to the initially-created, known item record. for (int j = 0; j < nItemsToCreateInList; j++) { @@ -717,8 +472,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @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 { readInternal(testName, knownResourceId, null); } @@ -729,22 +484,18 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// groups = {"read"}, dependsOnMethods = {"read"}) public void readByName(String testName) throws Exception { readInternal(testName, null, knownResourceShortIdentifer); } protected void readInternal(String testName, String CSID, String shortId) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = null; + setupRead(); if (CSID != null) { res = client.read(CSID); } else if (shortId != null) { @@ -752,8 +503,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM } else { Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); } - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); //FIXME: remove the following try catch once Aron fixes signatures try { PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); @@ -764,20 +515,22 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM throw new RuntimeException(e); } } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } /** - * Read item. + * Read named item. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) - public void readItem(String testName) throws Exception { - readItemInternal(testName, knownResourceId, null, knownItemResourceId, null); + @Test(dataProvider = "testName", groups = {"readItem", "readNamedItemInNamedAuth"}, + dependsOnMethods = {"readItemInNamedAuth"}) + public void readNamedItem(String testName) throws Exception { + readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer); } /** @@ -786,32 +539,21 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readItem"}) public void readItemInNamedAuth(String testName) throws Exception { readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); } - /** - * Read named item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) - public void readNamedItem(String testName) throws Exception { - readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer); - } - + /** * Read Named item in Named Auth. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readNamedItem"}) public void readNamedItemInNamedAuth(String testName) throws Exception { readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer); } @@ -821,15 +563,13 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM throws Exception { if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); logger.debug("Reading:" + ((authCSID != null) ? authCSID : authShortId) + "/" + ((itemCSID != null) ? authCSID : itemShortId)); } - // Perform setup. - setupRead(); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + setupRead(); ClientResponse res = null; if (authCSID != null) { if (itemCSID != null) { @@ -850,8 +590,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM } else { Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null"); } - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Check whether we've received a person. PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); PersonsCommon person = (PersonsCommon) extractPart(input, @@ -871,9 +611,10 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM List groups = person.getGroups().getGroup(); Assert.assertTrue(groups.size() > 0); Assert.assertNotNull(groups.get(0)); - } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -883,13 +624,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem"}) - public void verifyItemDisplayNames(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } + @Test(dataProvider = "testName", groups = {"update"}, + dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"}) + public void verifyItemDisplayName(String testName) throws Exception { // Perform setup. setupUpdate(); @@ -897,11 +634,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PersonAuthorityClient client = new PersonAuthorityClient(); PoxPayloadIn input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); + // Check whether person has expected displayName. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } PersonsCommon person = (PersonsCommon) extractPart(input, @@ -938,15 +678,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person); res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } PersonsCommon updatedPerson = @@ -973,15 +714,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the updated resource to the service and store the response. output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); + commonPart = output.addPart(client.getItemCommonPartName(), person); res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } updatedPerson = @@ -1011,32 +753,28 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"verifyItemDisplayNames"}) + @Test(dataProvider = "testName", groups = {"update"}, + dependsOnMethods = {"verifyItemDisplayName"}) public void verifyIllegalItemDisplayName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup for read. setupRead(); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - // Perform setup for update. - testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE); - PoxPayloadIn input = null; try { + assertStatusCode(res, testName); input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - + // + // Make an invalid UPDATE request -i.e., if we don't want the display name computed, then + // we need to supply one. + // PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); @@ -1046,14 +784,15 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person); + setupUpdateWithInvalidBody(); res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); try { - // intentionally empty try block + assertStatusCode(res, testName); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } @@ -1063,13 +802,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"createContact", "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItem"}) public void readContact(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); @@ -1079,12 +814,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Check whether we've received a contact. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } ContactsCommon contact = (ContactsCommon) extractPart(input, @@ -1100,85 +837,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM } - // 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"}) - public void readNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse 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(); - } - } - - /** - * Read item non existent. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) - public void readItemNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse 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(); - } - } - /** * Read contact non existent. * * @param testName the test name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readContact"}) + @Test(dataProvider = "testName", groups = {"readItem"}, + dependsOnMethods = {"readContact"}) public void readContactNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadNonExistent(); @@ -1187,73 +853,36 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, 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); + assertStatusCode(res, testName); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } // --------------------------------------------------------------- // CRUD tests : READ_LIST tests // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnGroups = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - AbstractCommonList list = null; - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - try { - list = res.getEntity(); - } finally { - res.releaseConnection(); - } - - // Optionally output additional data about list members for debugging. - if (logger.isTraceEnabled()) { - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } /** * Read item list. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnMethods = {"readList"}) + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// groups = {"readList"}, dependsOnMethods = {"readList"}) public void readItemList(String testName) { - readItemList(knownResourceId, null, testName); + readItemList(knownAuthorityWithItems, null, testName); } /** * Read item list by authority name. */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnMethods = {"readItemList"}) - public void readItemListByAuthorityName(String testName) { - readItemList(null, knownResourceShortIdentifer, testName); + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// groups = {"readList"}, dependsOnMethods = {"readItemList"}) + public void readItemListByName(String testName) { + readItemList(null, READITEMS_SHORT_IDENTIFIER, testName); } /** @@ -1263,10 +892,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param name the name */ private void readItemList(String vcsid, String name, String testName) { - - // Perform setup. setupReadList(); - // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = null; @@ -1277,24 +903,22 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM } else { Assert.fail("readItemList passed null csid and name!"); } - assertStatusCode(res, testName); AbstractCommonList list = null; try { + assertStatusCode(res, testName); list = res.getEntity(); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - List items = - list.getListItem(); + List items = list.getListItem(); 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, + // There will be 'nItemsToCreateInList' + // items created by the createItemList test, // all associated with the same parent resource. - int nExpectedItems = nItemsToCreateInList + 1; + int nExpectedItems = nItemsToCreateInList; if (logger.isDebugEnabled()) { logger.debug(testName + ": Expected " + nExpectedItems + " items; got: " + nItemsReturned); @@ -1317,7 +941,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM /** * Read contact list. */ - @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) + @Test(groups = {"readList"}, + dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItemList"}) public void readContactList() { readContactList(knownResourceId, knownItemResourceId); } @@ -1339,11 +964,13 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM AbstractCommonList list = null; ClientResponse res = client.readContactList(parentcsid, itemcsid); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); list = res.getEntity(); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } List listitems = @@ -1379,25 +1006,24 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnGroups = {"readItem", "readList"}) +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// groups = {"update"}, dependsOnGroups = {"readItem", "readList"}) public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - // Retrieve the contents of a resource to update. PersonAuthorityClient client = new PersonAuthorityClient(); PoxPayloadIn input = null; + setupRead(); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug("got PersonAuthority to update with ID: " + knownResourceId); + } input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, @@ -1414,15 +1040,17 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), personAuthority); + setupUpdate(); res = client.update(knownResourceId, output); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } PersonauthoritiesCommon updatedPersonAuthority = @@ -1442,26 +1070,28 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update"}) + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// groups = {"update"}, dependsOnMethods = {"update"}) public void updateItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - // Retrieve the contents of a resource to update. PersonAuthorityClient client = new PersonAuthorityClient(); PoxPayloadIn input = null; + setupRead(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug("got Person to update with ID: " + + knownItemResourceId + + " in PersonAuthority: " + knownResourceId); + } input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } PersonsCommon person = (PersonsCommon) extractPart(input, @@ -1484,15 +1114,17 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person); + setupUpdate(); res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } PersonsCommon updatedPerson = @@ -1517,30 +1149,35 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem"}) + @Test(dataProvider = "testName", groups = {"update"}, + dependsOnMethods = {"readContact", "testContactSubmitRequest", + "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"}) public void updateContact(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); + String contactsCommonLabel = new ContactClient().getCommonPartName(); // Retrieve the contents of a resource to update. PersonAuthorityClient client = new PersonAuthorityClient(); PoxPayloadIn input = null; + setupRead(); ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); + if (logger.isDebugEnabled()) { + logger.debug("got Contact to update with ID: " + + knownContactResourceId + + " in item: " + knownItemResourceId + + " in parent: " + knownResourceId); + } input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } ContactsCommon contact = (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); + contactsCommonLabel, ContactsCommon.class); Assert.assertNotNull(contact); // Verify the contents of this resource @@ -1563,19 +1200,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); //FIXME: REM - Replace with output.addPart(contact, client.getCommonPartName()) - commonPart.setLabel(client.getCommonPartName()); + PayloadOutputPart commonPart = output.addPart(contactsCommonLabel, contact); + setupUpdate(); res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); - assertStatusCode(res, testName); try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. input = new PoxPayloadIn(res.getEntity());; } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - ContactsCommon updatedContact = - (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); + ContactsCommon updatedContact = (ContactsCommon) extractPart(input, + contactsCommonLabel, ContactsCommon.class); Assert.assertNotNull(updatedContact); // Verify that the updated resource received the correct data. @@ -1584,217 +1222,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM "Data in updated object did not match submitted data."); } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* //FIXME: REM - Can we kill all this dead code please? - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(testName, logger); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateWithWrongXmlSchema: url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - - /* (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"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID(s) used when creating the request payload may be arbitrary. - // The only relevant ID may be the one used in update(), below. - PersonAuthorityClient client = new PersonAuthorityClient(); - String displayName = "displayName-NON_EXISTENT_ID"; - PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName()); - ClientResponse 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(); - } - } - - /** - * Update non existent item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) - public void updateNonExistentItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - PersonAuthorityClient client = new PersonAuthorityClient(); - Map nonexMap = new HashMap(); - nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX"); - nonexMap.put(PersonJAXBSchema.FORE_NAME, "John"); - nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne"); - nonexMap.put(PersonJAXBSchema.GENDER, "male"); - Map> nonexRepeatablesMap = new HashMap>(); - PoxPayloadOut multipart = - PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, - null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null), - nonexMap, nonexRepeatablesMap, client.getItemCommonPartName()); - ClientResponse 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(); - } - } - /** * Update non existent contact. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) + @Test(dataProvider = "testName", groups = {"update"}, + dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) public void updateNonExistentContact(String testName) throws Exception { // Currently a no-op test } @@ -1811,16 +1246,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnGroups = {"update"}) + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"updateContact"}) public void deleteContact(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - if (logger.isDebugEnabled()) { logger.debug("parentcsid =" + knownResourceId + " itemcsid = " + knownItemResourceId @@ -1829,167 +1257,38 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + setupDelete(); ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); 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); + assertStatusCode(res, testName); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } } - /** - * Delete item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) - public void deleteItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if (logger.isDebugEnabled()) { - logger.debug("parentcsid =" + knownResourceId - + " itemcsid = " + knownItemResourceId); - } - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse 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(); - } - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if (logger.isDebugEnabled()) { - logger.debug("parentcsid =" + knownResourceId); - } - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse 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(); - } + // Do nothing. See localDelete(). This ensure proper test order. + } + + @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse 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(); - } + public void deleteItem(String testName) throws Exception { + // Do nothing. We need to wait until after the test "localDelete" gets run. When it does, + // its dependencies will get run first and then we can call the base class' delete method. } - - /** - * Delete non existent item. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) - public void deleteNonExistentItem(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse 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(); - } + + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"verifyIllegalItemDisplayName", "testContactSubmitRequest", "deleteContact"}) + public void localDeleteItem(String testName) throws Exception { + super.deleteItem(testName); } /** @@ -1997,93 +1296,29 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"deleteContact"}) public void deleteNonExistentContact(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + setupDeleteNonExistent(); ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, 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); + assertStatusCode(res, testName); } finally { - res.releaseConnection(); - } - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - - } - - /** - * Test item submit request. - */ - @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) - public void testItemSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getItemResourceURL(knownResourceId, knownItemResourceId); - int statusCode = submitRequest(method, url); - - // 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 (res != null) { + res.releaseConnection(); + } } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - } /** * Test contact submit request. */ - @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"}) - public void testContactSubmitRequest() { + @Test(dataProvider = "testName", + dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"}) + public void testContactSubmitRequest(String testName) { // Expected status code: 200 OK final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); @@ -2097,7 +1332,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Check the status code of the response: does it match // the expected response(s)? if (logger.isDebugEnabled()) { - logger.debug("testItemSubmitRequest: url=" + url + logger.debug("testContactSubmitRequest: url=" + url + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); @@ -2144,7 +1379,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM res.releaseConnection(); } // Clean up item resources. - for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { itemResourceId = entry.getKey(); parentResourceId = entry.getValue(); // Note: Any non-success responses from the delete operation @@ -2240,4 +1475,76 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM return getContactServiceRootURL(parentResourceIdentifier, itemResourceIdentifier) + "/" + contactResourceIdentifier; } + + @Override + public void authorityTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected PersonsCommon updateItemInstance(PersonsCommon authorityItem) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedItemInstances(PersonsCommon original, + PersonsCommon updated) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + String shortId = identifier; + String displayName = "displayName-" + shortId; + PoxPayloadOut result = + PersonAuthorityClientUtils.createPersonAuthorityInstance( + displayName, shortId, commonPartName); + return result; + } + + @Override + protected PoxPayloadOut createNonExistenceInstance(String commonPartName, + String identifier) { + String displayName = "displayName-NON_EXISTENT_ID"; + PoxPayloadOut result = PersonAuthorityClientUtils.createPersonAuthorityInstance( + displayName, "NON_EXISTENT_SHORT_ID", commonPartName); + return result; + } + + protected PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier) { + Map nonexMap = new HashMap(); + nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX"); + nonexMap.put(PersonJAXBSchema.FORE_NAME, "John"); + nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne"); + nonexMap.put(PersonJAXBSchema.GENDER, "male"); + Map> nonexRepeatablesMap = new HashMap>(); + PoxPayloadOut result = + PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, + null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null), + nonexMap, nonexRepeatablesMap, commonPartName); + return result; + } + + + @Override + protected PersonauthoritiesCommon updateInstance( + PersonauthoritiesCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(PersonauthoritiesCommon original, + PersonauthoritiesCommon updated) throws Exception { + // TODO Auto-generated method stub + } + + @Override + protected void verifyReadItemInstance(PersonsCommon item) throws Exception { + // Do nothing for now. Add more 'read' validation checks here if applicable. + } } diff --git a/services/person/service/pom.xml b/services/person/service/pom.xml index bd08440a2..8a0b046fe 100644 --- a/services/person/service/pom.xml +++ b/services/person/service/pom.xml @@ -57,7 +57,6 @@ org.testng testng - 5.6 diff --git a/services/pom.xml b/services/pom.xml index 79a992278..61fcf8cea 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -77,7 +77,6 @@ org.testng testng test - jdk15 @@ -162,10 +161,10 @@ -Xannotate -verbose - -XtoString + -Xequals -XhashCode - -Xcopyable + @@ -261,6 +260,7 @@ + @@ -277,13 +277,6 @@ net.java.dev.jaxb2-commons jaxb-fluent-api 2.0.2 - - - org.testng - testng - 5.6 - test - jdk15 org.jvnet.jaxb2_commons diff --git a/services/query/service/pom.xml b/services/query/service/pom.xml index 86c948994..f45021241 100644 --- a/services/query/service/pom.xml +++ b/services/query/service/pom.xml @@ -30,7 +30,6 @@ org.testng testng - 5.6 diff --git a/services/relation/client/pom.xml b/services/relation/client/pom.xml index fb42d6d26..b3f908628 100644 --- a/services/relation/client/pom.xml +++ b/services/relation/client/pom.xml @@ -57,7 +57,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java index 6c9b3b2db..feaabf021 100644 --- a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java +++ b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java @@ -47,6 +47,10 @@ import org.collectionspace.services.relation.RelationshipType; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -59,17 +63,23 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision$ * $LastChangedDate$ */ -public class RelationServiceTest extends AbstractServiceTestImpl { +public class RelationServiceTest extends AbstractPoxServiceTestImpl { /** The logger. */ private final String CLASS_NAME = RelationServiceTest.class.getName(); private final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); private List personIdsCreated = new ArrayList(); - private String samSubjectPersonCSID = null; - private String oliveObjectPersonCSID = null; - private String samSubjectRefName = null; - private String oliveObjectRefName = null; + + private static final String UNINITIALIZED_CSID = "-1"; + private static final String UNINITIALIZED_REFNAME = "null"; + + private static final String PERSONS_DOCUMENT_TYPE = "Person"; + private String samSubjectPersonCSID = UNINITIALIZED_CSID; + private String oliveObjectPersonCSID = UNINITIALIZED_REFNAME; + private String samSubjectRefName = UNINITIALIZED_CSID; + private String oliveObjectRefName = UNINITIALIZED_REFNAME; + private String personAuthCSID = null; private String personShortId = PERSON_AUTHORITY_NAME; @@ -77,9 +87,6 @@ public class RelationServiceTest extends AbstractServiceTestImpl { /** The SERVICE path component. */ final String SERVICE_PATH_COMPONENT = "relations"; - /** The known resource id. */ - private String knownResourceId = null; - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -87,81 +94,26 @@ public class RelationServiceTest extends AbstractServiceTestImpl { protected CollectionSpaceClient getClientInstance() { return new RelationClient(); } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(RelationsCommonList.class); + + protected Class getCommonListType() { + return (Class)RelationsCommonList.class; } - - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + + /** + * Creates the person refs as a precondition for running the tests in this class. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) - @Override - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). + @BeforeSuite + private void createPersonRefs() { setupCreate(); - createPersonRefs(); - // Submit the request to the service and store the response. - RelationClient client = new RelationClient(); - String identifier = createIdentifier(); - PoxPayloadOut multipart = createRelationInstance(identifier); - ClientResponse res = client.create(multipart); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - // - // 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null){ - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); - } - - /** - * Creates the person refs. - */ - protected void createPersonRefs() { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); @@ -181,8 +133,15 @@ public class RelationServiceTest extends AbstractServiceTestImpl { Assert.assertNotNull(oliveObjectRefName); personIdsCreated.add(csid); } + + @AfterSuite + private void deletePersonRefs() { + // + // Delete all the persons we created for the tests + // + } - protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + private String createPerson(String firstName, String surName, String shortId, String authRefName) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -194,34 +153,16 @@ public class RelationServiceTest extends AbstractServiceTestImpl { ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); return extractId(res); - } - + } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - for(int i = 0; i < 3; i++){ - create(testName); - } - } - - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + @Test(dataProvider="testName", dependsOnMethods = {"create"}) public void createWithSelfRelation(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - + // Test result codes setup setupCreateWithInvalidBody(); // Submit the request to the service and store the response. @@ -242,607 +183,28 @@ public class RelationServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_BAD_REQUEST); //should be an error: same objectID and subjectID are not allowed by validator. } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this test really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //Should this test really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this test really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - RelationClient client = new RelationClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - // Get the common part from the response and check that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - RelationsCommon relationCommon = null; - if (payloadInputPart != null) { - relationCommon = (RelationsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(relationCommon); - - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - RelationClient client = new RelationClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - RelationClient client = new RelationClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - RelationsCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if(iterateThroughList && logger.isDebugEnabled()){ - List items = - list.getRelationListItem(); - int i = 0; - for(RelationsCommonList.RelationListItem item : items){ - logger.debug(testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); - i++; - } - } - - } - - - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readListPaginated(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - Long pageSize=1L; - Long pageNumber=0L; - RelationClient client = new RelationClient(); - ClientResponse res = client.readList("", //subjectCsid, - "", //subjectType, - "", //predicate, - "", //objectCsid, - "", //objectType, - "", //sortBy, - pageSize, - pageNumber); - RelationsCommonList list = res.getEntity(); - assertStatusCode(res, testName); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if(iterateThroughList && logger.isDebugEnabled()){ - List items = - list.getRelationListItem(); - int i = 0; - for(RelationsCommonList.RelationListItem item : items){ - logger.debug(testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); - i++; - } - } - - } - - - // Failure outcomes - // None at present. - - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - - logger.debug(testBanner(testName, CLASS_NAME)); - // Perform setup. - setupUpdate(); - - // Retrieve an existing resource that we can update. - RelationClient client = new RelationClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - logger.debug("Got object to update with ID: " + knownResourceId); - - // Extract the common part and verify that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - RelationsCommon relationCommon = null; - if (payloadInputPart != null) { - relationCommon = (RelationsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(relationCommon); - logger.trace("object before update"); - logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class)); - - String newSubjectDocType = relationCommon.getObjectDocumentType(); - String newObjectDocType = relationCommon.getSubjectDocumentType(); - String newSubjectId = relationCommon.getObjectCsid(); - String newObjectId = relationCommon.getSubjectCsid(); - // Update the content of this resource, inverting subject and object - relationCommon.setSubjectCsid(newSubjectId); - relationCommon.setSubjectDocumentType("Hooey"); - relationCommon.setObjectCsid(newObjectId); - relationCommon.setObjectDocumentType("Fooey"); - relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName()); - logger.trace("updated object to send"); - logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class)); - - // Submit the request containing the updated resource to the service - // and store the response. - PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - // Extract the common part of the updated resource and verify that it is not null. - input = new PoxPayloadIn(res.getEntity()); - RelationsCommon updatedRelationCommon = - (RelationsCommon) extractPart(input, - client.getCommonPartName(), RelationsCommon.class); - Assert.assertNotNull(updatedRelationCommon); - - logger.trace("updated object as received"); - logger.trace(objectAsXmlString(updatedRelationCommon, RelationsCommon.class)); - - final String msg = - "Data in updated object did not match submitted data."; - final String msg2 = - "Data in updated object was not correctly computed."; - Assert.assertEquals( - updatedRelationCommon.getSubjectCsid(), newSubjectId, msg); - Assert.assertEquals( - updatedRelationCommon.getSubjectDocumentType(), newSubjectDocType, msg2); - Assert.assertEquals( - updatedRelationCommon.getObjectCsid(), newObjectId, msg); - Assert.assertEquals( - updatedRelationCommon.getObjectDocumentType(), newObjectDocType, msg2); - Assert.assertEquals( - updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg); - - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this test really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this test really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this test really be empty? - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - RelationClient client = new RelationClient(); - PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID); - ClientResponse res = - client.update(NON_EXISTENT_ID, multipart); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - RelationClient client = new RelationClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - RelationClient client = new RelationClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // RELATE_OBJECT tests - // --------------------------------------------------------------- - /** - * Relate objects. - */ - @Test(dependsOnMethods = {"create"}) - public void relateObjects() { - //Should this test really be empty? - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- + /** - * Tests the code for manually submitting data that is used by several - * of the methods above. + * This method is called by the base class method (test) readList(). + * @param testName + * @param list */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - setupRead(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testSubmitRequest: url=" + url + - " status=" + statusCode); + @Override + protected void printList(String testName, RelationsCommonList list) { + List items = + list.getRelationListItem(); + int i = 0; + for(RelationsCommonList.RelationListItem item : items){ + logger.debug(testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + i++; } - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // --------------------------------------------------------------- @@ -865,8 +227,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl { private PoxPayloadOut createRelationInstance(RelationsCommon relation) { PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - result.addPart(relation, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new RelationClient().getCommonPartName()); + result.addPart(new RelationClient().getCommonPartName(), relation); if(logger.isDebugEnabled()){ logger.debug("to be created, relation common"); logger.debug(objectAsXmlString(relation, RelationsCommon.class)); @@ -895,7 +256,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl { private void fillRelation(RelationsCommon relationCommon, String identifier) { fillRelation(relationCommon, samSubjectPersonCSID, null, oliveObjectPersonCSID, null, RelationshipType.COLLECTIONOBJECT_INTAKE.toString(), - RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName"); + RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName-" + identifier); } /** @@ -926,4 +287,49 @@ public class RelationServiceTest extends AbstractServiceTestImpl { protected String getServiceName() { return RelationClient.SERVICE_NAME; } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return createRelationInstance(identifier); + } + + @Override + protected RelationsCommon updateInstance(RelationsCommon relationCommon) { + RelationsCommon result = new RelationsCommon(); + + // Update the content of this resource, inverting subject and object + result.setSubjectCsid(relationCommon.getObjectCsid()); + result.setSubjectDocumentType("Hooey"); // DocumentType changes should be ignored. + result.setObjectCsid(relationCommon.getSubjectCsid()); + result.setObjectDocumentType("Fooey"); // DocumentType changes should be ignored. + result.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName()); + + return result; + } + + @Override + protected void compareUpdatedInstances(RelationsCommon original, + RelationsCommon updated) throws Exception { + final String msg = + "Data in updated object did not match submitted data."; + final String msg2 = + "Data in updated object was not correctly computed."; + Assert.assertEquals( + updated.getSubjectCsid(), original.getSubjectCsid(), msg); + Assert.assertEquals( + updated.getSubjectDocumentType(), PERSONS_DOCUMENT_TYPE, msg2); // DocumentType changes should have been ignored. + Assert.assertEquals( + updated.getObjectCsid(), original.getObjectCsid(), msg); + Assert.assertEquals( + updated.getObjectDocumentType(), PERSONS_DOCUMENT_TYPE, msg2); // DocumentType changes should have been ignored. + Assert.assertEquals( + updated.getPredicateDisplayName(), original.getPredicateDisplayName(), msg); + } } diff --git a/services/relation/service/pom.xml b/services/relation/service/pom.xml index edaab8245..1007a6825 100644 --- a/services/relation/service/pom.xml +++ b/services/relation/service/pom.xml @@ -33,7 +33,6 @@ org.testng testng - 5.6 diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java index 4e7eb2178..1bc19d1a6 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java @@ -33,6 +33,7 @@ import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.relation.IRelationsManager; import org.collectionspace.services.common.relation.nuxeo.RelationsUtils; import org.slf4j.Logger; @@ -91,6 +92,15 @@ public class RelationResource extends ResourceBase { String relationClause = RelationsUtils.buildWhereClause(subjectCsid, subjectType, predicate, objectCsid, objectType); handler.getDocumentFilter().appendWhereClause(relationClause, IQueryManager.SEARCH_QUALIFIER_AND); + // + // Handle keyword clause + // + String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); + if (keywords != null && keywords.isEmpty() == false) { + String keywordClause = QueryManager.createWhereClauseFromKeywords(keywords); + handler.getDocumentFilter().appendWhereClause(keywordClause, IQueryManager.SEARCH_QUALIFIER_AND); + } + return (RelationsCommonList)finish_getList(ctx, handler); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.LIST_FAILED); diff --git a/services/report/client/pom.xml b/services/report/client/pom.xml index 8073f1569..f5f12af59 100644 --- a/services/report/client/pom.xml +++ b/services/report/client/pom.xml @@ -61,7 +61,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java b/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java index 9f5c7429b..db2976f13 100644 --- a/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java +++ b/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java @@ -56,6 +56,10 @@ public class ReportClient extends AbstractCommonListPoxServiceClientImpl { /** The logger. */ private final String CLASS_NAME = ReportServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); final String SERVICE_NAME = "reports"; final String SERVICE_PATH_COMPONENT = "reports"; - // Instance variables specific to this test. - /** The known resource id. */ - private String knownResourceId = null; - + // Instance variables specific to this test. private String testDocType = "Acquisition"; /* (non-Javadoc) @@ -73,240 +66,49 @@ public class ReportServiceTest extends AbstractServiceTestImpl { protected CollectionSpaceClient getClientInstance() { return new ReportClient(); } - -// @Override -// protected PoxPayloadOut createInstance(String identifier) { -// PoxPayloadOut multipart = createReportInstance(identifier); -// return multipart; -// } - - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - ReportClient client = new ReportClient(); - String identifier = createIdentifier(); - PoxPayloadOut multipart = createReportInstance(identifier); - ClientResponse res = client.create(multipart); - - // 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? - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null) { - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - for (int i = 0; i < 3; i++) { - create(testName); - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - ReportClient client = new ReportClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - // Get the common part of the response and verify that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - ReportsCommon reportCommon = null; - if (payloadInputPart != null) { - reportCommon = (ReportsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(reportCommon); - - // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters. - if (logger.isDebugEnabled()) { - logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" - + "UTF-8 data received=" + reportCommon.getNotes()); - } - Assert.assertEquals(reportCommon.getNotes(), getUTF8DataFragment(), - "UTF-8 data retrieved '" + reportCommon.getNotes() - + "' does not match expected data '" + getUTF8DataFragment()); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - ReportClient client = new ReportClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - ReportClient client = new ReportClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readList"}) + + @Test(dataProvider = "testName", + dependsOnMethods = {"CRUDTests"}) public void readListFiltered(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupReadList(); // Submit the request to the service and store the response. ReportClient client = new ReportClient(); - ClientResponse res = client.readListFiltered( - testDocType, "single"); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - List items = - list.getListItem(); + ClientResponse res = client.readListFiltered(testDocType, "single"); + AbstractCommonList list = null; + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + List items = list.getListItem(); // We must find the basic one we created boolean fFoundBaseItem = false; for (AbstractCommonList.ListItem item : items) { - if(knownResourceId.equalsIgnoreCase(AbstractCommonListUtils.ListItemGetCSID(item))) { + String itemCsid = AbstractCommonListUtils.ListItemGetCSID(item); + if (knownResourceId.equalsIgnoreCase(itemCsid)) { fFoundBaseItem = true; break; } } - if(!fFoundBaseItem) + if(!fFoundBaseItem) { Assert.fail("readListFiltered failed to return base item"); + } // Now filter for something else, and ensure it is NOT returned res = client.readListFiltered("Intake", "single"); - assertStatusCode(res, testName); - list = res.getEntity(); + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } items = list.getListItem(); // We must NOT find the basic one we created @@ -317,8 +119,14 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // Now filter for something else, and ensure it is NOT returned res = client.readListFiltered(testDocType, "group"); - assertStatusCode(res, testName); - list = res.getEntity(); + try { + assertStatusCode(res, testName); + list = res.getEntity(); + } finally { + if (res != null) { + res.releaseConnection(); + } + } items = list.getListItem(); // We must NOT find the basic one we created @@ -328,237 +136,25 @@ public class ReportServiceTest extends AbstractServiceTestImpl { } } - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readListFiltered"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - ReportClient client = new ReportClient(); - ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - if (logger.isDebugEnabled()) { - logger.debug("got object to update with ID: " + knownResourceId); - } - - // Extract the common part from the response. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); - ReportsCommon reportCommon = null; - if (payloadInputPart != null) { - reportCommon = (ReportsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(reportCommon); - - // Update its content. - reportCommon.setName("updated-" + reportCommon.getName()); - reportCommon.setOutputMIME("updated-" + reportCommon.getOutputMIME()); - if (logger.isDebugEnabled()) { - logger.debug("to be updated object"); - logger.debug(objectAsXmlString(reportCommon, ReportsCommon.class)); - } - reportCommon.setNotes("updated-" + reportCommon.getNotes()); - - // Submit the updated common part in an update request to the service - // and store the response. - PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); - PayloadOutputPart commonPart = output.addPart(reportCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - // Extract the updated common part from the response. - input = new PoxPayloadIn(res.getEntity()); - payloadInputPart = input.getPart(client.getCommonPartName()); - ReportsCommon updatedReportCommon = null; - if (payloadInputPart != null) { - updatedReportCommon = (ReportsCommon) payloadInputPart.getBody(); - } - Assert.assertNotNull(updatedReportCommon); - if (logger.isDebugEnabled()) { - logger.debug("updated object"); - logger.debug(objectAsXmlString(updatedReportCommon, ReportsCommon.class)); - } - - // Check selected fields in the updated common part. - Assert.assertEquals(updatedReportCommon.getName(), - reportCommon.getName(), - "Data in updated object did not match submitted data."); - - // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters. - if (logger.isDebugEnabled()) { - logger.debug("UTF-8 data sent=" + reportCommon.getNotes() + "\n" - + "UTF-8 data received=" + updatedReportCommon.getNotes()); - } - Assert.assertTrue(updatedReportCommon.getNotes().contains(getUTF8DataFragment()), - "UTF-8 data retrieved '" + updatedReportCommon.getNotes() - + "' does not contain expected data '" + getUTF8DataFragment()); - Assert.assertEquals(updatedReportCommon.getNotes(), - reportCommon.getNotes(), - "Data in updated object did not match submitted data."); - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - ReportClient client = new ReportClient(); - PoxPayloadOut multipart = createReportInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + /** + * This method overrides the delete method in the base class which is marked with the TestNG @Test annotation. + * Since we don't want the actually delete test to happen until later in the dependency test chain, we're make this + * an empty method. Later in the test suite, the method localDelete() will get called and it will call super.delete() */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readListFiltered", "testSubmitRequest", "update", "readWorkflow"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - ReportClient client = new ReportClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - ReportClient client = new ReportClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); + // + // Do nothing for now. The test localDelete() will get called later in the dependency chain. + // } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- + /** - * Tests the code for manually submitting data that is used by several - * of the methods above. + * This test will delete the known resource after the test readListFiltered() is run */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - + @Test(dataProvider = "testName", + dependsOnMethods = {"readListFiltered"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } // --------------------------------------------------------------- @@ -587,7 +183,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { List docTypes = new ArrayList(); docTypes.add(testDocType); return createReportInstance( - "Acquisition Summary", + "Acquisition Summary " + identifier, docTypes, true, false, false, true, "acq_basic.jasper", "application/pdf"); @@ -623,8 +219,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(reportCommon, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new ReportClient().getCommonPartName()); + multipart.addPart(new ReportClient().getCommonPartName(), reportCommon); if (logger.isDebugEnabled()) { logger.debug("to be created, report common"); @@ -634,4 +229,62 @@ public class ReportServiceTest extends AbstractServiceTestImpl { return multipart; } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = createReportInstance(identifier); + return result; + } + + @Override + protected ReportsCommon updateInstance(ReportsCommon reportsCommon) { + ReportsCommon result = new ReportsCommon(); + + result.setSupportsSingleDoc(true); + result.setName("updated-" + reportsCommon.getName()); + result.setOutputMIME("updated-" + reportsCommon.getOutputMIME()); + result.setNotes("updated-" + reportsCommon.getNotes()); + + return result; + } + + @Override + protected void compareUpdatedInstances(ReportsCommon original, + ReportsCommon updated) throws Exception { + // Check selected fields in the updated common part. + Assert.assertEquals(updated.getName(), + original.getName(), + "Name in updated object did not match submitted data."); + + // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters. + if (logger.isDebugEnabled()) { + logger.debug("UTF-8 data sent=" + original.getNotes() + "\n" + + "UTF-8 data received=" + updated.getNotes()); + } + Assert.assertTrue(updated.getNotes().contains(getUTF8DataFragment()), + "UTF-8 data retrieved '" + updated.getNotes() + + "' does not contain expected data '" + getUTF8DataFragment()); + Assert.assertEquals(updated.getNotes(), + original.getNotes(), + "Notes in updated object did not match submitted data."); + } + + protected void compareReadInstances(ReportsCommon original, ReportsCommon fromRead) throws Exception { + Assert.assertEquals(fromRead.getNotes(), getUTF8DataFragment(), + "UTF-8 data retrieved '" + fromRead.getNotes() + + "' does not match expected data '" + getUTF8DataFragment()); + } + + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ + @Override + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"}) + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + } } diff --git a/services/report/service/pom.xml b/services/report/service/pom.xml index 8615a4f71..54dedbe7c 100644 --- a/services/report/service/pom.xml +++ b/services/report/service/pom.xml @@ -50,7 +50,6 @@ org.testng testng - 5.6 diff --git a/services/security/client/pom.xml b/services/security/client/pom.xml index ef504dd89..f8659117c 100644 --- a/services/security/client/pom.xml +++ b/services/security/client/pom.xml @@ -61,7 +61,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java index 4995769f2..fc3341251 100644 --- a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java +++ b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java @@ -23,15 +23,13 @@ package org.collectionspace.services.security.client.test; import java.util.List; - import javax.ws.rs.core.Response; - -//import org.apache.commons.codec.binary.Base64; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.testng.Assert; import org.testng.annotations.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.collectionspace.services.account.AccountTenant; import org.collectionspace.services.account.AccountsCommon; @@ -42,16 +40,12 @@ import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.CollectionObjectFactory; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.BaseServiceTest; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; import org.collectionspace.services.collectionobject.TitleGroup; import org.collectionspace.services.collectionobject.TitleGroupList; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * AuthenticationServiceTest uses CollectionObject service to test * authentication @@ -59,15 +53,14 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: 434 $ $LastChangedDate: 2009-07-28 14:34:15 -0700 (Tue, * 28 Jul 2009) $ */ -public class AuthenticationServiceTest extends AbstractServiceTestImpl { +public class AuthenticationServiceTest extends BaseServiceTest { + private final Logger logger = LoggerFactory.getLogger(AuthenticationServiceTest.class); /** The known resource id. */ - private String knownResourceId = null; private String barneyAccountId = null; //active private String georgeAccountId = null; //inactive /** The logger. */ private final String CLASS_NAME = AuthenticationServiceTest.class.getName(); - private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTest#getServicePathComponent() @@ -98,23 +91,13 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { throw new UnsupportedOperationException(); //Since this test does not support lists, this method is not needed. } @Test(dataProvider = "testName") - @Override - public void readPaginatedList(String testName) throws Exception { - // Test not supported. - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void createActiveAccount(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup, such as initializing the type of service request // (e.g. CREATE, DELETE), its valid and expected status codes, and // its associated HTTP method name (e.g. POST, DELETE). @@ -134,9 +117,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": barney status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from this create operation // for additional tests below. @@ -148,12 +131,8 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void createInactiveAccount(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupCreate(); @@ -171,9 +150,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": george status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); // Store the ID returned from this create operation // for additional tests below. @@ -198,9 +177,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); res1.releaseConnection(); } @@ -208,17 +187,14 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTest#create() */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createActiveAccount"}) - @Override + @Test(dataProvider = "testName", + dependsOnMethods = {"createActiveAccount"}) public void create(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); collectionObjectClient.setAuth(true, "barney", true, "barney08", true); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); ClientResponse res = collectionObjectClient.create(multipart); @@ -237,18 +213,16 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createActiveAccount"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createActiveAccount"}) public void createWithoutAuthn(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String user = collectionObjectClient.getProperty(collectionObjectClient.USER_PROPERTY); String pass = collectionObjectClient.getProperty(collectionObjectClient.PASSWORD_PROPERTY); collectionObjectClient.setAuth(false, user, true, pass, true); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); ClientResponse res = collectionObjectClient.create(multipart); @@ -262,14 +236,12 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { } - @Test(dataProvider = "testName", dependsOnMethods = {"createInactiveAccount"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createInactiveAccount"}) public void createWithInactiveAccount(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); - } CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); collectionObjectClient.setAuth(true, "george", true, "george08", true); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); @@ -286,15 +258,13 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { /** * Creates the collection object instance without password. */ - @Test(dataProvider = "testName", dependsOnMethods = {"createActiveAccount"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createActiveAccount"}) public void createWithoutPassword(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); - } CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String user = collectionObjectClient.getProperty(collectionObjectClient.USER_PROPERTY); collectionObjectClient.setAuth(true, user, true, "", false); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); ClientResponse res = collectionObjectClient.create(multipart); @@ -308,14 +278,12 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { /** * Creates the collection object with unknown user */ - @Test(dataProvider = "testName", dependsOnMethods = {"createActiveAccount"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createActiveAccount"}) public void createWithUnknownUser(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); - } CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); collectionObjectClient.setAuth(true, "foo", true, "bar", true); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); ClientResponse res = collectionObjectClient.create(multipart); @@ -329,15 +297,13 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { /** * Creates the collection object instance with incorrect password. */ - @Test(dataProvider = "testName", dependsOnMethods = {"createActiveAccount"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"createActiveAccount"}) public void createWithIncorrectPassword(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); - } CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String user = collectionObjectClient.getProperty(collectionObjectClient.USER_PROPERTY); collectionObjectClient.setAuth(true, user, true, "bar", true); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); ClientResponse res = collectionObjectClient.create(multipart); @@ -353,12 +319,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { */ @Test(dataProvider = "testName", dependsOnMethods = {"createActiveAccount"}) public void createWithIncorrectUserPassword(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); - } CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); collectionObjectClient.setAuth(true, "foo", true, "bar", true); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); ClientResponse res = collectionObjectClient.create(multipart); @@ -375,12 +338,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { */ @Test(dataProvider = "testName", dependsOnMethods = {"createActiveAccount"}) public void createWithoutTenant(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); - } CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); collectionObjectClient.setAuth(true, "babybop", true, "babybop09", true); - String identifier = BaseServiceTest.createIdentifier(); + String identifier = createIdentifier(); PoxPayloadOut multipart = createCollectionObjectInstance( collectionObjectClient.getCommonPartName(), identifier); ClientResponse res = collectionObjectClient.create(multipart); @@ -392,24 +352,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { res.releaseConnection(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#delete() - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void delete(String testName) { - setupDelete(); - - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "createWithInactiveAccount"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"create", "createWithInactiveAccount"}) public void deleteAccounts(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDelete(); AccountClient accountClient = new AccountClient(); @@ -420,29 +365,19 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": barney status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); res = accountClient.delete(georgeAccountId); statusCode = res.getStatus(); if (logger.isDebugEnabled()) { logger.debug(testName + ": george status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); res.releaseConnection(); } - // --------------------------------------------------------------- - // Search tests - // --------------------------------------------------------------- - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void searchWorkflowDeleted(String testName) throws Exception { - // Fixme: null test for now, overriding test in base class - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -517,107 +452,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#createList() - */ - @Override - public void createList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithEmptyEntityBody() - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithMalformedXml() - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithWrongXmlSchema() - */ - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#read() - */ - @Override - public void read(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#readNonExistent() - */ - @Override - public void readNonExistent(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#readList() - */ - @Override - public void readList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#update() - */ - @Override - public void update(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithEmptyEntityBody() - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithMalformedXml() - */ - @Override - public void updateWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithWrongXmlSchema() - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#updateNonExistent() - */ - @Override - public void updateNonExistent(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTest#deleteNonExistent() - */ - @Override - public void deleteNonExistent(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. - } + @Override + protected Class getCommonListType() { + // TODO Auto-generated method stub + return null; + } } diff --git a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java index 048359220..65f66e498 100644 --- a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java +++ b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java @@ -32,14 +32,16 @@ import java.util.Collection; import java.util.Date; import java.util.Hashtable; import java.util.List; + import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; + import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.authorization.AccountRole; import org.collectionspace.services.authorization.AccountValue; import org.collectionspace.services.authorization.perms.ActionType; import org.collectionspace.services.authorization.perms.EffectType; - import org.collectionspace.services.authorization.perms.Permission; import org.collectionspace.services.authorization.perms.PermissionAction; import org.collectionspace.services.authorization.PermissionRole; @@ -63,22 +65,18 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.RoleClient; import org.collectionspace.services.client.RoleFactory; -import org.collectionspace.services.client.test.AbstractServiceTestImpl; +import org.collectionspace.services.client.test.BaseServiceTest; import org.collectionspace.services.dimension.DimensionsCommon; import org.collectionspace.services.intake.IntakesCommon; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.Test; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; /** * AuthorizationServiceTest, carries out tests against a @@ -91,14 +89,11 @@ import org.testng.annotations.BeforeClass; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class AuthorizationServiceTest extends AbstractServiceTestImpl { +public class AuthorizationServiceTest extends BaseServiceTest { private final String CLASS_NAME = AuthorizationServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. - private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); - //key for accValues is userId private Hashtable accValues = new Hashtable(); //key for permValues is id as there could be several perms for the same resource private Hashtable permValues = new Hashtable(); @@ -238,35 +233,17 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { */ @Override protected CollectionSpaceClient getClientInstance() { + // This method is meaningless to this test. return null; } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); - } - - @Test(dataProvider = "testName") - @Override - public void readPaginatedList(String testName) throws Exception { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - } // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void create(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -287,8 +264,8 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode()); knownResourceId = extractId(res); if (logger.isDebugEnabled()) { @@ -304,8 +281,8 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + " (verify not allowed): status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); //Finally, verify that elmo has no access to Intakes @@ -320,8 +297,8 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + " (verify create intake not allowed): status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); } @@ -354,14 +331,10 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { return multipart; } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + @Test(dataProvider = "testName", dependsOnMethods = {"delete"}) public void verifyCreateWithFlippedRoles(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreate(); // Submit the request to the service and store the response. @@ -386,8 +359,8 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode()); knownResourceId = extractId(res); if (logger.isDebugEnabled()) { @@ -402,46 +375,19 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + " (verify not allowed): status = " + statusCode); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); restoreInitialAccountRoles(); } - //to not cause uniqueness violation for permRole, createList is removed - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - } - // --------------------------------------------------------------- // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupRead(); @@ -450,186 +396,120 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { //elmo allowed to read client.setAuth(true, "elmo2010", true, "elmo2010", true); ClientResponse res = client.read(knownResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - DimensionsCommon dimension = (DimensionsCommon) extractPart(input, - client.getCommonPartName(), DimensionsCommon.class); - Assert.assertNotNull(dimension); + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + DimensionsCommon dimension = (DimensionsCommon) extractPart(input, + client.getCommonPartName(), DimensionsCommon.class); + Assert.assertNotNull(dimension); + } finally { + if (res != null) { + res.releaseConnection(); + } + } } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + @Test(dataProvider = "testName", dependsOnMethods = {"read"}) public void readLockedOut(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. - setupRead(); + setupForbidden(); // Submit the request to the service and store the response. DimensionClient client = new DimensionClient(); //lockedOut allowed to read client.setAuth(true, "lockedOut", true, "lockedOut", true); ClientResponse res = client.read(knownResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + " (test lockedOut): status = " + statusCode); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); - } - - // Failure outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void readNonExistent(String testName) throws Exception { - - // Perform setup. - setupReadNonExistent(); - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - setupReadList(); - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) - public void update(String testName) throws Exception { - setupUpdate(); - } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"read"}) public void updateNotAllowed(String testName) throws Exception { + setupForbidden(); - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupUpdate(); - + // Create a new client and change its AuthN credentials DimensionClient client = new DimensionClient(); - //elmo not allowed to update client.setAuth(true, "elmo2010", true, "elmo2010", true); - + // + // Create a new dimension object + // DimensionsCommon dimension = new DimensionsCommon(); dimension.setDimension("dimensionType"); // Update the content of this resource. dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit()); dimension.setValueDate("updated-" + dimension.getValueDate()); - // Submit the request to the service and store the response. + // + // Create and submit the request to the service and store the response. + // PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension); ClientResponse 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); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); - + // + // Create another new client with new credentials + // client = new DimensionClient(); - //lockedOut not allowed to update client.setAuth(true, "lockedOut", true, "lockedOut", true); + // + // Try the update again. + // res = client.update(knownResourceId, output); - statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": (lockedOut) status = " + statusCode); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - } - // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"updateNotAllowed"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"updateNotAllowed"}) public void deleteNotAllowed(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. + setupForbidden(); + // + // Create a new client and change the AuthN credentials + // DimensionClient client = new DimensionClient(); //bigbird can not delete client.setAuth(true, "bigbird2010", true, "bigbird2010", true); + // + // Try to make a DELETE request + // ClientResponse res = client.delete(knownResourceId); - 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); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); - } - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"deleteNotAllowed"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"deleteNotAllowed"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. setupDelete(); @@ -637,46 +517,13 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { DimensionClient client = new DimensionClient(); ClientResponse res = client.delete(knownResourceId); - 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); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - } - - // Failure outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void deleteNonExistent(String testName) throws Exception { - //ignoring this test as the service side returns 200 now even if it does - //not find a record in the db - } - - // --------------------------------------------------------------- - // Search tests - // --------------------------------------------------------------- - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void searchWorkflowDeleted(String testName) throws Exception { - // Fixme: null test for now, overriding test in base class - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create"}) - public void testSubmitRequest() throws Exception { } // --------------------------------------------------------------- @@ -706,7 +553,6 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { } private void deletePermissionRoles() { - List bigbirdRoleValues = new ArrayList(); bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues); @@ -714,7 +560,6 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { List elmoRoleValues = new ArrayList(); elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues); - } private void deleteAccountRoles() { @@ -765,8 +610,6 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { } } - - private void deletePermissions() { //delete entities for (PermissionValue pv : permValues.values()) { @@ -794,127 +637,126 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { private String createPermission(String resName, List actions, EffectType effect) { + String result = null; + setupCreate(); PermissionClient permClient = new PermissionClient(); Permission permission = PermissionFactory.createPermissionInstance(resName, - "default permissions for " + resName, - actions, effect, true, true, true); + "default permissions for " + resName, actions, effect, true, true, true); ClientResponse res = permClient.create(permission); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createPermission: resName=" + resName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreatePermission"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deletePermission(String permId) { setupDelete(); PermissionClient permClient = new PermissionClient(); ClientResponse res = permClient.delete(permId); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deletePermission: delete permission id=" - + permId + " status=" + statusCode); + try { + assertStatusCode(res, "DeletePermission"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } private String createRole(String roleName) { + String result = null; + setupCreate(); RoleClient roleClient = new RoleClient(); - Role role = RoleFactory.createRoleInstance(roleName, roleName, //the display name "role for " + roleName, true); ClientResponse res = roleClient.create(role); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createRole: name=" + roleName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreateRole"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deleteRole(String roleId) { setupDelete(); RoleClient roleClient = new RoleClient(); ClientResponse res = roleClient.delete(roleId); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deleteRole: delete role id=" + roleId - + " status=" + statusCode); + try { + assertStatusCode(res, "DeleteRole"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } private String createAccount(String userName, String email) { + String result = null; + setupCreate(); AccountClient accountClient = new AccountClient(); AccountsCommon account = AccountFactory.createAccountInstance( userName, userName, userName, email, accountClient.getTenantId(), true, false, true, true); ClientResponse res = accountClient.create(account); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createAccount: userName=" + userName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreateAccount"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deleteAccount(String accId) { setupDelete(); AccountClient accClient = new AccountClient(); ClientResponse res = accClient.delete(accId); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deleteAccount: delete account id=" - + accId + " status=" + statusCode); + try { + assertStatusCode(res, "DeleteAccount"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } private String createAccountRole(AccountValue av, Collection rvs) { + String result = null; + setupCreate(); - // Submit the request to the service and store the response. AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( av, rvs, true, true); AccountRoleClient client = new AccountRoleClient(); ClientResponse res = client.create(av.getAccountId(), accRole); - int statusCode = res.getStatus(); - - if (logger.isDebugEnabled()) { - logger.debug("createAccountRole: status = " + statusCode); + try { + assertStatusCode(res, "CreateAccountRole"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deleteAccountRole(AccountValue av, @@ -926,23 +768,19 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { AccountRoleClient client = new AccountRoleClient(); AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( av, rvs, true, true); - ClientResponse res = client.delete( - av.getAccountId()); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("deleteAccountRole: status = " + statusCode); + ClientResponse res = client.delete(av.getAccountId()); + try { + assertStatusCode(res, "DeleteAccountRole"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } - private String createPermissionRole(PermissionValue pv, - Collection rvs) { + private String createPermissionRole(PermissionValue pv, Collection rvs) { + String result = null; + setupCreate(); List rvls = new ArrayList(); rvls.addAll(rvs); @@ -950,16 +788,16 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { pv, rvls, true, true); PermissionRoleClient client = new PermissionRoleClient(); ClientResponse res = client.create(pv.getPermissionId(), permRole); - int statusCode = res.getStatus(); - - if (logger.isDebugEnabled()) { - logger.debug("createPermissionRole: status = " + statusCode); + try { + assertStatusCode(res, "CreatePermissionRole"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deletePermissionRole(PermissionValue pv, @@ -975,16 +813,17 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl { PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance( pv, rvls, true, true); ClientResponse res = client.delete(pv.getPermissionId()); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("deletePermissionRole : status = " + statusCode); + try { + assertStatusCode(res, "DeletePermissionRole"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } + + @Override + protected Class getCommonListType() { + throw new UnsupportedOperationException(); + } } diff --git a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java index 4d809f987..da5dbce93 100644 --- a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java +++ b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java @@ -32,7 +32,6 @@ import java.util.Collection; import java.util.Date; import java.util.Hashtable; import java.util.List; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.authorization.AccountRole; @@ -62,13 +61,10 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.RoleClient; import org.collectionspace.services.client.RoleFactory; -import org.collectionspace.services.client.test.AbstractServiceTestImpl; +import org.collectionspace.services.client.test.BaseServiceTest; import org.collectionspace.services.dimension.DimensionsCommon; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.Test; @@ -89,8 +85,18 @@ import org.testng.annotations.BeforeClass; * $LastChangedRevision: 917 $ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ -public class MultiTenancyTest extends AbstractServiceTestImpl { +public class MultiTenancyTest extends BaseServiceTest { + private static class UserInfo { + String userName; + String password; + + UserInfo(String u, String p) { + userName = u; + password = p; + } + } + private final String CLASS_NAME = MultiTenancyTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); private final static String TENANT_1_ADMIN_USER = "admin@core.collectionspace.org"; @@ -103,20 +109,9 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { private final static String TEST_ROLE_NAME = "ROLE_TEST_REGISTRAR"; private final static String TEST_SERVICE_A = "dimensions"; - private static class UserInfo { - - String userName; - String password; - - UserInfo(String u, String p) { - userName = u; - password = p; - } - } // Instance variables specific to this test. private String TENANT_RESOURCE_1 = null; private String TENANT_RESOURCE_2 = null; - private List allResourceIdsCreated = new ArrayList(); //key for userAccounts is userId private Hashtable userAccounts = new Hashtable(); //key for permValues is id as there could be several perms for the same resource @@ -128,9 +123,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { private Hashtable tenantAdminRoles = new Hashtable(); private Hashtable tenantPermissions = new Hashtable(); -// private String permId1; -// private String permId2; - /* * This method is called only by the parent class, AbstractServiceTestImpl */ @@ -141,10 +133,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { @BeforeClass(alwaysRun = true) public void seedData() { - if (logger.isDebugEnabled()) { - testBanner("seedData", CLASS_NAME); - } - //tenant admin users are used to create accounts, roles and permissions and relationships //assumption : two tenant admin users exist before running this test tenantAdminUsers.put(TENANT_1, new UserInfo(TENANT_1_ADMIN_USER, TENANT_ADMIN_PASS)); @@ -234,7 +222,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } private void seedAccountRoles() { - for (String tenantId : tenantAccounts.keySet()) { AccountValue av = (AccountValue) tenantAccounts.get(tenantId); seedAccountRole(tenantId, av.getUserId()); @@ -251,7 +238,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } private void seedPermissionRoles() { - for (String tenantId : tenantPermissions.keySet()) { PermissionValue pv = tenantPermissions.get(tenantId); seedPermissionRole(tenantId, pv.getPermissionId()); @@ -269,7 +255,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } } - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -282,33 +267,20 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( + protected AbstractCommonList getCommonList( ClientResponse response) { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 throw new UnsupportedOperationException(); } - @Test(dataProvider = "testName") - @Override - public void readPaginatedList(String testName) throws Exception { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - } // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void create(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - - ClientResponse res = create(testName, TENANT_1_USER, TENANT_1); - - TENANT_RESOURCE_1 = extractId(res); - + TENANT_RESOURCE_1 = create(testName, TENANT_1_USER, TENANT_1); if (logger.isDebugEnabled()) { logger.debug(testName + ": tenantId= " + TENANT_1 + " userId=" + TENANT_1_USER @@ -316,15 +288,9 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + @Test(dataProvider = "testName") public void create2(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - - ClientResponse res = create(testName, TENANT_2_USER, TENANT_2); - - TENANT_RESOURCE_2 = extractId(res); + TENANT_RESOURCE_2 = create(testName, TENANT_2_USER, TENANT_2); if (logger.isDebugEnabled()) { logger.debug(testName + ": tenantId= " + TENANT_2 + " userId=" + TENANT_2_USER @@ -332,65 +298,49 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } } - private ClientResponse create(String testName, String userName, String tenatnId) { + private String create(String testName, String userName, String tenatnId) { + String result = null; + setupCreate(); - // Submit the request to the service and store the response. + // + // Create a new client and change the default AuthN credentials + // DimensionClient client = new DimensionClient(); client.setAuth(true, userName, true, userName, true); + // + // Setup a dimension object to create + // String identifier = createIdentifier(); DimensionsCommon dimension = new DimensionsCommon(); dimension.setDimension("dimensionType"); dimension.setMeasurementUnit("measurementUnit-" + identifier); dimension.setValueDate(new Date().toString()); + // + // Create a payload and send the POST request + // PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(), dimension); ClientResponse res = client.create(multipart); - int statusCode = res.getStatus(); - - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + try { + assertStatusCode(res, testName); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode()); - return res; - } + return result; - //to not cause uniqueness violation for permRole, createList is removed - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createList(String testName) throws Exception { - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { } // --------------------------------------------------------------- // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } DimensionsCommon dimension = read(testName, TENANT_RESOURCE_1, TENANT_1_USER); Assert.assertNotNull(dimension); if (logger.isDebugEnabled()) { @@ -400,13 +350,9 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create2"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"create2"}) public void read2(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } DimensionsCommon dimension = read(testName, TENANT_RESOURCE_2, TENANT_2_USER); Assert.assertNotNull(dimension); if (logger.isDebugEnabled()) { @@ -417,159 +363,110 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } private DimensionsCommon read(String testName, String id, String userName) throws Exception { - setupRead(); + DimensionsCommon result = null; + + setupRead(); // Submit the request to the service and store the response. DimensionClient client = new DimensionClient(); client.setAuth(true, userName, true, userName, true); ClientResponse res = client.read(id); - assertStatusCode(res, testName); + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + result = (DimensionsCommon) extractPart(input, + client.getCommonPartName(), DimensionsCommon.class); + } finally { + if (res != null) { + res.releaseConnection(); + } + } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - return (DimensionsCommon) extractPart(input, - client.getCommonPartName(), DimensionsCommon.class); - } - // Failure outcomes - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void readNonExistent(String testName) throws Exception { - - // Perform setup. - setupReadNonExistent(); + return result; } // --------------------------------------------------------------- // CRUD tests : READ_LIST tests // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - setupReadList(); - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read", "readList", "readNonExistent"}) - public void update(String testName) throws Exception { - setupUpdate(); - - } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } - - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read2", "readNonExistent", "testSubmitRequest"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"read2"}) public void updateNonExistent(String testName) throws Exception { - + + setupUpdateNonExistent(); + // + // Create a new client and change the default AuthN credentials + // DimensionClient client = new DimensionClient(); //TENANT_1_USER is not allowed to update the resource of TENANT_2 client.setAuth(true, TENANT_1_USER, true, TENANT_1_USER, true); - + // + // Create a new dimension object to try to update + // DimensionsCommon dimension = new DimensionsCommon(); dimension.setDimension("dimensionType"); // Update the content of this resource. dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit()); dimension.setValueDate("updated-" + dimension.getValueDate()); - // Submit the request to the service and store the response. + // + // Create and send a dimension payload for the UPDATE request + // PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension); ClientResponse res = client.update(TENANT_RESOURCE_2, 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 + " resource = " + TENANT_RESOURCE_2 - + " status = " + statusCode); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - //going to incorrect Nuxeo domain would give DocumentNotFoundException - //instead of giving FORBIDDEN - Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode()); } // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"deleteNonExistent"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"deleteNonExistent"}) public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - int statusCode = delete(testName, TENANT_RESOURCE_1, TENANT_1_USER); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"updateNonExistent"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"updateNonExistent"}) public void delete2(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } int statusCode = delete(testName, TENANT_RESOURCE_2, TENANT_2_USER); } private int delete(String testName, String id, String userName) throws Exception { + int result = -1; + // Perform setup. setupDelete(); // Submit the request to the service and store the response. DimensionClient client = new DimensionClient(); client.setAuth(true, userName, true, userName, true); ClientResponse res = client.delete(id); - 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); + try { + result = assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - return statusCode; + + return result; } // Failure outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"read"}) public void deleteNonExistent(String testName) throws Exception { //ignoring this test as the service side returns 200 now even if it does //not find a record in the db - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. + // Perform setup. setupDelete(); // Submit the request to the service and store the response. @@ -577,49 +474,30 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { //TENANT_2_USER of TENANT_2 is not allowed to delete the resource of TENANT_1 client.setAuth(true, TENANT_2_USER, true, TENANT_2_USER, true); ClientResponse res = client.delete(TENANT_RESOURCE_1); - 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); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + //going to incorrect Nuxeo domain would give DocumentNotFoundException + //instead of giving FORBIDDEN + Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode()); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - //going to incorrect Nuxeo domain would give DocumentNotFoundException - //instead of giving FORBIDDEN - Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode()); } - // --------------------------------------------------------------- - // Search tests - // --------------------------------------------------------------- - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void searchWorkflowDeleted(String testName) throws Exception { - // Fixme: null test for now, overriding test in base class - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create"}) - public void testSubmitRequest() throws Exception { - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @AfterClass(alwaysRun = true) public void cleanUp() { - if (logger.isDebugEnabled()) { - testBanner("cleanUp", CLASS_NAME); - } setupDelete(); String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { @@ -644,7 +522,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } private void deletePermissionRoles() { - for (String tenantId : tenantPermissions.keySet()) { List tenantRoleValues = new ArrayList(); tenantRoleValues.add(tenantRoles.get(tenantId)); @@ -677,7 +554,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { } private void deleteAccounts() { - for (String tenantId : tenantAccounts.keySet()) { AccountValue av = tenantAccounts.get(tenantId); deleteAccount(tenantId, av.getAccountId()); @@ -686,6 +562,8 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { private String createPermission(String tenantId, String resName, List actions, EffectType effect) { + String result = null; + setupCreate(); PermissionClient permClient = new PermissionClient(); UserInfo ui = tenantAdminUsers.get(tenantId); @@ -695,16 +573,16 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { actions, effect, true, true, true); permission.setTenantId(tenantId); ClientResponse res = permClient.create(permission); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createPermission: resName=" + resName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreatePermission"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deletePermission(String tenantId, String permId) { @@ -713,18 +591,18 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { UserInfo ui = tenantAdminUsers.get(tenantId); permClient.setAuth(true, ui.userName, true, ui.password, true); ClientResponse res = permClient.delete(permId); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deletePermission: delete permission id=" - + permId + " status=" + statusCode); + try { + assertStatusCode(res, "DeletePermission"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } private String createRole(String tenantId, String roleName) { + String result = null; + setupCreate(); RoleClient roleClient = new RoleClient(); UserInfo ui = tenantAdminUsers.get(tenantId); @@ -734,16 +612,16 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { "role for " + roleName, true); role.setTenantId(tenantId); ClientResponse res = roleClient.create(role); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createRole: name=" + roleName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreateRole"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deleteRole(String tenantId, String roleId) { @@ -752,18 +630,18 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { UserInfo ui = tenantAdminUsers.get(tenantId); roleClient.setAuth(true, ui.userName, true, ui.password, true); ClientResponse res = roleClient.delete(roleId); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deleteRole: delete role id=" + roleId - + " status=" + statusCode); + try { + assertStatusCode(res, "DeleteRole"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } private String createAccount(String tenantId, String userName, String email) { + String result = null; + setupCreate(); AccountClient accountClient = new AccountClient(); UserInfo ui = tenantAdminUsers.get(tenantId); @@ -772,16 +650,16 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { userName, userName, userName, email, tenantId, true, false, true, true); ClientResponse res = accountClient.create(account); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("createAccount: tenantId=" + tenantId + " userName=" + userName - + " status = " + statusCode); + try { + assertStatusCode(res, "CreateAccount"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deleteAccount(String tenantId, String accId) { @@ -790,21 +668,20 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { UserInfo ui = tenantAdminUsers.get(tenantId); accClient.setAuth(true, ui.userName, true, ui.password, true); ClientResponse res = accClient.delete(accId); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deleteAccount: delete account id=" - + accId + " status=" + statusCode); + try { + assertStatusCode(res, "DeleteAccount"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } private String createAccountRole(String tenantId, AccountValue av, Collection rvs) { + String result = null; + setupCreate(); - // Submit the request to the service and store the response. AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( av, rvs, true, true); @@ -812,16 +689,16 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { UserInfo ui = tenantAdminUsers.get(tenantId); client.setAuth(true, ui.userName, true, ui.password, true); ClientResponse res = client.create(av.getAccountId(), accRole); - int statusCode = res.getStatus(); - - if (logger.isDebugEnabled()) { - logger.debug("createAccountRole: status = " + statusCode); + try { + assertStatusCode(res, "CreateAccountRole"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deleteAccountRole(String tenantId, AccountValue av, @@ -835,23 +712,20 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { client.setAuth(true, ui.userName, true, ui.password, true); AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( av, rvs, true, true); - ClientResponse res = client.delete( - av.getAccountId()); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("deleteAccountRole: status = " + statusCode); + ClientResponse res = client.delete(av.getAccountId()); + try { + assertStatusCode(res, "DeleteAccountRole"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } private String createPermissionRole(String tenantId, PermissionValue pv, Collection rvs) { + String result = null; + setupCreate(); List rvls = new ArrayList(); rvls.addAll(rvs); @@ -861,20 +735,19 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { UserInfo ui = tenantAdminUsers.get(tenantId); client.setAuth(true, ui.userName, true, ui.password, true); ClientResponse res = client.create(pv.getPermissionId(), permRole); - int statusCode = res.getStatus(); - - if (logger.isDebugEnabled()) { - logger.debug("createPermissionRole: status = " + statusCode); + try { + assertStatusCode(res, "createPermissionRole"); + result = extractId(res); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); - return extractId(res); + + return result; } private void deletePermissionRole(String tenantId, PermissionValue pv, List rvls) { - // Perform setup. setupDelete(); @@ -885,17 +758,13 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance( pv, rvls, true, true); ClientResponse res = client.delete(pv.getPermissionId()); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("deletePermissionRole : status = " + statusCode); + try { + assertStatusCode(res, "DeletePermissionRole"); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } @Override @@ -903,4 +772,10 @@ public class MultiTenancyTest extends AbstractServiceTestImpl { // TODO Auto-generated method stub throw new UnsupportedOperationException(); } + + @Override + protected Class getCommonListType() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException(); + } } diff --git a/services/taxonomy/client/pom.xml b/services/taxonomy/client/pom.xml index 42f2b3cdd..5f66bdc6a 100644 --- a/services/taxonomy/client/pom.xml +++ b/services/taxonomy/client/pom.xml @@ -59,7 +59,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java index 90cc6f74e..25d336904 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java @@ -26,10 +26,12 @@ */ package org.collectionspace.services.client; +import org.collectionspace.services.taxonomy.TaxonCommon; + /** * The Class TaxonomyAuthorityClient. */ -public class TaxonomyAuthorityClient extends AuthorityClientImpl { +public class TaxonomyAuthorityClient extends AuthorityClientImpl { public static final String SERVICE_NAME = "taxonomyauthority"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; @@ -67,4 +69,14 @@ public class TaxonomyAuthorityClient extends AuthorityClientImpl getProxyClass() { return TaxonomyAuthorityProxy.class; } + + @Override + public String getInAuthority(TaxonCommon item) { + return item.getInAuthority(); + } + + @Override + public void setInAuthority(TaxonCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } } diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java index f9c92a457..774bebbca 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java @@ -2,8 +2,6 @@ package org.collectionspace.services.client; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.Map; import javax.ws.rs.core.MediaType; @@ -21,7 +19,6 @@ import org.dom4j.DocumentException; import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.Assert; public class TaxonomyAuthorityClientUtils { diff --git a/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java index 4ed239c7f..8650b4c54 100644 --- a/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java +++ b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java @@ -22,12 +22,12 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.collectionspace.services.TaxonJAXBSchema; +import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; @@ -35,7 +35,7 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.TaxonomyAuthorityClient; import org.collectionspace.services.client.TaxonomyAuthorityClientUtils; -import org.collectionspace.services.common.AbstractCommonListUtils; +import org.collectionspace.services.client.TaxonomyAuthorityProxy; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.taxonomy.TaxonAuthorGroup; import org.collectionspace.services.taxonomy.TaxonAuthorGroupList; @@ -43,7 +43,6 @@ import org.collectionspace.services.taxonomy.TaxonCitationList; import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon; import org.collectionspace.services.taxonomy.TaxonCommon; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.jboss.resteasy.client.ClientResponse; @@ -61,7 +60,7 @@ import org.testng.annotations.Test; * $LastChangedRevision$ * $LastChangedDate$ */ -public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Taxonomy should have a base class! +public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest { /** The logger. */ private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName(); @@ -69,19 +68,6 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI private final String REFNAME = "refName"; private final String DISPLAYNAME = "displayName"; - @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_SHORTID = "CentauruspleurexanthemusGreen1832"; final String TEST_TERM_STATUS = "accepted"; final String TEST_TAXON_FULL_NAME = "Centaurus pleurexanthemus Green 1832"; @@ -97,132 +83,30 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI final String TEST_TAXON_IS_NAMED_HYBRID = "false"; final TaxonAuthorGroupList NULL_TAXON_AUTHOR_GROUP_LIST = null; final TaxonCitationList NULL_TAXON_CITATION_LIST = null; - /** The known resource id. */ - private String knownResourceId = null; + private String knownResourceShortIdentifer = null; - private String knownResourceRefName = null; private String knownTaxonomyTypeRefName = null; - private String knownItemResourceId = null; - private String knownItemResourceShortIdentifer = null; - /** The n items to create in list. */ - private int nItemsToCreateInList = 3; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); - /** The all item resource ids created. */ - private Map allItemResourceIdsCreated = - new HashMap(); - - 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; - } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() - */ @Override - protected CollectionSpaceClient getClientInstance() { - return new TaxonomyAuthorityClient(); + public String getServicePathComponent() { + return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT; } @Override - protected PoxPayloadOut createInstance(String identifier) { - 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; + protected String getServiceName() { + return TaxonomyAuthorityClient.SERVICE_NAME; } - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes + public String getItemServicePathComponent() { + return AuthorityClient.ITEMS; + } + /* (non-Javadoc) - * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create"}) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // 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); - final String EMPTY_REFNAME = ""; - PoxPayloadOut multipart = - TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance( - displayName, shortId, client.getCommonPartName()); - String newID = null; - ClientResponse 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); - } finally { - res.releaseConnection(); - } - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null) { - setKnownResource(newID, shortId, EMPTY_REFNAME); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(newID); - } - - /** - * Creates the item. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) - public void createItem(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupCreate(); - createItemInAuthority(knownResourceId, knownResourceRefName); + protected CollectionSpaceClient getClientInstance() { + return new TaxonomyAuthorityClient(); } /** @@ -236,7 +120,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI final String testName = "createItemInAuthority(" + vcsid + "," + authRefName + ")"; if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + logger.debug(getTestBanner(testName, CLASS_NAME)); } // Submit the request to the service and store the response. @@ -287,278 +171,112 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI // Store the IDs from any item resources created // by tests, along with the IDs of their parents, so these items // can be deleted after all tests have been run. - allItemResourceIdsCreated.put(newID, vcsid); + allResourceItemIdsCreated.put(newID, vcsid); return newID; } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) - */ - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) - */ - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) - */ - @Override - 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) - */ - @Override - @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); - } - } - - /** - * Creates the item list. - * - * @param testName the test name - * @throws Exception the exception - */ - @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++) { - createItem(testName); - } - } - - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnGroups = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - String newID = null; - ClientResponse res = client.read(knownResourceId); - try { - assertStatusCode(res, testName); - //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(); - } - } - - /** - * Read by name. - * - * @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 { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse res = client.readByName(knownResourceShortIdentifer); - try { - assertStatusCode(res, testName); - //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(); - } - } - /** - * Read item. + * Verify item display name. * * @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()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. + @Test(dataProvider = "testName", + dependsOnMethods = {"readItem", "updateItem"}) + public void verifyItemDisplayName(String testName) throws Exception { + // + // First read in our known resource + // + setupRead(); TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + TaxonCommon taxon = null; try { - assertStatusCode(res, testName); - // Check whether we've received an authority item record. + assertStatusCode(res, testName); + // Check whether taxon has expected displayName. PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - TaxonCommon taxon = (TaxonCommon) extractPart(input, + 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)); - } - - // Check that this authority item record has the correct identifier - // pointing to its parent authority record. - Assert.assertNotNull(taxon.getInAuthority(), "inAuthority field value is unexpectedly null."); - Assert.assertEquals(taxon.getInAuthority(), knownResourceId, - "Value of item's inAuthority field does not contain the correct identifier " - + "pointing to its parent authority record."); - - // Check individual fields in the authority item record. - Assert.assertNotNull(taxon.getTaxonFullName(), "Field value is unexpectedly null."); - Assert.assertEquals(taxon.getTaxonFullName(), TEST_TAXON_FULL_NAME, - "Field value " + taxon.getTaxonFullName() - + "does not match expected value " + TEST_TAXON_FULL_NAME); } finally { - res.releaseConnection(); + if (res != null) { + res.releaseConnection(); + } } - } - - /** - * Verify item display name. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem", "updateItem"}) - public void verifyItemDisplayName(String testName) throws Exception { + // + // Now setup for an update + // + String displayName = taxon.getDisplayName(); + // Make sure displayName matches computed form + String expectedDisplayName = + TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_TAXON_FULL_NAME); + Assert.assertNotNull(displayName, "Display name was null. Expected it to be: " + expectedDisplayName); + // Update the shortName and verify the computed name is updated. + taxon.setCsid(null); + taxon.setDisplayNameComputed(true); + taxon.setTaxonFullName("updated-" + TEST_TAXON_FULL_NAME); + expectedDisplayName = + TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_TAXON_FULL_NAME); + + // Create the update payload. + PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), taxon); - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. setupUpdate(); - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + TaxonCommon updatedTaxon = null; try { - assertStatusCode(res, testName); - // 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_TAXON_FULL_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_TAXON_FULL_NAME); - expectedDisplayName = - TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_TAXON_FULL_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); - assertStatusCode(res, testName); + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - TaxonCommon updatedTaxon = + PoxPayloadIn 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.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); - assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + // 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(client.getItemCommonPartName(), taxon); + setupUpdate(); // setup expected status code for result + res = client.updateItem(knownResourceId, knownItemResourceId, output); + try { + assertStatusCode(res, testName); // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn 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(); + if (res != null) { + res.releaseConnection(); + } } + // 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."); } /** @@ -567,66 +285,88 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"verifyItemDisplayName"}) + @Test(dataProvider = "testName", + dependsOnMethods = {"verifyItemDisplayName"}) public void verifyIllegalItemDisplayName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - - // Perform setup for read. + // + // First read in our known resource. + // setupRead(); - - // Submit the request to the service and store the response. TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - // Perform setup for update. - testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE); - + TaxonCommon taxon = null; try { + assertStatusCode(res, testName); // Check whether Taxonomy has expected displayName. PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - TaxonCommon taxon = (TaxonCommon) extractPart(input, + 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); - assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + // + // Try to Update with computed false and no displayName + // + taxon.setDisplayNameComputed(false); + taxon.setDisplayName(null); + + PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), taxon); + setupUpdateWithInvalidBody(); // we expect a failure here + res = client.updateItem(knownResourceId, knownItemResourceId, output); + try { + assertStatusCode(res, testName); } finally { res.releaseConnection(); } } - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + /** + * Read item list. */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) { + @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"; - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } // Perform setup. - setupReadNonExistent(); + setupReadList(); // Submit the request to the service and store the response. TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); + ClientResponse 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.getEntity(); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -634,142 +374,17 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI 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(); - } - } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); - /** - * Read item non existent. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readItem"}) - public void readItemNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse 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(); - } - } - - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnGroups = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse res = client.readList(); - try { - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } finally { - res.releaseConnection(); - } - } - - /** - * Read item list. - */ - @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) - public void readItemList() { - String testName = "readItemList"; - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - readItemList(knownResourceId, null); - } - - /** - * Read item list by authority name. - */ - @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) - public void readItemListByAuthorityName() { - String testName = "readItemListByAuthorityName"; - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - readItemList(null, knownResourceShortIdentifer); - } - - /** - * 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(); - ClientResponse 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.getEntity(); List items = list.getListItem(); 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, + // There will be 'nItemsToCreateInList' + // items created by the createItemList test, // all associated with the same parent resource. - int nExpectedItems = nItemsToCreateInList + 1; + int nExpectedItems = nItemsToCreateInList; if (logger.isDebugEnabled()) { logger.debug(testName + ": Expected " + nExpectedItems + " items; got: " + nItemsReturned); @@ -792,468 +407,28 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI } } - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) - */ - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnGroups = {"read", "readList"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse 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(); - } - } - - /** - * Update item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update"}) - public void updateItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse res = - client.readItem(knownResourceId, knownItemResourceId); - try { - assertStatusCode(res, testName); - 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); - assertStatusCode(res, testName); - - // 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 Taxon did not match submitted data."); - } finally { - res.releaseConnection(); - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) - */ - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) - */ @Override - public void updateWithMalformedXml(String testName) throws Exception { + public void delete(String testName) throws Exception { + // Do nothing. See localDelete(). This ensure proper test order. } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) - */ - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { + + @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } - - /* (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"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID(s) used when creating the request payload may be arbitrary. - // 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()); - ClientResponse 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(); - } - } - - /** - * Update non existent item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) - public void updateNonExistentItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // 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 nonexMap = new HashMap(); - nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME); - nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx"); - nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS); - // PoxPayloadOut multipart = - // TaxonomyAuthorityClientUtils.createTaxonInstance( - // TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"), - // nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST, - // client.getItemCommonPartName()); - final String EMPTY_REFNAME = ""; - PoxPayloadOut multipart = - TaxonomyAuthorityClientUtils.createTaxonInstance(EMPTY_REFNAME, - nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST, - client.getItemCommonPartName()); - ClientResponse 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(); - } - } - - // --------------------------------------------------------------- - // 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"}) public void deleteItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if (logger.isDebugEnabled()) { - logger.debug("parentcsid =" + knownResourceId - + " itemcsid = " + knownItemResourceId); - } - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse 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(); - } - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) - */ - @Override - // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - // groups = {"delete"}, dependsOnMethods = {"deleteItem"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - if (logger.isDebugEnabled()) { - logger.debug("parentcsid =" + knownResourceId); - } - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse 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(); - } - } - - // Failure outcomes - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) - */ - @Override - // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - // groups = {"delete"}, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse 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(); - } - } - - /** - * Delete non existent item. - * - * @param testName the test name - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) - public void deleteNonExistentItem(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); - ClientResponse 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(); - } - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - + // Do nothing. We need to wait until after the test "localDelete" gets run. When it does, + // its dependencies will get run first and then we can call the base class' delete method. } - - /** - * Test item submit request. - */ - @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) - public void testItemSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getItemResourceURL(knownResourceId, knownItemResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testItemSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS); - + + @Test(dataProvider = "testName", groups = {"delete"}, + dependsOnMethods = {"verifyIllegalItemDisplayName"}) + public void localDeleteItem(String testName) throws Exception { + super.deleteItem(testName); } - + // --------------------------------------------------------------- // Cleanup of resources created during testing // --------------------------------------------------------------- @@ -1283,7 +458,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); parentResourceId = knownResourceId; // Clean up item resources. - for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { itemResourceId = entry.getKey(); parentResourceId = entry.getValue(); // Note: Any non-success responses from the delete operation @@ -1338,4 +513,108 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) { return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier; } + + @Override + public void authorityTests(String testName) { + // TODO Auto-generated method stub + } + + // + // Taxonomy authority specific instances + // + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + String shortId = identifier; + String displayName = "displayName-" + shortId; + String baseRefName = + TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null); + PoxPayloadOut multipart = + TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance( + displayName, shortId, commonPartName); + return multipart; + } + + @Override + protected PoxPayloadOut createNonExistenceInstance(String commonPartName, String identifier) { + String displayName = "displayName-NON_EXISTENT_ID"; + PoxPayloadOut result = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance( + displayName, "nonEx", commonPartName); + return result; + } + + @Override + protected TaxonomyauthorityCommon updateInstance( + TaxonomyauthorityCommon taxonomyAuthority) { + TaxonomyauthorityCommon result = new TaxonomyauthorityCommon(); + + result.setDisplayName("updated-" + taxonomyAuthority.getDisplayName()); + result.setVocabType("updated-" + taxonomyAuthority.getVocabType()); + + return result; + } + + @Override + protected void compareUpdatedInstances(TaxonomyauthorityCommon original, + TaxonomyauthorityCommon updated) throws Exception { + // Verify that the updated resource received the correct data. + Assert.assertEquals(updated.getDisplayName(), + original.getDisplayName(), + "Display name in updated object did not match submitted data."); + } + + // + // Authority item specific overrides + // + + @Override + protected String createItemInAuthority(String authorityId) { + return createItemInAuthority(authorityId, null /*refname*/); + } + + @Override + protected TaxonCommon updateItemInstance(TaxonCommon authorityItem) { + TaxonCommon result = new TaxonCommon(); + + result.setDisplayName("updated-" + authorityItem.getTaxonFullName()); + result.setTaxonFullName("updated-" + authorityItem.getTaxonFullName()); + + return result; + } + + @Override + protected void compareUpdatedItemInstances(TaxonCommon original, + TaxonCommon updated) throws Exception { + Assert.assertEquals(updated.getTaxonFullName(), original.getTaxonFullName(), + "Taxon full name in updated Taxon did not match submitted data."); + } + + @Override + protected void verifyReadItemInstance(TaxonCommon item) throws Exception { + Assert.assertNotNull(item.getTaxonFullName(), "Field value is unexpectedly null."); + Assert.assertEquals(item.getTaxonFullName(), TEST_TAXON_FULL_NAME, + "Field value " + item.getTaxonFullName() + + "does not match expected value " + TEST_TAXON_FULL_NAME); + } + + @Override + protected PoxPayloadOut createNonExistenceItemInstance( + String commonPartName, String identifier) { + Map nonexMap = new HashMap(); + nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME); + nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx"); + nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS); + // PoxPayloadOut multipart = + // TaxonomyAuthorityClientUtils.createTaxonInstance( + // TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"), + // nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST, + // client.getItemCommonPartName()); + final String EMPTY_REFNAME = ""; + PoxPayloadOut result = + TaxonomyAuthorityClientUtils.createTaxonInstance(EMPTY_REFNAME, + nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST, + commonPartName); + return result; + } } diff --git a/services/taxonomy/service/pom.xml b/services/taxonomy/service/pom.xml index cbe760099..ba3946b05 100644 --- a/services/taxonomy/service/pom.xml +++ b/services/taxonomy/service/pom.xml @@ -52,7 +52,6 @@ org.testng testng - 5.6 diff --git a/services/vocabulary/client/pom.xml b/services/vocabulary/client/pom.xml index e78eeeefc..c1fbef4d1 100644 --- a/services/vocabulary/client/pom.xml +++ b/services/vocabulary/client/pom.xml @@ -44,7 +44,6 @@ org.testng testng - 5.6 org.jboss.resteasy diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java index 54d87bfb9..7aa09403c 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java @@ -26,10 +26,12 @@ */ package org.collectionspace.services.client; +import org.collectionspace.services.vocabulary.VocabularyitemsCommon; + /** * The Class VocabularyClient. */ -public class VocabularyClient extends AuthorityClientImpl { +public class VocabularyClient extends AuthorityClientImpl { public static final String SERVICE_NAME = "vocabularies"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -73,4 +75,14 @@ public class VocabularyClient extends AuthorityClientImpl { public String getCommonPartItemName() { return getCommonPartName(SERVICE_ITEM_PAYLOAD_NAME); } + + @Override + public void setInAuthority(VocabularyitemsCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } + + @Override + public String getInAuthority(VocabularyitemsCommon item) { + return item.getInAuthority(); + } } diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java index 5e62c178c..7bbc5c2ce 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java @@ -77,7 +77,7 @@ public class VocabularyClientUtils { +"\" in personAuthority: \"" + vcsid +"\""); } PoxPayloadOut multipart = createVocabularyItemInstance(null, //vocabularyRefName, - itemMap, client.getCommonPartItemName()); + itemMap, client.getItemCommonPartName()); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index ad183f898..0ed1d47b4 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -22,15 +22,9 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.collectionspace.services.client.AuthorityClient; -import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; @@ -38,15 +32,14 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.VocabularyClient; import org.collectionspace.services.client.VocabularyClientUtils; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.vocabulary.VocabulariesCommon; import org.collectionspace.services.vocabulary.VocabularyitemsCommon; import org.jboss.resteasy.client.ClientResponse; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.Test; /** @@ -56,7 +49,7 @@ import org.testng.annotations.Test; * $LastChangedRevision: 753 $ * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ */ -public class VocabularyServiceTest extends AbstractServiceTestImpl { +public class VocabularyServiceTest extends AbstractAuthorityServiceTest { private final String CLASS_NAME = VocabularyServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -64,23 +57,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { final String SERVICE_PATH_COMPONENT = VocabularyClient.SERVICE_PATH_COMPONENT;//"vocabularies"; final String SERVICE_PAYLOAD_NAME = VocabularyClient.SERVICE_PAYLOAD_NAME; final String SERVICE_ITEM_PAYLOAD_NAME = VocabularyClient.SERVICE_ITEM_PAYLOAD_NAME; - private String knownResourceId = null; - private String knownResourceShortIdentifer = null; - //private String knownResourceRefName = null; - //private String knownResourceFullRefName = null; - private String knownItemResourceId = null; - private int nItemsToCreateInList = 5; -// private List allResourceIdsCreated = new ArrayList(); -// private Map allResourceItemIdsCreated = -// new HashMap(); - protected void setKnownResource(String id, String shortIdentifer, - String refName, String fullRefName) { - knownResourceId = id; - knownResourceShortIdentifer = shortIdentifer; - //knownResourceRefName = refName; - //knownResourceFullRefName = fullRefName; - } /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() @@ -91,149 +68,24 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { } @Override - protected PoxPayloadOut createInstance(String identifier) { - VocabularyClient client = new VocabularyClient(); - String displayName = "displayName-" + identifier; - PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance( - displayName, identifier, client.getCommonPartName()); - return multipart; - } - - // --------------------------------------------------------------- - // CRUD tests : CREATE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup, such as initializing the type of service request - // (e.g. CREATE, DELETE), its valid and expected status codes, and - // its associated HTTP method name (e.g. POST, DELETE). - setupCreate(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - String identifier = createIdentifier(); - String displayName = "displayName-" + identifier; - PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance( - displayName, identifier, client.getCommonPartName()); - ClientResponse res = client.create(multipart); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null) { - setKnownResource(extractId(res), identifier, null, null ); - //VocabularyClientUtils.createVocabularyRefName(identifier, null), - //VocabularyClientUtils.createVocabularyRefName(identifier, displayName)); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } - } - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); - - } - - @Override - protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) { - String headerLabel = new VocabularyClient().getItemCommonPartName(); - HashMap vocabItemInfo = new HashMap(); - String shortId = createIdentifier(); - vocabItemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId); - vocabItemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId); - - return VocabularyClientUtils.createVocabularyItemInstance(identifier, vocabItemInfo, headerLabel); - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void createItem(String testName) { - - if (null != testName && logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreate(); - + protected String createItemInAuthority(String authorityId) { + String result = null; + VocabularyClient client = new VocabularyClient(); HashMap itemInfo = new HashMap(); String shortId = createIdentifier(); itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId); itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId); - String newID = VocabularyClientUtils.createItemInVocabulary(knownResourceId, + result = VocabularyClientUtils.createItemInVocabulary(authorityId, null /*knownResourceRefName*/, itemInfo, client); - - // Store the ID returned from the first item resource created - // for additional tests below. - if (knownItemResourceId == null) { - knownItemResourceId = newID; - if (null != testName && logger.isDebugEnabled()) { - logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); - } - } - // Store the IDs from any item resources created - // by tests, along with the IDs of their parents, so these items - // can be deleted after all tests have been run. - allResourceItemIdsCreated.put(newID, knownResourceId); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "createItem", "readItem"}) - public void createList(String testName) throws Exception { - for (int i = 0; i < 3; i++) { - // Force create to reset the known resource info - setKnownResource(null, null, null, null); - knownItemResourceId = null; - create(testName); - // Add nItemsToCreateInList items to each vocab - for (int j = 0; j < nItemsToCreateInList; j++) { - createItem(null); - } - } - } - - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { - } - - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { + allResourceItemIdsCreated.put(result, authorityId); + + return result; } - + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) + dependsOnMethods = {"CRUDTests"}) public void createWithBadShortId(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } testSetup(STATUS_BAD_REQUEST, ServiceRequestType.CREATE); // Submit the request to the service and store the response. @@ -241,29 +93,18 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance( "Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName()); ClientResponse res = client.create(multipart); - 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); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createItem"}) + dependsOnMethods = {"authorityTests"}) public void createItemWithBadShortId(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } setupCreateWithMalformedXml(); // Submit the request to the service and store the response. @@ -273,977 +114,222 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "Bad Item!"); PoxPayloadOut multipart = VocabularyClientUtils.createVocabularyItemInstance(null, //knownResourceRefName, - itemInfo, client.getCommonPartItemName()); + itemInfo, client.getItemCommonPartName()); ClientResponse res = client.createItem(knownResourceId, multipart); + try { + int statusCode = res.getStatus(); - int statusCode = res.getStatus(); - - if (!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME) - + "\" in personAuthority: \"" + knownResourceId //knownResourceRefName - + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - } - if (statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME) - + "\" in personAuthority: \"" + knownResourceId /*knownResourceRefName*/ + "\", Status:" + statusCode); - } - } - - /* - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithEmptyEntityBody(testName, CLASS_NAME); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()) { - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) - public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ - // --------------------------------------------------------------- - // CRUD tests : READ tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create"}) - public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.read(knownResourceId); - 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); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input, - client.getCommonPartName(), VocabulariesCommon.class); - - Assert.assertNotNull(vocabulary); - //Assert.assertEquals(vocabulary.getRefName(), knownResourceFullRefName); - } - - /** - * Read by name. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readByName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.readByName(knownResourceShortIdentifer); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input, - client.getCommonPartName(), VocabulariesCommon.class); - - Assert.assertNotNull(vocabulary); - } - - /* - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"read"}) - public void readByName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - ClientResponse res = client.read(knownResourceId); - int statusCode = res.getStatus(); - assertStatusCode(res, testName); - - //FIXME: remove the following try catch once Aron fixes signatures - try { - PoxPayloadIn input = (PoxPayloadIn) res.getEntity(); - VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input, - client.getCommonPartName(), VocabulariesCommon.class); - Assert.assertNotNull(vocabulary); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - */ - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createItem", "read"}) - public void readItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + if (!testRequestType.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME) + + "\" in personAuthority: \"" + knownResourceId //knownResourceRefName + + "\" " + invalidStatusCodeMessage(testRequestType, statusCode)); + } + if (statusCode != testExpectedStatusCode) { + throw new RuntimeException("Unexpected Status when creating Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME) + + "\" in personAuthority: \"" + knownResourceId /*knownResourceRefName*/ + "\", Status:" + statusCode); + } + } finally { + if (res != null) { + res.releaseConnection(); + } } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - // Check whether we've received a vocabulary item. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input, - client.getCommonPartItemName(), VocabularyitemsCommon.class); - Assert.assertNotNull(vocabularyItem); - Assert.assertEquals(vocabularyItem.getInAuthority(), knownResourceId); } - + // Failure outcomes @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"updateItem"}) + dependsOnMethods = {"updateItem"}) public void verifyIllegalItemDisplayName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup for read. setupRead(); // Submit the request to the service and store the response. VocabularyClient client = new VocabularyClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - // Perform setup for update. - testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE); - - // Check whether Person has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input, - client.getCommonPartItemName(), VocabularyitemsCommon.class); - Assert.assertNotNull(vitem); + VocabularyitemsCommon vitem = null; + try { + assertStatusCode(res, testName); + // Check whether Person has expected displayName. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + vitem = (VocabularyitemsCommon) extractPart(input, + client.getItemCommonPartName(), VocabularyitemsCommon.class); + Assert.assertNotNull(vitem); + } finally { + if (res != null) { + res.releaseConnection(); + } + } + // // Try to Update with null displayName + // + setupUpdateWithInvalidBody(); vitem.setDisplayName(null); - // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartItemName()); + PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), vitem); 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("updateItem: status = " + statusCode); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE, - "Expecting invalid message because of null displayName."); - + // // Now try to Update with 1-char displayName (too short) + // + setupUpdateWithInvalidBody(); vitem.setDisplayName("a"); - // Submit the updated resource to the service and store the response. output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME); - commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartItemName()); + commonPart = output.addPart(client.getItemCommonPartName(), vitem); 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, - "Expecting invalid message because of 1-char displayName."); - } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void readNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - 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); - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem", "readNonExistent"}) - public void readItemNonExistent(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadNonExistent(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.readItem(knownResourceId, NON_EXISTENT_ID); - 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); - } - // --------------------------------------------------------------- - // CRUD tests : READ_LIST tests - // --------------------------------------------------------------- - // Success outcomes - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "read"}) - public void readList(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.readList(); - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "readItem"}) - public void readItemList(String testName) { - readItemListInt(knownResourceId, null, testName); - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createList", "readItem"}) - public void readItemListByName(String testName) { - readItemListInt(null, knownResourceShortIdentifer, testName); - } - - private void readItemListInt(String vcsid, String shortId, String testName) { - - // Perform setup. - setupReadList(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = null; - if (vcsid != null) { - res = client.readItemList(vcsid, null, null); - } else if (shortId != null) { - res = client.readItemListForNamedAuthority(shortId, null, null); - } else { - Assert.fail("Internal Error: readItemList both vcsid and shortId are null!"); - } - assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); - - List items = list.getListItem(); - int nItemsReturned = items.size(); - long nItemsTotal = list.getTotalItems(); - if (logger.isDebugEnabled()) { - logger.debug(" " + testName + ": Expected " - + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal); - } - Assert.assertEquals(nItemsTotal, nItemsToCreateInList); - - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } - - // Failure outcomes - // None at present. - // --------------------------------------------------------------- - // CRUD tests : UPDATE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) - public void update(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = - client.read(knownResourceId); - assertStatusCode(res, testName); - - if (logger.isDebugEnabled()) { - logger.debug("got Vocabulary to update with ID: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input, - client.getCommonPartName(), VocabulariesCommon.class); - Assert.assertNotNull(vocabulary); - - // Update the contents of this resource. - vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName()); - vocabulary.setVocabType("updated-" + vocabulary.getVocabType()); - if (logger.isDebugEnabled()) { - logger.debug("to be updated Vocabulary"); - logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(SERVICE_PAYLOAD_NAME); - - PayloadOutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res = client.update(knownResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - VocabulariesCommon updatedVocabulary = - (VocabulariesCommon) extractPart(input, - client.getCommonPartName(), VocabulariesCommon.class); - Assert.assertNotNull(updatedVocabulary); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedVocabulary.getDisplayName(), - vocabulary.getDisplayName(), - "Data in updated object did not match submitted data."); - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem", "update", "verifyIgnoredUpdateWithInAuthority"}) - public void updateItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Retrieve the contents of a resource to update. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = - client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - if (logger.isDebugEnabled()) { - logger.debug("got VocabularyItem to update with ID: " - + knownItemResourceId - + " in Vocab: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input, - client.getCommonPartItemName(), VocabularyitemsCommon.class); - Assert.assertNotNull(vocabularyItem); - - // Update the contents of this resource. - vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName()); - if (logger.isDebugEnabled()) { - logger.debug("to be updated VocabularyItem"); - logger.debug(objectAsXmlString(vocabularyItem, - VocabularyitemsCommon.class)); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.releaseConnection(); + } } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartItemName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - VocabularyitemsCommon updatedVocabularyItem = - (VocabularyitemsCommon) extractPart(input, - client.getCommonPartItemName(), VocabularyitemsCommon.class); - Assert.assertNotNull(updatedVocabularyItem); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedVocabularyItem.getDisplayName(), - vocabularyItem.getDisplayName(), - "Data in updated VocabularyItem did not match submitted data."); } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem"}) - public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdate(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - assertStatusCode(res, testName); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input, - client.getCommonPartItemName(), VocabularyitemsCommon.class); - Assert.assertNotNull(vitem); - // Try to Update with new parent vocab (use self, for test). - Assert.assertEquals(vitem.getInAuthority(), - knownResourceId, - "VocabularyItem inAuthority does not match knownResourceId."); - vitem.setInAuthority(knownItemResourceId); - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartItemName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - assertStatusCode(res, testName); - - // Retrieve the updated resource and verify that the parent did not change - res = client.readItem(knownResourceId, knownItemResourceId); - input = new PoxPayloadIn(res.getEntity()); - VocabularyitemsCommon updatedVocabularyItem = - (VocabularyitemsCommon) extractPart(input, - client.getCommonPartItemName(), VocabularyitemsCommon.class); - Assert.assertNotNull(updatedVocabularyItem); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedVocabularyItem.getInAuthority(), - knownResourceId, - "VocabularyItem allowed update to the parent (inAuthority)."); + @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"}) + public void localDelete(String testName) throws Exception { + super.delete(testName); } - // Failure outcomes - // Placeholders until the three tests below can be uncommented. - // See Issue CSPACE-401. @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void updateWithMalformedXml(String testName) throws Exception { + public void delete(String testName) throws Exception { + // + // This overrides the base test. We don't want to do anything at this point + // in the test suite. See the localDelete() method for the actual "delete" test + // } - + @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } + public void deleteItem(String testName) throws Exception { + //Do nothing. We don't want to delete the known item until all the dependencies of the + // localDeleteItem() test have been fulfilled. + } + @Test(dataProvider = "testName", + dependsOnMethods = {"authorityTests", "readItemList", "testItemSubmitRequest", + "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"}) + public void localDeleteItem(String testName) throws Exception { + super.deleteItem(testName); + } + /* + * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may + * refer to this method in their @Test annotation declarations. + */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - + @Test(dataProvider = "testName", + dependsOnMethods = { + "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.baseAuthorityTests"}) + public void authorityTests(String testName) { + // This method only exists as a dependency target for TestNG + } + + // --------------------------------------------------------------- + // Vocabulary test specific overrides + // --------------------------------------------------------------- + @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; } @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) - public void updateWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + protected String getServiceName() { + return VocabularyClient.SERVICE_NAME; } - // Perform setup. - setupUpdateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateWithWrongXmlSchema: url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - */ + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + String displayName = "displayName-" + identifier; + PoxPayloadOut result = VocabularyClientUtils.createEnumerationInstance( + displayName, identifier, commonPartName); + return result; + } + @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); - - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - VocabularyClient client = new VocabularyClient(); - String displayName = "displayName-" + NON_EXISTENT_ID; - PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance( - displayName, NON_EXISTENT_ID, client.getCommonPartName()); - ClientResponse res = - client.update(NON_EXISTENT_ID, multipart); - 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); - } + protected PoxPayloadOut createInstance(String identifier) { + VocabularyClient client = new VocabularyClient(); + return createInstance(client.getCommonPartName(), identifier); + } - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) - public void updateNonExistentItem(String testName) throws Exception { + @Override + protected VocabulariesCommon updateInstance( + VocabulariesCommon vocabulariesCommon) { + VocabulariesCommon result = new VocabulariesCommon(); + + result.setDisplayName("updated-" + vocabulariesCommon.getDisplayName()); + result.setVocabType("updated-" + vocabulariesCommon.getVocabType()); + + return result; + } + + @Override + protected void compareUpdatedInstances(VocabulariesCommon original, + VocabulariesCommon updated) throws Exception { + Assert.assertEquals(updated.getDisplayName(), + original.getDisplayName(), + "Display name in updated object did not match submitted data."); + Assert.assertEquals(updated.getVocabType(), + original.getVocabType(), + "Vocabulary tyype name in updated object did not match submitted data."); + } + + // + // Vocabulary item specific overrides + // - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateNonExistent(); + @Override + protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) { + String headerLabel = new VocabularyClient().getItemCommonPartName(); + HashMap vocabItemInfo = new HashMap(); + String shortId = createIdentifier(); + vocabItemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId); + vocabItemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId); - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - VocabularyClient client = new VocabularyClient(); + return VocabularyClientUtils.createVocabularyItemInstance(identifier, vocabItemInfo, headerLabel); + } + + @Override + protected VocabularyitemsCommon updateItemInstance( + VocabularyitemsCommon authorityItem) { + VocabularyitemsCommon result = new VocabularyitemsCommon(); + result.setDisplayName("updated-" + authorityItem.getDisplayName()); + return result; + } + + @Override + protected void compareUpdatedItemInstances(VocabularyitemsCommon original, + VocabularyitemsCommon updated) throws Exception { + Assert.assertEquals(updated.getDisplayName(), + original.getDisplayName(), + "Display name in updated VocabularyItem did not match submitted data."); + } + + @Override + protected void verifyReadItemInstance(VocabularyitemsCommon item) + throws Exception { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createNonExistenceItemInstance( + String commonPartName, String identifier) { HashMap itemInfo = new HashMap(); itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "nonex"); itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-nonex"); - PoxPayloadOut multipart = + PoxPayloadOut result = VocabularyClientUtils.createVocabularyItemInstance( null, //VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null), - itemInfo, client.getCommonPartItemName()); - ClientResponse res = - client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); - 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); - } - - // --------------------------------------------------------------- - // CRUD tests : DELETE tests - // --------------------------------------------------------------- - // Success outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "deleteItem"}) - public void delete(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.delete(knownResourceId); - 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); - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest", - "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"}) - public void deleteItem(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("delete: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - - // Failure outcomes - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - 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); - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, - dependsOnMethods = {"deleteItem"}) - public void deleteNonExistentItem(String testName) { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupDeleteNonExistent(); - - // Submit the request to the service and store the response. - VocabularyClient client = new VocabularyClient(); - ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); - 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); - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - /** - * Tests the code for manually submitting data that is used by several - * of the methods above. - */ - @Test(dependsOnMethods = {"create", "read"}) - public void testSubmitRequest() { - - // Expected status code: 200 OK - setupRead(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url - + " status=" + statusCode); - } - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - } - - @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) - public void testItemSubmitRequest() { - - // Expected status code: 200 OK - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); - - // Submit the request to the service and store the response. - String method = ServiceRequestType.READ.httpMethodName(); - String url = getItemResourceURL(knownResourceId, knownItemResourceId); - int statusCode = submitRequest(method, url); - - // Check the status code of the response: does it match - // the expected response(s)? - 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. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ -// @AfterClass(alwaysRun = true) -// public void cleanUp() { -// String noTest = System.getProperty("noTestCleanup"); -// 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 ..."); -// } -// VocabularyClient client = new VocabularyClient(); -// String vocabularyResourceId; -// String vocabularyItemResourceId; -// // Clean up vocabulary item resources. -// for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { -// vocabularyItemResourceId = entry.getKey(); -// vocabularyResourceId = entry.getValue(); -// // Note: Any non-success responses are ignored and not reported. -// client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection(); -// } -// // Clean up vocabulary resources. -// for (String resourceId : allResourceIdsCreated) { -// // Note: Any non-success responses are ignored and not reported. -// client.delete(resourceId).releaseConnection(); -// } -// -// } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- - @Override - public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; - } - - public String getServicePathItemsComponent() { - return AuthorityClient.ITEMS; - } - - /** - * Returns the root URL for a service. - * - * This URL consists of a base URL for all services, followed by - * a path component for the owning vocabulary, followed by the - * path component for the items. - * - * @return The root URL for a service. - */ - protected String getItemServiceRootURL(String parentResourceIdentifier) { - return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent(); - } - - /** - * Returns the URL of a specific resource managed by a service, and - * designated by an identifier (such as a universally unique ID, or UUID). - * - * @param resourceIdentifier An identifier (such as a UUID) for a resource. - * - * @return The URL of a specific resource managed by a service. - */ - protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) { - return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier; - } - - @Override - protected String getServiceName() { - return VocabularyClient.SERVICE_NAME; - } + itemInfo, commonPartName); + return result; + } + } diff --git a/services/vocabulary/service/pom.xml b/services/vocabulary/service/pom.xml index 6b0041c28..f43debd7b 100644 --- a/services/vocabulary/service/pom.xml +++ b/services/vocabulary/service/pom.xml @@ -53,7 +53,6 @@ org.testng testng - 5.6 diff --git a/services/workflow/client/pom.xml b/services/workflow/client/pom.xml index a71164c6a..8f386a73c 100644 --- a/services/workflow/client/pom.xml +++ b/services/workflow/client/pom.xml @@ -9,7 +9,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.workflow.client services.workflow.client @@ -51,7 +50,6 @@ org.testng testng - 5.6 org.jboss.resteasy @@ -75,7 +73,6 @@ commons-httpclient commons-httpclient - 3.1 diff --git a/services/workflow/client/src/test/java/org/collectionspace/services/client/test/WorkflowServiceTest.java b/services/workflow/client/src/test/java/org/collectionspace/services/client/test/WorkflowServiceTest.java index c007ea5a6..387685ee4 100644 --- a/services/workflow/client/src/test/java/org/collectionspace/services/client/test/WorkflowServiceTest.java +++ b/services/workflow/client/src/test/java/org/collectionspace/services/client/test/WorkflowServiceTest.java @@ -22,9 +22,6 @@ */ package org.collectionspace.services.client.test; - -import javax.ws.rs.core.Response; - import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; @@ -39,7 +36,6 @@ import org.collectionspace.services.dimension.DimensionsCommon; import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; -import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +45,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class WorkflowServiceTest extends AbstractServiceTestImpl { +public class WorkflowServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = WorkflowServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); @@ -70,158 +66,96 @@ public class WorkflowServiceTest extends AbstractServiceTestImpl { return new DimensionClient(); } - @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { - return response.getEntity(AbstractCommonList.class); - } - - @Override - public void createList(String testName) throws Exception { - //empty N/A - } + // + // Test overrides + // + + @Override + public void create(String testName) throws Exception { + String csid = this.createTestObject(testName); + if (this.knownResourceId == null) { + this.knownResourceId = csid; + } + } @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); setupRead(); DimensionClient client = new DimensionClient(); ClientResponse res = client.getWorkflow(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); - if (logger.isDebugEnabled() == true) { - logger.debug("Workflow payload is: " + input.getXmlPayload()); + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class); + if (logger.isDebugEnabled() == true) { + logger.debug("Workflow payload is: " + input.getXmlPayload()); + } + Assert.assertNotNull(workflowsCommon); + } finally { + if (res != null) { + res.releaseConnection(); + } } - Assert.assertNotNull(workflowsCommon); } - -// @Override -// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) -// public void readList(String testName) throws Exception { -// logger.debug(testBanner(testName, CLASS_NAME)); -// setupReadList(); -// WorkflowClient client = new WorkflowClient(); -// ClientResponse res = client.readList(); -// assertStatusCode(res, testName); -// AbstractCommonList list = res.getEntity(); -// if (logger.isDebugEnabled()) { -// List items = -// list.getListItem(); -// int i = 0; -// for(AbstractCommonList.ListItem item : items){ -// logger.debug(testName + ": list-item[" + i + "] " + -// item.toString()); -// i++; -// } -// } -// } + + // + // FIXME: REM - This test should be a subclass of BaseServiceTest and *not* AbstractPoxServiceTestImpl + // @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) public void update(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); setupUpdate(); updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWSTATE_APPROVED); } - - @Override -// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupUpdateNonExistent(); - // Submit the request to the service and store the response. - // Note: The ID used in this 'create' call may be arbitrary. - // The only relevant ID may be the one used in update(), below. - WorkflowClient client = new WorkflowClient(); - PoxPayloadOut multipart = createDimensionInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - assertStatusCode(res, testName); - } - @Override -// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) public void delete(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDelete(); - WorkflowClient client = new WorkflowClient(); - ClientResponse res = client.delete(knownResourceId); - assertStatusCode(res, testName); - } - - // --------------------------------------------------------------- - // Failure outcome tests : means we expect response to fail, but test to succeed - // --------------------------------------------------------------- - - // Failure outcome - @Override -// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) - public void readNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupReadNonExistent(); - WorkflowClient client = new WorkflowClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcome - @Override -// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) - public void deleteNonExistent(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - setupDeleteNonExistent(); - WorkflowClient client = new WorkflowClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); - assertStatusCode(res, testName); - } - - // Failure outcomes - // Placeholders until the tests below can be implemented. See Issue CSPACE-401. - - @Override - public void createWithEmptyEntityBody(String testName) throws Exception { - } - - @Override - public void createWithMalformedXml(String testName) throws Exception { + // Do nothing. N/A } + + public void searchWorkflowDeleted(String testName) throws Exception { + // Do nothing. N/A + } - @Override - public void createWithWrongXmlSchema(String testName) throws Exception { - } + @Override + public void readList(String testName) throws Exception { + // Do nothing. N/A + } + + @Override + public void readPaginatedList(String testName) throws Exception { + // Do nothing. N/A + } - @Override - public void updateWithEmptyEntityBody(String testName) throws Exception { - } + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + } - @Override - public void updateWithMalformedXml(String testName) throws Exception { - } + @Override + protected WorkflowCommon updateInstance(WorkflowCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } - @Override - public void updateWithWrongXmlSchema(String testName) throws Exception { - } + @Override + protected void compareUpdatedInstances(WorkflowCommon original, + WorkflowCommon updated) throws Exception { + // TODO Auto-generated method stub + + } - // --------------------------------------------------------------- - // Search tests - // --------------------------------------------------------------- + /* + * (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ + @Override + public void createList(String testName) throws Exception { + //empty N/A + } - public void searchWorkflowDeleted(String testName) throws Exception { - } - - // --------------------------------------------------------------- - // Utility tests : tests of code used in tests above - // --------------------------------------------------------------- - -// @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() { - final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK - String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownResourceId); - int statusCode = submitRequest(method, url); - logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode); - Assert.assertEquals(statusCode, EXPECTED_STATUS); + // Do nothing. N/A } // --------------------------------------------------------------- @@ -230,17 +164,35 @@ public class WorkflowServiceTest extends AbstractServiceTestImpl { @Override protected PoxPayloadOut createInstance(String identifier) { - return createDimensionInstance(identifier); + String dimensionsCommonPartName = new DimensionClient().getCommonPartName(); + return createInstance(identifier, dimensionsCommonPartName); } + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return createDimensionInstance(commonPartName, identifier); + } + + /* + * We're using a DimensionsCommon instance to test the workflow service. + */ private PoxPayloadOut createDimensionInstance(String dimensionValue) { + String commonPartName = new DimensionClient().getCommonPartName(); + return createDimensionInstance(commonPartName, dimensionValue); + } + + /* + * We're using a DimensionsCommon instance to test the workflow service. + */ + private PoxPayloadOut createDimensionInstance(String commonPartName, + String dimensionValue) { String measurementUnit = "measurementUnit-" + dimensionValue; - String dimensionsCommonPartName = new DimensionClient().getCommonPartName(); DimensionsCommon dimensionsCommon = new DimensionsCommon(); dimensionsCommon.setMeasurementUnit(measurementUnit); PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(dimensionsCommonPartName, dimensionsCommon); + PayloadOutputPart commonPart = multipart.addPart(commonPartName, dimensionsCommon); if (logger.isDebugEnabled()) { logger.debug("To be created, Dimensions common: " + commonPart.asXML()); @@ -249,24 +201,5 @@ public class WorkflowServiceTest extends AbstractServiceTestImpl { return multipart; } - - @Override - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void create(String testName) throws Exception { - String csid = this.createTestObject(testName); - if (this.knownResourceId == null) { - this.knownResourceId = csid; - } - } - - - @Override - public void readList(String testName) throws Exception { - } - - @Override - public void readPaginatedList(String testName) throws Exception { - //empty N/A - } } diff --git a/services/workflow/service/pom.xml b/services/workflow/service/pom.xml index 76090dbb1..2f85981de 100644 --- a/services/workflow/service/pom.xml +++ b/services/workflow/service/pom.xml @@ -34,7 +34,6 @@ org.testng testng - 5.6