org.apache.commons.lang3.reflect.TypeLiteral#net.javacrumbs.jsonunit.core.Option源码实例Demo

下面列出了org.apache.commons.lang3.reflect.TypeLiteral#net.javacrumbs.jsonunit.core.Option 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: vividus   文件: JsonComparisonOptionsConverter.java
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public Options convertValue(String value, Type type)
{
    Type listOfOption = new TypeLiteral<List<Option>>() { }.getType();
    Set options = new HashSet<>(fluentEnumListConverter.convertValue(value, listOfOption));
    if (options.isEmpty())
    {
        return Options.empty();
    }
    Iterator<Option> iterator = options.iterator();
    Options jsonComparisonOptions = new Options(iterator.next());
    while (iterator.hasNext())
    {
        jsonComparisonOptions = jsonComparisonOptions.with(iterator.next());
    }
    return jsonComparisonOptions;
}
 
/**
 * Test getting a single event definition. GET event-registry-repository/event-definitions/{eventDefinitionResource}
 */
@EventDeploymentAnnotation(resources = { "org/flowable/eventregistry/rest/service/api/repository/simpleEvent.event" })
public void testGetEventDefinition() throws Exception {

    EventDefinition eventDefinition = repositoryService.createEventDefinitionQuery().singleResult();

    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + EventRestUrls.createRelativeResourceUrl(EventRestUrls.URL_EVENT_DEFINITION, eventDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "id: '" + eventDefinition.getId() + "',"
                    + "url: '" + httpGet.getURI().toString() + "',"
                    + "key: '" + eventDefinition.getKey() + "',"
                    + "version: " + eventDefinition.getVersion() + ","
                    + "name: '" + eventDefinition.getName() + "',"
                    + "description: " + eventDefinition.getDescription() + ","
                    + "deploymentId: '" + eventDefinition.getDeploymentId() + "',"
                    + "deploymentUrl: '" + SERVER_URL_PREFIX + EventRestUrls
                    .createRelativeResourceUrl(EventRestUrls.URL_DEPLOYMENT, eventDefinition.getDeploymentId()) + "',"
                    + "resourceName: '" + eventDefinition.getResourceName() + "',"
                    + "category: " + eventDefinition.getCategory()
                    + "}");
}
 
@Test
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testGetProcessInstanceLocalDateVariable() throws Exception {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    LocalDate now = LocalDate.now();
    runtimeService.setVariable(processInstance.getId(), "variable", now);

    CloseableHttpResponse response = executeRequest(
            new HttpGet(
                    SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "variable")),
            HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());

    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'variable',"
                    + "  type: 'localDate',"
                    + "  value: '" + now.toString() + "'"
                    + "}");
}
 
@Test
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testGetProcessInstanceInstantVariable() throws Exception {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Instant now = Instant.now();
    Instant nowWithoutNanos = now.truncatedTo(ChronoUnit.MILLIS);
    runtimeService.setVariable(processInstance.getId(), "variable", now);

    CloseableHttpResponse response = executeRequest(
            new HttpGet(
                    SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "variable")),
            HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());

    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'variable',"
                    + "  type: 'instant',"
                    + "  value: '" + nowWithoutNanos.toString() + "'"
                    + "}");
}
 
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testGetCaseInstanceInstantVariable() throws Exception {

    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
    Instant now = Instant.now();
    Instant nowWithoutNanos = now.truncatedTo(ChronoUnit.MILLIS);
    runtimeService.setVariable(caseInstance.getId(), "variable", now);

    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE,
                    caseInstance.getId(), "variable")), HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());

    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'variable',"
                    + "  type: 'instant',"
                    + "  value: '" + nowWithoutNanos.toString() + "'"
                    + "}");
}
 
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testGetCaseInstanceLocalDateVariable() throws Exception {

    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
    LocalDate now = LocalDate.now();
    runtimeService.setVariable(caseInstance.getId(), "variable", now);

    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE,
                    caseInstance.getId(), "variable")), HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());

    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'variable',"
                    + "  type: 'localDate',"
                    + "  value: '" + now.toString() + "'"
                    + "}");
}
 
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testGetCaseInstanceLocalDateTimeVariable() throws Exception {

    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime nowWithoutNanos = now.truncatedTo(ChronoUnit.MILLIS);
    runtimeService.setVariable(caseInstance.getId(), "variable", now);

    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE,
                    caseInstance.getId(), "variable")), HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());

    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'variable',"
                    + "  type: 'localDateTime',"
                    + "  value: '" + nowWithoutNanos.toString() + "'"
                    + "}");
}
 
@ChannelDeploymentAnnotation(resources = { "simpleChannel.channel" })
public void testGetChannelDefinitionResourceData() throws Exception {
    ChannelDefinition channelDefinition = repositoryService.createChannelDefinitionQuery().singleResult();

    HttpGet httpGet = new HttpGet(
            SERVER_URL_PREFIX + EventRestUrls.createRelativeResourceUrl(EventRestUrls.URL_CHANNEL_DEFINITION_RESOURCE_CONTENT, channelDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);

    // Check "OK" status
    String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
    closeResponse(response);
    assertThat(content).isNotNull();
    JsonNode eventNode = objectMapper.readTree(content);
    assertThatJson(eventNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "key: 'myChannel',"
                    + "channelEventKeyDetection:"
                    + " {"
                    + "   fixedValue: 'myEvent'"
                    + " }"
                    + "}");
}
 
源代码9 项目: flowable-engine   文件: TaskQueryResourceTest.java
protected void assertTenantIdPresent(String url, ObjectNode requestNode, String tenantId) throws IOException {
    // Do the actual call
    HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
    post.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(post, HttpStatus.SC_OK);

    // Check status and size
    JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
    assertThatJson(rootNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "data: [ {"
                    + "          tenantId: 'testTenant'"
                    + "      } ]"
                    + "}");
    closeResponse(response);
}
 
@Test
@Deployment
public void testGetActivities() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");

    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_ACTIVITIES_COLLECTION, processInstance.getId())),
            HttpStatus.SC_OK);

    // Check resulting instance
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThat(responseNode.isArray()).isTrue();
    assertThatJson(responseNode)
            .when(Option.IGNORING_ARRAY_ORDER)
            .isEqualTo("["
                    + "'waitState', 'anotherWaitState'"
                    + "]");
}
 
@ValueSource(strings = { "ignoring extra fields, ignoring_extra_array_items",
        "IGNORING_EXTRA_FIELDS, IGNORING_EXTRA_ARRAY_ITEMS" })
@ParameterizedTest
void testConvertValue(String valueToConvert)
{
    JsonComparisonOptionsConverter converter = new JsonComparisonOptionsConverter(
            new FluentEnumListConverter(new FluentTrimmedEnumConverter()));
    assertTrue(converter.convertValue(valueToConvert, Options.class).contains(Option.IGNORING_EXTRA_FIELDS));
    assertTrue(converter.convertValue(valueToConvert, Options.class).contains(Option.IGNORING_EXTRA_ARRAY_ITEMS));
}
 
源代码12 项目: flowable-engine   文件: DeploymentResourceTest.java
/**
 * Test deploying singe event definition file. POST event-registry-repository/deployments
 */
public void testPostNewDeploymentEventFile() throws Exception {
    try {
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + EventRestUrls.createRelativeResourceUrl(EventRestUrls.URL_DEPLOYMENT_COLLECTION));
        httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("simpleEvent.event", "application/json",
                ReflectUtil.getResourceAsStream("org/flowable/eventregistry/rest/service/api/repository/simpleEvent.event"), null));
        CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);

        // Check deployment
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);

        String newDeploymentId = responseNode.get("id").textValue();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + "url: '" + SERVER_URL_PREFIX + EventRestUrls.createRelativeResourceUrl(EventRestUrls.URL_DEPLOYMENT, newDeploymentId) + "',"
                        + "name: 'simpleEvent',"
                        + "tenantId: \"\","
                        + "category: null"
                        + "}");

        assertThat(repositoryService.createDeploymentQuery().deploymentId(newDeploymentId).count()).isEqualTo(1L);

        // Check if process is actually deployed in the deployment
        List<String> resources = repositoryService.getDeploymentResourceNames(newDeploymentId);
        assertThat(resources)
                .containsOnly("simpleEvent.event");
        assertThat(repositoryService.createEventDefinitionQuery().deploymentId(newDeploymentId).count()).isEqualTo(1L);

    } finally {
        // Always cleanup any created deployments, even if the test failed
        List<EventDeployment> deployments = repositoryService.createDeploymentQuery().list();
        for (EventDeployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId());
        }
    }
}
 
源代码13 项目: vividus   文件: JsonResponseValidationStepsTests.java
@Test
void testIsDataByJsonPathEqualIgnoringArrayOrderAndExtraArrayItems()
{
    when(httpTestContext.getJsonContext()).thenReturn(JSON);
    testIsDataByJsonPathEqual(ARRAY_PATH, "[2]", ARRAY_PATH_RESULT,
            new Options(Option.IGNORING_ARRAY_ORDER, Option.IGNORING_EXTRA_ARRAY_ITEMS));
}
 
/**
 * Test updating a single process variable using a binary stream. PUT runtime/process-instances/{processInstanceId}/variables/{variableName}
 */
@Test
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testUpdateBinaryProcessVariable() throws Exception {

    ProcessInstance processInstance = runtimeService
            .startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    runtimeService.setVariable(processInstance.getId(), "binaryVariable", "Initial binary value".getBytes());

    InputStream binaryContent = new ByteArrayInputStream("This is binary content".getBytes());

    // Add name and type
    Map<String, String> additionalFields = new HashMap<>();
    additionalFields.put("name", "binaryVariable");
    additionalFields.put("type", "binary");

    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "binaryVariable"));
    httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/octet-stream", binaryContent, additionalFields));
    CloseableHttpResponse response = executeBinaryRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "name: 'binaryVariable',"
                    + "type : 'binary',"
                    + "value : null,"
                    + "valueUrl : '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, processInstance.getId(), "binaryVariable") + "',"
                    + "scope : 'local'"
                    + "}");

    // Check actual value of variable in engine
    Object variableValue = runtimeService.getVariableLocal(processInstance.getId(), "binaryVariable");
    assertThat(variableValue).isInstanceOf(byte[].class);
    assertThat(new String((byte[]) variableValue)).isEqualTo("This is binary content");
}
 
源代码15 项目: allure-java   文件: JsonPatchMatcherTests.java
@Test
void shouldMatchWithOptions() {
    final boolean result = JsonPatchMatcher.jsonEquals("[1,2]")
            .withOptions(Options.empty().with(Option.IGNORING_ARRAY_ORDER))
            .matches("[2,1]");
    assertThat(result).isTrue();
}
 
源代码16 项目: flowable-engine   文件: ContentItemResourceTest.java
public void testGetContentItem() throws Exception {
    String contentItemId = createContentItem("test.pdf", "application/pdf", null, "12345",
            null, null, "test", "test2");

    ContentItem contentItem = contentService.createContentItemQuery().singleResult();

    try {
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + ContentRestUrls.createRelativeResourceUrl(
                ContentRestUrls.URL_CONTENT_ITEM, contentItemId));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);

        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + "  id: '" + contentItem.getId() + "',"
                        + "  name: '" + contentItem.getName() + "',"
                        + "  mimeType: '" + contentItem.getMimeType() + "',"
                        + "  taskId: null,"
                        + "  tenantId: '',"
                        + "  processInstanceId: '" + contentItem.getProcessInstanceId() + "',"
                        + "  created: " + new TextNode(getISODateStringWithTZ(contentItem.getCreated())) + ","
                        + "  createdBy: '" + contentItem.getCreatedBy() + "',"
                        + "  lastModified: " + new TextNode(getISODateStringWithTZ(contentItem.getLastModified())) + ","
                        + "  lastModifiedBy: '" + contentItem.getLastModifiedBy() + "',"
                        + "  url: '" + httpGet.getURI().toString() + "'"
                        + "}");

    } finally {
        contentService.deleteContentItem(contentItemId);
    }
}
 
源代码17 项目: flowable-engine   文件: ContentItemResourceTest.java
public void testUpdateContentItem() throws Exception {
    String contentItemId = createContentItem("test.pdf", "application/pdf", null,
            "12345", null, null, "test", "test2");

    ContentItem contentItem = contentService.createContentItemQuery().singleResult();

    try {
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "test2.txt");
        requestNode.put("mimeType", "application/txt");
        requestNode.put("createdBy", "testb");
        requestNode.put("lastModifiedBy", "testc");

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + ContentRestUrls.createRelativeResourceUrl(
                ContentRestUrls.URL_CONTENT_ITEM, contentItemId));
        httpPut.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);

        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + "  id: '" + contentItem.getId() + "',"
                        + "  name: 'test2.txt',"
                        + "  mimeType: 'application/txt',"
                        + "  taskId: null,"
                        + "  tenantId: '',"
                        + "  processInstanceId: '" + contentItem.getProcessInstanceId() + "',"
                        + "  created: " + new TextNode(getISODateStringWithTZ(contentItem.getCreated())) + ","
                        + "  createdBy: 'testb',"
                        + "  lastModified: " + new TextNode(getISODateStringWithTZ(contentItem.getLastModified())) + ","
                        + "  lastModifiedBy: 'testc'"
                        + "}");

    } finally {
        contentService.deleteContentItem(contentItemId);
    }
}
 
@Test
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testUpdateLocalDateTimeProcessVariable() throws Exception {
    LocalDateTime initial = LocalDateTime.parse("2020-01-18T12:32:45");
    LocalDateTime tenDaysLater = initial.plus(10, ChronoUnit.DAYS);
    ProcessInstance processInstance = runtimeService
            .startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    runtimeService.setVariable(processInstance.getId(), "myVar", initial);

    // Update variable
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "myVar");
    requestNode.put("value", "2020-01-28T12:32:45");
    requestNode.put("type", "localDateTime");

    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVar"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    assertThatJson(runtimeService.getVariable(processInstance.getId(), "myVar"))
            .isEqualTo(tenDaysLater);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  value: '2020-01-28T12:32:45'"
                    + "}");
}
 
源代码19 项目: flowable-engine   文件: TaskResourceTest.java
/**
 * Test getting a single task, spawned by a case. GET cmmn-runtime/tasks/{taskId}
 */
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testGetCaseTask() throws Exception {
    Calendar now = Calendar.getInstance();
    cmmnEngineConfiguration.getClock().setCurrentTime(now.getTime());

    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
    Task task = taskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
    taskService.setDueDate(task.getId(), now.getTime());
    taskService.setOwner(task.getId(), "owner");
    task = taskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
    assertThat(task).isNotNull();

    String url = buildUrl(CmmnRestUrls.URL_TASK, task.getId());
    CloseableHttpResponse response = executeRequest(new HttpGet(url), HttpStatus.SC_OK);

    // Check resulting task
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + " id: '" + task.getId() + "',"
                    + " assignee: '" + task.getAssignee() + "',"
                    + " owner: '" + task.getOwner() + "',"
                    + " formKey: '" + task.getFormKey() + "',"
                    + " description: '" + task.getDescription() + "',"
                    + " name: '" + task.getName() + "',"
                    + " priority: " + task.getPriority() + ","
                    + " parentTaskId: null,"
                    + " delegationState: null,"
                    + " tenantId: \"\","
                    + " dueDate: " + new TextNode(getISODateStringWithTZ(task.getDueDate())) + ","
                    + " createTime: " + new TextNode(getISODateStringWithTZ(task.getCreateTime())) + ","
                    + " caseInstanceUrl: '" + buildUrl(CmmnRestUrls.URL_CASE_INSTANCE, task.getScopeId()) + "',"
                    + " caseDefinitionUrl: '" + buildUrl(CmmnRestUrls.URL_CASE_DEFINITION, task.getScopeDefinitionId()) + "',"
                    + " url: '" + url + "'"
                    + "}");
}
 
/**
 * Test creating a single case variable. POST cmmn-runtime/case-instance/{caseInstanceId}/variables
 */
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testCreateSingleProcessInstanceVariable() throws Exception {
    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();

    ArrayNode requestNode = objectMapper.createArrayNode();
    ObjectNode variableNode = requestNode.addObject();
    variableNode.put("name", "myVariable");
    variableNode.put("value", "simple string value");
    variableNode.put("type", "string");

    // Create a new local variable
    HttpPost httpPost = new HttpPost(
            SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE_COLLECTION, caseInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0);
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'myVariable',"
                    + "  value: 'simple string value',"
                    + "  scope: 'global',"
                    + "  type: 'string'"
                    + "}");

    assertThat(runtimeService.hasVariable(caseInstance.getId(), "myVariable")).isTrue();
    assertThat(runtimeService.getVariable(caseInstance.getId(), "myVariable")).isEqualTo("simple string value");
}
 
/**
 * Test getting a process instance variable. GET cmmn-runtime/case-instances/{caseInstanceId}/variables/{variableName}
 */
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testGetCaseInstanceVariable() throws Exception {

    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
    runtimeService.setVariable(caseInstance.getId(), "variable", "caseValue");

    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE,
                    caseInstance.getId(), "variable")), HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  value: 'caseValue',"
                    + "  name: 'variable',"
                    + "  type: 'string'"
                    + "}");

    // Unexisting case
    closeResponse(executeRequest(
            new HttpGet(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE, "unexisting", "variable")),
            HttpStatus.SC_NOT_FOUND));

    // Unexisting variable
    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE,
            caseInstance.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND));
}
 
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testUpdateLocalDateTimeProcessVariable() throws Exception {

    LocalDateTime initial = LocalDateTime.parse("2020-01-18T12:32:45");
    LocalDateTime tenDaysLater = initial.plusDays(10);
    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase")
            .variables(Collections.singletonMap("overlappingVariable", (Object) "processValue")).start();
    runtimeService.setVariable(caseInstance.getId(), "myVar", initial);

    // Update variable
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "myVar");
    requestNode.put("value", "2020-01-28T12:32:45");
    requestNode.put("type", "localDateTime");

    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE, caseInstance.getId(), "myVar"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    assertThatJson(runtimeService.getVariable(caseInstance.getId(), "myVar")).isEqualTo(tenDaysLater);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  value: '2020-01-28T12:32:45'"
                    + "}");
}
 
/**
 * Test updating a single case variable using a binary stream. PUT cmmn-runtime/case-instances/{caseInstanceId}/variables/{variableName}
 */
@CmmnDeployment(resources = { "org/flowable/cmmn/rest/service/api/repository/oneHumanTaskCase.cmmn" })
public void testUpdateBinaryCaseVariable() throws Exception {
    CaseInstance caseInstance = runtimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase")
            .variables(Collections.singletonMap("overlappingVariable", (Object) "processValue")).start();
    runtimeService.setVariable(caseInstance.getId(), "binaryVariable", "Initial binary value".getBytes());

    InputStream binaryContent = new ByteArrayInputStream("This is binary content".getBytes());

    // Add name and type
    Map<String, String> additionalFields = new HashMap<>();
    additionalFields.put("name", "binaryVariable");
    additionalFields.put("type", "binary");

    HttpPut httpPut = new HttpPut(
            SERVER_URL_PREFIX + CmmnRestUrls.createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE, caseInstance.getId(), "binaryVariable"));
    httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/octet-stream", binaryContent, additionalFields));
    CloseableHttpResponse response = executeBinaryRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'binaryVariable',"
                    + "  value: null,"
                    + "  type: 'binary',"
                    + "  valueUrl: '" + SERVER_URL_PREFIX + CmmnRestUrls
                    .createRelativeResourceUrl(CmmnRestUrls.URL_CASE_INSTANCE_VARIABLE_DATA, caseInstance.getId(), "binaryVariable") + "'"
                    + "}");

    // Check actual value of variable in engine
    Object variableValue = runtimeService.getVariable(caseInstance.getId(), "binaryVariable");
    assertThat(variableValue).isNotNull();
    assertThat(variableValue).isInstanceOf(byte[].class);
    assertThat(new String((byte[]) variableValue)).isEqualTo("This is binary content");
}
 
源代码24 项目: flowable-engine   文件: TaskCommentResourceTest.java
@Test
@Deployment(resources = { "org/flowable/rest/service/api/oneTaskProcess.bpmn20.xml" })
public void testCreateCommentWithProcessInstanceId() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().singleResult();

    ObjectNode requestNode = objectMapper.createObjectNode();
    String message = "test";
    requestNode.put("message", message);
    requestNode.put("saveProcessInstanceId", true);

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, task.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);

    List<Comment> commentsOnTask = taskService.getTaskComments(task.getId());
    assertThat(commentsOnTask).isNotNull();
    assertThat(commentsOnTask).hasSize(1);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "message: '" + message + "',"
                    + "time: '${json-unit.any-string}',"
                    + "taskId: '" + task.getId() + "',"
                    + "taskUrl: '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), commentsOnTask.get(0).getId()) + "',"
                    + "processInstanceId: '" + processInstance.getId() + "',"
                    + "processInstanceUrl: '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, processInstance.getId(),
                            commentsOnTask.get(0).getId()) + "'"
                    + "}");
}
 
/**
 * Test getting a single event definition. GET event-registry-repository/channel-definitions/{channelDefinitionResource}
 */
@ChannelDeploymentAnnotation(resources = { "org/flowable/eventregistry/rest/service/api/repository/simpleChannel.channel" })
public void testGetChannelDefinition() throws Exception {

    ChannelDefinition channelDefinition = repositoryService.createChannelDefinitionQuery().singleResult();

    HttpGet httpGet = new HttpGet(
            SERVER_URL_PREFIX + EventRestUrls.createRelativeResourceUrl(EventRestUrls.URL_CHANNEL_DEFINITION, channelDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "id: '" + channelDefinition.getId() + "',"
                    + "url: '" + httpGet.getURI().toString() + "',"
                    + "key: '" + channelDefinition.getKey() + "',"
                    + "version: " + channelDefinition.getVersion() + ","
                    + "name: '" + channelDefinition.getName() + "',"
                    + "description: '" + channelDefinition.getDescription() + "',"
                    + "deploymentId: '" + channelDefinition.getDeploymentId() + "',"
                    + "deploymentUrl: '" + SERVER_URL_PREFIX + EventRestUrls
                    .createRelativeResourceUrl(EventRestUrls.URL_DEPLOYMENT, channelDefinition.getDeploymentId()) + "',"
                    + "resourceName: '" + channelDefinition.getResourceName() + "',"
                    + "category: '" + channelDefinition.getCategory() + "'"
                    + "}");
}
 
源代码26 项目: flowable-engine   文件: JpaRestTest.java
@Test
@Deployment(resources = { "org/flowable/rest/api/jpa/jpa-process.bpmn20.xml" })
public void testGetJpaVariableViaTaskCollection() throws Exception {

    // Get JPA managed entity through the repository
    Message message = messageRepository.findOne(1L);
    assertThat(message).isNotNull();
    assertThat(message.getText()).isEqualTo("Hello World");

    // add the entity to the process variables and start the process
    Map<String, Object> processVariables = new HashMap<>();
    processVariables.put("message", message);

    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("jpa-process", processVariables);
    assertThat(processInstance).isNotNull();

    Task task = processEngine.getTaskService().createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("Activiti is awesome!");

    // Request all variables (no scope provides) which include global and local
    HttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?includeProcessVariables=true"),
            HttpStatus.SC_OK);

    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data").get(0);
    assertThat(dataNode).isNotNull();

    JsonNode variableNode = dataNode.get("variables").get(0);
    assertThat(variableNode).isNotNull();

    // check for message variable of type serializable
    assertThatJson(variableNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "name: 'message',"
                    + "type: 'serializable',"
                    + "valueUrl: '${json-unit.any-string}',"
                    + "scope: 'global'"
                    + "}");
}
 
/**
 * Test getting a single process definition. GET repository/process-definitions/{processDefinitionResource}
 */
@Test
@Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetProcessDefinition() throws Exception {

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "id: '" + processDefinition.getId() + "',"
                    + "name: '" + processDefinition.getName() + "',"
                    + "key: '" + processDefinition.getKey() + "',"
                    + "category: '" + processDefinition.getCategory() + "',"
                    + "version: " + processDefinition.getVersion() + ","
                    + "description: '" + processDefinition.getDescription() + "',"
                    + "url: '" + httpGet.getURI().toString() + "',"
                    + "deploymentId: '" + processDefinition.getDeploymentId() + "',"
                    + "deploymentUrl: '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, processDefinition.getDeploymentId()) + "',"
                    + "resource: '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName())
                    + "',"
                    + "graphicalNotationDefined: false,"
                    + "diagramResource: null"
                    + "}");
}
 
/**
 * Test getting a single process definition with a graphical notation defined. GET repository/process-definitions/{processDefinitionResource}
 */
@Test
@Deployment
public void testGetProcessDefinitionWithGraphicalNotation() throws Exception {

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "id: '" + processDefinition.getId() + "',"
                    + "name: " + processDefinition.getName() + ","
                    + "key: '" + processDefinition.getKey() + "',"
                    + "category: '" + processDefinition.getCategory() + "',"
                    + "version: " + processDefinition.getVersion() + ","
                    + "description: " + processDefinition.getDescription() + ","
                    + "url: '" + httpGet.getURI().toString() + "',"
                    + "deploymentId: '" + processDefinition.getDeploymentId() + "',"
                    + "deploymentUrl: '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, processDefinition.getDeploymentId()) + "',"
                    + "resource: '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName())
                    + "',"
                    + "graphicalNotationDefined: true,"
                    + "diagramResource: '" + SERVER_URL_PREFIX + RestUrls
                    .createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(),
                            processDefinition.getDiagramResourceName()) + "'"
                    + "}");
}
 
/**
 * Test activating a suspended process definition. POST repository/process-definitions/{processDefinitionId}
 */
@Test
@Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testActivateProcessDefinition() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());

    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertThat(processDefinition.isSuspended()).isTrue();

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "activate");

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    // Check "OK" status
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "suspended: false"
                    + "}");

    // Check if process-definition is suspended
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertThat(processDefinition.isSuspended()).isFalse();
}
 
/**
 * Test getting a process instance variable. GET runtime/process-instances/{processInstanceId}/variables/{variableName}
 */
@Test
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testGetProcessInstanceVariable() throws Exception {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    runtimeService.setVariable(processInstance.getId(), "variable", "processValue");

    CloseableHttpResponse response = executeRequest(new HttpGet(
                    SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "variable")),
            HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "name: 'variable',"
                    + "type: 'string',"
                    + "value: 'processValue',"
                    + "scope: null"
                    + "}");

    // Illegal scope
    closeResponse(executeRequest(new HttpGet(
                    SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "variable")
                            + "?scope=illegal"),
            HttpStatus.SC_BAD_REQUEST));

    // Unexisting process
    closeResponse(executeRequest(
            new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, "unexisting", "variable")),
            HttpStatus.SC_NOT_FOUND));

    // Unexisting variable
    closeResponse(executeRequest(new HttpGet(
                    SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "unexistingVariable")),
            HttpStatus.SC_NOT_FOUND));
}