use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class JobExecutionConfigurationTest method testGetUsedArguments.
@Test
public void testGetUsedArguments() throws KettleException {
JobExecutionConfiguration executionConfiguration = new JobExecutionConfiguration();
JobMeta jobMeta = new JobMeta();
jobMeta.jobcopies = new ArrayList<>();
String[] commandLineArguments = new String[0];
IMetaStore metaStore = mock(IMetaStore.class);
JobEntryCopy jobEntryCopy0 = new JobEntryCopy();
TransMeta transMeta0 = mock(TransMeta.class);
Map<String, String> map0 = new HashMap<>();
map0.put("arg0", "argument0");
when(transMeta0.getUsedArguments(commandLineArguments)).thenReturn(map0);
JobEntryInterface jobEntryInterface0 = mock(JobEntryInterface.class);
when(jobEntryInterface0.isTransformation()).thenReturn(false);
jobEntryCopy0.setEntry(jobEntryInterface0);
jobMeta.jobcopies.add(jobEntryCopy0);
JobEntryCopy jobEntryCopy1 = new JobEntryCopy();
TransMeta transMeta1 = mock(TransMeta.class);
Map<String, String> map1 = new HashMap<>();
map1.put("arg1", "argument1");
when(transMeta1.getUsedArguments(commandLineArguments)).thenReturn(map1);
JobEntryTrans jobEntryTrans1 = mock(JobEntryTrans.class);
when(jobEntryTrans1.isTransformation()).thenReturn(true);
when(jobEntryTrans1.getTransMeta(executionConfiguration.getRepository(), metaStore, jobMeta)).thenReturn(transMeta1);
jobEntryCopy1.setEntry(jobEntryTrans1);
jobMeta.jobcopies.add(jobEntryCopy1);
JobEntryCopy jobEntryCopy2 = new JobEntryCopy();
TransMeta transMeta2 = mock(TransMeta.class);
Map<String, String> map2 = new HashMap<>();
map2.put("arg1", "argument1");
map2.put("arg2", "argument2");
when(transMeta2.getUsedArguments(commandLineArguments)).thenReturn(map2);
JobEntryTrans jobEntryTrans2 = mock(JobEntryTrans.class);
when(jobEntryTrans2.isTransformation()).thenReturn(true);
when(jobEntryTrans2.getTransMeta(executionConfiguration.getRepository(), metaStore, jobMeta)).thenReturn(transMeta2);
jobEntryCopy2.setEntry(jobEntryTrans2);
jobMeta.jobcopies.add(jobEntryCopy2);
executionConfiguration.getUsedArguments(jobMeta, commandLineArguments, metaStore);
assertEquals(2, executionConfiguration.getArguments().size());
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class CombinationLookupIT method testUseDefaultSchemaName.
public void testUseDefaultSchemaName() throws Exception {
String schemaName = "";
String tableName = "tableName";
String schemaTable = "default.tableName";
String technicalKeyField = "technicalKeyField";
DatabaseMeta databaseMeta = spy(new DatabaseMeta(databasesXML[0]) {
@Override
public String getFieldDefinition(ValueMetaInterface v, String tk, String pk, boolean use_autoinc) {
return "someValue";
}
});
when(databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName)).thenReturn(schemaTable);
CombinationLookupMeta clm = new CombinationLookupMeta();
clm.setTechnicalKeyField(technicalKeyField);
clm.setKeyLookup(new String[] { "keyLookup1", "keyLookup2" });
clm.setDatabaseMeta(databaseMeta);
clm.setTablename(tableName);
clm.setSchemaName(schemaName);
StepMeta stepMeta = mock(StepMeta.class);
RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
when(rowMetaInterface.size()).thenReturn(1);
Repository repository = mock(Repository.class);
IMetaStore metaStore = mock(IMetaStore.class);
SQLStatement sqlStatement = clm.getSQLStatements(new TransMeta(), stepMeta, rowMetaInterface, repository, metaStore);
String sql = sqlStatement.getSQL();
Assert.assertTrue(StringUtils.countMatches(sql, schemaTable) == 3);
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class JobEntryJobTest method testJobEntry.
@SuppressWarnings("unchecked")
private void testJobEntry(Repository rep, boolean includeJobName, ObjectLocationSpecificationMethod method, ObjectLocationSpecificationMethod expectedMethod) throws KettleXMLException, ParserConfigurationException, SAXException, IOException {
List<DatabaseMeta> databases = mock(List.class);
List<SlaveServer> slaveServers = mock(List.class);
IMetaStore metaStore = mock(IMetaStore.class);
JobEntryJob jobEntryJob = getJobEntryJob();
jobEntryJob.loadXML(getEntryNode(includeJobName, method), databases, slaveServers, rep, metaStore);
assertEquals("If we connect to repository then we use rep_name method", expectedMethod, jobEntryJob.getSpecificationMethod());
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class JobEntryTransTest method testJobEntry.
@SuppressWarnings("unchecked")
private void testJobEntry(Repository rep, boolean includeJobName, ObjectLocationSpecificationMethod method, ObjectLocationSpecificationMethod expectedMethod) throws KettleXMLException, ParserConfigurationException, SAXException, IOException {
List<DatabaseMeta> databases = mock(List.class);
List<SlaveServer> slaveServers = mock(List.class);
IMetaStore metaStore = mock(IMetaStore.class);
JobEntryTrans jobEntryTrans = getJobEntryTrans();
jobEntryTrans.loadXML(getEntryNode(includeJobName, method), databases, slaveServers, rep, metaStore);
assertEquals("If we connect to repository then we use rep_name method", expectedMethod, jobEntryTrans.getSpecificationMethod());
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-platform by pentaho.
the class MetaStoreImportHandler method importFile.
@Override
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
InputStream inputStream = bundle.getInputStream();
Path path = Files.createTempDirectory(METASTORE);
path.toFile().deleteOnExit();
// get the zipped metastore from the export bundle
ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
try {
String filePath = path.toString() + File.separator + entry.getName();
if (entry.isDirectory()) {
File dir = new File(filePath);
dir.mkdir();
} else {
File file = new File(filePath);
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(filePath);
IOUtils.copy(zis, fos);
IOUtils.closeQuietly(fos);
}
} finally {
zis.closeEntry();
}
}
IOUtils.closeQuietly(zis);
// get a hold of the metastore to import into
IMetaStore metastore = getRepoMetaStore();
if (metastore != null) {
// copy the exported metastore to where it needs to go
try {
if (tmpXmlMetaStore == null) {
tmpXmlMetaStore = new XmlMetaStore(path.toString());
} else {
// we are re-using an existing object, make sure the root folder is pointed at the new location on disk
tmpXmlMetaStore.setRootFolder(path.toString() + File.separator + METASTORE);
}
tmpXmlMetaStore.setName(bundle.getName());
String desc = bundle.getProperty("description") == null ? null : bundle.getProperty("description").toString();
tmpXmlMetaStore.setDescription(desc);
MetaStoreUtil.copy(tmpXmlMetaStore, metastore, bundle.overwriteInRepository());
} catch (MetaStoreException e) {
log.error("Could not restore the MetaStore");
log.debug("Error restoring the MetaStore", e);
}
}
}
Aggregations