Пример #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());
  }
Пример #2
0
 @Test
 public void should_not_accept_column() {
   assertFalse(action.acceptColumn(getColumn(Type.NUMERIC)));
   assertFalse(action.acceptColumn(getColumn(Type.FLOAT)));
   assertFalse(action.acceptColumn(getColumn(Type.DATE)));
   assertFalse(action.acceptColumn(getColumn(Type.BOOLEAN)));
 }
Пример #3
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());
  }
Пример #4
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());
  }
Пример #5
0
  @Test
  public void should_update_metadata_twice() {
    // 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 DataSetRow row = new DataSetRow(rowMetadata);

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

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

    // then
    assertEquals(expected, row.getRowMetadata().getColumns());
  }
Пример #6
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());
  }
Пример #7
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());
  }
Пример #8
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());
  }
Пример #9
0
 @Test
 public void testCategory() throws Exception {
   assertThat(action.getCategory(), is(ActionCategory.STRINGS.getDisplayName()));
 }
Пример #10
0
 @Test
 public void testAdapt() throws Exception {
   assertThat(action.adapt((ColumnMetadata) null), is(action));
   ColumnMetadata column = column().name("myColumn").id(0).type(Type.STRING).build();
   assertThat(action.adapt(column), is(action));
 }
Пример #11
0
 @Test
 public void should_accept_column() {
   assertTrue(action.acceptColumn(getColumn(Type.STRING)));
 }