Search in sources :

Example 11 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method lazyConversionTurnedOff.

@Test
public void lazyConversionTurnedOff() throws KettleException {
    KettleEnvironment.init();
    TransMeta transMeta = new TransMeta();
    CsvInputMeta csvInputMeta = new CsvInputMeta();
    csvInputMeta.setLazyConversionActive(true);
    StepMeta csvInput = new StepMeta("Csv", csvInputMeta);
    transMeta.addStep(csvInput);
    TableInputMeta tableInputMeta = new TableInputMeta();
    tableInputMeta.setLazyConversionActive(true);
    StepMeta tableInput = new StepMeta("Table", tableInputMeta);
    transMeta.addStep(tableInput);
    Transformation trans = TransMetaConverter.convert(transMeta);
    TransMeta cloneMeta;
    String transMetaXml = (String) trans.getConfig().get(TransMetaConverter.TRANS_META_CONF_KEY);
    Document doc;
    try {
        doc = XMLHandler.loadXMLString(transMetaXml);
        Node stepNode = XMLHandler.getSubNode(doc, "transformation");
        cloneMeta = new TransMeta(stepNode, null);
    } catch (KettleXMLException | KettleMissingPluginsException e) {
        throw new RuntimeException(e);
    }
    assertThat(((CsvInputMeta) cloneMeta.findStep("Csv").getStepMetaInterface()).isLazyConversionActive(), is(false));
    assertThat(((TableInputMeta) cloneMeta.findStep("Table").getStepMetaInterface()).isLazyConversionActive(), is(false));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) Node(org.w3c.dom.Node) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Document(org.w3c.dom.Document) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) Test(org.junit.Test)

Example 12 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method transIdFromRepo.

@Test
public void transIdFromRepo() throws Exception {
    TransMeta meta = new TransMeta();
    meta.setName("transName");
    Transformation trans = TransMetaConverter.convert(meta);
    assertThat(trans.getId(), is("/transName"));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 13 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method testRemovingDisabledInputSteps.

@Test
public void testRemovingDisabledInputSteps() {
    TransMeta trans = new TransMeta();
    StepMeta inputToBeRemoved = new StepMeta("InputToBeRemoved", stepMetaInterface);
    trans.addStep(inputToBeRemoved);
    StepMeta inputToStay = new StepMeta("InputToStay", stepMetaInterface);
    trans.addStep(inputToStay);
    StepMeta inputReceiver1 = new StepMeta("InputReceiver1", stepMetaInterface);
    trans.addStep(inputReceiver1);
    StepMeta inputReceiver2 = new StepMeta("InputReceiver2", stepMetaInterface);
    trans.addStep(inputReceiver2);
    TransHopMeta hop1 = new TransHopMeta(inputToBeRemoved, inputReceiver1, false);
    TransHopMeta hop2 = new TransHopMeta(inputToStay, inputReceiver1);
    TransHopMeta hop3 = new TransHopMeta(inputToBeRemoved, inputReceiver2, false);
    trans.addTransHop(hop1);
    trans.addTransHop(hop2);
    trans.addTransHop(hop3);
    Transformation transformation = TransMetaConverter.convert(trans);
    List<String> steps = transformation.getOperations().stream().map(op -> op.getId()).collect(Collectors.toList());
    assertThat("Only 2 ops should exist", steps.size(), is(2));
    assertThat(steps, hasItems("InputToStay", "InputReceiver1"));
    List<String> hops = transformation.getHops().stream().map(hop -> hop.getId()).collect(Collectors.toList());
    assertThat("Only 1 hop should exist", hops.size(), is(1));
    assertThat(hops, hasItems("InputToStay -> InputReceiver1"));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Trans(org.pentaho.di.trans.Trans) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) Hop(org.pentaho.di.engine.api.model.Hop) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) KettleClientEnvironment(org.pentaho.di.core.KettleClientEnvironment) Operation(org.pentaho.di.engine.api.model.Operation) TransMeta(org.pentaho.di.trans.TransMeta) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Document(org.w3c.dom.Document) Matchers.eq(org.mockito.Matchers.eq) Spy(org.mockito.Spy) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) StepInterface(org.pentaho.di.trans.step.StepInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) AfterClass(org.junit.AfterClass) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Variables(org.pentaho.di.core.variables.Variables) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) Collectors(java.util.stream.Collectors) ResolvableResource(org.pentaho.di.workarounds.ResolvableResource) List(java.util.List) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Mockito.mock(org.mockito.Mockito.mock) RestorePDIEngineEnvironment(org.pentaho.di.junit.rules.RestorePDIEngineEnvironment) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) KettleException(org.pentaho.di.core.exception.KettleException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) CoreMatchers.everyItem(org.hamcrest.CoreMatchers.everyItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XMLHandler(org.pentaho.di.core.xml.XMLHandler) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Node(org.w3c.dom.Node) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Props(org.pentaho.di.core.Props) Repository(org.pentaho.di.repository.Repository) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) KettleEnvironment(org.pentaho.di.core.KettleEnvironment) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TransHopMeta(org.pentaho.di.trans.TransHopMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) Assert.assertEquals(org.junit.Assert.assertEquals) Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 14 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method transWithHops.

@Test
public void transWithHops() {
    TransMeta meta = new TransMeta();
    meta.setFilename("fileName");
    StepMeta from = new StepMeta("step1", stepMetaInterface);
    meta.addStep(from);
    StepMeta to = new StepMeta("step2", stepMetaInterface);
    meta.addStep(to);
    meta.addTransHop(new TransHopMeta(from, to));
    Transformation trans = TransMetaConverter.convert(meta);
    assertThat(trans.getId(), is(meta.getFilename()));
    assertThat(trans.getOperations().size(), is(2));
    assertThat(trans.getHops().size(), is(1));
    assertThat(trans.getHops().get(0).getFrom().getId(), is(from.getName()));
    assertThat(trans.getHops().get(0).getTo().getId(), is(to.getName()));
    assertThat(trans.getHops().stream().map(Hop::getType).collect(Collectors.toList()), everyItem(is(Hop.TYPE_NORMAL)));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Hop(org.pentaho.di.engine.api.model.Hop) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 15 with Transformation

use of org.pentaho.di.engine.api.model.Transformation in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method testMultipleDisabledHops.

@Test
public void testMultipleDisabledHops() {
    TransMeta trans = new TransMeta();
    StepMeta input = new StepMeta("Input", stepMetaInterface);
    trans.addStep(input);
    StepMeta step1 = new StepMeta("Step1", stepMetaInterface);
    trans.addStep(step1);
    StepMeta step2 = new StepMeta("Step2", stepMetaInterface);
    trans.addStep(step2);
    StepMeta step3 = new StepMeta("Step3", stepMetaInterface);
    trans.addStep(step3);
    TransHopMeta hop1 = new TransHopMeta(input, step1, false);
    TransHopMeta hop2 = new TransHopMeta(step1, step2, false);
    TransHopMeta hop3 = new TransHopMeta(step2, step3, false);
    trans.addTransHop(hop1);
    trans.addTransHop(hop2);
    trans.addTransHop(hop3);
    Transformation transformation = TransMetaConverter.convert(trans);
    assertThat("Trans has steps though all of them should be removed", transformation.getOperations().size(), is(0));
    assertThat("Trans has hops though all of them should be removed", transformation.getHops().size(), is(0));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Aggregations

Transformation (org.pentaho.di.engine.api.model.Transformation)15 TransMeta (org.pentaho.di.trans.TransMeta)15 Test (org.junit.Test)12 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)12 StepMeta (org.pentaho.di.trans.step.StepMeta)10 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)7 HashMap (java.util.HashMap)6 List (java.util.List)6 Operation (org.pentaho.di.engine.api.model.Operation)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 KettleException (org.pentaho.di.core.exception.KettleException)5 Hop (org.pentaho.di.engine.api.model.Hop)5 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)5 Optional (java.util.Optional)3 Collectors.toMap (java.util.stream.Collectors.toMap)3 Repository (org.pentaho.di.repository.Repository)3 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)3 Trans (org.pentaho.di.trans.Trans)3