use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class WebServiceMetaTest method testGetFields.
@Test
public void testGetFields() throws Exception {
WebServiceMeta webServiceMeta = new WebServiceMeta();
webServiceMeta.setDefault();
RowMetaInterface rmi = mock(RowMetaInterface.class);
RowMetaInterface rmi2 = mock(RowMetaInterface.class);
StepMeta nextStep = mock(StepMeta.class);
IMetaStore metastore = mock(IMetaStore.class);
Repository rep = mock(Repository.class);
WebServiceField field1 = new WebServiceField();
field1.setName("field1");
field1.setWsName("field1WS");
field1.setXsdType("string");
WebServiceField field2 = new WebServiceField();
field2.setName("field2");
field2.setWsName("field2WS");
field2.setXsdType("string");
WebServiceField field3 = new WebServiceField();
field3.setName("field3");
field3.setWsName("field3WS");
field3.setXsdType("string");
webServiceMeta.setFieldsOut(Arrays.asList(field1, field2, field3));
webServiceMeta.getFields(rmi, "idk", new RowMetaInterface[] { rmi2 }, nextStep, new Variables(), rep, metastore);
verify(rmi).addValueMeta(argThat(matchValueMetaString("field1")));
verify(rmi).addValueMeta(argThat(matchValueMetaString("field2")));
verify(rmi).addValueMeta(argThat(matchValueMetaString("field3")));
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class WebServiceMetaTest method testReadRep.
@Test
public void testReadRep() throws Exception {
Repository rep = mock(Repository.class);
IMetaStore metastore = mock(IMetaStore.class);
DatabaseMeta dbMeta = mock(DatabaseMeta.class);
StringObjectId id_step = new StringObjectId("oid");
when(rep.getStepAttributeString(id_step, "wsOperation")).thenReturn("GetCurrentExchangeRate");
when(rep.getStepAttributeString(id_step, "wsOperationRequest")).thenReturn("opRequest");
when(rep.getStepAttributeString(id_step, "wsOperationNamespace")).thenReturn("opNamespace");
when(rep.getStepAttributeString(id_step, "wsInFieldContainer")).thenReturn("ifc");
when(rep.getStepAttributeString(id_step, "wsInFieldArgument")).thenReturn("ifa");
when(rep.getStepAttributeString(id_step, "wsOutFieldContainer")).thenReturn("ofc");
when(rep.getStepAttributeString(id_step, "wsOutFieldArgument")).thenReturn("ofa");
when(rep.getStepAttributeString(id_step, "proxyHost")).thenReturn("phost");
when(rep.getStepAttributeString(id_step, "proxyPort")).thenReturn("1234");
when(rep.getStepAttributeString(id_step, "httpLogin")).thenReturn("user");
when(rep.getStepAttributeString(id_step, "httpPassword")).thenReturn("password");
when(rep.getStepAttributeInteger(id_step, "callStep")).thenReturn(2L);
when(rep.getStepAttributeBoolean(id_step, "passingInputData")).thenReturn(true);
when(rep.getStepAttributeBoolean(id_step, 0, "compatible", true)).thenReturn(false);
when(rep.getStepAttributeString(id_step, "repeating_element")).thenReturn("repeat");
when(rep.getStepAttributeBoolean(id_step, 0, "reply_as_string")).thenReturn(true);
when(rep.countNrStepAttributes(id_step, "fieldIn_ws_name")).thenReturn(2);
when(rep.getStepAttributeString(id_step, 0, "fieldIn_name")).thenReturn("bank");
when(rep.getStepAttributeString(id_step, 0, "fieldIn_ws_name")).thenReturn("inBank");
when(rep.getStepAttributeString(id_step, 0, "fieldIn_xsd_type")).thenReturn("string");
when(rep.getStepAttributeString(id_step, 1, "fieldIn_name")).thenReturn("branch");
when(rep.getStepAttributeString(id_step, 1, "fieldIn_ws_name")).thenReturn("inBranch");
when(rep.getStepAttributeString(id_step, 1, "fieldIn_xsd_type")).thenReturn("string");
when(rep.countNrStepAttributes(id_step, "fieldOut_ws_name")).thenReturn(2);
when(rep.getStepAttributeString(id_step, 0, "fieldOut_name")).thenReturn("balance");
when(rep.getStepAttributeString(id_step, 0, "fieldOut_ws_name")).thenReturn("outBalance");
when(rep.getStepAttributeString(id_step, 0, "fieldOut_xsd_type")).thenReturn("int");
when(rep.getStepAttributeString(id_step, 1, "fieldOut_name")).thenReturn("transactions");
when(rep.getStepAttributeString(id_step, 1, "fieldOut_ws_name")).thenReturn("outTransactions");
when(rep.getStepAttributeString(id_step, 1, "fieldOut_xsd_type")).thenReturn("int");
WebServiceMeta webServiceMeta = new WebServiceMeta(rep, metastore, id_step, Collections.singletonList(dbMeta));
String expectedXml = "" + " <wsURL/>\n" + " <wsOperation>GetCurrentExchangeRate</wsOperation>\n" + " <wsOperationRequest>opRequest</wsOperationRequest>\n" + " <wsOperationNamespace>opNamespace</wsOperationNamespace>\n" + " <wsInFieldContainer>ifc</wsInFieldContainer>\n" + " <wsInFieldArgument>ifa</wsInFieldArgument>\n" + " <wsOutFieldContainer>ofc</wsOutFieldContainer>\n" + " <wsOutFieldArgument>ofa</wsOutFieldArgument>\n" + " <proxyHost>phost</proxyHost>\n" + " <proxyPort>1234</proxyPort>\n" + " <httpLogin>user</httpLogin>\n" + " <httpPassword>password</httpPassword>\n" + " <callStep>2</callStep>\n" + " <passingInputData>Y</passingInputData>\n" + " <compatible>N</compatible>\n" + " <repeating_element>repeat</repeating_element>\n" + " <reply_as_string>Y</reply_as_string>\n" + " <fieldsIn>\n" + " <field>\n" + " <name>bank</name>\n" + " <wsName>inBank</wsName>\n" + " <xsdType>string</xsdType>\n" + " </field>\n" + " <field>\n" + " <name>branch</name>\n" + " <wsName>inBranch</wsName>\n" + " <xsdType>string</xsdType>\n" + " </field>\n" + " </fieldsIn>\n" + " <fieldsOut>\n" + " <field>\n" + " <name>balance</name>\n" + " <wsName>outBalance</wsName>\n" + " <xsdType>int</xsdType>\n" + " </field>\n" + " <field>\n" + " <name>transactions</name>\n" + " <wsName>outTransactions</wsName>\n" + " <xsdType>int</xsdType>\n" + " </field>\n" + " </fieldsOut>\n";
String actualXml = TestUtils.toUnixLineSeparators(webServiceMeta.getXML());
assertEquals(expectedXml, actualXml);
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class RunTransServletTest method testRunTransServletCheckParameter.
@Test
public void testRunTransServletCheckParameter() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Mockito.when(request.getParameter("trans")).thenReturn("home/test.rtr");
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
Mockito.when(request.getContextPath()).thenReturn(RunTransServlet.CONTEXT_PATH);
Mockito.when(response.getWriter()).thenReturn(printWriter);
TransformationMap mockTransformationMap = Mockito.mock(TransformationMap.class);
SlaveServerConfig slaveServerConfig = Mockito.mock(SlaveServerConfig.class);
Mockito.when(mockTransformationMap.getSlaveServerConfig()).thenReturn(slaveServerConfig);
Repository repository = Mockito.mock(Repository.class);
Mockito.when(slaveServerConfig.getRepository()).thenReturn(repository);
RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock(RepositoryDirectoryInterface.class);
Mockito.when(repository.loadRepositoryDirectoryTree()).thenReturn(repositoryDirectoryInterface);
Mockito.when(repositoryDirectoryInterface.findDirectory(Mockito.anyString())).thenReturn(repositoryDirectoryInterface);
TransMeta transMeta = Mockito.mock(TransMeta.class);
Mockito.when(repository.loadTransformation(Mockito.any(), Mockito.any())).thenReturn(transMeta);
String testParameter = "testParameter";
Mockito.when(transMeta.listVariables()).thenReturn(new String[] { testParameter });
Mockito.when(transMeta.getVariable(Mockito.anyString())).thenReturn("default value");
Mockito.when(transMeta.listParameters()).thenReturn(new String[] { testParameter });
Mockito.when(request.getParameterNames()).thenReturn(new StringTokenizer(testParameter));
String testValue = "testValue";
Mockito.when(request.getParameterValues(testParameter)).thenReturn(new String[] { testValue });
RunTransServlet runTransServlet = Mockito.mock(RunTransServlet.class);
Mockito.doCallRealMethod().when(runTransServlet).doGet(Mockito.anyObject(), Mockito.anyObject());
Trans trans = new Trans(transMeta, new SimpleLoggingObject(RunTransServlet.CONTEXT_PATH, LoggingObjectType.CARTE, null));
Mockito.when(runTransServlet.createTrans(Mockito.anyObject(), Mockito.anyObject())).thenReturn(trans);
Mockito.when(transMeta.getParameterValue(Mockito.eq(testParameter))).thenReturn(testValue);
runTransServlet.log = new LogChannel("RunTransServlet");
runTransServlet.transformationMap = mockTransformationMap;
runTransServlet.doGet(request, response);
Assert.assertEquals(testValue, trans.getParameterValue(testParameter));
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class TransExecutionConfiguration method connectRepository.
public Repository connectRepository(RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password) throws KettleException {
RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryName);
if (repositoryMeta == null) {
log.logBasic("I couldn't find the repository with name '" + repositoryName + "'");
return null;
}
Repository rep = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
if (rep == null) {
log.logBasic("Unable to load repository plugin for '" + repositoryName + "'");
return null;
}
rep.init(repositoryMeta);
try {
rep.connect(username, password);
setRepository(rep);
return rep;
} catch (Exception e) {
log.logBasic("Unable to connect to the repository with name '" + repositoryName + "'");
return null;
}
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class TransMetaConverter method convert.
public static Transformation convert(TransMeta transMeta) {
final org.pentaho.di.engine.model.Transformation transformation = new org.pentaho.di.engine.model.Transformation(createTransformationId(transMeta));
try {
TransMeta copyTransMeta = (TransMeta) transMeta.realClone(false);
cleanupDisabledHops(copyTransMeta);
// Turn off lazy conversion for AEL for now
disableLazyConversion(copyTransMeta);
// This is needed to resolve resources if a parameter is used within steps like text file out or Hadoop out.
// It is unclear why this is needed, as the resource location can be resolved on the AEL/Driver/Executor side.
// This should be removed a long with org.pentaho.di.workarounds.ResolvableResource which is apparently deprecated
// since 8.1
copyTransMeta.activateParameters();
resolveStepMetaResources(copyTransMeta);
copyTransMeta.getSteps().forEach(createOperation(transformation));
findHops(copyTransMeta, hop -> true).forEach(createHop(transformation));
transformation.setConfig(TRANS_META_CONF_KEY, copyTransMeta.getXML());
transformation.setConfig(TRANS_META_NAME_CONF_KEY, Optional.ofNullable(transMeta.getName()).orElse(TRANS_DEFAULT_NAME));
Map<String, Transformation> subTransformations = copyTransMeta.getResourceDependencies().stream().flatMap(resourceReference -> resourceReference.getEntries().stream()).filter(entry -> ResourceEntry.ResourceType.ACTIONFILE.equals(entry.getResourcetype())).collect(toMap(ResourceEntry::getResource, entry -> {
try {
Repository repository = copyTransMeta.getRepository();
if (repository != null) {
Path path = Paths.get(entry.getResource());
RepositoryDirectoryInterface directory = repository.findDirectory(path.getParent().toString().replace(File.separator, "/"));
return convert(repository.loadTransformation(path.getFileName().toString(), directory, null, true, null));
}
return convert(new TransMeta(entry.getResource(), copyTransMeta.getParentVariableSpace()));
} catch (KettleException e) {
throw new RuntimeException(e);
}
}));
transformation.setConfig(SUB_TRANSFORMATIONS_KEY, (Serializable) subTransformations);
} catch (KettleException e) {
Throwables.propagate(e);
}
return transformation;
}
Aggregations