Skip to content

Commit

Permalink
EL 6.0 new tests (#1217)
Browse files Browse the repository at this point in the history
* Add a test for the new length property supported by ArrayElResolver

* Increment release target to 17 for EL TCK

* Add new test for RecordELResolver

* Code clean-up. No functional change.

* Add new test for method visibility

* Add tests for OptionalELResolver

* Code clean-up. No functional change.

* Fix test failure with Java 17

* Code clean-up - no functional change

* Remove unused code

getFeatureDescriptors() was remove in EL 6.0
  • Loading branch information
markt-asf authored Jan 29, 2024
1 parent 7f193f3 commit d3c0d07
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@
*/
package com.sun.ts.tests.common.el.api.resolver;

import java.beans.FeatureDescriptor;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;

import jakarta.el.ArrayELResolver;
import jakarta.el.BeanELResolver;
import jakarta.el.CompositeELResolver;
import jakarta.el.ELContext;
import jakarta.el.ELResolver;
import jakarta.el.ListELResolver;
import jakarta.el.MapELResolver;
import jakarta.el.MethodNotFoundException;
import jakarta.el.PropertyNotFoundException;
import jakarta.el.PropertyNotWritableException;
Expand Down Expand Up @@ -98,7 +92,7 @@ public static boolean testCompositeELResolver(ELContext elContext,

// getType()
elContext.setPropertyResolved(false);
Class type = compResolver.getType(elContext, null, "Bar");
Class<?> type = compResolver.getType(elContext, null, "Bar");
if (!elContext.isPropertyResolved()) {
buf.append("getType() did not resolve" + NL);
pass = false;
Expand Down Expand Up @@ -126,8 +120,7 @@ public static boolean testCompositeELResolver(ELContext elContext,

// getCommonPropertyType()
elContext.setPropertyResolved(false);
Class commonPropertyType = (compResolver.getCommonPropertyType(elContext,
null));
Class<?> commonPropertyType = (compResolver.getCommonPropertyType(elContext, null));
buf.append("getCommonPropertyType() returns ");
buf.append(commonPropertyType.getName() + NL);

Expand Down Expand Up @@ -172,7 +165,7 @@ public static boolean testELResolver(ELContext elContext, ELResolver resolver,
pass = false;
}

if (!readOnly && valueRetrieved != value) {
if (!readOnly && !Objects.equals(valueRetrieved, value)) {
if (valueRetrieved == null) {
buf.append("null value returned from getValue() method call!" + NL);
pass = false;
Expand All @@ -192,7 +185,7 @@ public static boolean testELResolver(ELContext elContext, ELResolver resolver,

// getType()
elContext.setPropertyResolved(false);
Class type = resolver.getType(elContext, base, property);
Class<?> type = resolver.getType(elContext, base, property);
if (!elContext.isPropertyResolved()) {
buf.append("getType() did not resolve" + NL);
pass = false;
Expand Down Expand Up @@ -229,8 +222,7 @@ public static boolean testELResolver(ELContext elContext, ELResolver resolver,

// getCommonPropertyType()
elContext.setPropertyResolved(false);
Class commonPropertyType = (resolver.getCommonPropertyType(elContext,
base));
Class<?> commonPropertyType = (resolver.getCommonPropertyType(elContext, base));
buf.append("getCommonPropertyType() returns ");
buf.append(commonPropertyType.getName() + "" + NL);

Expand Down Expand Up @@ -259,7 +251,7 @@ public static boolean testELResolver(ELContext elContext, ELResolver resolver,
* @return
*/
public static boolean testELResolverInvoke(ELContext elContext,
ELResolver resolver, Object beanName, Object methodName, Class[] types,
ELResolver resolver, Object beanName, Object methodName, Class<?>[] types,
Object[] values, Boolean negTest, StringBuffer buf) {

boolean pass = true;
Expand All @@ -270,13 +262,13 @@ public static boolean testELResolverInvoke(ELContext elContext,
Boolean nameMatch = (Boolean) resolver.invoke(elContext, beanName,
methodName, types, values);

if (!nameMatch) {
if (!nameMatch.booleanValue()) {
buf.append("invoke() did not Run properly." + NL);
pass = false;
}

} catch (MethodNotFoundException mnfe) {
if (negTest) {
if (negTest.booleanValue()) {
buf.append("Test Passed invoke() threw MethodNotFoundException");
} else {
pass = false;
Expand All @@ -290,67 +282,6 @@ public static boolean testELResolverInvoke(ELContext elContext,
return pass;
}

public static boolean testFeatureDescriptors(Iterator i, ELResolver resolver,
Object base, StringBuffer buf) {

if (i == null) {
buf.append("getFeatureDescriptors() returns null" + NL);
if (resolver instanceof ArrayELResolver
|| resolver instanceof ListELResolver) {
return true;
} else if (resolver instanceof MapELResolver && !(base instanceof Map)) {
return true;
} else if (resolver instanceof BeanELResolver && base != null) {
return true;
} else if (resolver instanceof BarELResolver) {
return true;
} else {
return false;
}
}

while (i.hasNext()) {
Object obj = i.next();
if (!(obj instanceof FeatureDescriptor)) {
buf.append("getFeatureDescriptors() ");
buf.append(
"does not return a collection of " + "FeatureDescriptors" + NL);
return false;
} else {
int numAttribs = 0;
FeatureDescriptor fd = (FeatureDescriptor) obj;
Enumeration e = fd.attributeNames();
while (e.hasMoreElements()) {
String attrib = (String) e.nextElement();
if (attrib.equals("type")) {
++numAttribs;
if (!(fd.getValue(attrib) instanceof Class)) {
buf.append("getFeatureDescriptors(): ");
buf.append("Invalid attribute for type." + NL);
return false;
}
}
if (attrib.equals("resolvableAtDesignTime")) {
++numAttribs;
if (!(fd.getValue(attrib) instanceof Boolean)) {
buf.append("getFeatureDescriptors(): ");
buf.append(
"Invalid attribute for " + "resolvableAtDesignTime." + NL);
return false;
}
}
}
if (numAttribs < 2) {
buf.append("getFeatureDescriptors(): ");
buf.append("Required attribute missing." + NL);
return false;
}
} // else
} // while

buf.append("Passed all getFeatureDescriptors() tests" + NL);
return true;
}

// --- Start Negative Method Tests ---
public static boolean testELResolverNPE(ELResolver resolver, Object base,
Expand Down
8 changes: 7 additions & 1 deletion el/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021 Contributors to the Eclipse Foundation
Copyright (c) 2024 Contributors to the Eclipse Foundation
All rights reserved.
This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -116,6 +116,12 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -21,8 +21,6 @@

package com.sun.ts.tests.el.api.jakarta_el.arrayelresolver;

import java.util.Properties;

import com.sun.ts.lib.util.TestUtil;
import com.sun.ts.tests.common.el.api.resolver.ResolverTest;
import com.sun.ts.tests.el.common.elcontext.BareBonesELContext;
Expand Down Expand Up @@ -258,7 +256,7 @@ public void arrayELResolverOBETest() throws Exception {
ELContext context = barebonesContext.getELContext();

try {
Object value = resolver.getValue(context, names, 5);
Object value = resolver.getValue(context, names, Integer.valueOf(5));

if (value != null) {
pass = false;
Expand Down Expand Up @@ -310,4 +308,34 @@ public void arrayELResolverCCETest() throws Exception {
throw new Exception("Failed: No exception thrown.");
}
}


/*
* @testName: arrayELResolverLengthTest
*
* @test_Strategy: Verify that the length of an array is available as a read-only property.
*/
@Test
public void arrayELResolverLengthTest() throws Exception {

boolean pass;
StringBuffer buf = new StringBuffer();
String[] colors = { "red", "blue", "green" };

try {
ArrayELResolver arrayResolver = new ArrayELResolver();
BareBonesELContext barebonesContext = new BareBonesELContext();
ELContext context = barebonesContext.getELContext();

pass = ResolverTest.testELResolver(context, arrayResolver, colors,
"length", "3", buf, true);
} catch (Exception ex) {
throw new Exception(ex);
}

if (!pass) {
throw new Exception(ELTestUtil.FAIL + buf.toString());
}
logger.log(Logger.Level.TRACE, buf.toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2021 Oracle and/or its affiliates and others.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -15,15 +15,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

/*
* $Id$
*/

package com.sun.ts.tests.el.api.jakarta_el.beanelresolver;

import java.util.Properties;


import com.sun.ts.lib.util.TestUtil;
import com.sun.ts.tests.common.el.api.resolver.ResolverTest;
import com.sun.ts.tests.el.common.elcontext.BareBonesELContext;
Expand All @@ -39,6 +32,7 @@
import org.junit.jupiter.api.TestInfo;

import java.lang.System.Logger;
import java.util.TimeZone;

public class ELClientIT {

Expand Down Expand Up @@ -195,8 +189,7 @@ public void beanELResolverInvokeTest() throws Exception {
Class<?>[] types = { String.class, String.class };
String[] values = { "Doug", "Donahue" };

pass = ResolverTest.testELResolverInvoke(context, beanResolver, sb,
"isName", types, values, false, buf);
pass = ResolverTest.testELResolverInvoke(context, beanResolver, sb, "isName", types, values, Boolean.FALSE, buf);
} catch (Exception ex) {
throw new Exception(ex);
}
Expand Down Expand Up @@ -234,8 +227,8 @@ public void beanELResolverInvokeVoidTest() throws Exception {

if (null == result) {
// validate the new values.
pass = ResolverTest.testELResolverInvoke(context, beanResolver, sb,
"isName", types, values, false, buf);
pass = ResolverTest.testELResolverInvoke(
context, beanResolver, sb, "isName", types, values, Boolean.FALSE, buf);
} else {
pass = false;
buf.append("Unexpected Value returned!" + TestUtil.NEW_LINE
Expand Down Expand Up @@ -275,8 +268,8 @@ public void beanELResolverInvokeMNFETest() throws Exception {
Class<?>[] types = { String.class, String.class };
String[] values = { "Doug", "Donahue" };

pass = ResolverTest.testELResolverInvoke(context, beanResolver, sb,
"bogus_Method", types, values, true, buf);
pass = ResolverTest.testELResolverInvoke(
context, beanResolver, sb, "bogus_Method", types, values, Boolean.TRUE, buf);

} catch (Exception ex) {
throw new Exception(ex);
Expand Down Expand Up @@ -396,4 +389,35 @@ public void beanELResolverPNWETest() throws Exception {
}
logger.log(Logger.Level.TRACE, buf.toString());
}

/**
* @testName: beanELResolverMethodVisibilityTest
*
* @test_Strategy: Verify that API calls work as expected for a property that is not visible via the implementing
* class (it is in an internal, non-exported class) but is visible via an interface method:
* beanELResolver() getValue() getType() setValue() isReadOnly() getCommonPropertyType()
* getFeatureDescriptors()
*/
@Test
public void beanELResolverMethodVisibilityTest() throws Exception {

boolean pass = false;
StringBuffer buf = new StringBuffer();
TimeZone tz = TimeZone.getDefault();

try {
BeanELResolver beanResolver = new BeanELResolver();
BareBonesELContext barebonesContext = new BareBonesELContext();
ELContext context = barebonesContext.getELContext();

pass = ResolverTest.testELResolver(context, beanResolver, tz, "rawOffset", Integer.valueOf(0), buf, false);
} catch (Exception ex) {
throw new Exception(ex);
}

if (!pass) {
throw new Exception(ELTestUtil.FAIL + buf.toString());
}
logger.log(Logger.Level.TRACE, buf.toString());
}
}
Loading

0 comments on commit d3c0d07

Please sign in to comment.