Search in sources :

Example 1 with DataNode

use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-kettle by pentaho.

the class DatabaseDelegateTest method testExtraOptionEscapeWithInvalidCharInDatabaseType.

@Test
public void testExtraOptionEscapeWithInvalidCharInDatabaseType() throws KettleException {
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    when(dbMeta.getPluginId()).thenReturn("pluginId");
    when(dbMeta.getAccessTypeDesc()).thenReturn("Native");
    when(dbMeta.getHostname()).thenReturn("AS/400Host");
    when(dbMeta.getDatabaseName()).thenReturn("mainframeTable");
    when(dbMeta.getDatabasePortNumberString()).thenReturn("1234");
    when(dbMeta.getUsername()).thenReturn("testUser");
    when(dbMeta.getPassword()).thenReturn("123");
    when(dbMeta.getServername()).thenReturn("as400.dot.com");
    when(dbMeta.getDataTablespace()).thenReturn("tableSpace");
    when(dbMeta.getIndexTablespace()).thenReturn("123");
    // Create an extra options that has an unsupported character like '/'
    Properties extraOptions = new Properties();
    extraOptions.setProperty("EXTRA_OPTION_AS/400.optionExtraOption", "true");
    when(dbMeta.getAttributes()).thenReturn(extraOptions);
    IUnifiedRepository purRepo = mock(IUnifiedRepository.class);
    when(purRepo.getReservedChars()).thenReturn(Arrays.asList(new Character[] { '/' }));
    when(mockPurRepository.getUnderlyingRepository()).thenReturn(purRepo);
    DataNode escapedAttributes = dbDelegate.elementToDataNode(dbMeta);
    // Should only be one option in list
    for (Iterator<DataNode> iter = escapedAttributes.getNodes().iterator(); iter.hasNext(); ) {
        DataNode options = iter.next();
        assertTrue("Invalid escaped extra options", options.hasProperty("EXTRA_OPTION_AS%2F400.optionExtraOption"));
        assertFalse("Should not contain un-escaped option", options.hasProperty("EXTRA_OPTION_AS/400.optionExtraOption"));
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Properties(java.util.Properties) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 2 with DataNode

use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-kettle by pentaho.

the class DelegatesPrivateDatabasesTest method savesNode_IfSetIsEmpty.

@Test
public void savesNode_IfSetIsEmpty() throws Exception {
    meta.setPrivateDatabases(Collections.<String>emptySet());
    DataNode dataNode = element2node();
    DataNode dbsNode = dataNode.getNode(privateDbsNodeName);
    assertNotNull("Even if the set is empty, the node should be saved as an indicator", dbsNode);
    DataNode databaseNode = Iterables.getFirst(dbsNode.getNodes(), null);
    assertNull(databaseNode);
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Test(org.junit.Test)

Example 3 with DataNode

use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-kettle by pentaho.

the class DelegatesPrivateDatabasesTest method doesNotSaveNode_IfSetIsNull.

@Test
public void doesNotSaveNode_IfSetIsNull() throws Exception {
    meta.setPrivateDatabases(null);
    DataNode dataNode = element2node();
    DataNode dbsNode = dataNode.getNode(privateDbsNodeName);
    assertNull(dbsNode);
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Test(org.junit.Test)

Example 4 with DataNode

use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-kettle by pentaho.

the class DelegatesPrivateDatabasesTest method element2node.

private DataNode element2node() throws KettleException {
    DataNode dataNode = delegate.elementToDataNode(meta);
    assertNotNull(dataNode);
    return dataNode;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode)

Example 5 with DataNode

use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-kettle by pentaho.

the class JobDelegateTest method testElementToDataNodeSavesCopyAttributes.

@Test
public void testElementToDataNodeSavesCopyAttributes() throws KettleException {
    JobMeta mockJobMeta = mock(JobMeta.class);
    IUnifiedRepository mockUnifiedRepository = mock(IUnifiedRepository.class);
    JobDelegate jobDelegate = new JobDelegate(mockPurRepository, mockUnifiedRepository);
    JobLogTable mockJobLogTable = mock(JobLogTable.class);
    JobEntryCopy mockJobEntryCopy = mock(JobEntryCopy.class);
    Map<String, Map<String, String>> attributes = new HashMap<String, Map<String, String>>();
    Map<String, String> group = new HashMap<String, String>();
    final String mockGroup = "MOCK_GROUP";
    final String mockProperty = "MOCK_PROPERTY";
    final String mockValue = "MOCK_VALUE";
    group.put(mockProperty, mockValue);
    attributes.put(mockGroup, group);
    when(mockJobEntryCopy.getAttributesMap()).thenReturn(attributes);
    JobEntryBaseAndInterface mockJobEntry = mock(JobEntryBaseAndInterface.class);
    when(mockJobMeta.listParameters()).thenReturn(new String[] {});
    when(mockJobMeta.getJobLogTable()).thenReturn(mockJobLogTable);
    when(mockJobMeta.nrJobEntries()).thenReturn(1);
    when(mockJobMeta.getJobEntry(0)).thenReturn(mockJobEntryCopy);
    when(mockJobEntryCopy.getName()).thenReturn("MOCK_NAME");
    when(mockJobEntryCopy.getLocation()).thenReturn(new Point(0, 0));
    when(mockJobEntryCopy.getEntry()).thenReturn(mockJobEntry);
    DataNode dataNode = jobDelegate.elementToDataNode(mockJobMeta);
    DataNode groups = dataNode.getNode("entries").getNodes().iterator().next().getNode(AttributesMapUtil.NODE_ATTRIBUTE_GROUPS);
    DataNode mockGroupNode = groups.getNode(mockGroup);
    assertEquals(mockValue, mockGroupNode.getProperty(mockProperty).getString());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobLogTable(org.pentaho.di.core.logging.JobLogTable) HashMap(java.util.HashMap) Point(org.pentaho.di.core.gui.Point) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) HashMap(java.util.HashMap) Map(java.util.Map) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Aggregations

DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)63 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)22 Test (org.junit.Test)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)17 DataProperty (org.pentaho.platform.api.repository2.unified.data.node.DataProperty)15 DataNodeRef (org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef)11 Matchers.anyString (org.mockito.Matchers.anyString)7 Date (java.util.Date)6 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)6 ArrayList (java.util.ArrayList)5 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 ITenant (org.pentaho.platform.api.mt.ITenant)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 NotePadMeta (org.pentaho.di.core.NotePadMeta)4 KettleException (org.pentaho.di.core.exception.KettleException)4 JobMeta (org.pentaho.di.job.JobMeta)4 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)4 StringObjectId (org.pentaho.di.repository.StringObjectId)4 Properties (java.util.Properties)3