Search in sources :

Example 21 with JSONObject

use of org.camunda.bpm.engine.impl.util.json.JSONObject in project camunda-bpm-platform by camunda.

the class AbstractEmptyBodyFilterTest method evaluatePostRequest.

private void evaluatePostRequest(HttpEntity reqBody, String reqContentType, int expectedStatusCode, boolean assertResponseBody) throws IOException {
    HttpPost post = new HttpPost(BASE_URL + START_PROCESS_INSTANCE_BY_KEY_URL);
    post.setConfig(reqConfig);
    if (reqContentType != null) {
        post.setHeader(HttpHeaders.CONTENT_TYPE, reqContentType);
    }
    post.setEntity(reqBody);
    CloseableHttpResponse response = client.execute(post);
    assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode());
    if (assertResponseBody) {
        assertEquals(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, new JSONObject(EntityUtils.toString(response.getEntity(), "UTF-8")).get("id"));
    }
    response.close();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 22 with JSONObject

use of org.camunda.bpm.engine.impl.util.json.JSONObject in project camunda-bpm-platform by camunda.

the class SetJobRetriesBatchConfigurationJsonConverter method toJsonObject.

public JSONObject toJsonObject(SetRetriesBatchConfiguration configuration) {
    JSONObject json = new JSONObject();
    JsonUtil.addListField(json, JOB_IDS, configuration.getIds());
    JsonUtil.addField(json, RETRIES, configuration.getRetries());
    return json;
}
Also used : JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject)

Example 23 with JSONObject

use of org.camunda.bpm.engine.impl.util.json.JSONObject in project camunda-bpm-platform by camunda.

the class AbstractBatchJobHandler method writeConfiguration.

@Override
public byte[] writeConfiguration(T configuration) {
    JSONObject jsonObject = getJsonConverterInstance().toJsonObject(configuration);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    Writer writer = StringUtil.writerForStream(outStream);
    jsonObject.write(writer);
    IoUtil.flushSilently(writer);
    return outStream.toByteArray();
}
Also used : JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer)

Example 24 with JSONObject

use of org.camunda.bpm.engine.impl.util.json.JSONObject in project camunda-bpm-platform by camunda.

the class DeleteHistoricProcessInstanceBatchConfigurationJsonConverter method readProcessInstanceIds.

protected List<String> readProcessInstanceIds(JSONObject jsonObject) {
    List<Object> objects = JsonUtil.jsonArrayAsList(jsonObject.getJSONArray(HISTORIC_PROCESS_INSTANCE_IDS));
    List<String> processInstanceIds = new ArrayList<String>();
    for (Object object : objects) {
        processInstanceIds.add((String) object);
    }
    return processInstanceIds;
}
Also used : ArrayList(java.util.ArrayList) JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject)

Example 25 with JSONObject

use of org.camunda.bpm.engine.impl.util.json.JSONObject in project camunda-bpm-platform by camunda.

the class JsonUtilTest method testJsonObjectToMap.

@Test
@SuppressWarnings("unchecked")
public void testJsonObjectToMap() {
    assertNull(jsonObjectAsMap(null));
    JSONObject jsonObject = new JSONObject();
    Map<String, Object> map = jsonObjectAsMap(jsonObject);
    assertTrue(map.isEmpty());
    jsonObject.put("boolean", true);
    jsonObject.put("int", 12);
    jsonObject.put("double", 11.1);
    jsonObject.put("long", 13l);
    jsonObject.put("string", "test");
    jsonObject.put("list", Collections.singletonList("test"));
    jsonObject.put("map", Collections.singletonMap("test", "test"));
    jsonObject.put("date", new Date(0));
    jsonObject.put("null", JSONObject.NULL);
    map = jsonObjectAsMap(jsonObject);
    assertEquals(9, map.size());
    assertEquals(true, map.get("boolean"));
    assertEquals(12, map.get("int"));
    assertEquals(11.1, map.get("double"));
    assertEquals(13l, map.get("long"));
    assertEquals("test", map.get("string"));
    List<Object> embeddedList = (List<Object>) map.get("list");
    assertEquals(1, embeddedList.size());
    assertEquals("test", embeddedList.get(0));
    Map<String, Object> embeddedMap = (Map<String, Object>) map.get("map");
    assertEquals(1, embeddedMap.size());
    assertTrue(embeddedMap.containsKey("test"));
    assertEquals("test", embeddedMap.get("test"));
    Date embeddedDate = (Date) map.get("date");
    assertEquals(new Date(0), embeddedDate);
    assertTrue(map.containsKey("null"));
    assertNull(map.get("null"));
}
Also used : JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) List(java.util.List) JsonUtil.jsonArrayAsList(org.camunda.bpm.engine.impl.util.JsonUtil.jsonArrayAsList) JsonUtil.jsonObjectAsMap(org.camunda.bpm.engine.impl.util.JsonUtil.jsonObjectAsMap) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JSONObject (org.camunda.bpm.engine.impl.util.json.JSONObject)40 ArrayList (java.util.ArrayList)10 JSONArray (org.camunda.bpm.engine.impl.util.json.JSONArray)5 TaskQueryImpl (org.camunda.bpm.engine.impl.TaskQueryImpl)4 QueryOrderingProperty (org.camunda.bpm.engine.impl.QueryOrderingProperty)3 JsonTaskQueryConverter (org.camunda.bpm.engine.impl.json.JsonTaskQueryConverter)3 QueryProperty (org.camunda.bpm.engine.query.QueryProperty)3 Map (java.util.Map)2 QueryOperator (org.camunda.bpm.engine.impl.QueryOperator)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Writer (java.io.Writer)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 Direction (org.camunda.bpm.engine.impl.Direction)1 QueryEntityRelationCondition (org.camunda.bpm.engine.impl.QueryEntityRelationCondition)1