Skip to content

Commit

Permalink
replaced deprecated junit.framework.Assert with correct org.junit.Ass…
Browse files Browse the repository at this point in the history
…ert class
  • Loading branch information
Maurizio Turatti committed Dec 17, 2014
1 parent e63d389 commit 10de2f0
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.softinstigate.restheart.db.MongoDBClientSingleton;
import com.softinstigate.restheart.hal.Representation;
import java.net.URI;
import junit.framework.Assert;
import static org.junit.Assert.*;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
Expand Down Expand Up @@ -446,12 +446,12 @@ public void tearDown() {

protected HttpResponse check(String message, Response resp, int expectedCode) throws Exception {
HttpResponse httpResp = resp.returnResponse();
Assert.assertNotNull(httpResp);
assertNotNull(httpResp);

StatusLine statusLine = httpResp.getStatusLine();
Assert.assertNotNull(statusLine);
assertNotNull(statusLine);

Assert.assertEquals(message, expectedCode, statusLine.getStatusCode());
assertEquals(message, expectedCode, statusLine.getStatusCode());

return httpResp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import junit.framework.Assert;
import static org.junit.Assert.*;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
Expand Down Expand Up @@ -58,20 +58,20 @@ public void testGzipAcceptEncoding() throws Exception {
Response resp = notDecompressingExecutor.execute(Request.Get(rootUri).addHeader(Headers.ACCEPT_ENCODING_STRING, Headers.GZIP.toString()));

HttpResponse httpResp = resp.returnResponse();
Assert.assertNotNull(httpResp);
assertNotNull(httpResp);
HttpEntity entity = httpResp.getEntity();
Assert.assertNotNull(entity);
assertNotNull(entity);
StatusLine statusLine = httpResp.getStatusLine();
Assert.assertNotNull(statusLine);
assertNotNull(statusLine);

String content = EntityUtils.toString(entity);

Header h = httpResp.getFirstHeader("Content-Encoding");

Assert.assertNotNull("check accept encoding header not null", h);
Assert.assertEquals("check accept encoding header value", Headers.GZIP.toString(), h.getValue());
assertNotNull("check accept encoding header not null", h);
assertEquals("check accept encoding header value", Headers.GZIP.toString(), h.getValue());

Assert.assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode());
assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode());

try {
GZIPInputStream gzipis = new GZIPInputStream(new ByteArrayInputStream(content.getBytes(StandardCharsets.ISO_8859_1)));
Expand All @@ -81,7 +81,7 @@ public void testGzipAcceptEncoding() throws Exception {
}
}
catch (Exception ex) {
Assert.fail("check decompressing content");
fail("check decompressing content");
}
}
}

Large diffs are not rendered by default.

132 changes: 66 additions & 66 deletions src/test/java/com/softinstigate/restheart/integrationtest/GetDBIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.softinstigate.restheart.utils.HttpStatus;
import java.net.URI;
import java.net.URISyntaxException;
import junit.framework.Assert;
import static org.junit.Assert.*;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
Expand Down Expand Up @@ -61,160 +61,160 @@ public void testGetDBPaging() throws Exception {
Response resp = adminExecutor.execute(Request.Get(dbUriPaging));

HttpResponse httpResp = resp.returnResponse();
Assert.assertNotNull(httpResp);
assertNotNull(httpResp);
HttpEntity entity = httpResp.getEntity();
Assert.assertNotNull(entity);
assertNotNull(entity);
StatusLine statusLine = httpResp.getStatusLine();
Assert.assertNotNull(statusLine);
assertNotNull(statusLine);

Assert.assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode());
Assert.assertNotNull("content type not null", entity.getContentType());
Assert.assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue());
assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode());
assertNotNull("content type not null", entity.getContentType());
assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue());

String content = EntityUtils.toString(entity);

Assert.assertNotNull("", content);
assertNotNull("", content);

JsonObject json = null;

try {
json = JsonObject.readFrom(content);
}
catch (Throwable t) {
Assert.fail("parsing received json");
fail("parsing received json");
}

Assert.assertNotNull("check json not null", json);
assertNotNull("check json not null", json);

Assert.assertNotNull("check not null _link", json.get("_links"));
Assert.assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject));
assertNotNull("check not null _link", json.get("_links"));
assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject));

Assert.assertNotNull("check not null _returned property", json.get("_returned"));
Assert.assertNotNull("check not null _size value", json.get("_size"));
Assert.assertNotNull("check not null _total_pages", json.get("_total_pages"));
assertNotNull("check not null _returned property", json.get("_returned"));
assertNotNull("check not null _size value", json.get("_size"));
assertNotNull("check not null _total_pages", json.get("_total_pages"));

Assert.assertEquals("check _returned value to be 1", 1, json.get("_returned").asInt());
Assert.assertEquals("check _size value to be 2", 3, json.get("_size").asInt());
Assert.assertEquals("check _total_pages value to be 2", 3, json.get("_total_pages").asInt());
assertEquals("check _returned value to be 1", 1, json.get("_returned").asInt());
assertEquals("check _size value to be 2", 3, json.get("_size").asInt());
assertEquals("check _total_pages value to be 2", 3, json.get("_total_pages").asInt());

JsonObject links = (JsonObject) json.get("_links");

Assert.assertNotNull("check not null self", links.get("self"));
Assert.assertNotNull("check not null rh:root", links.get("rh:root"));
Assert.assertNotNull("check not null rh:paging", links.get("rh:paging"));
Assert.assertNotNull("check not null next", links.get("next"));
Assert.assertNotNull("check not null first", links.get("first"));
Assert.assertNotNull("check not null last", links.get("last"));
Assert.assertNull("check null previous", links.get("previous"));
assertNotNull("check not null self", links.get("self"));
assertNotNull("check not null rh:root", links.get("rh:root"));
assertNotNull("check not null rh:paging", links.get("rh:paging"));
assertNotNull("check not null next", links.get("next"));
assertNotNull("check not null first", links.get("first"));
assertNotNull("check not null last", links.get("last"));
assertNull("check null previous", links.get("previous"));

Response respSelf = adminExecutor.execute(Request.Get(dbUriPaging.resolve(links.get("self").asObject().get("href").asString())));
HttpResponse httpRespSelf = respSelf.returnResponse();
Assert.assertNotNull(httpRespSelf);
assertNotNull(httpRespSelf);

Response respRoot = adminExecutor.execute(Request.Get(dbUriPaging.resolve(links.get("rh:root").asObject().get("href").asString())));
HttpResponse httpRespRoot = respRoot.returnResponse();
Assert.assertNotNull(httpRespRoot);
assertNotNull(httpRespRoot);

Response respNext = adminExecutor.execute(Request.Get(dbUriPaging.resolve(links.get("next").asObject().get("href").asString())));
HttpResponse httpRespNext = respNext.returnResponse();
Assert.assertNotNull(httpRespNext);
assertNotNull(httpRespNext);

Response respFirst = adminExecutor.execute(Request.Get(dbUriPaging.resolve(links.get("first").asObject().get("href").asString())));
HttpResponse respRespFirst = respFirst.returnResponse();
Assert.assertNotNull(respRespFirst);
assertNotNull(respRespFirst);

Response respLast = adminExecutor.execute(Request.Get(dbUriPaging.resolve(links.get("last").asObject().get("href").asString())));
HttpResponse httpRespLast = respLast.returnResponse();
Assert.assertNotNull(httpRespLast);
assertNotNull(httpRespLast);
}

private void testGetDb(URI uri) throws Exception {
Response resp = adminExecutor.execute(Request.Get(uri));

HttpResponse httpResp = resp.returnResponse();
Assert.assertNotNull(httpResp);
assertNotNull(httpResp);
HttpEntity entity = httpResp.getEntity();
Assert.assertNotNull(entity);
assertNotNull(entity);
StatusLine statusLine = httpResp.getStatusLine();
Assert.assertNotNull(statusLine);
assertNotNull(statusLine);

Assert.assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode());
Assert.assertNotNull("content type not null", entity.getContentType());
Assert.assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue());
assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode());
assertNotNull("content type not null", entity.getContentType());
assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue());

String content = EntityUtils.toString(entity);

Assert.assertNotNull("", content);
assertNotNull("", content);

JsonObject json = null;

try {
json = JsonObject.readFrom(content);
}
catch (Throwable t) {
Assert.fail("parsing received json");
fail("parsing received json");
}

Assert.assertNotNull("check json not null", json);
Assert.assertNotNull("check not null _created_on property", json.get("_created_on"));
Assert.assertNotNull("check not null _etag property", json.get("_etag"));
Assert.assertNotNull("check not null _lastupdated_on property", json.get("_lastupdated_on"));
Assert.assertNotNull("check not null _db-props-cached property", json.get("_db-props-cached"));
Assert.assertNotNull("check not null _returned property", json.get("_returned"));
Assert.assertNotNull("check not null _size property", json.get("_size"));
Assert.assertNotNull("check not null _total_pages property", json.get("_total_pages"));
assertNotNull("check json not null", json);
assertNotNull("check not null _created_on property", json.get("_created_on"));
assertNotNull("check not null _etag property", json.get("_etag"));
assertNotNull("check not null _lastupdated_on property", json.get("_lastupdated_on"));
assertNotNull("check not null _db-props-cached property", json.get("_db-props-cached"));
assertNotNull("check not null _returned property", json.get("_returned"));
assertNotNull("check not null _size property", json.get("_size"));
assertNotNull("check not null _total_pages property", json.get("_total_pages"));

Assert.assertNotNull("check not null _embedded", json.get("_embedded"));
assertNotNull("check not null _embedded", json.get("_embedded"));

Assert.assertTrue("check _embedded to be a json object", (json.get("_embedded") instanceof JsonObject));
assertTrue("check _embedded to be a json object", (json.get("_embedded") instanceof JsonObject));

JsonObject embedded = (JsonObject) json.get("_embedded");

Assert.assertNotNull("check not null _embedded.rh:coll", embedded.get("rh:coll"));
assertNotNull("check not null _embedded.rh:coll", embedded.get("rh:coll"));

Assert.assertTrue("check _embedded.rh:coll to be a json array", (embedded.get("rh:coll") instanceof JsonArray));
assertTrue("check _embedded.rh:coll to be a json array", (embedded.get("rh:coll") instanceof JsonArray));

JsonArray rhcoll = (JsonArray) embedded.get("rh:coll");

Assert.assertNotNull("check not null _embedded.rh:coll[0]", rhcoll.get(0));
assertNotNull("check not null _embedded.rh:coll[0]", rhcoll.get(0));

Assert.assertTrue("check _embedded.rh:coll[0] to be a json object", (rhcoll.get(0) instanceof JsonObject));
assertTrue("check _embedded.rh:coll[0] to be a json object", (rhcoll.get(0) instanceof JsonObject));

JsonObject rhcoll0 = (JsonObject) rhcoll.get(0);

Assert.assertNotNull("check not null _embedded.rh:coll[0]._id", rhcoll0.get("_id"));
assertNotNull("check not null _embedded.rh:coll[0]._id", rhcoll0.get("_id"));

Assert.assertNotNull("check not null _embedded.rh:coll[0]._links", rhcoll0.get("_links"));
assertNotNull("check not null _embedded.rh:coll[0]._links", rhcoll0.get("_links"));

Assert.assertTrue("check _embedded.rh:coll[0]._links to be a json object", (rhcoll0.get("_links") instanceof JsonObject));
assertTrue("check _embedded.rh:coll[0]._links to be a json object", (rhcoll0.get("_links") instanceof JsonObject));

JsonObject rhcoll0Links = (JsonObject) rhcoll0.get("_links");

Assert.assertNotNull("check not null _embedded.rh:coll[0]._links.self", rhcoll0Links.get("self"));
assertNotNull("check not null _embedded.rh:coll[0]._links.self", rhcoll0Links.get("self"));

Assert.assertTrue("check _embedded.rh:coll[0]._links.self to be a json object", (rhcoll0Links.get("self") instanceof JsonObject));
assertTrue("check _embedded.rh:coll[0]._links.self to be a json object", (rhcoll0Links.get("self") instanceof JsonObject));

JsonObject rhdb0LinksSelf = (JsonObject) rhcoll0Links.get("self");

Assert.assertNotNull("check not null _embedded.rh:coll[0]._links.self.href", rhdb0LinksSelf.get("href"));
assertNotNull("check not null _embedded.rh:coll[0]._links.self.href", rhdb0LinksSelf.get("href"));

Assert.assertTrue("check _embedded.rh:coll[0]._links.self.href to be a string", (rhdb0LinksSelf.get("href").isString()));
assertTrue("check _embedded.rh:coll[0]._links.self.href to be a string", (rhdb0LinksSelf.get("href").isString()));

try {
URI _uri = new URI(rhdb0LinksSelf.get("href").asString());
}
catch (URISyntaxException use) {
Assert.fail("check _embedded.rh:coll[0]._links.self.href to be a valid URI");
fail("check _embedded.rh:coll[0]._links.self.href to be a valid URI");
}

Assert.assertNotNull("check not null _link", json.get("_links"));
Assert.assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject));
assertNotNull("check not null _link", json.get("_links"));
assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject));

JsonObject links = (JsonObject) json.get("_links");

Assert.assertNotNull("check not null self", links.get("self"));
Assert.assertNotNull("check not null rh:root", links.get("rh:root"));
Assert.assertNotNull("check not null rh:paging", links.get("rh:paging"));
Assert.assertNotNull("check not null curies", links.get("curies"));
assertNotNull("check not null self", links.get("self"));
assertNotNull("check not null rh:root", links.get("rh:root"));
assertNotNull("check not null rh:paging", links.get("rh:paging"));
assertNotNull("check not null curies", links.get("curies"));
}
}
Loading

0 comments on commit 10de2f0

Please sign in to comment.