MYFACESTEST-53: MockApplication12 elResolver cannot interpret EL reserved words. Thx to Matt Benson
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java b/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java
new file mode 100644
index 0000000..4e75881
--- /dev/null
+++ b/test12/src/main/java/org/apache/myfaces/test/el/ReservedWordsELResolver.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.test.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.PropertyNotWritableException;
+
+/**
+ * {@code ELResolver} for reserved words.
+ */
+public class ReservedWordsELResolver extends AbstractELResolver {
+ private static final Map<String, Object> VALUES;
+ static {
+ HashMap<String, Object> values = new HashMap<String, Object>();
+ values.put("true", Boolean.TRUE);
+ values.put("false", Boolean.FALSE);
+ values.put("null", null);
+ VALUES = Collections.unmodifiableMap(values);
+ }
+
+ private List<FeatureDescriptor> featureDescriptors;
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ return VALUES.get(property);
+ }
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ Object value = VALUES.get(property);
+ return value == null ? null : value.getClass();
+ }
+ return null;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property,
+ Object value) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ throw new PropertyNotWritableException(property.toString());
+ }
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ if (base == null && VALUES.containsKey(property)) {
+ context.setPropertyResolved(true);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized Iterator<FeatureDescriptor> getFeatureDescriptors(
+ ELContext context, Object base) {
+ if (featureDescriptors == null) {
+ featureDescriptors = new ArrayList<FeatureDescriptor>();
+ for (Map.Entry<String, Object> e : VALUES.entrySet()) {
+ final Class<?> type =
+ e.getValue() == null ? null : e.getValue().getClass();
+ featureDescriptors.add(descriptor(e.getKey(), e.getKey(),
+ e.getKey(), false, false, true, type, true));
+ }
+ featureDescriptors =
+ Collections.unmodifiableList(featureDescriptors);
+ }
+ return featureDescriptors.iterator();
+ }
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return base == null ? String.class : null;
+ }
+
+}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
index b2ac06d..30d60d8 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
@@ -48,6 +48,7 @@
import org.apache.myfaces.test.el.FacesScopedAttributeELResolver;
import org.apache.myfaces.test.el.FacesVariableResolverChainWrapper;
import org.apache.myfaces.test.el.MockExpressionFactory;
+import org.apache.myfaces.test.el.ReservedWordsELResolver;
/**
* <p>Mock implementation of <code>Application</code> that includes the semantics
@@ -237,6 +238,7 @@
composite.add(new ArrayELResolver());
composite.add(new BeanELResolver());
composite.add(new FacesScopedAttributeELResolver());
+ composite.add(new ReservedWordsELResolver());
// Make the resolver we have configured the application wide one
resolver = composite;
diff --git a/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java b/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java
new file mode 100644
index 0000000..d8d0d00
--- /dev/null
+++ b/test12/src/test/java/org/apache/myfaces/test/el/ReservedWordsELResolverTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.test.el;
+
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+
+import javax.el.ELContext;
+
+/**
+ * @author Matt Benson
+ */
+public class ReservedWordsELResolverTest extends AbstractJsfTestCase {
+
+ /**
+ * <p>Construct a new instance of this test case.</p>
+ *
+ * @param name Name of this test case
+ */
+ public ReservedWordsELResolverTest(String name) {
+ super(name);
+ }
+
+ public void testGetReservedWords() {
+ ELContext elContext = facesContext.getELContext();
+ assertEquals(Boolean.TRUE, application.getExpressionFactory()
+ .createValueExpression(elContext, "#{true}", Boolean.class)
+ .getValue(elContext));
+ assertEquals(Boolean.FALSE, application.getExpressionFactory()
+ .createValueExpression(elContext, "#{false}", Boolean.class)
+ .getValue(elContext));
+ assertNull(application.getExpressionFactory()
+ .createValueExpression(elContext, "#{null}", Object.class)
+ .getValue(elContext));
+ }
+}