Search in sources :

Example 1 with ValueEncoderSource

use of org.apache.tapestry5.services.ValueEncoderSource 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 2 with ValueEncoderSource

use of org.apache.tapestry5.services.ValueEncoderSource in project tapestry-5 by apache.

the class ContextValueEncoderImplTest method to_value.

@Test
public void to_value() {
    ValueEncoder valueEncoder = mockValueEncoder();
    ValueEncoderSource source = mockValueEncoderSource();
    Long value = 23L;
    String clientValue = "twentythree";
    train_getValueEncoder(source, Long.class, valueEncoder);
    train_toValue(valueEncoder, clientValue, value);
    replay();
    ContextValueEncoder cve = new ContextValueEncoderImpl(source);
    assertSame(cve.toValue(Long.class, clientValue), value);
    verify();
}
Also used : ValueEncoder(org.apache.tapestry5.ValueEncoder) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) Test(org.testng.annotations.Test)

Example 3 with ValueEncoderSource

use of org.apache.tapestry5.services.ValueEncoderSource in project tapestry-5 by apache.

the class ContextValueEncoderImplTest method to_client.

@Test
public void to_client() {
    ValueEncoder valueEncoder = mockValueEncoder();
    ValueEncoderSource source = mockValueEncoderSource();
    Long value = 23L;
    String encoded = "twentythree";
    train_getValueEncoder(source, Long.class, valueEncoder);
    train_toClient(valueEncoder, value, encoded);
    replay();
    ContextValueEncoder cve = new ContextValueEncoderImpl(source);
    assertSame(cve.toClient(value), encoded);
    verify();
}
Also used : ValueEncoder(org.apache.tapestry5.ValueEncoder) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) Test(org.testng.annotations.Test)

Aggregations

ContextValueEncoder (org.apache.tapestry5.services.ContextValueEncoder)3 ValueEncoderSource (org.apache.tapestry5.services.ValueEncoderSource)3 Test (org.testng.annotations.Test)3 ValueEncoder (org.apache.tapestry5.ValueEncoder)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 Platform (org.apache.tapestry5.corelib.components.SelectTest.Platform)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 URLEventContext (org.apache.tapestry5.internal.URLEventContext)1 ContextValueEncoderImpl (org.apache.tapestry5.internal.services.ContextValueEncoderImpl)1 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)1 EnumValueEncoder (org.apache.tapestry5.util.EnumValueEncoder)1