Skip to content

Commit

Permalink
GEODE-7869: Cleanup warnings in geode-web-api
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-at-work committed Mar 16, 2020
1 parent 9b269de commit 9d1e682
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import com.fasterxml.jackson.databind.JsonNode;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand Down Expand Up @@ -57,35 +59,35 @@ public static void before() {
}

@Test
public void testListFunctions() throws Exception {
public void testListFunctions() {
assertResponse(restClient.doGet("/functions", "user", "wrongPswd")).hasStatusCode(401);
assertResponse(restClient.doGet("/functions", "user", "user")).hasStatusCode(403);
assertResponse(restClient.doGet("/functions", "dataRead", "dataRead"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
.hasContentType(MediaType.APPLICATION_JSON_VALUE);
}

@Test
public void executeNotRegisteredFunction() throws Exception {
public void executeNotRegisteredFunction() {
assertResponse(restClient.doPost("/functions/invalid-function-id", "user", "wrongPswd", ""))
.hasStatusCode(401);
assertResponse(restClient.doPost("/functions/invalid-function-id", "user", "user", ""))
.hasStatusCode(404);
}

@Test
public void testQueries() throws Exception {
public void testQueries() {
restClient.doGetAndAssert("/queries", "user", "wrongPswd")
.hasStatusCode(401);
restClient.doGetAndAssert("/queries", "user", "user")
.hasStatusCode(403);
restClient.doGetAndAssert("/queries", "dataRead", "dataRead")
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
.hasContentType(MediaType.APPLICATION_JSON_VALUE);
}

@Test
public void testAdhocQuery() throws Exception {
public void testAdhocQuery() {
restClient.doGetAndAssert("/queries/adhoc?q=", "user", "wrongPswd")
.hasStatusCode(401);
restClient.doGetAndAssert("/queries/adhoc?q=", "user", "user")
Expand All @@ -97,7 +99,7 @@ public void testAdhocQuery() throws Exception {
}

@Test
public void testPostQuery() throws Exception {
public void testPostQuery() {
assertResponse(restClient.doPost("/queries?id=0&q=", "user", "wrongPswd", ""))
.hasStatusCode(401);
assertResponse(restClient.doPost("/queries?id=0&q=", "user", "user", ""))
Expand All @@ -107,7 +109,7 @@ public void testPostQuery() throws Exception {
}

@Test
public void testPostQuery2() throws Exception {
public void testPostQuery2() {
assertResponse(restClient.doPost("/queries/id", "user", "wrongPswd", "{\"id\" : \"foo\"}"))
.hasStatusCode(401);
assertResponse(restClient.doPost("/queries/id", "user", "user", "{\"id\" : \"foo\"}"))
Expand All @@ -117,7 +119,7 @@ public void testPostQuery2() throws Exception {
}

@Test
public void testPutQuery() throws Exception {
public void testPutQuery() {
assertResponse(restClient.doPut("/queries/id", "user", "wrongPswd", "{\"id\" : \"foo\"}"))
.hasStatusCode(401);
assertResponse(restClient.doPut("/queries/id", "user", "user", "{\"id\" : \"foo\"}"))
Expand All @@ -127,7 +129,7 @@ public void testPutQuery() throws Exception {
}

@Test
public void testDeleteQuery() throws Exception {
public void testDeleteQuery() {
assertResponse(restClient.doDelete("/queries/id", "user", "wrongPswd"))
.hasStatusCode(401);
assertResponse(restClient.doDelete("/queries/id", "stranger", "stranger"))
Expand All @@ -137,22 +139,22 @@ public void testDeleteQuery() throws Exception {
}

@Test
public void testServers() throws Exception {
public void testServers() {
assertResponse(restClient.doGet("/servers", "user", "wrongPswd"))
.hasStatusCode(401);
assertResponse(restClient.doGet("/servers", "stranger", "stranger"))
.hasStatusCode(403);
assertResponse(restClient.doGet("/servers", "cluster", "cluster"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
.hasContentType(MediaType.APPLICATION_JSON_VALUE);
}

/**
* This test should always return an OK, whether the user is known or unknown. A phishing script
* should not be able to determine whether a user/password combination is good
*/
@Test
public void testPing() throws Exception {
public void testPing() {
assertResponse(restClient.doHEAD("/ping", "stranger", "stranger"))
.hasStatusCode(200);
assertResponse(restClient.doGet("/ping", "stranger", "stranger"))
Expand All @@ -168,9 +170,9 @@ public void testPing() throws Exception {
* Test permissions on retrieving a list of regions.
*/
@Test
public void getRegions() throws Exception {
public void getRegions() throws IOException {
JsonNode jsonObject = assertResponse(restClient.doGet("", "dataRead", "dataRead"))
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_VALUE)
.getJsonObject();

JsonNode regions = jsonObject.get("regions");
Expand All @@ -194,7 +196,7 @@ public void getRegions() throws Exception {
* Test permissions on getting a region
*/
@Test
public void getRegion() throws Exception {
public void getRegion() {
// Test an unknown user - 401 error
assertResponse(restClient.doGet("/" + REGION_NAME, "user", "wrongPswd"))
.hasStatusCode(401);
Expand All @@ -205,14 +207,14 @@ public void getRegion() throws Exception {

// Test an authorized user - 200
assertResponse(restClient.doGet("/" + REGION_NAME, "data", "data"))
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_VALUE);
}

/**
* Test permissions on HEAD region
*/
@Test
public void headRegion() throws Exception {
public void headRegion() {
// Test an unknown user - 401 error
assertResponse(restClient.doHEAD("/" + REGION_NAME, "user", "wrongPswd"))
.hasStatusCode(401);
Expand All @@ -230,7 +232,7 @@ public void headRegion() throws Exception {
* Test permissions on deleting a region
*/
@Test
public void deleteRegion() throws Exception {
public void deleteRegion() {
// Test an unknown user - 401 error
assertResponse(restClient.doDelete("/" + REGION_NAME, "user", "wrongPswd"))
.hasStatusCode(401);
Expand All @@ -244,10 +246,10 @@ public void deleteRegion() throws Exception {
* Test permissions on getting a region's keys
*/
@Test
public void getRegionKeys() throws Exception {
public void getRegionKeys() {
// Test an authorized user
assertResponse(restClient.doGet("/" + REGION_NAME + "/keys", "data", "data"))
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_VALUE);
// Test an unauthorized user
assertResponse(restClient.doGet("/" + REGION_NAME + "/keys", "dataWrite", "dataWrite"))
.hasStatusCode(403);
Expand All @@ -257,11 +259,11 @@ public void getRegionKeys() throws Exception {
* Test permissions on retrieving a key from a region
*/
@Test
public void getRegionKey() throws Exception {
public void getRegionKey() {
// Test an authorized user
assertResponse(restClient.doGet("/" + REGION_NAME + "/key1", "dataReadAuthRegionKey1",
"dataReadAuthRegionKey1"))
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
.hasStatusCode(200).hasContentType(MediaType.APPLICATION_JSON_VALUE);

// Test an unauthorized user
assertResponse(restClient.doGet("/" + REGION_NAME + "/key1", "dataWrite", "dataWrite"))
Expand All @@ -272,7 +274,7 @@ public void getRegionKey() throws Exception {
* Test permissions on deleting a region's key(s)
*/
@Test
public void deleteRegionKey() throws Exception {
public void deleteRegionKey() {
// Test an unknown user - 401 error
assertResponse(restClient.doDelete("/" + REGION_NAME + "/key1", "user", "wrongPswd"))
.hasStatusCode(401);
Expand All @@ -291,7 +293,7 @@ public void deleteRegionKey() throws Exception {
* Test permissions on deleting a region's key(s)
*/
@Test
public void postRegionKey() throws Exception {
public void postRegionKey() {
// Test an unknown user - 401 error
assertResponse(restClient.doPost("/" + REGION_NAME + "?key9", "user", "wrongPswd",
"{ \"key9\" : \"foo\" }"))
Expand All @@ -312,7 +314,7 @@ public void postRegionKey() throws Exception {
* Test permissions on deleting a region's key(s)
*/
@Test
public void putRegionKey() throws Exception {
public void putRegionKey() {

String json =
"{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1012,\"description\":\"Order for XYZ Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/20/2014\",\"contact\":\"Jelly Bean\",\"email\":\"[email protected]\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":1,\"description\":\"Product-100\",\"quantity\":12,\"unitPrice\":5,\"totalPrice\":60}],\"totalPrice\":225}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void getRegionKey() throws Exception {
JsonNode jsonNode =
assertResponse(restClient.doGet("/customers/1", "dataReader", "1234567"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.hasContentType(MediaType.APPLICATION_JSON_VALUE)
.getJsonObject();

assertEquals("*********", jsonNode.get("ssn").asText());
Expand All @@ -86,7 +86,7 @@ public void getRegionKey() throws Exception {
jsonNode =
assertResponse(restClient.doGet("/customers/1", "super-user", "1234567"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.hasContentType(MediaType.APPLICATION_JSON_VALUE)
.getJsonObject();
assertEquals("555555555", jsonNode.get("ssn").asText());
assertEquals(1L, jsonNode.get("id").asLong());
Expand All @@ -98,7 +98,7 @@ public void getMultipleRegionKeys() throws Exception {
JsonNode jsonNode =
assertResponse(restClient.doGet("/customers/1,3", "dataReader", "1234567"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.hasContentType(MediaType.APPLICATION_JSON_VALUE)
.getJsonObject();

JsonNode customers = jsonNode.get("customers");
Expand All @@ -116,7 +116,7 @@ public void getMultipleRegionKeys() throws Exception {
public void getRegion() throws Exception {
JsonNode jsonNode = assertResponse(restClient.doGet("/customers", "dataReader", "1234567"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.hasContentType(MediaType.APPLICATION_JSON_VALUE)
.getJsonObject();

JsonNode customers = jsonNode.get("customers");
Expand All @@ -134,7 +134,7 @@ public void adhocQuery() throws Exception {
+ URLEncoder.encode("SELECT * FROM /customers order by customerId", "UTF-8");
JsonNode jsonArray = assertResponse(restClient.doGet(query, "dataReader", "1234567"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.hasContentType(MediaType.APPLICATION_JSON_VALUE)
.getJsonObject();

final int length = jsonArray.size();
Expand All @@ -160,7 +160,7 @@ public void namedQuery() throws Exception {
String query = "/queries";
assertResponse(restClient.doGet(query, "dataReader", "1234567"))
.hasStatusCode(200)
.hasContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
.hasContentType(MediaType.APPLICATION_JSON_VALUE);

// Execute the query
JsonNode jsonArray =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,48 @@ public void prQueryWithHeteroIndex() throws Exception {
QueryService qs = cache.getQueryService();

// create a local and Partition region for 1st select query
Region r1 = server.createRegion(RegionShortcut.LOCAL, "region1",
Region<Integer, Portfolio> r1 = server.createRegion(RegionShortcut.LOCAL, "region1",
rf -> rf.setValueConstraint(Portfolio.class));
qs.createIndex("IdIndex1", "r.ID", "/region1 r, r.positions.values pos");
Region r2 = server.createRegion(RegionShortcut.PARTITION, "region2",
Region<Integer, NewPortfolio> r2 = server.createRegion(RegionShortcut.PARTITION, "region2",
rf -> rf.setValueConstraint(NewPortfolio.class));
qs.createIndex("IdIndex2", "r.id", "/region2 r");

// create two local regions for 2nd select query to compare the result set
Region r3 = server.createRegion(RegionShortcut.LOCAL, "region3",
Region<Integer, Portfolio> r3 = server.createRegion(RegionShortcut.LOCAL, "region3",
rf -> rf.setValueConstraint(Portfolio.class));
Region r4 = server.createRegion(RegionShortcut.LOCAL, "region4",
Region<Integer, NewPortfolio> r4 = server.createRegion(RegionShortcut.LOCAL, "region4",
rf -> rf.setValueConstraint(NewPortfolio.class));

Portfolio[] portfolio = createPortfoliosAndPositions(count);
NewPortfolio[] newPortfolio = createNewPortfoliosAndPositions(count);

for (int i = 0; i < count; i++) {
r1.put(new Integer(i), portfolio[i]);
r2.put(new Integer(i), newPortfolio[i]);
r3.put(new Integer(i), portfolio[i]);
r4.put(new Integer(i), newPortfolio[i]);
r1.put(i, portfolio[i]);
r2.put(i, newPortfolio[i]);
r3.put(i, portfolio[i]);
r4.put(i, newPortfolio[i]);
}

ArrayList results[][] = new ArrayList[whereClauses.length][2];
ArrayList<?>[][] results = new ArrayList<?>[whereClauses.length][2];
for (int i = 0; i < whereClauses.length; i++) {
// issue the first select on region 1 and region 2
SelectResults selectResults = (SelectResults) qs.newQuery("<trace> Select "
+ (whereClauses[i].contains("ORDER BY") ? "DISTINCT" : "")
+ "* from /region1 r1, /region2 r2 where " + whereClauses[i])
.execute();
results[i][0] = (ArrayList) selectResults.asList();
@SuppressWarnings("unchecked")
SelectResults<ArrayList<ArrayList<?>>> selectResults =
(SelectResults<ArrayList<ArrayList<?>>>) qs.newQuery("<trace> Select "
+ (whereClauses[i].contains("ORDER BY") ? "DISTINCT" : "")
+ "* from /region1 r1, /region2 r2 where " + whereClauses[i])
.execute();
results[i][0] = (ArrayList<?>) selectResults.asList();

// issue the second select on region 3 and region 4
SelectResults queryResult = (SelectResults) qs.newQuery("<trace> Select "
+ (whereClauses[i].contains("ORDER BY") ? "DISTINCT" : "")
+ "* from /region3 r1, /region4 r2 where " + whereClauses[i])
.execute();
results[i][1] = (ArrayList) queryResult.asList();
@SuppressWarnings("unchecked")
SelectResults<ArrayList<ArrayList<?>>> queryResult =
(SelectResults<ArrayList<ArrayList<?>>>) qs.newQuery("<trace> Select "
+ (whereClauses[i].contains("ORDER BY") ? "DISTINCT" : "")
+ "* from /region3 r1, /region4 r2 where " + whereClauses[i])
.execute();
results[i][1] = (ArrayList<?>) queryResult.asList();
}

// compare the resultsets and expect them to be equal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ public void waitTillClientsAreReadyOnServer(String serverName, int serverPort, i
*
* @param regionFactoryConsumer a lamda that allows you to customize the regionFactory
*/
public Region createRegion(RegionShortcut type, String name,
Consumer<RegionFactory> regionFactoryConsumer) {
RegionFactory regionFactory = getCache().createRegionFactory(type);
public <K, V> Region<K, V> createRegion(RegionShortcut type, String name,
Consumer<RegionFactory<K, V>> regionFactoryConsumer) {
RegionFactory<K, V> regionFactory = getCache().createRegionFactory(type);
regionFactoryConsumer.accept(regionFactory);
return regionFactory.create(name);
}
Expand Down
1 change: 1 addition & 0 deletions geode-web-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ apply from: "${rootDir}/${scriptDir}/standard-subproject-configuration.gradle"
apply plugin: 'war'

apply from: "${project.projectDir}/../gradle/publish-war.gradle"
apply from: "${project.projectDir}/../gradle/warnings.gradle"

jar.enabled = false

Expand Down
Loading

0 comments on commit 9d1e682

Please sign in to comment.