use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.
the class JavaSnippetTemplate method loadSettings.
/**
* Loads parameters.
* @param settings to load from
*/
@Override
public void loadSettings(final NodeSettingsRO settings) {
try {
String metaCategory = settings.getString(META_CATEGORY, null);
m_metaCategory = getMetaCategoryClass(metaCategory);
m_category = settings.getString(CATEGORY, "default");
m_name = settings.getString(NAME, "?");
m_description = settings.getString(DESCRIPTION, "");
m_version = settings.getString(m_version, JavaSnippetTemplate.VERSION_1_X);
NodeSettingsRO snippet = settings.getNodeSettings(SNIPPET);
m_snippetSettings = new JavaSnippetSettings();
m_snippetSettings.loadSettingsForDialog(snippet);
m_uuid = m_snippetSettings.getTemplateUUID();
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
} catch (InvalidSettingsException e) {
throw new IllegalStateException(e);
}
}
use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.
the class JavaSnippetTest method testSimpleSnippet.
/**
* Test execution of a simple java snippet.
* @throws Exception
*/
@Test
public void testSimpleSnippet() throws Exception {
final JavaSnippetSettings settings = new JavaSnippetSettings("throw new Abort(\"success\");");
snippet.setSettings(settings);
final AbstractJSnippet s = snippet.createSnippetInstance();
assertNotNull(s);
try {
s.snippet();
fail("Expected exception to be thrown by snippet");
} catch (Abort e) {
if (!e.getMessage().equals("success")) {
throw e;
}
}
}
use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.
the class JavaEditVarNodeModel method validateSettings.
/**
* {@inheritDoc}
*/
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
JavaSnippetSettings s = new JavaSnippetSettings();
s.loadSettings(settings);
// TODO: Check settings
}
use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.
the class JavaSnippetTest method testAdditionalBundles.
/**
* Test compiling with additional eclipse/osgi bundles.
* @throws Exception
*/
@Test
public void testAdditionalBundles() throws Exception {
final JavaSnippetSettings settings = new JavaSnippetSettings("new Complex(1.0, 1.0);");
settings.setBundles(new String[] { "org.apache.commons.math3" });
settings.setScriptImports("import org.apache.commons.math3.complex.Complex;");
snippet.setSettings(settings);
final AbstractJSnippet s = snippet.createSnippetInstance();
assertNotNull(s);
s.snippet();
}
use of org.knime.base.node.jsnippet.util.JavaSnippetSettings in project knime-core by knime.
the class JavaSnippetTest method testEncoding.
/**
* Test encoding.
* @throws Exception
*/
@Test
public void testEncoding() throws Exception {
final JavaSnippetSettings settings = new JavaSnippetSettings("outString = \"���\";");
final OutCol outCol = new OutCol();
outCol.setJavaName("outString");
outCol.setConverterFactory(ConverterUtil.getConverterFactory(String.class, StringCell.TYPE).get());
settings.getJavaSnippetFields().getOutColFields().add(outCol);
snippet.setSettings(settings);
final AbstractJSnippet s = snippet.createSnippetInstance();
assertNotNull(s);
s.snippet();
final Field outStringField = s.getClass().getField("outString");
final String string = (String) outStringField.get(s);
assertEquals(string, "���");
}
Aggregations