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 ZipFileMetaTest method testReadRep.
@Test
public void testReadRep() throws Exception {
ZipFileMeta zipFileMeta = new ZipFileMeta();
Repository rep = mock(Repository.class);
IMetaStore metastore = mock(IMetaStore.class);
DatabaseMeta dbMeta = mock(DatabaseMeta.class);
StringObjectId oid = new StringObjectId("oid");
when(rep.getStepAttributeString(oid, "sourcefilenamefield")).thenReturn(SOURCE_FILENAME);
when(rep.getStepAttributeString(oid, "targetfilenamefield")).thenReturn(TARGET_FILENAME);
when(rep.getStepAttributeString(oid, "baseFolderField")).thenReturn(BASE_FOLDER);
when(rep.getStepAttributeString(oid, "operation_type")).thenReturn(OPERATION_TYPE);
when(rep.getStepAttributeBoolean(oid, "addresultfilenames")).thenReturn(ADD_RESULT_FILENAME);
when(rep.getStepAttributeBoolean(oid, "overwritezipentry")).thenReturn(OVERWRITE_ZIP_ENTRY);
when(rep.getStepAttributeBoolean(oid, "createparentfolder")).thenReturn(CREATE_PARENT_FOLDER);
when(rep.getStepAttributeBoolean(oid, "keepsourcefolder")).thenReturn(KEEP_SOURCE_FOLDER);
when(rep.getStepAttributeString(oid, "movetofolderfield")).thenReturn(MOVE_TO_FOLDER_FIELD);
zipFileMeta.readRep(rep, metastore, oid, Collections.singletonList(dbMeta));
assertEquals(SOURCE_FILENAME, zipFileMeta.getDynamicSourceFileNameField());
assertEquals(TARGET_FILENAME, zipFileMeta.getDynamicTargetFileNameField());
assertEquals(BASE_FOLDER, zipFileMeta.getBaseFolderField());
assertEquals(ZipFileMeta.getOperationTypeByDesc(OPERATION_TYPE), zipFileMeta.getOperationType());
assertEquals(MOVE_TO_FOLDER_FIELD, zipFileMeta.getMoveToFolderField());
assertTrue(zipFileMeta.isaddTargetFileNametoResult());
assertTrue(zipFileMeta.isOverwriteZipEntry());
assertTrue(zipFileMeta.isKeepSouceFolder());
assertTrue(zipFileMeta.isCreateParentFolder());
Mockito.reset(rep, metastore);
StringObjectId transid = new StringObjectId("transid");
zipFileMeta.saveRep(rep, metastore, transid, oid);
verify(rep).saveStepAttribute(transid, oid, "sourcefilenamefield", SOURCE_FILENAME);
verify(rep).saveStepAttribute(transid, oid, "targetfilenamefield", TARGET_FILENAME);
verify(rep).saveStepAttribute(transid, oid, "baseFolderField", BASE_FOLDER);
verify(rep).saveStepAttribute(transid, oid, "operation_type", OPERATION_TYPE);
verify(rep).saveStepAttribute(transid, oid, "addresultfilenames", ADD_RESULT_FILENAME);
verify(rep).saveStepAttribute(transid, oid, "overwritezipentry", OVERWRITE_ZIP_ENTRY);
verify(rep).saveStepAttribute(transid, oid, "createparentfolder", CREATE_PARENT_FOLDER);
verify(rep).saveStepAttribute(transid, oid, "keepsourcefolder", KEEP_SOURCE_FOLDER);
verify(rep).saveStepAttribute(transid, oid, "movetofolderfield", MOVE_TO_FOLDER_FIELD);
Mockito.verifyNoMoreInteractions(rep, metastore);
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class JobEntryTransTest method testGetTransMeta.
@Test
public void testGetTransMeta() throws KettleException {
String param1 = "param1";
String param2 = "param2";
String param3 = "param3";
String parentValue1 = "parentValue1";
String parentValue2 = "parentValue2";
String childValue3 = "childValue3";
JobEntryTrans jobEntryTrans = spy(getJobEntryTrans());
Repository rep = Mockito.mock(Repository.class);
TransMeta meta = new TransMeta();
meta.setVariable(param2, "childValue2 should be override");
meta.setVariable(param3, childValue3);
Mockito.doReturn(meta).when(rep).loadTransformation(Mockito.eq("test.ktr"), Mockito.anyObject(), Mockito.anyObject(), Mockito.anyBoolean(), Mockito.anyObject());
VariableSpace parentSpace = new Variables();
parentSpace.setVariable(param1, parentValue1);
parentSpace.setVariable(param2, parentValue2);
jobEntryTrans.setFileName("/home/admin/test.ktr");
Mockito.doNothing().when(jobEntryTrans).logBasic(Mockito.anyString());
jobEntryTrans.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
TransMeta transMeta;
jobEntryTrans.setPassingAllParameters(false);
transMeta = jobEntryTrans.getTransMeta(rep, null, parentSpace);
Assert.assertEquals(null, transMeta.getVariable(param1));
Assert.assertEquals(parentValue2, transMeta.getVariable(param2));
Assert.assertEquals(childValue3, transMeta.getVariable(param3));
jobEntryTrans.setPassingAllParameters(true);
transMeta = jobEntryTrans.getTransMeta(rep, null, parentSpace);
Assert.assertEquals(parentValue1, transMeta.getVariable(param1));
Assert.assertEquals(parentValue2, transMeta.getVariable(param2));
Assert.assertEquals(childValue3, transMeta.getVariable(param3));
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class JobEntryTransTest method testChooseSpecMethodByRepositoryConnectionStatus.
/**
* BACKLOG-179 - Exporting/Importing Jobs breaks Transformation specification when using "Specify by reference"
*
* Test checks that we choose different {@link ObjectLocationSpecificationMethod} when connection to
* {@link Repository} and disconnected.
*
* <b>Important!</b> You must rewrite test when change import logic
*
* @throws KettleXMLException
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
*/
@Test
public void testChooseSpecMethodByRepositoryConnectionStatus() throws KettleXMLException, ParserConfigurationException, SAXException, IOException {
Repository rep = mock(Repository.class);
when(rep.isConnected()).thenReturn(true);
// 000
// not connected, no jobname, no method
testJobEntry(null, false, null, ObjectLocationSpecificationMethod.FILENAME);
// 001
// not connected, no jobname, REPOSITORY_BY_REFERENCE method
testJobEntry(null, false, ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE, ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE);
// not connected, no jobname, REPOSITORY_BY_NAME method
testJobEntry(null, false, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
// not connected, no jobname, FILENAME method
testJobEntry(null, false, ObjectLocationSpecificationMethod.FILENAME, ObjectLocationSpecificationMethod.FILENAME);
// 010
// not connected, jobname, no method
testJobEntry(null, true, null, ObjectLocationSpecificationMethod.FILENAME);
// 011
// not connected, jobname, REPOSITORY_BY_REFERENCE method
testJobEntry(null, true, ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE, ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE);
// not connected, jobname, REPOSITORY_BY_NAME method
testJobEntry(null, true, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
// not connected, jobname, FILENAME method
testJobEntry(null, true, ObjectLocationSpecificationMethod.FILENAME, ObjectLocationSpecificationMethod.FILENAME);
// 100
// connected, no jobname, no method
testJobEntry(rep, false, null, ObjectLocationSpecificationMethod.FILENAME);
// 101
// connected, no jobname, REPOSITORY_BY_REFERENCE method
testJobEntry(rep, false, ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE, ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE);
// connected, no jobname, REPOSITORY_BY_NAME method
testJobEntry(rep, false, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
// connected, no jobname, FILENAME method
testJobEntry(rep, false, ObjectLocationSpecificationMethod.FILENAME, ObjectLocationSpecificationMethod.FILENAME);
// 110
// connected, jobname, no method
testJobEntry(rep, true, null, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
// 111
// connected, jobname, REPOSITORY_BY_REFERENCE method
testJobEntry(rep, true, ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
// connected, jobname, REPOSITORY_BY_NAME method
testJobEntry(rep, true, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
// connected, jobname, FILENAME method
testJobEntry(rep, true, ObjectLocationSpecificationMethod.FILENAME, ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class JobExecutionConfigurationTest method testConnectRepository.
@Test
public void testConnectRepository() throws KettleException {
JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration();
final RepositoriesMeta repositoriesMeta = mock(RepositoriesMeta.class);
final RepositoryMeta repositoryMeta = mock(RepositoryMeta.class);
final Repository repository = mock(Repository.class);
final String mockRepo = "mockRepo";
final boolean[] connectionSuccess = { false };
Repository initialRepo = mock(Repository.class);
jobExecutionConfiguration.setRepository(initialRepo);
KettleLogStore.init();
// Create mock repository plugin
MockRepositoryPlugin mockRepositoryPlugin = mock(MockRepositoryPlugin.class);
when(mockRepositoryPlugin.getIds()).thenReturn(new String[] { "mockRepo" });
when(mockRepositoryPlugin.matches("mockRepo")).thenReturn(true);
when(mockRepositoryPlugin.getName()).thenReturn("mock-repository");
when(mockRepositoryPlugin.getClassMap()).thenAnswer(new Answer<Map<Class<?>, String>>() {
@Override
public Map<Class<?>, String> answer(InvocationOnMock invocation) throws Throwable {
Map<Class<?>, String> dbMap = new HashMap<Class<?>, String>();
dbMap.put(Repository.class, repositoryMeta.getClass().getName());
return dbMap;
}
});
PluginRegistry.getInstance().registerPlugin(RepositoryPluginType.class, mockRepositoryPlugin);
// Define valid connection criteria
when(repositoriesMeta.findRepository(anyString())).thenAnswer(new Answer<RepositoryMeta>() {
@Override
public RepositoryMeta answer(InvocationOnMock invocation) throws Throwable {
return mockRepo.equals(invocation.getArguments()[0]) ? repositoryMeta : null;
}
});
when(mockRepositoryPlugin.loadClass(Repository.class)).thenReturn(repository);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if ("username".equals(invocation.getArguments()[0]) && "password".equals(invocation.getArguments()[1])) {
connectionSuccess[0] = true;
} else {
connectionSuccess[0] = false;
throw new KettleException("Mock Repository connection failed");
}
return null;
}
}).when(repository).connect(anyString(), anyString());
// Ignore repository not found in RepositoriesMeta
jobExecutionConfiguration.connectRepository(repositoriesMeta, "notFound", "username", "password");
assertEquals("Repository Changed", initialRepo, jobExecutionConfiguration.getRepository());
// Ignore failed attempt to connect
jobExecutionConfiguration.connectRepository(repositoriesMeta, mockRepo, "username", "");
assertEquals("Repository Changed", initialRepo, jobExecutionConfiguration.getRepository());
// Save repository if connection passes
jobExecutionConfiguration.connectRepository(repositoriesMeta, mockRepo, "username", "password");
assertEquals("Repository didn't change", repository, jobExecutionConfiguration.getRepository());
assertTrue("Repository not connected", connectionSuccess[0]);
}
Aggregations