running (getFakeApplication(),
new Runnable() {
public void run() {
try {
String sFakeCollection = getRouteAddress();
FakeRequest requestCreation = new FakeRequest(POST, sFakeCollection);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
Result result = route(requestCreation);
assertRoute(result, "testDropCollection.create", Status.CREATED, null, true);
//Insert some object in there
String sFakeInsertObjects = getRouteForObjects();
JsonNode payload = (new ObjectMapper()).readTree("{\"test\":\"testvalue\"}");
int cont=15;
for(int i=0;i<cont;i++){
requestCreation = new FakeRequest(POST, sFakeInsertObjects);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
requestCreation = requestCreation.withJsonBody(payload, POST);
Result result1 = route(requestCreation);
assertRoute(result1, "testDropCollection.populate", Status.OK, null, true);
}
//check if the collection is full
String sFakeCollectionCount = getRouteForCount();
requestCreation = new FakeRequest(GET, sFakeCollectionCount);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = route(requestCreation);
assertRoute(result, "routeDropCollection.count", Status.OK, "\"count\":"+cont, true);
//drop the collection
requestCreation = new FakeRequest(DELETE, sFakeCollection);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = route(requestCreation);
assertRoute(result, "routeDropCollection.drop", Status.OK, null, false);
//check the collection does not exist
requestCreation = new FakeRequest(GET, sFakeCollectionCount);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = route(requestCreation);
assertRoute(result, "routeDropCollection.count_not_found", Status.NOT_FOUND, null, false);
//try to recreate the same
requestCreation = new FakeRequest(POST, sFakeCollection);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = route(requestCreation);
assertRoute(result, "testDropCollection.create_the_same", Status.CREATED, null, true);
//check the collection is empty
requestCreation = new FakeRequest(GET, sFakeCollectionCount);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = route(requestCreation);
assertRoute(result, "routeDropCollection.count_must_be_empty", Status.OK, "\"count\":0", true);
//finally... drop
requestCreation = new FakeRequest(DELETE, sFakeCollection);
requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = route(requestCreation);
assertRoute(result, "routeDropCollection.drop_final", Status.OK, null, false);
} catch (JsonProcessingException e) {