final Logger logger = LoggerFactory.getLogger(AbstractServiceTest.class);
- // Currently used for performing several negative (failure) tests.
+ // An HTTP client, used for performing several negative (failure) tests.
//
- // @TODO To be replaced with RESTeasy's ClientRequest, per Issue CSPACE-386.
+ // @TODO To be replaced with RESTeasy's ClientRequest (a higher-level API
+ // that is based on HttpClient), per Issue CSPACE-386.
protected HttpClient httpClient = new HttpClient();
- // Used (only) to obtain the base service URL.
- private final TestServiceClient serviceClient = new TestServiceClient();
+ // A base-level client, used (only) to obtain the base service URL.
+ private static final TestServiceClient serviceClient = new TestServiceClient();
- // The status code expected to be returned by a test method (where relevant).
+ // A resource identifier believed to be non-existent in actual use,
+ // used when testing service calls that reference non-existent resources.
+ protected final String NON_EXISTENT_ID = createNonExistentIdentifier();
+
+ // The HTTP status code expected to be returned in the response,
+ // from a request made to a service (where relevant).
int EXPECTED_STATUS_CODE = 0;
// The generic type of service request being tested (e.g. CREATE, UPDATE, DELETE).
// such as the set of valid status codes that may be returned.
ServiceRequestType REQUEST_TYPE = ServiceRequestType.NON_EXISTENT;
-
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
contents = "";
}
StringRequestEntity entity = null;
- final String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
+ final String XML_DECLARATION =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
final String XML_CONTENT_TYPE=MediaType.APPLICATION_XML;
final String UTF8_CHARSET_NAME = "UTF-8";
try {
entity =
- new StringRequestEntity(XML_DECLARATION + contents, XML_CONTENT_TYPE, UTF8_CHARSET_NAME);
+ new StringRequestEntity(
+ XML_DECLARATION + contents, XML_CONTENT_TYPE, UTF8_CHARSET_NAME);
} catch (UnsupportedEncodingException e) {
logger.error("Unsupported character encoding error: ", e);
}
// Instance variables specific to this test.
private CollectionObjectClient client = new CollectionObjectClient();
-
- // Instance variables common to all entity service test classes.
- private final String NON_EXISTENT_ID = createNonExistentIdentifier();
+ final String SERVICE_PATH_COMPONENT = "collectionobjects";
private String knownObjectId = null;
// ---------------------------------------------------------------
// Perform setup, such as initializing the type of service request
// and its valid and expected status codes.
- super.setupCreate();
+ setupCreate();
// Submit the request to the service and store the response.
String identifier = createIdentifier();
public void createWithMalformedXml() {
// Perform setup.
- super.setupCreateWithMalformedXml();
+ setupCreateWithMalformedXml();
// Submit the request to the service and store the response.
String url = getServiceRootURL();
public void createWithWrongXmlSchema() {
// Perform setup.
- super.setupCreateWithWrongXmlSchema();
+ setupCreateWithWrongXmlSchema();
// Submit the request to the service and store the response.
String url = getServiceRootURL();
public void read() {
// Perform setup.
- super.setupRead();
+ setupRead();
// Submit the request to the service and store the response.
ClientResponse<CollectionObject> res =
public void readNonExistent() {
// Perform setup.
- super.setupReadNonExistent();
+ setupReadNonExistent();
// Submit the request to the service and store the response.
ClientResponse<CollectionObject> res =
public void readList() {
// Perform setup.
- super.setupReadList();
+ setupReadList();
// Submit the request to the service and store the response.
ClientResponse<CollectionObjectList> res = client.getCollectionObjectList();
public void update() {
// Perform setup.
- super.setupUpdate();
+ setupUpdate();
// Retrieve an existing resource that we can update.
ClientResponse<CollectionObject> res =
public void updateWithMalformedXml() {
// Perform setup.
- super.setupUpdateWithMalformedXml();
+ setupUpdateWithMalformedXml();
// Submit the request to the service and store the response.
String url = getResourceURL(knownObjectId);
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ @Override
@Test(dependsOnMethods = {"create", "testSubmitRequest"}) // , "createWithMalformedXml"})
public void updateWithWrongXmlSchema() {
// Perform setup.
- super.setupUpdateWithWrongXmlSchema();
+ setupUpdateWithWrongXmlSchema();
// Submit the request to the service and store the response.
String url = getResourceURL(knownObjectId);
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ @Override
@Test(dependsOnMethods = {"update"})
public void updateNonExistent() {
// Perform setup.
- super.setupUpdateNonExistent();
+ setupUpdateNonExistent();
// Submit the request to the service and store the response.
// Note: The ID used in this 'create' call may be arbitrary.
// Success outcomes
+ @Override
@Test(dependsOnMethods =
{"create", "read", "testSubmitRequest", "update"})
public void delete() {
// Perform setup.
- super.setupDelete();
+ setupDelete();
// Submit the request to the service and store the response.
ClientResponse<Response> res = client.deleteCollectionObject(knownObjectId);
// Failure outcomes
+ @Override
@Test(dependsOnMethods = {"delete"})
public void deleteNonExistent() {
// Perform setup.
- super.setupDeleteNonExistent();
+ setupDeleteNonExistent();
// Submit the request to the service and store the response.
ClientResponse<Response> res =
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+
+ @Override
+ public String getServicePathComponent() {
+ // @TODO Determine if it is possible to obtain this value programmatically.
+ // We set this in an annotation in the CollectionObjectProxy interface, for instance.
+ // We also set service-specific constants in each service module.
+ return SERVICE_PATH_COMPONENT;
+ }
private CollectionObject createCollectionObject(String identifier) {
CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier,
return collectionObject;
}
- @Override
- public String getServicePathComponent() {
- // @TODO Determine if it is possible to obtain this value programmatically.
- // We set this in an annotation in the CollectionObjectProxy interface, for instance.
- // We also set service-specific constants in each service module.
- final String SERVICE_PATH_COMPONENT = "collectionobjects";
- return SERVICE_PATH_COMPONENT;
- }
}