Package org.springframework.binding.support

Examples of org.springframework.binding.support.TestBean


    /**
     * Tests read actions on a read-only model.
     */
    public void testReadOnly() {
        TestBean bean = new TestBean();
        ValueModel readOnlyModel = new BeanPropertyAccessStrategy(bean).getPropertyValueModel("readOnly");
        BufferedValueModel buffer = new BufferedValueModel(readOnlyModel, commitTrigger);
       
        assertSame(
            "Can read values from a read-only model.",
            buffer.getValue(),
            readOnlyModel.getValue());
       
        Object newValue1 = "new value";
        buffer.setValue(newValue1);
        assertSame(
            "Can read values from a read-only model when buffering.",
            buffer.getValue(),
            newValue1);
       
        revert();
        assertSame(
            "Can read values from a read-only model after a flush.",
            buffer.getValue(),
            bean.getReadOnly());
       
        buffer.setValue("new value2");
        try {
            commit();
            fail("Cannot commit to a read-only model.");
View Full Code Here


    /**
     * Test to ensure that the AccessStrategy works correctly with writeable/readable properties.     *
     */
    public void testReadOnlyPropertyAccess()
    {
        AbstractFormModel model = getFormModel(new TestBean());
        PropertyAccessStrategy propertyAccessStrategy = model.getPropertyAccessStrategy();
        PropertyMetadataAccessStrategy metaDataAccessStrategy = propertyAccessStrategy.getMetadataAccessStrategy();

        assertFalse("Property is readonly, isWriteable() should return false.", metaDataAccessStrategy.isWriteable("readOnly"));
        assertTrue("Property is readonly, isReadable() should return true.", metaDataAccessStrategy.isReadable("readOnly"));
View Full Code Here

    private JFormattedTextField ftc;

    private FormattedTextFieldBinding b;
   
    protected TestBean createTestBean() {
        TestBean testBean = super.createTestBean();
        testBean.setNumberProperty(initialValue);
        return testBean;
    }
View Full Code Here

        property = setUpBinding();
        vm = fm.getValueModel(property);
    }

    protected TestBean createTestBean() {
        return new TestBean();
    }
View Full Code Here

  protected AbstractFormModel getFormModel(ValueModel valueModel, boolean buffering) {
    return new TestAbstractFormModel(valueModel, buffering);
  }

  public void testGetValueModelFromPAS() {
    TestBean p = new TestBean();
    TestPropertyAccessStrategy tpas = new TestPropertyAccessStrategy(p);
    AbstractFormModel fm = getFormModel(tpas, true);
    ValueModel vm1 = fm.getValueModel("simpleProperty");
    assertEquals(1, tpas.numValueModelRequests());
    assertEquals("simpleProperty", tpas.lastRequestedValueModel());
View Full Code Here

      // exprected
    }
  }

  public void testUnbufferedWritesThrough() {
    TestBean p = new TestBean();
    BeanPropertyAccessStrategy pas = new BeanPropertyAccessStrategy(p);
    AbstractFormModel fm = getFormModel(pas, false);
    ValueModel vm = fm.getValueModel("simpleProperty");

    vm.setValue("1");
    assertEquals("1", p.getSimpleProperty());

    vm.setValue(null);
    assertEquals(null, p.getSimpleProperty());
  }
View Full Code Here

    vm.setValue(null);
    assertEquals(null, p.getSimpleProperty());
  }

  public void testBufferedDoesNotWriteThrough() {
    TestBean p = new TestBean();
    BeanPropertyAccessStrategy pas = new BeanPropertyAccessStrategy(p);
    AbstractFormModel fm = getFormModel(pas, true);
    ValueModel vm = fm.getValueModel("simpleProperty");

    vm.setValue("1");
    assertEquals(null, p.getSimpleProperty());

    vm.setValue(null);
    assertEquals(null, p.getSimpleProperty());
  }
View Full Code Here

  public void testDirtyTrackingWithoutBuffering() {
    testDirtyTracking(false);
  }

  public void testDirtyTracking(boolean buffering) {
    TestBean p = new TestBean();
    BeanPropertyAccessStrategy pas = new BeanPropertyAccessStrategy(p);
    TestPropertyChangeListener pcl = new TestPropertyChangeListener(FormModel.DIRTY_PROPERTY);
    AbstractFormModel fm = getFormModel(pas, buffering);
    fm.addPropertyChangeListener(FormModel.DIRTY_PROPERTY, pcl);
    ValueModel vm = fm.getValueModel("simpleProperty");
    assertTrue(!fm.isDirty());

    vm.setValue("2");
    assertTrue(fm.isDirty());
    assertEquals(1, pcl.eventCount());

    fm.commit();
    assertTrue(!fm.isDirty());
    assertEquals(2, pcl.eventCount());

    vm.setValue("1");
    assertTrue(fm.isDirty());
    assertEquals(3, pcl.eventCount());

    fm.setFormObject(new TestBean());
    assertTrue(!fm.isDirty());
    assertEquals(4, pcl.eventCount());

    vm.setValue("2");
    assertTrue(fm.isDirty());
View Full Code Here

   * parent should also be dirty. When parent reverts, child should revert
   * too.
   */
  public void testDirtyTracksKids() {
    TestPropertyChangeListener pcl = new TestPropertyChangeListener(FormModel.DIRTY_PROPERTY);
    AbstractFormModel pfm = getFormModel(new TestBean());
    AbstractFormModel fm = getFormModel(new TestBean());
    pfm.addPropertyChangeListener(FormModel.DIRTY_PROPERTY, pcl);
    pfm.addChild(fm);
    ValueModel childSimpleProperty = fm.getValueModel("simpleProperty");
    ValueModel parentSimpleProperty = pfm.getValueModel("simpleProperty");
    // test child property dirty -> parent dirty
View Full Code Here

    assertTrue(!pfm.isDirty());
    assertEquals(6, pcl.eventCount());
  }

  public void testSetFormObjectDoesNotRevertChangesToPreviousFormObject() {
    TestBean p1 = new TestBean();
    BeanPropertyAccessStrategy pas = new BeanPropertyAccessStrategy(p1);
    AbstractFormModel fm = getFormModel(pas, false);
    fm.getValueModel("simpleProperty").setValue("1");
    fm.setFormObject(new TestBean());
    assertEquals("1", p1.getSimpleProperty());
  }
View Full Code Here

TOP

Related Classes of org.springframework.binding.support.TestBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.