/** Test if errors with expressions also set the error flag on the node. */ public void testExpressionError() { Node n = numberNode.newInstance(testLibrary, "number1"); n.setExpression("value", "***"); try { n.update(); fail("Should have caused an exception."); } catch (ProcessingError e) { assertTrue(e.getCause().toString().toLowerCase().contains("cannot compile expression")); assertTrue(n.hasError()); // As stated in Node#update(ProcessingContext), even if an error occurred the node is still // marked as clean // and events are fired. It is important to mark the node as clean so that subsequent changes // to the node // mark it as dirty, triggering an event. This allows you to fix the cause of the error in the // node. assertFalse(n.isDirty()); assertNull(n.getOutputValue()); } n.setExpression("value", "10 + 1"); assertTrue(n.isDirty()); n.update(); assertFalse(n.hasError()); assertFalse(n.isDirty()); assertEquals(11, n.getOutputValue()); }
/** This is the same test as ParameterTest#testExpressionDependencies, but at the Node level. */ public void testRemoveExpressionDependency() { Node net = testNetworkNode.newInstance(testLibrary, "net"); Node number1 = net.create(numberNode); number1.addParameter("bob", Parameter.Type.INT, 10); number1.setExpression("value", "bob"); number1.setRendered(); net.update(); assertEquals(10, net.getOutputValue()); number1.removeParameter("bob"); try { net.update(); fail(); } catch (ProcessingError e) { assertTrue(e.getCause().getMessage().toLowerCase().contains("cannot evaluate expression")); } assertTrue(net.hasError()); assertTrue(number1.hasError()); assertNull(net.getOutputValue()); }