use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class JobEntrySetVariablesTest method testJobEntrySetVariablesExecute_VARIABLE_TYPE_JVM_VariableNotNull.
@Test
public void testJobEntrySetVariablesExecute_VARIABLE_TYPE_JVM_VariableNotNull() throws Exception {
List<DatabaseMeta> databases = mock(List.class);
List<SlaveServer> slaveServers = mock(List.class);
Repository repository = mock(Repository.class);
IMetaStore metaStore = mock(IMetaStore.class);
entry.loadXML(getEntryNode("variableNotNull", "someValue", "JVM"), databases, slaveServers, repository, metaStore);
assertNull(System.getProperty("variableNotNull"));
Result result = entry.execute(new Result(), 0);
assertTrue("Result should be true", result.getResult());
assertEquals("someValue", System.getProperty("variableNotNull"));
}
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 DeleteMetaTest method testReadRepToLoadKeys.
@Test
public void testReadRepToLoadKeys() throws KettleException {
DeleteMeta deleteMeta = new DeleteMeta();
Repository rep = mock(Repository.class);
IMetaStore metaStore = mock(IMetaStore.class);
ObjectId idStep = mock(ObjectId.class);
List<DatabaseMeta> databases = new ArrayList<>();
String keyNameValue = UUID.randomUUID().toString();
String keyFieldValue = UUID.randomUUID().toString();
String keyConditionValue = UUID.randomUUID().toString();
String keyName2Value = UUID.randomUUID().toString();
when(rep.countNrStepAttributes(idStep, "key_field")).thenReturn(1);
when(rep.getStepAttributeString(idStep, 0, "key_name")).thenReturn(keyNameValue);
when(rep.getStepAttributeString(idStep, 0, "key_field")).thenReturn(keyFieldValue);
when(rep.getStepAttributeString(idStep, 0, "key_condition")).thenReturn(keyConditionValue);
when(rep.getStepAttributeString(idStep, 0, "key_name2")).thenReturn(keyName2Value);
deleteMeta.readRep(rep, metaStore, idStep, databases);
assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyStream")).length);
assertEquals(keyNameValue, ((String[]) getInternalState(deleteMeta, "keyStream"))[0]);
assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyLookup")).length);
assertEquals(keyFieldValue, ((String[]) getInternalState(deleteMeta, "keyLookup"))[0]);
assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyCondition")).length);
assertEquals(keyConditionValue, ((String[]) getInternalState(deleteMeta, "keyCondition"))[0]);
assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyStream2")).length);
assertEquals(keyName2Value, ((String[]) getInternalState(deleteMeta, "keyStream2"))[0]);
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class BaseStreamStepMeta method check.
public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
long duration = Long.MIN_VALUE;
try {
duration = Long.parseLong(space.environmentSubstitute(getBatchDuration()));
} catch (NumberFormatException e) {
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, NOT_A_NUMBER, "Duration"), stepMeta));
}
long size = Long.MIN_VALUE;
try {
size = Long.parseLong(space.environmentSubstitute(getBatchSize()));
} catch (NumberFormatException e) {
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, NOT_A_NUMBER, "Number of records"), stepMeta));
}
if (duration == 0 && size == 0) {
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.NoBatchDefined"), stepMeta));
}
try {
int prefetch = Integer.parseInt(space.environmentSubstitute(getPrefetchCount()));
if (prefetch <= 0) {
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.PrefetchZeroOrLess", prefetch, size), stepMeta));
}
if (prefetch < size) {
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.PrefetchLessThanBatch", prefetch, size), stepMeta));
}
} catch (NumberFormatException e) {
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, NOT_A_NUMBER, "Message prefetch limit"), stepMeta));
}
try {
TransMeta subMeta = mappingMetaRetriever.get(this, repository, metaStore, space);
if (!StringUtil.isEmpty(getSubStep())) {
String realSubStepName = space.environmentSubstitute(getSubStep());
if (!subMeta.getSteps().stream().anyMatch(subStepMeta -> subStepMeta.getName().equals(realSubStepName))) {
remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.ResultStepMissing", subMeta.getName(), realSubStepName), stepMeta));
}
}
} catch (KettleException e) {
getLog().logDebug("Error loading subtrans meta", e);
}
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class SystemDataMetaTest method testLoadXML.
@Test
public void testLoadXML() throws Exception {
SystemDataMeta systemDataMeta = new SystemDataMeta();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new InputSource(new StringReader(expectedXML)));
Node node = document;
IMetaStore store = null;
systemDataMeta.loadXML(node, null, store);
assertEquals(expectedSystemDataMeta, systemDataMeta);
}
Aggregations