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(); }
@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 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 testGetIcon_imageTypeNotFound() throws Exception { given().expect() // .statusCode(404) // .log().ifValidationFails() // .get(getVersionPrefix() + "/properties/{name}/icon/{type}", DATA_STORE_DEFINITION_NAME, DefinitionImageType.SVG_ICON); }
@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()); }
@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()); }