Skip to main content
summaryrefslogtreecommitdiffstats
blob: 793745c18dc871072093e98e8facdda3bb20fda2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*******************************************************************************
 * Copyright (c) 2001, 2008 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.validation.el.tests.jsp;

import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jdt.core.Signature;
import org.eclipse.jst.jsf.common.internal.types.TypeConstants;
import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver;
import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory;
import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContextFactory;
import org.eclipse.jst.jsf.core.JSFVersion;
import org.eclipse.jst.jsf.core.internal.tld.IJSFConstants;
import org.eclipse.jst.jsf.core.internal.tld.ITLDConstants;
import org.eclipse.jst.jsf.core.tests.util.JSFCoreUtilHelper;
import org.eclipse.jst.jsf.core.tests.validation.MockValidationReporter.ReportedProblem;
import org.eclipse.jst.jsf.metadataprocessors.MetaDataEnabledProcessingFactory;
import org.eclipse.jst.jsf.metadataprocessors.features.IValidValues;
import org.eclipse.jst.jsf.test.util.TestFileResource;
import org.eclipse.jst.jsf.validation.el.tests.ELValidationTestPlugin;
import org.eclipse.jst.jsf.validation.el.tests.base.ELAssert;
import org.eclipse.jst.jsf.validation.el.tests.base.SingleJSPTestCase;
import org.eclipse.jst.jsf.validation.internal.el.diagnostics.DiagnosticFactory;
import org.w3c.dom.Attr;

/**
 * Test cases for load bundle resolution
 * 
 * @author cbateman
 */
public class LoadBundleResolutionTestCase extends SingleJSPTestCase
{
    public LoadBundleResolutionTestCase()
    {
        super("/testdata/jsps/loadBundleResolution.jsp.data", "/loadBundleResolution.jsp", JSFVersion.V1_1,FACES_CONFIG_FILE_NAME_1_1);
    }

    @Override
    protected void setUp() throws Exception
    {
        super.setUp();

        // add a resource bundle to the default package to test regression on bug 144525
        final TestFileResource resource = new TestFileResource();
        resource.load(ELValidationTestPlugin.getDefault().getBundle(),
        "/testdata/classes/Bundle.properties.data");
        _jdtTestEnv.addResourceFile("src", new ByteArrayInputStream(resource.toBytes()),
                "", "Bundle.properties");
        JSFCoreUtilHelper.injectTestTagRegistryFactoryProvider(JSFCoreUtilHelper.createSimpleRegistryFactory());

    }

    @Override
    protected void tearDown() throws Exception
    {
        super.tearDown();
        JSFCoreUtilHelper.injectTestTagRegistryFactoryProvider(null);
    }

    @Override
    public void testSanity()
    {
        assertEquals("bundle.bundleProp2", ELAssert.getELText(_structuredDocument,1003));
        assertEquals("noPackageBundle.bundleProp2", ELAssert.getELText(_structuredDocument,1051));
        assertEquals("bundle.bundleProp1 && myBean.stringProperty", ELAssert.getELText(_structuredDocument,1111));
        assertEquals("empty bundle", ELAssert.getELText(_structuredDocument,1187));
        assertEquals("empty bundle.bundleProp2", ELAssert.getELText(_structuredDocument,1232));
        assertEquals("bundle.bundleProp2 + 5", ELAssert.getELText(_structuredDocument,1289));
        assertEquals("bundleProp2", ELAssert.getELText(_structuredDocument,1341));
        assertEquals("bundle.x.y", ELAssert.getELText(_structuredDocument,1382));
        assertEquals("noPackageBundle.x.y", ELAssert.getELText(_structuredDocument,1422));

        assertEquals("-bundle.bundleProp1", ELAssert.getELText(_structuredDocument,1496));
        assertEquals("bundle.bundleProp3", ELAssert.getELText(_structuredDocument,1548));
        assertEquals("msg", ELAssert.getELText(_structuredDocument,1599));
        assertEquals("bundle.x", ELAssert.getELText(_structuredDocument,1635));
        assertEquals("noPackageBundle.notAProperty", ELAssert.getELText(_structuredDocument,1673));
    }

    @Override
    public void testNoErrorExprs()
    {
        assertNoError(1003, TypeConstants.TYPE_STRING);
        assertNoError(1051, TypeConstants.TYPE_STRING);
        assertNoError(1111, Signature.SIG_BOOLEAN);
        assertNoError(1187, Signature.SIG_BOOLEAN);
        assertNoError(1232, Signature.SIG_BOOLEAN);
        assertNoError(1289, Signature.SIG_LONG);
        //assertNoError(1341, TypeConstants.TYPE_STRING);
        assertNoError(1382, TypeConstants.TYPE_STRING);
        // see  https://bugs.eclipse.org/bugs/show_bug.cgi?id=190671
        assertNoError(1422, TypeConstants.TYPE_STRING);
    }

    @Override
    public void testWarningExprs()
    {
        List<ReportedProblem> list = assertSemanticWarning(1496, Signature.SIG_LONG, 1);
        ELAssert.assertContainsProblem(list, DiagnosticFactory.UNARY_OP_STRING_CONVERSION_NOT_GUARANTEED_ID);

        list = assertSemanticWarning(1548, null, 1);
        ELAssert.assertContainsProblem(list, DiagnosticFactory.MEMBER_NOT_FOUND_ID);

        // ensure that we are validating that the basename for the missing bundle
        // is being validated since the related variable will not be flagged
        // this check replaces a previous check at 1640 for a variable not
        // found warning. Rather than marking loadBundle variables bad when
        // we can't find the variable, we now mark the basename bad instead
        // of the variable
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=190671
        ensureMissingBundleValidation();

        list = assertSemanticWarning(1635, null, 1);
        ELAssert.assertContainsProblem(list, DiagnosticFactory.MEMBER_IS_INTERMEDIATE_ID);

        list = assertSemanticWarning(1673, null, 1);
        ELAssert.assertContainsProblem(list, DiagnosticFactory.MEMBER_NOT_FOUND_ID);
    }

    @Override
    public void testErrorExprs()
    {
        // no error
    }


    private void ensureMissingBundleValidation()
    {
        final IStructuredDocumentContext context =
            IStructuredDocumentContextFactory.INSTANCE.getContext(_structuredDocument, 839);

        final IDOMContextResolver contextResolver =
            IStructuredDocumentContextResolverFactory.INSTANCE.getDOMContextResolver(context);

        final Attr attr = (Attr) contextResolver.getNode();
        String attributeVal = attr.getValue();
        assertEquals("TestMessages", attributeVal);
        assertEquals(IJSFConstants.ATTR_BASENAME, attr.getLocalName());

        // verify that attribute value validation is picking up on missing bundles
        final List<?> vv =
            MetaDataEnabledProcessingFactory.getInstance()
            .getAttributeValueRuntimeTypeFeatureProcessors
            (IValidValues.class, context, ITLDConstants.URI_JSF_CORE
                    , IJSFConstants.TAG_LOADBUNDLE, IJSFConstants.ATTR_BASENAME);

        boolean validatesMissingBundle = false;

        for (final Iterator<?> it = vv.iterator();it.hasNext();)
        {
            final IValidValues v = (IValidValues)it.next();
            if (attributeVal == null)
            {
                attributeVal = "";//ensure to be non-null
            }
            if (!v.isValidValue(attributeVal.trim())){
                if (v.getValidationMessages().size() > 0)
                {
                    validatesMissingBundle = true;
                    break;
                }
            }
        }

        assertTrue(validatesMissingBundle);
    }
}

Back to the top