net.javacrumbs.jsonunit.core.Option Java Examples

The following examples show how to use net.javacrumbs.jsonunit.core.Option. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChannelDefinitionResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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'"
                    + " }"
                    + "}");
}
 
Example #2
Source File: ExecutionActiveActivitiesCollectionResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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'"
                    + "]");
}
 
Example #3
Source File: JsonComparisonOptionsConverter.java    From vividus with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: TaskQueryResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #5
Source File: EventDefinitionResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * 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()
                    + "}");
}
 
Example #6
Source File: ProcessInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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() + "'"
                    + "}");
}
 
Example #7
Source File: ProcessInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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() + "'"
                    + "}");
}
 
Example #8
Source File: CaseInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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() + "'"
                    + "}");
}
 
Example #9
Source File: CaseInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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() + "'"
                    + "}");
}
 
Example #10
Source File: CaseInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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() + "'"
                    + "}");
}
 
Example #11
Source File: ContentItemResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #12
Source File: ContentItemResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #13
Source File: ProcessInstanceResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test suspending a single process instance.
 */
@Test
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testActivateProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
    runtimeService.suspendProcessInstanceById(processInstance.getId());

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

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

    // Check engine id instance is suspended
    assertThat(runtimeService.createProcessInstanceQuery().active().processInstanceId(processInstance.getId()).count()).isEqualTo(1);

    // Check resulting instance is suspended
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "id: '" + processInstance.getId() + "',"
                    + "suspended: false"
                    + "}");

    // Activating again should result in conflict
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
 
Example #14
Source File: ProcessDefinitionResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #15
Source File: ProcessDefinitionResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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()) + "'"
                    + "}");
}
 
Example #16
Source File: ProcessDefinitionResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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"
                    + "}");
}
 
Example #17
Source File: ProcessInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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");
}
 
Example #18
Source File: JsonPatchMatcherTests.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Test
void shouldMatchWithOptions() {
    final boolean result = JsonPatchMatcher.jsonEquals("[1,2]")
            .withOptions(Options.empty().with(Option.IGNORING_ARRAY_ORDER))
            .matches("[2,1]");
    assertThat(result).isTrue();
}
 
Example #19
Source File: TaskResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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 + "'"
                    + "}");
}
 
Example #20
Source File: CaseInstanceVariablesCollectionResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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");
}
 
Example #21
Source File: CaseInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #22
Source File: JsonResponseValidationStepsTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #23
Source File: DeploymentResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
        }
    }
}
 
Example #24
Source File: JsonComparisonOptionsConverterTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #25
Source File: CaseInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@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'"
                    + "}");
}
 
Example #26
Source File: CaseInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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");
}
 
Example #27
Source File: JpaRestTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@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'"
                    + "}");
}
 
Example #28
Source File: TaskCommentResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@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()) + "'"
                    + "}");
}
 
Example #29
Source File: ChannelDefinitionResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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() + "'"
                    + "}");
}
 
Example #30
Source File: ProcessInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@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'"
                    + "}");
}