Exemplo n.º 1
0
  @Test
  public void testQuoteReservedWords() {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    doCallRealMethod().when(databaseMeta).quoteReservedWords(any(RowMetaInterface.class));
    doCallRealMethod().when(databaseMeta).quoteField(anyString());
    doCallRealMethod().when(databaseMeta).setDatabaseInterface(any(DatabaseInterface.class));
    doReturn("\"").when(databaseMeta).getStartQuote();
    doReturn("\"").when(databaseMeta).getEndQuote();
    final DatabaseInterface databaseInterface = mock(DatabaseInterface.class);
    doReturn(true).when(databaseInterface).isQuoteAllFields();
    databaseMeta.setDatabaseInterface(databaseInterface);

    final RowMeta fields = new RowMeta();
    for (int i = 0; i < 10; i++) {
      final ValueMeta valueMeta = new ValueMeta("test_" + i);
      fields.addValueMeta(valueMeta);
    }

    for (int i = 0; i < 10; i++) {
      databaseMeta.quoteReservedWords(fields);
    }

    for (int i = 0; i < 10; i++) {
      databaseMeta.quoteReservedWords(fields);
      final String name = fields.getValueMeta(i).getName();
      // check valueMeta index in list
      assertTrue(name.contains("test_" + i));
      // check valueMeta is found by quoted name
      assertNotNull(fields.searchValueMeta(name));
    }
  }
Exemplo n.º 2
0
  @Test
  public void testModifyingName() throws Exception {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    OracleDatabaseMeta odbm = new OracleDatabaseMeta();
    doCallRealMethod().when(databaseMeta).setDatabaseInterface(any(DatabaseInterface.class));
    doCallRealMethod().when(databaseMeta).setName(anyString());
    doCallRealMethod().when(databaseMeta).getName();
    doCallRealMethod().when(databaseMeta).getDisplayName();
    databaseMeta.setDatabaseInterface(odbm);
    databaseMeta.setName("test");

    List<DatabaseMeta> list = new ArrayList<DatabaseMeta>();
    list.add(databaseMeta);

    DatabaseMeta databaseMeta2 = mock(DatabaseMeta.class);
    OracleDatabaseMeta odbm2 = new OracleDatabaseMeta();
    doCallRealMethod().when(databaseMeta2).setDatabaseInterface(any(DatabaseInterface.class));
    doCallRealMethod().when(databaseMeta2).setName(anyString());
    doCallRealMethod().when(databaseMeta2).getName();
    doCallRealMethod().when(databaseMeta2).setDisplayName(anyString());
    doCallRealMethod().when(databaseMeta2).getDisplayName();
    doCallRealMethod()
        .when(databaseMeta2)
        .verifyAndModifyDatabaseName(any(ArrayList.class), anyString());
    databaseMeta2.setDatabaseInterface(odbm2);
    databaseMeta2.setName("test");

    databaseMeta2.verifyAndModifyDatabaseName(list, null);

    assertTrue(!databaseMeta.getDisplayName().equals(databaseMeta2.getDisplayName()));
  }
Exemplo n.º 3
0
 @Test
 public void testGetFeatureSummary() throws Exception {
   DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
   OracleDatabaseMeta odbm = new OracleDatabaseMeta();
   doCallRealMethod().when(databaseMeta).setDatabaseInterface(any(DatabaseInterface.class));
   doCallRealMethod().when(databaseMeta).getFeatureSummary();
   doCallRealMethod().when(databaseMeta).getAttributes();
   databaseMeta.setDatabaseInterface(odbm);
   List<RowMetaAndData> result = databaseMeta.getFeatureSummary();
   assertNotNull(result);
   for (RowMetaAndData rmd : result) {
     assertEquals(2, rmd.getRowMeta().size());
     assertEquals("Parameter", rmd.getRowMeta().getValueMeta(0).getName());
     assertEquals(ValueMetaInterface.TYPE_STRING, rmd.getRowMeta().getValueMeta(0).getType());
     assertEquals("Value", rmd.getRowMeta().getValueMeta(1).getName());
     assertEquals(ValueMetaInterface.TYPE_STRING, rmd.getRowMeta().getValueMeta(1).getType());
   }
 }
Exemplo n.º 4
0
  @Test
  public void testApplyingDefaultOptions() throws Exception {
    HashMap<String, String> existingOptions = new HashMap<String, String>();
    existingOptions.put("type1.extra", "extraValue");
    existingOptions.put("type1.existing", "existingValue");
    existingOptions.put("type2.extra", "extraValue2");

    HashMap<String, String> newOptions = new HashMap<String, String>();
    newOptions.put("type1.new", "newValue");
    newOptions.put("type1.existing", "existingDefault");

    // Register Natives to create a default DatabaseMeta
    DatabasePluginType.getInstance().searchPlugins();
    DatabaseMeta meta = new DatabaseMeta();
    DatabaseInterface type = mock(DatabaseInterface.class);
    meta.setDatabaseInterface(type);

    when(type.getExtraOptions()).thenReturn(existingOptions);
    when(type.getDefaultOptions()).thenReturn(newOptions);

    meta.applyDefaultOptions(type);
    verify(type).addExtraOption("type1", "new", "newValue");
    verify(type, never()).addExtraOption("type1", "existing", "existingDefault");
  }
Exemplo n.º 5
0
 @Test
 public void testDatabaseAccessTypeCode() throws Exception {
   String expectedJndi = "JNDI";
   String access = DatabaseMeta.getAccessTypeDesc(DatabaseMeta.getAccessType(expectedJndi));
   assertEquals(expectedJndi, access);
 }