Example #1
0
  @Test
  public void should_substring_the_new_substring() throws IOException {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);

    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0003", " ipsum ");
    expectedValues.put("0004", "ips");
    expectedValues.put("0002", "01/01/2015");

    ActionTestWorkbench.test(row, action.create(parameters).getRowAction());

    // when
    parameters.put("column_id", "0003");
    parameters.put(FROM_INDEX_PARAMETER, "1");
    parameters.put(TO_INDEX_PARAMETER, "4");
    parameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), "0003");
    ActionTestWorkbench.test(row, action.create(parameters).getRowAction());

    // then
    assertEquals(expectedValues, row.values());
  }
Example #2
0
  @Test
  public void should_fill_empty_string_other_column_not_date() throws Exception {
    // given
    final DataSetRow row =
        builder() //
            .with(value("David Bowie").type(Type.STRING)) //
            .with(
                value("")
                    .type(Type.DATE)
                    .statistics(
                        ChangeDatePatternTest.class.getResourceAsStream(
                            "statistics_yyyy-MM-dd.json"))) //
            .with(value("tagada").type(Type.DATE)) //
            .build();
    Map<String, String> parameters =
        ActionMetadataTestUtils.parseParameters( //
            this.getClass().getResourceAsStream("fillEmptyIntegerAction.json"));

    // when
    parameters.put(FillIfEmpty.MODE_PARAMETER, FillIfEmpty.OTHER_COLUMN_MODE);
    parameters.put(FillIfEmpty.SELECTED_COLUMN_PARAMETER, "0002");
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));

    // then
    assertEquals("tagada", row.get("0002"));
    assertEquals("tagada", row.get("0001"));
    assertEquals("David Bowie", row.get("0000"));
  }
Example #3
0
  @Test
  public void test_TDP_591() throws Exception {
    // given
    final DataSetRow row =
        builder() //
            .with(value("David Bowie").type(Type.STRING)) //
            .with(
                value("")
                    .type(Type.DATE)
                    .statistics(
                        ChangeDatePatternTest.class.getResourceAsStream(
                            "statistics_yyyy-MM-dd.json"))) //
            .with(value("100").type(Type.STRING)) //
            .build();
    Map<String, String> parameters =
        ActionMetadataTestUtils.parseParameters(
            this.getClass().getResourceAsStream("fillEmptyDateAction.json"));

    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));

    // then
    assertEquals("1970-01-01", row.get("0001"));
    assertEquals("David Bowie", row.get("0000"));
  }
Example #4
0
  @Test
  public void should_substring_n_before_end_4() throws IOException {
    // given
    parameters.put(FROM_MODE_PARAMETER, Substring.FROM_N_BEFORE_END_PARAMETER);
    parameters.put(FROM_N_BEFORE_END_PARAMETER, "5");
    parameters.put(TO_MODE_PARAMETER, Substring.TO_N_BEFORE_END_PARAMETER);
    parameters.put(TO_N_BEFORE_END_PARAMETER, "1");

    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon ipsum");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);

    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ipsum");
    expectedValues.put("0003", "ipsu");
    expectedValues.put("0002", "01/01/2015");

    // when
    ActionTestWorkbench.test(row, action.create(parameters).getRowAction());

    // then
    assertEquals(expectedValues, row.values());
  }
Example #5
0
  @Test
  public void should_substring_resulting_to_empty_on_strange_bounds_start_index_sup_to_end_index()
      throws IOException {
    // given
    parameters.put(FROM_INDEX_PARAMETER, "6");
    parameters.put(TO_INDEX_PARAMETER, "1");

    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);

    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0003", "");
    expectedValues.put("0002", "01/01/2015");

    // when
    ActionTestWorkbench.test(row, action.create(parameters).getRowAction());

    // then
    assertEquals(expectedValues, row.values());
  }
Example #6
0
  @Test
  public void should_not_change_other_columns() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0001", "the beatles");
    final DataSetRow row = new DataSetRow(values);

    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));

    // then
    assertEquals("the beatles", row.get("0001"));
  }
Example #7
0
  @Test
  public void should_transform_upper_to_proper() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "THE BEATLES");
    final DataSetRow row = new DataSetRow(values);

    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));

    // then
    assertEquals("The Beatles", row.get("0000"));
  }
Example #8
0
  @Test
  public void should_not_fill_empty_date() throws Exception {
    // given
    final DataSetRow row =
        builder() //
            .with(value("David Bowie").type(Type.STRING)) //
            .with(value("not empty").type(Type.DATE)) //
            .with(value("100").type(Type.STRING)) //
            .build();
    Map<String, String> parameters =
        ActionMetadataTestUtils.parseParameters( //
            this.getClass().getResourceAsStream("fillEmptyDateAction.json"));

    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));

    // then
    assertEquals("1/1/1970 10:00:00", row.get("0001"));
    assertEquals("David Bowie", row.get("0000"));
  }
Example #9
0
  @Test
  public void should_substring_to_the_end_when_end_index_is_too_big_and_out_of_bound() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon ip");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);

    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ip");
    expectedValues.put("0003", " ip");
    expectedValues.put("0002", "01/01/2015");

    // when
    ActionTestWorkbench.test(row, action.create(parameters).getRowAction());

    // then
    assertEquals(expectedValues, row.values());
  }
Example #10
0
  @Test
  public void should_substring() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);

    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0003", " ipsum ");
    expectedValues.put("0002", "01/01/2015");

    // when
    ActionTestWorkbench.test(row, action.create(parameters).getRowAction());

    // then
    assertEquals(expectedValues, row.values());
  }
Example #11
0
  @Test
  public void should_update_metadata() {
    // given
    final List<ColumnMetadata> input = new ArrayList<>();
    input.add(createMetadata("0000", "recipe"));
    input.add(createMetadata("0001", "steps"));
    input.add(createMetadata("0002", "last update"));
    final RowMetadata rowMetadata = new RowMetadata(input);

    final List<ColumnMetadata> expected = new ArrayList<>();
    expected.add(createMetadata("0000", "recipe"));
    expected.add(createMetadata("0001", "steps"));
    expected.add(createMetadata("0003", "steps_substring"));
    expected.add(createMetadata("0002", "last update"));

    // when
    ActionTestWorkbench.test(rowMetadata, action.create(parameters).getRowAction());

    // then
    assertEquals(expected, rowMetadata.getColumns());
  }
Example #12
0
  @Test
  public void should_substring_to_the_beginning_when_end_index_is_negative() {
    // given
    parameters.put(TO_INDEX_PARAMETER, "-1");

    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bac");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);

    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bac");
    expectedValues.put("0003", "");
    expectedValues.put("0002", "01/01/2015");

    // when
    ActionTestWorkbench.test(row, action.create(parameters).getRowAction());

    // then
    assertEquals(expectedValues, row.values());
  }