Search in sources :

Example 1 with Platform

use of org.apache.tapestry5.corelib.components.SelectTest.Platform 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 Platform

use of org.apache.tapestry5.corelib.components.SelectTest.Platform in project tapestry-5 by apache.

the class TemplateParserImplTest method just_HTML.

@Test
public void just_HTML() {
    Resource resource = getResource("justHTML.tml");
    ComponentTemplate template = getParser().parseTemplate(resource);
    assertSame(template.getResource(), resource);
    assertFalse(template.usesStrictMixinParameters());
    List<TemplateToken> tokens = template.getTokens();
    // They add up quick ...
    assertEquals(tokens.size(), 20);
    StartElementToken t0 = get(tokens, 0);
    // Spot check a few things ...
    assertEquals(t0.name, "html");
    assertEquals(t0.namespaceURI, "");
    checkLine(t0, 1);
    TextToken t1 = get(tokens, 1);
    // Concerned this may not work cross platform.
    assertEquals(t1.text, "\n    ");
    StartElementToken t2 = get(tokens, 2);
    assertEquals(t2.name, "head");
    checkLine(t2, 2);
    TextToken t5 = get(tokens, 5);
    assertEquals(t5.text, "title");
    checkLine(t5, 3);
    get(tokens, 6);
    StartElementToken t12 = get(tokens, 12);
    assertEquals(t12.name, "p");
    AttributeToken t13 = get(tokens, 13);
    assertEquals(t13.name, "class");
    assertEquals(t13.value, "important");
    assertEquals(t13.namespaceURI, "");
    TextToken t14 = get(tokens, 14);
    // Simplify the text, converting consecutive whitespace to just a single space.
    assertEquals(t14.text.replaceAll("\\s+", " ").trim(), "Tapestry rocks! Line 2");
    // Line number is the *start* line of the whole text block.
    checkLine(t14, 6);
}
Also used : Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) AbstractResource(org.apache.tapestry5.ioc.internal.util.AbstractResource) Test(org.testng.annotations.Test)

Example 3 with Platform

use of org.apache.tapestry5.corelib.components.SelectTest.Platform in project tapestry-5 by apache.

the class ModuleTargetAttribute method write.

@Override
protected ByteVector write(final ClassWriter classWriter, final byte[] code, final int codeLength, final int maxStack, final int maxLocals) {
    ByteVector byteVector = new ByteVector();
    byteVector.putShort(platform == null ? 0 : classWriter.newUTF8(platform));
    return byteVector;
}
Also used : ByteVector(org.apache.tapestry5.internal.plastic.asm.ByteVector)

Example 4 with Platform

use of org.apache.tapestry5.corelib.components.SelectTest.Platform in project tapestry-5 by apache.

the class SelectTest method checkSubmittedOption.

/**
 * Utility for testing the "secure" option with various values and model
 * states. This avoids a lot of redundant test setup code.
 *
 * @param withModel whether there should be a model to test against
 * @param secureOption which "secure" option to test
 * @param expectedError the expected error message, nor null if no error
 * @throws ValidationException
 */
private void checkSubmittedOption(boolean withModel, SecureOption secureOption, String expectedError) throws ValidationException {
    ValueEncoder<Platform> encoder = getService(ValueEncoderSource.class).getValueEncoder(Platform.class);
    ValidationTracker tracker = mockValidationTracker();
    Request request = mockRequest();
    Messages messages = mockMessages();
    FieldValidationSupport fvs = mockFieldValidationSupport();
    TypeCoercer typeCoercer = mockTypeCoercer();
    InternalComponentResources resources = mockInternalComponentResources();
    Binding selectModelBinding = mockBinding();
    expect(request.getParameter("xyz")).andReturn("MAC");
    expect(messages.contains(EasyMock.anyObject(String.class))).andReturn(false).anyTimes();
    expect(resources.getBinding("model")).andReturn(selectModelBinding);
    final Holder<SelectModel> modelHolder = Holder.create();
    expect(typeCoercer.coerce(EasyMock.or(EasyMock.isA(SelectModel.class), EasyMock.isNull()), EasyMock.eq(SelectModel.class))).andAnswer(new IAnswer<SelectModel>() {

        @Override
        public SelectModel answer() throws Throwable {
            return modelHolder.get();
        }
    });
    expect(selectModelBinding.get()).andAnswer(new IAnswer<SelectModel>() {

        @Override
        public SelectModel answer() throws Throwable {
            return modelHolder.get();
        }
    });
    Select select = new Select();
    tracker.recordInput(select, "MAC");
    // when not failing we will expect to call the fvs.validate method
    if (expectedError == null) {
        fvs.validate(Platform.MAC, resources, null);
    } else {
        tracker.recordError(EasyMock.eq(select), EasyMock.contains(expectedError));
    }
    replay();
    if (withModel) {
        modelHolder.put(new EnumSelectModel(Platform.class, messages));
    }
    set(select, "encoder", encoder);
    set(select, "model", modelHolder.get());
    set(select, "request", request);
    set(select, "secure", secureOption);
    // Disable BeanValidationContextSupport
    set(select, "beanValidationDisabled", true);
    set(select, "tracker", tracker);
    set(select, "fieldValidationSupport", fvs);
    set(select, "typeCoercer", typeCoercer);
    set(select, "resources", resources);
    select.processSubmission("xyz");
    if (expectedError == null) {
        assertEquals(get(select, "value"), Platform.MAC);
    }
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) Platform(org.apache.tapestry5.corelib.components.SelectTest.Platform) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) Request(org.apache.tapestry5.http.services.Request) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) EnumSelectModel(org.apache.tapestry5.util.EnumSelectModel) EnumSelectModel(org.apache.tapestry5.util.EnumSelectModel)

Aggregations

TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 Platform (org.apache.tapestry5.corelib.components.SelectTest.Platform)2 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)2 ValueEncoderSource (org.apache.tapestry5.services.ValueEncoderSource)2 Test (org.testng.annotations.Test)2 Messages (org.apache.tapestry5.commons.Messages)1 Resource (org.apache.tapestry5.commons.Resource)1 Request (org.apache.tapestry5.http.services.Request)1 URLEventContext (org.apache.tapestry5.internal.URLEventContext)1 ByteVector (org.apache.tapestry5.internal.plastic.asm.ByteVector)1 ContextValueEncoderImpl (org.apache.tapestry5.internal.services.ContextValueEncoderImpl)1 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)1 AbstractResource (org.apache.tapestry5.ioc.internal.util.AbstractResource)1 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)1 ContextValueEncoder (org.apache.tapestry5.services.ContextValueEncoder)1 EnumSelectModel (org.apache.tapestry5.util.EnumSelectModel)1 EnumValueEncoder (org.apache.tapestry5.util.EnumValueEncoder)1