use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class WebServiceMetaTest method testGetFieldOut.
@Test
public void testGetFieldOut() throws Exception {
DatabaseMeta dbMeta = mock(DatabaseMeta.class);
IMetaStore metastore = mock(IMetaStore.class);
WebServiceMeta webServiceMeta = new WebServiceMeta(getTestNode(), Collections.singletonList(dbMeta), metastore);
assertNull(webServiceMeta.getFieldOutFromWsName("", true));
assertEquals("GetCurrentExchangeRateResult", webServiceMeta.getFieldOutFromWsName("GetCurrentExchangeRateResult", false).getName());
assertEquals("GetCurrentExchangeRateResult", webServiceMeta.getFieldOutFromWsName("something:GetCurrentExchangeRateResult", true).getName());
}
use of org.pentaho.metastore.api.IMetaStore 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.metastore.api.IMetaStore 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.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryIT method testDatabaseRepository.
public void testDatabaseRepository() throws Exception {
KettleEnvironment.init();
String filename = File.createTempFile("kdrtest", "").getAbsolutePath();
System.out.println("Using file '" + filename + "' as a H2 database repository");
try {
DatabaseMeta databaseMeta = new DatabaseMeta("H2Repo", "H2", "JDBC", null, filename, null, null, null);
repositoryMeta = new KettleDatabaseRepositoryMeta("KettleDatabaseRepository", "H2Repo", "H2 Repository", databaseMeta);
repository = new KettleDatabaseRepository();
repository.init(repositoryMeta);
repository.connectionDelegate.connect(true, true);
KettleDatabaseRepositoryCreationHelper helper = new KettleDatabaseRepositoryCreationHelper(repository);
helper.createRepositorySchema(null, false, new ArrayList<String>(), false);
repository.disconnect();
// Test connecting...
//
repository.connect("admin", "admin");
assertTrue(repository.isConnected());
// Test database save
DatabaseMeta dataBaseForSave = new DatabaseMeta("H2Test", "H2", "JDBC", null, filename, null, null, null);
repository.save(dataBaseForSave, "User creates new database");
// load new database from repository by generated id on save step
DatabaseMeta loadedDataBase = repository.loadDatabaseMeta(dataBaseForSave.getObjectId(), "User creates new database");
assertEquals("Database object before save and after load form database is diffenert", dataBaseForSave, loadedDataBase);
// Test loading the directory tree
tree = repository.loadRepositoryDirectoryTree();
assertNotNull(tree);
// Test directory creation
//
RepositoryDirectoryInterface fooDirectory = repository.createRepositoryDirectory(tree, "foo");
RepositoryDirectoryInterface barDirectory = repository.createRepositoryDirectory(fooDirectory, "bar");
RepositoryDirectoryInterface samplesDirectory = repository.createRepositoryDirectory(fooDirectory, "samples");
// Test directory path lookup
RepositoryDirectoryInterface checkBar = tree.findDirectory("/foo/bar");
assertNotNull(checkBar);
assertTrue(checkBar.equals(barDirectory));
// Save all the transformations samples.
//
verifyTransformationSamples(samplesDirectory);
verifyJobSamples(samplesDirectory);
// Verify metastore functionality
//
IMetaStore metaStore = repository.getMetaStore();
KettleMetaStoreTestBase testBase = new KettleMetaStoreTestBase();
testBase.testFunctionality(metaStore);
// Finally test disconnecting
repository.disconnect();
assertFalse(repository.isConnected());
} catch (Exception e) {
e.printStackTrace();
throw new KettleException("Error during database repository unit testing", e);
} finally {
// Remove the H2 database file
//
assertTrue(new File(filename + ".h2.db").delete());
assertTrue(new File(filename + ".trace.db").delete());
}
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class KettleFileRepositoryIT method testDatabaseRepository.
public void testDatabaseRepository() throws Exception {
KettleEnvironment.init();
String dirName = System.getProperty("java.io.tmpdir") + "/" + UUID.randomUUID();
File dirFile = new File(dirName);
if (!dirFile.mkdir()) {
throw new KettleException("bad luck, directory '" + dirName + "' already exists and can't be used to put a file repository in it.");
}
System.out.println("Using folder '" + dirName + "' to store a file repository in.");
try {
repositoryMeta = new KettleFileRepositoryMeta("KettleFileRepository", "FileRep", "File repository", dirName);
repository = new KettleFileRepository();
repository.init(repositoryMeta);
// Test connecting... (no security needed)
//
repository.connect(null, null);
assertTrue(repository.isConnected());
// Test loading the directory tree
//
tree = repository.loadRepositoryDirectoryTree();
assertNotNull(tree);
// Test directory creation
//
RepositoryDirectoryInterface fooDirectory = repository.createRepositoryDirectory(tree, "foo");
RepositoryDirectoryInterface barDirectory = repository.createRepositoryDirectory(fooDirectory, "bar");
RepositoryDirectoryInterface samplesDirectory = repository.createRepositoryDirectory(fooDirectory, "samples");
// Test directory path lookup
RepositoryDirectoryInterface checkBar = tree.findDirectory("/foo/bar");
assertNotNull(checkBar);
assertTrue(checkBar.equals(barDirectory));
// Save all the transformations samples.
//
verifyTransformationSamples(samplesDirectory);
verifyJobSamples(samplesDirectory);
// Verify metastore functionality
//
IMetaStore metaStore = repository.getMetaStore();
KettleMetaStoreTestBase testBase = new KettleMetaStoreTestBase();
testBase.testFunctionality(metaStore);
// Test directory deletion
repository.deleteRepositoryDirectory(samplesDirectory);
RepositoryDirectoryInterface checkDelete = tree.findDirectory("/foo/bar/samples");
assertNull(checkDelete);
// Finally test disconnecting
repository.disconnect();
assertFalse(repository.isConnected());
} catch (Exception e) {
e.printStackTrace();
throw new KettleException("Error during database repository unit testing", e);
} finally {
// Remove all the files and folders in the repository...
//
FileUtils.deleteDirectory(dirFile);
}
}
Aggregations