Search in sources :

Example 1 with SetOperatorPropertyRequest

use of com.datatorrent.stram.plan.logical.requests.SetOperatorPropertyRequest in project apex-core by apache.

the class StramWebServicesTest method testSubmitLogicalPlanChange.

@Test
public void testSubmitLogicalPlanChange() throws JSONException, Exception {
    List<LogicalPlanRequest> requests = new ArrayList<>();
    WebResource r = resource();
    CreateOperatorRequest request1 = new CreateOperatorRequest();
    request1.setOperatorName("operatorName");
    request1.setOperatorFQCN("className");
    requests.add(request1);
    SetOperatorPropertyRequest request2 = new SetOperatorPropertyRequest();
    request2.setOperatorName("operatorName");
    request2.setPropertyName("propertyName");
    request2.setPropertyValue("propertyValue");
    requests.add(request2);
    ObjectMapper mapper = new ObjectMapper();
    final Map<String, Object> m = new HashMap<>();
    m.put("requests", requests);
    final JSONObject jsonRequest = new JSONObject(mapper.writeValueAsString(m));
    ClientResponse response = r.path(StramWebServices.PATH).path(StramWebServices.PATH_LOGICAL_PLAN).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, jsonRequest);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    assertEquals(DummyStreamingContainerManager.lastRequests.size(), 2);
    LogicalPlanRequest request = DummyStreamingContainerManager.lastRequests.get(0);
    assertTrue(request instanceof CreateOperatorRequest);
    request1 = (CreateOperatorRequest) request;
    assertEquals(request1.getOperatorName(), "operatorName");
    assertEquals(request1.getOperatorFQCN(), "className");
    request = DummyStreamingContainerManager.lastRequests.get(1);
    assertTrue(request instanceof SetOperatorPropertyRequest);
    request2 = (SetOperatorPropertyRequest) request;
    assertEquals(request2.getOperatorName(), "operatorName");
    assertEquals(request2.getPropertyName(), "propertyName");
    assertEquals(request2.getPropertyValue(), "propertyValue");
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SetOperatorPropertyRequest(com.datatorrent.stram.plan.logical.requests.SetOperatorPropertyRequest) WebResource(com.sun.jersey.api.client.WebResource) JSONObject(org.codehaus.jettison.json.JSONObject) LogicalPlanRequest(com.datatorrent.stram.plan.logical.requests.LogicalPlanRequest) JSONObject(org.codehaus.jettison.json.JSONObject) CreateOperatorRequest(com.datatorrent.stram.plan.logical.requests.CreateOperatorRequest) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Aggregations

CreateOperatorRequest (com.datatorrent.stram.plan.logical.requests.CreateOperatorRequest)1 LogicalPlanRequest (com.datatorrent.stram.plan.logical.requests.LogicalPlanRequest)1 SetOperatorPropertyRequest (com.datatorrent.stram.plan.logical.requests.SetOperatorPropertyRequest)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 JerseyTest (com.sun.jersey.test.framework.JerseyTest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 Test (org.junit.Test)1