Search in sources :

Example 21 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class SelectTest method context_that_needs_to_be_encoded.

@Test
public void context_that_needs_to_be_encoded() throws Exception {
    ValueEncoderSource valueEncoderSource = mockValueEncoderSource();
    TypeCoercer typeCoercer = getService(TypeCoercer.class);
    ContextValueEncoder contextValueEncoder = new ContextValueEncoderImpl(valueEncoderSource);
    ValueEncoder<Platform> platformEncoder = new ValueEncoder<SelectTest.Platform>() {

        @Override
        public Platform toValue(String clientValue) {
            return Platform.valueOf(clientValue.substring(10));
        }

        @Override
        public String toClient(Platform value) {
            return "Platform: " + value.name();
        }
    };
    InternalComponentResources resources = mockInternalComponentResources();
    expect(valueEncoderSource.getValueEncoder(Platform.class)).andReturn(platformEncoder).anyTimes();
    expect(valueEncoderSource.getValueEncoder(String.class)).andReturn(new StringValueEncoder()).anyTimes();
    expect(resources.triggerContextEvent(EasyMock.eq(EventConstants.VALUE_CHANGED), eqEventContext(null, Platform.LINUX), EasyMock.isA(ComponentEventCallback.class))).andReturn(true);
    Select select = new Select();
    set(select, "resources", resources);
    set(select, "encoder", new StringValueEncoder());
    set(select, "typeCoercer", typeCoercer);
    replay();
    select.onChange(new URLEventContext(contextValueEncoder, new String[] { platformEncoder.toClient(Platform.LINUX) }), null);
    verify();
}
Also used : Platform(org.apache.tapestry5.corelib.components.SelectTest.Platform) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) EnumValueEncoder(org.apache.tapestry5.util.EnumValueEncoder) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) URLEventContext(org.apache.tapestry5.internal.URLEventContext) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) ContextValueEncoderImpl(org.apache.tapestry5.internal.services.ContextValueEncoderImpl) Test(org.testng.annotations.Test)

Example 22 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class EmptyGrid method getModel.

public BeanModel getModel() {
    BeanModel<Object> model = beanModelSource.createDisplayModel(Object.class, messages);
    model.add("random", new PropertyConduit() {

        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
            return null;
        }

        public void set(Object instance, Object value) {
            throw new UnsupportedOperationException();
        }

        public Class getPropertyType() {
            return Long.class;
        }

        public Type getPropertyGenericType() {
            return Long.class;
        }

        public Object get(Object instance) {
            return random.nextLong();
        }
    });
    return model;
}
Also used : Type(java.lang.reflect.Type) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit)

Example 23 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class PersistentFieldBundleImplTest method get_nested_component_value.

@Test
public void get_nested_component_value() {
    String value = "FIELD-VALUE";
    PersistentFieldChange change = new PersistentFieldChangeImpl("foo.bar", "field", value);
    Collection<PersistentFieldChange> changes = Arrays.asList(change);
    PersistentFieldBundle bundle = new PersistentFieldBundleImpl(changes);
    assertTrue(bundle.containsValue("foo.bar", "field"));
    assertSame(bundle.getValue("foo.bar", "field"), value);
    assertFalse(bundle.containsValue("foo.bar", "other"));
}
Also used : PersistentFieldBundle(org.apache.tapestry5.services.PersistentFieldBundle) PersistentFieldChange(org.apache.tapestry5.services.PersistentFieldChange) Test(org.testng.annotations.Test)

Example 24 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class PersistentFieldBundleImplTest method get_root_component_value.

@Test
public void get_root_component_value() {
    String value = "FIELD-VALUE";
    PersistentFieldChange change = new PersistentFieldChangeImpl("", "field", value);
    Collection<PersistentFieldChange> changes = Arrays.asList(change);
    PersistentFieldBundle bundle = new PersistentFieldBundleImpl(changes);
    assertTrue(bundle.containsValue("", "field"));
    assertTrue(bundle.containsValue(null, "field"));
    assertSame(bundle.getValue("", "field"), value);
    assertSame(bundle.getValue(null, "field"), value);
    assertFalse(bundle.containsValue("", "other"));
    assertFalse(bundle.containsValue(null, "other"));
}
Also used : PersistentFieldBundle(org.apache.tapestry5.services.PersistentFieldBundle) PersistentFieldChange(org.apache.tapestry5.services.PersistentFieldChange) Test(org.testng.annotations.Test)

Example 25 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class PersistentFieldManagerImplTest method post_change_strategy_by_meta_data.

@Test
public void post_change_strategy_by_meta_data() {
    String pageName = "foo.Bar";
    String nestedId = "nested";
    String fieldName = "field";
    String strategyName = "foo";
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    PersistentFieldStrategy strat = newPersistentFieldStrategy();
    MetaDataLocator locator = mockMetaDataLocator();
    Object value = new Object();
    Map<String, PersistentFieldStrategy> strategies = newMap();
    strategies.put(strategyName, strat);
    train_getComponentModel(resources, model);
    train_getFieldPersistenceStrategy(model, fieldName, "");
    train_findMeta(locator, SymbolConstants.PERSISTENCE_STRATEGY, resources, String.class, strategyName);
    train_getNestedId(resources, nestedId);
    strat.postChange(pageName, nestedId, fieldName, value);
    replay();
    PersistentFieldManager manager = new PersistentFieldManagerImpl(locator, strategies);
    manager.postChange(pageName, resources, fieldName, value);
    verify();
}
Also used : PersistentFieldStrategy(org.apache.tapestry5.services.PersistentFieldStrategy) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)83 ComponentResources (org.apache.tapestry5.ComponentResources)30 ComponentModel (org.apache.tapestry5.model.ComponentModel)16 MarkupWriter (org.apache.tapestry5.MarkupWriter)13 Field (org.apache.tapestry5.Field)12 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)11 Location (org.apache.tapestry5.commons.Location)11 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)11 Type (org.apache.tapestry5.internal.plastic.asm.Type)11 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)11 Messages (org.apache.tapestry5.commons.Messages)10 JSONObject (org.apache.tapestry5.json.JSONObject)10 Request (org.apache.tapestry5.http.services.Request)9 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)8 Link (org.apache.tapestry5.http.Link)8 Binding (org.apache.tapestry5.Binding)7 ValidationException (org.apache.tapestry5.ValidationException)7 InternalPropertyConduit (org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)7