public static Response sendHttpGet(String contentType, String httpGetCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .log().all() .expect() .log().all() .when() .get(httpGetCommand); } return given() .contentType(contentType) .log().all() .when() .get(httpGetCommand); }
@Test public void getJdbcProperties() throws java.io.IOException { // when Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect().statusCode(200).log().ifError() // .get(getVersionPrefix() + "/properties/{definitionName}", DATA_STORE_DEFINITION_NAME); // then ObjectNode jdbcProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream()); // should resemble jdbc_data_store_form.json assertNotNull(jdbcProperties.get("jsonSchema")); assertNotNull(jdbcProperties.get("properties")); assertNotNull(jdbcProperties.get("uiSchema")); assertEquals("JDBCDatastore", jdbcProperties.get("properties").get("@definitionName").textValue()); }
protected final ResponseSpecification buildRequest(AbstractRestRequest request, boolean withBody) { RequestSpecification builder = authenticatedRequest(request); if (withBody && request.hasBody()) { builder.body(request.getBody()); } if (request.hasQueryParams()) { for (Map.Entry<String, Collection<?>> param : request.getQueryParams().entrySet()) { builder.queryParam(param.getKey(), param.getValue()); } } return builder.expect() .spec(request.getSpecification()) .log().ifValidationFails(); }
private String getDataStoreDefinitionPropertiesTitle(Locale locale) throws IOException { Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with().port(localServerPort) // .param(LANGUAGE_QUERY_PARAMETER_NAME, locale.toLanguageTag()) .get(getVersionPrefix() + "/properties/{name}", DATA_STORE_DEFINITION_NAME); JsonNode jsonNode = mapper.readTree(response.asInputStream()); return jsonNode.get("jsonSchema").get("title").asText(); }
public static Response sendHttpGet(String contentType, String httpGetCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .log().all() .expect() .log().all() .when() .get(httpGetCommand); } return given() .contentType(contentType) .log().all() .when() .get(httpGetCommand); }
@Test public void testGetConnectors_badDefinition() throws Exception { given().expect() // .statusCode(400) // .log().ifValidationFails() // // TODO: check returned error .body(Matchers.containsString("definitionClass")) // .get(getVersionPrefix() + "/properties/{name}/connectors", DATA_SET_DEFINITION_NAME); }
@Test public void setDatasetData_DiRuntime() throws Exception { // given String payload = IOUtils.toString(getClass().getResourceAsStream("jdbc_component_write_properties_on_DI.json")) .replace("{jdbc_url}", dbUrl); // when given().content(payload).contentType(APPLICATION_JSON_UTF8_VALUE) // .expect().statusCode(200).log().ifError() // .put(getVersionPrefix() + "/runtimes/data"); // then Statement statement = db.getConnection().createStatement(); ResultSet countRS = statement.executeQuery("SELECT COUNT(*) AS count FROM users"); countRS.next(); assertEquals(101, countRS.getInt("count")); ResultSet resultSet = statement.executeQuery("SELECT * FROM users WHERE email='david.bowie@awesome.uk'"); while (resultSet.next()) { assertEquals("1", resultSet.getString("id")); assertEquals("David", resultSet.getString("first_name")); assertEquals("Bowie", resultSet.getString("last_name")); assertEquals("david.bowie@awesome.uk", resultSet.getString("email")); assertEquals("male", resultSet.getString("gender")); assertEquals("127.0.0.1", resultSet.getString("ip_address")); } }
public static Response sendHttpPost(String contentType, String payload, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .body(payload) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .body(payload) // .log().all() .when() .post(httpPostCommand); }
@Test @Ignore("manual test cause the Aspect need to have this class in it's cutpoint") public void testException() { // checks that the RuntimeException is converted to a TalendRuntimeException by the aspect given() // .expect() // .statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).log().ifValidationFails() // .when()// .get("/tests/exception")// .then()// .body("code", containsString(CommonErrorCodes.UNEXPECTED_EXCEPTION.toString())) .body("message", equalTo("global_error_test")); }
@Test public void testGetVersion() throws Exception { Response r = given().accept(APPLICATION_JSON_UTF8_VALUE) // .expect() // .statusCode(200).log().ifError() // .with().port(localServerPort) // .get(getVersionPrefix() + "/version"); r.then() // .statusCode(HttpStatus.OK.value()).log().ifError() // .contentType(APPLICATION_JSON_UTF8_VALUE); // We don't care what values are returned as long as they are filled. JsonPath jsonPathEvaluator = r.jsonPath(); assertThat(jsonPathEvaluator.get("version"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); assertThat(jsonPathEvaluator.get("commit"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); assertThat(jsonPathEvaluator.get("time"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); } }
public static Response sendHttpPost(String contentType, Map<String, ?> parameters, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .formParameters(parameters) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .formParameters(parameters) // .log().all() .when() .post(httpPostCommand); }
@Test public void testGetIcon_imageTypeNotFound() throws Exception { given().expect() // .statusCode(404) // .log().ifValidationFails() // .get(getVersionPrefix() + "/properties/{name}/icon/{type}", DATA_STORE_DEFINITION_NAME, DefinitionImageType.SVG_ICON); }
protected static void assertCreateUser(User user){ given() .contentType("application/json;charset=UTF-8") .accept("application/json") .body(user) .expect().log().ifError() .statusCode(HttpStatus.SC_CREATED) .when() .post(getHost() + CONTEXT_PATH + "/users"); }
public static Response sendHttpPost(String contentType, Map<String, ?> parameters, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .formParameters(parameters) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .formParameters(parameters) // .log().all() .when() .post(httpPostCommand); }
@Test public void testGetSchema_wrongSql() throws java.io.IOException { // given UiSpecsPropertiesDto datasetConnectionInfo = new UiSpecsPropertiesDto(); datasetConnectionInfo.setProperties(mapper.readValue( getClass().getResourceAsStream("jdbc_data_set_properties_no_schema_wrong_table_name.json"), ObjectNode.class)); datasetConnectionInfo.setDependencies(singletonList(getJdbcDataStoreProperties())); String dataSetDefinitionName = "JDBCDataset"; // when ApiError response = given().content(datasetConnectionInfo).contentType(APPLICATION_JSON_UTF8_VALUE) // .accept(APPLICATION_JSON_UTF8_VALUE) // .expect().statusCode(400).log().ifValidationFails() // .post(getVersionPrefix() + "/runtimes/schema").as(ApiError.class); // then assertEquals("TCOMP_JDBC_SQL_SYNTAX_ERROR", response.getCode()); assertEquals("Table/View 'TOTO' does not exist.", response.getMessage()); }
protected static UserDTO assertUserExists(String path){ Response response = given() .expect().log().ifError() .statusCode(HttpStatus.SC_OK) .when() .get(getHost() + CONTEXT_PATH + path + JSON_SUFFIX); return deserialize(response.getBody().asString()); } }
public static Response sendHttpPost(String contentType, String payload, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .body(payload) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .body(payload) // .log().all() .when() .post(httpPostCommand); }
@Test public void testTriggerOnProperty_nonExistentTrigger() throws Exception { String callback = "toto"; String propName = "tagId"; ApiError errorContainer = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(400).log().ifValidationFails() // .with() // .content(buildTestDataStoreFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/trigger/{callback}/{propName}", callback, propName).as(ApiError.class); assertEquals("Talend_ALL_UNEXPECTED_ARGUMENT", errorContainer.getCode()); assertNotNull(errorContainer.getMessageTitle()); assertNotNull(errorContainer.getMessage()); }
@Test public void initializeJDBCDatastoreProperties() throws java.io.IOException { // given SerPropertiesDto propDto = new SerPropertiesDto(); propDto.setProperties(new JDBCDatastoreProperties("").init().toSerialized()); // when Response response = given().content(propDto).contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect().statusCode(200).log().ifError() // .post(getVersionPrefix() + "/properties/uispec"); // then ObjectNode jdbcProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream()); // should resemble jdbc_data_store_form.json assertNotNull(jdbcProperties.get("jsonSchema")); assertNotNull(jdbcProperties.get("properties")); assertNotNull(jdbcProperties.get("uiSchema")); assertEquals("JDBCDatastore", jdbcProperties.get("properties").get("@definitionName").textValue()); }
@Test public void test404() { given() .expect().statusCode(404) .then().log().all() .when().get("invalid"); }