@AfterClass(alwaysRun = true)
@Override
public void cleanUp() {
- setupDelete("delete");
+ setupDelete("cleanUp");
String noTest = System.getProperty("noTestCleanup");
if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
* @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,
* @param accId the acc id
*/
private void deleteAccount(String accId) {
- setupDelete();
+ setupDelete("deleteAccount");
AccountClient accClient = new AccountClient();
ClientResponse<Response> res = accClient.delete(accId);
int statusCode = res.getStatus();
* @return the string
*/
private String createRole(String roleName) {
- setupCreate();
+ setupCreate("createRole");
RoleClient roleClient = new RoleClient();
Role role = RoleFactory.createRoleInstance(roleName,
* @param roleId the role id
*/
private void deleteRole(String roleId) {
- setupDelete();
+ setupDelete("deleteRole");
RoleClient roleClient = new RoleClient();
ClientResponse<Response> res = roleClient.delete(roleId);
int statusCode = res.getStatus();
dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
public void updateWrongUser(String testName) throws Exception {
- setupUpdate();
+ setupUpdate(testName);
// Submit the request to the service and store the response.
//
@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()) {
* @return the string
*/
private String createPermission(String resName, EffectType effect) {
- setupCreate();
+ setupCreate("createPermission");
PermissionClient permClient = new PermissionClient();
List<PermissionAction> actions = PermissionFactory.createDefaultActions();
Permission permission = PermissionFactory.createPermissionInstance(resName,
* @param permId the perm id
*/
private void deletePermission(String permId) {
- setupDelete();
+ setupDelete("deletePermission");
PermissionClient permClient = new PermissionClient();
ClientResponse<Response> res = permClient.delete(permId);
int statusCode = res.getStatus();
* @return the string
*/
private String createRole(String roleName) {
- setupCreate();
+ setupCreate("createRole");
RoleClient roleClient = new RoleClient();
Role role = RoleFactory.createRoleInstance(roleName,
* @param roleId the role id
*/
private void deleteRole(String roleId) {
- setupDelete();
+ setupDelete("deleteRole");
RoleClient roleClient = new RoleClient();
ClientResponse<Response> res = roleClient.delete(roleId);
int statusCode = res.getStatus();
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;
/* Use this to keep track of resources to delete */
protected List<String> allResourceIdsCreated = new ArrayList<String>();
-
+
/**
* Gets the logger.
*
/**
* 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)
/**
* 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)
/**
* 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)
/**
* 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);
}
// ---------------------------------------------------------------
/**
* 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
/**
* 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);
}
// ---------------------------------------------------------------
/**
* 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
/**
* 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
/**
* 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)
/**
* 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)
/**
* 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)
/**
* 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);
}
// ---------------------------------------------------------------
/**
* 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
/**
* 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);
}
// ---------------------------------------------------------------
public abstract class BaseServiceTest {\r
\r
//Maven's base directory -i.e., the one containing the current pom.xml\r
- static protected final String MAVEN_BASEDIR_PROPERTY = "maven.basedir";\r
+ protected static final String MAVEN_BASEDIR_PROPERTY = "maven.basedir";\r
/** The Constant logger. */\r
- static protected final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class);\r
+ private static final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class);\r
/** The Constant serviceClient. */\r
protected static final TestServiceClient serviceClient = new TestServiceClient();\r
/** The non-existent id. */\r
\r
protected final static String BANNER_SEPARATOR_LINE =\r
"===================================================";\r
-\r
+ protected final static String BANNER_PREFIX =\r
+ "\n" + BANNER_SEPARATOR_LINE + "\n";\r
+ protected final static String BANNER_SUFFIX =\r
+ "\n" + BANNER_SEPARATOR_LINE;\r
\r
/**\r
* Instantiates a new base service test.\r
*\r
* @param m The currently running test method.\r
*\r
- * @return The name of the currently running test method.\r
*/\r
@DataProvider(name = "testName")\r
public static Object[][] testName(Method m) {\r
REQUEST_TYPE = ServiceRequestType.NON_EXISTENT;\r
}\r
\r
-\r
- /**\r
- * Initializes setup values for a given test.\r
+ /**\r
+ * Initializes setup values for a given test, and prints a banner\r
+ * identifying the test being run, using the local logger for this class.\r
*\r
* @param expectedStatusCode A status code expected to be returned in the response.\r
*\r
* @param serviceRequestType A type of service request (e.g. CREATE, DELETE).\r
+ *\r
+ * @param testName The name of the test being run.\r
*/\r
protected void testSetup(\r
int expectedStatusCode,\r
- ServiceRequestType reqType) {\r
- String testName = null;\r
- testSetup(expectedStatusCode, reqType, testName);\r
+ ServiceRequestType reqType,\r
+ String testName) {\r
+ testSetup(expectedStatusCode, reqType, testName, null);\r
}\r
\r
/**\r
- * Initializes setup values for a given test.\r
+ * Initializes setup values for a given test, and prints a banner\r
+ * identifying the test being run, using a specified logger.\r
*\r
* @param expectedStatusCode A status code expected to be returned in the response.\r
*\r
* @param serviceRequestType A type of service request (e.g. CREATE, DELETE).\r
*\r
* @param testName The name of the test being run.\r
+ *\r
+ * @param testLogger An optional logger to use within the current base\r
+ * class, when generating log statements related to that test.\r
+ * If null, the logger of the current base class will be used.\r
*/\r
protected void testSetup(\r
int expectedStatusCode,\r
ServiceRequestType reqType,\r
- String testName) {\r
+ String testName,\r
+ Logger testLogger) {\r
+\r
+ testSetup(expectedStatusCode, reqType);\r
\r
- clearSetup();\r
- EXPECTED_STATUS_CODE = expectedStatusCode;\r
- REQUEST_TYPE = reqType;\r
- \r
// Print a banner identifying the test being run.\r
- if ((testName != null) && (! testName.trim().isEmpty())) {\r
- if (logger.isDebugEnabled()) {\r
- logger.debug(testBanner(testName));\r
+ //\r
+ // If an optional logger has been provided, such as by a\r
+ // calling class, use that logger to print the banner.\r
+ if (testLogger != null) {\r
+ if (testLogger.isDebugEnabled()) {\r
+ testLogger.debug(testBanner(testName, testLogger));\r
+ }\r
+ // Otherwise, use this base class's logger to print the banner.\r
+ } else {\r
+ testLogger = logger;\r
+ if (testLogger.isDebugEnabled()) {\r
+ testLogger.debug(testBanner(testName));\r
}\r
}\r
}\r
\r
+ /**\r
+ * Initializes setup values for a given test.\r
+ *\r
+ * @param expectedStatusCode A status code expected to be returned in the response.\r
+ *\r
+ * @param serviceRequestType A type of service request (e.g. CREATE, DELETE).\r
+ */\r
+ protected void testSetup(\r
+ int expectedStatusCode,\r
+ ServiceRequestType reqType) {\r
+ clearSetup();\r
+ EXPECTED_STATUS_CODE = expectedStatusCode;\r
+ REQUEST_TYPE = reqType;\r
+ }\r
+\r
/**\r
* Returns an error message indicating that the status code returned by a\r
* specific call to a service does not fall within a set of valid status\r
*/\r
protected static String testBanner(String testName) {\r
testName = (testName == null || testName.trim().isEmpty()) ?\r
- "Test = no test name specified" : " Test = " + testName;\r
+ " Test = no test name specified" : " Test = " + testName;\r
return banner(testName);\r
}\r
\r
/**\r
- * Returns text inside a banner.\r
+ * Returns a test-specific banner.\r
*\r
- * @param label The label to be output inside a banner.\r
+ * @param testName The name of a test method.\r
+ *\r
+ * @param testLogger An optional logger to use within the current base\r
+ * class, when generating log statements related to that test.\r
*\r
- * @return A banner.\r
+ * @return A test-specific banner.\r
+ */\r
+ protected static String testBanner(String testName, Logger testLogger) {\r
+ String testClass = testLogger.getName();\r
+ return testBanner(testName, testClass);\r
+ }\r
+\r
+ /**\r
+ * Returns a test-specific banner.\r
+ *\r
+ * @param testName The name of a test method.\r
+ *\r
+ * @param testClass The name of a test class.\r
+ *\r
+ * @return A test-specific banner.\r
+ */\r
+ protected static String testBanner(String testName, String testClass) {\r
+ testName = (testName == null || testName.trim().isEmpty()) ?\r
+ " Test = no test name specified" : " Test = " + testName;\r
+ testClass = (testClass == null || testClass.trim().isEmpty()) ?\r
+ "Class = no test class specified" : "Class = " + classNameFromPackageName(testClass);\r
+ String testLabel = testClass + "\n" + testName;\r
+ return banner(testLabel);\r
+ }\r
+\r
+ /**\r
+ * Returns a 'banner', consisting of a text label inside a pair of prefix\r
+ * and suffix strings.\r
+ *\r
+ * @param label The label to be output inside the banner.\r
+ *\r
+ * @return The banner.\r
*/\r
protected static String banner(String label) {\r
StringBuffer sb = new StringBuffer();\r
- sb.append("\n");\r
- sb.append(BANNER_SEPARATOR_LINE);\r
- sb.append("\n");\r
- sb.append(" " + label);\r
- sb.append("\n");\r
- sb.append(BANNER_SEPARATOR_LINE);\r
+ sb.append(BANNER_PREFIX);\r
+ sb.append(label);\r
+ sb.append(BANNER_SUFFIX);\r
return sb.toString();\r
}\r
+\r
+ protected static String classNameFromPackageName(String className) {\r
+ if (className == null || className.trim().isEmpty()) {\r
+ return className;\r
+ }\r
+ final char PKG_SEPARATOR = '.';\r
+ int pos = className.lastIndexOf(PKG_SEPARATOR) + 1;\r
+ if (pos > 0) {\r
+ className = className.substring(pos);\r
+ }\r
+ return className;\r
+ }\r
}\r
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();
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();
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();
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();
public void readByName(String testName) throws Exception {
// Perform setup.
- setupRead();
+ setupRead(testName);
// Submit the request to the service and store the response.
ClientResponse<MultipartInput> res = client.read(knownResourceId);
displayName, refName,
new OrgAuthorityClient().getCommonPartName());
}
-}
\ No newline at end of file
+}
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. */
// 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()
*/
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 {
// 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();
}
/**
- * 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).");
}
/**
- * 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 ...
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();
// 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;
}
/**
- * 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();
return SERVICE_PATH_COMPONENT;
}
+
// ---------------------------------------------------------------
// Utilities: setup routines for search tests
// ---------------------------------------------------------------
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();
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();
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();
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();
public void readByName(String testName) throws Exception {
// Perform setup.
- setupRead();
+ setupRead(testName);
// Submit the request to the service and store the response.
ClientResponse<MultipartInput> res = client.read(knownResourceId);