Example #1
0
 /*
  * Test the getValue() method when the value of the expression is evaluated
  * by a previous call to getValue().
  */
 public void testGetValue_Evaluated() throws Exception {
   MockObject mo = new MockObject(false);
   Expression t = new Expression(mo, "method", new Object[0]);
   assertEquals("method1", t.getValue());
   MockObject.assertCalled("method1", new Object[0]);
   assertEquals("method1", t.getValue());
   MockObject.assertNotCalled();
 }
Example #2
0
 /*
  * Test the method getValue() with a normal object, the method name "new"
  * and valid arguments.
  */
 public void testGetValue_UnboundedNormalConstructor() throws Exception {
   Expression t = new Expression(MockObject.class, "new", new Object[0]);
   t.getValue();
   MockObject.assertCalled("new0", new Object[0]);
   t = new Expression(MockObject.class, "new", null);
   assertTrue(t.getValue() instanceof MockObject);
   MockObject.assertCalled("new0", new Object[0]);
 }
Example #3
0
 /*
  * Test the setValue() method when the value of the expression is set by the
  * constructor.
  */
 public void testSetValue_Constructor() throws Exception {
   MockObject mo = new MockObject(false);
   Expression t = new Expression(mo, mo, "method", new Object[0]);
   assertSame(mo, t.getValue());
   MockObject.assertNotCalled();
   t.setValue(null);
   assertSame(null, t.getValue());
   MockObject.assertNotCalled();
 }
 @Test
 public void testLessThan() {
   MockObject o = new MockObject();
   o.i = 5;
   coll.save(o);
   // Ensure that the serializer actually worked
   assertThat((Integer) coll.getDbCollection().findOne().get("i"), equalTo(15));
   assertThat(coll.find().lessThan("i", 12).toArray(), hasSize(1));
 }
Example #5
0
 /*
  * Test the method getValue() with a normal object, a valid method name and
  * valid arguments.
  */
 public void testGetValue_UnboundedNormalInstanceMethod() throws Exception {
   MockObject mo = new MockObject(false);
   Expression t = new Expression(mo, "method", new Object[0]);
   assertEquals("method1", t.getValue());
   MockObject.assertCalled("method1", new Object[0]);
   t = new Expression(mo, "method", null);
   assertEquals("method1", t.getValue());
   MockObject.assertCalled("method1", new Object[0]);
 }
  @Test
  public void testArrayEquals() {
    MockObject o = new MockObject();
    MockObject o1 = new MockObject();
    o1.id = new org.bson.types.ObjectId().toString();
    o.items = Arrays.asList(o1);
    coll.save(o);

    assertThat(coll.find().is("items", Arrays.asList(o1)).toArray(), hasSize(1));
  }
  @Test
  public void testAll() {
    MockObject o = new MockObject();
    MockObject o1 = new MockObject();
    o1.id = new org.bson.types.ObjectId().toString();
    o.items = Arrays.asList(o1);
    coll.save(o);

    // Ensure that the serializer actually worked
    assertThat(coll.find().all("items", o1).toArray(), hasSize(1));
  }
Example #8
0
  /*
   * Test the method getValue() with a normal object with overloaded methods
   * (primitive type VS wrapper class), a valid method name and valid
   * arguments.
   *
   * Note: decided by definition position!
   */
  public void testGetValue_UnboundedPrimitiveVSWrapper() throws Exception {
    MockObject mo = new MockObject(false);
    Object[] arguments = new Object[] {new Integer(1)};
    Expression t = new Expression(mo, "methodB", arguments);
    assertEquals("methodB2", t.getValue());
    MockObject.assertCalled("methodB2", arguments);

    arguments = new Object[] {Boolean.FALSE};
    t = new Expression(mo, "methodB", arguments);
    assertEquals("methodB3", t.getValue());
    MockObject.assertCalled("methodB3", arguments);
  }
Example #9
0
  /*
   * Test the method getValue() with a normal object, an overloaded method and
   * valid arguments.
   */
  public void testGetValue_UnboundedOverloadedMethods() throws Exception {
    MockObject mo = new MockObject(false);
    Object[] arguments = new Object[] {new Object()};
    Expression t = new Expression(mo, "method", arguments);
    assertEquals("method2", t.getValue());
    MockObject.assertCalled("method2", arguments);

    arguments = new Object[] {"test"};
    t = new Expression(mo, "method", arguments);
    assertEquals("method3", t.getValue());
    MockObject.assertCalled("method3", arguments);
  }
 @Test
 public void testAnd() {
   MockObject o = new MockObject();
   o.i = 5;
   coll.save(o);
   // Ensure that the serializer actually worked
   assertThat(
       coll.find().and(DBQuery.lessThan("i", 12), DBQuery.greaterThan("i", 4)).toArray(),
       hasSize(1));
   assertThat(
       coll.find().and(DBQuery.lessThan("i", 12), DBQuery.greaterThan("i", 9)).toArray(),
       hasSize(0));
 }
Example #11
0
 /*
  * Test the method getValue() with a normal object with void method name and
  * valid arguments.
  */
 public void testGetValue_UnboundedVoidMethod() throws Exception {
   MockObject mo = new MockObject(false);
   Object[] arguments = new Object[] {new Integer(1)};
   Expression t = new Expression(mo, "voidMethod", arguments);
   assertNull(t.getValue());
   MockObject.assertCalled("voidMethod2", arguments);
 }
Example #12
0
 /*
  * Test the method getValue() with an object, a static method name and valid
  * arguments.
  */
 public void testGetValue_UnboundedNormalStaticMethodViaObject() throws Exception {
   MockObject mo = new MockObject(false);
   Object[] arguments = new Object[] {new Object()};
   Expression t = new Expression(mo, "staticMethod", arguments);
   assertEquals("staticMethod", t.getValue());
   MockObject.assertCalled("staticMethod", arguments);
 }
Example #13
0
 /*
  * Test the setValue() method with a non-null value when the value of the
  * expression is still unbounded.
  */
 public void testSetValue_UnboundNormal() throws Exception {
   MockObject mo = new MockObject(false);
   Expression t = new Expression(mo, "method", new Object[0]);
   t.setValue(mo);
   assertSame(mo, t.getValue());
   MockObject.assertNotCalled();
 }
Example #14
0
  /*
   * Test the method getValue() with a Class object of a normal class that has
   * a method of the same signature as Class.forName(String), a static method
   * name "forName" and valid argument "string".
   */
  public void testGetValue_UnboundedAmbitiousStaticMethod() throws Exception {
    Object[] arguments = new Object[] {"test"};
    Expression t = new Expression(MockObject.class, "forName", arguments);
    assertNull(t.getValue());
    MockObject.assertCalled("forName", arguments);

    t = new Expression(String.class, "forName", new Object[] {"java.lang.String"});
    assertSame(String.class, t.getValue());
  }
Example #15
0
 /*
  * Test the method getValue() with a normal object, the method name "new"
  * that throws an exception and valid arguments.
  */
 public void testGetValue_UnboundedExceptionalConstructor() throws Exception {
   Expression t = new Expression(MockObject.class, "new", new Object[] {null, null});
   try {
     t.getValue();
     fail("Should throw NullPointerException!");
   } catch (NullPointerException ex) {
     // expected
   }
   MockObject.assertCalled("new4", new Object[] {null, null});
 }
Example #16
0
 /*
  * Test the method getValue() with a normal object, a valid method that
  * throws an exception and valid arguments.
  */
 public void testGetValue_UnboundedExceptionalMethod() throws Exception {
   MockObject mo = new MockObject(false);
   Expression t = new Expression(mo, "method", new Object[] {null, null});
   try {
     t.getValue();
     fail("Should throw NullPointerException!");
   } catch (NullPointerException ex) {
     // expected
   }
   MockObject.assertCalled("method4", new Object[] {null, null});
 }
  @Test
  public void testAddJsonMapValueAsNested() throws Exception {
    ScriptWrapper wrapper = new ScriptWrapper();
    wrapper.addLine("AddJsonMapValue $mockObject.mockString, key=k2, value=v2");

    // parse
    HulaExecutable parserResult = parseAndAssert(wrapper.toString());

    Map<String, String> values = new HashMap<String, String>();
    values.put("k1", "v1");
    MockObject mo1 = new MockObject();
    mo1.mockString = new Gson().toJson(values);

    // run
    HulaContext hctx = new HulaContext();
    hctx.setParameter("mockObject", mo1);
    evaluateBeanShell(parserResult, hctx);

    MockObject mo2 = (MockObject) hctx.getParameter("mockObject");

    Assert.assertEquals("invalid json", "{\"k1\":\"v1\",\"k2\":\"v2\"}", mo2.mockString);
  }
  public void testPropertyAccessors() {
    SpringBeanWrapper beanWrapper;
    MockObject object;
    HashMap map;
    String value;

    beanWrapper = new SpringBeanWrapper(beanFactory.assignBeanWrapper(object = new MockObject()));
    assertNull(beanWrapper.getPropertyValue("string"));
    assertNull(object.getString());

    beanWrapper.setPropertyValue("string", (value = "value"));
    assertEquals(value, beanWrapper.getPropertyValue("string"));
    assertEquals(value, object.getString());

    map = new HashMap();
    map.put("string", (value = "map"));

    beanWrapper.setPropertyValues(map);
    assertEquals(value, beanWrapper.getPropertyValue("string"));
    assertEquals(value, object.getString());

    try {
      beanWrapper.getPropertyValue("method-does-not-exist");
      fail("Failed to detect non-existant property");
    } catch (Exception e) {
    }

    map = new HashMap();
    map.put("method-does-not-exist", "value");
    try {

      beanWrapper.setPropertyValues(map);
      fail("Failed to detect non-existant property");
    } catch (Exception e) {
    }
  }
Example #19
0
  /*
   * Test the method getValue() with a normal object with overloaded
   * constructors, the method name "new" and valid arguments. See Java
   * Language Specification (15.11) for reference.
   *
   * Note: decided by definition position.
   */
  public void testGetValue_UnboundedOverloadedConstructors() throws Exception {
    Object[] arguments = new Object[] {new Object()};
    Expression t = new Expression(MockObject.class, "new", arguments);
    t.getValue();
    MockObject.assertCalled("new2", arguments);

    // FIXME: the following 2 commented assert cannot pass neither in RI nor in Harmony
    // (HARMONY-4392),
    // waiting for dev-list approval to fix Harmony implementation following spec
    arguments = new Object[] {"test"};
    t = new Expression(MockObject.class, "new", arguments);
    assertTrue(t.getValue() instanceof MockObject);
    //         MockObject.assertCalled("new3", arguments);

    arguments = new Object[] {new Integer(1)};
    t = new Expression(MockObject.class, "new", arguments);
    assertTrue(t.getValue() instanceof MockObject);
    //        MockObject.assertCalled("new1-2", arguments);
  }
 public boolean getResult(@MockParamBinding MockObject mockObject) {
   return mockObject.isValue();
 }