From: Aron Roberts Date: Wed, 26 May 2010 04:09:38 +0000 (+0000) Subject: CSPACE-1911: In client test framework, 'banner' signifying the start of a test can... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=3d28fc6d43213561707a1a7ef37d187806563172;p=tmp%2Fjakarta-migration.git CSPACE-1911: In client test framework, 'banner' signifying the start of a test can now be output using a passed-in Logger. This reflects the caller's class name and line number in the log statement, and can also print the class name in the banner. Examples of such calls are implemented, for now, only in PersonAuthoritySearchTest, but can be trivially bulk-implemented in all other test classes. --- 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 a64c61ee2..453ed93a9 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 @@ -482,7 +482,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { @AfterClass(alwaysRun = true) @Override public void cleanUp() { - setupDelete("delete"); + setupDelete("cleanUp"); String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { @@ -529,7 +529,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @return the string */ private String createAccount(String userName, String email) { - setupCreate(); + setupCreate("createAccount"); AccountClient accClient = new AccountClient(); AccountsCommon account = AccountFactory.createAccountInstance( userName, userName, userName, email, @@ -553,7 +553,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @param accId the acc id */ private void deleteAccount(String accId) { - setupDelete(); + setupDelete("deleteAccount"); AccountClient accClient = new AccountClient(); ClientResponse res = accClient.delete(accId); int statusCode = res.getStatus(); @@ -577,7 +577,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @return the string */ private String createRole(String roleName) { - setupCreate(); + setupCreate("createRole"); RoleClient roleClient = new RoleClient(); Role role = RoleFactory.createRoleInstance(roleName, @@ -601,7 +601,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { * @param roleId the role id */ private void deleteRole(String roleId) { - setupDelete(); + setupDelete("deleteRole"); RoleClient roleClient = new RoleClient(); ClientResponse res = roleClient.delete(roleId); int statusCode = res.getStatus(); 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 91268ad99..123230c00 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 @@ -992,7 +992,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"}) public void updateWrongUser(String testName) throws Exception { - setupUpdate(); + setupUpdate(testName); // Submit the request to the service and store the response. // 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 2471d408e..c2121a313 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 @@ -472,7 +472,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { @AfterClass(alwaysRun = true) @Override public void cleanUp() { - setupDelete("cleanup"); + setupDelete("cleanUp"); String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -518,7 +518,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @return the string */ private String createPermission(String resName, EffectType effect) { - setupCreate(); + setupCreate("createPermission"); PermissionClient permClient = new PermissionClient(); List actions = PermissionFactory.createDefaultActions(); Permission permission = PermissionFactory.createPermissionInstance(resName, @@ -543,7 +543,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @param permId the perm id */ private void deletePermission(String permId) { - setupDelete(); + setupDelete("deletePermission"); PermissionClient permClient = new PermissionClient(); ClientResponse res = permClient.delete(permId); int statusCode = res.getStatus(); @@ -568,7 +568,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @return the string */ private String createRole(String roleName) { - setupCreate(); + setupCreate("createRole"); RoleClient roleClient = new RoleClient(); Role role = RoleFactory.createRoleInstance(roleName, @@ -592,7 +592,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { * @param roleId the role id */ private void deleteRole(String roleId) { - setupDelete(); + setupDelete("deleteRole"); RoleClient roleClient = new RoleClient(); ClientResponse res = roleClient.delete(roleId); int statusCode = res.getStatus(); 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 2fd5e344c..c4dfb7efa 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 @@ -54,7 +54,10 @@ import org.testng.annotations.Test; public abstract class AbstractServiceTestImpl extends BaseServiceTest implements ServiceTest { /** The logger. */ - protected final Logger logger = LoggerFactory.getLogger(AbstractServiceTestImpl.class); + 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; @@ -62,7 +65,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /* Use this to keep track of resources to delete */ protected List allResourceIdsCreated = new ArrayList(); - + /** * Gets the logger. * @@ -88,20 +91,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up create tests. + * + * @param testName The name of the test being run. */ - protected void setupCreate() { - setupCreate("Create"); + protected void setupCreate(String testName) { + setupCreate(testName, LOGGER_NULL); } /** * Sets up create tests. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupCreate(String label) { + protected void setupCreate(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } /* (non-Javadoc) @@ -124,20 +132,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up create tests with empty entity body. + * + * @param testName The name of the test being run. */ - protected void setupCreateWithEmptyEntityBody() { - setupCreateWithEmptyEntityBody("CreateWithEmptyEntityBody"); + protected void setupCreateWithEmptyEntityBody(String testName) { + setupCreateWithEmptyEntityBody(testName, LOGGER_NULL); } /** * Sets up create tests with empty entity body. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupCreateWithEmptyEntityBody(String label) { + protected void setupCreateWithEmptyEntityBody(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } /* (non-Javadoc) @@ -148,20 +161,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up create tests with malformed xml. + * + * @param testName The name of the test being run. */ - protected void setupCreateWithMalformedXml() { - setupCreateWithMalformedXml("CreateWithMalformedXml"); + protected void setupCreateWithMalformedXml(String testName) { + setupCreateWithMalformedXml(testName, LOGGER_NULL); } /** * Sets up create tests with malformed xml. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupCreateWithMalformedXml(String label) { + protected void setupCreateWithMalformedXml(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } /* (non-Javadoc) @@ -172,20 +190,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up create tests with wrong xml schema. + * + * @param testName The name of the test being run. */ - protected void setupCreateWithWrongXmlSchema() { - setupCreateWithWrongXmlSchema("CreateWithWrongXmlSchema"); + protected void setupCreateWithWrongXmlSchema(String testName) { + setupCreateWithWrongXmlSchema(testName, LOGGER_NULL); } /** * Sets up create tests with wrong xml schema. * - * @param label the new up create with wrong xml schema + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupCreateWithWrongXmlSchema(String label) { + protected void setupCreateWithWrongXmlSchema(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); REQUEST_TYPE = ServiceRequestType.CREATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // --------------------------------------------------------------- @@ -202,20 +225,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up read tests. + * + * @param testName The name of the test being run. */ - protected void setupRead() { - setupRead("Read"); + protected void setupRead(String testName) { + setupRead(testName, LOGGER_NULL); } /** * Sets up read tests. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupRead(String label) { + protected void setupRead(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); REQUEST_TYPE = ServiceRequestType.READ; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // Failure outcomes @@ -228,20 +256,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up read non existent tests. + * + * @param testName The name of the test being run. */ - protected void setupReadNonExistent() { - setupReadNonExistent("ReadNonExistent"); + protected void setupReadNonExistent(String testName) { + setupReadNonExistent(testName, LOGGER_NULL); } /** * Sets up read non existent tests. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupReadNonExistent(String label) { + protected void setupReadNonExistent(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode(); REQUEST_TYPE = ServiceRequestType.READ; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // --------------------------------------------------------------- @@ -260,20 +293,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up read list tests. + * + * @param testName The name of the test being run. */ - protected void setupReadList() { - setupReadList("ReadList"); + protected void setupReadList(String testName) { + setupReadList(testName, LOGGER_NULL); } /** * Sets up read list tests. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupReadList(String label) { + protected void setupReadList(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); REQUEST_TYPE = ServiceRequestType.READ_LIST; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // Failure outcomes @@ -294,20 +332,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up update tests. + * + * @param testName The name of the test being run. */ - protected void setupUpdate() { - setupUpdate("Update"); + protected void setupUpdate(String testName) { + setupUpdate(testName, LOGGER_NULL); } /** * Sets up update tests. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupUpdate(String label) { + protected void setupUpdate(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // Failure outcomes @@ -320,20 +363,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up update tests with an empty entity body. + * + * @param testName The name of the test being run. */ - protected void setupUpdateWithEmptyEntityBody() { - setupUpdateWithEmptyEntityBody("UpdateWithEmptyEntityBody"); + protected void setupUpdateWithEmptyEntityBody(String testName) { + setupUpdateWithEmptyEntityBody(testName, LOGGER_NULL); } /** * Sets up update tests with an empty entity body. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupUpdateWithEmptyEntityBody(String label) { + protected void setupUpdateWithEmptyEntityBody(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } /* (non-Javadoc) @@ -344,20 +392,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up update tests with malformed xml. + * + * @param testName The name of the test being run. */ - protected void setupUpdateWithMalformedXml() { - setupUpdateWithMalformedXml("UpdateWithMalformedXml"); + protected void setupUpdateWithMalformedXml(String testName) { + setupUpdateWithMalformedXml(testName, LOGGER_NULL); } /** * Sets up update tests with malformed xml. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupUpdateWithMalformedXml(String label) { + protected void setupUpdateWithMalformedXml(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } /* (non-Javadoc) @@ -368,20 +421,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up update tests with wrong xml schema. + * + * @param testName The name of the test being run. */ - protected void setupUpdateWithWrongXmlSchema() { - setupUpdateWithWrongXmlSchema("UpdateWithWrongXmlSchema"); + protected void setupUpdateWithWrongXmlSchema(String testName) { + setupUpdateWithWrongXmlSchema(testName, LOGGER_NULL); } /** * Sets up update tests with wrong xml schema. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupUpdateWithWrongXmlSchema(String label) { + protected void setupUpdateWithWrongXmlSchema(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } /* (non-Javadoc) @@ -392,20 +450,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up update non existent tests. + * + * @param testName The name of the test being run. */ - protected void setupUpdateNonExistent() { - setupUpdateNonExistent("UpdateNonExistent"); + protected void setupUpdateNonExistent(String testName) { + setupUpdateNonExistent(testName, LOGGER_NULL); } /** * Sets up update non existent tests * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupUpdateNonExistent(String label) { + protected void setupUpdateNonExistent(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode(); REQUEST_TYPE = ServiceRequestType.UPDATE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // --------------------------------------------------------------- @@ -422,20 +485,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up delete tests. + * + * @param testName The name of the test being run. */ - protected void setupDelete() { - setupDelete("Delete"); + protected void setupDelete(String testName) { + setupDelete(testName, LOGGER_NULL); } /** * Sets up delete tests. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupDelete(String label) { + protected void setupDelete(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); REQUEST_TYPE = ServiceRequestType.DELETE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // Failure outcomes @@ -448,20 +516,25 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** * Sets up delete non existent tests. + * + * @param testName The name of the test being run. */ - protected void setupDeleteNonExistent() { - setupDeleteNonExistent("DeleteNonExistent"); + protected void setupDeleteNonExistent(String testName) { + setupDeleteNonExistent(testName, LOGGER_NULL); } /** * Sets up delete non existent tests. * - * @param label A label to be displayed prior to running this test. + * @param testName The name of the test being run. + * + * @param testLogger The logger to use within the current base class, + * when generating log statements related to that test. */ - protected void setupDeleteNonExistent(String label) { + protected void setupDeleteNonExistent(String testName, Logger testLogger) { EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode(); REQUEST_TYPE = ServiceRequestType.DELETE; - testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label); + testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, testName, testLogger); } // --------------------------------------------------------------- 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 98f826d4b..256011ed1 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 @@ -72,9 +72,9 @@ import org.collectionspace.services.jaxb.AbstractCommonList; public abstract class BaseServiceTest { //Maven's base directory -i.e., the one containing the current pom.xml - static protected final String MAVEN_BASEDIR_PROPERTY = "maven.basedir"; + protected static final String MAVEN_BASEDIR_PROPERTY = "maven.basedir"; /** The Constant logger. */ - static protected final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class); + private static final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class); /** The Constant serviceClient. */ protected static final TestServiceClient serviceClient = new TestServiceClient(); /** The non-existent id. */ @@ -96,7 +96,10 @@ public abstract class BaseServiceTest { protected final static String BANNER_SEPARATOR_LINE = "==================================================="; - + protected final static String BANNER_PREFIX = + "\n" + BANNER_SEPARATOR_LINE + "\n"; + protected final static String BANNER_SUFFIX = + "\n" + BANNER_SEPARATOR_LINE; /** * Instantiates a new base service test. @@ -129,7 +132,6 @@ public abstract class BaseServiceTest { * * @param m The currently running test method. * - * @return The name of the currently running test method. */ @DataProvider(name = "testName") public static Object[][] testName(Method m) { @@ -157,47 +159,77 @@ public abstract class BaseServiceTest { REQUEST_TYPE = ServiceRequestType.NON_EXISTENT; } - - /** - * Initializes setup values for a given test. + /** + * Initializes setup values for a given test, and prints a banner + * identifying the test being run, using the local logger for this class. * * @param expectedStatusCode A status code expected to be returned in the response. * * @param serviceRequestType A type of service request (e.g. CREATE, DELETE). + * + * @param testName The name of the test being run. */ protected void testSetup( int expectedStatusCode, - ServiceRequestType reqType) { - String testName = null; - testSetup(expectedStatusCode, reqType, testName); + ServiceRequestType reqType, + String testName) { + testSetup(expectedStatusCode, reqType, testName, null); } /** - * Initializes setup values for a given test. + * Initializes setup values for a given test, and prints a banner + * identifying the test being run, using a specified logger. * * @param expectedStatusCode A status code expected to be returned in the response. * * @param serviceRequestType A type of service request (e.g. CREATE, DELETE). * * @param testName The name of the test being run. + * + * @param testLogger An optional logger to use within the current base + * class, when generating log statements related to that test. + * If null, the logger of the current base class will be used. */ protected void testSetup( int expectedStatusCode, ServiceRequestType reqType, - String testName) { + String testName, + Logger testLogger) { + + testSetup(expectedStatusCode, reqType); - clearSetup(); - EXPECTED_STATUS_CODE = expectedStatusCode; - REQUEST_TYPE = reqType; - // Print a banner identifying the test being run. - if ((testName != null) && (! testName.trim().isEmpty())) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); + // + // If an optional logger has been provided, such as by a + // calling class, use that logger to print the banner. + if (testLogger != null) { + if (testLogger.isDebugEnabled()) { + testLogger.debug(testBanner(testName, testLogger)); + } + // Otherwise, use this base class's logger to print the banner. + } else { + testLogger = logger; + if (testLogger.isDebugEnabled()) { + testLogger.debug(testBanner(testName)); } } } + /** + * Initializes setup values for a given test. + * + * @param expectedStatusCode A status code expected to be returned in the response. + * + * @param serviceRequestType A type of service request (e.g. CREATE, DELETE). + */ + protected void testSetup( + int expectedStatusCode, + ServiceRequestType reqType) { + clearSetup(); + EXPECTED_STATUS_CODE = expectedStatusCode; + REQUEST_TYPE = reqType; + } + /** * Returns an error message indicating that the status code returned by a * specific call to a service does not fall within a set of valid status @@ -558,25 +590,68 @@ public abstract class BaseServiceTest { */ protected static String testBanner(String testName) { testName = (testName == null || testName.trim().isEmpty()) ? - "Test = no test name specified" : " Test = " + testName; + " Test = no test name specified" : " Test = " + testName; return banner(testName); } /** - * Returns text inside a banner. + * Returns a test-specific banner. * - * @param label The label to be output inside a banner. + * @param testName The name of a test method. + * + * @param testLogger An optional logger to use within the current base + * class, when generating log statements related to that test. * - * @return A banner. + * @return A test-specific banner. + */ + protected static String testBanner(String testName, Logger testLogger) { + String testClass = testLogger.getName(); + return testBanner(testName, testClass); + } + + /** + * Returns a test-specific banner. + * + * @param testName The name of a test method. + * + * @param testClass The name of a test class. + * + * @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; + testClass = (testClass == null || testClass.trim().isEmpty()) ? + "Class = no test class specified" : "Class = " + classNameFromPackageName(testClass); + String testLabel = testClass + "\n" + testName; + return banner(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("\n"); - sb.append(BANNER_SEPARATOR_LINE); - sb.append("\n"); - sb.append(" " + label); - sb.append("\n"); - sb.append(BANNER_SEPARATOR_LINE); + sb.append(BANNER_PREFIX); + sb.append(label); + sb.append(BANNER_SUFFIX); return sb.toString(); } + + protected static String classNameFromPackageName(String className) { + if (className == null || className.trim().isEmpty()) { + return className; + } + final char PKG_SEPARATOR = '.'; + int pos = className.lastIndexOf(PKG_SEPARATOR) + 1; + if (pos > 0) { + className = className.substring(pos); + } + return className; + } } 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 83fd1e9fd..c7aa0dd04 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 @@ -344,7 +344,7 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { public void read(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); @@ -381,7 +381,7 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { public void readByName(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); 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 00a58f8f8..da318a55f 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 @@ -484,7 +484,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { public void read(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); @@ -525,7 +525,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { public void readByName(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); @@ -561,7 +561,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { public void readByName(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. ClientResponse res = client.read(knownResourceId); @@ -1978,4 +1978,4 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { displayName, refName, new OrgAuthorityClient().getCommonPartName()); } -} \ No newline at end of file +} 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 06cd8a5ca..e443935cf 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 @@ -69,7 +69,8 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { final String TEST_PARTIAL_TERM_DISPLAY_NAME = TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME; - // Non-existent test name for partial term matching + // Non-existent partial term name (first letters of each of the words + // in a pangram for the English alphabet). private static final String TEST_PARTIAL_TERM_NON_EXISTENT = "jlmbsoq"; /** The known resource id. */ @@ -93,6 +94,10 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { // The number of matches expected on each partial term. final int NUM_MATCHES_EXPECTED = 1; + // The minimum number of characters that must be included + // a partial term, in order to permit matching to occur. + final int PARTIAL_TERM_MIN_LENGTH = 1; + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -122,6 +127,18 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { return TEST_PARTIAL_TERM_NON_EXISTENT; } + private String getPartialTermMinimumLength() { + String partialTerm = getPartialTerm(); + if (partialTerm == null || partialTerm.trim().isEmpty()) { + return partialTerm; + } + if (getPartialTerm().length() > PARTIAL_TERM_MIN_LENGTH) { + return partialTerm.substring(0, PARTIAL_TERM_MIN_LENGTH); + } else { + return partialTerm; + } + } + @BeforeClass public void setup() { try { @@ -143,13 +160,13 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { // Success outcomes /** - * Read item list by partial term. + * Reads an item list by partial term. */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"readListByPartialTerm"}) public void partialTermMatch(String testName) { if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); + logger.debug(testBanner(testName, logger)); } int numMatchesFound = 0; String partialTerm = getPartialTerm(); @@ -165,36 +182,50 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { } /** - * Read item list by partial term, where the match is case-insensitive. - * Tests by attempting a partial match on all-lowercase and all-uppercase - * variations of the partial term. + * Reads an item list by partial term, with a partial term that consists + * of an all-lowercase variation of the expected match, to test case-insensitive + * matching. */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) - public void partialTermMatchCaseInsensitive(String testName) { + public void partialTermMatchCaseInsensitiveLowerCase(String testName) { if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); + logger.debug(testBanner(testName, logger)); } int numMatchesFound = 0; - final String PARTIAL_TERM_LOWERCASE = getPartialTerm().toLowerCase(); + final String partialTerm = getPartialTerm().toLowerCase(); if (logger.isDebugEnabled()) { - logger.debug("Attempting match on partial term '" + PARTIAL_TERM_LOWERCASE + "' ..."); + logger.debug("Attempting match on partial term '" + partialTerm + "' ..."); } numMatchesFound = - readItemListByPartialTerm(knownResourceId, PARTIAL_TERM_LOWERCASE); + readItemListByPartialTerm(knownResourceId, partialTerm); if (logger.isDebugEnabled()) { logger.debug("Found " + numMatchesFound + " match(es), expected " + NUM_MATCHES_EXPECTED + " match(es)."); } Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED); + } - final String PARTIAL_TERM_UPPERCASE = getPartialTerm().toUpperCase(); + /** + * Reads an item list by partial term, with a partial term that consists + * of an all-uppercase variation of the expected match, to test case-insensitive + * matching. + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) + public void partialTermMatchCaseInsensitiveUpperCase(String testName) { + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, logger)); + } + int numMatchesFound = 0; + + final String partialTerm = getPartialTerm().toUpperCase(); if (logger.isDebugEnabled()) { - logger.debug("Attempting match on partial term '" + PARTIAL_TERM_UPPERCASE + "' ..."); + logger.debug("Attempting match on partial term '" + partialTerm + "' ..."); } numMatchesFound = - readItemListByPartialTerm(knownResourceId, PARTIAL_TERM_UPPERCASE); + readItemListByPartialTerm(knownResourceId, partialTerm); if (logger.isDebugEnabled()) { logger.debug("Found " + numMatchesFound + " match(es), expected " + NUM_MATCHES_EXPECTED + " match(es)."); @@ -203,8 +234,32 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { } /** - * Read item list by partial term, with at least one Unicode UTF-8 character - * (outside the USASCII range) in the partial term. + * 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, + groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) + public void partialTermMatchMinimumLength(String testName) { + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, logger)); + } + int numMatchesFound = 0; + String partialTerm = getPartialTermMinimumLength(); + if (logger.isDebugEnabled()) { + logger.debug("Attempting match on partial term '" + partialTerm + "' ..."); + } + numMatchesFound = readItemListByPartialTerm(knownResourceId, partialTerm); + // Zero matches are expected on a non-existent term. + if (logger.isDebugEnabled()) { + logger.debug("Found " + numMatchesFound + " match(es), expected " + + NUM_MATCHES_EXPECTED + " match(es)."); + } + Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED); + } + + /** + * Reads an item list by partial term, with a partial term that contains + * at least one Unicode UTF-8 character (outside the USASCII range). */ // FIXME: Test currently fails with a true UTF-8 String - need to investigate why. // Will be commented out for now until we get this working ... @@ -213,7 +268,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchUTF8(String testName) { if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); + logger.debug(testBanner(testName, logger)); } int numMatchesFound = 0; String partialTerm = getPartialTermUtf8(); @@ -233,14 +288,14 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { // Failure outcomes /** - * Read item list by partial term, where the partial term is not + * 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 = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"}) public void partialTermMatchOnNonexistentTerm(String testName) { if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName)); + logger.debug(testBanner(testName, logger)); } int numMatchesFound = 0; int ZERO_MATCHES_EXPECTED = 0; @@ -258,21 +313,20 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { } /** - * Read item list by partial term. + * Reads an item list by partial term, given an authority and a term. * - * @param testName The name of the test which has invoked this method. * @param authorityCsid The CSID of the authority within which partial term matching * will be performed. * @param partialTerm A partial term to match item resources. * @return The number of item resources matched by the partial term. */ - private int readItemListByPartialTerm( String authorityCsid, String partialTerm) { + private int readItemListByPartialTerm(String authorityCsid, String partialTerm) { // Perform setup. int expectedStatusCode = Response.Status.OK.getStatusCode(); ServiceRequestType requestType = ServiceRequestType.READ_LIST; String testName = "readItemListByPartialTerm"; - testSetup(expectedStatusCode, requestType); + testSetup(expectedStatusCode, requestType, testName, logger); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); @@ -362,6 +416,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { return SERVICE_PATH_COMPONENT; } + // --------------------------------------------------------------- // Utilities: setup routines for search tests // --------------------------------------------------------------- @@ -372,7 +427,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { int expectedStatusCode = Response.Status.CREATED.getStatusCode(); ServiceRequestType requestType = ServiceRequestType.CREATE; String testName = "createPersonAuthority"; - testSetup(expectedStatusCode, requestType, testName); + testSetup(expectedStatusCode, requestType, testName, logger); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); 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 257c299c1..0b1da65d6 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 @@ -525,7 +525,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { public void read(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); @@ -565,7 +565,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { public void readByName(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); 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 73b7af6a9..7fc7e720e 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 @@ -291,7 +291,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { public void read(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. VocabularyClient client = new VocabularyClient(); @@ -323,7 +323,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { public void readByName(String testName) throws Exception { // Perform setup. - setupRead(); + setupRead(testName); // Submit the request to the service and store the response. ClientResponse res = client.read(knownResourceId);