@Test public void test_OPAL_1110() { JavascriptValueSource source = new JavascriptValueSource(TextType.get(), "1"); source.initialise(); Value value = source.getValue(mockValueSet); assertThat(value.getValue()).isEqualTo("1"); }
@Test public void test_simple_script() { JavascriptValueSource source = new JavascriptValueSource(DecimalType.get(), "1"); source.initialise(); Value value = source.getValue(mockValueSet); assertThat(value.getValue()).isEqualTo(1d); }
@Test public void test_engine_method() { JavascriptValueSource source = new JavascriptValueSource(DateTimeType.get(), "now()"); source.initialise(); Value value = source.getValue(mockValueSet); assertThat(value).isNotNull(); assertThat(value.isNull()).isFalse(); assertThat(value.getValueType()).isEqualTo(DateTimeType.get()); Date dateValue = (Date) value.getValue(); // Make sure both dates are within 1 second of one-another assertThat(System.currentTimeMillis() - dateValue.getTime()).isLessThan(1000); }
@Test public void test_compile_error() { // Error is on second line of script String script = "var i = 1+1;\nERROR!"; JavascriptValueSource source = new JavascriptValueSource(IntegerType.get(), script); source.setScriptName("Bogus"); try { source.initialise(); source.getValue(null); fail("EvaluatorException was expected"); } catch (MagmaJsRuntimeException e) { assertThat(e.getCause() instanceof EvaluatorException); EvaluatorException cause = (EvaluatorException) e.getCause(); assertThat(cause.sourceName()).isEqualTo("Bogus"); assertThat(cause.lineNumber()).isEqualTo(2); assertThat(cause.lineSource()).isEqualTo("ERROR!"); } }