kaisun2000 commented on a change in pull request #339: Implementation of
stateModelDef modification in REST 2.0
URL: https://github.com/apache/helix/pull/339#discussion_r306097821
##########
File path:
helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
##########
@@ -405,7 +407,68 @@ public void
testEnableDisableMaintenanceModeWithCustomFields() {
accessor.getBaseDataAccessor().exists(accessor.keyBuilder().maintenance().getPath(),
0));
}
- @Test()
+ @Test(dependsOnMethods = "testEnableDisableMaintenanceModeWithCustomFields")
+ public void testGetStateModelDef() throws IOException {
+
+ System.out.println("Start test :" + TestHelper.getTestMethodName());
+ String cluster = "TestCluster_1";
+ String stateModelDefs = get("clusters/" + cluster + "/statemodeldefs",
null, Response.Status.OK.getStatusCode(), true);
+ Map<String, Object> defMap = OBJECT_MAPPER.readValue(stateModelDefs, new
TypeReference<HashMap<String, Object>>(){});
+
+ Assert.assertTrue(defMap.size()==2);
+ Assert.assertTrue(defMap.get("stateModelDefinitions") instanceof List);
+ List<String> stateModelNames =
(List<String>)defMap.get("stateModelDefinitions");
+ Assert.assertEquals(stateModelNames.size(), 6);
+
+ String oneModel = stateModelNames.get(1);
+ String twoModel = stateModelNames.get(2);
+
+ String oneModelUri = "clusters/" + cluster + "/statemodeldefs/" + oneModel;
+ String oneResult = get(oneModelUri, null,
Response.Status.OK.getStatusCode(), true);
+ ZNRecord oneRecord = OBJECT_MAPPER.readValue(oneResult, ZNRecord.class);
+
+ String twoModelUri = "clusters/" + cluster + "/statemodeldefs/" + twoModel;
+ String twoResult = get("clusters/" + cluster + "/statemodeldefs/" +
twoModel, null, Response.Status.OK.getStatusCode(), true);
+ ZNRecord twoRecord = OBJECT_MAPPER.readValue(twoResult, ZNRecord.class);
+
+ // delete one, expect success
+ String deleteOneUri = "clusters/" + cluster + "/statemodeldefs/" +
oneRecord.getId();
+ Response deleteOneRsp = target(deleteOneUri).request().delete();
+ Assert.assertEquals(deleteOneRsp.getStatus(),
Response.Status.OK.getStatusCode());
+
+ Response queryRsp = target(oneModelUri).request().get();
+ Assert.assertTrue(queryRsp.getStatus() ==
Response.Status.NOT_FOUND.getStatusCode());
+ // delete one again, expect success
+ Response deleteOneRsp2 = target(deleteOneUri).request().delete();
+ Assert.assertTrue(deleteOneRsp2.getStatus() ==
Response.Status.OK.getStatusCode());
+ // create the delete one, expect success
+ String createOneUri = "clusters/" + cluster + "/statemodeldefs/" +
oneModel;
+ Response createOneRsp =
target(createOneUri).request().put(Entity.entity(OBJECT_MAPPER.writeValueAsString(oneRecord),
MediaType.APPLICATION_JSON_TYPE));
+ Assert.assertTrue(createOneRsp.getStatus() ==
Response.Status.OK.getStatusCode());
+
+ // create the delete one again, expect failure
+ Response createOneRsp2 =
target(createOneUri).request().put(Entity.entity(OBJECT_MAPPER.writeValueAsString(oneRecord),
MediaType.APPLICATION_JSON_TYPE));
+ Assert.assertTrue(createOneRsp2.getStatus() ==
Response.Status.BAD_REQUEST.getStatusCode());
+
+ // set the delete one with a modification
+ ZNRecord newRecord = new ZNRecord(twoRecord, oneRecord.getId());
+ Response setOneRsp =
target(createOneUri).request().post(Entity.entity(OBJECT_MAPPER.writeValueAsString(newRecord),
MediaType.APPLICATION_JSON_TYPE));
+ Assert.assertTrue(setOneRsp.getStatus() ==
Response.Status.OK.getStatusCode());
+
+ String oneResult2 = get(oneModelUri, null,
Response.Status.OK.getStatusCode(), true);
+ ZNRecord oneRecord2 = OBJECT_MAPPER.readValue(oneResult2, ZNRecord.class);
+ Assert.assertEquals(oneRecord2, newRecord);
+
+ // set the delete one with original; namely restore the original condition
+ Response setOneRsp2 =
target(createOneUri).request().post(Entity.entity(OBJECT_MAPPER.writeValueAsString(oneRecord),
MediaType.APPLICATION_JSON_TYPE));
+ Assert.assertTrue( setOneRsp2.getStatus() ==
Response.Status.OK.getStatusCode());
Review comment:
will use helix coding style formatter
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services