APISonar


com.jayway.restassured.http.ContentType.JSON

> com > jayway > restassured > http > ContentType > JSON
com APIs jayway APIs restassured APIs http APIs ContentType APIs JSON APIs

Example 1
public void testEvaluateDecision_NotFound() {
    String message = "expected message";
    when(decisionEvaluationBuilderMock.evaluate()).thenThrow(new NotFoundException(message));

    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", Collections.emptyMap());

    given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID)
      .contentType(POST_JSON_CONTENT_TYPE).body(json)
      .then().expect()
        .statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON)
        .body("type", is(InvalidRequestException.class.getSimpleName()))
        .body("message", containsString(message))
    .when().post(EVALUATE_DECISION_URL);
  }
Example 2
public void testSetRetriesByProcessWithoutRetries() {
    Map<String, Object> messageBodyJson = new HashMap<String, Object>();
    messageBodyJson.put("processInstances", null);

    given()
        .contentType(ContentType.JSON)
        .body(messageBodyJson)
        .then().expect()
        .statusCode(Status.BAD_REQUEST.getStatusCode())
        .when().post(SET_JOB_RETRIES_ASYNC_URL);
  }
Example 3
public void testSetJobPriorityToExtremeValue() {
    Map<String, Object> priorityJson = new HashMap<String, Object>();
    priorityJson.put("priority", Long.MAX_VALUE);

    given()
      .pathParam("id", MockProvider.EXAMPLE_JOB_ID)
      .contentType(ContentType.JSON)
      .body(priorityJson)
    .then().expect()
      .statusCode(Status.NO_CONTENT.getStatusCode())
    .when().put(JOB_RESOURCE_SET_PRIORITY_URL);

    verify(mockManagementService).setJobPriority(MockProvider.EXAMPLE_JOB_ID, Long.MAX_VALUE);
  }
Example 4
private Response publishEvent(final EventType eventType) {
        return given()
                .body("[{\"foo\":\"bar\"}]")
                .contentType(ContentType.JSON)
                .post(MessageFormat.format("/event-types/{0}/events", eventType.getName()));
    }
Example 5
public void testGetTaskComments() {
    Response response = given()
      .pathParam("id", EXAMPLE_TASK_ID)
      .header("accept", MediaType.APPLICATION_JSON)
    .then().expect()
      .statusCode(Status.OK.getStatusCode())
      .contentType(ContentType.JSON)
      .body("$.size()", equalTo(1))
    .when()
      .get(SINGLE_TASK_COMMENTS_URL);

    verifyTaskComments(mockTaskComments, response);
    verify(taskServiceMock).getTaskComments(EXAMPLE_TASK_ID);
  }
Example 6
public void testSetJobDuedateNull() {
    Map<String, Object> duedateVariableJson = new HashMap<String, Object>();
    duedateVariableJson.put("duedate", null);

    given().pathParam("id", MockProvider.EXAMPLE_JOB_ID).contentType(ContentType.JSON).body(duedateVariableJson).then().expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
    .when().put(JOB_RESOURCE_SET_DUEDATE_URL);

    verify(mockManagementService).setJobDuedate(MockProvider.EXAMPLE_JOB_ID, null);

  }
Example 7
public void shouldThrowBadRequestExceptionWhenFactoryConfigurationNotProvided() throws Exception {
        final Response response = given().auth()
                                         .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
                                         .contentType(ContentType.JSON)
                                         .expect()
                                         .statusCode(400)
                                         .post(SERVICE_PATH);
        final String errMessage = getFromResponse(response, ServiceError.class).getMessage();
        assertEquals(errMessage, "Factory configuration required");
    }
Example 8
public void testPutSingleVariableWithNoValue() {
    String variableKey = "aVariableKey";

    given().pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey)
      .contentType(ContentType.JSON).body(EMPTY_JSON_OBJECT)
      .header("accept", MediaType.APPLICATION_JSON)
      .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
      .when().put(SINGLE_TASK_PUT_SINGLE_VARIABLE_URL);

    verify(taskServiceMock).setVariable(eq(EXAMPLE_TASK_ID), eq(variableKey),
        argThat(EqualsNullValue.matcher()));
  }
Example 9
protected ValidatableResponse streamTestMatch(String streamId, String request) {
        return given()
                .when()
                .body(request)
                .post("/streams/" + streamId + "/testMatch")
                .then()
                .contentType(ContentType.JSON)
                .statusCode(200);
    }
Example 10
public static void blacklist(final String name, final BlacklistService.Type type) throws IOException {
        given()
                .contentType(ContentType.JSON)
                .put(String.format("%s/%s/%s", BLACKLIST_URL, type, name))
                .then()
                .statusCode(HttpStatus.SC_NO_CONTENT);
    }
Example 11
public void testDeleteProcessInstance() {
    String deleteReason = "some delete reason";
    Map<String, String> messageBodyJson = new HashMap<String, String>();
    messageBodyJson.put("deleteReason", deleteReason);
    
    given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).contentType(ContentType.JSON).body(messageBodyJson)
      .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
      .when().delete(PROCESS_INSTANCE_URL);
    
    verify(runtimeServiceMock).deleteProcessInstance(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, deleteReason);
  }
Example 12
public void testGetIdentityLinksByType() {
    Map<String, Object> expectedGroupIdentityLink = toExpectedJsonMap(mockCandidateGroupIdentityLink);
    Map<String, Object> expectedGroupIdentityLink2 = toExpectedJsonMap(mockCandidateGroup2IdentityLink);

    given().pathParam("id", EXAMPLE_TASK_ID).queryParam("type", IdentityLinkType.CANDIDATE)
      .header("accept", MediaType.APPLICATION_JSON)
      .then().expect()
        .statusCode(Status.OK.getStatusCode()).contentType(ContentType.JSON)
        .body("$.size()", equalTo(2))
        .body("$", hasItem(expectedGroupIdentityLink))
        .body("$", hasItem(expectedGroupIdentityLink2))
      .when().get(TASK_IDENTITY_LINKS_URL);

    verify(taskServiceMock).getIdentityLinksForTask(EXAMPLE_TASK_ID);
  }
Example 13
public void testExecuteJobRuntimeException() {
    String jobId = MockProvider.EXAMPLE_JOB_ID;

    doThrow(new RuntimeException("Runtime exception")).when(mockManagementService).executeJob(jobId);

    given().pathParam("id", jobId)
    .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON)
    .body("type", equalTo(RestException.class.getSimpleName())).body("message", equalTo("Runtime exception"))
    .when().post(JOB_RESOURCE_EXECUTE_JOB_URL);
  }
Example 14
public void testFailingInstantiation() {
    String messageName = "aMessage";
    
    // thrown, if instantiation of the process or signalling the instance fails
    doThrow(new ProcessEngineException("Expected exception"))
      .when(runtimeServiceMock).correlateMessage(any(String.class), any(String.class), any(Map.class), any(Map.class));
    
    Map<String, Object> messageParameters = new HashMap<String, Object>();
    messageParameters.put("messageName", messageName);
    given().contentType(POST_JSON_CONTENT_TYPE).body(messageParameters)
      .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON)
      .body("type", equalTo(ProcessEngineException.class.getSimpleName()))
      .body("message", equalTo("Expected exception"))
      .when().post(MESSAGE_URL);
  }
Example 15
public void testMessagesTimersParameterAsPost() {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("messages", MockProvider.EXAMPLE_MESSAGES);
    parameters.put("timers", MockProvider.EXAMPLE_TIMERS);

    given().contentType(POST_JSON_CONTENT_TYPE).body(parameters)
    .then().expect().statusCode(Status.BAD_REQUEST.getStatusCode())
    .contentType(ContentType.JSON)
    .body("type",equalTo(InvalidRequestException.class.getSimpleName()))
    .body("message", equalTo("Parameter timers cannot be used together with parameter messages."))
    .when().post(JOBS_RESOURCE_URL);
  }
Example 16
public void testInvalidNumericParameter() {
    String anInvalidIntegerQueryParam = "aString";

    given()
      .queryParam("version", anInvalidIntegerQueryParam)
      .then()
        .expect()
          .statusCode(Status.BAD_REQUEST.getStatusCode())
          .contentType(ContentType.JSON)
          .body("type", equalTo(InvalidRequestException.class.getSimpleName()))
          .body("message", equalTo("Cannot set query parameter 'version' to value 'aString': "
            + "Cannot convert value aString to java type java.lang.Integer"))
      .when()
        .get(DECISION_DEFINITION_QUERY_URL);
  }
Example 17
public void testInvalidDueDateComparator() {

    String variableValue = "2013-05-05T00:00:00";
    String invalidComparator = "bt";

    String queryValue = invalidComparator + "_" + variableValue;
    given().queryParam("dueDates", queryValue)
        .then()
        .expect()
        .statusCode(Status.BAD_REQUEST.getStatusCode())
        .contentType(ContentType.JSON)
        .body("type",equalTo(InvalidRequestException.class.getSimpleName()))
        .body("message", equalTo("Invalid due date comparator specified: " + invalidComparator))
        .when().get(JOBS_RESOURCE_URL);
  }
Example 18
public void testGetBlacklist() throws Exception {
        final EventType eventType = NakadiTestUtils.createEventType();
        blacklist(eventType.getName(), BlacklistService.Type.CONSUMER_ET);
        TestUtils.waitFor(
                () -> given()
                        .contentType(ContentType.JSON)
                        .get(BLACKLIST_URL)
                        .then()
                        .statusCode(HttpStatus.SC_OK)
                        .body("consumers.event_types", hasItems(eventType.getName())),
                1000, 200);
    }
Example 19
public void testReadOnlyGroupCreateFails() {
    Group newGroup = MockProvider.createMockGroup();    
    when(identityServiceMock.isReadOnly()).thenReturn(true);
    
    given().body(GroupDto.fromGroup(newGroup)).contentType(ContentType.JSON)
      .then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).contentType(ContentType.JSON)
      .body("type", equalTo(InvalidRequestException.class.getSimpleName()))
      .body("message", equalTo("Identity service implementation is read-only."))
      .when().post(CREATE_GROUP_URL);
    
    verify(identityServiceMock, never()).newGroup(MockProvider.EXAMPLE_GROUP_ID);    
  }
Example 20
public void testPutSingleVariable() {
    String variableKey = "aVariableKey";
    String variableValue = "aVariableValue";

    Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue);

    given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey)
      .contentType(ContentType.JSON).body(variableJson)
      .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
      .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);

    verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey),
        argThat(EqualsUntypedValue.matcher().value(variableValue)));
  }
Example 21
protected void executeAndVerifyFailingSorting(String sortBy, String sortOrder, Status expectedStatus, String expectedErrorType, String expectedErrorMessage) {
    given().queryParam("sortBy", sortBy).queryParam("sortOrder", sortOrder)
      .then().expect().statusCode(expectedStatus.getStatusCode()).contentType(ContentType.JSON)
      .body("type", equalTo(expectedErrorType))
      .body("message", equalTo(expectedErrorMessage))
      .when().get(PROCESS_DEFINITION_QUERY_URL);
  }
Example 22
public void verifyUser () {
    when(processEngine.getIdentityService()
        .checkPassword(TEST_USERNAME, TEST_PASSWORD))
    .thenReturn(true);

    BasicUserCredentialsDto userCredentialsDto = new BasicUserCredentialsDto();
    userCredentialsDto.setUsername(TEST_USERNAME);
    userCredentialsDto.setUsername(TEST_PASSWORD);
    given()
        .body(userCredentialsDto).contentType(ContentType.JSON).
    expect().statusCode(Status.BAD_REQUEST.getStatusCode()).contentType(ContentType.JSON)
        .body("type", equalTo(InvalidRequestException.class.getSimpleName()))
        .body("message", equalTo("Username and password are required"))
        .when().post(VERIFY_USER_URL);
  }
Example 23
public void testMessageEventTriggeringWithoutVariables() {
    String messageName = "aMessageName";
    
    given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("messageName", messageName)
      .contentType(ContentType.JSON).body(EMPTY_JSON_OBJECT)
      .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
      .when().post(TRIGGER_MESSAGE_SUBSCRIPTION_URL);
  
    verify(runtimeServiceMock).messageEventReceived(eq(messageName), eq(MockProvider.EXAMPLE_EXECUTION_ID),
        argThat(new EqualsMap(null)));
  }
Example 24
public void testDeleteProcessInstanceThrowsAuthorizationException() {
    String message = "expected exception";
    doThrow(new AuthorizationException(message)).when(runtimeServiceMock).deleteProcessInstance(anyString(), anyString());

    given()
      .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)
    .then().expect()
      .statusCode(Status.FORBIDDEN.getStatusCode())
      .contentType(ContentType.JSON)
      .body("type", equalTo(AuthorizationException.class.getSimpleName()))
      .body("message", equalTo(message))
    .when()
      .delete(SINGLE_PROCESS_INSTANCE_URL);
  }
Example 25
public void testNonExistingProcessDefinitionRetrieval_ByKey() {
    String nonExistingKey = "aNonExistingDefinitionKey";

    when(repositoryServiceMock.createProcessDefinitionQuery().processDefinitionKey(nonExistingKey)).thenReturn(processDefinitionQueryMock);
    when(processDefinitionQueryMock.latestVersion()).thenReturn(processDefinitionQueryMock);
    when(processDefinitionQueryMock.singleResult()).thenReturn(null);

    given().pathParam("key", nonExistingKey)
    .then().expect()
      .statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON)
      .body("type", is(RestException.class.getSimpleName()))
      .body("message", containsString("No matching process definition with key: " + nonExistingKey))
    .when().get(SINGLE_PROCESS_DEFINITION_BY_KEY_URL);
  }