@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);
  }
예제 #3
0
  @Test
  public void testNullValue() {
    Value value = TextType.get().nullValue();

    String xml = xstream.toXML(value);
    Value unmarshalled = (Value) xstream.fromXML(xml);

    assertThat(value).isEqualTo(unmarshalled);
    assertThat(unmarshalled.isNull()).isTrue();
  }
예제 #4
0
 /**
  * Convert the value as loaded from the SQL table into the expected variable value type (column
  * type may not match exactly the variable value type).
  *
  * @param variable
  * @param value
  * @return
  */
 private Value convertValue(Variable variable, Value value) {
   if (value.getValueType() != variable.getValueType()) {
     return variable.isRepeatable()
         ? convertToSequence(variable, value)
         : variable.getValueType().convert(value);
   }
   if (variable.isRepeatable() && !value.isSequence()) {
     return convertToSequence(variable, value);
   }
   return value;
 }
  @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);
  }
 private void add(@NotNull Value value) {
   Assert.notNull(value, "Value cannot be null");
   if (summary.empty) summary.empty = false;
   if (value.isSequence()) {
     if (value.isNull()) {
       summary.frequencyDist.addValue(NULL_NAME);
     } else {
       //noinspection ConstantConditions
       for (Value v : value.asSequence().getValue()) {
         add(v);
       }
     }
   } else {
     summary.frequencyDist.addValue(value.isNull() ? NULL_NAME : value.toString());
   }
 }
예제 #7
0
 private Value convertToSequence(Variable variable, Value value) {
   return value.isNull()
       ? variable.getValueType().nullSequence()
       : variable.getValueType().sequenceOf(value.toString());
 }