@Test public void testLabelInvalidAddition() throws UniformInterfaceException, Exception { WebResource r = resource(); ClientResponse response; // Add a invalid label NodeLabelsInfo nlsifo = new NodeLabelsInfo(); nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("a&")); response = r.path("ws").path("v1").path("cluster").path("add-node-labels") .queryParam("user.name", userName).accept(MediaType.APPLICATION_JSON) .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON) .post(ClientResponse.class); String expectedmessage = "java.io.IOException: label name should only contains" + " {0-9, a-z, A-Z, -, _} and should not started with" + " {-,_}, now it is= a&"; validateJsonExceptionContent(response, expectedmessage); }
@Test public void testLabelChangeExclusivity() throws Exception, JSONException { WebResource r = resource(); ClientResponse response; NodeLabelsInfo nlsifo = new NodeLabelsInfo(); nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("newlabel", true)); response = r.path("ws").path("v1").path("cluster").path("add-node-labels") .queryParam("user.name", userName).accept(MediaType.APPLICATION_JSON) .entity(toJson(nlsifo, NodeLabelsInfo.class), MediaType.APPLICATION_JSON) .post(ClientResponse.class); // new info and change exclusivity NodeLabelsInfo nlsinfo2 = new NodeLabelsInfo(); nlsinfo2.getNodeLabelsInfo().add(new NodeLabelInfo("newlabel", false)); response = r.path("ws").path("v1").path("cluster").path("add-node-labels") .queryParam("user.name", userName).accept(MediaType.APPLICATION_JSON) .entity(toJson(nlsinfo2, NodeLabelsInfo.class), MediaType.APPLICATION_JSON) .post(ClientResponse.class); String expectedmessage = "java.io.IOException: Exclusivity cannot be modified for an existing" + " label with : <newlabel:exclusivity=false>"; validateJsonExceptionContent(response, expectedmessage); }
nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("a")); response = r.path("ws").path("v1").path("cluster") nlsifo = response.getEntity(NodeLabelsInfo.class); assertEquals(1, nlsifo.getNodeLabels().size()); for (NodeLabelInfo nl : nlsifo.getNodeLabelsInfo()) { assertEquals("a", nl.getName()); assertTrue(nl.getExclusivity()); nlsifo.getNodeLabelsInfo().add(new NodeLabelInfo("b", false)); response = r.path("ws").path("v1").path("cluster") for (NodeLabelInfo nl : nlsifo.getNodeLabelsInfo()) { if (nl.getName().equals("b")) { assertFalse(nl.getExclusivity()); response.getType().toString()); nlsifo = response.getEntity(NodeLabelsInfo.class); assertTrue(nlsifo.getNodeLabelsInfo().contains(new NodeLabelInfo("a"))); response.getType().toString()); nlsifo = response.getEntity(NodeLabelsInfo.class); assertTrue(nlsifo.getNodeLabelsInfo().contains( new NodeLabelInfo("b", false))); NodeLabelsInfo nlinfo = ntlinfo.getNodeToLabels().get("nid:0"); assertEquals(1, nlinfo.getNodeLabels().size());