Search in sources :

Example 1 with PreviewParameters

use of org.talend.dataprep.transformation.preview.api.PreviewParameters in project data-prep by Talend.

the class DiffTest method should_return_preview.

@Test
public void should_return_preview() throws Exception {
    // given
    PreviewParameters input = new // 
    PreviewParameters(// 
    getSingleTransformation(), // 
    getMultipleTransformation(), // 
    createDataset("../preview/input.csv", "input4preview", "text/csv"), // 
    null, // 
    "[2,4,6]", HEAD);
    // when
    final String response = // 
    given().contentType(// 
    ContentType.JSON).body(// 
    mapper.writer().writeValueAsString(input)).when().expect().statusCode(200).log().ifError().post(// 
    "/transform/preview").asString();
    // then
    final String expected = IOUtils.toString(this.getClass().getResourceAsStream("../preview/expected_output.json"), UTF_8);
    assertEquals(expected, response, false);
}
Also used : PreviewParameters(org.talend.dataprep.transformation.preview.api.PreviewParameters) Test(org.junit.Test)

Example 2 with PreviewParameters

use of org.talend.dataprep.transformation.preview.api.PreviewParameters in project data-prep by Talend.

the class DiffTest method should_return_empty_array_when_step_does_not_create_columns.

@Test
public void should_return_empty_array_when_step_does_not_create_columns() throws Exception {
    // given
    final PreviewParameters previewParams = new // 
    PreviewParameters(// 
    getSingleTransformation(), // 
    getMultipleTransformationWithoutNewColumn(), // 
    createDataset("../preview/input.csv", "input4preview", "text/csv"), // 
    null, // 
    null, HEAD);
    final List<PreviewParameters> input = Collections.singletonList(previewParams);
    // when
    final String response = // 
    given().contentType(// 
    ContentType.JSON).body(// 
    mapper.writer().writeValueAsString(input)).when().expect().statusCode(200).log().ifError().post("/transform/diff/metadata").asString();
    // then
    assertEquals("[{\"createdColumns\":[]}]", response, false);
}
Also used : PreviewParameters(org.talend.dataprep.transformation.preview.api.PreviewParameters) Test(org.junit.Test)

Example 3 with PreviewParameters

use of org.talend.dataprep.transformation.preview.api.PreviewParameters in project data-prep by Talend.

the class DiffTest method test_TDP_1184.

/**
 * After TDP-1184 fix, there is a problem on preview (regression?).
 * Use case is:
 * - delete a column (lastname here)
 * - add new columns (with split on city here)
 * - preview an action on the first new column (uppercase on 0000 here)
 * <p>
 * -> lastname is still on the preview data for lines 4 & 6. it is absent (which is what we expect) only for the first line!
 */
@Test
public void test_TDP_1184() throws Exception {
    // given
    PreviewParameters input = new // 
    PreviewParameters(// 
    getTransformation_TDP_1184_step_1(), // 
    getTransformation_TDP_1184_step_2(), // 
    createDataset("../preview/input.csv", "tdp-1184", "text/csv"), // 
    null, // 
    "[1,4,6]", HEAD);
    // when
    final String response = // 
    given().contentType(// 
    ContentType.JSON).body(// 
    mapper.writer().writeValueAsString(input)).when().expect().statusCode(200).log().ifError().post(// 
    "/transform/preview").asString();
    // then
    final InputStream expected = this.getClass().getResourceAsStream("../preview/expected_output_TDP_1184.json");
    assertThat(response, sameJSONAsFile(expected));
}
Also used : PreviewParameters(org.talend.dataprep.transformation.preview.api.PreviewParameters) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with PreviewParameters

use of org.talend.dataprep.transformation.preview.api.PreviewParameters in project data-prep by Talend.

the class DiffTest method should_return_created_columns_for_multiple_diffs.

@Test
public void should_return_created_columns_for_multiple_diffs() throws Exception {
    // given
    final String datasetId = createDataset("../preview/input.csv", "input4preview", "text/csv");
    final PreviewParameters previewParams = new // 
    PreviewParameters(// 
    getSingleTransformation(), // 
    getMultipleTransformationWithNewColumn(), // 
    datasetId, // 
    null, // 
    null, HEAD);
    final PreviewParameters previewParamsBis = new // 
    PreviewParameters(// 
    getMultipleTransformationWithNewColumn(), // 
    getMultipleTransformationWithNewColumnBis(), // 
    datasetId, // 
    null, // 
    null, HEAD);
    final List<PreviewParameters> input = new ArrayList<>(2);
    input.add(previewParams);
    input.add(previewParamsBis);
    // when
    final String response = // 
    given().contentType(// 
    ContentType.JSON).body(// 
    mapper.writer().writeValueAsString(input)).when().expect().statusCode(200).log().ifError().post("/transform/diff/metadata").asString();
    // then
    assertEquals("[{\"createdColumns\":[\"0009\"]}, {\"createdColumns\":[\"0010\"]}]", response, false);
}
Also used : PreviewParameters(org.talend.dataprep.transformation.preview.api.PreviewParameters) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with PreviewParameters

use of org.talend.dataprep.transformation.preview.api.PreviewParameters in project data-prep by Talend.

the class DiffTest method should_return_created_columns.

@Test
public void should_return_created_columns() throws Exception {
    // given
    final PreviewParameters previewParams = new // 
    PreviewParameters(// 
    getSingleTransformation(), // 
    getMultipleTransformationWithNewColumn(), // 
    createDataset("../preview/input.csv", "input4preview", "text/csv"), // 
    null, // 
    null, HEAD);
    final List<PreviewParameters> input = Collections.singletonList(previewParams);
    // when
    final String response = // 
    given().contentType(// 
    ContentType.JSON).body(// 
    mapper.writer().writeValueAsString(input)).when().expect().statusCode(200).log().ifError().post("/transform/diff/metadata").asString();
    // then
    assertEquals("[{\"createdColumns\":[\"0009\"]}]", response, false);
}
Also used : PreviewParameters(org.talend.dataprep.transformation.preview.api.PreviewParameters) Test(org.junit.Test)

Aggregations

PreviewParameters (org.talend.dataprep.transformation.preview.api.PreviewParameters)6 Test (org.junit.Test)5 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 APPLICATION_JSON (org.apache.http.entity.ContentType.APPLICATION_JSON)1 StringEntity (org.apache.http.entity.StringEntity)1 SCOPE_PROTOTYPE (org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE)1 Scope (org.springframework.context.annotation.Scope)1 HttpStatus (org.springframework.http.HttpStatus)1 Component (org.springframework.stereotype.Component)1 ExceptionContext.withBuilder (org.talend.daikon.exception.ExceptionContext.withBuilder)1 HEAD (org.talend.dataprep.api.export.ExportParameters.SourceType.HEAD)1