Ejemplo n.º 1
0
  /**
   * Verify that if a constant value is assigned to a given field, and that field appears as an
   * entry mapped from a column, that the constant value will still take precedence.
   *
   * @expectedResults Assert that the new value is maintained.
   */
  @Test
  public void testConstValueOverridesColumnValue() throws Exception {

    Properties mappings = new Properties();
    final String sfdcField = "Name";
    final String csvFieldName =
        "abc"; // this is the column in the csv file to which the sfdc field will be bound

    final String constantValue = "NotAbc";
    final String wrappedConstantValue = "\"" + constantValue + "\"";

    LoadMapper mapper = new LoadMapper(null, null, null);

    // place a dao column -> sfdc field mapping
    // (src, dest).
    mapper.putMapping(csvFieldName, sfdcField);

    // place a constant mapping into the LoadMapper.
    mappings.setProperty(wrappedConstantValue, sfdcField);
    mapper.putPropertyFileMappings(mappings);

    Row input = Row.singleEntryImmutableRow(constantValue, sfdcField);

    Map<String, Object> result = mapper.mapData(input);

    // verify that the old value holds
    assertEquals(constantValue, result.get(sfdcField));
  }
Ejemplo n.º 2
0
 @Test
 public void testVerifyMappingsAreValidUnknownColumn() throws Exception {
   LoadMapper loadMapper = new LoadMapper(getController().getPartnerClient(), null, null);
   loadMapper.putMapping(SOURCE_NAMES[0], "non_existing_col_aa");
   try {
     loadMapper.verifyMappingsAreValid();
     Assert.fail("An exception should have been thrown since destination column does not exist");
   } catch (MappingInitializationException ignored) {
     // expected
   }
 }
Ejemplo n.º 3
0
  @Test
  public void testMapDataEmptyEntriesIgnored() throws Exception {
    LoadMapper loadMapper = new LoadMapper(null, null, null);
    loadMapper.putMapping("SOURCE_COL", "");

    Row inputData = Row.singleEntryImmutableRow("SOURCE_COL", "123");

    Map<String, Object> result = loadMapper.mapData(inputData);

    assertTrue("Empty destination column should have not been mapped", result.isEmpty());
  }
Ejemplo n.º 4
0
  /**
   * Verify that the map can be populated from a properties file.
   *
   * @expectedResults Assert that the source values (value) are mapped to the correct destination
   *     names (key). Also verify that the constant (key) is mapped correctly to the
   *     destinationConstant (value).
   * @throws MappingInitializationException
   */
  @Test
  public void testMapProperties() throws MappingInitializationException {
    // prepopulate properties map
    Properties mappings = new Properties();
    for (int i = 0; i < SOURCE_NAMES.length; i++) {
      mappings.setProperty(SOURCE_NAMES[i], DEST_NAMES[i]);
    }
    mappings.setProperty("\"" + CONSTANT_VALUE + "\"", DEST_CONSTANT_NAME);

    LoadMapper mapper = new LoadMapper(null, Arrays.asList(SOURCE_NAMES), null);
    mapper.putPropertyFileMappings(mappings);
    verifyMapping(mapper, DEST_NAMES);
  }
Ejemplo n.º 5
0
  /**
   * Verify that multiple fields can have the same value for a constant when listed as a
   * comma-separated list. It also tests that white space does not affect the interpretation of
   * these fields.
   *
   * @expectedResults Assert that the mappings from various keys (fields) can have the same value.
   * @throws MappingInitializationException
   */
  @Test
  public void testDuplicateConstants() throws MappingInitializationException {
    Properties mappings = new Properties();

    String constantValue = "5";
    String wrappedConstantValue = "\"" + constantValue + "\"";

    final String value = wrappedConstantValue;
    mappings.setProperty(value, "Name, field1__c,field2__c,   field3__c,\n\tfield4__c");
    mappings.setProperty("", "Value6");
    LoadMapper mapper = new LoadMapper(null, null, null);
    mapper.putPropertyFileMappings(mappings);
    Row result = mapper.mapData(Row.emptyRow());
    assertEquals(constantValue, result.get("Name"));
    assertEquals(constantValue, result.get("field1__c"));
    assertEquals(constantValue, result.get("field2__c"));
    assertEquals(constantValue, result.get("field3__c"));
    assertEquals(constantValue, result.get("field4__c"));
  }
Ejemplo n.º 6
0
 /**
  * Helper method to verify that the LoadMapper has mapped the specified columns to their correct
  * respective field, along with any constants in the mapping file.
  */
 private void verifyMapping(LoadMapper mapper, String... destNames) {
   Row destValueMap = mapper.mapData(this.sourceRow);
   for (int i = 0; i < destNames.length; i++) {
     assertNotNull(
         "Destination# " + i + "(" + destNames[i] + ") should have a mapped value",
         destValueMap.get(destNames[i]));
     assertEquals(
         "Destination# " + i + "(" + destNames[i] + ") should contain the expected value",
         SOURCE_VALUES[i],
         destValueMap.get(destNames[i]));
   }
   // verify constant mapped correctly
   assertEquals(
       "Destination[" + DEST_CONSTANT_NAME + "] should contain constant",
       CONSTANT_VALUE,
       destValueMap.get(DEST_CONSTANT_NAME));
 }
Ejemplo n.º 7
0
 @Test
 public void testVerifyMappingsAreValidEmptyEntries() throws Exception {
   LoadMapper loadMapper = new LoadMapper(null, null, null);
   loadMapper.putMapping("SOURCE_COL", "");
   loadMapper.verifyMappingsAreValid(); // no exception expected
 }