Search in sources :

Example 1 with ISubTransAwareMeta

use of org.pentaho.di.trans.ISubTransAwareMeta in project pentaho-metaverse by pentaho.

the class KettleAnalyzerUtilTest method testGetSubTransMetaPath.

@Test
public void testGetSubTransMetaPath() throws MetaverseAnalyzerException {
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, null));
    final ISubTransAwareMeta meta = Mockito.mock(ISubTransAwareMeta.class);
    final TransMeta subTransMeta = Mockito.mock(TransMeta.class);
    final StepMeta parentStepMeta = Mockito.mock(StepMeta.class);
    final TransMeta parentTransMeta = Mockito.mock(TransMeta.class);
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, null));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta));
    Mockito.doReturn(ObjectLocationSpecificationMethod.FILENAME).when(meta).getSpecificationMethod();
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, null));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta));
    Mockito.doReturn(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME).when(meta).getSpecificationMethod();
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, null));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta));
    Mockito.doReturn(ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE).when(meta).getSpecificationMethod();
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, null));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta));
    Mockito.doReturn(ObjectLocationSpecificationMethod.FILENAME).when(meta).getSpecificationMethod();
    Mockito.doReturn(parentStepMeta).when(meta).getParentStepMeta();
    Mockito.doReturn("foo").when(meta).getFileName();
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, null).endsWith(File.separator + "foo"));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "foo"));
    Mockito.doReturn(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME).when(meta).getSpecificationMethod();
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, null).endsWith(File.separator + "foo"));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "foo"));
    Mockito.doReturn("dir/foe").when(subTransMeta).getPathAndName();
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, null).endsWith(File.separator + "foo"));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "dir" + File.separator + "foe"));
    Mockito.doReturn("ktr").when(subTransMeta).getDefaultExtension();
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, null).endsWith(File.separator + "foo"));
    assertNull(KettleAnalyzerUtil.getSubTransMetaPath(null, subTransMeta));
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "dir" + File.separator + "foe.ktr"));
    Mockito.doReturn("${rootDir}/dir/foe").when(subTransMeta).getPathAndName();
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "${rootDir}" + File.separator + "dir" + File.separator + "foe.ktr"));
    // mimic variable replacement where the variable is missing, should be removed from results
    Mockito.doReturn(parentTransMeta).when(parentStepMeta).getParentTransMeta();
    Mockito.doReturn("/dir/foe.ktr").when(parentTransMeta).environmentSubstitute(Mockito.anyString());
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "dir" + File.separator + "foe.ktr"));
    assertFalse(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "${rootDir}" + File.separator + "dir" + File.separator + "foe.ktr"));
    // mimic variable replacement where the variable present
    Mockito.doReturn("myRootDir/dir/foe.ktr").when(parentTransMeta).environmentSubstitute(Mockito.anyString());
    assertTrue(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta).endsWith(File.separator + "myRootDir" + File.separator + "dir" + File.separator + "foe.ktr"));
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) ISubTransAwareMeta(org.pentaho.di.trans.ISubTransAwareMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ISubTransAwareMeta

use of org.pentaho.di.trans.ISubTransAwareMeta in project pentaho-metaverse by pentaho.

the class KettleAnalyzerUtilTest method testGetSubTransMeta.

@Test
public void testGetSubTransMeta() throws MetaverseAnalyzerException, KettleException {
    final ISubTransAwareMeta meta = Mockito.mock(ISubTransAwareMeta.class);
    final TransMeta subTransMeta = Mockito.mock(TransMeta.class);
    final StepMeta parentStepMeta = Mockito.mock(StepMeta.class);
    final TransMeta parentTransMeta = Mockito.mock(TransMeta.class);
    final Repository repo = Mockito.mock(Repository.class);
    final RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock(RepositoryDirectoryInterface.class);
    // test file in repository
    Mockito.doReturn(ObjectLocationSpecificationMethod.FILENAME).when(meta).getSpecificationMethod();
    Mockito.doReturn(parentStepMeta).when(meta).getParentStepMeta();
    Mockito.doReturn(parentTransMeta).when(parentStepMeta).getParentTransMeta();
    Mockito.doReturn(repo).when(parentTransMeta).getRepository();
    Mockito.doReturn("/some/path/to/foo").when(meta).getFileName();
    Mockito.doReturn(repositoryDirectoryInterface).when(repo).findDirectory("/some/path/to");
    Mockito.doReturn(subTransMeta).when(repo).loadTransformation("foo", repositoryDirectoryInterface, null, true, null);
    Mockito.doReturn("/some/path/to/foo").when(parentTransMeta).environmentSubstitute("/some/path/to/foo");
    assertTrue(KettleAnalyzerUtil.getSubTransMeta(meta).equals(subTransMeta));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) ISubTransAwareMeta(org.pentaho.di.trans.ISubTransAwareMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ISubTransAwareMeta (org.pentaho.di.trans.ISubTransAwareMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Repository (org.pentaho.di.repository.Repository)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1