From ce5d10a35a58997ee69f324ae553ee30f8c78e9b Mon Sep 17 00:00:00 2001 From: Alwin Joseph Date: Mon, 29 Jul 2024 00:04:05 +0530 Subject: [PATCH] Restore the EL EE tests as module el, move EL standalone tck module to el-tck --- {el => el-tck}/docs/LICENSE_EFTL.md | 0 {el => el-tck}/docs/ReleaseNotes.html | 0 {el => el-tck}/docs/TCK-Exclude-List.txt | 0 .../docs/assertions/ELJavadocAssertions.xml | 0 .../docs/assertions/ELSpecAssertions.xml | 0 {el => el-tck}/docs/index.html | 0 {el => el-tck}/docs/userguide/README.md | 0 {el => el-tck}/docs/userguide/pom.xml | 0 .../userguide/src/main/jbake/assets/README.md | 0 .../src/main/jbake/assets/_config.yml | 0 .../src/main/jbake/assets/css/style.css | 0 .../img/eclipse_foundation_logo_tiny.png | Bin .../userguide/src/main/jbake/content/README | 0 .../src/main/jbake/content/attributes.conf | 0 .../src/main/jbake/content/config.adoc | 0 .../src/main/jbake/content/config.inc | 0 .../src/main/jbake/content/debug-tips.inc | 0 .../src/main/jbake/content/debug.adoc | 0 .../src/main/jbake/content/defns.inc | 0 .../userguide/src/main/jbake/content/faq.adoc | 0 .../main/jbake/content/install-server-vi.inc | 0 .../src/main/jbake/content/install-server.inc | 0 .../src/main/jbake/content/install.adoc | 0 .../src/main/jbake/content/intro.adoc | 0 .../src/main/jbake/content/intro.inc | 0 .../src/main/jbake/content/packages.inc | 0 .../src/main/jbake/content/platforms.inc | 0 .../src/main/jbake/content/preface.adoc | 0 .../src/main/jbake/content/rebuild.adoc | 0 .../src/main/jbake/content/rebuild.inc | 0 .../src/main/jbake/content/req-software.inc | 0 .../src/main/jbake/content/rules.adoc | 0 .../src/main/jbake/content/rules.inc | 0 .../src/main/jbake/content/tck-packages.inc | 0 .../src/main/jbake/content/title.adoc | 0 .../src/main/jbake/content/title.inc | 0 .../src/main/jbake/content/using-examples.inc | 0 .../src/main/jbake/content/using.adoc | 0 .../src/main/jbake/content/using.inc | 0 .../userguide/src/main/jbake/jbake.properties | 0 .../src/main/jbake/templates/footer.ftl | 0 .../src/main/jbake/templates/header.ftl | 0 .../src/main/jbake/templates/menu.ftl | 0 .../src/main/jbake/templates/page.ftl | 0 .../userguide/src/theme/jakartaee-theme.yml | 0 el-tck/pom.xml | 172 ++ {el => el-tck}/src/main/assembly/assembly.xml | 0 .../arrayelresolver/ELClientIT.java | 0 .../jakarta_el/beanelresolver/ELClientIT.java | 0 .../beannameelresolver/ELClientIT.java | 0 .../compositeelresolver/ELClientIT.java | 0 .../api/jakarta_el/elcontext/ELClientIT.java | 0 .../jakarta_el/elprocessor/ELClientIT.java | 0 .../api/jakarta_el/elresolver/ELClientIT.java | 0 .../api/jakarta_el/expression/ELClientIT.java | 0 .../expressionfactory/ELClientIT.java | 0 .../jakarta_el/functionmapper/ELClientIT.java | 0 .../lambdaexpression/ELClientIT.java | 0 .../jakarta_el/listelresolver/ELClientIT.java | 0 .../jakarta_el/mapelresolver/ELClientIT.java | 0 .../methodexpression/ELClientIT.java | 0 .../api/jakarta_el/methodinfo/ELClientIT.java | 0 .../methodreference/ELClientIT.java | 0 .../optionalelresolver/ELClientIT.java | 2 +- .../recordelresolver/ELClientIT.java | 0 .../resourcebundleelresolver/ELClientIT.java | 0 .../staticfieldelresolver/ELClientIT.java | 0 .../staticfieldelresolver/TCKELClass.java | 52 + .../valueexpression/ELClientIT.java | 0 .../jakarta_el/valueexpression/Worker.java | 58 + .../jakarta_el/variablemapper/ELClientIT.java | 0 .../common/api/expression/ExpressionTest.java | 0 .../el/common/api/resolver/BarELResolver.java | 0 .../el/common/api/resolver/ResolverTest.java | 0 .../el/common/elcontext/BarELContext.java | 62 + .../common/elcontext/BareBonesELContext.java | 61 + .../common/elcontext/FuncMapperELContext.java | 63 + .../el/common/elcontext/SimpleELContext.java | 147 + .../tests/el/common/elcontext/VRContext.java | 101 + .../common/elcontext/VarMapperELContext.java | 102 + .../common/elresolver/EmployeeELResolver.java | 114 + .../el/common/elresolver/EnumELResolver.java | 0 .../common/elresolver/FunctionELResolver.java | 95 + .../common/elresolver/VariableELResolver.java | 124 + .../el/common/elresolver/VectELResolver.java | 87 + .../functionmapper/TCKFunctionMapper.java | 74 + .../com/sun/ts/tests/el/common/spec/Book.java | 0 .../sun/ts/tests/el/common/util/Customer.java | 84 + .../sun/ts/tests/el/common/util/DataBase.java | 132 + .../com/sun/ts/tests/el/common/util/Date.java | 47 + .../ts/tests/el/common/util/ELTestUtil.java | 239 ++ .../sun/ts/tests/el/common/util/ExprEval.java | 385 +++ .../sun/ts/tests/el/common/util/Fault.java | 125 + .../ts/tests/el/common/util/MethodsBean.java | 68 + .../tests/el/common/util/NameValuePair.java | 84 + .../sun/ts/tests/el/common/util/Order.java | 56 + .../sun/ts/tests/el/common/util/Product.java | 66 + .../ts/tests/el/common/util/ResolverType.java | 25 + .../ts/tests/el/common/util/SimpleBean.java | 65 + .../tests/el/common/util/SimpleInterface.java | 30 + .../sun/ts/tests/el/common/util/TestNum.java | 87 + .../ts/tests/el/common/util/TypesBean.java | 171 ++ .../ts/tests/el/common/util/Validator.java | 998 +++++++ .../el/signaturetest/el/ELSigTestIT.java | 0 .../el/signaturetest/el/PackageList.java | 0 .../ts/tests/el/signaturetest/el/SigTest.java | 0 .../el/signaturetest/el/SigTestData.java | 0 .../el/signaturetest/el/SigTestDriver.java | 0 .../el/signaturetest/el/SigTestResult.java | 0 .../signaturetest/el/SignatureTestDriver.java | 0 .../el/SignatureTestDriverFactory.java | 0 .../spec/assignmentoperator/ELClientIT.java | 0 .../el/spec/binaryoperator/ELClientIT.java | 0 .../ts/tests/el/spec/coercion/ELClientIT.java | 0 .../spec/collectionoperators/ELClientIT.java | 0 .../el/spec/concatoperator/ELClientIT.java | 0 .../spec/conditionaloperator/ELClientIT.java | 0 .../el/spec/emptyoperator/ELClientIT.java | 0 .../ts/tests/el/spec/lambda/ELClientIT.java | 0 .../ts/tests/el/spec/language/ELClientIT.java | 0 .../ts/tests/el/spec/literal/ELClientIT.java | 0 .../ts/tests/el/spec/mapper/ELClientIT.java | 0 .../spec/operatorprecedence/ELClientIT.java | 0 .../spec/relationaloperator/ELClientIT.java | 0 .../el/spec/semicolonoperator/ELClientIT.java | 0 .../el/spec/unaryoperator/ELClientIT.java | 0 .../src/main/resources/LICENSE_EFTL.md | 0 .../src/main/resources/LICENSE_EPL.md | 0 .../tests/signaturetest/el/jakarta.el.sig_5.0 | 0 .../tests/signaturetest/el/jakarta.el.sig_6.0 | 0 .../signaturetest/el/sig-test-pkg-list.txt | 0 .../ts/tests/signaturetest/el/sig-test.map | 0 .../src/main/resources/jakarta.el.sig_5.0 | 0 .../src/main/resources/jakarta.el.sig_6.0 | 0 el/pom.xml | 144 +- .../java/com/sun/ts/tests/el/api/build.xml | 22 + .../jakarta_el/arrayelresolver/ELClient.java | 330 +++ .../api/jakarta_el/arrayelresolver/build.xml | 32 + .../jakarta_el/beanelresolver/ELClient.java | 413 +++ .../api/jakarta_el/beanelresolver/build.xml | 32 + .../beannameelresolver/ELClient.java | 260 ++ .../jakarta_el/beannameelresolver/build.xml | 32 + .../sun/ts/tests/el/api/jakarta_el/build.xml | 22 + .../compositeelresolver/ELClient.java | 302 +++ .../jakarta_el/compositeelresolver/build.xml | 32 + .../el/api/jakarta_el/elcontext/ELClient.java | 226 ++ .../el/api/jakarta_el/elcontext/build.xml | 32 + .../api/jakarta_el/elprocessor/ELClient.java | 172 ++ .../el/api/jakarta_el/elprocessor/build.xml | 32 + .../api/jakarta_el/elresolver/ELClient.java | 213 ++ .../el/api/jakarta_el/elresolver/build.xml | 32 + .../api/jakarta_el/expression/ELClient.java | 172 ++ .../el/api/jakarta_el/expression/build.xml | 32 + .../expressionfactory/ELClient.java | 524 ++++ .../jakarta_el/expressionfactory/build.xml | 32 + .../jakarta_el/functionmapper/ELClient.java | 98 + .../api/jakarta_el/functionmapper/build.xml | 32 + .../jakarta_el/lambdaexpression/ELClient.java | 103 + .../api/jakarta_el/lambdaexpression/build.xml | 32 + .../jakarta_el/listelresolver/ELClient.java | 225 ++ .../api/jakarta_el/listelresolver/build.xml | 32 + .../jakarta_el/mapelresolver/ELClient.java | 158 ++ .../el/api/jakarta_el/mapelresolver/build.xml | 32 + .../jakarta_el/methodexpression/ELClient.java | 685 +++++ .../api/jakarta_el/methodexpression/build.xml | 32 + .../api/jakarta_el/methodinfo/ELClient.java | 121 + .../el/api/jakarta_el/methodinfo/build.xml | 32 + .../jakarta_el/methodreference/ELClient.java | 133 + .../optionalelresolver/ELClient.java | 296 +++ .../jakarta_el/recordelresolver/ELClient.java | 78 + .../resourcebundleelresolver/ELClient.java | 181 ++ .../resourcebundleelresolver/build.xml | 32 + .../staticfieldelresolver/ELClient.java | 349 +++ .../staticfieldelresolver/build.xml | 32 + .../jakarta_el/valueexpression/ELClient.java | 531 ++++ .../api/jakarta_el/valueexpression/build.xml | 32 + .../jakarta_el/variablemapper/ELClient.java | 123 + .../api/jakarta_el/variablemapper/build.xml | 25 + .../main/java/com/sun/ts/tests/el/build.xml | 22 + .../java/com/sun/ts/tests/el/common/build.xml | 22 + .../el/common/elcontext/BarELContext.java | 2 +- .../el/common/elcontext/SimpleELContext.java | 14 +- .../tests/el/common/elcontext/VRContext.java | 12 +- .../common/elcontext/VarMapperELContext.java | 11 +- .../functionmapper/TCKFunctionMapper.java | 14 +- .../ts/tests/el/common/util/ELTestUtil.java | 23 +- .../tests/el/common/util/EnumELResolver.java | 25 + .../sun/ts/tests/el/common/util/ExprEval.java | 51 +- .../ts/tests/el/common/util/Validator.java | 241 +- .../el/spec/assignmentoperator/ELClient.java | 931 +++++++ .../el/spec/assignmentoperator/build.xml | 30 + .../el/spec/binaryoperator/ELClient.java | 1120 ++++++++ .../ts/tests/el/spec/binaryoperator/build.xml | 30 + .../java/com/sun/ts/tests/el/spec/build.xml | 22 + .../ts/tests/el/spec/coercion/ELClient.java | 1912 +++++++++++++ .../sun/ts/tests/el/spec/coercion/build.xml | 31 + .../el/spec/collectionoperators/ELClient.java | 744 ++++++ .../el/spec/collectionoperators/build.xml | 30 + .../el/spec/concatoperator/ELClient.java | 284 ++ .../ts/tests/el/spec/concatoperator/build.xml | 30 + .../el/spec/conditionaloperator/ELClient.java | 139 + .../el/spec/conditionaloperator/build.xml | 31 + .../tests/el/spec/emptyoperator/ELClient.java | 196 ++ .../ts/tests/el/spec/emptyoperator/build.xml | 31 + .../sun/ts/tests/el/spec/lambda/ELClient.java | 888 +++++++ .../com/sun/ts/tests/el/spec/lambda/build.xml | 30 + .../ts/tests/el/spec/language/ELClient.java | 588 ++++ .../sun/ts/tests/el/spec/language/build.xml | 32 + .../ts/tests/el/spec/literal/ELClient.java | 404 +++ .../sun/ts/tests/el/spec/literal/build.xml | 31 + .../sun/ts/tests/el/spec/mapper/ELClient.java | 176 ++ .../com/sun/ts/tests/el/spec/mapper/build.xml | 25 + .../el/spec/operatorprecedence/ELClient.java | 508 ++++ .../el/spec/operatorprecedence/build.xml | 31 + .../el/spec/relationaloperator/ELClient.java | 2365 +++++++++++++++++ .../el/spec/relationaloperator/build.xml | 31 + .../el/spec/semicolonoperator/ELClient.java | 857 ++++++ .../tests/el/spec/semicolonoperator/build.xml | 30 + .../tests/el/spec/unaryoperator/ELClient.java | 540 ++++ .../ts/tests/el/spec/unaryoperator/build.xml | 31 + pom.xml | 1 + 221 files changed, 22699 insertions(+), 325 deletions(-) rename {el => el-tck}/docs/LICENSE_EFTL.md (100%) rename {el => el-tck}/docs/ReleaseNotes.html (100%) rename {el => el-tck}/docs/TCK-Exclude-List.txt (100%) rename {el => el-tck}/docs/assertions/ELJavadocAssertions.xml (100%) rename {el => el-tck}/docs/assertions/ELSpecAssertions.xml (100%) rename {el => el-tck}/docs/index.html (100%) rename {el => el-tck}/docs/userguide/README.md (100%) rename {el => el-tck}/docs/userguide/pom.xml (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/assets/README.md (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/assets/_config.yml (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/assets/css/style.css (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/assets/img/eclipse_foundation_logo_tiny.png (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/README (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/attributes.conf (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/config.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/config.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/debug-tips.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/debug.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/defns.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/faq.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/install-server-vi.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/install-server.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/install.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/intro.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/intro.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/packages.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/platforms.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/preface.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/rebuild.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/rebuild.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/req-software.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/rules.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/rules.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/tck-packages.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/title.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/title.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/using-examples.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/using.adoc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/content/using.inc (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/jbake.properties (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/templates/footer.ftl (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/templates/header.ftl (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/templates/menu.ftl (100%) rename {el => el-tck}/docs/userguide/src/main/jbake/templates/page.ftl (100%) rename {el => el-tck}/docs/userguide/src/theme/jakartaee-theme.yml (100%) create mode 100644 el-tck/pom.xml rename {el => el-tck}/src/main/assembly/assembly.xml (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClientIT.java (99%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClientIT.java (100%) create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/TCKELClass.java rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClientIT.java (100%) create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/Worker.java rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/common/api/expression/ExpressionTest.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/common/api/resolver/BarELResolver.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/common/api/resolver/ResolverTest.java (100%) create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BareBonesELContext.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/FuncMapperELContext.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/EmployeeELResolver.java rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/common/elresolver/EnumELResolver.java (100%) create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/FunctionELResolver.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VariableELResolver.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VectELResolver.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/common/spec/Book.java (100%) create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/Customer.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/DataBase.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/Date.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/Fault.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/MethodsBean.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/NameValuePair.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/Order.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/Product.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/ResolverType.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleBean.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleInterface.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/TestNum.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/TypesBean.java create mode 100644 el-tck/src/main/java/com/sun/ts/tests/el/common/util/Validator.java rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/ELSigTestIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/PackageList.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTest.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestData.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestDriver.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestResult.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriver.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriverFactory.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/language/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/literal/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClientIT.java (100%) rename {el => el-tck}/src/main/resources/LICENSE_EFTL.md (100%) rename {el => el-tck}/src/main/resources/LICENSE_EPL.md (100%) rename {el => el-tck}/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_5.0 (100%) rename {el => el-tck}/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_6.0 (100%) rename {el => el-tck}/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test-pkg-list.txt (100%) rename {el => el-tck}/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test.map (100%) rename {el => el-tck}/src/main/resources/jakarta.el.sig_5.0 (100%) rename {el => el-tck}/src/main/resources/jakarta.el.sig_6.0 (100%) create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/common/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/common/util/EnumELResolver.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/coercion/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/lambda/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/language/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/language/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/literal/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/literal/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/mapper/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/build.xml create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClient.java create mode 100644 el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/build.xml diff --git a/el/docs/LICENSE_EFTL.md b/el-tck/docs/LICENSE_EFTL.md similarity index 100% rename from el/docs/LICENSE_EFTL.md rename to el-tck/docs/LICENSE_EFTL.md diff --git a/el/docs/ReleaseNotes.html b/el-tck/docs/ReleaseNotes.html similarity index 100% rename from el/docs/ReleaseNotes.html rename to el-tck/docs/ReleaseNotes.html diff --git a/el/docs/TCK-Exclude-List.txt b/el-tck/docs/TCK-Exclude-List.txt similarity index 100% rename from el/docs/TCK-Exclude-List.txt rename to el-tck/docs/TCK-Exclude-List.txt diff --git a/el/docs/assertions/ELJavadocAssertions.xml b/el-tck/docs/assertions/ELJavadocAssertions.xml similarity index 100% rename from el/docs/assertions/ELJavadocAssertions.xml rename to el-tck/docs/assertions/ELJavadocAssertions.xml diff --git a/el/docs/assertions/ELSpecAssertions.xml b/el-tck/docs/assertions/ELSpecAssertions.xml similarity index 100% rename from el/docs/assertions/ELSpecAssertions.xml rename to el-tck/docs/assertions/ELSpecAssertions.xml diff --git a/el/docs/index.html b/el-tck/docs/index.html similarity index 100% rename from el/docs/index.html rename to el-tck/docs/index.html diff --git a/el/docs/userguide/README.md b/el-tck/docs/userguide/README.md similarity index 100% rename from el/docs/userguide/README.md rename to el-tck/docs/userguide/README.md diff --git a/el/docs/userguide/pom.xml b/el-tck/docs/userguide/pom.xml similarity index 100% rename from el/docs/userguide/pom.xml rename to el-tck/docs/userguide/pom.xml diff --git a/el/docs/userguide/src/main/jbake/assets/README.md b/el-tck/docs/userguide/src/main/jbake/assets/README.md similarity index 100% rename from el/docs/userguide/src/main/jbake/assets/README.md rename to el-tck/docs/userguide/src/main/jbake/assets/README.md diff --git a/el/docs/userguide/src/main/jbake/assets/_config.yml b/el-tck/docs/userguide/src/main/jbake/assets/_config.yml similarity index 100% rename from el/docs/userguide/src/main/jbake/assets/_config.yml rename to el-tck/docs/userguide/src/main/jbake/assets/_config.yml diff --git a/el/docs/userguide/src/main/jbake/assets/css/style.css b/el-tck/docs/userguide/src/main/jbake/assets/css/style.css similarity index 100% rename from el/docs/userguide/src/main/jbake/assets/css/style.css rename to el-tck/docs/userguide/src/main/jbake/assets/css/style.css diff --git a/el/docs/userguide/src/main/jbake/assets/img/eclipse_foundation_logo_tiny.png b/el-tck/docs/userguide/src/main/jbake/assets/img/eclipse_foundation_logo_tiny.png similarity index 100% rename from el/docs/userguide/src/main/jbake/assets/img/eclipse_foundation_logo_tiny.png rename to el-tck/docs/userguide/src/main/jbake/assets/img/eclipse_foundation_logo_tiny.png diff --git a/el/docs/userguide/src/main/jbake/content/README b/el-tck/docs/userguide/src/main/jbake/content/README similarity index 100% rename from el/docs/userguide/src/main/jbake/content/README rename to el-tck/docs/userguide/src/main/jbake/content/README diff --git a/el/docs/userguide/src/main/jbake/content/attributes.conf b/el-tck/docs/userguide/src/main/jbake/content/attributes.conf similarity index 100% rename from el/docs/userguide/src/main/jbake/content/attributes.conf rename to el-tck/docs/userguide/src/main/jbake/content/attributes.conf diff --git a/el/docs/userguide/src/main/jbake/content/config.adoc b/el-tck/docs/userguide/src/main/jbake/content/config.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/config.adoc rename to el-tck/docs/userguide/src/main/jbake/content/config.adoc diff --git a/el/docs/userguide/src/main/jbake/content/config.inc b/el-tck/docs/userguide/src/main/jbake/content/config.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/config.inc rename to el-tck/docs/userguide/src/main/jbake/content/config.inc diff --git a/el/docs/userguide/src/main/jbake/content/debug-tips.inc b/el-tck/docs/userguide/src/main/jbake/content/debug-tips.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/debug-tips.inc rename to el-tck/docs/userguide/src/main/jbake/content/debug-tips.inc diff --git a/el/docs/userguide/src/main/jbake/content/debug.adoc b/el-tck/docs/userguide/src/main/jbake/content/debug.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/debug.adoc rename to el-tck/docs/userguide/src/main/jbake/content/debug.adoc diff --git a/el/docs/userguide/src/main/jbake/content/defns.inc b/el-tck/docs/userguide/src/main/jbake/content/defns.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/defns.inc rename to el-tck/docs/userguide/src/main/jbake/content/defns.inc diff --git a/el/docs/userguide/src/main/jbake/content/faq.adoc b/el-tck/docs/userguide/src/main/jbake/content/faq.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/faq.adoc rename to el-tck/docs/userguide/src/main/jbake/content/faq.adoc diff --git a/el/docs/userguide/src/main/jbake/content/install-server-vi.inc b/el-tck/docs/userguide/src/main/jbake/content/install-server-vi.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/install-server-vi.inc rename to el-tck/docs/userguide/src/main/jbake/content/install-server-vi.inc diff --git a/el/docs/userguide/src/main/jbake/content/install-server.inc b/el-tck/docs/userguide/src/main/jbake/content/install-server.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/install-server.inc rename to el-tck/docs/userguide/src/main/jbake/content/install-server.inc diff --git a/el/docs/userguide/src/main/jbake/content/install.adoc b/el-tck/docs/userguide/src/main/jbake/content/install.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/install.adoc rename to el-tck/docs/userguide/src/main/jbake/content/install.adoc diff --git a/el/docs/userguide/src/main/jbake/content/intro.adoc b/el-tck/docs/userguide/src/main/jbake/content/intro.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/intro.adoc rename to el-tck/docs/userguide/src/main/jbake/content/intro.adoc diff --git a/el/docs/userguide/src/main/jbake/content/intro.inc b/el-tck/docs/userguide/src/main/jbake/content/intro.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/intro.inc rename to el-tck/docs/userguide/src/main/jbake/content/intro.inc diff --git a/el/docs/userguide/src/main/jbake/content/packages.inc b/el-tck/docs/userguide/src/main/jbake/content/packages.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/packages.inc rename to el-tck/docs/userguide/src/main/jbake/content/packages.inc diff --git a/el/docs/userguide/src/main/jbake/content/platforms.inc b/el-tck/docs/userguide/src/main/jbake/content/platforms.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/platforms.inc rename to el-tck/docs/userguide/src/main/jbake/content/platforms.inc diff --git a/el/docs/userguide/src/main/jbake/content/preface.adoc b/el-tck/docs/userguide/src/main/jbake/content/preface.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/preface.adoc rename to el-tck/docs/userguide/src/main/jbake/content/preface.adoc diff --git a/el/docs/userguide/src/main/jbake/content/rebuild.adoc b/el-tck/docs/userguide/src/main/jbake/content/rebuild.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/rebuild.adoc rename to el-tck/docs/userguide/src/main/jbake/content/rebuild.adoc diff --git a/el/docs/userguide/src/main/jbake/content/rebuild.inc b/el-tck/docs/userguide/src/main/jbake/content/rebuild.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/rebuild.inc rename to el-tck/docs/userguide/src/main/jbake/content/rebuild.inc diff --git a/el/docs/userguide/src/main/jbake/content/req-software.inc b/el-tck/docs/userguide/src/main/jbake/content/req-software.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/req-software.inc rename to el-tck/docs/userguide/src/main/jbake/content/req-software.inc diff --git a/el/docs/userguide/src/main/jbake/content/rules.adoc b/el-tck/docs/userguide/src/main/jbake/content/rules.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/rules.adoc rename to el-tck/docs/userguide/src/main/jbake/content/rules.adoc diff --git a/el/docs/userguide/src/main/jbake/content/rules.inc b/el-tck/docs/userguide/src/main/jbake/content/rules.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/rules.inc rename to el-tck/docs/userguide/src/main/jbake/content/rules.inc diff --git a/el/docs/userguide/src/main/jbake/content/tck-packages.inc b/el-tck/docs/userguide/src/main/jbake/content/tck-packages.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/tck-packages.inc rename to el-tck/docs/userguide/src/main/jbake/content/tck-packages.inc diff --git a/el/docs/userguide/src/main/jbake/content/title.adoc b/el-tck/docs/userguide/src/main/jbake/content/title.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/title.adoc rename to el-tck/docs/userguide/src/main/jbake/content/title.adoc diff --git a/el/docs/userguide/src/main/jbake/content/title.inc b/el-tck/docs/userguide/src/main/jbake/content/title.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/title.inc rename to el-tck/docs/userguide/src/main/jbake/content/title.inc diff --git a/el/docs/userguide/src/main/jbake/content/using-examples.inc b/el-tck/docs/userguide/src/main/jbake/content/using-examples.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/using-examples.inc rename to el-tck/docs/userguide/src/main/jbake/content/using-examples.inc diff --git a/el/docs/userguide/src/main/jbake/content/using.adoc b/el-tck/docs/userguide/src/main/jbake/content/using.adoc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/using.adoc rename to el-tck/docs/userguide/src/main/jbake/content/using.adoc diff --git a/el/docs/userguide/src/main/jbake/content/using.inc b/el-tck/docs/userguide/src/main/jbake/content/using.inc similarity index 100% rename from el/docs/userguide/src/main/jbake/content/using.inc rename to el-tck/docs/userguide/src/main/jbake/content/using.inc diff --git a/el/docs/userguide/src/main/jbake/jbake.properties b/el-tck/docs/userguide/src/main/jbake/jbake.properties similarity index 100% rename from el/docs/userguide/src/main/jbake/jbake.properties rename to el-tck/docs/userguide/src/main/jbake/jbake.properties diff --git a/el/docs/userguide/src/main/jbake/templates/footer.ftl b/el-tck/docs/userguide/src/main/jbake/templates/footer.ftl similarity index 100% rename from el/docs/userguide/src/main/jbake/templates/footer.ftl rename to el-tck/docs/userguide/src/main/jbake/templates/footer.ftl diff --git a/el/docs/userguide/src/main/jbake/templates/header.ftl b/el-tck/docs/userguide/src/main/jbake/templates/header.ftl similarity index 100% rename from el/docs/userguide/src/main/jbake/templates/header.ftl rename to el-tck/docs/userguide/src/main/jbake/templates/header.ftl diff --git a/el/docs/userguide/src/main/jbake/templates/menu.ftl b/el-tck/docs/userguide/src/main/jbake/templates/menu.ftl similarity index 100% rename from el/docs/userguide/src/main/jbake/templates/menu.ftl rename to el-tck/docs/userguide/src/main/jbake/templates/menu.ftl diff --git a/el/docs/userguide/src/main/jbake/templates/page.ftl b/el-tck/docs/userguide/src/main/jbake/templates/page.ftl similarity index 100% rename from el/docs/userguide/src/main/jbake/templates/page.ftl rename to el-tck/docs/userguide/src/main/jbake/templates/page.ftl diff --git a/el/docs/userguide/src/theme/jakartaee-theme.yml b/el-tck/docs/userguide/src/theme/jakartaee-theme.yml similarity index 100% rename from el/docs/userguide/src/theme/jakartaee-theme.yml rename to el-tck/docs/userguide/src/theme/jakartaee-theme.yml diff --git a/el-tck/pom.xml b/el-tck/pom.xml new file mode 100644 index 0000000000..14458f72eb --- /dev/null +++ b/el-tck/pom.xml @@ -0,0 +1,172 @@ + + + + 4.0.0 + + + jakarta.tck + project + 11.0.0-M1 + + + jakarta-expression-language-tck + 6.0.1 + jar + + el-tck + EL TCK + + + 6.0.0 + + + + + jakarta.el + jakarta.el-api + ${jakarta.el-api.version} + + + org.junit.jupiter + junit-jupiter + compile + + + jakarta.tck + sigtest-maven-plugin + 2.3 + + + + + + ${bundle-name}-${project.version} + + + src/main/resources + + LICENSE_${license}.md + com/ + + + + + + + maven-deploy-plugin + + true + + + + maven-javadoc-plugin + + none + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + distribution + + single + + package + + + src/main/assembly/assembly.xml + + \ + false + ${bundle-name}-${project.version} + + + + + + + + + + EFTL + + true + + + jakarta-expression-language-tck + EFTL + + + + EPL + + expression-language-tck + EPL + + + + record-signature + + false + + + jakarta-expression-language-tck + EFTL + + + + + jakarta.tck + sigtest-maven-plugin + 2.2 + + ${project.build.directory}/jakarta.el.sig_${project.parent.version} + jakarta.el + + + + + generate + + + + + + + + + + + diff --git a/el/src/main/assembly/assembly.xml b/el-tck/src/main/assembly/assembly.xml similarity index 100% rename from el/src/main/assembly/assembly.xml rename to el-tck/src/main/assembly/assembly.xml diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClientIT.java similarity index 99% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClientIT.java index 8e53b60e8d..83c69a63a7 100644 --- a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClientIT.java +++ b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClientIT.java @@ -118,7 +118,7 @@ public void optionalELResolverObjectNullTest() throws Exception { } /** - * @testName: optionalELResolverObjectNullTest + * @testName: optionalELResolverObjectNonNullTest * * @test_Strategy: Verify that API calls work as expected for: getValue() getType() setValue() isReadOnly() * getCommonPropertyType() when the base object is an non-empty Optional and the property is non-null diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClientIT.java diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/TCKELClass.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/TCKELClass.java new file mode 100644 index 0000000000..01324d9c0f --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/TCKELClass.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.staticfieldelresolver; + +public class TCKELClass { + public static String firstName = "Ender"; + + public static String lastName = "Wiggins"; + + // Not writable from StaticFieldELResolver + public String notStatic = "notStatic"; + + private static String privStatic = "privStatic"; + + /** + * + * @param firstName + * - first name @String + * @param lastName + * - last Name + * @return true is full name matches the given firstName + " " + lastName + * pattern. + */ + public static boolean isName(String name) { + boolean result = Boolean.FALSE; + + if (name.equals(firstName)) { + result = true; + } + + return result; + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClientIT.java diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/Worker.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/Worker.java new file mode 100644 index 0000000000..e1a0818f80 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/Worker.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.valueexpression; + +public class Worker { + private String firstName = "Doug"; + + private String lastName = "Donahue"; + + /** + * @return the lastName + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName + * the lastName to set + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return the firstName + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName + * the firstName to set + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/common/api/expression/ExpressionTest.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/api/expression/ExpressionTest.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/common/api/expression/ExpressionTest.java rename to el-tck/src/main/java/com/sun/ts/tests/el/common/api/expression/ExpressionTest.java diff --git a/el/src/main/java/com/sun/ts/tests/el/common/api/resolver/BarELResolver.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/api/resolver/BarELResolver.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/common/api/resolver/BarELResolver.java rename to el-tck/src/main/java/com/sun/ts/tests/el/common/api/resolver/BarELResolver.java diff --git a/el/src/main/java/com/sun/ts/tests/el/common/api/resolver/ResolverTest.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/api/resolver/ResolverTest.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/common/api/resolver/ResolverTest.java rename to el-tck/src/main/java/com/sun/ts/tests/el/common/api/resolver/ResolverTest.java diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java new file mode 100644 index 0000000000..07a6de777e --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elcontext; + +import com.sun.ts.tests.el.common.api.resolver.BarELResolver; + +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.FunctionMapper; +import jakarta.el.VariableMapper; + +/* This ELContext contains only a simple EL resolver used to + resolve expressions handled by the BarELResolver. +*/ + +public class BarELContext extends ELContext { + + private final ELResolver elResolver; + + /* + * Constructor. + */ + public BarELContext() { + this.elResolver = new BarELResolver(); + } + + public ELResolver getELResolver() { + return (ELResolver) elResolver; + } + + public ELContext getELContext() { + return (ELContext) (this); + } + + public VariableMapper getVariableMapper() { + return null; + } + + public FunctionMapper getFunctionMapper() { + return null; + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BareBonesELContext.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BareBonesELContext.java new file mode 100644 index 0000000000..a2d6f38b67 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/BareBonesELContext.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elcontext; + +import jakarta.el.CompositeELResolver; +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.FunctionMapper; +import jakarta.el.VariableMapper; + +/* This ELContext contains only a single CompositeELResolver + for use in testing the ELResolver API. +*/ + +public class BareBonesELContext extends ELContext { + + private final ELResolver elResolver; + + /* + * Constructor. + */ + public BareBonesELContext() { + this.elResolver = new CompositeELResolver(); + } + + public ELResolver getELResolver() { + return (ELResolver) elResolver; + } + + public ELContext getELContext() { + return (ELContext) (this); + } + + public VariableMapper getVariableMapper() { + return null; + } + + public FunctionMapper getFunctionMapper() { + return null; + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/FuncMapperELContext.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/FuncMapperELContext.java new file mode 100644 index 0000000000..7974df4758 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/FuncMapperELContext.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elcontext; + +import com.sun.ts.tests.el.common.elresolver.FunctionELResolver; +import com.sun.ts.tests.el.common.functionmapper.TCKFunctionMapper; + +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.FunctionMapper; +import jakarta.el.VariableMapper; + +/* This ELContext provides only a FunctionMapper implementation and + an ELResolver that resolves only the functions mapped by the + FunctionMapper. + */ + +public class FuncMapperELContext extends ELContext { + + private final ELResolver elResolver; + + private final FunctionMapper funcMapper; + + /* + * Constructor. + */ + public FuncMapperELContext() { + elResolver = new FunctionELResolver(); + funcMapper = new TCKFunctionMapper(); + } + + public ELResolver getELResolver() { + return elResolver; + } + + public VariableMapper getVariableMapper() { + return null; + } + + public FunctionMapper getFunctionMapper() { + return funcMapper; + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java new file mode 100644 index 0000000000..148fa5d9c5 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.el.common.elcontext; + + +import com.sun.ts.tests.el.common.elresolver.EmployeeELResolver; +import com.sun.ts.tests.el.common.elresolver.VariableELResolver; +import com.sun.ts.tests.el.common.elresolver.VectELResolver; +import com.sun.ts.tests.el.common.util.ResolverType; + +import jakarta.el.CompositeELResolver; +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.FunctionMapper; +import jakarta.el.VariableMapper; + +import java.lang.System.Logger; + +/** + * A basic ELContext that meets the needs of most EL tests. The no-args + * constructor builds the ELContext from a VariableELResolver that enables the + * setting and resolution of variables when base is null. The single- argument + * constructor allows the user to build the ELContext from any ELResolver. This + * ELContext is "simple" because no VariableMapper or FunctionMapper are used. + */ +public class SimpleELContext extends ELContext { + + private static final Logger logger = System.getLogger(SimpleELContext.class.getName()); + + private static final String NLINE = System.getProperty("line.separator"); + + private final CompositeELResolver compResolver; + + private ELResolver myResolver; + + private VariableELResolver varResolver; + + // Custom ELResolvers. + public enum Resolver { + + EmployeeELResolver, VariableELResolver, VectELResolver + }; + + /* + * Default Constructor. + */ + public SimpleELContext() { + this.compResolver = new CompositeELResolver(); + } + + /* + * Constructor with an ELResolver given through an enum. + */ + public SimpleELContext(ResolverType resolverType) { + this.myResolver = this.getMyResolver(resolverType); + this.compResolver = new CompositeELResolver(); + } + + public ELResolver getELResolver() { + ELResolver elResolver; + + if (myResolver == null) { + varResolver = new VariableELResolver(); + compResolver.add(varResolver); + } else { + if (myResolver instanceof VariableELResolver) { + varResolver = (VariableELResolver) myResolver; + } else { + varResolver = null; + } + compResolver.add(myResolver); + } + + elResolver = (ELResolver) compResolver; + + return elResolver; + } + + public ELContext getELContext() { + return (ELContext) (this); + } + + public VariableMapper getVariableMapper() { + return null; + } + + public FunctionMapper getFunctionMapper() { + return null; + } + + // This method is not required by the ELContext API. It is for + // removing all entries from the the VariableELResolver's + // static hashtable between test invocations. + public void cleanup() { + if (varResolver != null) { + varResolver.cleanup(); + } + } + + // ------------------------------- Private Methods + // ------------------------------ + private ELResolver getMyResolver(ResolverType enumResolver) { + + switch (enumResolver) { + case EMPLOYEE_ELRESOLVER: + myResolver = new EmployeeELResolver(); + logger.log(Logger.Level.TRACE, "Setting ELResolver == EmployeeELResolver"); + break; + + case VARIABLE_ELRESOLVER: + myResolver = new VariableELResolver(); + logger.log(Logger.Level.TRACE, "Setting ELResolver == VariableELResolver"); + break; + + case VECT_ELRESOLVER: + myResolver = new VectELResolver(); + logger.log(Logger.Level.TRACE, "Setting ELResolver == VectELResolver"); + break; + + default: + logger.log(Logger.Level.TRACE, + "Unknown ELResolver! " + enumResolver + " trying to use default" + + NLINE + "Setting" + " ELResolver == VariableELResolver"); + break; + } + + return myResolver; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java new file mode 100644 index 0000000000..b8666a39af --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.el.common.elcontext; + +import java.util.Properties; + + +import com.sun.ts.tests.el.api.jakarta_el.valueexpression.Worker; +import com.sun.ts.tests.el.common.elresolver.VariableELResolver; +import com.sun.ts.tests.el.common.functionmapper.TCKFunctionMapper; + +import jakarta.el.BeanELResolver; +import jakarta.el.CompositeELResolver; +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.FunctionMapper; +import jakarta.el.VariableMapper; + +import java.lang.System.Logger; + +public class VRContext extends ELContext { + + private static final Logger logger = System.getLogger(VRContext.class.getName()); + + private final VariableMapper varMapper; + + private final CompositeELResolver compResolver; + + public VRContext(Properties testProps) { + this.compResolver = new CompositeELResolver(); + varMapper = this.getVariableMapperImpl(testProps); + } + + public ELResolver getELResolver() { + ELResolver elResolver; + ELResolver rel = new VariableELResolver(); + rel.setValue(this, "worker", null, new Worker()); + compResolver.add(rel); + + BeanELResolver br = new BeanELResolver(); + br.setValue(this, "worker", null, new Worker()); + compResolver.add(br); + elResolver = compResolver; + + return elResolver; + } + + @Override + public FunctionMapper getFunctionMapper() { + + return new TCKFunctionMapper(); + } + + @Override + public VariableMapper getVariableMapper() { + return varMapper; + } + + private Object getImplSpecificInstance(String classname) { + + Class clazz; + Object instance = null; + + try { + clazz = Class.forName(classname); + instance = clazz.newInstance(); + } catch (ClassNotFoundException cnfe) { + logger.log(Logger.Level.ERROR, "ClassNotFoundException: " + cnfe.getMessage()); + } catch (InstantiationException ie) { + logger.log(Logger.Level.ERROR, "InstantiationException: " + ie.getMessage()); + } catch (IllegalAccessException iae) { + logger.log(Logger.Level.ERROR, "IllegalAccessException: " + iae.getMessage()); + } + return instance; + } + + private VariableMapper getVariableMapperImpl(Properties testProps) { + String implSpecificClassName = testProps.getProperty("variable.mapper"); + + return (implSpecificClassName == null) ? null + : (VariableMapper) getImplSpecificInstance(implSpecificClassName); + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java new file mode 100644 index 0000000000..ea9e35b370 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.el.common.elcontext; + +import java.util.Properties; + + +import com.sun.ts.tests.el.common.elresolver.VariableELResolver; + +import jakarta.el.CompositeELResolver; +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.FunctionMapper; +import jakarta.el.VariableMapper; + +import java.lang.System.Logger; +/** + * This ELContext provides a VariableELResolver to enable the setting and + * resolution of variables as well as a VariableMapper implementation. The path + * to the implementation is passed to the EL Context via a property in the + * ts.jte file. + */ +public class VarMapperELContext extends ELContext { + + private static final Logger logger = System.getLogger(VarMapperELContext.class.getName()); + + private final VariableMapper varMapper; + + private final CompositeELResolver compResolver; + + /* + * Constructor. + */ + public VarMapperELContext(Properties testProps) { + this.compResolver = new CompositeELResolver(); + varMapper = this.getVariableMapperImpl(testProps); + } + + public ELResolver getELResolver() { + ELResolver elResolver; + this.compResolver.add(new VariableELResolver()); + this.compResolver.add(new jakarta.el.BeanELResolver()); + elResolver = (ELResolver) compResolver; + + return elResolver; + } + + public ELContext getELContext() { + return (ELContext) (this); + } + + public VariableMapper getVariableMapper() { + return varMapper; + } + + public FunctionMapper getFunctionMapper() { + return null; + } + + private Object getImplSpecificInstance(String classname) { + + Class clazz; + Object instance = null; + + try { + clazz = Class.forName(classname); + instance = clazz.newInstance(); + } catch (ClassNotFoundException cnfe) { + logger.log(Logger.Level.ERROR, "ClassNotFoundException: " + cnfe.getMessage()); + } catch (InstantiationException ie) { + logger.log(Logger.Level.ERROR, "InstantiationException: " + ie.getMessage()); + } catch (IllegalAccessException iae) { + logger.log(Logger.Level.ERROR, "IllegalAccessException: " + iae.getMessage()); + } + return instance; + } + + private VariableMapper getVariableMapperImpl(Properties testProps) { + String implSpecificClassName = testProps.getProperty("variable.mapper"); + + return (implSpecificClassName == null) ? null + : (VariableMapper) getImplSpecificInstance(implSpecificClassName); + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/EmployeeELResolver.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/EmployeeELResolver.java new file mode 100644 index 0000000000..107e63233e --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/EmployeeELResolver.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elresolver; + +import java.util.Iterator; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ELResolver; + +/* This simple EL Resolver resolves only method expressions of + * the form ${worker.methodName}, where 'worker' is resolved to + * com.sun.ts.tests.el.spec.language.EmployeeBean and 'methodName' is one of its + * methods. + */ + +public class EmployeeELResolver extends ELResolver { + + private static final String FIRST_NAME = "Ricky"; + + private static final String LAST_NAME = "Bobby"; + + public Object getValue(ELContext context, Object base, Object property) + throws ELException { + if (context == null) + throw new NullPointerException(); + + Object result = null; + String propertyName = property.toString(); + + if (base == null) { + // Resolving first variable (e.g. ${worker}). + if ("worker".equals(propertyName)) { + result = "worker has no name!"; + } + + } else if ((base instanceof String) && ("firstName".equals(property))) { + + result = EmployeeELResolver.FIRST_NAME; + + } else if ((base instanceof String) && ("lastName".equals(property))) { + + result = EmployeeELResolver.LAST_NAME; + } + + if (result != null) + context.setPropertyResolved(true); + return result; + } + + public Class getType(ELContext context, Object base, Object property) + throws ELException { + if (context == null) + throw new NullPointerException(); + + String propertyName = property.toString(); + if ((base == null && propertyName.equals("worker")) + || (base instanceof String && base.equals("worker"))) + context.setPropertyResolved(true); + + // we never set a value + return null; + } + + public void setValue(ELContext context, Object base, Object property, + Object value) { + if (context == null) + throw new NullPointerException(); + + if ((base == null && "worker".equals(property)) + || (base instanceof String && base.equals("worker"))) + context.setPropertyResolved(true); + } + + public boolean isReadOnly(ELContext context, Object base, Object property) { + if (context == null) + throw new NullPointerException(); + + String propertyName = property.toString(); + if ((base == null && propertyName.equals("worker")) + || (base instanceof String && base.equals("worker"))) + context.setPropertyResolved(true); + return true; + } + + public Iterator getFeatureDescriptors(ELContext context, Object base) { + return null; + } + + public Class getCommonPropertyType(ELContext context, Object base) { + if (base == null) + return Object.class; + return null; + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/common/elresolver/EnumELResolver.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/EnumELResolver.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/common/elresolver/EnumELResolver.java rename to el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/EnumELResolver.java diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/FunctionELResolver.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/FunctionELResolver.java new file mode 100644 index 0000000000..786ea73847 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/FunctionELResolver.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elresolver; + +import java.util.Iterator; + +import com.sun.ts.tests.el.common.functionmapper.TCKFunctionMapper; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ELResolver; + +/* This ELResolver resolves only functions mapped by the TCKFunctionMapper. + * It does not allow variables to be set. +*/ + +public class FunctionELResolver extends ELResolver { + + public Object getValue(ELContext context, Object base, Object property) + throws ELException { + if (context == null) + throw new NullPointerException(); + + Object result = null; + if (base == null) { + context.setPropertyResolved(true); + String[] function = property.toString().split(":", 2); + + // Strip off parentheses + String localname = function[1].substring(0, function[1].length() - 3); + result = new TCKFunctionMapper().resolveFunction(function[0], localname); + } + + return result; + } + + public Class getType(ELContext context, Object base, Object property) + throws ELException { + if (context == null) + throw new NullPointerException(); + + if (base == null) + context.setPropertyResolved(true); + + return null; + } + + public void setValue(ELContext context, Object base, Object property, + Object value) { + if (context == null) + throw new NullPointerException(); + + if (base == null) + context.setPropertyResolved(true); + } + + public boolean isReadOnly(ELContext context, Object base, Object property) { + if (context == null) + throw new NullPointerException(); + + if (base == null) + context.setPropertyResolved(true); + return false; + } + + public Iterator getFeatureDescriptors(ELContext context, Object base) { + return null; + } + + public Class getCommonPropertyType(ELContext context, Object base) { + if (base == null) + return Object.class; + return null; + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VariableELResolver.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VariableELResolver.java new file mode 100644 index 0000000000..7fb8e4e0f9 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VariableELResolver.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elresolver; + +import java.beans.FeatureDescriptor; +import java.util.Hashtable; +import java.util.Iterator; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ELResolver; + +public class VariableELResolver extends ELResolver { + + private Hashtable varTable; + + public Object getValue(ELContext context, Object base, Object property) + throws ELException { + if (context == null) { + throw new NullPointerException(); + } + + Object result = null; + if (base == null) { + context.setPropertyResolved(true); + if (varTable != null) { + result = varTable.get(property.toString()); + } + } + + return result; + } + + public Class getType(ELContext context, Object base, Object property) + throws ELException { + if (context == null) { + throw new NullPointerException(); + } + + if (base == null) { + context.setPropertyResolved(true); + } + + return null; + } + + public void setValue(ELContext context, Object base, Object property, + Object value) { + if (context == null) { + throw new NullPointerException(); + } + + if (varTable == null) { + varTable = new Hashtable(); + } + + if (value == null) { + varTable = new Hashtable(); + varTable.clear(); + return; + } + + if (base == null) { + varTable.put(property.toString(), value); + context.setPropertyResolved(true); + } else { + varTable.put(base, value); + context.setPropertyResolved(true); + } + } + + public boolean isReadOnly(ELContext context, Object base, Object property) { + if (context == null) { + throw new NullPointerException(); + } + + if (base == null) { + context.setPropertyResolved(true); + } + return false; + } + + public Iterator getFeatureDescriptors(ELContext context, + Object base) { + return null; + } + + public Class getCommonPropertyType(ELContext context, Object base) { + if (base == null) { + return Object.class; + } + return null; + } + + // This method is not required by the ELResolver API. It is for + // removing all entries from the the VariableELResolver's + // static hashtable between test invocations. + public void cleanup() { + + if (varTable != null) { + varTable.clear(); + } + + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VectELResolver.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VectELResolver.java new file mode 100644 index 0000000000..0897f865df --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/elresolver/VectELResolver.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elresolver; + +import java.util.Iterator; +import java.util.Vector; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ELResolver; + +/* This simple EL Resolver resolves only method expressions of + the form ${vect.methodName}, where 'vect' is resolved to java.util.Vector + and 'methodName' is one of its methods. +*/ + +public class VectELResolver extends ELResolver { + + public Object getValue(ELContext context, Object base, Object property) + throws ELException { + if (context == null) + throw new NullPointerException(); + + if (base == null && "vect".equals(property)) { + context.setPropertyResolved(true); + return new Vector(); + } + return null; + } + + public Class getType(ELContext context, Object base, Object property) + throws ELException { + if (context == null) + throw new NullPointerException(); + + if (base == null && "vect".equals(property)) + context.setPropertyResolved(true); + + // we never set a value + return null; + } + + public void setValue(ELContext context, Object base, Object property, + Object value) { + if (context == null) + throw new NullPointerException(); + + if (base == null && "vect".equals(property)) + context.setPropertyResolved(true); + } + + public boolean isReadOnly(ELContext context, Object base, Object property) { + if (context == null) + throw new NullPointerException(); + + if (base == null && "vect".equals(property)) + context.setPropertyResolved(true); + return true; + } + + public Iterator getFeatureDescriptors(ELContext context, Object base) { + return null; + } + + public Class getCommonPropertyType(ELContext context, Object base) { + return null; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java new file mode 100644 index 0000000000..cfb9efabac --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.functionmapper; + +import java.lang.reflect.Method; +import java.util.HashMap; + +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.FunctionMapper; + +import java.lang.System.Logger; + +/* A simple implementation of FunctionMapper that maps only + a single function to Integer.valueOf(String). +*/ + +public class TCKFunctionMapper extends FunctionMapper { + + private static final Logger logger = System.getLogger(TCKFunctionMapper.class.getName()); + + private static final String KEY = "Int:val"; + + private final Class clazz = Integer.class; + + private final HashMap fMap; + + public TCKFunctionMapper() { + + fMap = new HashMap(); + try { + fMap.put(KEY, clazz.getMethod("valueOf", String.class)); + } catch (NoSuchMethodException nsme) { + logger.log(Logger.Level.ERROR, "CONSTRUCTOR: Can't find method!"); + ELTestUtil.printStackTrace(nsme); + } + } + + public Method resolveFunction(String prefix, String localName) { + + String key = prefix + ":" + localName; + return fMap.get(key); + } + + public void update() { + + fMap.remove(KEY); + try { + fMap.put(KEY, clazz.getMethod("toString", int.class)); + } catch (NoSuchMethodException nsme) { + logger.log(Logger.Level.ERROR, "UPDATE: Can't find method!"); + ELTestUtil.printStackTrace(nsme); + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/common/spec/Book.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/spec/Book.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/common/spec/Book.java rename to el-tck/src/main/java/com/sun/ts/tests/el/common/spec/Book.java diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Customer.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Customer.java new file mode 100644 index 0000000000..c375075e6b --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Customer.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +import java.util.ArrayList; +import java.util.List; + +public class Customer { + int customerID; + + String name; + + String address; + + String city; + + String country; + + String phone; + + List orders; + + public Customer(int customerID, String name, String address, String city, + String country, String phone) { + this.customerID = customerID; + this.name = name; + this.address = address; + this.city = city; + this.country = country; + this.phone = phone; + this.orders = new ArrayList(); + } + + public String toString() { + return "Customer: " + customerID + ", " + name + ", " + city + ", " + + country; + } + + public int getCustomerID() { + return customerID; + } + + public String getName() { + return name; + } + + public String getAddress() { + return address; + } + + public String getCity() { + return city; + } + + public String getCountry() { + return country; + } + + public String getPhone() { + return phone; + } + + public List getOrders() { + return orders; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/DataBase.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/DataBase.java new file mode 100644 index 0000000000..037702d420 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/DataBase.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +import java.util.ArrayList; +import java.util.List; + +public class DataBase { + + private int curCustomer = 100; + + private int curProduct = 200; + + private int curOrder = 10; + + private boolean inited; + + private List customers; + + private List products; + + private List orders; + + private List ints; + + public List getInts() { + return this.ints; + } + + public List getCustomers() { + return this.customers; + } + + public List getProducts() { + return this.products; + } + + public List getOrders() { + return this.orders; + } + + public void init() { + if (inited) { + return; + } + + inited = true; + customers = new ArrayList(); + orders = new ArrayList(); + products = new ArrayList(); + ints = new ArrayList(); + + initCustomer(); + initProduct(); + initOrder(); + initNums(); + } + + void initNums() { + for (int i = 0; i < 10; i++) { + ints.add(Integer.valueOf(i)); + } + } + + void initCustomer() { + c("John Doe", "123 Willow Road", "Menlo Park", "USA", "650-734-2187"); + c("Mary Lane", "75 State Street", "Atlanta", "USA", "302-145-8765"); + c("Charlie Yeh", "5 Nathan Road", "Kowlon", "Hong Kong", "11-7565-2323"); + } + + void initProduct() { + p("Eagle", "book", 12.50, 100); // id: 200 + p("Coming Home", "dvd", 8.00, 50); // id: 201 + p("Greatest Hits", "cd", 6.5, 200); // id: 202 + p("History of Golf", "book", 11.0, 30); // id: 203 + p("Toy Story", "dvd", 10.00, 1000); // id: 204 + p("iSee", "book", 12.50, 150); // 205 + } + + void initOrder() { + o(100, new Date(2010, 2, 18), 20.80); + o(100, new Date(2011, 5, 3), 34.50); + o(100, new Date(2011, 8, 2), 210.75); + o(101, new Date(2011, 1, 15), 50.23); + o(101, new Date(2012, 1, 3), 126.77); + o(102, new Date(2011, 4, 15), 101.20); + } + + void c(String name, String address, String city, String country, + String phone) { + customers + .add(new Customer(curCustomer++, name, address, city, country, phone)); + } + + void o(int customerID, Date orderDate, double total) { + Order order = new Order(curOrder++, customerID, orderDate, total); + this.orders.add(order); + findCustomer(customerID).getOrders().add(order); + } + + void p(String name, String category, double unitPrice, int unitsInStock) { + products.add( + new Product(curProduct++, name, category, unitPrice, unitsInStock)); + } + + private Customer findCustomer(int id) { + for (Customer customer : customers) { + if (customer.customerID == id) { + return customer; + } + } + return null; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Date.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Date.java new file mode 100644 index 0000000000..6f1a238d82 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Date.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +public class Date { + int year, month, date; + + public Date(int year, int month, int date) { + this.year = year; + this.month = month; + this.date = date; + } + + public int getYear() { + return year; + } + + public int getMonth() { + return month; + } + + public int getDate() { + return date; + } + + public String toString() { + return "" + month + "/" + date + "/" + year; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java new file mode 100644 index 0000000000..a5ef1306e6 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id: $ + */ +package com.sun.ts.tests.el.common.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.io.PrintWriter; +import java.io.StringWriter; + +import java.lang.System.Logger; + +public final class ELTestUtil { + + private static final Logger logger = System.getLogger(ELTestUtil.class.getName()); + + public static final String NL = System.getProperty("line.separator", "\n"); + + public static final String PASS = "Test PASSED"; + + public static final String FAIL = "Test FAILED"; + + private ELTestUtil() { + throw new IllegalStateException(); + } + + /** + * Checks to see if a NullPointerException is thrown from a given + * method(methName) from a given Class(className). use this method for any + * none Abstract classes you wish to test. + * + * @param className + * - The Class that has the method under test. + * @param methName + * - The method that you want to test. + * @param argTypes + * - The type value of the arguments for the method under test. + * @param params + * - The parameters you are feeding into the method under test. + * + * @throws Exception + */ + public static void checkForNPE(String className, String methName, + Class[] argTypes, Object[] params) throws Exception { + + try { + checkForNPE(Class.forName(className), methName, argTypes, params); + + } catch (ClassNotFoundException cnfe) { + throw new Exception(FAIL + NL + cnfe.toString()); + } + + } // End checkForNPE + + /** + * Checks to see if a NullPointerException is thrown from a given + * method(methName) from a given Class. use this method for any Abstract + * classes you wish to test. You can pass in the instantiated class that you + * want to test. + * + * @param Class + * - The class you want to test. + * @param methName + * - The method that you want to test. + * @param argTypes + * - The type value of the arguments for the method under test. + * @param params + * - The parameters you are feeding into the method under test. + * + * @throws Exception + */ + public static void checkForNPE(Class clazz, String methName, + Class[] argTypes, Object[] params) throws Exception { + + try { + checkForNPE(clazz.newInstance(), methName, argTypes, params); + + } catch (Exception e) { + throw new Exception(FAIL + NL + e.toString()); + } + + } // End checkForNPE + + /** + * Checks to see if a NullPointerException is thrown from a given + * method(methName) from a given Class. use this method for any Abstract + * classes you wish to test. You can pass in the instantiated class that you + * want to test. + * + * @param object + * - The Object you want to test. + * @param methName + * - The method that you want to test. + * @param argTypes + * - The type value of the arguments for the method under test. + * @param params + * - The parameters you are feeding into the method under test. + * + * @throws Exception + */ + public static void checkForNPE(Object object, String methName, + Class[] argTypes, Object[] params) throws Exception { + + checkForException(object, methName, argTypes, params, + new NullPointerException()); + + } // End checkForNPE + + /** + * Checks to see if a ClassNotFoundException is thrown + * + * @param object + * - The Object you want to test. + * @param methName + * - The method that you want to test. + * @param argTypes + * - The type value of the arguments for the method under test. + * @param params + * - The parameters you are feeding into the method under test. + * + * @throws Exception + */ + public static void checkForCNFE(Object object, String methName, + Class[] argTypes, Object[] params) throws Exception { + + checkForException(object, methName, argTypes, params, + new ClassNotFoundException()); + + } // End checkForCNFE + + /** + * Checks to see if a NoSuchMethodException is thrown + * + * @param object + * - The Object you want to test. + * @param methName + * - The method that you want to test. + * @param argTypes + * - The type value of the arguments for the method under test. + * @param params + * - The parameters you are feeding into the method under test. + * + * @throws Exception + */ + public static void checkForNSME(Object object, String methName, + Class[] argTypes, Object[] params) throws Exception { + + checkForException(object, methName, argTypes, params, + new NoSuchMethodException()); + + } // End checkForCNFE + + // ------------------------------------ private methods + + /* + * Checks to see if a NoSuchMethodException is thrown + * + * @param object - The Object you want to test. + * + * @param methName - The method that you want to test. + * + * @param argTypes - The type value of the arguments for the method under + * test. + * + * @param params - The parameters you are feeding into the method under test. + * + * @throws Exception + */ + private static void checkForException(Object object, String methName, + Class[] argTypes, Object[] params, Object exceptionType) throws Exception { + + StringBuffer buff = new StringBuffer(); + String className = object.getClass().getName(); + String exceptionMess = buildMess(exceptionType.getClass().getSimpleName()); + + try { + Method execMeth = object.getClass().getMethod(methName, argTypes); + execMeth.invoke(object, params); + + buff.append(FAIL + " No Exception thrown!" + NL + "Expected a " + + exceptionType.getClass().getSimpleName() + " to be thrown!" + NL + + "when testing: " + className + "." + methName); + + } catch (InvocationTargetException ite) { + if (exceptionType.getClass().isInstance(ite.getCause())) { + logger.log(Logger.Level.INFO, PASS); + return; + + } else { + buff.append(exceptionMess + ite.getCause().getClass().getSimpleName() + + NL + "When testing: " + className + "." + methName + NL + + ite.getCause().toString()); + } + + } catch (Throwable t) { + buff.append(exceptionMess + t.getClass().getSimpleName() + NL + + "When testing: " + className + "." + methName + NL + t.toString()); + } + + throw new Exception(FAIL + NL + buff.toString()); + + } // End checkForException + + private static String buildMess(String exceptionName) { + return FAIL + " Unexpected Exception Thrown!" + NL + "Expected: " + + exceptionName + NL + "Received: "; + } + + public static void printStackTrace(Throwable e) { + if (e == null) { + return; + } + try { + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + e.printStackTrace(writer); + writer.close(); + } catch (Exception E) { + } + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java new file mode 100644 index 0000000000..f6a917b597 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.MathContext; +import java.math.RoundingMode; +import java.util.Enumeration; +import java.util.Hashtable; + + +import com.sun.ts.tests.el.common.elcontext.SimpleELContext; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ELResolver; +import jakarta.el.ExpressionFactory; +import jakarta.el.MethodExpression; +import jakarta.el.PropertyNotFoundException; +import jakarta.el.PropertyNotWritableException; +import jakarta.el.ValueExpression; + +import java.lang.System.Logger; + +public final class ExprEval { + + private static final Logger logger = System.getLogger(ExprEval.class.getName()); + + // Suppress default constructor for non-instantiability + private ExprEval() { + } + + public static String buildElExpr(boolean deferred, String operation) { + + String sandwich = null; + if (operation == null) + sandwich = "{A}"; + else if ("unary_minus".equals(operation)) + sandwich = "{-A}"; + else if ("unary_not".equals(operation)) + sandwich = "{not A}"; + else if ("unary_bang".equals(operation)) + sandwich = "{! A}"; + else if ("empty".equals(operation)) + sandwich = "{empty A}"; + else if ("conditional".equals(operation)) + sandwich = "{A " + "?" + "B" + ":" + " C}"; + else // binary operation + sandwich = "{A " + operation + " B}"; + + return (deferred) ? "#" + sandwich : "$" + sandwich; + } + + /** + * Evaluates the ValueExpression expression relative to the provided context + * and resolverType, then returns the resulting value. + * + * @param exprStr + * - the String for the expression to be evaluated e.g. "${A + B}" + * @param nameVals + * - an array of NameValuePair objects, each of which contains an + * expression variable and the value to which it is to be set. + * @param expectedClass + * - the type of the result produced by evaluating the expression. + * @param resolverType + * - The type of ELResolver to use for expression resolution. + * + * @return - The result of the expression evaluation. + * + * @throws jakarta.el.ELException + * @throws jakarta.el.PropertyNotFoundException + * @throws jakarta.el.PropertyNotWritableException + */ + public static Object evaluateValueExpression(String exprStr, + NameValuePair[] nameVals, Class expectedClass, ResolverType resolverType) + throws ELException, PropertyNotFoundException, + PropertyNotWritableException { + + // get what we need to create the expression + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new SimpleELContext(resolverType)).getELContext(); + ELResolver resolver = context.getELResolver(); + ExprEval.cleanup(); + + // set the values of variables to be used in the expression + if (nameVals == null) { + resolver.setValue(context, null, "A", null); + logger.log(Logger.Level.TRACE, "setting var 'A' to value null"); + resolver.setValue(context, null, "B", null); + logger.log(Logger.Level.TRACE, "setting var 'B' to value null"); + + } else { + for (int i = 0; i < nameVals.length; ++i) { + String name = nameVals[i].getName(); + Object val = nameVals[i].getValue(); + logger.log(Logger.Level.TRACE, "setting var " + name + " to value " + val); + resolver.setValue(context, null, name, val); + } + } + + // create the expression + logger.log(Logger.Level.TRACE, "Creating ValueExpression"); + logger.log(Logger.Level.TRACE, "context is " + context.getClass().toString()); + logger.log(Logger.Level.TRACE, "exprStr is " + exprStr); + logger.log(Logger.Level.TRACE, "expectedClass is " + expectedClass.toString()); + logger.log(Logger.Level.TRACE, + "resolver is " + context.getELResolver().getClass().toString()); + ValueExpression vexp = expFactory.createValueExpression(context, exprStr, + expectedClass); + + // now evaluate + return vexp.getValue(context); + } + + /** + * Evaluates the ValueExpression expression relative to the provided context + * and the resolverType of + * com.sun.ts.tests.el.common.elresolver.VariableELResolver, then returns the + * resulting value. + * + * @param exprStr + * - the String for the expression to be evaluated e.g. "${A + B}" + * @param nameVals + * - an array of NameValuePair Objects, each of which contains an + * expression variable and the value to which it is to be set + * @param expectedClass + * - the type of the result produced by evaluating the expression. + * + * @return - The result of the expression evaluation. + * + * @throws jakarta.el.ELException + * @throws jakarta.el.PropertyNotFoundException + * @throws jakarta.el.PropertyNotWritableException + */ + public static Object evaluateValueExpression(String exprStr, + NameValuePair[] nameVals, Class expectedClass) throws ELException, + PropertyNotFoundException, PropertyNotWritableException { + + return ExprEval.evaluateValueExpression(exprStr, nameVals, expectedClass, + ResolverType.VARIABLE_ELRESOLVER); + } + + /** + * Used to evaluate MethodExpression() + * + * @param exprStr + * - Expression to be parsed as a MethodExpression. + * @param params + * - Parameters to pass to the method, or null if no parameters. + * @param expectedClass + * - Expected return type. + * @param resolverType + * - ELResolver to use for expression resolution. + * + * @return - the result of the method invocation. + * + * @throws jakarta.el.ELException + * @throws jakarta.el.PropertyNotFoundException + * @throws jakarta.el.PropertyNotWritableException + */ + public static Object evaluateMethodExpression(String exprStr, Class[] params, + Class expectedClass, ResolverType resolverType) throws ELException, + PropertyNotFoundException, PropertyNotWritableException { + + // get what we need to create the expression + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new SimpleELContext(resolverType)).getELContext(); + + // create the expression + MethodExpression mexp = expFactory.createMethodExpression(context, exprStr, + expectedClass, params); + + // now evaluate it + return mexp.invoke(context, params); + } + + /** + * @param exprStr + * - Expression to be parsed. + * @param exprVal + * - The value passed to ValueExpression.setValue(). + * @param expectedClass + * - Expected return type. + * + * @return - the result of the method invocation. + * + * @throws jakarta.el.ELException + * @throws jakarta.el.PropertyNotFoundException + * @throws jakarta.el.PropertyNotWritableException + * + */ + public static Object evaluateCoerceValueExpression(String exprStr, + Object exprVal, Class expectedClass) throws ELException, + PropertyNotFoundException, PropertyNotWritableException { + + // get what we need to create the expression + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new SimpleELContext(ResolverType.VARIABLE_ELRESOLVER)) + .getELContext(); + + // create the expression + ValueExpression vexp = expFactory.createValueExpression(context, exprStr, + expectedClass); + + // set expression value + vexp.setValue(context, exprVal); + + // grab the value for evaluation. + return vexp.getValue(context); + } + + /** + * Parse a ValueExpression once, evaluate it many times, while adding Context + * Objects to the ELContext one at a time. + * + * @param exprStr + * - Expression to be parsed. + * @param exprVal + * - The value passed to ValueExpression.setValue(). + * @param expectedClass + * - Expected return type. + * @param contextobj + * - a Hashtable of context objects in the form of key=Class, + * value=value. + * @throws jakarta.el.ELException + * @throws jakarta.el.PropertyNotFoundException + * @throws jakarta.el.PropertyNotWritableException + * @throws java.lang.ClassNotFoundException + * @return - status of the evaluation. + */ + public static boolean evaluateManyValueExpression(String exprStr, + Object exprVal, Class expectedClass, Hashtable contextobj) + throws ELException, PropertyNotFoundException, + PropertyNotWritableException, ClassNotFoundException { + + boolean result = true; + + // get what we need to create the expression + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new SimpleELContext(ResolverType.VARIABLE_ELRESOLVER)) + .getELContext(); + + // create the expression + ValueExpression vexp = expFactory.createValueExpression(context, exprStr, + expectedClass); + + // set expression value + vexp.setValue(context, exprVal); + + // start adding objects to the Context. + Enumeration keys = contextobj.keys(); + while (keys.hasMoreElements()) { + Class cl = (Class) keys.nextElement(); + Object value = contextobj.get(cl); + + // add the object + context.putContext(cl, value); + logger.log(Logger.Level.TRACE, "Adding value: " + "\"" + value + "\"" + " To Context!"); + + // test the expression + if (!(ExprEval.compareValue(exprVal, vexp.getValue(context)))) { + logger.log(Logger.Level.ERROR, "Expression Failed! After Adding: " + "\"" + value + + "\"" + " To Context"); + result = false; + } + } + + // return the status of the evaluation. + return result; + + } + + public static boolean compareClass(Object obj, Class expectedClass) { + + boolean isInstance = expectedClass.isInstance(obj); + if (!isInstance) { + logger.log(Logger.Level.ERROR, "Unexpected type for expression evaluation"); + logger.log(Logger.Level.ERROR, "Expected type: " + expectedClass.toString()); + logger.log(Logger.Level.ERROR, "Computed type: " + obj.getClass().toString()); + } + return isInstance; + } + + public static boolean compareValue(Object val, Object expectedVal) { + + if (!val.equals(expectedVal)) { + logger.log(Logger.Level.ERROR, "Unexpected value for expression evaluation"); + logger.log(Logger.Level.ERROR, "Expected value: " + expectedVal.toString()); + logger.log(Logger.Level.ERROR, "Computed value: " + val.toString()); + return false; + } + + return true; + } + + public static boolean compareValue(Boolean val, Boolean expectedVal) { + + if (!val.equals(expectedVal)) { + logger.log(Logger.Level.ERROR, "Unexpected value for expression evaluation"); + logger.log(Logger.Level.ERROR, "Expected value: " + expectedVal.toString()); + logger.log(Logger.Level.ERROR, "Computed value: " + val.toString()); + return false; + } + + return true; + } + + public static boolean compareValue(Double val, Float expectedVal, int eps) { + + BigDecimal a = new BigDecimal(val); + BigDecimal b = new BigDecimal(expectedVal); + + return compareValue(a, b, eps); + } + + public static boolean compareValue(Float val, Float expectedVal, int eps) { + + BigDecimal a = new BigDecimal(val); + BigDecimal b = new BigDecimal(expectedVal); + + return compareValue(a, b, eps); + } + + public static boolean compareValue(Long val, Long expectedVal, int eps) { + + BigDecimal a = new BigDecimal(val); + BigDecimal b = new BigDecimal(expectedVal); + + return compareValue(a, b, eps); + } + + public static boolean compareValue(BigInteger val, BigInteger expectedVal, + int eps) { + + BigDecimal a = new BigDecimal(val); + BigDecimal b = new BigDecimal(expectedVal); + + return compareValue(a, b, eps); + } + + public static boolean compareValue(BigDecimal val, BigDecimal expectedVal, + int eps) { + + MathContext mc = new MathContext(eps, RoundingMode.DOWN); + BigDecimal a = val.abs(mc); + BigDecimal b = expectedVal.abs(mc); + + if (!(0 == a.compareTo(b))) { + logger.log(Logger.Level.ERROR, "Unexpected value for expression evaluation"); + logger.log(Logger.Level.ERROR, "Expected value: " + expectedVal); + logger.log(Logger.Level.ERROR, "Computed value: " + val); + return false; + } + + return true; + } + + // This method is used to remove resolvable items from the static + // hashtable used by the SimpleELContext's VariableELResolver. + // It is meant to be called at the end of a test. + public static void cleanup() { + (new SimpleELContext()).cleanup(); + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Fault.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Fault.java new file mode 100644 index 0000000000..dea2527ac7 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Fault.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.el.common.util; + +import java.io.PrintStream; +import java.io.PrintWriter; + + + +/** + * This exception must be thrown to signify a + * test failure. Overrides 3 printStackTrace methods to preserver the original + * stack trace. Using setStackTraceElement() would be more elegant but it is + * not available prior to j2se 1.4. + * + * @author Kyle Grucci + */ + public class Fault extends Exception { + private static final long serialVersionUID = -1574745208867827913L; + + public Throwable t; + + /** + * creates a Fault with a message + */ + public Fault(String msg) { + super(msg); + // TestUtil.logErr(msg); + } + + /** + * creates a Fault with a message. + * + * @param msg + * the message + * @param t + * prints this exception's stacktrace + */ + public Fault(String msg, Throwable t) { + super(msg); + this.t = t; + // TestUtil.logErr(msg, t); + } + + /** + * creates a Fault with a Throwable. + * + * @param t + * the Throwable + */ + public Fault(Throwable t) { + super(t); + this.t = t; + } + + /** + * Prints this Throwable and its backtrace to the standard error stream. + * + */ + public void printStackTrace() { + if (this.t != null) { + this.t.printStackTrace(); + } else { + super.printStackTrace(); + } + } + + /** + * Prints this throwable and its backtrace to the specified print stream. + * + * @param s + * PrintStream to use for output + */ + public void printStackTrace(PrintStream s) { + if (this.t != null) { + this.t.printStackTrace(s); + } else { + super.printStackTrace(s); + } + } + + /** + * Prints this throwable and its backtrace to the specified print writer. + * + * @param s + * PrintWriter to use for output + */ + public void printStackTrace(PrintWriter s) { + if (this.t != null) { + this.t.printStackTrace(s); + } else { + super.printStackTrace(s); + } + } + + @Override + public Throwable getCause() { + return t; + } + + @Override + public synchronized Throwable initCause(Throwable cause) { + if (t != null) + throw new IllegalStateException("Can't overwrite cause"); + if (!Exception.class.isInstance(cause)) + throw new IllegalArgumentException("Cause not permitted"); + this.t = (Exception) cause; + return this; + } + } diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/MethodsBean.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/MethodsBean.java new file mode 100644 index 0000000000..46bb82e368 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/MethodsBean.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ +package com.sun.ts.tests.el.common.util; + +public class MethodsBean { + + public String targetA(CharSequence arg0) { + return "CharSequence"; + } + + public String targetA(String arg0) { + return "String"; + } + + public String targetA(Long arg0) { + return "Long"; + } + + public String targetB(CharSequence arg0) { + return "CharSequence"; + } + + public String targetB(Long arg0) { + return "Long"; + } + + public String targetC(CharSequence arg0, CharSequence arg1) { + return "CharSequence-CharSequence"; + } + + public String targetC(String arg0, String... varArgs) { + return "String-Strings"; + } + + public String targetD(Long arg0, Long arg1) { + return "Long-Long"; + } + + public String targetD(String arg0, String... varArgs) { + return "String-Strings"; + } + + public String targetE(Long arg0, Long arg1) { + return "Long-Long"; + } + + public String targetE(String arg0, String arg1) { + return "String-String"; + } + + @Deprecated + public String targetF(String arg0, Long arg1) { + return "String-Long"; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/NameValuePair.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/NameValuePair.java new file mode 100644 index 0000000000..26a5de02b6 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/NameValuePair.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +// This class holds the name of a variable in an Expression +// and the value to which the variable is to be set. +public class NameValuePair { + + private final String name; + + private final Object value; + + public NameValuePair(String name, Object value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public Object getValue() { + return value; + } + + /* + * Builds a NameValuePair[] with values assigned to Tag Names A and B. + */ + public static NameValuePair[] buildNameValuePair(Object a, Object b) { + + NameValuePair value1 = new NameValuePair("A", a); + NameValuePair value2 = new NameValuePair("B", b); + + NameValuePair values[] = { value1, value2 }; + + return values; + } + + /* + * Builds a NameValuePair[] with a value assigned to Tag Name A. + */ + public static NameValuePair[] buildUnaryNameValue(Object a) { + + NameValuePair value1 = new NameValuePair("A", a); + + NameValuePair value[] = { value1 }; + + return value; + } + + /* + * Builds a NameValuePair[] with values assigned to Tag Names A, B, and C. + */ + public static NameValuePair[] buildConditionalNameValue(Object a, Object b, + Object c) { + + NameValuePair value1 = new NameValuePair("A", a); + NameValuePair value2 = new NameValuePair("B", b); + NameValuePair value3 = new NameValuePair("C", c); + + NameValuePair values[] = { value1, value2, value3 }; + + return values; + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Order.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Order.java new file mode 100644 index 0000000000..49af247a8e --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Order.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.el.common.util; + +public class Order { + + int orderID; + + int customerID; + + Date orderDate; + + double total; + + public Order(int orderID, int customerID, Date orderDate, double total) { + this.orderID = orderID; + this.customerID = customerID; + this.orderDate = orderDate; + this.total = total; + } + + public String toString() { + return "Order: " + orderID + ", " + customerID + ", " + orderDate.toString() + + ", " + total; + } + + public int getOrderID() { + return orderID; + } + + public int getCustomerID() { + return customerID; + } + + public Date getOrderDate() { + return orderDate; + } + + public double getTotal() { + return total; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Product.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Product.java new file mode 100644 index 0000000000..7970bf4a1f --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Product.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.el.common.util; + +public class Product { + + public int productID; + + public String name; + + public String category; + + public double unitPrice; + + public int unitsInStock; + + Product(int productID, String name, String category, double unitPrice, + int unitsInStock) { + + this.productID = productID; + this.name = name; + this.category = category; + this.unitPrice = unitPrice; + this.unitsInStock = unitsInStock; + } + + public String toString() { + return "Product: " + productID + ", " + name + ", " + category + ", " + + unitPrice + ", " + unitsInStock; + } + + public int getProductID() { + return productID; + } + + public String getName() { + return name; + } + + public String getCategory() { + return category; + } + + public double getUnitPrice() { + return unitPrice; + } + + public int getUnitsInStock() { + return unitsInStock; + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ResolverType.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ResolverType.java new file mode 100644 index 0000000000..f8beb2ccde --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/ResolverType.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +public enum ResolverType { + EMPLOYEE_ELRESOLVER, VARIABLE_ELRESOLVER, VECT_ELRESOLVER; +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleBean.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleBean.java new file mode 100644 index 0000000000..7f62e2d116 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleBean.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2007, 2021 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.el.common.util; + +import java.io.Serializable; + +public class SimpleBean implements Serializable, SimpleInterface { + + private String fullName = "Doug Donahue"; // Default Setting + + private String intention; + + public void setIntention(String s) { + intention = s; + } + + public String getIntention() { + return intention; + } + + /** + * Set full name using the pattern firstName + " " + lastName. + * + * @param firstName + * @param lastName + */ + public void setFullName(String firstName, String lastName) { + this.fullName = firstName + " " + lastName; + } + + /** + * + * @param firstName + * - first name @String + * @param lastName + * - last Name + * @return true is full name matches the given firstName + " " + lastName + * pattern. + */ + public boolean isName(String firstName, String lastName) { + boolean result = Boolean.FALSE; + String testName = firstName + " " + lastName; + + if (testName.equals(fullName)) { + result = true; + } + + return result; + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleInterface.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleInterface.java new file mode 100644 index 0000000000..ec209465c5 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/SimpleInterface.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ +package com.sun.ts.tests.el.common.util; + +/** + * Defines an interface with default methods: one read-only, one read-write. + */ +public interface SimpleInterface { + default String getDefaultRO() { + return "RO"; + } + default String getDefaultRW() { + return "RW"; + } + default void setDefaultRW(String ignored) { + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/TestNum.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/TestNum.java new file mode 100644 index 0000000000..dfd191d68d --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/TestNum.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.el.common.util; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; + +/** + * Used to store lists that will be utilized accross the board for a common + * point of reference when testing. + */ +public final class TestNum { + + private static final String COMPARATOR = "1"; + + private static ArrayList floatList; + + private static ArrayList numberList; + + /** + * Private as this class will only have static methods and members. + */ + private TestNum() { + } + + /** + * Used for a common list of Float values when testing. + * + * @return - A set list of common Floats that we use as test values. + */ + public static ArrayList getFloatList() { + + floatList = new ArrayList(); + + floatList.add(Float.valueOf("1.00005f")); + floatList.add(Float.valueOf("1.5E-4d")); + floatList.add(Float.valueOf("1.5E+4")); + floatList.add(Float.valueOf("1.5e+4")); + + return floatList; + + } + + /** + * Used a common reference point for Number types and a common value is + * assigned (1). + * + * @return - A common List of Number types with a constant value. + */ + public static ArrayList getNumberList() { + + numberList = new ArrayList(); + + numberList.add(BigDecimal.valueOf(Long.valueOf(COMPARATOR))); + numberList.add(Double.valueOf(COMPARATOR)); + numberList.add(Float.valueOf(COMPARATOR)); + numberList.add(COMPARATOR + ".0"); + numberList.add(COMPARATOR + "e0"); + numberList.add(COMPARATOR + "E0"); + numberList.add(BigInteger.valueOf(Long.valueOf(COMPARATOR))); + numberList.add(Long.valueOf(COMPARATOR)); + numberList.add(Integer.valueOf(COMPARATOR)); + numberList.add(Short.valueOf(COMPARATOR)); + numberList.add(Byte.valueOf(COMPARATOR)); + + return numberList; + + } +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/TypesBean.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/TypesBean.java new file mode 100644 index 0000000000..2ef49fd057 --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/TypesBean.java @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.HashMap; + +/** + * This is a simple bean with different type values for testing Expressions. + * + */ +public class TypesBean { + private final static String COMPARATOR = "1"; + + private static HashMap, String> numberMap; + + private BigDecimal tckBigDecimal = BigDecimal + .valueOf(Long.valueOf(COMPARATOR)); + + private Double tckDouble = Double.valueOf(COMPARATOR); + + private Float tckFloat = Float.valueOf(COMPARATOR); + + private BigInteger tckBigInteger = BigInteger + .valueOf(Long.valueOf(COMPARATOR)); + + private Long tckLong = Long.valueOf(COMPARATOR); + + private Integer tckInteger = Integer.valueOf(COMPARATOR); + + private Short tckShort = Short.valueOf(COMPARATOR); + + private Byte tckByte = Byte.valueOf(COMPARATOR); + + private Boolean tckBoolean = true; + + private Byte tckNull = null; + + // Getter Setter for Type BigDeciaml + public BigDecimal getTckBigDecimal() { + return tckBigDecimal; + } + + public void setTckBigDecimal(BigDecimal tckBigDecimal) { + this.tckBigDecimal = tckBigDecimal; + } + + // Getter Setter for Type Double + public Double getTckDouble() { + return tckDouble; + } + + public void setTckDouble(Double tckDouble) { + this.tckDouble = tckDouble; + } + + // Getter Setter for Type Float + public Float getTckFloat() { + return tckFloat; + } + + public void setTckFloat(Float tckFloat) { + this.tckFloat = tckFloat; + } + + // Getter Setter for Type Integer + public BigInteger getTckBigInteger() { + return tckBigInteger; + } + + public void setTckBigInteger(BigInteger tckBigInteger) { + this.tckBigInteger = tckBigInteger; + } + + // Getter Setter for Type Long + public Long getTckLong() { + return tckLong; + } + + public void setTckLong(Long tckLong) { + this.tckLong = tckLong; + } + + // Getter Setter for Type Integer + public Integer getTckInteger() { + return tckInteger; + } + + public void setTckInteger(Integer tckInt) { + this.tckInteger = tckInt; + } + + // Getter Setter for Type Short + public Short getTckShort() { + return tckShort; + } + + public void setTckShort(Short tchShort) { + this.tckShort = tchShort; + } + + // Getter Setter for Type Byte + public Byte getTckByte() { + return tckByte; + } + + public void setTckByte(Byte tckByte) { + this.tckByte = tckByte; + } + + // Getter Setter for Type Boolean + public Boolean getTckBoolean() { + return tckBoolean; + } + + public void setTckBoolean(Boolean tckBoolean) { + this.tckBoolean = tckBoolean; + } + + public Byte getTckNull() { + return tckNull; + } + + public void setTckNullString(Byte tckNull) { + this.tckNull = tckNull; + } + + /** + * This method will return an HaashMap of Key = Class, Value = String for the + * purpose of using them in an ElProcessor expression. + * + * + * @return - A common List of Number types with a constant value. + */ + public static HashMap, String> getNumberMap() { + + numberMap = new HashMap, String>(); + + numberMap.put(BigDecimal.class, "b = types.tckBigDecimal"); + numberMap.put(Double.class, "b = types.tckDouble"); + numberMap.put(Float.class, "b = types.tckFloat"); + numberMap.put(BigInteger.class, "b = types.tckBigInteger"); + numberMap.put(Long.class, "b = types.tckLong"); + numberMap.put(Integer.class, "b = types.tckInteger"); + numberMap.put(Short.class, "b = types.tckShort"); + numberMap.put(Byte.class, "b = types.tckByte"); + + return numberMap; + + } + +} diff --git a/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Validator.java b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Validator.java new file mode 100644 index 0000000000..3c74a2926b --- /dev/null +++ b/el-tck/src/main/java/com/sun/ts/tests/el/common/util/Validator.java @@ -0,0 +1,998 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.util; + +import java.math.BigDecimal; +import java.math.BigInteger; + + +import jakarta.el.ELProcessor; + +import java.lang.System.Logger; + +public class Validator { + + private static final Logger logger = System.getLogger(Validator.class.getName()); + + private static Validator instance = null; + + protected Validator() { + // Exists only to defeat instantiation. + } + + private Validator getInstance() { + if (instance == null) { + instance = new Validator(); + } + return instance; + } + + /** + * This method is used to validate an expression that have at least one + * BigDecimal in it. We pass in one of the operands(testVal), the other + * operand is automatically picked up from the NumberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testBigDecimal(BigDecimal testVal, Object expectedVal, + String operator) throws Exception { + boolean pass = false; + Class returnType; + + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, + "*** Start " + "\"" + "BigDecimal" + "\"" + " Test Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are BigDecimal and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+=" (concatenation) then coerce both operands to + * String and concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "%" then the return type is Double. + } else if ("%".equals(operator)) { + + returnType = Double.class; + logger.log(Logger.Level.INFO, "Setting Expected Type: " + returnType.getName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, + Double.valueOf(((BigDecimal) expectedVal).doubleValue()))); + } else { + returnType = BigDecimal.class; + logger.log(Logger.Level.INFO, "Setting Expected Type: " + returnType.getName()); + + pass = (ExprEval.compareClass(result, returnType) && ExprEval + .compareValue((BigDecimal) result, (BigDecimal) expectedVal, 5)); + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, + "*** End " + "\"" + "BigDecimal" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one Float + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the NumberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testFloat(Float testVal, Object expectedVal, + String operator) throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, "*** Start " + "\"" + "Float" + "\"" + " Test Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList is BigDecimal skip it. + if (testNum instanceof BigDecimal) { + logger.log(Logger.Level.INFO, "Skip " + testNum.getClass().getSimpleName() + + " for Float tests we already tested for this in the" + + " BigDecimal tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are Float and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+="concatenation then coerce both operands to String + * and concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "%" then the return type is Double. + } else if ("%".equals(operator)) { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, + Double.valueOf(((Float) expectedVal).doubleValue()))); + } else { + if (testNum instanceof BigInteger) { + returnType = BigDecimal.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue(((BigDecimal) result).floatValue(), + (Float) expectedVal, 3)); + } else { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) && ExprEval + .compareValue((Double) result, (Float) expectedVal, 3)); + } + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, "*** End " + "\"" + "Float" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one Double + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the NumberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testDouble(Double testVal, Object expectedVal, + String operator) throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, + "*** Start " + "\"" + "Double" + "\"" + "Test " + "Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList is BigDecimal, Float skip it. + if ((testNum instanceof BigDecimal) || (testNum instanceof Float)) { + String skipType = testNum.getClass().getSimpleName(); + logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are Double and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+=" (concatenation) then coerce both operands to + * String and concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "%" then the return type is Double. + } else if ("%".equals(operator)) { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, expectedVal)); + } else { + if (testNum instanceof BigInteger) { + returnType = BigDecimal.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue(((BigDecimal) result).doubleValue(), + expectedVal)); + } else { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, expectedVal)); + } + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, "*** End " + "\"" + "Double" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one + * NumericString in it (numeric String containing ".", "e", or "E". We pass in + * one of the operands(testVal), the other operand is automatically picked up + * from the NumberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testNumericString(String testVal, Double expectedVal, + String operator) throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, "*** Start " + "\"" + "NumericString" + "\"" + "Test " + + "Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList is BigDecimal, Float, Double skip + // it. + if ((testNum instanceof BigDecimal) || (testNum instanceof Float) + || (testNum instanceof Double)) { + String skipType = testNum.getClass().getSimpleName(); + logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are String and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + if ("%".equals(operator)) { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, expectedVal)); + } else { + if (testNum instanceof BigInteger) { + returnType = BigDecimal.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue(((BigDecimal) result).doubleValue(), + expectedVal)); + } else { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, expectedVal)); + } + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, + "*** End " + "\"" + "NumericString" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one + * BigInteger in it. We pass in one of the operands(testVal), the other + * operand is automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testBigInteger(BigInteger testVal, Object expectedVal, + String operator) throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, + "*** Start " + "\"" + "BigInteger" + "\"" + " Test Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList BigDecimal, Float, Double, or + // String skip it. + if ((testNum instanceof BigDecimal) || (testNum instanceof Float) + || (testNum instanceof Double) || (testNum instanceof String)) { + String skipType = testNum.getClass().getSimpleName(); + logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are BigInteger and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+=" then coerce both operands to String and + * concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "/" then the return type is + // BigDecimal. + } else if ("/".equals(operator)) { + returnType = BigDecimal.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((BigDecimal) result, + BigDecimal.valueOf(((BigInteger) expectedVal).doubleValue()), + 0)); + } else { + returnType = BigInteger.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) && ExprEval + .compareValue((BigInteger) result, (BigInteger) expectedVal, 0)); + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, + "*** End " + "\"" + "BigInteger" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one Long + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testLong(Long testVal, Object expectedVal, String operator) + throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, "*** Start " + "\"" + "Long" + "\"" + " Test Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList BigDecimal, Float, Double, + // String or BigInteger skip it. + if ((testNum instanceof BigDecimal) || (testNum instanceof Float) + || (testNum instanceof Double) || (testNum instanceof String) + || (testNum instanceof BigInteger)) { + String skipType = testNum.getClass().getSimpleName(); + logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are Long and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+=" then coerce both operands to String and + * concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "/" then the return type is Double. + } else if ("/".equals(operator)) { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, + ((Long) expectedVal).doubleValue())); + } else { + returnType = Long.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Long) result, (Long) expectedVal, 0)); + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, "*** End " + "\"" + "Long" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one + * Integer in it. We pass in one of the operands(testVal), the other operand + * is automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testInteger(Integer testVal, Object expectedVal, + String operator) throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, + "*** Start " + "\"" + "Integer" + "\"" + " Test Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList BigDecimal, Float, Double, String, + // Long, or BigInteger skip it. + if ((testNum instanceof BigDecimal) || (testNum instanceof Float) + || (testNum instanceof Double) || (testNum instanceof String) + || (testNum instanceof Long) || (testNum instanceof BigInteger)) { + String skipType = testNum.getClass().getSimpleName(); + logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are Integer and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+=" then coerce both operands to String and + * concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "/" then the return type is Double. + } else if ("/".equals(operator)) { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, + ((Integer) expectedVal).doubleValue())); + } else { + returnType = Long.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Long) result, + ((Integer) expectedVal).longValue())); + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, + "*** End " + "\"" + "Integer" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one Short + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testShort(Short testVal, Object expectedVal, + String operator) throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO,"*** Start " + "\"" + "Short" + "\"" + " Test Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList BigDecimal, Float, Double, String, + // Long, BigInteger, Integer skip it. + if (!(testNum instanceof Short || testNum instanceof Byte)) { + String skipType = testNum.getClass().getSimpleName(); + logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are Short and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+=" then coerce both operands to String and + * concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "/" then the return type is Double. + } else if ("/".equals(operator)) { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, + ((Short) expectedVal).doubleValue())); + } else { + returnType = Long.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) && ExprEval + .compareValue((Long) result, ((Short) expectedVal).longValue())); + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, "*** End " + "\"" + "Short" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that have at least one Byte + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testByte(Byte testVal, Object expectedVal, String operator) + throws Exception { + + boolean pass = false; + Class returnType; + + // For each NumberType in this list. + for (int i = 0; TestNum.getNumberList().size() > i; i++) { + logger.log(Logger.Level.INFO, "*** Start " + "\"" + "Byte" + "\"" + " Test Sequence ***"); + + Object testNum = TestNum.getNumberList().get(i); + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + // If Test value from numberList BigDecimal, Float, Double, String, + // Long, BigInteger, Integer, Short skip it. + if (!(testNum instanceof Byte)) { + String skipType = testNum.getClass().getSimpleName(); + logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + try { + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are Byte and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + logger.log(Logger.Level.INFO, "result is " + result.toString()); + + /* + * If operator is "+=" then coerce both operands to String and + * concatenate them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testVal, result, testNum); + + // If the Operator is "/" then the return type is Double. + } else if ("/".equals(operator)) { + returnType = Double.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue((Double) result, + ((Byte) expectedVal).doubleValue())); + } else { + returnType = Long.class; + logger.log(Logger.Level.INFO, + "Setting Expected Type: " + returnType.getCanonicalName()); + + pass = (ExprEval.compareClass(result, returnType) && ExprEval + .compareValue((Long) result, ((Byte) expectedVal).longValue())); + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO,"*** End " + "\"" + "Byte" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one boolean + * in it. + * + * @param testValOne + * - The boolean operand. + * @param testValTwo + * - The second operand that will be coerced to a boolean. + * @param expectedVal + * - The expected value returned from the Expression evaluation. + * @param operator + * - The operator in which the operands are compared. (i.e. "+", "-", + * etc...) + */ + public static void testBoolean(boolean testValOne, Object testValTwo, + Object expectedVal, String operator) throws Exception { + + boolean pass = false; + + NameValuePair values[] = NameValuePair.buildNameValuePair(testValOne, + testValTwo); + + try { + logger.log(Logger.Level.INFO, + "*** Start " + "\"" + "Boolean" + "\"" + " Test Sequence ***"); + String expr = ExprEval.buildElExpr(true, operator); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + logger.log(Logger.Level.INFO, "types are Boolean and " + testValTwo.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + /* + * If operator is "+=" then coerce both operands to String and concatenate + * them. (NEW to EL 3.0) + */ + if ("+=".equals(operator)) { + pass = Validator.runConcatenationTest(testValOne, result, testValTwo); + + } else { + logger.log(Logger.Level.INFO, "result is " + result.toString()); + pass = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue((Boolean) result, expectedVal)); + } + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, "*** End " + "\"" + "Boolean" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + + public static void testExpression(ELProcessor elp, String expr, + Object expected, String testName) throws Exception { + boolean pass = false; + + try { + logger.log(Logger.Level.INFO, "*** Start " + testName + " Test Sequence ***"); + logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + Object result = elp.eval(expr); + + pass = ExprEval.compareClass(result, expected.getClass()) + && ExprEval.compareValue(result, expected); + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (RuntimeException re) { + ELTestUtil.printStackTrace(re); + throw new Exception(re); + + } catch (Exception e) { + ELTestUtil.printStackTrace(e); + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + logger.log(Logger.Level.INFO, "*** End " + testName + " Test Sequence ***"); + } + } + + // ------------------------- private methods + + private static Boolean runConcatenationTest(Object testVal, Object result, + Object testNum) { + + Class returnType = String.class; + String expectedResult = testVal.toString() + testNum.toString(); + + logger.log(Logger.Level.INFO, "Setting Expected Type: " + returnType.getName()); + + return (ExprEval.compareClass(result, returnType) + && ExprEval.compareValue(result, expectedResult)); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/ELSigTestIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/ELSigTestIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/ELSigTestIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/ELSigTestIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/PackageList.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/PackageList.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/PackageList.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/PackageList.java diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTest.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTest.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTest.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTest.java diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestData.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestData.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestData.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestData.java diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestDriver.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestDriver.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestDriver.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestDriver.java diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestResult.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestResult.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestResult.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SigTestResult.java diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriver.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriver.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriver.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriver.java diff --git a/el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriverFactory.java b/el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriverFactory.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriverFactory.java rename to el-tck/src/main/java/com/sun/ts/tests/el/signaturetest/el/SignatureTestDriverFactory.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/language/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/language/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/language/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/language/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/literal/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/literal/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/literal/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/literal/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClientIT.java diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClientIT.java b/el-tck/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClientIT.java similarity index 100% rename from el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClientIT.java rename to el-tck/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClientIT.java diff --git a/el/src/main/resources/LICENSE_EFTL.md b/el-tck/src/main/resources/LICENSE_EFTL.md similarity index 100% rename from el/src/main/resources/LICENSE_EFTL.md rename to el-tck/src/main/resources/LICENSE_EFTL.md diff --git a/el/src/main/resources/LICENSE_EPL.md b/el-tck/src/main/resources/LICENSE_EPL.md similarity index 100% rename from el/src/main/resources/LICENSE_EPL.md rename to el-tck/src/main/resources/LICENSE_EPL.md diff --git a/el/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_5.0 b/el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_5.0 similarity index 100% rename from el/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_5.0 rename to el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_5.0 diff --git a/el/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_6.0 b/el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_6.0 similarity index 100% rename from el/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_6.0 rename to el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/jakarta.el.sig_6.0 diff --git a/el/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test-pkg-list.txt b/el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test-pkg-list.txt similarity index 100% rename from el/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test-pkg-list.txt rename to el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test-pkg-list.txt diff --git a/el/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test.map b/el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test.map similarity index 100% rename from el/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test.map rename to el-tck/src/main/resources/com/sun/ts/tests/signaturetest/el/sig-test.map diff --git a/el/src/main/resources/jakarta.el.sig_5.0 b/el-tck/src/main/resources/jakarta.el.sig_5.0 similarity index 100% rename from el/src/main/resources/jakarta.el.sig_5.0 rename to el-tck/src/main/resources/jakarta.el.sig_5.0 diff --git a/el/src/main/resources/jakarta.el.sig_6.0 b/el-tck/src/main/resources/jakarta.el.sig_6.0 similarity index 100% rename from el/src/main/resources/jakarta.el.sig_6.0 rename to el-tck/src/main/resources/jakarta.el.sig_6.0 diff --git a/el/pom.xml b/el/pom.xml index 14458f72eb..f4ac5a0d8a 100644 --- a/el/pom.xml +++ b/el/pom.xml @@ -1,7 +1,7 @@ - - maven-deploy-plugin - - true - - - - maven-javadoc-plugin - - none - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.3.0 - - - distribution - - single - - package - - - src/main/assembly/assembly.xml - - \ - false - ${bundle-name}-${project.version} - - - - - - - - - - EFTL - - true - - - jakarta-expression-language-tck - EFTL - - - - EPL - - expression-language-tck - EPL - - - - record-signature - - false - - - jakarta-expression-language-tck - EFTL - - - - - jakarta.tck - sigtest-maven-plugin - 2.2 - - ${project.build.directory}/jakarta.el.sig_${project.parent.version} - jakarta.el - - - - - generate - - - - - - - - - - diff --git a/el/src/main/java/com/sun/ts/tests/el/api/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/build.xml new file mode 100644 index 0000000000..668f4f1218 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClient.java new file mode 100644 index 0000000000..6f0e1b0b91 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/ELClient.java @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.arrayelresolver; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +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; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ArrayELResolver; +import jakarta.el.ELContext; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + private static final String[] names = { "doug", "nick", "roger", "ryan", + "ed" }; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + TestUtil.logTrace("Cleanup method called"); + } + + /** + * @testName: arrayELResolverTest + * + * @assertion_ids: EL:JAVADOC:1; EL:JAVADOC:3; EL:JAVADOC:4; EL:JAVADOC:5; + * EL:JAVADOC:6; EL:JAVADOC:7; EL:JAVADOC:8 + * + * @test_Strategy: Verify that API calls work as expected: arrayELResolver() + * getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() getFeatureDescriptors() + */ + public void arrayELResolverTest() 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, + Integer.valueOf(1), "yellow", buf, false); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: arrayELResolverNPETest + * + * @assertion_ids: EL:JAVADOC:1; EL:JAVADOC:5; EL:JAVADOC:6; EL:JAVADOC:7; + * EL:JAVADOC:8; EL:JAVADOC:122; EL:JAVADOC:125; + * EL:JAVADOC:128; EL:JAVADOC:131 + * + * @test_Strategy: Verify that the following methods throw a + * NullPointerException, if context is null: + * + * getValue() getType() setValue() isReadOnly() + */ + public void arrayELResolverNPETest() throws Exception { + + boolean pass; + StringBuffer buf = new StringBuffer(); + + ArrayELResolver resolver = new ArrayELResolver(); + + try { + pass = ResolverTest.testELResolverNPE(resolver, names, Integer.valueOf(1), + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: arrayELResolverPNFETest + * + * @assertion_ids: EL:JAVADOC:1; EL:JAVADOC:5; EL:JAVADOC:7; EL:JAVADOC:8; + * EL:JAVADOC:121; EL:JAVADOC:127; EL:JAVADOC:134 + * + * @test_Strategy: Verify that the following methods throw a + * PropertyNotFoundException, if the given index is out of + * bounds for this array : + * + * getType() isReadOnly() setValue() + */ + public void arrayELResolverPNFETest() throws Exception { + + boolean pass; + StringBuffer buf = new StringBuffer(); + + ArrayELResolver resolver = new ArrayELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + try { + pass = ResolverTest.testELResolverPNFE(context, resolver, names, + Integer.valueOf(10), buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: arrayELResolverIAETest + * + * @assertion_ids: EL:JAVADOC:1; EL:JAVADOC:6; EL:JAVADOC:8; EL:JAVADOC:124; + * EL:JAVADOC:132 + * + * @test_Strategy: Verify that the following methods throw an + * IllegalArgumentException, if the property could not be + * coerced into an integer: + * + * getValue() setValue() + */ + public void arrayELResolverIAETest() throws Exception { + + boolean pass; + StringBuffer buf = new StringBuffer(); + + ArrayELResolver resolver = new ArrayELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + try { + pass = ResolverTest.testELResolverIAE(context, resolver, names, "GARBAGE", + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: arrayELResolverPNWETest + * + * @assertion_ids: EL:JAVADOC:2; EL:JAVADOC:8; EL:JAVADOC:127; EL:JAVADOC:133 + * + * @test_Strategy: Verify that the single-parameter constructor for + * arrayELResolver can be used to construct a read-only + * resolver, and that the setValue() method throws a + * PropertyNotWritableException, if the resolver was + * constructed in read-only mode. + * + * ArrayELResolver(boolean) setValue() + */ + public void arrayELResolverPNWETest() throws Exception { + + boolean pass; + StringBuffer buf = new StringBuffer(); + + ArrayELResolver resolver = new ArrayELResolver(true); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + try { + pass = ResolverTest.testELResolverPNWE(context, resolver, names, + Integer.valueOf(1), "billy", buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /* + * @testName: arrayELResolverOBETest + * + * @assertion_ids: EL:JAVADOC:1; EL:JAVADOC:6 + * + * @test_Strategy: Verify that if the index is out of bounds, null is + * returned. + * + * getValue() + */ + public void arrayELResolverOBETest() throws Exception { + + boolean pass = true; + + StringBuffer buf = new StringBuffer(); + + ArrayELResolver resolver = new ArrayELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + try { + Object value = resolver.getValue(context, names, Integer.valueOf(5)); + + if (value != null) { + pass = false; + buf.append("Expected Value: 'null'").append(TestUtil.NEW_LINE) + .append("Received Value: ").append(value.toString()); + } + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + } + + /* + * @testName: arrayELResolverCCETest + * + * @assertion_ids: EL:JAVADOC:1; EL:JAVADOC:8; EL:JAVADOC:130 + * + * @test_Strategy: Verify that if the class of a specified object prevents it + * from being added to the array, a ClassCastException is thrown. + * + * setValue() + */ + public void arrayELResolverCCETest() throws Exception { + + boolean pass = false; + + ArrayELResolver resolver = new ArrayELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + try { + resolver.setValue(context, names, Integer.valueOf(1), Boolean.TRUE); + + } catch (ClassCastException cce) { + pass = true; + + } catch (Exception e) { + TestUtil.logErr( + "Failed: Exception thrown but was not a " + "ClassCastException"); + throw new Exception(e); + } + + if (!pass) { + 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. + */ + 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()); + } + TestUtil.logTrace(buf.toString()); + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/build.xml new file mode 100644 index 0000000000..314686ecb9 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/arrayelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClient.java new file mode 100644 index 0000000000..2ddb1aed2a --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/ELClient.java @@ -0,0 +1,413 @@ +/* + * Copyright (c) 2009, 2021 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +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; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.SimpleBean; + +import jakarta.el.BeanELResolver; +import jakarta.el.ELContext; + +import java.util.TimeZone; + +public class ELClient extends ServiceEETest { + + private SimpleBean sb; + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + sb = new SimpleBean(); + } + + public void cleanup() throws Exception { + TestUtil.logTrace("Cleanup method called"); + } + + /** + * @testName: beanELResolverTest + * + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16 + * + * @test_Strategy: Verify that API calls work as expected: beanELResolver() + * getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() getFeatureDescriptors() + */ + public void beanELResolverTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + sb.setIntention("initial_setting"); + + try { + BeanELResolver beanResolver = new BeanELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + pass = ResolverTest.testELResolver(context, beanResolver, sb, "intention", + "ABC123", buf, false); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: beanELResolverDefaultMethodReadOnlyTest + * + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16 + * + * @test_Strategy: Verify that API calls work as expected when accessing + * read-only properties defined via a default interface method + */ + public void beanELResolverDefaultMethodReadOnlyTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BeanELResolver beanResolver = new BeanELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + pass = ResolverTest.testELResolver(context, beanResolver, sb, "defaultRO", + "RO", buf, true); + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Test of a valid expression using a Bean with a read-only " + + "property implemented via default methods threw an Exception!" + TestUtil.NEW_LINE + + "Received: " + ex.toString() + TestUtil.NEW_LINE); + + ex.printStackTrace(); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + + /** + * @testName: beanELResolverDefaultMethodReadWriteTest + * + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16 + * + * @test_Strategy: Verify that API calls work as expected when accessing + * writable properties defined via a default interface method + */ + public void beanELResolverDefaultMethodReadWriteTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BeanELResolver beanResolver = new BeanELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + pass = ResolverTest.testELResolver(context, beanResolver, sb, "defaultRW", + "RW", buf, false); + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Test of a valid expression using a Bean with a read-write " + + "property implemented via default methods threw an Exception!" + TestUtil.NEW_LINE + + "Received: " + ex.toString() + TestUtil.NEW_LINE); + + ex.printStackTrace(); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: beanELResolverInvokeTest + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16; EL:JAVADOC:142 + * @test_Strategy: Verify that API calls work as expected for + * BeanELResolver.invoke(). + */ + public void beanELResolverInvokeTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BeanELResolver beanResolver = new BeanELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + Class[] types = { String.class, String.class }; + String[] values = { "Doug", "Donahue" }; + + pass = ResolverTest.testELResolverInvoke(context, beanResolver, sb, + "isName", types, values, Boolean.FALSE, buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + + }// End beanELResolverInvokeTest + + /** + * @testName: beanELResolverInvokeVoidTest + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16 + * @test_Strategy: Verify that the ELResolver.invoke() API calls work as + * expected when calling a method that returns void. + */ + public void beanELResolverInvokeVoidTest() throws Exception { + + boolean pass; + StringBuffer buf = new StringBuffer(); + + try { + BeanELResolver beanResolver = new BeanELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + Class[] types = { String.class, String.class }; + String[] values = { "Peter", "Pan" }; + + Object result = beanResolver.invoke(context, sb, "setFullName", types, + values); + + if (null == result) { + // validate the new values. + pass = ResolverTest.testELResolverInvoke(context, beanResolver, sb, + "isName", types, values, Boolean.FALSE, buf); + } else { + pass = false; + buf.append("Unexpected Value returned!" + TestUtil.NEW_LINE + + "Expected: null" + TestUtil.NEW_LINE + "Recieved: " + + result.getClass().getName()); + } + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + + }// End beanELResolverInvokeVoidTest + + /** + * @testName: beanELResolverInvokeMNFETest + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16; EL:JAVADOC:143 + * @test_Strategy: Verify that the invoke() method throws + * MethodNotFoundException if no suitable method can be found. + */ + public void beanELResolverInvokeMNFETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BeanELResolver beanResolver = new BeanELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + Class[] types = { String.class, String.class }; + String[] values = { "Doug", "Donahue" }; + + pass = ResolverTest.testELResolverInvoke(context, beanResolver, sb, + "bogus_Method", types, values, Boolean.TRUE, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + + }// End beanELResolverInvokeMNFETest + + /** + * @testName: beanELResolverNPETest + * + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:13; EL:JAVADOC:14; EL:JAVADOC:15; + * EL:JAVADOC:16; EL:JAVADOC:136; EL:JAVADOC:139; + * EL:JAVADOC:145; EL:JAVADOC:148 + * + * @test_Strategy: Verify that the following methods throw a + * NullPointerException, if context is null: + * + * getType() getValue() isReadOnly() setValue() + */ + public void beanELResolverNPETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + sb.setIntention("initial_setting"); + + BeanELResolver resolver = new BeanELResolver(); + + try { + pass = ResolverTest.testELResolverNPE(resolver, sb, "intention", "billy", + buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: beanELResolverPNFETest + * + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:13; EL:JAVADOC:14; EL:JAVADOC:15; + * EL:JAVADOC:16; EL:JAVADOC:137; EL:JAVADOC:140; + * EL:JAVADOC:146; EL:JAVADOC:149 + * + * @test_Strategy: Verify that the following methods throw a + * PropertyNotFoundException, if the base is not null and the + * specified property does not exist. + * + * getType() isReadOnly() setValue() getValue() + */ + public void beanELResolverPNFETest() throws Exception { + + boolean pass = true; + + StringBuffer buf = new StringBuffer(); + sb.setIntention("initial_setting"); + + BeanELResolver resolver = new BeanELResolver(); + BareBonesELContext barebonesComtext = new BareBonesELContext(); + ELContext context = barebonesComtext.getELContext(); + + try { + pass = ResolverTest.testELResolverPNFE(context, resolver, sb, + "Bogus_Field", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: beanELResolverPNWETest + * + * @assertion_ids: EL:JAVADOC:10; EL:JAVADOC:16; EL:JAVADOC:150 + * + * @test_Strategy: Verify that the single-parameter constructor for + * beanELResolver can be used to construct a read-only + * resolver, and that the setValue() method throws a + * PropertyNotWritableException, if the resolver was + * constructed in read-only mode. + * + * BeanELResolver(boolean) setValue() + */ + public void beanELResolverPNWETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + BeanELResolver resolver = new BeanELResolver(true); + BareBonesELContext barebonesComtext = new BareBonesELContext(); + ELContext context = barebonesComtext.getELContext(); + + try { + pass = ResolverTest.testELResolverPNWE(context, resolver, sb, "intention", + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(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() + */ + 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()); + } + TestUtil.logTrace(buf.toString()); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/build.xml new file mode 100644 index 0000000000..714c317e09 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beanelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClient.java new file mode 100644 index 0000000000..664f2176bd --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/ELClient.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.beannameelresolver; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.common.el.api.resolver.ResolverTest; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.SimpleBean; + +import jakarta.el.BeanNameELResolver; +import jakarta.el.BeanNameResolver; +import jakarta.el.ELContext; +import jakarta.el.ELManager; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + TestUtil.logTrace("Cleanup method called"); + } + + /** + * @testName: beanNameELResolverTest + * + * @assertion_ids: EL:JAVADOC:152; EL:JAVADOC:153; EL:JAVADOC:154; + * EL:JAVADOC:155; EL:JAVADOC:158; EL:JAVADOC:161; + * EL:JAVADOC:164 + * + * @test_Strategy: Verify the following method calls work as expected: + * getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() getFeatureDescriptors() + */ + public void beanNameELResolverTest() throws Exception { + StringBuffer buf = new StringBuffer(); + boolean pass = false; + + ELManager elm = new ELManager(); + BeanNameResolver bnr = new TCKBeanNameResolver(); + BeanNameELResolver belr = new BeanNameELResolver(bnr); + + elm.addBeanNameResolver(bnr); + elm.addELResolver(belr); + elm.defineBean("simpleBean", new SimpleBean()); + + ELContext context = elm.getELContext(); + + try { + pass = ResolverTest.testELResolver(context, context.getELResolver(), + bnr.getBean("simpleBean"), "intention", "GOLDEN", buf, false); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + + TestUtil.logMsg(buf.toString()); + } + + /** + * @testName: beanNameELResolverInvokeMNFETest + * + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16; + * EL:JAVADOC:143; EL:JAVADOC:237 + * + * @test_Strategy: Verify that the invoke() method throws + * MethodNotFoundException if no suitable method can be found. + */ + public void beanNameELResolverInvokeMNFETest() throws Exception { + StringBuffer buf = new StringBuffer(); + boolean pass = false; + + ELManager elm = new ELManager(); + BeanNameResolver bnr = new TCKBeanNameResolver(); + BeanNameELResolver belr = new BeanNameELResolver(bnr); + + elm.addBeanNameResolver(bnr); + elm.addELResolver(belr); + elm.defineBean("simpleBean", new SimpleBean()); + + ELContext context = elm.getELContext(); + + Class[] types = { String.class, String.class }; + String[] values = { "Doug", "Donahue" }; + + try { + pass = ResolverTest.testELResolverInvoke(context, context.getELResolver(), + new SimpleBean(), "bogue_method", types, values, true, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logMsg(buf.toString()); + + }// End beanELResolverInvokeMNFETest + + /** + * @testName: beanNameELResolverInvokeTest + * + * @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13; + * EL:JAVADOC:14; EL:JAVADOC:15; EL:JAVADOC:16; + * EL:JAVADOC:142; EL:JAVADOC:199; EL:JAVADOC:200; + * EL:JAVADOC:202; EL:JAVADOC:203; EL:JAVADOC:236 + * + * @test_Strategy: Verify that API calls work as expected for + * BeanNameELResolver.invoke(). + */ + public void beanNameELResolverInvokeTest() throws Exception { + StringBuffer buf = new StringBuffer(); + boolean pass = false; + + ELManager elm = new ELManager(); + BeanNameResolver bnr = new TCKBeanNameResolver(); + BeanNameELResolver belr = new BeanNameELResolver(bnr); + + elm.addBeanNameResolver(bnr); + elm.addELResolver(belr); + elm.defineBean("simpleBean", new SimpleBean()); + + ELContext context = elm.getELContext(); + + Class[] types = { String.class, String.class }; + String[] values = { "Doug", "Donahue" }; + + try { + pass = ResolverTest.testELResolverInvoke(context, context.getELResolver(), + new SimpleBean(), "isName", types, values, false, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logMsg(buf.toString()); + + }// End beanELResolverInvokeTest + + /** + * @testName: beanNameELResolverGetTypeNPETest + * + * @assertion_ids: EL:JAVADOC:156 + * + * @test_Strategy: Validate a NullPointerException is thrown if context is + * null. + */ + public void beanNameELResolverGetTypeNPETest() throws Exception { + BeanNameResolver bnr = new TCKBeanNameResolver(); + BeanNameELResolver belr = new BeanNameELResolver(bnr); + + ELTestUtil.checkForNPE(belr, "getType", + new Class[] { ELContext.class, Object.class, Object.class }, + new Object[] { null, "Ender", "Wiggins" }); + + }// End beanNameELResolverGetTypeNPETest + + /** + * @testName: beanNameELResolverGetValueNPETest + * + * @assertion_ids: EL:JAVADOC:159 + * + * @test_Strategy: Validate a NullPointerException is thrown if context is + * null. + */ + public void beanNameELResolverGetValueNPETest() throws Exception { + BeanNameResolver bnr = new TCKBeanNameResolver(); + BeanNameELResolver belr = new BeanNameELResolver(bnr); + + ELTestUtil.checkForNPE(belr, "getValue", + new Class[] { ELContext.class, Object.class, Object.class }, + new Object[] { null, "Ender", "Wiggins" }); + + }// End beanNameELResolverGetValueNPETest + + /** + * @testName: beanNameELResolverIsReadOnlyNPETest + * + * @assertion_ids: EL:JAVADOC:162 + * + * @test_Strategy: Validate a NullPointerException is thrown if context is + * null. + */ + public void beanNameELResolverIsReadOnlyNPETest() throws Exception { + BeanNameResolver bnr = new TCKBeanNameResolver(); + BeanNameELResolver belr = new BeanNameELResolver(bnr); + + ELTestUtil.checkForNPE(belr, "isReadOnly", + new Class[] { ELContext.class, Object.class, Object.class }, + new Object[] { null, "Ender", "Wiggins" }); + + }// End beanNameELResolverIsReadOnlyNPETest + + /** + * @testName: beanNameELResolverSetValueNPETest + * + * @assertion_ids: EL:JAVADOC:165 + * + * @test_Strategy: Validate a NullPointerException is thrown if context is + * null. + */ + public void beanNameELResolverSetValueNPETest() throws Exception { + BeanNameResolver bnr = new TCKBeanNameResolver(); + BeanNameELResolver belr = new BeanNameELResolver(bnr); + + ELTestUtil.checkForNPE(belr, "setValue", + new Class[] { ELContext.class, Object.class, Object.class, + Object.class }, + new Object[] { null, "Ender", "Valintine", "Wiggins" }); + + }// End beanNameELResolverSetValueNPETest + + // -------------------------------------------- private classes + + private static class TCKBeanNameResolver extends BeanNameResolver { + + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/build.xml new file mode 100644 index 0000000000..a97a1499b7 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/beannameelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/build.xml new file mode 100644 index 0000000000..95bdaa8619 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClient.java new file mode 100644 index 0000000000..610f407e52 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/ELClient.java @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.compositeelresolver; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +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; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.SimpleBean; + +import jakarta.el.ArrayELResolver; +import jakarta.el.BeanELResolver; +import jakarta.el.CompositeELResolver; +import jakarta.el.ELContext; +import jakarta.el.ELManager; + +public class ELClient extends ServiceEETest { + + private static final String[] names = { "doug", "nick", "roger", "ryan", + "ed" }; + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: compositeELResolverTest + * + * @assertion_ids: EL:JAVADOC:24; EL:JAVADOC:25; EL:JAVADOC:26; EL:JAVADOC:27; + * EL:JAVADOC:28; EL:JAVADOC:29; EL:JAVADOC:30; EL:JAVADOC:31; + * EL:JAVADOC:34 + * + * @test_Strategy: Verify that API calls work as expected: + * CompositeELResolver() add() getValue() getType() setValue() + * isReadOnly() getCommonPropertyType() + * getFeatureDescriptors() ELContext.getELResolver() + */ + public void compositeELResolverTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BareBonesELContext compContext = new BareBonesELContext(); + ELContext context = compContext.getELContext(); + + // Create the CompositeELResolver. + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + + pass = ResolverTest.testCompositeELResolver(context, compResolver, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: compositeELResolverInvokeTest + * + * @assertion_ids: EL:JAVADOC:24; EL:JAVADOC:25; EL:JAVADOC:181 + * + * @test_Strategy: Verify that API calls work as expected for + * BeanELResolver.invoke(). + */ + public void compositeELResolverInvokeTest() throws Exception { + SimpleBean sb = new SimpleBean(); + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BeanELResolver beanResolver = new BeanELResolver(); + ELManager elm = new ELManager(); + ELContext context = elm.getELContext(); + + // Create the CompositeELResolver. + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + + compResolver.add(beanResolver); + + Class[] types = { String.class, String.class }; + String[] values = { "Doug", "Donahue" }; + + pass = ResolverTest.testELResolverInvoke(context, compResolver, sb, + "isName", types, values, false, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + + }// End beanELResolverInvokeTest + + /** + * @testName: compositeELResolverAddNPETest + * + * @assertion_ids: EL:JAVADOC:24; EL:JAVADOC:25; EL:JAVADOC:174 + * + * @test_Strategy: Verify that the CompositeELResolver.add method throws a + * NullPointerException if the provided resolver is null. + */ + public void compositeELResolverAddNPETest() throws Exception { + + boolean pass = true; + StringBuffer buf = new StringBuffer(); + + try { + BareBonesELContext compContext = new BareBonesELContext(); + ELContext context = compContext.getELContext(); + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + + compResolver.add(null); + + buf.append(TestUtil.NEW_LINE + "Tested Failed, CompositeResolver.add(), " + + "should have thrown NullPointerException!"); + pass = false; + + } catch (NullPointerException npe) { + TestUtil.logMsg("Expected Exception thrown, when providing a" + + " null resolver to Composite.add()"); + + } catch (Exception e) { + buf.append("test failed with: " + TestUtil.NEW_LINE + "EXPECTED: " + + "NullPointerException to be thrown " + TestUtil.NEW_LINE + + "RECEIVED: " + e.toString() + "" + TestUtil.NEW_LINE); + pass = false; + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: compositeELResolverNPETest + * + * @assertion_ids: EL:JAVADOC:25; EL:JAVADOC:26; EL:JAVADOC:27; EL:JAVADOC:28; + * EL:JAVADOC:29; EL:JAVADOC:30; EL:JAVADOC:31; + * EL:JAVADOC:175; EL:JAVADOC:178; EL:JAVADOC:175; + * EL:JAVADOC:182; EL:JAVADOC:185 + * + * @test_Strategy: Verify that API calls work as expected: getValue() + * getType() setValue() isReadOnly() getCommonPropertyType() + * getFeatureDescriptors() + */ + public void compositeELResolverNPETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BareBonesELContext compContext = new BareBonesELContext(); + ELContext context = compContext.getELContext(); + + // Create dummy ELResolvers to populate the CompositeELResolver. + ArrayELResolver aResolver = new ArrayELResolver(); + BeanELResolver bResolver = new BeanELResolver(); + + // Create the CompositeELResolver & add the dummy ELResolvers to it. + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + compResolver.add(aResolver); + compResolver.add(bResolver); + + pass = ResolverTest.testELResolverNPE(compResolver, names, + Integer.valueOf(2), "steve", buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: compositeELResolverPNFETest + * + * @assertion_ids: EL:JAVADOC:25; EL:JAVADOC:28; EL:JAVADOC:30; EL:JAVADOC:31; + * EL:JAVADOC:176; EL:JAVADOC:179; EL:JAVADOC:183; + * EL:JAVADOC:186 + * + * @test_Strategy: Verify that API calls throw PropertyNotFoundException as + * expected: getType() setValue() isReadOnly() + */ + public void compositeELResolverPNFETest() throws Exception { + + boolean pass = true; + StringBuffer buf = new StringBuffer(); + + try { + BareBonesELContext compContext = new BareBonesELContext(); + ELContext context = compContext.getELContext(); + + // Create an ArrayELResolver to populate the CompositeELResolver. + ArrayELResolver aResolver = new ArrayELResolver(); + + // Create the CompositeELResolver & add the ELResolver to it. + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + compResolver.add(aResolver); + + pass = ResolverTest.testELResolverPNFE(context, compResolver, names, + Integer.valueOf(10), buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: compositeELResolverPNWETest + * + * @assertion_ids: EL:JAVADOC:25; EL:JAVADOC:187 + * + * @test_Strategy: Verify that the setValue() method throws a + * PropertyNotWritableException, if the resolver was + * constructed in read-only mode. + * + * setValue() + */ + public void compositeELResolverPNWETest() throws Exception { + boolean pass = false; + StringBuffer buf = new StringBuffer(); + SimpleBean sb = new SimpleBean(); + + BareBonesELContext compContext = new BareBonesELContext(); + ELContext context = compContext.getELContext(); + + // Create an ArrayELResolver to populate the CompositeELResolver. + BeanELResolver resolver = new BeanELResolver(true); + + // Create the CompositeELResolver & add the ELResolver to it. + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + compResolver.add(resolver); + + try { + pass = ResolverTest.testELResolverPNWE(context, resolver, sb, "intention", + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/build.xml new file mode 100644 index 0000000000..6c5a7b6d2a --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/compositeelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClient.java new file mode 100644 index 0000000000..0a559b28b7 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/ELClient.java @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.elcontext; + +import java.util.List; +import java.util.Locale; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELContext; +import jakarta.el.ELManager; +import jakarta.el.EvaluationListener; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + this.testProps = p; + } + + /** + * Does nothing... + * + * @throws Exception + */ + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elContextPutGetContextTest + * @assertion_ids: EL:JAVADOC:33; EL:JAVADOC:39; EL:JAVADOC:328; + * EL:JAVADOC:326; EL:JAVADOC:321 + * @test_Strategy: Assert that we get back the expected value from + * getContext() that we put in with putContext(). + * + * @since: 3.0 + */ + + public void elContextPutGetContextTest() throws Exception { + ELManager elm = new ELManager(); + ELContext elc = elm.getELContext(); + String testStr = "TCKContext"; + + elc.putContext(String.class, testStr); + String result = elc.getContext(String.class).toString(); + + if (!testStr.equals(result)) { + throw new Exception(ELTestUtil.FAIL + " Unexpected Context Returned!" + + TestUtil.NEW_LINE + "Expected: " + testStr + TestUtil.NEW_LINE + + "Received: " + result); + } + + } // end elContextPutGetContextTest + + /** + * @testName: elContextGetSetLocaleTest + * @assertion_ids: EL:JAVADOC:36; EL:JAVADOC:40; EL:JAVADOC:328; + * EL:JAVADOC:329 + * @test_Strategy: Assert that we get back the Locale we set. + * + * @since: 3.0 + */ + + public void elContextGetSetLocaleTest() throws Exception { + ELManager elm = new ELManager(); + ELContext elc = elm.getELContext(); + + String disName = "english"; + Locale en = new Locale(disName); + elc.setLocale(en); + String result = elc.getLocale().getDisplayName(); + + if (!result.equalsIgnoreCase(disName)) { + throw new Exception(ELTestUtil.FAIL + " Unexpected Locale Returned!" + + TestUtil.NEW_LINE + "Expected: " + disName + TestUtil.NEW_LINE + + "Received: " + result); + } + + } // end elContextGetSetLocaleTest + + /** + * @testName: elContextIsSetPropertyResolvedTest + * @assertion_ids: EL:JAVADOC:38; EL:JAVADOC:41; EL:JAVADOC:328; + * EL:JAVADOC:329; EL:JAVADOC:322 + * @test_Strategy: Assert that when we call setPropertyResolved that + * isPropertyResolved returns true. + * + * @since: 3.0 + */ + + public void elContextIsSetPropertyResolvedTest() throws Exception { + ELManager elm = new ELManager(); + ELContext elc = elm.getELContext(); + + boolean isProp = elc.isPropertyResolved(); + + if (isProp) { + throw new Exception( + ELTestUtil.FAIL + " Unexpected result from isPropertyResolved()!" + + TestUtil.NEW_LINE + "Should have been false!"); + } + + elc.setPropertyResolved(true); + isProp = elc.isPropertyResolved(); + + if (!isProp) { + throw new Exception( + ELTestUtil.FAIL + " Unexpected result from isPropertyResolved()!" + + TestUtil.NEW_LINE + "Should have been true!"); + } + + } // end elContextIsSetPropertyResolvedTest + + /** + * @testName: elContextPutContextNPETest + * @assertion_ids: EL:JAVADOC:33; EL:JAVADOC:198; EL:JAVADOC:328; + * EL:JAVADOC:329; EL:JAVADOC:327 + * @test_Strategy: Validate that a NullPointerException is thrown if Class is + * null or Object is null. + * + * @since: 3.0 + */ + + public void elContextPutContextNPETest() throws Exception { + ELManager elm = new ELManager(); + ELContext elc = elm.getELContext(); + + TestUtil.logMsg("Testing: ELContext.putContext(String.class, null)"); + ELTestUtil.checkForNPE(elc, "putContext", + new Class[] { Class.class, Object.class }, + new Object[] { String.class, null }); + + TestUtil.logMsg("Testing: ELContext.putContext(null, testStrg)"); + ELTestUtil.checkForNPE(elc, "putContext", + new Class[] { Class.class, Object.class }, + new Object[] { String.class, null }); + + } // end elContextPutContextNPETest + + /** + * @testName: elContextGetContextNPETest + * @assertion_ids: EL:JAVADOC:33; EL:JAVADOC:194; EL:JAVADOC:328; + * EL:JAVADOC:329; EL:JAVADOC:321 + * @test_Strategy: Validate that a NullPointerException is thrown if key is + * null. + * + * @since: 3.0 + */ + + public void elContextGetContextNPETest() throws Exception { + ELManager elm = new ELManager(); + ELContext elc = elm.getELContext(); + + TestUtil.logMsg("Testing: ELContext.getContext(null)"); + ELTestUtil.checkForNPE(elc, "getContext", new Class[] { Class.class }, + new Object[] { null }); + + } // end elContextGetContextNPETest + + /** + * @testName: elContextAddGetListenersTest + * @assertion_ids: EL:JAVADOC:33; EL:JAVADOC:191; EL:JAVADOC:197; + * EL:JAVADOC:328; EL:JAVADOC:329 + * @test_Strategy: Validate that a NullPointerException is thrown if key is + * null. + * + * @since: 3.0 + */ + + public void elContextAddGetListenersTest() throws Exception { + ELManager elm = new ELManager(); + ELContext elc = elm.getELContext(); + + EvaluationListener listenerOne = new TCKEvalListener(); + EvaluationListener listenerTwo = new TCKEvalListener(); + + elc.addEvaluationListener(listenerOne); + elc.addEvaluationListener(listenerTwo); + + List listeners = elc.getEvaluationListeners(); + + if (!(listeners.contains(listenerOne) && listeners.contains(listenerTwo))) { + throw new Exception( + ELTestUtil.FAIL + " Was unable to find test listeners in List " + + "returned form " + "ElContext.getListeners()!"); + } + + } // end elContextAddGetListenersTest + + // ---------------------------------------------- private classes + + private static class TCKEvalListener extends EvaluationListener { + // do nothing this is just for test purposes. + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/build.xml new file mode 100644 index 0000000000..5860c53a0d --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elcontext/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClient.java new file mode 100644 index 0000000000..c7e7dd1bed --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/ELClient.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.elprocessor; + +import java.lang.reflect.Method; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELProcessor; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + this.testProps = p; + } + + /** + * Does nothing... + * + * @throws Exception + */ + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elProcessorDefineFunctionNPETest + * @assertion_ids: EL:JAVADOC:220; EL:JAVADOC:216; EL:JAVADOC:219 + * @test_Strategy: Assert that a NullPointerException is thrown if any of the + * arguments is null. + * + * @since: 3.0 + */ + + public void elProcessorDefineFunctionNPETest() throws Exception { + ELProcessor elp = new ELProcessor(); + + Method meth; + try { + meth = elp.getClass().getMethod("toString", new Class[] {}); + + // Tests for defineFunction(String, String, Method) + TestUtil.logMsg( + "Testing: ELProcessor.defineFunction(null, " + "function, meth)"); + ELTestUtil.checkForNPE(elp, "defineFunction", + new Class[] { String.class, String.class, Method.class }, + new Object[] { null, "function", meth }); + + TestUtil.logMsg( + "Testing: ELProcessor.defineFunction(prefix, " + "null, meth)"); + ELTestUtil.checkForNPE(elp, "defineFunction", + new Class[] { String.class, String.class, Method.class }, + new Object[] { "prefix", null, meth }); + + TestUtil.logMsg( + "Testing: ELProcessor.defineFunction(prefix, " + "function, null)"); + ELTestUtil.checkForNPE(elp, "defineFunction", + new Class[] { String.class, String.class, Method.class }, + new Object[] { "prefix", "function", null }); + + // Tests for defineFunction(String, String, String, String) + TestUtil.logMsg("Testing: ELProcessor.defineFunction(prefix, " + + "function, className, null)"); + ELTestUtil.checkForNPE(elp, "defineFunction", + new Class[] { String.class, String.class, String.class, + String.class }, + new Object[] { "prefix", "function", "className", null }); + + TestUtil.logMsg("Testing: ELProcessor.defineFunction(prefix, " + + "function, null, method)"); + ELTestUtil.checkForNPE(elp, "defineFunction", + new Class[] { String.class, String.class, String.class, + String.class }, + new Object[] { "prefix", "function", null, "method" }); + + TestUtil.logMsg("Testing: ELProcessor.defineFunction(prefix, " + + "null, className, method)"); + ELTestUtil.checkForNPE(elp, "defineFunction", + new Class[] { String.class, String.class, String.class, + String.class }, + new Object[] { "prefix", null, "className", "method" }); + + TestUtil.logMsg("Testing: ELProcessor.defineFunction(null, " + + "function, className, method)"); + ELTestUtil.checkForNPE(elp, "defineFunction", + new Class[] { String.class, String.class, String.class, + String.class }, + new Object[] { null, "function", "className", "method" }); + + } catch (SecurityException e) { + e.printStackTrace(); + + } catch (NoSuchMethodException nsme) { + nsme.printStackTrace(); + } + + } // end elProcessorDefineFunctionNPETest + + /** + * @testName: elProcessorDefineFunctionCNFETest + * @assertion_ids: EL:JAVADOC:220; EL:JAVADOC:214; EL:JAVADOC:217 + * @test_Strategy: Assert that a ClassNotFoundException if the specified class + * does not exists. + * + * @since: 3.0 + */ + + public void elProcessorDefineFunctionCNFETest() throws Exception { + ELProcessor elp = new ELProcessor(); + + TestUtil.logMsg("Testing: ELProcessor.defineFunction(null, " + + "function, className, method)"); + ELTestUtil.checkForCNFE(elp, "defineFunction", + new Class[] { String.class, String.class, String.class, + String.class }, + new Object[] { "prefix", "function", "bogus", "method" }); + + } // end elProcessorDefineFunctionCNFETest + + /** + * @testName: elProcessorDefineFunctionNSMETest + * @assertion_ids: EL:JAVADOC:220; EL:JAVADOC:215 + * @test_Strategy: Assert that a NoSuchMethodException if the method (with or + * without the signature) is not a declared method of the + * class, or if the method signature is not valid. + * + * @since: 3.0 + */ + + public void elProcessorDefineFunctionNSMETest() throws Exception { + ELProcessor elp = new ELProcessor(); + + TestUtil.logMsg("Testing: ELProcessor.defineFunction(null, " + + "function, className, method)"); + ELTestUtil.checkForCNFE(elp, "defineFunction", + new Class[] { String.class, String.class, String.class, + String.class }, + new Object[] { "prefix", "function", "java.util.String", "bogus" }); + + } // end elProcessorDefineFunctionNSMETest +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/build.xml new file mode 100644 index 0000000000..6abe312b65 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elprocessor/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClient.java new file mode 100644 index 0000000000..f52f55db43 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/ELClient.java @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.elresolver; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +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.BarELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.SimpleBean; + +import jakarta.el.ArrayELResolver; +import jakarta.el.BeanELResolver; +import jakarta.el.CompositeELResolver; +import jakarta.el.ELContext; +import jakarta.el.ELManager; +import jakarta.el.ELResolver; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + private static final String[] names = { "doug", "nick", "roger", "ryan", + "ed" }; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elResolverTest + * + * @assertion_ids: EL:JAVADOC:50; EL:JAVADOC:51; EL:JAVADOC:52; EL:JAVADOC:53; + * EL:JAVADOC:54; EL:JAVADOC:55; EL:JAVADOC:229 + * + * @test_Strategy: Create an ELContext and get its ELResolver. Verify that API + * calls work as expected: getValue() getType() setValue() + * isReadOnly() getCommonPropertyType() + * getFeatureDescriptors() + */ + + public void elResolverTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + BarELContext barContext = new BarELContext(); + ELContext context = barContext.getELContext(); + + if (barContext != null) { + ELResolver resolver = barContext.getELResolver(); + pass = ResolverTest.testELResolver(context, resolver, null, "Bar", + "Foo", buf, true); + } + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + + } // end elResolverTest + + /** + * @testName: elResolverNPETest + * + * @assertion_ids: EL:JAVADOC:233; EL:JAVADOC:239; EL:JAVADOC:242 + * + * @test_Strategy: Verify that a NullPointerException is thrown as expected + * for the following methods: getValue() getType() setValue() + * isReadOnly() + * + * @since: 3.0 + */ + public void elResolverNPETest() throws Exception { + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + ELContext context = new ELManager().getELContext(); + + // Create dummy ELResolvers to populate the CompositeELResolver. + ELResolver aResolver = new ArrayELResolver(); + ELResolver bResolver = new BeanELResolver(); + + // Create the CompositeELResolver & add the dummy ELResolvers to it. + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + compResolver.add(aResolver); + compResolver.add(bResolver); + + try { + pass = ResolverTest.testELResolverNPE(compResolver, names, + Integer.valueOf(2), "steve", buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + + }// end elResolverNPETest + + /** + * @testName: elResolverPNFETest + * + * @assertion_ids: EL:JAVADOC:231; EL:JAVADOC:234; EL:JAVADOC:240 + * + * @test_Strategy: Verify that API calls throw PropertyNotFoundException as + * expected: getType() setValue() isReadOnly() + */ + public void elResolverPNFETest() throws Exception { + boolean pass = true; + StringBuffer buf = new StringBuffer(); + + ELContext context = new ELManager().getELContext(); + + // Create an ArrayELResolver to populate the CompositeELResolver. + ELResolver aResolver = new ArrayELResolver(); + + // Create the CompositeELResolver & add the ELResolver to it. + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + compResolver.add(aResolver); + + try { + pass = ResolverTest.testELResolverPNFE(context, compResolver, names, + Integer.valueOf(10), buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + + }// end elResolverPNFETest + + /** + * @testName: elResolverPNWETest + * + * @assertion_ids: EL:JAVADOC:50; EL:JAVADOC:244 + * + * @test_Strategy: Verify that the setValue() method throws a + * PropertyNotWritableException, if the resolver was + * constructed in read-only mode. + * + * setValue() + */ + public void elResolverPNWETest() throws Exception { + boolean pass = false; + StringBuffer buf = new StringBuffer(); + SimpleBean sb = new SimpleBean(); + + ELContext context = new ELManager().getELContext(); + + ELResolver resolver = new BeanELResolver(true); + CompositeELResolver compResolver = (CompositeELResolver) context + .getELResolver(); + compResolver.add(resolver); + + try { + pass = ResolverTest.testELResolverPNWE(context, resolver, sb, "intention", + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + + } // end elResolverPNWETest + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/build.xml new file mode 100644 index 0000000000..bcf8bc71cc --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/elresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClient.java new file mode 100644 index 0000000000..0e1cae41ce --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/ELClient.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.expression; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.common.el.api.expression.ExpressionTest; +import com.sun.ts.tests.el.common.elcontext.SimpleELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.ResolverType; + +import jakarta.el.ELContext; +import jakarta.el.Expression; +import jakarta.el.ExpressionFactory; +import jakarta.el.MethodExpression; +import jakarta.el.ValueExpression; + +public class ELClient extends ServiceEETest { + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + /** + * Does nothing. + * + * @throws Exception + */ + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: negativeEqualsTest + * + * @assertion_ids: EL:JAVADOC:56 + * + * @test_Strategy: Validate the behavior of Expression API Expression.equals() + * + * Verify that an Expression cannot equal null, and that a + * ValueExpression and a MethodExpression cannot be equal. + */ + + public void negativeEqualsTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new SimpleELContext()).getELContext(); + + // compare Expressions to null + ValueExpression vexp1 = expFactory.createValueExpression(context, + "${null}", Object.class); + + if (ExpressionTest.equalsTest(vexp1, null, buf)) { + pass = false; + buf.append("ValueExpression tested equal to null" + TestUtil.NEW_LINE); + } + + MethodExpression mexp1 = expFactory.createMethodExpression(context, + "null", null, new Class[] {}); + + if (ExpressionTest.equalsTest(mexp1, null, buf)) { + pass = false; + buf.append("MethodExpression tested equal to null" + TestUtil.NEW_LINE); + } + + // compare ValueExpressions to MethodExpressions + ValueExpression vexp2 = expFactory.createValueExpression(context, + "literal", Object.class); + + MethodExpression mexp2 = expFactory.createMethodExpression(context, + "literal", null, new Class[] {}); + + if (ExpressionTest.equalsTest(vexp2, mexp2, buf)) { + pass = false; + buf.append("ValueExpression tested equal to " + "MethodExpression" + + TestUtil.NEW_LINE); + } + + if (ExpressionTest.equalsTest(mexp2, vexp2, buf)) { + pass = false; + buf.append("MethodExpression tested equal to " + "ValueExpression" + + TestUtil.NEW_LINE); + } + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + + TestUtil.logTrace(buf.toString()); + + }// End negativeEqualsTest + + /** + * @testName: expressionHashCodeTest + * + * @assertion_ids: EL:JAVADOC:59 + * + * @test_Strategy: Validate the if two objects are equal according to the + * equals(Object) method, then calling the hashCode method on + * each of the two objects must produce the same integer + * result. + * + */ + + public void expressionHashCodeTest() throws Exception { + SimpleELContext simpleContext = new SimpleELContext( + ResolverType.VECT_ELRESOLVER); + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = simpleContext.getELContext(); + + Class[] paramTypes1 = { Object.class }; + + String exprStr1 = "#{vect.add}"; + + Expression mexp1 = expFactory.createMethodExpression(context, exprStr1, + boolean.class, paramTypes1); + + Expression mexp2 = expFactory.createMethodExpression(context, exprStr1, + boolean.class, paramTypes1); + + if (!mexp1.equals(mexp2)) { + throw new Exception("Failed: equals check failed!"); + + } + + if (!(mexp1.hashCode() == mexp2.hashCode())) { + throw new Exception("Failed: hashCode check failed!"); + } + + }// End expressionHashCodeTest + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/build.xml new file mode 100644 index 0000000000..b61782a4cd --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expression/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClient.java new file mode 100644 index 0000000000..5b5f41f447 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/ELClient.java @@ -0,0 +1,524 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.expressionfactory; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.elcontext.SimpleELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ExpressionFactory; +import jakarta.el.MethodExpression; +import jakarta.el.ValueExpression; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + TestUtil.logTrace("Cleanup method called"); + } + + /** + * @testName: newInstanceTest + * + * @assertion_ids: EL:JAVADOC:119; EL:JAVADOC:120 + * @test_Strategy: Verify that an ExpressionFactory can be instantiated with + * the newInstance() API. + */ + public void newInstanceTest() throws Exception { + + try { + ExpressionFactory.newInstance(); + ExpressionFactory.newInstance(null); + + Properties props = new Properties(); + props.setProperty("jakarta.el.cacheSize", "128M"); + ExpressionFactory.newInstance(props); + + } catch (Exception ex) { + throw new Exception(ex); + } + } + + /** + * @testName: createValueExpressionTest + * + * @assertion_ids: EL:JAVADOC:63 + * @test_Strategy: Verify that the ExpressionFactory can handle the types of + * input specified in the javadoc when invoking the + * createValueExpression(ELContext, String, Class) method. + */ + public void createValueExpressionTest() throws Exception { + + boolean pass = true; + + String[] exprStr = { + + // $ delimiter + "${employee.lastname}", + + // # delimiter + "#{employee.lastname}", + + // literal text + "John Doe", + + // multiple expressions using the same delimiter + "${employee.firstname}${employee.lastname}", + "#{employee.firstname}#{employee.lastname}", + + // mixed literal text and expressions using the same delimiter + "Name: ${employee.firstname}${employee.lastname}", + "Name: #{employee.firstname}#{employee.lastname}" + + }; + + ValueExpression vexp = null; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + SimpleELContext context = new SimpleELContext(); + + for (int i = 0; i < exprStr.length; ++i) { + try { + vexp = expFactory.createValueExpression(context, exprStr[i], + Object.class); + } catch (NullPointerException npe) { + pass = false; + TestUtil.logErr(ELTestUtil.FAIL + exprStr[i]); + TestUtil.printStackTrace(npe); + continue; + } catch (ELException ee) { + pass = false; + TestUtil.logErr(ELTestUtil.FAIL + exprStr[i]); + TestUtil.printStackTrace(ee); + continue; + } + + if (!vexp.getExpressionString().equals(exprStr[i])) { + pass = false; + TestUtil.logErr("Failed. Expression string mismatch."); + TestUtil.logErr("Expected: " + exprStr[i]); + TestUtil.logErr("Received: " + vexp.getExpressionString()); + } + } + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + } + + /** + * @testName: createValueExpression2Test + * + * @assertion_ids: EL:JAVADOC:64 + * @test_Strategy: Verify the functionality of the + * createValueExpression(Object, Class) method. + */ + public void createValueExpression2Test() throws Exception { + + boolean pass = true; + + // test cases mix coercable and non-coercable object/type + // instances + ObjectAndType[] testCases = { + new ObjectAndType("some string", String.class), + new ObjectAndType(null, String.class), + new ObjectAndType(Integer.valueOf(1), String.class), + new ObjectAndType(Double.valueOf(1.5d), Integer.class), + new ObjectAndType("10000", Long.class), + new ObjectAndType(Integer.valueOf(1), Boolean.class), + new ObjectAndType(Boolean.TRUE, Character.class), + new ObjectAndType(Integer.valueOf(1), Class.class) }; + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + + for (int i = 0; i < testCases.length; ++i) { + try { + expFactory.createValueExpression(testCases[i].obj, testCases[i].type); + } catch (Exception e) { + pass = false; + TestUtil.logErr("Exception: Test Case " + i); + TestUtil.printStackTrace(e); + } + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + } + + /** + * @testName: createValueExpressionELExceptionTest + * + * @assertion_ids: EL:JAVADOC:63 + * @test_Strategy: Verify that + * ExpressionFactory.createValueExpression(ELContext, String, + * Class) throws an ELException for mixed delimiter + * expressions and expressions with syntactical errors. + */ + public void createValueExpressionELExceptionTest() throws Exception { + + boolean pass = true; + + String[] exprStr = { + + // $ delimiter with missing bracket + "${employee.lastname", + + // # delimiter with incomplete [] operation + "#{employee[lastname}", + + // invalid operation + "${ 5 ! 3 }", + + // binary operation with missing operand + "${ 5 + }", + + // multiple expressions with mixed delimiters + "${employee.firstname}#{employee.lastname}", + "#{employee.firstname}${employee.lastname}", + + // mixed literal text and expressions with mixed delimiters + "Name: ${employee.firstname}#{employee.lastname}", + "Name: #{employee.firstname}${employee.lastname}" + + }; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + SimpleELContext context = new SimpleELContext(); + + for (int i = 0; i < exprStr.length; ++i) { + try { + expFactory.createValueExpression(context, exprStr[i], Object.class); + } catch (ELException ee) { + continue; + } catch (NullPointerException npe) { + pass = false; + TestUtil.logErr(ELTestUtil.FAIL + exprStr[i]); + TestUtil.printStackTrace(npe); + continue; + } + pass = false; + TestUtil.logErr("Failed. No ELException thrown when calling"); + TestUtil.logErr("createValueExpression() with parameter " + exprStr[i]); + } + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + } + + /** + * @testName: createMethodExpressionTest + * + * @assertion_ids: EL:JAVADOC:62 + * @test_Strategy: Verify that the ExpressionFactory can handle the types of + * input specified in the javadoc when invoking the + * createMethodExpression(ELContext, String, Class) method, + * with the restriction that only expressions that share the + * same syntax as an lvalue are allowed (EL Spec 1.2.1.2). + */ + public void createMethodExpressionTest() throws Exception { + + boolean pass = true; + + String[] exprStr = { + + // $ delimiter + "${add}", "${vect.add}", "${vect[add]}", + + // # delimiter + "#{add}", "#{vect.add}", "#{vect[add]}", + + // literal text + "add" }; + + MethodExpression mexp = null; + Class[] paramTypes = {}; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + SimpleELContext context = new SimpleELContext(); + + for (int i = 0; i < exprStr.length; ++i) { + try { + mexp = expFactory.createMethodExpression(context, exprStr[i], + Object.class, paramTypes); + } catch (NullPointerException npe) { + pass = false; + TestUtil.logErr(ELTestUtil.FAIL + exprStr[i]); + TestUtil.printStackTrace(npe); + continue; + } catch (ELException ee) { + pass = false; + TestUtil.logErr(ELTestUtil.FAIL + exprStr[i]); + TestUtil.printStackTrace(ee); + continue; + } + + if (!mexp.getExpressionString().equals(exprStr[i])) { + pass = false; + TestUtil.logErr("Failed. Expression string mismatch."); + TestUtil.logErr("Expected: " + exprStr[i]); + TestUtil.logErr("Received: " + mexp.getExpressionString()); + } + } + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + } + + /** + * @testName: createMethodExpressionELExceptionTest + * + * @assertion_ids: EL:JAVADOC:63; EL:JAVADOC:253 + * + * @test_Strategy: Verify that ExpressionFactory.createMethodExpression() + * throws an ELException for expressions with syntactical + * errors, and for expressions that are not lvalues. + */ + public void createMethodExpressionELExceptionTest() throws Exception { + + boolean pass = true; + + String[] exprStr = { + + // $ delimiter with missing bracket + "${vect.add", + + // # delimiter with incomplete [] operation + "#{vect[add}", + + // Expressions that are not lvalues + // constant value + "${ 5 }", + + // unary operation + "${ -A }", + + // binary operation + "${ A + B }", + + // multiple expressions + "${vect.remove}${vect.add}", "#{vect.remove}#{vect.add}", + "${vect.remove}#{vect.add}", "#{vect.remove}${vect.add}" + + }; + + Class[] paramTypes = {}; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + SimpleELContext context = new SimpleELContext(); + + for (int i = 0; i < exprStr.length; ++i) { + try { + expFactory.createMethodExpression(context, exprStr[i], Object.class, + paramTypes); + } catch (ELException ee) { + continue; + } catch (NullPointerException npe) { + pass = false; + TestUtil.logErr(ELTestUtil.FAIL + exprStr[i]); + TestUtil.printStackTrace(npe); + continue; + } + pass = false; + TestUtil.logErr("Failed. No ELException thrown when calling"); + TestUtil + .logErr("createMethodExpression() with parameter " + exprStr[i]); + } + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + } + + /** + * @testName: createExpressionNPETest + * + * @assertion_ids: EL:JAVADOC:62; EL:JAVADOC:63; EL:JAVADOC:64; + * EL:JAVADOC:253; EL:JAVADOC:254; EL:JAVADOC:256 + * + * @test_Strategy: Verify that ExpressionFactory.createValueExpression() and + * ExpressionFactory.createMethodExpression() throw a + * NullPointerException under the conditions stated in the + * javadoc. + */ + public void createExpressionNPETest() throws Exception { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + SimpleELContext context = new SimpleELContext(); + + TestUtil.logMsg("Testing: ELContext.createValueExpression(context, " + + "function, null)"); + ELTestUtil.checkForNPE(expFactory, "createValueExpression", + new Class[] { ELContext.class, String.class, Class.class }, + new Object[] { context, "function", null }); + + TestUtil.logMsg( + "Testing: ELContext.createValueExpression(instance, " + "null)"); + ELTestUtil.checkForNPE(expFactory, "createValueExpression", + new Class[] { Object.class, Class.class }, + new Object[] { "function", null }); + + TestUtil.logMsg("Testing: ELContext.createMethodExpression(context, " + + "instance, returnTypes, null)"); + ELTestUtil.checkForNPE(expFactory, "createMethodExpression", + new Class[] { ELContext.class, String.class, Class.class, + Class[].class }, + new Object[] { context, "${foo}", Object.class, null }); + + } + + /** + * @testName: coerceToTypeTest + * + * @assertion_ids: EL:JAVADOC:61 + * @test_Strategy: Verify that the coerceToType() method coerces an object to + * a specific type according to the EL type conversion rules. + */ + public void coerceToTypeTest() throws Exception { + + boolean pass = true; + + ObjectAndType[] testCases = { + new ObjectAndType("some string", String.class), + new ObjectAndType(null, String.class), + new ObjectAndType(Integer.valueOf(1), String.class), + new ObjectAndType(Double.valueOf(1.5d), String.class), + new ObjectAndType(Boolean.FALSE, String.class), + new ObjectAndType(Double.valueOf(1.5d), Integer.class), + new ObjectAndType(Integer.valueOf(1), Float.class), + new ObjectAndType("10000", Long.class), + new ObjectAndType("no value", Boolean.class), + new ObjectAndType(null, null) }; + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + + for (int i = 0; i < testCases.length; ++i) { + try { + Object coercedObj = expFactory.coerceToType(testCases[i].obj, + testCases[i].type); + if (coercedObj == null) { + if (!(testCases[i].type == null || testCases[i].obj == null)) { + pass = false; + TestUtil.logErr("Failed: Test Case " + i); + } + + } else if (!ExprEval.compareClass(coercedObj, testCases[i].type)) { + pass = false; + TestUtil.logErr("Failed: Test Case " + i); + } + } catch (Exception e) { + pass = false; + TestUtil.logErr("Exception: Test Case " + i); + TestUtil.printStackTrace(e); + } + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + } + + /** + * @testName: coerceToTypeELExceptionTest + * + * @assertion_ids: EL:JAVADOC:61; EL:JAVADOC:251 + * + * @test_Strategy: Verify that the coerceToType() method throws an ELException + * for invalid type conversions. + */ + public void coerceToTypeELExceptionTest() throws Exception { + + boolean pass = true; + + ObjectAndType[] testCases = { + new ObjectAndType(Integer.valueOf(1), Boolean.class), + new ObjectAndType(Boolean.FALSE, Long.class), + new ObjectAndType(Boolean.TRUE, Character.class), + new ObjectAndType(true, Float.class), + new ObjectAndType("non-numeric string", Long.class), + new ObjectAndType(Integer.valueOf(1), Class.class) }; + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + + for (int i = 0; i < testCases.length; ++i) { + try { + expFactory.coerceToType(testCases[i].obj, testCases[i].type); + pass = false; + TestUtil.logErr("Test Case " + i + " did not cause an exception"); + } catch (ELException elx) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Test Case " + i + " threw an exception"); + TestUtil.logErr("but it was not an ELException"); + TestUtil.printStackTrace(e); + } + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + } + + private static class ObjectAndType { + + public Object obj; + + public Class type; + + public ObjectAndType(Object obj, Class type) { + this.obj = obj; + this.type = type; + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/build.xml new file mode 100644 index 0000000000..ce2ae3e5a5 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/expressionfactory/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClient.java new file mode 100644 index 0000000000..784a758c19 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/ELClient.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.functionmapper; + +import java.lang.reflect.Method; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.elcontext.FuncMapperELContext; + +import jakarta.el.FunctionMapper; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: functionMapperTest + * + * @assertion_ids: EL:JAVADOC:35; EL:JAVADOC:67 + * @test_Strategy: Validate the behavior of ELContext.getFunctionMapper() + * FunctionMapper.resolveFunction() + */ + + public void functionMapperTest() throws Exception { + + String expected = "public static java.lang.Integer " + + "java.lang.Integer.valueOf" + + "(java.lang.String) throws java.lang.NumberFormatException"; + + FuncMapperELContext context = new FuncMapperELContext(); + FunctionMapper funcMapper = context.getFunctionMapper(); + TestUtil.logTrace("FunctionMapper is " + funcMapper.toString()); + + if (funcMapper.resolveFunction("foo", "bar") != null) { + TestUtil.logErr("Expected call to resolveFunction() to unassigned " + + "function to return null" + TestUtil.NEW_LINE + + "Instead call returned: " + + funcMapper.resolveFunction("foo", "bar").getName() + + TestUtil.NEW_LINE); + + throw new Exception("Resolved unassigned function"); + } + + Method method = funcMapper.resolveFunction("Int", "val"); + if (method == null) { + TestUtil.logErr("Expected call to resolveFunction() to resolvable " + + "function to return a non-null value" + TestUtil.NEW_LINE); + + throw new Exception("Incorrect resolution: null method"); + } else { + String methodSignature = method.toString(); + if (!methodSignature.equals(expected)) { + TestUtil.logErr("Method Signature of resolved function is " + "invalid" + + TestUtil.NEW_LINE + "Expected value:" + expected + + TestUtil.NEW_LINE); + + throw new Exception("Incorrect resolution: wrong method Signature"); + } + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/build.xml new file mode 100644 index 0000000000..24237c9460 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/functionmapper/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClient.java new file mode 100644 index 0000000000..15ac6495e9 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/ELClient.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.el.api.jakarta_el.lambdaexpression; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ExpressionFactory; +import jakarta.el.LambdaExpression; +import jakarta.el.StandardELContext; + +public class ELClient extends ServiceEETest { + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + TestUtil.logTrace("Cleanup method called"); + } + + /** + * @testName: invokeNPETest + * + * @assertion_ids: EL:JAVADOC:406 + * + * @test_Strategy: Throws a NullPointerException if elContext is null. + */ + + public void invokeNPETest() throws Exception { + List params = new ArrayList(); + params.add("one"); + LambdaExpression le = new LambdaExpression(params, null); + + ELTestUtil.checkForNPE(le, "invoke", + new Class[] { ELContext.class, Object[].class }, + new Object[] { null, new Object[] { "one" } }); + }// End invokeNPETest + + /** + * @testName: invokeELETest + * + * @assertion_ids: EL:JAVADOC:408 + * + * @test_Strategy: Throws a ELException if not enough arguments are provided. + */ + + public void invokeELETest() throws Exception { + StringBuffer buff = new StringBuffer(); + boolean pass = false; + List params = new ArrayList(); + params.add("one"); + + LambdaExpression le = new LambdaExpression(params, null); + try { + le.invoke(new StandardELContext(ExpressionFactory.newInstance()), + new Object[] {}); + buff.append(ELTestUtil.FAIL + " No Exception thrown!" + ELTestUtil.NL + + "Expected an ELException to be thrown!"); + } catch (ELException ele) { + TestUtil.logMsg(ELTestUtil.PASS); + pass = true; + } catch (Exception e) { + TestUtil.logMsg(ELTestUtil.FAIL + ELTestUtil.NL + "Expected: ELException" + + ELTestUtil.NL + "Received: " + e.getClass().getSimpleName()); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + }// End invokeELETest + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/build.xml new file mode 100644 index 0000000000..8b90a7e45e --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/lambdaexpression/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClient.java new file mode 100644 index 0000000000..6bfe6f166a --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/ELClient.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.listelresolver; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +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; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELContext; +import jakarta.el.ListELResolver; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + private List names; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + names = new ArrayList(); + names.add("doug"); + names.add("nick"); + names.add("ryan"); + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: listELResolverTest + * + * @assertion_ids: EL:JAVADOC:68; EL:JAVADOC:69; EL:JAVADOC:70; EL:JAVADOC:71; + * EL:JAVADOC:72; EL:JAVADOC:73; EL:JAVADOC:75 + * + * @test_Strategy: Verify that API calls work as expected: ListELResolver() + * getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() getFeatureDescriptors() + */ + + public void listELResolverTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + ListELResolver listResolver = new ListELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + pass = ResolverTest.testELResolver(context, listResolver, names, + Integer.valueOf(1), "ed", buf, false); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: listELResolverNPETest + * + * @assertion_ids: EL:JAVADOC:70; EL:JAVADOC:71; EL:JAVADOC:72; EL:JAVADOC:73; + * EL:JAVADOC:75; EL:JAVADOC:276; EL:JAVADOC:279; + * EL:JAVADOC:282; EL:JAVADOC:285 + * + * @test_Strategy: Verify that the following methods throw a + * NullPointerException, if context is null: + * + * getType() getValue() isReadOnly() setValue() + */ + + public void listELResolverNPETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + ListELResolver resolver = new ListELResolver(); + + try { + pass = ResolverTest.testELResolverNPE(resolver, names, Integer.valueOf(1), + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: listELResolverPNFETest + * + * @assertion_ids: EL:JAVADOC:70; EL:JAVADOC:72; EL:JAVADOC:73; EL:JAVADOC:75; + * EL:JAVADOC:275; EL:JAVADOC:281; EL:JAVADOC:288 + * @test_Strategy: Verify that the following methods throw a + * PropertyNotFoundException, if the given index is out of + * bounds for this list: + * + * getType() isReadOnly() setValue() + */ + public void listELResolverPNFETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + ListELResolver resolver = new ListELResolver(); + BareBonesELContext barebonesComtext = new BareBonesELContext(); + ELContext context = barebonesComtext.getELContext(); + + try { + pass = ResolverTest.testELResolverPNFE(context, resolver, names, + Integer.valueOf(10), buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: listELResolverIAETest + * + * @assertion_ids: EL:JAVADOC:71; EL:JAVADOC:73; EL:JAVADOC:75; + * EL:JAVADOC:278; EL:JAVADOC:286 + * + * @test_Strategy: Verify that the following methods throw an + * IllegalArgumentException, if the property could not be + * coerced into an integer: + * + * getValue() setValue() + */ + public void listELResolverIAETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + ListELResolver resolver = new ListELResolver(); + BareBonesELContext barebonesComtext = new BareBonesELContext(); + ELContext context = barebonesComtext.getELContext(); + + try { + pass = ResolverTest.testELResolverIAE(context, resolver, names, "GARBAGE", + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: listELResolverPNWETest + * + * @assertion_ids: EL:JAVADOC:74; EL:JAVADOC:75; EL:JAVADOC:287 + * + * @test_Strategy: Verify that the single-parameter constructor for + * listELResolver can be used to construct a read-only + * resolver, and that the setValue() method throws a + * PropertyNotWritableException, if the resolver was + * constructed in read-only mode. + * + * ListELResolver(boolean) setValue() + */ + public void listELResolverPNWETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + ListELResolver resolver = new ListELResolver(true); + BareBonesELContext barebonesComtext = new BareBonesELContext(); + ELContext context = barebonesComtext.getELContext(); + + try { + pass = ResolverTest.testELResolverPNWE(context, resolver, names, + Integer.valueOf(1), "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/build.xml new file mode 100644 index 0000000000..bfe7db2e8a --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/listelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClient.java new file mode 100644 index 0000000000..bb4d3850e6 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/ELClient.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.mapelresolver; + +import java.util.HashMap; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +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; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELContext; +import jakarta.el.MapELResolver; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + private HashMap animals; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + animals = new HashMap(); + animals.put("dog", "retriever"); + animals.put("fish", "bass"); + animals.put("bird", "parrot"); + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: mapELResolverTest + * + * @assertion_ids: EL:JAVADOC:76; EL:JAVADOC:77; EL:JAVADOC:78; EL:JAVADOC:79; + * EL:JAVADOC:80; EL:JAVADOC:81; EL:JAVADOC:83 + * @test_Strategy: Verify that API calls work as expected: MapELResolver() + * getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() getFeatureDescriptors() + */ + + public void mapELResolverTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + MapELResolver mapResolver = new MapELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + pass = ResolverTest.testELResolver(context, mapResolver, animals, "dog", + "labador", buf, false); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: mapELResolverNPETest + * + * @assertion_ids: EL:JAVADOC:78; EL:JAVADOC:79; EL:JAVADOC:80; EL:JAVADOC:81; + * EL:JAVADOC:83; EL:JAVADOC:293; EL:JAVADOC:295; + * EL:JAVADOC:298; EL:JAVADOC:290 + * + * @test_Strategy: Verify that the following methods throw a + * NullPointerException, if context is null: + * + * getType() getValue() isReadOnly() setValue() + */ + public void mapELResolverNPETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + MapELResolver resolver = new MapELResolver(); + + try { + pass = ResolverTest.testELResolverNPE(resolver, animals, "dog", "billy", + buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: mapELResolverPNWETest + * + * @assertion_ids: EL:JAVADOC:82; EL:JAVADOC:83; EL:JAVADOC:301 + * + * @test_Strategy: Verify that the single-parameter constructor for + * mapELResolver can be used to construct a read-only + * resolver, and that the setValue() method throws a + * PropertyNotWritableException, if the resolver was + * constructed in read-only mode. + * + * MapELResolver(boolean) setValue() + */ + public void mapELResolverPNWETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + MapELResolver resolver = new MapELResolver(true); + BareBonesELContext barebonesComtext = new BareBonesELContext(); + ELContext context = barebonesComtext.getELContext(); + + try { + pass = ResolverTest.testELResolverPNWE(context, resolver, animals, "dog", + "billy", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/build.xml new file mode 100644 index 0000000000..9304605e51 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/mapelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClient.java new file mode 100644 index 0000000000..56a3b49a42 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/ELClient.java @@ -0,0 +1,685 @@ +/* + * Copyright (c) 2009, 2021 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.methodexpression; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.common.el.api.expression.ExpressionTest; +import com.sun.ts.tests.el.common.elcontext.SimpleELContext; +import com.sun.ts.tests.el.common.elcontext.VarMapperELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.MethodsBean; +import com.sun.ts.tests.el.common.util.ResolverType; + +import jakarta.el.ELContext; +import jakarta.el.ELException; +import jakarta.el.ExpressionFactory; +import jakarta.el.MethodExpression; +import jakarta.el.MethodNotFoundException; +import jakarta.el.PropertyNotFoundException; +import jakarta.el.ValueExpression; + +public class ELClient extends ServiceEETest { + + private static final String NL = System.getProperty("line.seperator", "\n"); + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: positiveMethodExpressionTest + * + * @assertion_ids: EL:JAVADOC:84; EL:JAVADOC:85; EL:JAVADOC:58; EL:JAVADOC:60 + * @test_Strategy: Validate the behavior of MethodExpression API + * MethodExpression.getMethodInfo() MethodExpression.invoke() + * Expression.isLiteralText() Expression.getExpressionString() + */ + + public void positiveMethodExpressionTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + + boolean pass1, pass2, pass3, pass4; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + + SimpleELContext simpleContext = new SimpleELContext( + ResolverType.VECT_ELRESOLVER); + ELContext context = simpleContext.getELContext(); + + // case 1: non-null return value + Object[] params1 = new Object[] { "new member" }; + Class[] paramTypes1 = { Object.class }; + String exprStr1 = "#{vect.add}"; + + MethodExpression mexp1 = expFactory.createMethodExpression(context, + exprStr1, boolean.class, paramTypes1); + pass1 = ExpressionTest.testMethodExpression(mexp1, context, exprStr1, + params1, Boolean.TRUE, false, buf); + + // case 2: null return value + Object[] params2 = new Object[] { Integer.valueOf(0), "new member" }; + Class[] paramTypes2 = { int.class, Object.class }; + String exprStr2 = "#{vect.add}"; + + MethodExpression mexp2 = expFactory.createMethodExpression(context, + exprStr2, null, paramTypes2); + pass2 = ExpressionTest.testMethodExpression(mexp2, context, exprStr2, + params2, null, false, buf); + + // case 3: literal expression returning String + Object[] params3 = null; + Class[] paramTypes3 = {}; + String exprStr3 = "true"; + + MethodExpression mexp3 = expFactory.createMethodExpression(context, + exprStr3, String.class, paramTypes3); + pass3 = ExpressionTest.testMethodExpression(mexp3, context, exprStr3, + params3, "true", true, buf); + + // case 4: literal expression returning non-String value + Object[] params4 = null; + Class[] paramTypes4 = {}; + String exprStr4 = "true"; + + MethodExpression mexp4 = expFactory.createMethodExpression(context, + exprStr4, Boolean.class, paramTypes4); + pass4 = ExpressionTest.testMethodExpression(mexp4, context, exprStr4, + params4, Boolean.TRUE, true, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!(pass1 && pass2 && pass3 && pass4)) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + + /** + * @testName: negativeMethodExpressionTest + * + * @assertion_ids: EL:JAVADOC:84; EL:JAVADOC:85; EL:JAVADOC:302; + * EL:JAVADOC:306; EL:JAVADOC:303; EL:JAVADOC:307; + * EL:JAVADOC:309; EL:JAVADOC:310; EL:JAVADOC:304; + * EL:JAVADOC:308 + * + * @test_Strategy: Validate the behavior of MethodExpression API + * MethodExpression.getMethodInfo() MethodExpression.invoke() + */ + + public void negativeMethodExpressionTest() throws Exception { + + boolean pass = true; + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + + SimpleELContext simpleContext = new SimpleELContext( + ResolverType.VECT_ELRESOLVER); + ELContext context = simpleContext.getELContext(); + + Object[] params = new Object[] { "new member" }; + Class[] paramTypes = { Object.class }; + + // case 1: NullPointerException. Null ELContext passed to methods. + String exprStr1 = "#{vect.add}"; + + MethodExpression mexp1 = expFactory.createMethodExpression(context, + exprStr1, boolean.class, paramTypes); + try { + mexp1.getMethodInfo(null); + pass = false; + TestUtil.logErr("Call to getMethodInfo() with null ELContext " + + "parameter did not" + NL); + TestUtil.logErr(" cause an exception to be thrown" + NL); + + } catch (NullPointerException npe) { + // do nothing test passed! + TestUtil.logMsg("Expected Exception Thrown, when Null ELContext " + + "passed to getMethodInfo(): " + npe.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to getMethodInfo() with null ELContext " + + "threw the wrong Exception!" + NL + "Expected: NullPointerException" + + NL + "Received: " + e.toString() + NL); + + e.printStackTrace(); + } + + try { + mexp1.invoke(null, params); + pass = false; + TestUtil.logErr( + "Call to invoke() with null ELContext parameter did " + "not" + NL); + TestUtil.logErr(" cause an exception to be thrown" + NL); + + } catch (NullPointerException npe) { + // Do nothing test passed! + TestUtil.logMsg("Expected Exception Thrown, when Null ELContext " + + "passed to invoke(): " + npe.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to invoke() with null ELContext " + + "throw the wrong Exception!" + NL + "Expected: NullPointerException" + + NL + "Received: " + e.toString() + NL); + + e.printStackTrace(); + } + + // case 2: MethodNotFoundException. Property found, but + // method does not exist. + String exprStr2 = "#{vect.noSuchMethod}"; + + MethodExpression mexp2 = expFactory.createMethodExpression(context, + exprStr2, boolean.class, paramTypes); + try { + mexp2.getMethodInfo(context); + pass = false; + TestUtil.logErr("Call to getMethodInfo() for non-existent method did " + + "not cause" + NL); + TestUtil.logErr(" an exception to be thrown" + NL); + + } catch (MethodNotFoundException mnfe) { + // do nothing test passed! + TestUtil.logMsg("Expected Exception Thrown, when method does not " + + "exists for getMethodInfo(): " + mnfe.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr( + "Call to getMethodInfo() for non-existent method threw the wrong " + + "exception!" + NL + "Expected: MethodNotFoundException" + NL + + "Received: " + e.toString() + NL); + + e.printStackTrace(); + } + + try { + mexp2.invoke(context, params); + pass = false; + TestUtil.logErr( + "Call to invoke() for non-existent method did not " + "cause" + NL); + TestUtil.logErr(" an exception to be thrown" + NL); + + } catch (MethodNotFoundException mnfe) { + // do thing test passed! + TestUtil.logMsg("Expected Exception Thrown, when method does not " + + "exists for invoke(): " + mnfe.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr( + "Call to getMethodInfo() for non-existent method threw the wrong " + + "exception!" + NL + "Expected: MethodNotFoundException" + NL + + "Received: " + e.toString() + NL); + + e.printStackTrace(); + } + + // case 3: PropertyNotFoundException: No such property in ELContext. + String exprStr3 = "#{wect.add}"; + + MethodExpression mexp3 = expFactory.createMethodExpression(context, + exprStr3, boolean.class, paramTypes); + + try { + mexp3.getMethodInfo(context); + pass = false; + TestUtil.logErr("Call to getMethodInfo() for non-existent property " + + "did not cause" + NL); + TestUtil.logErr(" an exception to be thrown" + NL); + + } catch (PropertyNotFoundException pnfe) { + // Do nothing test passed! + TestUtil.logMsg( + "Expected Exception Thrown, No such property in " + "ELContext" + + "for getMethodInfo(): " + pnfe.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr( + "Call to getMethodInfo() for non-existent property threw the wrong " + + "exception!" + NL + "Expected: PropertyNotFoundException" + NL + + "Received: " + e.toString() + NL); + + e.printStackTrace(); + } + + try { + mexp3.invoke(context, params); + pass = false; + TestUtil.logErr("Call to invoke() for non-existent property did " + "not " + + "cause" + NL); + TestUtil.logErr(" an exception to be thrown" + NL); + + } catch (PropertyNotFoundException pnfe) { + // Do nothing test passed! + TestUtil.logMsg("Expected Exception Thrown, No such property in " + + "ELContext" + "for invoke(): " + pnfe.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr( + "Call to invoke() for non-existent property threw " + "the wrong " + + "exception!" + NL + "Expected: PropertyNotFoundException" + NL + + "Received: " + e.toString() + NL); + + e.printStackTrace(); + } + + // case 4: ELException: Call to invoke() with string literal. + // Expected return type is void. + String exprStr4 = "literal"; + + MethodExpression mexp4 = expFactory.createMethodExpression(context, + exprStr4, void.class, paramTypes); + + try { + mexp4.invoke(context, params); + pass = false; + TestUtil.logErr( + "Call to invoke() for string literal with expected " + "return" + NL); + TestUtil.logErr( + " value of void did not cause an exception to be " + "thrown" + NL); + + } catch (ELException ee) { + // Do nothing test passed! + TestUtil.logMsg("Expected Exception Thrown. Call to invoke() with " + + "string literal ELContext for invoke()." + NL + + "Expected return type is void: " + ee.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to invoke() for string literal with expected return" + + NL + "value of void caused the wrong exception to be thrown!" + NL + + "Expected: ELException: " + NL + "Received: " + e.toString()); + + e.printStackTrace(); + } + + // case 5: ELException: Call to invoke() with string literal. + // Expected return type can't be coerced. + String exprStr5 = "literal"; + + MethodExpression mexp5 = expFactory.createMethodExpression(context, + exprStr5, Double.class, paramTypes); + + try { + mexp5.invoke(context, params); + pass = false; + TestUtil.logErr("Call to invoke() for string literal with " + + "non-coercable expected " + NL); + TestUtil.logErr( + "return value did not cause an exception to be " + "thrown" + NL); + + } catch (ELException ee) { + // Do nothing test passed! + TestUtil.logMsg("Expected Exception Thrown. Call to invoke() with " + + "string literal ELContext for " + "invoke()." + NL + + "Expected return type can't be coerced: " + + ee.getClass().getSimpleName()); + + } catch (Exception e) { + pass = false; + TestUtil.logErr( + "Call to invoke() for string literal with non-coercable expected " + + NL + "return value caused the wrong exception to be thrown!" + + NL + "Expected: ELException: " + NL + "Received: " + + e.toString()); + + e.printStackTrace(); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL); + + } + + /* + * @testName: methodExpressionSerializableTest + * + * @assertion_ids: EL:SPEC:44 + * + * @test_Strategy: Validate that MethodExpression implements Serializable and + * that a MethodExpression can be manually serialized and deserialized. + */ + public void methodExpressionSerializableTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + Class[] paramTypes = { Object.class }; + String exprStr = "#{vect.add}"; + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new SimpleELContext()).getELContext(); + + // Setup eval-expression + MethodExpression evalmexp = expFactory.createMethodExpression(context, + exprStr, Boolean.class, paramTypes); + TestUtil.logTrace( + "Eval Method Expression For Testing: " + evalmexp.toString() + NL); + + // Setup literal-expression + MethodExpression literalmexp = expFactory.createMethodExpression(context, + "vect.add", Boolean.class, paramTypes); + TestUtil.logTrace("Literal Method Expression For Testing: " + + literalmexp.toString() + NL); + + // Test both eval & literal expressions. + if (!(ExpressionTest.expressionSerializableTest(evalmexp, buf) + && ExpressionTest.expressionSerializableTest(literalmexp, buf))) { + pass = false; + } + + } catch (Exception ex) { + throw new Exception(ex); + + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + else + TestUtil.logTrace(buf.toString()); + } + + /* + * @testName: methodExpressionMatchingExactPreferredTest + * + * @assertion_ids: EL:SPEC:80 + * + * @test_Strategy: Validate that MethodExpression identifies the correct + * method for the given parameters and that exact type matches are always + * preferred. + */ + public void methodExpressionMatchingExactPreferredTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + String exprStr = "#{bean.targetA('text')}"; + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new VarMapperELContext(testProps)).getELContext(); + + MethodsBean bean = new MethodsBean(); + ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.class); + context.getVariableMapper().setVariable("bean", ve); + + // Single String arg so should match to "String" + MethodExpression me = expFactory.createMethodExpression(context, exprStr, String.class, null); + if (!ExpressionTest.testMethodExpression(me, context, exprStr, null, "String", false, buf)) { + pass = false; + } + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Call to getMethodInfo() with valid method expression " + + "threw an Exception!" + NL + "Received: " + ex.toString() + NL); + + ex.printStackTrace(); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + else + TestUtil.logTrace(buf.toString()); + } + + /* + * @testName: methodExpressionMatchingOverloadBeatsCoercionTest + * + * @assertion_ids: EL:SPEC:80 + * + * @test_Strategy: Validate that MethodExpression identifies the correct + * method for the given parameters and that overloading is preferred to + * coercion. + */ + public void methodExpressionMatchingOverloadBeatsCoercionTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + String exprStr = "#{bean.targetB('1')}"; + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new VarMapperELContext(testProps)).getELContext(); + + MethodsBean bean = new MethodsBean(); + ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.class); + context.getVariableMapper().setVariable("bean", ve); + + MethodExpression me = expFactory.createMethodExpression(context, exprStr, String.class, null); + if (!ExpressionTest.testMethodExpression(me, context, exprStr, null, "CharSequence", false, buf)) { + pass = false; + } + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Call to getMethodInfo() with valid method expression " + + "threw an Exception!" + NL + "Received: " + ex.toString() + NL); + + ex.printStackTrace(); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + else + TestUtil.logTrace(buf.toString()); + } + + /* + * @testName: methodExpressionMatchingOverloadBeatsExactVarArgsTest + * + * @assertion_ids: EL:SPEC:80 + * + * @test_Strategy: Validate that MethodExpression identifies the correct + * method for the given parameters and that any match without varags is + * preferred to all matches with varrags + */ + public void methodExpressionMatchingOverloadBeatsExactVarArgsTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + String exprStr = "#{bean.targetC('aaa','bbb')}"; + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new VarMapperELContext(testProps)).getELContext(); + + MethodsBean bean = new MethodsBean(); + ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.class); + context.getVariableMapper().setVariable("bean", ve); + + MethodExpression me = expFactory.createMethodExpression(context, exprStr, String.class, null); + if (!ExpressionTest.testMethodExpression(me, context, exprStr, null, "CharSequence-CharSequence", false, buf)) { + pass = false; + } + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Call to getMethodInfo() with valid method expression " + + "threw an Exception!" + NL + "Received: " + ex.toString() + NL); + + ex.printStackTrace(); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + else + TestUtil.logTrace(buf.toString()); + } + + /* + * @testName: methodExpressionMatchingCoercionBeatsExactVarArgsTest + * + * @assertion_ids: EL:SPEC:80 + * + * @test_Strategy: Validate that MethodExpression identifies the correct + * method for the given parameters and that any match without varags is + * preferred to all matches with varrags + */ + public void methodExpressionMatchingCoercionBeatsExactVarArgsTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + String exprStr = "#{bean.targetD('1','1')}"; + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new VarMapperELContext(testProps)).getELContext(); + + MethodsBean bean = new MethodsBean(); + ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.class); + context.getVariableMapper().setVariable("bean", ve); + + MethodExpression me = expFactory.createMethodExpression(context, exprStr, String.class, null); + if (!ExpressionTest.testMethodExpression(me, context, exprStr, null, "Long-Long", false, buf)) { + pass = false; + } + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Call to getMethodInfo() with valid method expression " + + "threw an Exception!" + NL + "Received: " + ex.toString() + NL); + + ex.printStackTrace(); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + else + TestUtil.logTrace(buf.toString()); + } + + /* + * @testName: methodExpressionMatchingVarArgsTest + * + * @assertion_ids: EL:SPEC:80 + * + * @test_Strategy: Validate that MethodExpression identifies the correct + * method for the given parameters and that varags will be matched if no other + * suitable match is available + */ + public void methodExpressionMatchingVarArgsTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + String exprStr = "#{bean.targetD('aaa','bbb')}"; + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new VarMapperELContext(testProps)).getELContext(); + + MethodsBean bean = new MethodsBean(); + ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.class); + context.getVariableMapper().setVariable("bean", ve); + + MethodExpression me = expFactory.createMethodExpression(context, exprStr, String.class, null); + if (!ExpressionTest.testMethodExpression(me, context, exprStr, null, "String-Strings", false, buf)) { + pass = false; + } + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Call to getMethodInfo() with valid method expression " + + "threw an Exception!" + NL + "Received: " + ex.toString() + NL); + + ex.printStackTrace(); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + else + TestUtil.logTrace(buf.toString()); + } + + /* + * @testName: methodExpressionMatchingAmbiguousTest + * + * @assertion_ids: EL:SPEC:80 + * + * @test_Strategy: Validate that MethodExpression does not match a method when + * the match is ambiguous and that a MethodNotFoundException is thrown + */ + public void methodExpressionMatchingAmbiguousTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + String exprStr = "#{bean.targetE('1234',1234)}"; + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new VarMapperELContext(testProps)).getELContext(); + + MethodsBean bean = new MethodsBean(); + ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.class); + context.getVariableMapper().setVariable("bean", ve); + + MethodExpression me = expFactory.createMethodExpression(context, exprStr, String.class, null); + me.getMethodInfo(context); + pass = false; + } catch (MethodNotFoundException mnfe) { + pass = true; + } catch (Exception ex) { + pass = false; + TestUtil.logErr("Call to getMethodInfo() with ambiguous method expression " + + "threw the wrong Exception!" + NL + "Expected: MethodNotFoundException" + + NL + "Received: " + ex.toString() + NL); + + ex.printStackTrace(); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + else + TestUtil.logTrace(buf.toString()); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/build.xml new file mode 100644 index 0000000000..3ef4104d50 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodexpression/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClient.java new file mode 100644 index 0000000000..b5cf68deea --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/ELClient.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.methodinfo; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.common.el.api.expression.ExpressionTest; +import com.sun.ts.tests.el.common.elcontext.SimpleELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.ResolverType; + +import jakarta.el.ELContext; +import jakarta.el.ExpressionFactory; +import jakarta.el.MethodExpression; +import jakarta.el.MethodInfo; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + /** + * @testName: methodInfoTest + * + * @assertion_ids: EL:JAVADOC:411;EL:JAVADOC:412;EL:JAVADOC:413 + * @test_Strategy: Validate the behavior of MethodInfo MethodInfo class + * methods: MethodInfo.getName() MethodInfo.getReturnType() + * MethodInfo.getParamTypes() + */ + + public void methodInfoTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + + boolean pass1, pass2, pass3, pass4 = false; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + + SimpleELContext simpleContext = new SimpleELContext( + ResolverType.VECT_ELRESOLVER); + ELContext context = simpleContext.getELContext(); + + // case 1: non-null return value + Class[] paramTypes1 = { Object.class }; + MethodExpression mexp1 = expFactory.createMethodExpression(context, + "#{vect.add}", boolean.class, paramTypes1); + MethodInfo minfo1 = mexp1.getMethodInfo(context); + pass1 = ExpressionTest.testMethodInfo(minfo1, "add", boolean.class, 1, + paramTypes1, buf); + + // case 2: null return value + Class[] paramTypes2 = { int.class, Object.class }; + + MethodExpression mexp2 = expFactory.createMethodExpression(context, + "#{vect.add}", null, paramTypes2); + MethodInfo minfo2 = mexp2.getMethodInfo(context); + pass2 = ExpressionTest.testMethodInfo(minfo2, "add", void.class, 2, + paramTypes2, buf); + + // case 3: literal expression returning String + Class[] paramTypes3 = {}; + + MethodExpression mexp3 = expFactory.createMethodExpression(context, + "true", String.class, paramTypes3); + MethodInfo minfo3 = mexp3.getMethodInfo(context); + pass3 = ExpressionTest.testMethodInfo(minfo3, "true", String.class, 0, + paramTypes3, buf); + + // case 4: literal expression returning non-String value + Class[] paramTypes4 = {}; + + MethodExpression mexp4 = expFactory.createMethodExpression(context, + "true", Boolean.class, paramTypes4); + MethodInfo minfo4 = mexp4.getMethodInfo(context); + pass4 = ExpressionTest.testMethodInfo(minfo4, "true", Boolean.class, 0, + paramTypes4, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!(pass1 && pass2 && pass3 && pass4)) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/build.xml new file mode 100644 index 0000000000..0e2d82e25e --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodinfo/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClient.java new file mode 100644 index 0000000000..495f8ebf56 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/methodreference/ELClient.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ +package com.sun.ts.tests.el.api.jakarta_el.methodreference; + +import java.util.Properties; +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; + + +import com.sun.ts.tests.el.common.util.Fault; +import com.sun.ts.tests.common.el.api.expression.ExpressionTest; +import com.sun.ts.tests.el.common.elcontext.VarMapperELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.MethodsBean; + +import jakarta.el.ELContext; +import jakarta.el.ExpressionFactory; +import jakarta.el.MethodExpression; +import jakarta.el.MethodInfo; +import jakarta.el.MethodNotFoundException; +import jakarta.el.MethodReference; +import jakarta.el.PropertyNotFoundException; +import jakarta.el.ValueExpression; + + +public class ELClient extends ServiceEETest { + + private static final String NL = System.getProperty("line.seperator", "\n"); + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + + + /** + * @testName: methodReferenceTest + * + * @assertion_ids: EL:JAVADOC:87; EL:JAVADOC:88; EL:JAVADOC:89 + * @test_Strategy: Validate the behavior of MethodReference class methods: + * MethodReference.getBase() MethodReference.getMethodInfo() + * MethodReference.getAnnotations() + * MethodReference.getEvaluatedParameters + */ + public void methodReferenceTest() throws Fault { + + StringBuffer buf = new StringBuffer(); + + boolean pass1, pass2, pass3, pass4; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new VarMapperELContext(testProps)).getELContext(); + + MethodsBean bean = new MethodsBean(); + ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.class); + context.getVariableMapper().setVariable("bean", ve); + + // case 1: non-null return value + MethodExpression mexp1 = expFactory.createMethodExpression( + context, "#{bean.targetF('aaa',1234)}", String.class, null); + MethodInfo minfo1 = mexp1.getMethodInfo(context); + MethodReference mref1 = mexp1.getMethodReference(context); + pass1 = ExpressionTest.testMethodReference(mref1, bean, minfo1, + new Class[] { Deprecated.class }, + new Object[] { "aaa", Long.valueOf(1234) }, + buf); + + // case 2: NPE + try { + mexp1.getMethodReference(null); + pass2 = false; + buf.append("Did not get expected NullPointerException for null context." + NL); + } catch (NullPointerException npe) { + pass2 = true; + } + + // case 3: PNFE + MethodExpression mexp3 = expFactory.createMethodExpression( + context, "#{noSuchBean.method()}", String.class, null); + try { + mexp3.getMethodReference(context); + pass3 = false; + buf.append("Did not get expected PropertyNotFoundException return for unknown bean." + NL); + } catch (PropertyNotFoundException pnfe) { + pass3 = true; + } + + // case 4: MNFE + MethodExpression mexp4 = expFactory.createMethodExpression( + context, "#{bean.noSuchMethod()}", String.class, null); + try { + mexp4.getMethodReference(context); + pass4 = false; + buf.append("Did not get expected MethodNotFoundException return for unknown bean." + NL); + } catch (MethodNotFoundException mnfe) { + pass4 = true; + } + + } catch (Exception ex) { + TestUtil.logErr("Test getMethodReference threw an Exception!" + ELTestUtil.NL + + "Received: " + ex.toString() + ELTestUtil.NL); + ex.printStackTrace(); + throw new Fault(ex); + } + + if (!(pass1 && pass2 && pass3 && pass4)) + throw new Fault(ELTestUtil.FAIL + NL + buf.toString()); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClient.java new file mode 100644 index 0000000000..97eed91642 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/optionalelresolver/ELClient.java @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ +package com.sun.ts.tests.el.api.jakarta_el.optionalelresolver; + +import java.lang.System.Logger; +import java.util.Optional; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import java.util.Properties; + +import com.sun.ts.tests.el.common.elcontext.BareBonesELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.BeanELResolver; +import jakarta.el.CompositeELResolver; +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.MethodNotFoundException; +import jakarta.el.OptionalELResolver; +import jakarta.el.PropertyNotWritableException; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + /** + * @testName: optionalELResolverEmptyNullTest + * + * @test_Strategy: Verify that API calls work as expected for: getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() when the base object is an empty Optional and the property is null + */ + public void optionalELResolverEmptyNullTest() throws Exception { + + boolean pass = true; + StringBuffer buf = new StringBuffer(); + Object testObject = Optional.empty(); + + pass = testOptionalELResolverProperty(buf, testObject, null, null); + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: optionalELResolverEmptyNonNullTest + * + * @test_Strategy: Verify that API calls work as expected for: getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() when the base object is an empty Optional and the property is non-null + */ + public void optionalELResolverEmptyNonNullTest() throws Exception { + + boolean pass = true; + StringBuffer buf = new StringBuffer(); + Object testObject = Optional.empty(); + + pass = testOptionalELResolverProperty(buf, testObject, "property", null); + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: optionalELResolverObjectNullTest + * + * @test_Strategy: Verify that API calls work as expected for: getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() when the base object is an non-empty Optional and the property is null + */ + public void optionalELResolverObjectNullTest() throws Exception { + + boolean pass = true; + StringBuffer buf = new StringBuffer(); + TestBean testBean = new TestBean("data"); + Object testObject = Optional.of(testBean); + + pass = testOptionalELResolverProperty(buf, testObject, null, testBean); + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: optionalELResolverObjectNullTest + * + * @test_Strategy: Verify that API calls work as expected for: getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() when the base object is an non-empty Optional and the property is non-null + */ + public void optionalELResolverObjectNonNullTest() throws Exception { + + boolean pass = true; + StringBuffer buf = new StringBuffer(); + TestBean testBean = new TestBean("data"); + Object testObject = Optional.of(testBean); + + pass = testOptionalELResolverProperty(buf, testObject, "propertyA", "data"); + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + public static boolean testOptionalELResolverProperty(StringBuffer buf, Object base, Object property, Object expectedValue) { + boolean pass = true; + + BareBonesELContext barebonesContext = new BareBonesELContext(); + + // OptionalELResolver depends on BeanELResolver to resolve properties of an object wrapped in an Optional + ELResolver resolver = barebonesContext.getELResolver(); + BeanELResolver beanResolver = new BeanELResolver(); + OptionalELResolver optionalResolver = new OptionalELResolver(); + ((CompositeELResolver) resolver).add(optionalResolver); + ((CompositeELResolver) resolver).add(beanResolver); + + ELContext context = barebonesContext.getELContext(); + + // getValue() + Object result = resolver.getValue(context, base, property); + if (expectedValue == null && result != null || expectedValue != null && !expectedValue.equals(result)) { + buf.append("getValue(): Expected [" + expectedValue + "] but got [" + result + "]"); + pass = false; + } + + // getType() + result = resolver.getType(context, base, property); + if (result != null) { + pass = false; + } + + // setValue() + try { + resolver.setValue(context, base, property, "anything"); + pass = false; + } catch (PropertyNotWritableException pnwe) { + // Expected + } + + // isReadOnly() + boolean bResult = resolver.isReadOnly(context, base, property); + if (!bResult) { + pass = false; + } + + // getCommonPropertyType() + result = resolver.getCommonPropertyType(context, base); + if (result != Object.class) { + pass = false; + } + + return pass; + } + + /** + * @testName: optionalELResolverEmptyInvoke + * + */ + public void optionalELResolverEmptyInvoke() throws Exception { + boolean pass = true; + StringBuffer buf = new StringBuffer(); + Object testObject = Optional.empty(); + + pass = testOptionalELResolverInvoke(buf, testObject, "doSomething", null); + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: optionalELResolverEmptyInvokeInvalid + * + */ + public void optionalELResolverEmptyInvokeInvalid() throws Exception { + boolean pass = true; + StringBuffer buf = new StringBuffer(); + Object testObject = Optional.empty(); + + pass = testOptionalELResolverInvoke(buf, testObject, "unknownMethod", null); + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: optionalELResolverObjectInvoke + * + */ + public void optionalELResolverObjectInvoke() throws Exception { + boolean pass = true; + StringBuffer buf = new StringBuffer(); + TestBean testBean = new TestBean("data"); + Object testObject = Optional.of(testBean); + + pass = testOptionalELResolverInvoke(buf, testObject, "doSomething", TestBean.DATA); + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: optionalELResolverObjectInvokeInvalid + * + */ + public void optionalELResolverObjectInvokeInvalid() throws Exception { + boolean pass = true; + StringBuffer buf = new StringBuffer(); + TestBean testBean = new TestBean("data"); + Object testObject = Optional.of(testBean); + + try { + testOptionalELResolverInvoke(buf, testObject, "unknownMethod", null); + pass = false; + buf.append("invoke(): Expected MethodNotFoundException but no exception was thrown"); + } catch (MethodNotFoundException mnfe) { + // Expected (so pass is not set to false) + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + public static boolean testOptionalELResolverInvoke(StringBuffer buf, Object base, Object method, Object expectedValue) { + boolean pass = true; + + BareBonesELContext barebonesContext = new BareBonesELContext(); + + // OptionalELResolver depends on BeanELResolver to invoke methods of an object wrapped in an Optional + ELResolver resolver = barebonesContext.getELResolver(); + BeanELResolver beanResolver = new BeanELResolver(); + OptionalELResolver optionalResolver = new OptionalELResolver(); + ((CompositeELResolver) resolver).add(optionalResolver); + ((CompositeELResolver) resolver).add(beanResolver); + ELContext context = barebonesContext.getELContext(); + + // invoke() + Object result = resolver.invoke(context, base, method, null, null); + if (expectedValue == null && result != null || expectedValue != null && !expectedValue.equals(result)) { + buf.append("invoke(): Expected [" + expectedValue + "] but got [" + result + "]"); + pass = false; + } + + return pass; + } + + public static class TestBean { + private static final String DATA = "interesting data"; + private final String propertyA; + public TestBean(String propertyA) { + this.propertyA = propertyA; + } + public String getPropertyA() { + return propertyA; + } + public String doSomething() { + return DATA; + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClient.java new file mode 100644 index 0000000000..ed8b07202d --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/recordelresolver/ELClient.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ +package com.sun.ts.tests.el.api.jakarta_el.recordelresolver; + +import java.lang.System.Logger; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import java.util.Properties; + +import com.sun.ts.tests.common.el.api.resolver.ResolverTest; +import com.sun.ts.tests.el.common.elcontext.BareBonesELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELContext; +import jakarta.el.RecordELResolver; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + + /** + * @testName: recordELResolverTest + * + * @test_Strategy: Verify that API calls work as expected for: arrayELResolver() getValue() getType() setValue() + * isReadOnly() getCommonPropertyType() getFeatureDescriptors(). Records should behave similarly to read-only beans. + */ + public void recordELResolverTest() throws Exception { + + boolean pass; + StringBuffer buf = new StringBuffer(); + TestRecord testRecord = new TestRecord("valueA", "valueB"); + + try { + RecordELResolver recordResolver = new RecordELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + pass = ResolverTest.testELResolver(context, recordResolver, testRecord, "propertyA", "newValue", buf, true); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logTrace(buf.toString()); + } + + + public record TestRecord(String propertyA, String propertyB) { } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClient.java new file mode 100644 index 0000000000..81b2e3bf63 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/ELClient.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.resourcebundleelresolver; + +import java.io.Serializable; +import java.util.Enumeration; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.StringTokenizer; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +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; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELContext; +import jakarta.el.ResourceBundleELResolver; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + private TckResourceBundle tckrb; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + tckrb = new TckResourceBundle(); + } + + public void cleanup() throws Exception { + } + + /** + * @testName: resourceBundleELResolverTest + * + * @assertion_ids: EL:JAVADOC:103; EL:JAVADOC:104; EL:JAVADOC:105; + * EL:JAVADOC:106; EL:JAVADOC:107; EL:JAVADOC:108; + * EL:JAVADOC:109 + * + * @test_Strategy: Verify that API calls work as expected: + * ResourceBundleELResolver() setValue() getValue() getType() + * isReadOnly() getCommonPropertyType() + * getFeatureDescriptors() + */ + + public void resourceBundleELResolverTest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + try { + ResourceBundleELResolver rsbResolver = new ResourceBundleELResolver(); + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + + pass = ResolverTest.testELResolver(context, rsbResolver, tckrb, "Dinner", + "DINNER", buf, true); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: resourceBundleELResolverNPETest + * + * @assertion_ids: EL:JAVADOC:106; EL:JAVADOC:105; EL:JAVADOC:107; + * EL:JAVADOC:108; EL:JAVADOC:109; EL:JAVADOC:313; + * EL:JAVADOC:314; EL:JAVADOC:316; EL:JAVADOC:317 + * + * @test_Strategy: Verify that the following methods throw a + * NullPointerException, if context is null: + * + * getValue() getType() setValue() isReadOnly() + */ + public void resourceBundleELResolverNPETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + ResourceBundleELResolver resolver = new ResourceBundleELResolver(); + + try { + pass = ResolverTest.testELResolverNPE(resolver, tckrb, "brunch", "BRUNCH", + buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + /** + * @testName: resourceBundleELResolverPNWETest + * + * @assertion_ids: EL:JAVADOC:108; EL:JAVADOC:109; EL:JAVADOC:318 + * + * @test_Strategy: Verify that the following methods throw a + * PropertyNotWritableException, since + * ResourceBundleELResolvers are non-writable. + * + * setValue() + */ + public void resourceBundleELResolverPNWETest() throws Exception { + + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + BareBonesELContext barebonesContext = new BareBonesELContext(); + ELContext context = barebonesContext.getELContext(); + ResourceBundleELResolver rsbResolver = new ResourceBundleELResolver(); + + try { + pass = ResolverTest.testELResolverPNWE(context, rsbResolver, tckrb, + "snack", "SNACK", buf); + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + TestUtil.logTrace(buf.toString()); + } + + private static class TckResourceBundle extends ResourceBundle + implements Serializable { + + private static final String KEYS = "Breakfast Lunch Dinner"; + + public Object handleGetObject(String key) { + if ("Breakfast".equals(key)) + return "BREAKFAST"; + if ("Lunch".equals(key)) + return "LUNCH"; + if ("Dinner".equals(key)) + return "DINNER"; + + return null; + } + + public Enumeration getKeys() { + StringTokenizer keyTokenizer = new StringTokenizer(KEYS); + + return keyTokenizer; + + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/build.xml new file mode 100644 index 0000000000..d03965126d --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/resourcebundleelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClient.java new file mode 100644 index 0000000000..2ca5fb492e --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/ELClient.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2012, 2021 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.staticfieldelresolver; + +import java.util.Iterator; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.common.el.api.resolver.ResolverTest; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELClass; +import jakarta.el.ELContext; +import jakarta.el.ELManager; +import jakarta.el.PropertyNotFoundException; +import jakarta.el.PropertyNotWritableException; +import jakarta.el.StaticFieldELResolver; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + TestUtil.logTrace("Cleanup method called"); + } + + /** + * @testName: staticFieldELResolverTest + * + * @assertion_ids: EL:JAVADOC:330; EL:JAVADOC:331; EL:JAVADOC:332; + * EL:JAVADOC:335; EL:JAVADOC:338; EL:JAVADOC:341; + * EL:JAVADOC:343; EL:JAVADOC:346; EL:JAVADOC:189; + * EL:JAVADOC:204 + * + * + * @test_Strategy: Verify the following method calls work as expected: + * getValue() getType() setValue() isReadOnly() + * getCommonPropertyType() + */ + public void staticFieldELResolverTest() throws Exception { + StringBuffer buf = new StringBuffer(); + boolean pass = true; + + ELManager elm = new ELManager(); + StaticFieldELResolver resolver = new StaticFieldELResolver(); + elm.addELResolver(resolver); + ELContext context = elm.getELContext(); + + Object base = new ELClass(TCKELClass.class); + Object property = "firstName"; + Object value = "Ender"; + + // setValue() + context.setPropertyResolved(false); + try { + resolver.setValue(context, base, property, value); + buf.append(ELTestUtil.FAIL + TestUtil.NEW_LINE + + "Expected PropertyNotWritableException to be " + + "thrown when calling setValue()!" + TestUtil.NEW_LINE + + "No exception was thown!" + TestUtil.NEW_LINE); + pass = false; + + } catch (PropertyNotWritableException pnwe) { + buf.append(ELTestUtil.PASS + TestUtil.NEW_LINE + + "PropertyNotWritableException Thrown as expected for " + + "setValue()!" + TestUtil.NEW_LINE); + } catch (Exception e) { + buf.append(ELTestUtil.FAIL + TestUtil.NEW_LINE + + "Wrong Exception Thrownfor setValue()!" + TestUtil.NEW_LINE + + "Expected: PropertyNotWritableException" + TestUtil.NEW_LINE + + "Received: " + e.getClass().getSimpleName() + TestUtil.NEW_LINE); + } + + // getValue() + context.setPropertyResolved(false); + Object valueRetrieved = resolver.getValue(context, base, property); + if (!context.isPropertyResolved()) { + buf.append("getValue() did not resolve" + TestUtil.NEW_LINE); + pass = false; + } + + if (valueRetrieved != value) { + buf.append("Invalid value from getValue():" + TestUtil.NEW_LINE + + "Value expected: " + value.toString() + TestUtil.NEW_LINE + + "Value retrieved: " + valueRetrieved.toString() + + TestUtil.NEW_LINE); + pass = false; + } + + // getType() + context.setPropertyResolved(false); + Class type = resolver.getType(context, base, property); + if (!context.isPropertyResolved()) { + buf.append("getType() did not resolve" + TestUtil.NEW_LINE); + pass = false; + } else if (type != null) { + buf.append("getType() returns " + type.getName() + " rather than null" + TestUtil.NEW_LINE); + pass = false; + } else { + buf.append("getType() returns null" + TestUtil.NEW_LINE + "as expected." + TestUtil.NEW_LINE); + } + + // isReadOnly + context.setPropertyResolved(false); + boolean nonWritable = resolver.isReadOnly(context, base, property); + if (!context.isPropertyResolved()) { + buf.append("isReadOnly() did not resolve" + TestUtil.NEW_LINE); + pass = false; + + } else if (!nonWritable) { + buf.append("isReadOnly() returned unexpected value: " + TestUtil.NEW_LINE + + "Expected: false" + TestUtil.NEW_LINE + "Received: " + nonWritable + + TestUtil.NEW_LINE); + pass = false; + + } else { + buf.append("isReadOnly() returns false as expected" + TestUtil.NEW_LINE); + } + + // getCommonPropertyType() + context.setPropertyResolved(false); + Class commonPropertyType = (resolver.getCommonPropertyType(context, + base)); + buf.append("getCommonPropertyType() returns " + commonPropertyType.getName() + + TestUtil.NEW_LINE); + + // getFeatureDescriptors() commenting below as the method is deprecated in EL 6.0 + // context.setPropertyResolved(false); + // Iterator i = resolver.getFeatureDescriptors(context, base); + + // if (i == null) { + // buf.append("getFeatureDescriptors() returns null" + TestUtil.NEW_LINE); + // } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + TestUtil.NEW_LINE + buf.toString()); + } + + } // End staticFieldELResolverTest + + /** + * @testName: staticFieldResolverInvokeMNFETest + * + * @assertion_ids: EL:JAVADOC:339; EL:JAVADOC:189; EL:JAVADOC:204 + * + * @test_Strategy: Verify that the invoke() method throws + * MethodNotFoundException if no suitable method can be found. + */ + public void staticFieldResolverInvokeMNFETest() throws Exception { + StringBuffer buf = new StringBuffer(); + boolean pass = false; + + ELManager elm = new ELManager(); + StaticFieldELResolver resolver = new StaticFieldELResolver(); + elm.addELResolver(resolver); + ELContext context = elm.getELContext(); + + Class[] types = { String.class, String.class }; + String[] values = { "Doug", "Donahue" }; + + try { + pass = ResolverTest.testELResolverInvoke(context, context.getELResolver(), + new ELClass(TCKELClass.class), "bogue_method", types, values, true, + buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + TestUtil.logMsg(buf.toString()); + + }// End staticFieldResolverInvokeMNFETest + + /** + * @testName: staticFieldELResolverInvokeTest + * + * @assertion_ids: EL:JAVADOC:338; EL:JAVADOC:189; EL:JAVADOC:204 + * + * @test_Strategy: Verify that API calls work as expected for + * BeanNameELResolver.invoke(). + */ + public void staticFieldELResolverInvokeTest() throws Exception { + StringBuffer buf = new StringBuffer(); + boolean pass = false; + + ELManager elm = new ELManager(); + StaticFieldELResolver resolver = new StaticFieldELResolver(); + elm.addELResolver(resolver); + ELContext context = elm.getELContext(); + + Class[] types = { String.class }; + String[] values = { "Ender" }; + + try { + pass = ResolverTest.testELResolverInvoke(context, context.getELResolver(), + new ELClass(TCKELClass.class), "isName", types, values, false, buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + + TestUtil.logMsg(buf.toString()); + + }// End staticFieldELResolverInvokeTest + + /** + * @testName: staticFieldELResolverNPETest + * + * @assertion_ids: EL:JAVADOC:333; EL:JAVADOC:336; EL:JAVADOC:342; + * EL:JAVADOC:344; EL:JAVADOC:189 + * + * @test_Strategy: Verify that the following methods throw a + * NullPointerException, if context is null: + * + * getType() getValue() isReadOnly() setValue() + */ + public void staticFieldELResolverNPETest() throws Exception { + boolean pass = false; + StringBuffer buf = new StringBuffer(); + + ELManager elm = new ELManager(); + StaticFieldELResolver resolver = new StaticFieldELResolver(); + elm.addELResolver(resolver); + + try { + pass = ResolverTest.testELResolverNPE(resolver, + new ELClass(TCKELClass.class), "intention", "billy", buf); + + } catch (Exception ex) { + throw new Exception(ex); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + + TestUtil.logTrace(buf.toString()); + + } // End staticFieldELResolverNPETest + + /** + * @testName: staticFieldResolverInvokePNFETest + * + * @assertion_ids: EL:JAVADOC:334; EL:JAVADOC:337 + * + * @test_Strategy: Verify that the invoke() method throws + * PropertyNotFoundException the specified class does not + * exist, or if the field is not a public static filed of the + * class, or if the field is inaccessible. + */ + public void staticFieldResolverInvokePNFETest() throws Exception { + + Object base = new ELClass(TCKELClass.class); + + // Test for non static field + testForPNFE("notStatic", base); + + // Test for Private static field + testForPNFE("privStatic", base); + + // Test for non existent Class + testForPNFE("privStatic", "bogus"); + + }// End staticFieldResolverInvokePNFETest + + // ------------------------- private methods + + private void testForPNFE(String property, Object base) { + StringBuffer buf = new StringBuffer(); + + ELManager elm = new ELManager(); + StaticFieldELResolver resolver = new StaticFieldELResolver(); + elm.addELResolver(resolver); + ELContext context = elm.getELContext(); + + // getType() + try { + resolver.getType(context, base, property); + buf.append(ELTestUtil.FAIL + " getType() did not throw any exception." + + TestUtil.NEW_LINE + "Expected: PropertyNotFoundException " + + TestUtil.NEW_LINE); + + } catch (PropertyNotFoundException pnfe) { + buf.append(ELTestUtil.PASS); + + } catch (Exception e) { + buf.append(ELTestUtil.FAIL + "Wrong Exception thrown for getType()!" + + TestUtil.NEW_LINE + " Expected: PropertyNotFoundException" + + TestUtil.NEW_LINE + "Received: " + e.getClass().getSimpleName()); + } + + // getValue() + try { + resolver.getValue(context, base, property); + buf.append(ELTestUtil.FAIL + " getValue() did not throw any exception." + + TestUtil.NEW_LINE + "Expected: PropertyNotFoundException " + + TestUtil.NEW_LINE); + + } catch (PropertyNotFoundException pnfe) { + buf.append(ELTestUtil.PASS); + + } catch (Exception e) { + buf.append(ELTestUtil.FAIL + "Wrong Exception thrown getValue()!" + + TestUtil.NEW_LINE + " Expected: PropertyNotFoundException" + + TestUtil.NEW_LINE + "Received: " + e.getClass().getSimpleName()); + } + + }// End testForPNFE + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/build.xml new file mode 100644 index 0000000000..2895b98198 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/staticfieldelresolver/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClient.java new file mode 100644 index 0000000000..2e8ec7cab1 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/ELClient.java @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.el.api.jakarta_el.valueexpression; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.common.el.api.expression.ExpressionTest; +import com.sun.ts.tests.el.common.elcontext.BareBonesELContext; +import com.sun.ts.tests.el.common.elcontext.SimpleELContext; +import com.sun.ts.tests.el.common.elcontext.VRContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELContext; +import jakarta.el.ELResolver; +import jakarta.el.ExpressionFactory; +import jakarta.el.PropertyNotFoundException; +import jakarta.el.ValueExpression; +import jakarta.el.ValueReference; + +public class ELClient extends ServiceEETest { + private Hashtable, Object> testValueTable; + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + this.initializeTable(); + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: positiveValueExpressionTest + * @assertion_ids: EL:JAVADOC:110; EL:JAVADOC:111; EL:JAVADOC:112; + * EL:JAVADOC:113; EL:JAVADOC:114; EL:JAVADOC:60; + * EL:JAVADOC:58 + * @test_Strategy: Validate the behavior of ValueExpression API + * ValueExpression.getValue() ValueExpression.setValue() + * ValueExpression.getType() ValueExpression.getExpectedType() + * ValueExpression.isReadOTestUtil.NEW_LINEy() + * Expression.isLiteralText() Expression.getExpressionString() + */ + public void positiveValueExpressionTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + + boolean pass1, pass2, pass3, pass4; + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + + ELContext context = (new SimpleELContext()).getELContext(); + ELResolver resolver = context.getELResolver(); + resolver.setValue(context, null, "foo", "bar"); + + // string variable + // readOTestUtil.NEW_LINEy() and isLiteralText() expected to return false + buf.append("Testing expression 1 " + TestUtil.NEW_LINE); + String exprStr1 = "${foo}"; + ValueExpression vexp1 = expFactory.createValueExpression(context, + exprStr1, String.class); + pass1 = ExpressionTest.testValueExpression(vexp1, context, exprStr1, + String.class, "bar", false, false, buf); + + // literal expression + // readOTestUtil.NEW_LINEy() and isLiteralText() expected to return true + buf.append("Testing expression 2 " + TestUtil.NEW_LINE); + String exprStr2 = "foo"; + ValueExpression vexp2 = expFactory.createValueExpression(context, + exprStr2, String.class); + pass2 = ExpressionTest.testValueExpression(vexp2, context, exprStr2, + String.class, "foo", true, true, buf); + + // expression that is not an l-value + // readOTestUtil.NEW_LINEy() expected to return true + // isLiteralText() expected to return false + buf.append("Testing expression 3 " + TestUtil.NEW_LINE); + String exprStr3 = "#{1 + 1}"; + ValueExpression vexp3 = expFactory.createValueExpression(context, + exprStr3, Integer.class); + pass3 = ExpressionTest.testValueExpression(vexp3, context, exprStr3, + Integer.class, Integer.valueOf(2), true, false, buf); + + // Expression test for ValueReference. + buf.append("Testing expression 4 " + TestUtil.NEW_LINE); + pass4 = true; + + ELContext contextTwo = new VRContext(testProps); + String exprStr4 = "#{worker.lastName}"; + + ValueExpression vexp4 = expFactory.createValueExpression(contextTwo, + exprStr4, String.class); + + ValueReference vr = vexp4.getValueReference(contextTwo); + + if (vr == null) { + pass4 = false; + buf.append("ValueRefernce should have return a non null " + "value."); + } else { + Object base = vr.getBase(); + + if (base != null) { + String baseName = base.getClass().getSimpleName(); + if (!"Worker".equals(baseName)) { + buf.append("Unexpected Base Value!" + TestUtil.NEW_LINE + + "Expected: Worker" + TestUtil.NEW_LINE + "Received: " + + baseName); + pass4 = false; + } + } + } + + } catch (Exception ex) { + throw new Exception(ex); + } + + if ((pass1 && pass2 && pass3 && pass4)) { + TestUtil.logTrace(buf.toString()); + + } else { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + } + + /** + * @testName: negativeValueExpressionTest + * @assertion_ids: EL:JAVADOC:111; EL:JAVADOC:112; EL:JAVADOC:113; + * EL:JAVADOC:114; EL:JAVADOC:368; EL:JAVADOC:371; + * EL:JAVADOC:372; EL:JAVADOC:375; EL:JAVADOC:376; + * EL:JAVADOC:378; EL:JAVADOC:379; EL:JAVADOC:380 + * + * @test_Strategy: Validate the behavior of ValueExpression API + * ValueExpression.getValue() ValueExpression.setValue() + * ValueExpression.getType() + * ValueExpression.isReadOTestUtil.NEW_LINEy() + * + * If the ELContext parameter for these methods is null, a + * NullPointerException is thrown. If the ELContext parameter + * is not the same as the one with which the ValueExpression + * was created, a PropertyNotFoundException is thrown. + */ + public void negativeValueExpressionTest() throws Exception { + + boolean pass = true; + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext simpleContext = (new SimpleELContext()).getELContext(); + ELContext emptyContext = (new BareBonesELContext()).getELContext(); + + ELResolver resolver = simpleContext.getELResolver(); + + try { + resolver.setValue(simpleContext, null, "foo", "bar"); + } catch (Exception e) { + throw new Exception(e); + } + + String exprStr = "${foo}"; + + ValueExpression vexp = expFactory.createValueExpression(simpleContext, + exprStr, String.class); + + // NullPointerException + try { + vexp.getValue(null); + pass = false; + TestUtil.logErr("Call to getValue() with null ELContext parameter " + + "did not" + TestUtil.NEW_LINE + " cause an exception to be thrown" + + TestUtil.NEW_LINE); + + } catch (NullPointerException npe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to getValue() with null ELContext " + + "parameter caused an exception to be thrown, but it was not a" + + TestUtil.NEW_LINE + " NullPointerException: " + e.toString() + + TestUtil.NEW_LINE); + } + + try { + vexp.setValue(null, "foo"); + pass = false; + TestUtil.logErr("Call to setValue() with null ELContext parameter " + + "did not" + TestUtil.NEW_LINE + " cause an exception to be thrown" + + TestUtil.NEW_LINE); + + } catch (NullPointerException npe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to setValue() with null ELContext " + + "parameter caused" + TestUtil.NEW_LINE + + " an exception to be thrown, but it was not a" + TestUtil.NEW_LINE + + " NullPointerException: " + e.toString() + TestUtil.NEW_LINE); + } + + try { + vexp.isReadOnly(null); + pass = false; + TestUtil.logErr("Call to isReadOTestUtil.NEW_LINEy() with null ELContext " + + "parameter did not" + TestUtil.NEW_LINE + + " cause an exception to be thrown" + TestUtil.NEW_LINE); + + } catch (NullPointerException npe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to isReadOTestUtil.NEW_LINEy() with null ELContext " + + "parameter caused" + TestUtil.NEW_LINE + + "an exception to be thrown, but it was not a" + TestUtil.NEW_LINE + + "NullPointerException: " + e.toString() + TestUtil.NEW_LINE); + } + + try { + vexp.getType(null); + pass = false; + TestUtil.logErr("Call to getType() with null ELContext parameter " + + "did not" + TestUtil.NEW_LINE + "cause an exception to be thrown" + + TestUtil.NEW_LINE); + + } catch (NullPointerException npe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to getType() with null ELContext parameter " + + "caused" + TestUtil.NEW_LINE + + "an exception to be thrown, but it was not a" + TestUtil.NEW_LINE + + "NullPointerException: " + e.toString() + TestUtil.NEW_LINE); + } + + // PropertyNotFoundException + try { + vexp.setValue(emptyContext, "foo"); + pass = false; + TestUtil.logErr("Call to setValue() for non-existent property did " + + "not cause" + TestUtil.NEW_LINE + "an exception to be thrown" + + TestUtil.NEW_LINE); + + } catch (PropertyNotFoundException pnfe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to setValue() for non-existent property " + + "caused an exception to be thrown, but it was not a" + + TestUtil.NEW_LINE + "PropertyNotFoundException: " + e.toString() + + TestUtil.NEW_LINE); + } + + try { + vexp.getValue(emptyContext); + pass = false; + TestUtil.logErr("Call to getValue() for non-existent property did " + + "not cause an exception to be thrown" + TestUtil.NEW_LINE); + + } catch (PropertyNotFoundException pnfe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to getValue() for non-existent property " + + "caused an exception to be thrown, but it was not a PropertyNotFoundException: " + + TestUtil.NEW_LINE + e.toString() + TestUtil.NEW_LINE); + } + + try { + vexp.isReadOnly(emptyContext); + pass = false; + TestUtil.logErr( + "Call to isReadOTestUtil.NEW_LINEy() for non-existent property did " + + "not cause an exception to be thrown" + TestUtil.NEW_LINE); + + } catch (PropertyNotFoundException pnfe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr( + "Call to isReadOTestUtil.NEW_LINEy() for non-existent property " + + "caused an exception to be thrown, but it was not a" + + " PropertyNotFoundException: " + TestUtil.NEW_LINE + + e.toString() + TestUtil.NEW_LINE); + } + + try { + vexp.getType(emptyContext); + pass = false; + TestUtil.logErr("Call to getType() for non-existent property did not " + + "cause an exception to be thrown" + TestUtil.NEW_LINE); + + } catch (PropertyNotFoundException pnfe) { + pass = true; + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Call to getType() for non-existent property " + + "caused an exception to be thrown, but it was not a" + + TestUtil.NEW_LINE + " PropertyNotFoundException: " + e.toString() + + TestUtil.NEW_LINE); + } + + if (!pass) { + throw new Exception(ELTestUtil.FAIL); + } + } + + /** + * @testName: valueExpressionSerializableTest + * + * @assertion_ids: EL:SPEC:44 + * + * @test_Strategy: Validate that ValueExpression implements Serializable and + * that a ValueExpression can be manually serialized and + * deserialized. + */ + public void valueExpressionSerializableTest() throws Exception { + + boolean pass; + + StringBuffer buf = new StringBuffer(); + Enumeration keys = testValueTable.keys(); + Class testClass; + Object testValue; + + while (keys.hasMoreElements()) { + pass = true; + testClass = (Class) keys.nextElement(); + testValue = testValueTable.get(testClass); + + try { + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + ELContext context = (new SimpleELContext()).getELContext(); + + // Set eval-expression. + ValueExpression evalvexp = expFactory.createValueExpression(context, + "${" + testValue + "}", testClass); + TestUtil.logTrace("Eval Value Expression For Testing: " + + evalvexp.toString() + TestUtil.NEW_LINE); + + // Set literal-expression + ValueExpression literalvexp = expFactory.createValueExpression(context, + "\"" + testValue + "\"", testClass); + TestUtil.logTrace("Literal Value Expression For Testing: " + + literalvexp.toString() + TestUtil.NEW_LINE); + + // Set Composite Expression + ValueExpression compositevexp = expFactory.createValueExpression( + context, "#{" + testValue + "}" + " " + testValue, testClass); + TestUtil.logTrace("Composite Value Expression For Testing: " + + compositevexp.toString() + TestUtil.NEW_LINE); + + // Test eval, literal, & composite expressions. + if (!(ExpressionTest.expressionSerializableTest(evalvexp, buf) + && ExpressionTest.expressionSerializableTest(literalvexp, buf) + && ExpressionTest.expressionSerializableTest(compositevexp, buf))) { + pass = false; + break; + } + + } catch (Exception ex) { + throw new Exception(ex); + + } + + if (pass) { + TestUtil.logTrace(buf.toString()); + } else { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + } + } + + /* + * The HashTable is of this format. + * + * Key = Test Class Value = Test Value + */ + private void initializeTable() { + testValueTable = new Hashtable, Object>(); + + testValueTable.put(String.class, "SERIAL"); + testValueTable.put(Integer.class, Integer.valueOf("123")); + testValueTable.put(Boolean.class, Boolean.TRUE); + } + + /** + * @testName: valueExpressionEqualsTest + * + * @assertion_ids: EL:JAVADOC:56 + * + * @test_Strategy: Validate that ValueExpression implements equals() and that + * the behavior is as expected + */ + public void valueExpressionEqualsTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + + boolean pass = true; + + try { + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + SimpleELContext context = new SimpleELContext(); + ELResolver resolver = context.getELResolver(); + + // case 1: Expressions of the same type and equal value, but + // different parsed representations are NOT equal. + String exprStr1 = "${foo}"; + String exprStr2 = "${bar}"; + resolver.setValue(context, null, "foo", "SOME VALUE"); + resolver.setValue(context, null, "bar", "SOME VALUE"); + + ValueExpression vexp1 = expFactory.createValueExpression(context, + exprStr1, String.class); + ValueExpression vexp2 = expFactory.createValueExpression(context, + exprStr2, String.class); + + buf.append("vexp1 has value " + (String) vexp1.getValue(context) + + TestUtil.NEW_LINE); + buf.append("vexp2 has value " + (String) vexp2.getValue(context) + + TestUtil.NEW_LINE); + + if (ExpressionTest.equalsTest(vexp1, vexp2, buf)) { + pass = false; + buf.append( + "Failed: case 1: same type and equal value" + TestUtil.NEW_LINE); + } + + // case 2: White space is ignored + String exprStr3 = "${A+B+C}"; + String exprStr4 = "${ A + B + C }"; + + ValueExpression vexp3 = expFactory.createValueExpression(context, + exprStr3, Object.class); + ValueExpression vexp4 = expFactory.createValueExpression(context, + exprStr4, Object.class); + + if (!ExpressionTest.equalsTest(vexp3, vexp4, buf)) { + buf.append("Failed: case 2: white space" + TestUtil.NEW_LINE); + pass = false; + } + + // case 3: Equivalent Operators + String exprStr5 = "${A < B}"; + String exprStr6 = "${A lt B}"; + + ValueExpression vexp5 = expFactory.createValueExpression(context, + exprStr5, Object.class); + ValueExpression vexp6 = expFactory.createValueExpression(context, + exprStr6, Object.class); + + if (!ExpressionTest.equalsTest(vexp5, vexp6, buf)) { + buf.append("Failed: case 3: equivalent operators" + TestUtil.NEW_LINE); + pass = false; + } + + // case 4: Reversed operands + String exprStr7 = "${A + B}"; + String exprStr8 = "${B + A}"; + + ValueExpression vexp7 = expFactory.createValueExpression(context, + exprStr7, Object.class); + ValueExpression vexp8 = expFactory.createValueExpression(context, + exprStr8, Object.class); + + if (ExpressionTest.equalsTest(vexp7, vexp8, buf)) { + buf.append("Failed: case 4: reversed operands" + TestUtil.NEW_LINE); + pass = false; + } + + // case 5: '$' and '#' delimiters are parsed the same + String exprStr9 = "${A}"; + String exprStr10 = "#{A}"; + + ValueExpression vexp9 = expFactory.createValueExpression(context, + exprStr9, Object.class); + ValueExpression vexp10 = expFactory.createValueExpression(context, + exprStr10, Object.class); + + if (!ExpressionTest.equalsTest(vexp9, vexp10, buf)) { + buf.append("Failed: case 5: delimiters" + TestUtil.NEW_LINE); + pass = false; + } + + } catch (Exception ex) { + throw new Exception(ex); + + } + + if (pass) { + TestUtil.logTrace(buf.toString()); + } else { + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } + + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/build.xml new file mode 100644 index 0000000000..5ff0b73d7a --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/valueexpression/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClient.java new file mode 100644 index 0000000000..98b141c6d1 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/ELClient.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * 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.variablemapper; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.elcontext.VarMapperELContext; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ExpressionFactory; +import jakarta.el.ValueExpression; +import jakarta.el.VariableMapper; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + /** + * @testName: variableMapperTest + * + * @assertion_ids: EL:JAVADOC:37; EL:JAVADOC:116; EL:JAVADOC:117 + * @test_Strategy: Validate the behavior of ELContext.getVariableMapper() + * VariableMapper.resolveVariable() + * VariableMapper.setVariable() + */ + + public void variableMapperTest() throws Exception { + + StringBuffer buf = new StringBuffer(); + + boolean pass = true; + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + VarMapperELContext context = new VarMapperELContext(testProps); + VariableMapper varMapper = context.getVariableMapper(); + TestUtil.logTrace("VariableMapper is " + varMapper.toString()); + + if (varMapper.resolveVariable("foo") != null) { + pass = false; + buf.append("Expected call to resolveVariable() to unassigned " + + "variable to return null" + TestUtil.NEW_LINE + + "Instead call returned " + varMapper.resolveVariable("foo") + + TestUtil.NEW_LINE); + } + + ValueExpression vexp1 = expFactory.createValueExpression(context, "${bar}", + String.class); + ValueExpression vexp2 = varMapper.setVariable("foo", vexp1); + + if (vexp2 != null) { + pass = false; + buf.append("Expected call to setVariable() to return null " + + "for previously unassigned variable" + TestUtil.NEW_LINE + + "Instead return value was " + vexp2 + TestUtil.NEW_LINE); + } + + ValueExpression vexp3 = varMapper.resolveVariable("foo"); + + if (!vexp3.equals(vexp1)) { + pass = false; + buf.append("Expected call to resolveVariable() to assigned " + + "variable to return " + vexp1.toString() + TestUtil.NEW_LINE + + "Instead call returned " + vexp3.toString() + TestUtil.NEW_LINE); + } + + ValueExpression vexp4 = varMapper.setVariable("foo", null); + + if (!vexp4.equals(vexp1)) { + pass = false; + buf.append("Expected call to resolveVariable() to assigned " + + "variable to return " + vexp1.toString() + TestUtil.NEW_LINE + + "Instead call returned " + vexp4.toString() + TestUtil.NEW_LINE); + } + + ValueExpression vexp5 = varMapper.resolveVariable("foo"); + + if (vexp5 != null) { + pass = false; + buf.append("Expected call to resolveVariable() to return null" + + " after unassignment" + TestUtil.NEW_LINE + + "Instead return value was " + vexp5 + TestUtil.NEW_LINE); + } + + if (!pass) + throw new Exception(ELTestUtil.FAIL + buf.toString()); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/build.xml b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/build.xml new file mode 100644 index 0000000000..0b4f2a2340 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/api/jakarta_el/variablemapper/build.xml @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/build.xml b/el/src/main/java/com/sun/ts/tests/el/build.xml new file mode 100644 index 0000000000..1972a0f084 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/common/build.xml b/el/src/main/java/com/sun/ts/tests/el/common/build.xml new file mode 100644 index 0000000000..0edb95ad02 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/common/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java index 07a6de777e..1e285f4325 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/BarELContext.java @@ -21,7 +21,7 @@ package com.sun.ts.tests.el.common.elcontext; -import com.sun.ts.tests.el.common.api.resolver.BarELResolver; +import com.sun.ts.tests.common.el.api.resolver.BarELResolver; import jakarta.el.ELContext; import jakarta.el.ELResolver; diff --git a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java index 148fa5d9c5..7ca0c505f9 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/SimpleELContext.java @@ -20,7 +20,7 @@ */ package com.sun.ts.tests.el.common.elcontext; - +import com.sun.ts.lib.util.TestUtil; import com.sun.ts.tests.el.common.elresolver.EmployeeELResolver; import com.sun.ts.tests.el.common.elresolver.VariableELResolver; import com.sun.ts.tests.el.common.elresolver.VectELResolver; @@ -32,8 +32,6 @@ import jakarta.el.FunctionMapper; import jakarta.el.VariableMapper; -import java.lang.System.Logger; - /** * A basic ELContext that meets the needs of most EL tests. The no-args * constructor builds the ELContext from a VariableELResolver that enables the @@ -43,8 +41,6 @@ */ public class SimpleELContext extends ELContext { - private static final Logger logger = System.getLogger(SimpleELContext.class.getName()); - private static final String NLINE = System.getProperty("line.separator"); private final CompositeELResolver compResolver; @@ -122,21 +118,21 @@ private ELResolver getMyResolver(ResolverType enumResolver) { switch (enumResolver) { case EMPLOYEE_ELRESOLVER: myResolver = new EmployeeELResolver(); - logger.log(Logger.Level.TRACE, "Setting ELResolver == EmployeeELResolver"); + TestUtil.logTrace("Setting ELResolver == EmployeeELResolver"); break; case VARIABLE_ELRESOLVER: myResolver = new VariableELResolver(); - logger.log(Logger.Level.TRACE, "Setting ELResolver == VariableELResolver"); + TestUtil.logTrace("Setting ELResolver == VariableELResolver"); break; case VECT_ELRESOLVER: myResolver = new VectELResolver(); - logger.log(Logger.Level.TRACE, "Setting ELResolver == VectELResolver"); + TestUtil.logTrace("Setting ELResolver == VectELResolver"); break; default: - logger.log(Logger.Level.TRACE, + TestUtil.logTrace( "Unknown ELResolver! " + enumResolver + " trying to use default" + NLINE + "Setting" + " ELResolver == VariableELResolver"); break; diff --git a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java index b8666a39af..00b75a0131 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VRContext.java @@ -22,7 +22,7 @@ import java.util.Properties; - +import com.sun.ts.lib.util.TestUtil; import com.sun.ts.tests.el.api.jakarta_el.valueexpression.Worker; import com.sun.ts.tests.el.common.elresolver.VariableELResolver; import com.sun.ts.tests.el.common.functionmapper.TCKFunctionMapper; @@ -34,12 +34,8 @@ import jakarta.el.FunctionMapper; import jakarta.el.VariableMapper; -import java.lang.System.Logger; - public class VRContext extends ELContext { - private static final Logger logger = System.getLogger(VRContext.class.getName()); - private final VariableMapper varMapper; private final CompositeELResolver compResolver; @@ -83,11 +79,11 @@ private Object getImplSpecificInstance(String classname) { clazz = Class.forName(classname); instance = clazz.newInstance(); } catch (ClassNotFoundException cnfe) { - logger.log(Logger.Level.ERROR, "ClassNotFoundException: " + cnfe.getMessage()); + TestUtil.logErr("ClassNotFoundException: " + cnfe.getMessage()); } catch (InstantiationException ie) { - logger.log(Logger.Level.ERROR, "InstantiationException: " + ie.getMessage()); + TestUtil.logErr("InstantiationException: " + ie.getMessage()); } catch (IllegalAccessException iae) { - logger.log(Logger.Level.ERROR, "IllegalAccessException: " + iae.getMessage()); + TestUtil.logErr("IllegalAccessException: " + iae.getMessage()); } return instance; } diff --git a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java index ea9e35b370..24ae529d6e 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/elcontext/VarMapperELContext.java @@ -22,7 +22,7 @@ import java.util.Properties; - +import com.sun.ts.lib.util.TestUtil; import com.sun.ts.tests.el.common.elresolver.VariableELResolver; import jakarta.el.CompositeELResolver; @@ -31,7 +31,6 @@ import jakarta.el.FunctionMapper; import jakarta.el.VariableMapper; -import java.lang.System.Logger; /** * This ELContext provides a VariableELResolver to enable the setting and * resolution of variables as well as a VariableMapper implementation. The path @@ -40,8 +39,6 @@ */ public class VarMapperELContext extends ELContext { - private static final Logger logger = System.getLogger(VarMapperELContext.class.getName()); - private final VariableMapper varMapper; private final CompositeELResolver compResolver; @@ -84,11 +81,11 @@ private Object getImplSpecificInstance(String classname) { clazz = Class.forName(classname); instance = clazz.newInstance(); } catch (ClassNotFoundException cnfe) { - logger.log(Logger.Level.ERROR, "ClassNotFoundException: " + cnfe.getMessage()); + TestUtil.logErr("ClassNotFoundException: " + cnfe.getMessage()); } catch (InstantiationException ie) { - logger.log(Logger.Level.ERROR, "InstantiationException: " + ie.getMessage()); + TestUtil.logErr("InstantiationException: " + ie.getMessage()); } catch (IllegalAccessException iae) { - logger.log(Logger.Level.ERROR, "IllegalAccessException: " + iae.getMessage()); + TestUtil.logErr("IllegalAccessException: " + iae.getMessage()); } return instance; } diff --git a/el/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java b/el/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java index cfb9efabac..10bc40a399 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/functionmapper/TCKFunctionMapper.java @@ -24,20 +24,16 @@ import java.lang.reflect.Method; import java.util.HashMap; -import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.lib.util.TestUtil; import jakarta.el.FunctionMapper; -import java.lang.System.Logger; - /* A simple implementation of FunctionMapper that maps only a single function to Integer.valueOf(String). */ public class TCKFunctionMapper extends FunctionMapper { - private static final Logger logger = System.getLogger(TCKFunctionMapper.class.getName()); - private static final String KEY = "Int:val"; private final Class clazz = Integer.class; @@ -50,8 +46,8 @@ public TCKFunctionMapper() { try { fMap.put(KEY, clazz.getMethod("valueOf", String.class)); } catch (NoSuchMethodException nsme) { - logger.log(Logger.Level.ERROR, "CONSTRUCTOR: Can't find method!"); - ELTestUtil.printStackTrace(nsme); + TestUtil.logErr("CONSTRUCTOR: Can't find method!"); + TestUtil.printStackTrace(nsme); } } @@ -67,8 +63,8 @@ public void update() { try { fMap.put(KEY, clazz.getMethod("toString", int.class)); } catch (NoSuchMethodException nsme) { - logger.log(Logger.Level.ERROR, "UPDATE: Can't find method!"); - ELTestUtil.printStackTrace(nsme); + TestUtil.logErr("UPDATE: Can't find method!"); + TestUtil.printStackTrace(nsme); } } } diff --git a/el/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java b/el/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java index a5ef1306e6..fa1f53946a 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/util/ELTestUtil.java @@ -22,15 +22,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.System.Logger; +import com.sun.ts.lib.harness.EETest.Fault; +import com.sun.ts.lib.util.TestUtil; public final class ELTestUtil { - private static final Logger logger = System.getLogger(ELTestUtil.class.getName()); - public static final String NL = System.getProperty("line.separator", "\n"); public static final String PASS = "Test PASSED"; @@ -200,7 +197,7 @@ private static void checkForException(Object object, String methName, } catch (InvocationTargetException ite) { if (exceptionType.getClass().isInstance(ite.getCause())) { - logger.log(Logger.Level.INFO, PASS); + TestUtil.logMsg(PASS); return; } else { @@ -222,18 +219,4 @@ private static String buildMess(String exceptionName) { return FAIL + " Unexpected Exception Thrown!" + NL + "Expected: " + exceptionName + NL + "Received: "; } - - public static void printStackTrace(Throwable e) { - if (e == null) { - return; - } - try { - StringWriter sw = new StringWriter(); - PrintWriter writer = new PrintWriter(sw); - e.printStackTrace(writer); - writer.close(); - } catch (Exception E) { - } - } - } diff --git a/el/src/main/java/com/sun/ts/tests/el/common/util/EnumELResolver.java b/el/src/main/java/com/sun/ts/tests/el/common/util/EnumELResolver.java new file mode 100644 index 0000000000..52b194fd55 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/common/util/EnumELResolver.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.common.elresolver; + +public enum EnumELResolver { + EMPLOYEE_ELRESOLVER, VARIABLE_ELRESOLVER, VECT_ELRESOLVER; +} diff --git a/el/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java b/el/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java index f6a917b597..a6ba39face 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/util/ExprEval.java @@ -28,7 +28,7 @@ import java.util.Enumeration; import java.util.Hashtable; - +import com.sun.ts.lib.util.TestUtil; import com.sun.ts.tests.el.common.elcontext.SimpleELContext; import jakarta.el.ELContext; @@ -40,12 +40,8 @@ import jakarta.el.PropertyNotWritableException; import jakarta.el.ValueExpression; -import java.lang.System.Logger; - public final class ExprEval { - private static final Logger logger = System.getLogger(ExprEval.class.getName()); - // Suppress default constructor for non-instantiability private ExprEval() { } @@ -105,25 +101,25 @@ public static Object evaluateValueExpression(String exprStr, // set the values of variables to be used in the expression if (nameVals == null) { resolver.setValue(context, null, "A", null); - logger.log(Logger.Level.TRACE, "setting var 'A' to value null"); + TestUtil.logTrace("setting var 'A' to value null"); resolver.setValue(context, null, "B", null); - logger.log(Logger.Level.TRACE, "setting var 'B' to value null"); + TestUtil.logTrace("setting var 'B' to value null"); } else { for (int i = 0; i < nameVals.length; ++i) { String name = nameVals[i].getName(); Object val = nameVals[i].getValue(); - logger.log(Logger.Level.TRACE, "setting var " + name + " to value " + val); + TestUtil.logTrace("setting var " + name + " to value " + val); resolver.setValue(context, null, name, val); } } // create the expression - logger.log(Logger.Level.TRACE, "Creating ValueExpression"); - logger.log(Logger.Level.TRACE, "context is " + context.getClass().toString()); - logger.log(Logger.Level.TRACE, "exprStr is " + exprStr); - logger.log(Logger.Level.TRACE, "expectedClass is " + expectedClass.toString()); - logger.log(Logger.Level.TRACE, + TestUtil.logTrace("Creating ValueExpression"); + TestUtil.logTrace("context is " + context.getClass().toString()); + TestUtil.logTrace("exprStr is " + exprStr); + TestUtil.logTrace("expectedClass is " + expectedClass.toString()); + TestUtil.logTrace( "resolver is " + context.getELResolver().getClass().toString()); ValueExpression vexp = expFactory.createValueExpression(context, exprStr, expectedClass); @@ -275,11 +271,12 @@ public static boolean evaluateManyValueExpression(String exprStr, // add the object context.putContext(cl, value); - logger.log(Logger.Level.TRACE, "Adding value: " + "\"" + value + "\"" + " To Context!"); + TestUtil + .logTrace("Adding value: " + "\"" + value + "\"" + " To Context!"); // test the expression if (!(ExprEval.compareValue(exprVal, vexp.getValue(context)))) { - logger.log(Logger.Level.ERROR, "Expression Failed! After Adding: " + "\"" + value + TestUtil.logErr("Expression Failed! After Adding: " + "\"" + value + "\"" + " To Context"); result = false; } @@ -294,9 +291,9 @@ public static boolean compareClass(Object obj, Class expectedClass) { boolean isInstance = expectedClass.isInstance(obj); if (!isInstance) { - logger.log(Logger.Level.ERROR, "Unexpected type for expression evaluation"); - logger.log(Logger.Level.ERROR, "Expected type: " + expectedClass.toString()); - logger.log(Logger.Level.ERROR, "Computed type: " + obj.getClass().toString()); + TestUtil.logErr("Unexpected type for expression evaluation"); + TestUtil.logErr("Expected type: " + expectedClass.toString()); + TestUtil.logErr("Computed type: " + obj.getClass().toString()); } return isInstance; } @@ -304,9 +301,9 @@ public static boolean compareClass(Object obj, Class expectedClass) { public static boolean compareValue(Object val, Object expectedVal) { if (!val.equals(expectedVal)) { - logger.log(Logger.Level.ERROR, "Unexpected value for expression evaluation"); - logger.log(Logger.Level.ERROR, "Expected value: " + expectedVal.toString()); - logger.log(Logger.Level.ERROR, "Computed value: " + val.toString()); + TestUtil.logErr("Unexpected value for expression evaluation"); + TestUtil.logErr("Expected value: " + expectedVal.toString()); + TestUtil.logErr("Computed value: " + val.toString()); return false; } @@ -316,9 +313,9 @@ public static boolean compareValue(Object val, Object expectedVal) { public static boolean compareValue(Boolean val, Boolean expectedVal) { if (!val.equals(expectedVal)) { - logger.log(Logger.Level.ERROR, "Unexpected value for expression evaluation"); - logger.log(Logger.Level.ERROR, "Expected value: " + expectedVal.toString()); - logger.log(Logger.Level.ERROR, "Computed value: " + val.toString()); + TestUtil.logErr("Unexpected value for expression evaluation"); + TestUtil.logErr("Expected value: " + expectedVal.toString()); + TestUtil.logErr("Computed value: " + val.toString()); return false; } @@ -366,9 +363,9 @@ public static boolean compareValue(BigDecimal val, BigDecimal expectedVal, BigDecimal b = expectedVal.abs(mc); if (!(0 == a.compareTo(b))) { - logger.log(Logger.Level.ERROR, "Unexpected value for expression evaluation"); - logger.log(Logger.Level.ERROR, "Expected value: " + expectedVal); - logger.log(Logger.Level.ERROR, "Computed value: " + val); + TestUtil.logErr("Unexpected value for expression evaluation"); + TestUtil.logErr("Expected value: " + expectedVal); + TestUtil.logErr("Computed value: " + val); return false; } diff --git a/el/src/main/java/com/sun/ts/tests/el/common/util/Validator.java b/el/src/main/java/com/sun/ts/tests/el/common/util/Validator.java index 3c74a2926b..836926a2ea 100644 --- a/el/src/main/java/com/sun/ts/tests/el/common/util/Validator.java +++ b/el/src/main/java/com/sun/ts/tests/el/common/util/Validator.java @@ -24,15 +24,12 @@ import java.math.BigDecimal; import java.math.BigInteger; +import com.sun.ts.lib.harness.EETest.Fault; +import com.sun.ts.lib.util.TestUtil; import jakarta.el.ELProcessor; -import java.lang.System.Logger; - public class Validator { - - private static final Logger logger = System.getLogger(Validator.class.getName()); - private static Validator instance = null; protected Validator() { @@ -58,6 +55,7 @@ private Validator getInstance() { * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testBigDecimal(BigDecimal testVal, Object expectedVal, String operator) throws Exception { @@ -65,7 +63,7 @@ public static void testBigDecimal(BigDecimal testVal, Object expectedVal, Class returnType; for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** Start " + "\"" + "BigDecimal" + "\"" + " Test Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -75,13 +73,14 @@ public static void testBigDecimal(BigDecimal testVal, Object expectedVal, try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are BigDecimal and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil + .logMsg("types are BigDecimal and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+=" (concatenation) then coerce both operands to @@ -95,30 +94,30 @@ public static void testBigDecimal(BigDecimal testVal, Object expectedVal, } else if ("%".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, "Setting Expected Type: " + returnType.getName()); + TestUtil.logMsg("Setting Expected Type: " + returnType.getName()); pass = (ExprEval.compareClass(result, returnType) && ExprEval.compareValue((Double) result, Double.valueOf(((BigDecimal) expectedVal).doubleValue()))); } else { returnType = BigDecimal.class; - logger.log(Logger.Level.INFO, "Setting Expected Type: " + returnType.getName()); + TestUtil.logMsg("Setting Expected Type: " + returnType.getName()); pass = (ExprEval.compareClass(result, returnType) && ExprEval .compareValue((BigDecimal) result, (BigDecimal) expectedVal, 5)); } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** End " + "\"" + "BigDecimal" + "\"" + " Test Sequence ***"); } @@ -140,6 +139,7 @@ public static void testBigDecimal(BigDecimal testVal, Object expectedVal, * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testFloat(Float testVal, Object expectedVal, String operator) throws Exception { @@ -149,7 +149,8 @@ public static void testFloat(Float testVal, Object expectedVal, // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, "*** Start " + "\"" + "Float" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** Start " + "\"" + "Float" + "\"" + " Test Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -158,7 +159,7 @@ public static void testFloat(Float testVal, Object expectedVal, // If Test value from numberList is BigDecimal skip it. if (testNum instanceof BigDecimal) { - logger.log(Logger.Level.INFO, "Skip " + testNum.getClass().getSimpleName() + TestUtil.logMsg("Skip " + testNum.getClass().getSimpleName() + " for Float tests we already tested for this in the" + " BigDecimal tests."); continue; @@ -166,13 +167,13 @@ public static void testFloat(Float testVal, Object expectedVal, try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are Float and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil.logMsg("types are Float and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+="concatenation then coerce both operands to String @@ -184,7 +185,7 @@ public static void testFloat(Float testVal, Object expectedVal, // If the Operator is "%" then the return type is Double. } else if ("%".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -193,7 +194,7 @@ public static void testFloat(Float testVal, Object expectedVal, } else { if (testNum instanceof BigInteger) { returnType = BigDecimal.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -201,7 +202,7 @@ public static void testFloat(Float testVal, Object expectedVal, (Float) expectedVal, 3)); } else { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) && ExprEval @@ -210,15 +211,16 @@ public static void testFloat(Float testVal, Object expectedVal, } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, "*** End " + "\"" + "Float" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** End " + "\"" + "Float" + "\"" + " Test Sequence ***"); } if (!pass) @@ -239,6 +241,7 @@ public static void testFloat(Float testVal, Object expectedVal, * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testDouble(Double testVal, Object expectedVal, String operator) throws Exception { @@ -248,7 +251,7 @@ public static void testDouble(Double testVal, Object expectedVal, // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** Start " + "\"" + "Double" + "\"" + "Test " + "Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -259,20 +262,20 @@ public static void testDouble(Double testVal, Object expectedVal, // If Test value from numberList is BigDecimal, Float skip it. if ((testNum instanceof BigDecimal) || (testNum instanceof Float)) { String skipType = testNum.getClass().getSimpleName(); - logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + TestUtil.logMsg("Skip " + skipType + " Data type already " + "tested for this in the " + skipType + " tests."); continue; } try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are Double and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil.logMsg("types are Double and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+=" (concatenation) then coerce both operands to @@ -284,7 +287,7 @@ public static void testDouble(Double testVal, Object expectedVal, // If the Operator is "%" then the return type is Double. } else if ("%".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -292,7 +295,7 @@ public static void testDouble(Double testVal, Object expectedVal, } else { if (testNum instanceof BigInteger) { returnType = BigDecimal.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -300,7 +303,7 @@ public static void testDouble(Double testVal, Object expectedVal, expectedVal)); } else { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -309,16 +312,17 @@ public static void testDouble(Double testVal, Object expectedVal, } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, "*** End " + "\"" + "Double" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** End " + "\"" + "Double" + "\"" + " Test Sequence ***"); } if (!pass) @@ -340,6 +344,7 @@ public static void testDouble(Double testVal, Object expectedVal, * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testNumericString(String testVal, Double expectedVal, String operator) throws Exception { @@ -349,7 +354,7 @@ public static void testNumericString(String testVal, Double expectedVal, // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, "*** Start " + "\"" + "NumericString" + "\"" + "Test " + TestUtil.logMsg("*** Start " + "\"" + "NumericString" + "\"" + "Test " + "Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -362,24 +367,24 @@ public static void testNumericString(String testVal, Double expectedVal, if ((testNum instanceof BigDecimal) || (testNum instanceof Float) || (testNum instanceof Double)) { String skipType = testNum.getClass().getSimpleName(); - logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + TestUtil.logMsg("Skip " + skipType + " Data type already " + "tested for this in the " + skipType + " tests."); continue; } try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are String and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil.logMsg("types are String and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); if ("%".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -387,7 +392,7 @@ public static void testNumericString(String testVal, Double expectedVal, } else { if (testNum instanceof BigInteger) { returnType = BigDecimal.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -395,7 +400,7 @@ public static void testNumericString(String testVal, Double expectedVal, expectedVal)); } else { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -404,16 +409,16 @@ public static void testNumericString(String testVal, Double expectedVal, } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** End " + "\"" + "NumericString" + "\"" + " Test Sequence ***"); } @@ -435,6 +440,7 @@ public static void testNumericString(String testVal, Double expectedVal, * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testBigInteger(BigInteger testVal, Object expectedVal, String operator) throws Exception { @@ -444,7 +450,7 @@ public static void testBigInteger(BigInteger testVal, Object expectedVal, // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** Start " + "\"" + "BigInteger" + "\"" + " Test Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -457,20 +463,21 @@ public static void testBigInteger(BigInteger testVal, Object expectedVal, if ((testNum instanceof BigDecimal) || (testNum instanceof Float) || (testNum instanceof Double) || (testNum instanceof String)) { String skipType = testNum.getClass().getSimpleName(); - logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + TestUtil.logMsg("Skip " + skipType + " Data type already " + "tested for this in the " + skipType + " tests."); continue; } try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are BigInteger and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil + .logMsg("types are BigInteger and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+=" then coerce both operands to String and @@ -483,7 +490,7 @@ public static void testBigInteger(BigInteger testVal, Object expectedVal, // BigDecimal. } else if ("/".equals(operator)) { returnType = BigDecimal.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -492,7 +499,7 @@ public static void testBigInteger(BigInteger testVal, Object expectedVal, 0)); } else { returnType = BigInteger.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) && ExprEval @@ -500,16 +507,16 @@ public static void testBigInteger(BigInteger testVal, Object expectedVal, } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** End " + "\"" + "BigInteger" + "\"" + " Test Sequence ***"); } @@ -531,6 +538,7 @@ public static void testBigInteger(BigInteger testVal, Object expectedVal, * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testLong(Long testVal, Object expectedVal, String operator) throws Exception { @@ -540,7 +548,8 @@ public static void testLong(Long testVal, Object expectedVal, String operator) // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, "*** Start " + "\"" + "Long" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** Start " + "\"" + "Long" + "\"" + " Test Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -553,20 +562,20 @@ public static void testLong(Long testVal, Object expectedVal, String operator) || (testNum instanceof Double) || (testNum instanceof String) || (testNum instanceof BigInteger)) { String skipType = testNum.getClass().getSimpleName(); - logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + TestUtil.logMsg("Skip " + skipType + " Data type already " + "tested for this in the " + skipType + " tests."); continue; } try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are Long and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil.logMsg("types are Long and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+=" then coerce both operands to String and @@ -578,7 +587,7 @@ public static void testLong(Long testVal, Object expectedVal, String operator) // If the Operator is "/" then the return type is Double. } else if ("/".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -586,7 +595,7 @@ public static void testLong(Long testVal, Object expectedVal, String operator) ((Long) expectedVal).doubleValue())); } else { returnType = Long.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -594,16 +603,17 @@ public static void testLong(Long testVal, Object expectedVal, String operator) } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, "*** End " + "\"" + "Long" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** End " + "\"" + "Long" + "\"" + " Test Sequence ***"); } if (!pass) @@ -624,6 +634,7 @@ public static void testLong(Long testVal, Object expectedVal, String operator) * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testInteger(Integer testVal, Object expectedVal, String operator) throws Exception { @@ -633,7 +644,7 @@ public static void testInteger(Integer testVal, Object expectedVal, // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** Start " + "\"" + "Integer" + "\"" + " Test Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -647,20 +658,21 @@ public static void testInteger(Integer testVal, Object expectedVal, || (testNum instanceof Double) || (testNum instanceof String) || (testNum instanceof Long) || (testNum instanceof BigInteger)) { String skipType = testNum.getClass().getSimpleName(); - logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + TestUtil.logMsg("Skip " + skipType + " Data type already " + "tested for this in the " + skipType + " tests."); continue; } try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are Integer and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil + .logMsg("types are Integer and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+=" then coerce both operands to String and @@ -672,7 +684,7 @@ public static void testInteger(Integer testVal, Object expectedVal, // If the Operator is "/" then the return type is Double. } else if ("/".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -680,7 +692,7 @@ public static void testInteger(Integer testVal, Object expectedVal, ((Integer) expectedVal).doubleValue())); } else { returnType = Long.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -689,16 +701,16 @@ public static void testInteger(Integer testVal, Object expectedVal, } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** End " + "\"" + "Integer" + "\"" + " Test Sequence ***"); } @@ -720,6 +732,7 @@ public static void testInteger(Integer testVal, Object expectedVal, * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testShort(Short testVal, Object expectedVal, String operator) throws Exception { @@ -729,7 +742,8 @@ public static void testShort(Short testVal, Object expectedVal, // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO,"*** Start " + "\"" + "Short" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** Start " + "\"" + "Short" + "\"" + " Test Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -740,20 +754,20 @@ public static void testShort(Short testVal, Object expectedVal, // Long, BigInteger, Integer skip it. if (!(testNum instanceof Short || testNum instanceof Byte)) { String skipType = testNum.getClass().getSimpleName(); - logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + TestUtil.logMsg("Skip " + skipType + " Data type already " + "tested for this in the " + skipType + " tests."); continue; } try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are Short and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil.logMsg("types are Short and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+=" then coerce both operands to String and @@ -765,7 +779,7 @@ public static void testShort(Short testVal, Object expectedVal, // If the Operator is "/" then the return type is Double. } else if ("/".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -773,7 +787,7 @@ public static void testShort(Short testVal, Object expectedVal, ((Short) expectedVal).doubleValue())); } else { returnType = Long.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) && ExprEval @@ -781,16 +795,17 @@ public static void testShort(Short testVal, Object expectedVal, } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, "*** End " + "\"" + "Short" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** End " + "\"" + "Short" + "\"" + " Test Sequence ***"); } if (!pass) @@ -811,6 +826,7 @@ public static void testShort(Short testVal, Object expectedVal, * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testByte(Byte testVal, Object expectedVal, String operator) throws Exception { @@ -820,7 +836,8 @@ public static void testByte(Byte testVal, Object expectedVal, String operator) // For each NumberType in this list. for (int i = 0; TestNum.getNumberList().size() > i; i++) { - logger.log(Logger.Level.INFO, "*** Start " + "\"" + "Byte" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** Start " + "\"" + "Byte" + "\"" + " Test Sequence ***"); Object testNum = TestNum.getNumberList().get(i); @@ -831,20 +848,20 @@ public static void testByte(Byte testVal, Object expectedVal, String operator) // Long, BigInteger, Integer, Short skip it. if (!(testNum instanceof Byte)) { String skipType = testNum.getClass().getSimpleName(); - logger.log(Logger.Level.INFO, "Skip " + skipType + " Data type already " + TestUtil.logMsg("Skip " + skipType + " Data type already " + "tested for this in the " + skipType + " tests."); continue; } try { String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are Byte and " + testNum.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil.logMsg("types are Byte and " + testNum.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); /* * If operator is "+=" then coerce both operands to String and @@ -856,7 +873,7 @@ public static void testByte(Byte testVal, Object expectedVal, String operator) // If the Operator is "/" then the return type is Double. } else if ("/".equals(operator)) { returnType = Double.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) @@ -864,7 +881,7 @@ public static void testByte(Byte testVal, Object expectedVal, String operator) ((Byte) expectedVal).doubleValue())); } else { returnType = Long.class; - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "Setting Expected Type: " + returnType.getCanonicalName()); pass = (ExprEval.compareClass(result, returnType) && ExprEval @@ -872,16 +889,17 @@ public static void testByte(Byte testVal, Object expectedVal, String operator) } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO,"*** End " + "\"" + "Byte" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** End " + "\"" + "Byte" + "\"" + " Test Sequence ***"); } if (!pass) @@ -903,6 +921,7 @@ public static void testByte(Byte testVal, Object expectedVal, String operator) * @param operator * - The operator in which the operands are compared. (i.e. "+", "-", * etc...) + * @throws com.sun.ts.lib.harness.EETest.Fault */ public static void testBoolean(boolean testValOne, Object testValTwo, Object expectedVal, String operator) throws Exception { @@ -913,11 +932,12 @@ public static void testBoolean(boolean testValOne, Object testValTwo, testValTwo); try { - logger.log(Logger.Level.INFO, + TestUtil.logMsg( "*** Start " + "\"" + "Boolean" + "\"" + " Test Sequence ***"); String expr = ExprEval.buildElExpr(true, operator); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); - logger.log(Logger.Level.INFO, "types are Boolean and " + testValTwo.getClass().getName()); + TestUtil.logMsg("expression to be evaluated is " + expr); + TestUtil + .logMsg("types are Boolean and " + testValTwo.getClass().getName()); Object result = ExprEval.evaluateValueExpression(expr, values, Object.class); @@ -930,22 +950,23 @@ public static void testBoolean(boolean testValOne, Object testValTwo, pass = Validator.runConcatenationTest(testValOne, result, testValTwo); } else { - logger.log(Logger.Level.INFO, "result is " + result.toString()); + TestUtil.logMsg("result is " + result.toString()); pass = (ExprEval.compareClass(result, Boolean.class) && ExprEval.compareValue((Boolean) result, expectedVal)); } } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, "*** End " + "\"" + "Boolean" + "\"" + " Test Sequence ***"); + TestUtil + .logMsg("*** End " + "\"" + "Boolean" + "\"" + " Test Sequence ***"); } if (!pass) @@ -958,8 +979,8 @@ public static void testExpression(ELProcessor elp, String expr, boolean pass = false; try { - logger.log(Logger.Level.INFO, "*** Start " + testName + " Test Sequence ***"); - logger.log(Logger.Level.INFO, "expression to be evaluated is " + expr); + TestUtil.logMsg("*** Start " + testName + " Test Sequence ***"); + TestUtil.logMsg("expression to be evaluated is " + expr); Object result = elp.eval(expr); pass = ExprEval.compareClass(result, expected.getClass()) @@ -969,16 +990,16 @@ public static void testExpression(ELProcessor elp, String expr, throw new Exception("TEST FAILED: pass = false"); } catch (RuntimeException re) { - ELTestUtil.printStackTrace(re); + TestUtil.printStackTrace(re); throw new Exception(re); } catch (Exception e) { - ELTestUtil.printStackTrace(e); + TestUtil.printStackTrace(e); throw new Exception(e); } finally { ExprEval.cleanup(); - logger.log(Logger.Level.INFO, "*** End " + testName + " Test Sequence ***"); + TestUtil.logMsg("*** End " + testName + " Test Sequence ***"); } } @@ -990,7 +1011,7 @@ private static Boolean runConcatenationTest(Object testVal, Object result, Class returnType = String.class; String expectedResult = testVal.toString() + testNum.toString(); - logger.log(Logger.Level.INFO, "Setting Expected Type: " + returnType.getName()); + TestUtil.logMsg("Setting Expected Type: " + returnType.getName()); return (ExprEval.compareClass(result, returnType) && ExprEval.compareValue(result, expectedResult)); diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClient.java new file mode 100644 index 0000000000..a4fa9603bb --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/ELClient.java @@ -0,0 +1,931 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.assignmentoperator; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.TypesBean; +import com.sun.ts.tests.el.common.util.Validator; + +import jakarta.el.ELProcessor; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elAssignmentOperatorBigDecimalTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - BigDecimal + * + * Variable B - Rotating through the following types: + * BigDecimal, BigInteger, Integer, Float, Long, Short, + * Double, Byte + * + * Excluded: none + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorBigDecimalTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "BigDecimal"; + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String aValue = "a = types.tckBigDecimal"; + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + elp.eval(aValue); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a + b", BigDecimal.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", BigDecimal.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", BigDecimal.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", BigDecimal.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", BigDecimal.valueOf(1), + comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a % b", Double.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Double.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + + } // End elAssignmentOperatorBigDecimalTest + + /** + * @testName: elAssignmentOperatorFloatTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - Float + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorFloatTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Float"; + String aValue = "a = types.tckFloat"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if (excludeList.contains(bName)) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + elp.eval(aValue); + elp.eval(bValue); + + if ("BigInteger".equals(bName)) { + // (+ operator) + Validator.testExpression(elp, "a + b", BigDecimal.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", BigDecimal.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", BigDecimal.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", BigDecimal.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", BigDecimal.valueOf(1), + comparitorA + " div " + bName); + + } else { + // (+ operator) + Validator.testExpression(elp, "a + b", Double.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", Double.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", Double.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", Double.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", Double.valueOf(1), + comparitorA + " div " + bName); + + } + + // The same for all other tested data types. + + // (% operator) + Validator.testExpression(elp, "a % b", Double.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Double.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elAssignmentOperatorFloatTest + + /** + * @testName: elAssignmentOperatorDoubleTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - Double + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, Float + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorDoubleTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Double"; + String aValue = "a = types.tckDouble"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if (excludeList.contains(bName)) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + elp.eval(aValue); + elp.eval(bValue); + + if ("BigInteger".equals(bName)) { + // (+ operator) + Validator.testExpression(elp, "a + b", BigDecimal.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", BigDecimal.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", BigDecimal.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", BigDecimal.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", BigDecimal.valueOf(1), + comparitorA + " div " + bName); + + } else { + // (+ operator) + Validator.testExpression(elp, "a + b", Double.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", Double.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", Double.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", Double.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", Double.valueOf(1), + comparitorA + " div " + bName); + + } + + // The same for all other tested data types. + + // (% operator) + Validator.testExpression(elp, "a % b", Double.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Double.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elAssignmentOperatorDoubleTest + + /** + * @testName: elAssignmentOperatorBigIntegerTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - BigInteger + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, Float, Double + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorBigIntegerTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "BigInteger"; + String aValue = "a = types.tckBigInteger"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + elp.eval(aValue); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a + b", BigInteger.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", BigInteger.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", BigInteger.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", BigDecimal.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", BigDecimal.valueOf(1), + comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a % b", BigInteger.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", BigInteger.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elAssignmentOperatorBigIntegerTest + + /** + * @testName: elAssignmentOperatorIntegerTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - Integer + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorIntegerTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Integer"; + String aValue = "a = types.tckInteger"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + elp.eval(aValue); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a + b", Long.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", Long.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", Long.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", Double.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", Double.valueOf(1), + comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a % b", Long.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Long.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elAssignmentOperatorIntegerTest + + /** + * @testName: elAssignmentOperatorLongTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - Long + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorLongTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Long"; + String aValue = "a = types.tckLong"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + elp.eval(aValue); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a + b", Long.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", Long.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", Long.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", Double.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", Double.valueOf(1), + comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a % b", Long.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Long.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elAssignmentOperatorLongTest + + /** + * @testName: elAssignmentOperatorShortTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - Short + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer, + * Long + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorShortTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Short"; + String aValue = "a = types.tckShort"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + excludeList.add("Long"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + elp.eval(aValue); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a + b", Long.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", Long.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", Long.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", Double.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", Double.valueOf(1), + comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a % b", Long.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Long.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elAssignmentOperatorShortTest + + /** + * @testName: elAssignmentOperatorByteTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - Byte + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer, + * Long, Short + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorByteTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Byte"; + String aValue = "a = types.tckByte"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + excludeList.add("Long"); + excludeList.add("Short"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + elp.eval(aValue); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a + b", Long.valueOf(2), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b", Long.valueOf(1), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b", Long.valueOf(0), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b", Double.valueOf(1), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b", Double.valueOf(1), + comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a % b", Long.valueOf(0), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Long.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elAssignmentOperatorByteTest + + /** + * @testName: elAssignmentOperatorNullTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - null + * + * Variable B - null + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorNullTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + elp.defineBean("types", new TypesBean()); + + Long expected = Long.valueOf(0); + String aValue = "a = types.tckNull"; + String bValue = "b = types.tckNull"; + + elp.eval(aValue); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a + b", expected, "null + null"); + + // (- operator) + Validator.testExpression(elp, "a - b", expected, "null - null"); + + // (* operator) + Validator.testExpression(elp, "a * b", expected, "null * null"); + + // (/ operator) + Validator.testExpression(elp, "a / b", expected, "null / null"); + + // (div operator) + Validator.testExpression(elp, "a div b", expected, "null div null"); + + // (% operator) + Validator.testExpression(elp, "a % b", expected, "null % null"); + + // (mod operator) + Validator.testExpression(elp, "a mod b", expected, "null mod null"); + + } // End elAssignmentOperatorNullTest + + /** + * @testName: elAssignmentOperatorMultiTest + * @assertion_ids: EL:SPEC:48.1.1; EL:SPEC:48.1.2; EL:SPEC:48.1.3; + * EL:SPEC:48.1.4 + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Variable A - BigDecimal + * + * Variable B - Rotating through the following types: + * BigDecimal, BigInteger, Integer, Float, Long, Short, + * Double, Byte + * + * Excluded: none + * + * @since: 3.0 + * + */ + public void elAssignmentOperatorMultiTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "BigDecimal"; + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bName = bType.getSimpleName(); + + String aValue = "a = types.tckBigDecimal"; + String bValue = TypesBean.getNumberMap().get(bType); + String cValue = "c = types.tckBigDecimal"; + + elp.eval(aValue); + elp.eval(bValue); + elp.eval(cValue); + + // (+ operator) + Validator.testExpression(elp, "a + b + c", BigDecimal.valueOf(3), + comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a * b + c", BigDecimal.valueOf(2), + comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a - b + c", BigDecimal.valueOf(1), + comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a / b + c", BigDecimal.valueOf(2), + comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a div b + c", BigDecimal.valueOf(2), + comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a % b + c", BigDecimal.valueOf(1), + comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b + c", BigDecimal.valueOf(1), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + + } // End elAssignmentOperatorMultiTest + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/build.xml new file mode 100644 index 0000000000..1a481aa85e --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/assignmentoperator/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClient.java new file mode 100644 index 0000000000..47918aeb14 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/ELClient.java @@ -0,0 +1,1120 @@ +/* + * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.binaryoperator; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Iterator; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; +import com.sun.ts.tests.el.common.util.TestNum; +import com.sun.ts.tests.el.common.util.Validator; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elNullOperandAddTest + * @assertion_ids: EL:SPEC:17.1 + * @test_Strategy: Validate that if both of the operands in an EL "+" + * (addition) operation are null, the result is (Long) 0. + */ + public void elNullOperandAddTest() throws Exception { + + boolean pass = false; + + Long expectedResult = Long.valueOf("0"); + try { + String expr = ExprEval.buildElExpr(true, "+"); + TestUtil.logTrace("expression to be evaluated is " + expr); + + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult, 0)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elNullOperandSubtractTest + * @assertion_ids: EL:SPEC:17.1 + * @test_Strategy: Validate that if both of the operands in an EL "-" + * (subtraction) operation are null, the result is (Long) 0. + */ + public void elNullOperandSubtractTest() throws Exception { + + boolean pass = false; + + Long expectedResult = Long.valueOf("0"); + try { + String expr = ExprEval.buildElExpr(false, "-"); + TestUtil.logTrace("expression to be evaluated is " + expr); + + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult, 0)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elNullOperandMultiplyTest + * @assertion_ids: EL:SPEC:17.1 + * @test_Strategy: Validate that if both of the operands in an EL "*" + * (multiplication) operation are null, the result is (Long) + * 0. + */ + public void elNullOperandMultiplyTest() throws Exception { + + boolean pass = false; + + Long expectedResult = Long.valueOf("0"); + try { + String expr = ExprEval.buildElExpr(true, "*"); + TestUtil.logTrace("expression to be evaluated is " + expr); + + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult, 0)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elNullOperandDivisionTest + * @assertion_ids: EL:SPEC:18.1 + * @test_Strategy: Validate that if both of the operands in an EL "/" + * (division) operation are null, the result is (Long) 0. + * + */ + public void elNullOperandDivisionTest() throws Exception { + + boolean pass = false; + Long expectedResult = Long.valueOf("0"); + + try { + String expr = ExprEval.buildElExpr(true, "/"); + TestUtil.logTrace("expression to be evaluated is " + expr); + + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult, 0)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elNullOperandModulusTest + * @assertion_ids: EL:SPEC:19.1 + * @test_Strategy: Validate that if both of the operands in an EL "%" (mod) + * operation are null, the result is (Long) 0. + * + */ + public void elNullOperandModulusTest() throws Exception { + + boolean pass = false; + + Long expectedResult = Long.valueOf("0"); + try { + String expr = ExprEval.buildElExpr(true, "%"); + TestUtil.logTrace("expression to be evaluated is " + expr); + + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult, 0)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elBigDecimalAddTest + * @assertion_ids: EL:SPEC:17.2.1 + * @test_Strategy: Validate that if one of the operands in an EL "+" + * (addition) operation is a BigDecimal, the result is coerced + * to BigDecimal and is the sum of the operands. + * + * Equations tested: BigDecimal + BigDecimal BigDecimal + + * Double BigDecimal + Float BigDecimal + String containing + * ".", "e", or "E" BigDecimal + BigInteger BigDecimal + + * Integer BigDecimal + Long BigDecimal + Short BigDecimal + + * Byte + */ + public void elBigDecimalAddTest() throws Exception { + + BigDecimal testValue = BigDecimal.valueOf(10.531); + BigDecimal expectedResult = BigDecimal.valueOf(11.531); + + Validator.testBigDecimal(testValue, expectedResult, "+"); + + } + + /** + * @testName: elBigDecimalSubtractTest + * @assertion_ids: EL:SPEC:17.2.2 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a BigDecimal, the result is + * coerced to BigDecimal and is the difference of the + * operands. + * + * Equations tested: BigDecimal - BigDecimal BigDecimal - + * Double BigDecimal - Float BigDecimal - String containing + * ".", "e", or "E" BigDecimal - BigInteger BigDecimal - + * Integer BigDecimal - Long BigDecimal - Short BigDecimal - + * Byte + */ + public void elBigDecimalSubtractTest() throws Exception { + + BigDecimal testValue = BigDecimal.valueOf(10.531); + BigDecimal expectedResult = BigDecimal.valueOf(9.531); + + Validator.testBigDecimal(testValue, expectedResult, "-"); + + } + + /** + * @testName: elBigDecimalMultiplyTest + * @assertion_ids: EL:SPEC:17.2.3 + * @test_Strategy: Validate that if one of the operands in an EL "*" + * (multiplication) operation is a BigDecimal, the result is + * coerced to BigDecimal and is the product of the operands. + * + * Equations tested: BigDecimal * BigDecimal BigDecimal * + * Double BigDecimal * Float BigDecimal * String containing + * ".", "e", or "E" BigDecimal * BigInteger BigDecimal * + * Integer BigDecimal * Long BigDecimal * Short BigDecimal * + * Byte + */ + public void elBigDecimalMultiplyTest() throws Exception { + + BigDecimal testValue = BigDecimal.valueOf(1.5); + BigDecimal expectedResult = BigDecimal.valueOf(1.5); + + Validator.testBigDecimal(testValue, expectedResult, "*"); + + } + + /** + * @testName: elBigDecimalDivisionTest + * @assertion_ids: EL:SPEC:18.2 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a BigDecimal, the result is coerced to + * BigDecimal and is the quotient of the operands. + * + * Equations tested: BigDecimal / BigDecimal BigDecimal / + * Double BigDecimal / Float BigDecimal / String containing + * ".", "e", or "E" BigDecimal / BigInteger BigDecimal / + * Integer BigDecimal / Long BigDecimal / Short BigDecimal / + * Byte + */ + public void elBigDecimalDivisionTest() throws Exception { + + BigDecimal testValue = BigDecimal.valueOf(3.0); + BigDecimal expectedResult = BigDecimal.valueOf(3.0); + + Validator.testBigDecimal(testValue, expectedResult, "/"); + + } + + /** + * @testName: elBigDecimalModulusTest + * @assertion_ids: EL:SPEC:19.2 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a BigDecimal, the result is coerced to Double + * and is the remainder of the quotient of the operands. + * + * Equations tested: BigDecimal % BigDecimal BigDecimal % + * Double BigDecimal % Float BigDecimal % String containing + * ".", "e", or "E" BigDecimal % BigInteger BigDecimal % + * Integer BigDecimal % Long BigDecimal % Short BigDecimal % + * Byte + */ + public void elBigDecimalModulusTest() throws Exception { + + BigDecimal testValue = BigDecimal.valueOf(2.5); + BigDecimal expectedResult = BigDecimal.valueOf(0.5); + + Validator.testBigDecimal(testValue, expectedResult, "%"); + + } + + /** + * @testName: elBigIntegerAddTest + * @assertion_ids: EL:SPEC:17.4.1 + * @test_Strategy: Validate that if one of the operands in an EL "+" + * (addition) operation is a BigInteger, the result is coerced + * to BigInteger and is the sum of the operands. + * + * Equations tested: BigInteger + BigInteger BigInteger + + * Integer BigInteger + Long BigInteger + Short BigInteger + + * Byte + */ + public void elBigIntegerAddTest() throws Exception { + + BigInteger testValue = BigInteger.valueOf(10531); + BigInteger expectedResult = BigInteger.valueOf(10532); + + Validator.testBigInteger(testValue, expectedResult, "+"); + + } + + /** + * @testName: elBigIntegerSubtractTest + * @assertion_ids: EL:SPEC:17.4.2 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a BigInteger, the result is + * coerced to BigInteger and is the difference of the + * operands. + * + * Equations tested: BigInteger - BigInteger BigInteger - + * Integer BigInteger - Long BigInteger - Short BigInteger - + * Byte + */ + public void elBigIntegerSubtractTest() throws Exception { + + BigInteger testValue = BigInteger.valueOf(10531); + BigInteger expectedResult = BigInteger.valueOf(10530); + + Validator.testBigInteger(testValue, expectedResult, "-"); + + } + + /** + * @testName: elBigIntegerMultiplyTest + * @assertion_ids: EL:SPEC:17.4.3 + * @test_Strategy: Validate that if one of the operands in an EL "*" operation + * is a BigInteger, the result is coerced to BigInteger and is + * the product of the operands. + * + * BigInteger * BigInteger BigInteger * Integer BigInteger * + * Long BigInteger * Short BigInteger * Byte + */ + public void elBigIntegerMultiplyTest() throws Exception { + + BigInteger testValue = BigInteger.valueOf(10531); + BigInteger expectedResult = BigInteger.valueOf(10531); + + Validator.testBigInteger(testValue, expectedResult, "*"); + + } + + /** + * @testName: elBigIntegerDivisionTest + * @assertion_ids: EL:SPEC:18.2 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a BigInteger, the result is coerced to + * BigDecimal and is the quotient of the operands. + * + * BigInteger / BigInteger BigInteger / Integer BigInteger / + * Long BigInteger / Short BigInteger / Byte + */ + public void elBigIntegerDivisionTest() throws Exception { + + BigInteger testValue = BigInteger.valueOf(10531); + BigInteger expectedResult = BigInteger.valueOf(10531); + + Validator.testBigInteger(testValue, expectedResult, "/"); + + } + + /** + * @testName: elBigIntegerModulusTest + * @assertion_ids: EL:SPEC:19.3 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a BigInteger, the result is coerced to + * BigInteger and is the remainder of the quotient of the + * operands. + * + * BigInteger % BigInteger BigInteger % Integer BigInteger % + * Long BigInteger % Short BigInteger % Byte + */ + public void elBigIntegerModulusTest() throws Exception { + + BigInteger testValue = BigInteger.valueOf(10531); + BigInteger expectedResult = BigInteger.valueOf(0); + + Validator.testBigInteger(testValue, expectedResult, "%"); + + } + + /** + * @testName: elFloatAddTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "+" + * (addition) operation is a Float, the result is coerced to + * Double and is the sum of the operands. + * + * Equations tested: Float + Double Float + Float Float + + * String containing ".", "e", or "E" Float + BigInteger Float + * + Integer Float + Long Float + Short Float + Byte + */ + public void elFloatAddTest() throws Exception { + + Float expectedResult; + // For each float in validate List. + for (Iterator it = TestNum.getFloatList().iterator(); it.hasNext();) { + Float testValue = (Float) it.next(); + expectedResult = testValue + Float.valueOf("1.0"); + Validator.testFloat(testValue, expectedResult, "+"); + } + + } + + /** + * @testName: elFloatSubtractTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a Float, the result is coerced + * to Double and is the difference of the operands. + * + * Equations tested: Float - Double Float - Float Float - + * String containing ".", "e", or "E" Float - BigInteger Float + * - Integer Float - Long Float - Short Float - Byte + */ + public void elFloatSubtractTest() throws Exception { + + Float expectedResult; + // For each float in validate List. + for (Iterator it = TestNum.getFloatList().iterator(); it.hasNext();) { + Float testValue = (Float) it.next(); + expectedResult = testValue - Float.valueOf("1.0"); + Validator.testFloat(testValue, expectedResult, "-"); + } + + } + + /** + * @testName: elFloatMultiplyTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "*" + * (multiplication) operation is a Float, the result is + * coerced to Double and is the product of the operands. + * + * Equations tested: Float * Double Float * Float Float * + * String containing ".", "e", or "E" Float * BigInteger Float + * * Integer Float * Long Float * Short Float * Byte + */ + public void elFloatMultiplyTest() throws Exception { + + Float expectedResult; + // For each float in validate List. + for (Iterator it = TestNum.getFloatList().iterator(); it.hasNext();) { + Float testValue = (Float) it.next(); + expectedResult = testValue * Float.valueOf("1.0"); + Validator.testFloat(testValue, expectedResult, "*"); + } + + } + + /** + * @testName: elFloatDivisionTest + * @assertion_ids: EL:SPEC:18.2; EL:SPEC:18.3 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a Float, the result is coerced to Double and + * is the quotient of the operands. + * + * Equations tested: Float / Double Float / Float Float / + * String containing ".", "e", or "E" Float / BigInteger Float + * / Integer Float / Long Float / Short Float / Byte + */ + public void elFloatDivisionTest() throws Exception { + + Float expectedResult; + // For each float in validate List. + for (Iterator it = TestNum.getFloatList().iterator(); it.hasNext();) { + Float testValue = (Float) it.next(); + expectedResult = testValue / Float.valueOf("1.0"); + Validator.testFloat(testValue, expectedResult, "/"); + } + + } + + /** + * @testName: elFloatModulusTest + * @assertion_ids: EL:SPEC:19.2 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a Float, the result is coerced to Double and + * is the remainder of the quotient of the operands. + * + * Equations tested: Float % Double Float % Float Float % + * String containing ".", "e", or "E" Float % BigInteger Float + * % Integer Float % Long Float % Short Float % Byte + */ + public void elFloatModulusTest() throws Exception { + + Float expectedResult; + // For each float in validate List. + for (Iterator it = TestNum.getFloatList().iterator(); it.hasNext();) { + Float testValue = (Float) it.next(); + expectedResult = testValue % Float.valueOf("1.0"); + Validator.testFloat(testValue, expectedResult, "%"); + } + + } + + /** + * @testName: elDoubleAddTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "+" + * (addition) operation is a Double, the result is coerced to + * Double and is the sum of the operands. + * + * Equations tested: Double + Double Double + String + * containing ".", "e", or "E" Double + BigInteger Double + + * Integer Double + Long Double + Short Double + Byte + */ + public void elDoubleAddTest() throws Exception { + + Double testValue = Double.valueOf(2.5); + Double expectedResult = Double.valueOf(3.5); + + Validator.testDouble(testValue, expectedResult, "+"); + + } + + /** + * @testName: elDoubleSubtractTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a Double, the result is coerced + * to Double and is the difference of the operands. + * + * Equations tested: Double - Double Double - String + * containing ".", "e", or "E" Double - BigInteger Double - + * Integer Double - Long Double - Short Double - Byte + */ + public void elDoubleSubtractTest() throws Exception { + + Double testValue = Double.valueOf(2.5); + Double expectedResult = Double.valueOf(1.5); + + Validator.testDouble(testValue, expectedResult, "-"); + + } + + /** + * @testName: elDoubleMultiplyTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "*" + * (multiplication) operation is a Double, the result is + * coerced to Double and is the product of the operands. + * + * Equations tested: Double * Double Double * String + * containing ".", "e", or "E" Double * BigInteger Double * + * Integer Double * Long Double * Short Double * Byte + */ + public void elDoubleMultiplyTest() throws Exception { + + Double testValue = Double.valueOf(2.5); + Double expectedResult = Double.valueOf(2.5); + + Validator.testDouble(testValue, expectedResult, "*"); + + } + + /** + * @testName: elDoubleDivisionTest + * @assertion_ids: EL:SPEC:18.2; EL:SPEC:18.3 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a Double, the result is coerced to Double and + * is the quotient of the operands. + * + * Equations tested: Double / Double Double / String + * containing ".", "e", or "E" Double / BigInteger Double / + * Integer Double / Long Double / Short Double / Byte + */ + public void elDoubleDivisionTest() throws Exception { + + Double testValue = Double.valueOf(2.5); + Double expectedResult = Double.valueOf(2.5); + + Validator.testDouble(testValue, expectedResult, "/"); + + } + + /** + * @testName: elDoubleModulusTest + * @assertion_ids: EL:SPEC:19.2 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a Double, the result is coerced to Double and + * is the remainder of the quotient of the operands. + * + * Equations tested: Double % Double Double % String + * containing ".", "e", or "E" Double % BigInteger Double % + * Integer Double % Long Double % Short Double % Byte + */ + public void elDoubleModulusTest() throws Exception { + + Double testValue = Double.valueOf(2.5); + Double expectedResult = Double.valueOf(0.5); + + Validator.testDouble(testValue, expectedResult, "%"); + } + + /** + * @testName: elNumericStringSubtractTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a numeric string, the result is + * coerced to Double and is the difference of the operands. + * + * Equations tested: Numeric String - String containing ".", + * "e", or "E" Numeric String - BigInteger Numeric String - + * Integer Numeric String - Long Numeric String - Short + * Numeric String - Byte + */ + public void elNumericStringSubtractTest() throws Exception { + + String testValue = "25e-1"; + Double expectedResult = Double.valueOf(1.5); + + Validator.testNumericString(testValue, expectedResult, "-"); + + } + + /** + * @testName: elNumericStringMultiplyTest + * @assertion_ids: EL:SPEC:17.3.1; EL:SPEC:17.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "*" + * (multiplication) operation is a numeric string, the result + * is coerced to Double and is the product of the operands. + * + * Equations tested: Numeric String * String containing ".", + * "e", or "E" Numeric String * BigInteger Numeric String * + * Integer Numeric String * Long Numeric String * Short + * Numeric String * Byte + */ + public void elNumericStringMultiplyTest() throws Exception { + + String testValue = "25E-1"; + Double expectedResult = Double.valueOf(2.5); + + Validator.testNumericString(testValue, expectedResult, "*"); + + } + + /** + * @testName: elNumericStringDivisionTest + * @assertion_ids: EL:SPEC:18.2; EL:SPEC:18.3 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a numeric string, the result is coerced to + * Double and is the quotient of the operands. + * + * Equations tested: Numeric String / String containing ".", + * "e", or "E" Numeric String / BigInteger Numeric String / + * Integer Numeric String / Long Numeric String / Short + * Numeric String / Byte + */ + public void elNumericStringDivisionTest() throws Exception { + + String testValue = "2.5"; + Double expectedResult = Double.valueOf(2.5); + + Validator.testNumericString(testValue, expectedResult, "/"); + + } + + /** + * @testName: elNumericStringModulusTest + * @assertion_ids: EL:SPEC:19.2 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a numeric string, the result is coerced to + * Double and is the remainder of the quotient of the + * operands. + * + * Equations tested: Numeric String % String containing ".", + * "e", or "E" Numeric String % BigInteger Numeric String % + * Integer Numeric String % Long Numeric String % Short + * Numeric String % Byte + */ + public void elNumericStringModulusTest() throws Exception { + + String testValue = "2.5e0"; + Double expectedResult = Double.valueOf(0.5); + + Validator.testNumericString(testValue, expectedResult, "%"); + + } + + /** + * @testName: elLongAddTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "+" + * (addition) operation is a Long, the result is coerced to + * Long and is the sum of the operands. + * + * Equations tested: Long + Integer Long + Long Long + Short + * Long + Byte + */ + public void elLongAddTest() throws Exception { + + Long testValue = Long.valueOf(25000); + Long expectedResult = Long.valueOf(25001); + + Validator.testLong(testValue, expectedResult, "+"); + + } + + /** + * @testName: elLongSubtractTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a Long, the result is coerced to + * Long and is the difference of the operands. + * + * Equations tested: Long - Integer Long - Long Long - Short + * Long - Byte + */ + public void elLongSubtractTest() throws Exception { + + Long testValue = Long.valueOf(25000); + Long expectedResult = Long.valueOf(24999); + + Validator.testLong(testValue, expectedResult, "-"); + + } + + /** + * @testName: elLongMultiplyTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "*" + * (multiplication) operation is a Long, the result is coerced + * to Long and is the product of the operands. + * + * Equations tested: Long * Integer Long * Long Long * Short + * Long * Byte + */ + public void elLongMultiplyTest() throws Exception { + + Long testValue = Long.valueOf(25000); + Long expectedResult = Long.valueOf(25000); + + Validator.testLong(testValue, expectedResult, "*"); + + } + + /** + * @testName: elLongDivisionTest + * @assertion_ids: EL:SPEC:18.3 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a Long, the result is coerced to Double and is + * the quotient of the operands. + * + * Equations tested: Long / Integer Long / Long Long / Short + * Long / Byte + */ + public void elLongDivisionTest() throws Exception { + + Long testValue = Long.valueOf(25000); + Long expectedResult = Long.valueOf(25000); + + Validator.testLong(testValue, expectedResult, "/"); + + } + + /** + * @testName: elLongModulusTest + * @assertion_ids: EL:SPEC:19.4 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a Long, the result is coerced to Long and is + * the remainder of the quotient of the operands. + * + * Equations tested: Long % Integer Long % Long Long % Short + * Long % Byte + */ + public void elLongModulusTest() throws Exception { + + Long testValue = Long.valueOf(25000); + Long expectedResult = Long.valueOf(0); + + Validator.testLong(testValue, expectedResult, "%"); + + } + + /** + * @testName: elIntegerAddTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "+" + * (addition) operation is a Integer, the result is coerced to + * Long and is the sum of the operands. + * + * Equations tested: Integer + Integer Integer + Short Integer + * + Byte + */ + public void elIntegerAddTest() throws Exception { + + Integer testValue = Integer.valueOf(25); + Integer expectedResult = Integer.valueOf(26); + + Validator.testInteger(testValue, expectedResult, "+"); + + } + + /** + * @testName: elIntegerSubtractTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a Integer, the result is coerced + * to Long and is the difference of the operands. + * + * Equations tested: Long - Integer Long - Short Long - Byte + */ + public void elIntegerSubtractTest() throws Exception { + + Integer testValue = Integer.valueOf(25); + Integer expectedResult = Integer.valueOf(24); + + Validator.testInteger(testValue, expectedResult, "-"); + + } + + /** + * @testName: elIntegerMultiplyTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "*" + * (multiplication) operation is a Integer, the result is + * coerced to Long and is the product of the operands. + * + * Equations tested: Integer * Integer Integer * Short Integer + * * Byte + */ + public void elIntegerMultiplyTest() throws Exception { + + Integer testValue = Integer.valueOf(25); + Integer expectedResult = Integer.valueOf(25); + + Validator.testInteger(testValue, expectedResult, "*"); + + } + + /** + * @testName: elIntegerDivisionTest + * @assertion_ids: EL:SPEC:18.3 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a Integer, the result is coerced to Double and + * is the quotient of the operands. + * + * Equations tested: Integer / Integer Integer / Short Integer + * / Byte + */ + public void elIntegerDivisionTest() throws Exception { + + Integer testValue = Integer.valueOf(25); + Integer expectedResult = Integer.valueOf(25); + + Validator.testInteger(testValue, expectedResult, "/"); + + } + + /** + * @testName: elIntegerModulusTest + * @assertion_ids: EL:SPEC:19.4 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a Integer, the result is coerced to Long and + * is the remainder of the quotient of the operands. + * + * Equations tested: Integer % Integer Integer % Short Integer + * % Byte + */ + public void elIntegerModulusTest() throws Exception { + + Integer testValue = Integer.valueOf(25); + Integer expectedResult = Integer.valueOf(0); + + Validator.testInteger(testValue, expectedResult, "%"); + + } + + /** + * @testName: elShortAddTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "+" + * (addition) operation is a Short, the result is coerced to + * Long and is the sum of the operands. + * + * Equations tested: Short + Short Short + Byte + */ + public void elShortAddTest() throws Exception { + + Short testValue = Short.valueOf("2"); + Short expectedResult = Short.valueOf("3"); + + Validator.testShort(testValue, expectedResult, "+"); + + } + + /** + * @testName: elShortSubtractTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "-" + * (subtraction) operation is a Short, the result is coerced + * to Long and is the difference of the operands. + * + * Equations tested: Short - Short Short - Byte + */ + public void elShortSubtractTest() throws Exception { + + Short testValue = Short.valueOf("2"); + Short expectedResult = Short.valueOf("1"); + + Validator.testShort(testValue, expectedResult, "-"); + + } + + /** + * @testName: elShortMultiplyTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if one of the operands in an EL "*" + * (multiplication) operation is a Short, the result is + * coerced to Long and is the product of the operands. + * + * Equations tested: Short * Short Short * Byte + */ + public void elShortMultiplyTest() throws Exception { + + Short testValue = Short.valueOf("2"); + Short expectedResult = Short.valueOf("2"); + + Validator.testShort(testValue, expectedResult, "*"); + + } + + /** + * @testName: elShortDivisionTest + * @assertion_ids: EL:SPEC:18.3 + * @test_Strategy: Validate that if one of the operands in an EL "/" (div) + * operation is a Short, the result is coerced to Double and + * is the quotient of the operands. + * + * Equations tested: Short / Short Short / Byte + */ + public void elShortDivisionTest() throws Exception { + + Short testValue = Short.valueOf("2"); + Short expectedResult = Short.valueOf("2"); + + Validator.testShort(testValue, expectedResult, "/"); + + } + + /** + * @testName: elShortModulusTest + * @assertion_ids: EL:SPEC:19.4 + * @test_Strategy: Validate that if one of the operands in an EL "%" (mod) + * operation is a Short, the result is coerced to Long and is + * the remainder of the quotient of the operands. + * + * Equations tested: Short % Short Short % Byte + */ + public void elShortModulusTest() throws Exception { + + Short testValue = Short.valueOf("2"); + Short expectedResult = Short.valueOf("0"); + + Validator.testShort(testValue, expectedResult, "%"); + + } + + /** + * @testName: elByteAddTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if both operands in an EL "+" (addition) + * operation are Bytes, the result is coerced to Long and is + * the sum of the operands. + * + * Equations tested: Byte + Byte + */ + public void elByteAddTest() throws Exception { + + Byte testValue = Byte.valueOf("2"); + Byte expectedResult = Byte.valueOf("3"); + + Validator.testByte(testValue, expectedResult, "+"); + + } + + /** + * @testName: elByteSubtractTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if both operands in an EL "-" (subtraction) + * operation are Bytes, the result is coerced to Long and is + * the difference of the operands. + * + * Equations tested: Byte - Byte + */ + public void elByteSubtractTest() throws Exception { + + Byte testValue = Byte.valueOf("2"); + Byte expectedResult = Byte.valueOf("1"); + + Validator.testByte(testValue, expectedResult, "-"); + + } + + /** + * @testName: elByteMultiplyTest + * @assertion_ids: EL:SPEC:17.5 + * @test_Strategy: Validate that if both operands in an EL "*" + * (multiplication) operation are Bytes, the result is coerced + * to Long and is the product of the operands. + * + * Equations tested: Byte * Byte + */ + public void elByteMultiplyTest() throws Exception { + + Byte testValue = Byte.valueOf("2"); + Byte expectedResult = Byte.valueOf("2"); + + Validator.testByte(testValue, expectedResult, "*"); + + } + + /** + * @testName: elByteDivisionTest + * @assertion_ids: EL:SPEC:18.3 + * @test_Strategy: Validate that if both operands in an EL "/" (div) operation + * are Bytes, the result is coerced to Double and is the + * quotient of the operands. + * + * Equations tested: Byte / Byte + */ + public void elByteDivisionTest() throws Exception { + + Byte testValue = Byte.valueOf("2"); + Byte expectedResult = Byte.valueOf("2"); + + Validator.testByte(testValue, expectedResult, "/"); + + } + + /** + * @testName: elByteModulusTest + * @assertion_ids: EL:SPEC:19.4 + * @test_Strategy: Validate that if both operands in an EL "%" (mod) operation + * are Bytes, the result is coerced to Long and is the + * remainder of the quotient of the operands. + * + * Equations tested: Byte % Byte + */ + public void elByteModulusTest() throws Exception { + + Byte testValue = Byte.valueOf("2"); + Byte expectedResult = Byte.valueOf("0"); + + Validator.testByte(testValue, expectedResult, "%"); + + } + + /** + * @testName: elBooleanAndTest + * @assertion_ids: EL:SPEC:23.1; EL:SPEC:24.2.1 + * @test_Strategy: Validate that if one of the operands in an EL "&&", "and" + * operation is a Boolean, the result is coerced to Boolean. + * + * Equations tested: Boolean && String Boolean && Boolean + * Boolean and String Boolean and Boolean + * + */ + public void elBooleanAndTest() throws Exception { + + Validator.testBoolean(true, "true", true, "&&"); + Validator.testBoolean(true, true, true, "&&"); + + Validator.testBoolean(true, "false", false, "and"); + Validator.testBoolean(true, false, false, "and"); + + } + + /** + * @testName: elBooleanOrTest + * @assertion_ids: EL:SPEC:23.1; EL:SPEC:24.2.1 + * @test_Strategy: Validate that if one of the operands in an EL "||", "or" + * operation is a Boolean, the result is coerced to Boolean. + * + * Equations tested: Boolean || String Boolean || Boolean + * Boolean or String Boolean or Boolean + * + */ + public void elBooleanOrTest() throws Exception { + + Validator.testBoolean(false, "false", false, "||"); + Validator.testBoolean(true, "false", true, "or"); + + Validator.testBoolean(true, false, true, "||"); + Validator.testBoolean(true, true, true, "or"); + + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/build.xml new file mode 100644 index 0000000000..f78ee93f3c --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/binaryoperator/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/build.xml new file mode 100644 index 0000000000..1d710f6545 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClient.java new file mode 100644 index 0000000000..6d2030e36a --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClient.java @@ -0,0 +1,1912 @@ +/* + * Copyright (c) 2009, 2021 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * $Id$ + */ + +package com.sun.ts.tests.el.spec.coercion; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.Time; +import java.util.Date; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; +import java.util.function.Predicate; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; +import com.sun.ts.tests.el.common.util.NameValuePair; + +import jakarta.el.ELException; +import jakarta.el.ELProcessor; + +public class ELClient extends ServiceEETest { + + private Properties testProps; + + private static final String NLINE = System.getProperty("line.separator", + "\n"); + + private static final String BYTE = "30"; + + private static final String SHORT = "32"; + + private static final String INTEGER = "33"; + + private static final String LONG = "34"; + + // NOTE: The elStringToNumberCoercionTest assumes a non-numeric + // ending character for Float and Double types + private static final String FLOAT = "35.5f"; + + private static final String DOUBLE = "36.5d"; + + private static final String BIGINT = "125"; + + private static final String BIGDEC = "100.5"; + + private static enum greeting { + hello, goodbye + }; + + private Hashtable numberTable; + + private enum planets { + MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE + /** ,PLUTO */ + }; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + initializeNumberTable(); + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: positivePrimitiveToBoxedTest + * @assertion_ids: EL:SPEC:37.3; EL:SPEC:37.5 + * @test_Strategy: Validate that the primitive types - boolean - char - byte - + * short - int - long - float - double when found in an + * expression are converted to the appropriate 'boxed' types. + */ + public void positivePrimitiveToBoxedTest() throws Exception { + + boolean fail = false; + boolean[] pass = { false, false, false, false, false, false, false, false }; + Object result = null; + + try { + result = ExprEval.evaluateValueExpression("${true}", null, Boolean.class); + pass[0] = ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue(result, Boolean.TRUE); + + result = ExprEval.evaluateValueExpression("#{'x'}", null, + Character.class); + pass[1] = ExprEval.compareClass(result, Character.class) + && ExprEval.compareValue(result, Character.valueOf('x')); + + result = ExprEval.evaluateValueExpression("${2}", null, Byte.class); + pass[2] = ExprEval.compareClass(result, Byte.class) + && ExprEval.compareValue(result, Byte.valueOf("2")); + + result = ExprEval.evaluateValueExpression("#{20}", null, Short.class); + pass[3] = ExprEval.compareClass(result, Short.class) + && ExprEval.compareValue(result, Short.valueOf("20")); + + result = ExprEval.evaluateValueExpression("${2000}", null, Integer.class); + pass[4] = ExprEval.compareClass(result, Integer.class) + && ExprEval.compareValue(result, Integer.valueOf(2000)); + + result = ExprEval.evaluateValueExpression("#{2000}", null, Long.class); + pass[5] = ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue(result, Long.valueOf(2000L)); + + result = ExprEval.evaluateValueExpression("${2e+3}", null, Float.class); + pass[6] = ExprEval.compareClass(result, Float.class) + && ExprEval.compareValue(result, Float.valueOf(2000f)); + + result = ExprEval.evaluateValueExpression("#{2000.00}", null, + Double.class); + pass[7] = ExprEval.compareClass(result, Double.class) + && ExprEval.compareValue(result, Double.valueOf(2000)); + + } catch (RuntimeException re) { + throw new Exception(re); + } catch (Exception e) { + throw new Exception(e); + } + + for (int i = 0; i < pass.length; ++i) { + if (!pass[i]) { + fail = true; + TestUtil.logErr("Unexpected result for test case " + i); + } + } + + if (fail) + throw new Exception("TEST FAILED"); + } + + /** + * @testName: positiveBoxedToPrimitiveTest + * @assertion_ids: EL:SPEC:37.3; EL:SPEC:37.4 + * @test_Strategy: Validate that the 'boxed' types - Boolean - Character - + * Byte - Short - Integer - Long - Float - Double when found + * in an expression are converted to the appropriate primitive + * types. Note that the conversion takes place in + * ExprEval.evaluateValueExpression() when + * ExpressionFactory.createValueExpression() is called. When + * ValueExpression.getValue() is subsequently called, the + * primitive type is converted back to its 'boxed' type. + */ + public void positiveBoxedToPrimitiveTest() throws Exception { + + boolean fail = false; + boolean[] pass = { false, false, false, false, false, false, false, false }; + Object result = null; + + String immExpr = "${A}"; + String defExpr = "#{A}"; + + Boolean boolVal = Boolean.FALSE; + NameValuePair[] boolNV = NameValuePair.buildUnaryNameValue(boolVal); + + Character charVal = Character.valueOf('x'); + NameValuePair[] charNV = NameValuePair.buildUnaryNameValue(charVal); + + Byte byteVal = Byte.valueOf("2"); + NameValuePair[] byteNV = NameValuePair.buildUnaryNameValue(byteVal); + + Short shortVal = Short.valueOf("20"); + NameValuePair[] shortNV = NameValuePair.buildUnaryNameValue(shortVal); + + Integer intVal = Integer.valueOf(2000); + NameValuePair[] intNV = NameValuePair.buildUnaryNameValue(intVal); + + Long longVal = Long.valueOf(2000); + NameValuePair[] longNV = NameValuePair.buildUnaryNameValue(longVal); + + Float floatVal = Float.valueOf("2e+3"); + NameValuePair[] floatNV = NameValuePair.buildUnaryNameValue(floatVal); + + Double doubleVal = Double.valueOf(2000.0); + NameValuePair[] doubleNV = NameValuePair.buildUnaryNameValue(doubleVal); + + try { + result = ExprEval.evaluateValueExpression(defExpr, boolNV, boolean.class); + pass[0] = ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue(result, boolVal); + + result = ExprEval.evaluateValueExpression(immExpr, charNV, char.class); + pass[1] = ExprEval.compareClass(result, Character.class) + && ExprEval.compareValue(result, charVal); + + result = ExprEval.evaluateValueExpression(defExpr, byteNV, byte.class); + pass[2] = ExprEval.compareClass(result, Byte.class) + && ExprEval.compareValue(result, byteVal); + + result = ExprEval.evaluateValueExpression(immExpr, shortNV, short.class); + pass[3] = ExprEval.compareClass(result, Short.class) + && ExprEval.compareValue(result, shortVal); + + result = ExprEval.evaluateValueExpression(defExpr, intNV, int.class); + pass[4] = ExprEval.compareClass(result, Integer.class) + && ExprEval.compareValue(result, intVal); + + result = ExprEval.evaluateValueExpression(immExpr, longNV, long.class); + pass[5] = ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue(result, longVal); + + result = ExprEval.evaluateValueExpression(defExpr, floatNV, float.class); + pass[6] = ExprEval.compareClass(result, Float.class) + && ExprEval.compareValue(result, floatVal); + + result = ExprEval.evaluateValueExpression(immExpr, doubleNV, + double.class); + pass[7] = ExprEval.compareClass(result, Double.class) + && ExprEval.compareValue(result, doubleVal); + + } catch (RuntimeException re) { + throw new Exception(re); + } catch (Exception e) { + throw new Exception(e); + } finally { + ExprEval.cleanup(); + } + + for (int i = 0; i < pass.length; ++i) { + if (!pass[i]) { + fail = true; + TestUtil.logErr("Unexpected result for test case " + i); + } + } + + if (fail) + throw new Exception("TEST FAILED"); + } + + /** + * @testName: positiveElBooleanCoercionTest + * @assertion_ids: EL:SPEC:41.1; EL:SPEC:41.2; EL:SPEC:41.3 + * @test_Strategy: Validate that null, the empty String, a Boolean, and a + * proper String argument to Boolean.valueOf() are coerced to + * the expected Boolean values. + */ + public void positiveElBooleanCoercionTest() throws Exception { + + Class expectedClass = Boolean.class; + boolean pass = false; + + try { + Object result2 = ExprEval.evaluateValueExpression("#{''}", null, + expectedClass); + Object result3 = ExprEval.evaluateValueExpression( + "${" + Boolean.TRUE + "}", null, expectedClass); + Object result4 = ExprEval.evaluateValueExpression("#{'true'}", null, + expectedClass); + + TestUtil.logTrace("result2 is " + result2.toString()); + TestUtil.logTrace("result3 is " + result3.toString()); + TestUtil.logTrace("result4 is " + result4.toString()); + + pass = (ExprEval.compareClass(result2, expectedClass) + && ExprEval.compareValue(result2, Boolean.FALSE) + && ExprEval.compareClass(result3, expectedClass) + && ExprEval.compareValue(result3, Boolean.TRUE) + && ExprEval.compareClass(result4, expectedClass) + && ExprEval.compareValue(result4, Boolean.TRUE)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: negativeElBooleanCoercionTest + * @assertion_ids: EL:SPEC:41.4; EL:JAVADOC:112 + * @test_Strategy: Validate that an error occurs when an attempt is made to + * coerce an invalid class to a Boolean. The coercion is + * performed with a call to ValueExpression.getValue(), which + * must throw an ELException. + */ + public void negativeElBooleanCoercionTest() throws Exception { + + boolean pass = false; + + try { + ExprEval.evaluateValueExpression("${1}", null, Boolean.class); + TestUtil.logErr( + "No exception thrown when coercing invalid class " + "to Boolean"); + + } catch (ELException ee) { + pass = true; + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elPrimitiveToStringCoercionTest + * @assertion_ids: EL:SPEC:38.1; EL:SPEC:38.2; EL:SPEC:38.3; EL:SPEC:38.5 + * @test_Strategy: Validate that the following types coerce to type of String + * and the expected String value is returned. + * + * Types: String(), boolean, null, byte, char, short, int, + * long, float, double, enum. + * + */ + public void elPrimitiveToStringCoercionTest() throws Exception { + + boolean pass1, pass2, pass4, pass5, pass6, pass7, pass8, pass9, pass10, + pass11 = false; + + Object result1, result2, result4, result5, result6, result7, result8, + result9, result10, result11; + + Class expectedClass = String.class; + + String primString = "\"STRING\""; // result1 + boolean primBoolean = false; // result2 + // String nothing = null; // result3 + byte primByte = 0; // result4 + char primChar = '1'; // result5 + short primShort = 2; // result6 + int primInt = 3; // result7 + long primLong = 4L; // result8 + float primFloat = 5.5f; // result9 + double primDouble = 6.5d; // result10 + greeting morning; // result11 + morning = greeting.hello; + + try { + // String to String + result1 = ExprEval.evaluateValueExpression("${" + primString + "}", null, + expectedClass); + pass1 = (ExprEval.compareClass(result1, expectedClass) + && ExprEval.compareValue(result1, "STRING")); + + // boolean to String + result2 = ExprEval.evaluateValueExpression("#{" + primBoolean + "}", null, + expectedClass); + pass2 = (ExprEval.compareClass(result2, expectedClass) + && ExprEval.compareValue(result2, "false")); + + // byte to String + result4 = ExprEval.evaluateValueExpression("#{" + primByte + "}", null, + expectedClass); + pass4 = (ExprEval.compareClass(result4, expectedClass) + && ExprEval.compareValue(result4, "0")); + + // char to String + result5 = ExprEval.evaluateValueExpression("#{" + primChar + "}", null, + expectedClass); + pass5 = (ExprEval.compareClass(result5, expectedClass) + && ExprEval.compareValue(result5, "1")); + + // short to String + result6 = ExprEval.evaluateValueExpression("#{" + primShort + "}", null, + expectedClass); + pass6 = (ExprEval.compareClass(result6, expectedClass) + && ExprEval.compareValue(result6, "2")); + + // int to String + result7 = ExprEval.evaluateValueExpression("#{" + primInt + "}", null, + expectedClass); + pass7 = (ExprEval.compareClass(result7, expectedClass) + && ExprEval.compareValue(result7, "3")); + + // long to String + result8 = ExprEval.evaluateValueExpression("#{" + primLong + "}", null, + expectedClass); + pass8 = (ExprEval.compareClass(result8, expectedClass) + && ExprEval.compareValue(result8, "4")); + + // float to String + result9 = ExprEval.evaluateValueExpression("#{" + primFloat + "}", null, + expectedClass); + pass9 = (ExprEval.compareClass(result9, expectedClass) + && ExprEval.compareValue(result9, "5.5")); + + // double to String + result10 = ExprEval.evaluateValueExpression("#{" + primDouble + "}", null, + expectedClass); + pass10 = (ExprEval.compareClass(result10, expectedClass) + && ExprEval.compareValue(result10, "6.5")); + + // enum to String + result11 = ExprEval.evaluateValueExpression("#{'" + morning + "'}", null, + expectedClass); + + pass11 = (ExprEval.compareClass(result11, expectedClass) + && ExprEval.compareValue(result11, morning.name())); + + } catch (RuntimeException re) { + throw new Exception(re); + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass1) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "String Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass2) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "boolean Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass4) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "byte Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass5) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "char Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass6) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "short Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass7) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "int Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass8) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "long Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass9) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "float Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass10) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "double Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass11) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "enum Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + } + + /** + * @testName: elWrapperToStringCoercionTest + * @assertion_ids: EL:SPEC:38.5 + * @test_Strategy: Validate that the following types coerce to type of String + * and the expected String value is returned. + * + * Types: Boolean, Byte, Character, Short, Integer, Long, + * Float, Double. + * + */ + public void elWrapperToStringCoercionTest() throws Exception { + + boolean pass1, pass2, pass3, pass4, pass5, pass6, pass7, pass8 = false; + + Object result1, result2, result3, result4, result5, result6, result7, + result8; + + Class expectedClass = String.class; + + Boolean boo = false; // result1 + Byte bite = 0; // result2 + Character funny = '1'; // result3 + Short tee = 2; // result4 + Integer i = 3; // result5 + Long rope = 4L; // result6 + Float ter = 5.5f; // result7 + Double down = 6.5d; // result8 + + try { + // Boolean to String + result1 = ExprEval.evaluateValueExpression("${" + boo + "}", null, + expectedClass); + pass1 = (ExprEval.compareClass(result1, expectedClass) + && ExprEval.compareValue(result1, "false")); + + // Byte to String + result2 = ExprEval.evaluateValueExpression("#{" + bite + "}", null, + expectedClass); + pass2 = (ExprEval.compareClass(result2, expectedClass) + && ExprEval.compareValue(result2, "0")); + + // Character to String + result3 = ExprEval.evaluateValueExpression("#{" + funny + "}", null, + expectedClass); + pass3 = (ExprEval.compareClass(result3, expectedClass) + && ExprEval.compareValue(result3, "1")); + + // Short to String + result4 = ExprEval.evaluateValueExpression("#{" + tee + "}", null, + expectedClass); + pass4 = (ExprEval.compareClass(result4, expectedClass) + && ExprEval.compareValue(result4, "2")); + + // Integer to String + result5 = ExprEval.evaluateValueExpression("#{" + i + "}", null, + expectedClass); + pass5 = (ExprEval.compareClass(result5, expectedClass) + && ExprEval.compareValue(result5, "3")); + + // Long to String + result6 = ExprEval.evaluateValueExpression("#{" + rope + "}", null, + expectedClass); + pass6 = (ExprEval.compareClass(result6, expectedClass) + && ExprEval.compareValue(result6, "4")); + + // Float to String + result7 = ExprEval.evaluateValueExpression("#{" + ter + "}", null, + expectedClass); + pass7 = (ExprEval.compareClass(result7, expectedClass) + && ExprEval.compareValue(result7, "5.5")); + + // long to String + result8 = ExprEval.evaluateValueExpression("#{" + down + "}", null, + expectedClass); + pass8 = (ExprEval.compareClass(result8, expectedClass) + && ExprEval.compareValue(result8, "6.5")); + + } catch (RuntimeException re) { + throw new Exception(re); + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass1) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "String Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass2) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "boolean Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass3) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "null Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass4) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "byte Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass5) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "char Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass6) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "short Coerced to String Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass7) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "int Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + if (!pass8) + throw new Exception( + "TEST FAILED: pass = false" + NLINE + "long Coerced to String Failed!" + + NLINE + "See above for expected value." + NLINE); + } + + /** + * @testName: positiveElCharacterCoercionTest + * @assertion_ids: EL:SPEC:40.1; EL:SPEC:40.2; EL:SPEC:40.4; EL:SPEC:40.5 + * @test_Strategy: Validate that the following types coerce to type of + * Character and the expected Character value is returned. + * + * Types: String, Byte, Character, Short, Integer, Long, + * Float, Double, null, empty String. + * + */ + public void positiveElCharacterCoercionTest() throws Exception { + + boolean pass1, pass2, pass3, pass4, pass5, pass6, pass7, pass8, + pass10 = false; + + Object result1, result2, result3, result4, result5, result6, result7, + result8, result10; + + Class expectedClass = Character.class; + + Byte bite = 7; + Character funny = '1'; + Short tee = 2; + Integer i = 3; + Long rope = 4L; + Float ter = 5f; + Double down = 6.5d; + + try { + // String to Character + result1 = ExprEval.evaluateValueExpression("${'STRING'}", null, + expectedClass); + pass1 = (ExprEval.compareClass(result1, expectedClass) + && ExprEval.compareValue(result1, 'S')); + + // Byte to Character + result2 = ExprEval.evaluateValueExpression("${" + bite + "}", null, + expectedClass); + pass2 = (ExprEval.compareClass(result2, expectedClass) + && ExprEval.compareValue(result2, Character.valueOf((char) 7))); + + // Character to Character + result3 = ExprEval.evaluateValueExpression("${" + funny + "}", null, + expectedClass); + pass3 = (ExprEval.compareClass(result3, expectedClass) + && ExprEval.compareValue(result3, Character.valueOf((char) 1))); + + // Short to Character + result4 = ExprEval.evaluateValueExpression("${" + tee + "}", null, + expectedClass); + pass4 = (ExprEval.compareClass(result4, expectedClass) + && ExprEval.compareValue(result4, Character.valueOf((char) 2))); + + // Integer to Character + result5 = ExprEval.evaluateValueExpression("${" + i + "}", null, + expectedClass); + pass5 = (ExprEval.compareClass(result5, expectedClass) + && ExprEval.compareValue(result5, Character.valueOf((char) 3))); + + // Long to Character + result6 = ExprEval.evaluateValueExpression("${" + rope + "}", null, + expectedClass); + pass6 = (ExprEval.compareClass(result6, expectedClass) + && ExprEval.compareValue(result6, Character.valueOf((char) 4))); + + // Float to Character + result7 = ExprEval.evaluateValueExpression("${" + ter + "}", null, + expectedClass); + pass7 = (ExprEval.compareClass(result7, expectedClass) + && ExprEval.compareValue(result7, Character.valueOf((char) 5))); + + // Double to Character + result8 = ExprEval.evaluateValueExpression("${" + down + "}", null, + expectedClass); + pass8 = (ExprEval.compareClass(result8, expectedClass) + && ExprEval.compareValue(result8, Character.valueOf((char) 6))); + + // empty String to Character + result10 = ExprEval.evaluateValueExpression("${''}", null, expectedClass); + pass10 = (ExprEval.compareClass(result10, expectedClass) + && ExprEval.compareValue(result10, Character.valueOf((char) 0))); + + } catch (RuntimeException re) { + throw new Exception(re); + } catch (Exception e) { + TestUtil.printStackTrace(e); + throw new Exception(e); + } + + if (!pass1) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "String Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass2) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Byte Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass3) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Character Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass4) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Short Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass5) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Integer Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass6) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Long Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass7) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Float Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass8) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Double Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + if (!pass10) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Empty String Coerced to Character Failed!" + NLINE + + "See above for expected value." + NLINE); + + } + + /** + * @testName: negativeElCharacterCoercionTest + * @assertion_ids: EL:SPEC:40.3; EL:JAVADOC:112 + * @test_Strategy: Validate that an error occurs when an attempt is made to + * coerce a boolean to Character. The coercion is performed + * with a call to ValueExpression.getValue(), which must throw + * an ELException. + */ + public void negativeElCharacterCoercionTest() throws Exception { + + boolean pass = false; + + try { + ExprEval.evaluateValueExpression("${" + pass + "}", null, + Character.class); + TestUtil.logErr( + "No exception thrown when coercing Boolean " + "to Character!"); + + } catch (ELException ee) { + pass = true; + + } catch (Exception e) { + TestUtil.logErr("Exception thrown, but it was not an ELException"); + TestUtil.printStackTrace(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: negativeElNumberCoercionTest + * @assertion_ids: EL:SPEC:39.3; EL:SPEC:39.6.1.1; EL:SPEC:39.7.3; + * EL:SPEC:39.7.1; EL:SPEC:39.6.1.1; EL:JAVADOC:112 + * @test_Strategy: Validate that an error occurs when an attempt is made to + * coerce a: -Boolean to Number. -String to a Number. The + * coercion is performed with a call to + * ValueExpression.getValue(), which must throw an + * ELException. + */ + public void negativeElNumberCoercionTest() throws Exception { + + boolean pass; + Enumeration keys = numberTable.keys(); + String name; + Class testClass; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + // Coercing Boolean to Number type. + try { + ExprEval.evaluateValueExpression("${" + pass + "}", null, testClass); + TestUtil.logErr("No exception thrown when coercing Boolean " + "to " + + name + "!" + NLINE); + + } catch (ELException ee) { + pass = true; + + } catch (Exception e) { + TestUtil.logErr("Exception thrown, but it was not an ELException"); + TestUtil.printStackTrace(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + // Coercing String to Number type. + try { + ExprEval.evaluateValueExpression("${'A'}", null, testClass); + TestUtil.logErr("No exception thrown when coercing String " + "to " + + name + "!" + NLINE); + + } catch (ELException ee) { + pass = true; + + } catch (Exception e) { + TestUtil.logErr("Exception thrown, but it was not an ELException"); + TestUtil.printStackTrace(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + } + + /** + * @testName: elNullToNumberCoercionTest + * @assertion_ids: EL:SPEC:39.1 + * @test_Strategy: Validate that when null or empty String is given. That the + * returned value is 0. Test this for the Following types. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + */ + public void elNullToNumberCoercionTest() throws Exception { + + boolean pass1; + Object result1; + Enumeration keys = numberTable.keys(); + String name; + Class testClass; + Object expectedValue; + + while (keys.hasMoreElements()) { + pass1 = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + expectedValue = Byte.valueOf((byte) 0); + } else if ("Short".equals(name)) { + expectedValue = Short.valueOf((short) 0); + } else if ("Integer".equals(name)) { + expectedValue = Integer.valueOf(0); + } else if ("Long".equals(name)) { + expectedValue = Long.valueOf(0L); + } else if ("Float".equals(name)) { + expectedValue = Float.valueOf(0f); + } else if ("Double".equals(name)) { + expectedValue = Double.valueOf(0d); + } else if ("BigInteger".equals(name)) { + expectedValue = BigInteger.valueOf(0); + } else if ("BigDecimal".equals(name)) { + expectedValue = BigDecimal.valueOf(0); + } else { + // Default Value, this should never been utilized. + expectedValue = "0"; + } + + try { + // Coercing Empty String to Number type. + result1 = ExprEval.evaluateValueExpression("${''}", null, testClass); + pass1 = (ExprEval.compareClass(result1, testClass) + && ExprEval.compareValue(result1, expectedValue)); + if (!pass1) + throw new Exception("TEST FAILED: pass = false" + NLINE + + "Empty String Coerced to " + name + " Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + } + + /** + * @testName: elNumberToByteCoercionTest + * @assertion_ids: EL:SPEC:39.5.3 + * @test_Strategy: Validate that following Number types coerce to Byte and the + * expected Byte value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToByteCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = Byte.class; + Byte expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = Byte.valueOf(BYTE); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = Byte.valueOf(SHORT); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = Byte.valueOf(INTEGER); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = Byte.valueOf(LONG); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = Byte.valueOf((Float.valueOf(FLOAT)).byteValue()); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = Byte.valueOf((Double.valueOf(DOUBLE)).byteValue()); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = Byte.valueOf(BIGINT); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = Byte.valueOf((Double.valueOf(BIGDEC)).byteValue()); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = Byte.valueOf("1"); + } + + try { + // Coercing Numbers to Byte type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue(result, expectedValue)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to Byte Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elNumberToShortCoercionTest + * @assertion_ids: EL:SPEC:39.5.4 + * @test_Strategy: Validate that following Number types coerce to Short and + * the expected Short value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToShortCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = Short.class; + Short expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = Short.valueOf(BYTE); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = Short.valueOf(SHORT); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = Short.valueOf(INTEGER); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = Short.valueOf(LONG); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = Short.valueOf((Float.valueOf(FLOAT)).shortValue()); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = Short.valueOf((Double.valueOf(DOUBLE)).shortValue()); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = Short.valueOf(BIGINT); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = Short.valueOf((Double.valueOf(BIGDEC)).shortValue()); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = Short.valueOf("1"); + } + + try { + // Coercing Number to Short type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue(result, expectedValue)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to Short Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elNumberToIntegerCoercionTest + * @assertion_ids: EL:SPEC:39.5.5 + * @test_Strategy: Validate that following Number types coerce to Integer and + * the expected Integer value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToIntegerCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = Integer.class; + Integer expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = Integer.valueOf(BYTE); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = Integer.valueOf(SHORT); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = Integer.valueOf(INTEGER); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = Integer.valueOf(LONG); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = Integer.valueOf(Float.valueOf(FLOAT).intValue()); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = Integer.valueOf(Double.valueOf(DOUBLE).intValue()); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = Integer.valueOf(BIGINT); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = Integer.valueOf(Double.valueOf(BIGDEC).intValue()); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = Integer.valueOf("1"); + } + + try { + // Coercing Number to Integer type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue(result, expectedValue)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to Integer Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + } + + /** + * @testName: elNumberToLongCoercionTest + * @assertion_ids: EL:SPEC:39.5.6 + * @test_Strategy: Validate that following Number types coerce to Long and the + * expected Long value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToLongCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = Long.class; + Long expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = Long.valueOf(BYTE); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = Long.valueOf(SHORT); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = Long.valueOf(INTEGER); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = Long.valueOf(LONG); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = Long.valueOf(Float.valueOf(FLOAT).longValue()); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = Long.valueOf(Double.valueOf(DOUBLE).longValue()); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = Long.valueOf(BIGINT); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = Long.valueOf(Double.valueOf(BIGDEC).longValue()); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = Long.valueOf("1"); + } + + try { + // Coercing Number to Long type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue(result, expectedValue)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to Long Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elNumberToFloatCoercionTest + * @assertion_ids: EL:SPEC:39.5.7 + * @test_Strategy: Validate that following Number types coerce to Float and + * the expected Float value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToFloatCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = Float.class; + Float expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = Float.valueOf(BYTE); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = Float.valueOf(SHORT); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = Float.valueOf(INTEGER); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = Float.valueOf(LONG); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = Float.valueOf(FLOAT); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = Float.valueOf(DOUBLE); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = Float.valueOf(BIGINT); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = Float.valueOf(BIGDEC); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = Float.valueOf("1"); + } + + try { + // Coercing Number to Float type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue((Float) result, expectedValue, 2)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to Float Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elNumberToDoubleCoercionTest + * @assertion_ids: EL:SPEC:39.5.8 + * @test_Strategy: Validate that following Number types coerce to Double and + * the expected Double value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToDoubleCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = Double.class; + Double expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = Double.valueOf(BYTE); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = Double.valueOf(SHORT); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = Double.valueOf(INTEGER); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = Double.valueOf(LONG); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = Double.valueOf(FLOAT); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = Double.valueOf(DOUBLE); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = Double.valueOf(BIGINT); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = Double.valueOf(BIGDEC); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = Double.valueOf("1"); + } + + try { + // Coercing Number to Double type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue(result, expectedValue)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to Double Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elStringToNumberCoercionTest + * @assertion_ids: EL:SPEC:39.6.1.2; EL:SPEC:39.7.2; EL:SPEC:39.7.4 + * @test_Strategy: Validate that String types coerce to the following types + * and the expected value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elStringToNumberCoercionTest() throws Exception { + + boolean pass; + Object result, expectedValue; + Enumeration keys = numberTable.keys(); + Class expectedClass; + String name, testValue; + + while (keys.hasMoreElements()) { + pass = false; + expectedClass = (Class) keys.nextElement(); + name = expectedClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = BYTE; + expectedValue = Byte.valueOf(BYTE); + } else if ("Short".equals(name)) { + testValue = SHORT; + expectedValue = Short.valueOf(SHORT); + } else if ("Integer".equals(name)) { + testValue = INTEGER; + expectedValue = Integer.valueOf(INTEGER); + } else if ("Long".equals(name)) { + testValue = LONG; + expectedValue = Long.valueOf(LONG); + } else if ("Float".equals(name)) { + + // remove non-numeric char + testValue = FLOAT.substring(0, FLOAT.length() - 1); + expectedValue = Float.valueOf(FLOAT); + } else if ("Double".equals(name)) { + testValue = DOUBLE.substring(0, DOUBLE.length() - 1); + expectedValue = Double.valueOf(DOUBLE); + } else if ("BigInteger".equals(name)) { + testValue = BIGINT; + expectedValue = BigInteger.valueOf(Long.valueOf(BIGINT)); + } else if ("BigDecimal".equals(name)) { + testValue = BIGDEC; + expectedValue = BigDecimal.valueOf(Double.valueOf(BIGDEC)); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = "1"; + } + + try { + // Coercing String to Number types. + result = ExprEval.evaluateValueExpression("${'" + testValue + "'}", + null, expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue(result, expectedValue)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + "Coerced to " + + name + " Failed!" + NLINE + "See above for expected value." + + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elCharacterToNumberCoercionTest + * @assertion_ids: EL:SPEC:39.2 + * @test_Strategy: Validate that Character types coerce to the following types + * and the expected value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elCharacterToNumberCoercionTest() throws Exception { + + boolean pass; + Object result, expectedValue; + Enumeration keys = numberTable.keys(); + Class expectedClass; + Character testValue; + String name; + + while (keys.hasMoreElements()) { + pass = false; + expectedClass = (Class) keys.nextElement(); + name = expectedClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = '1'; + expectedValue = Byte.valueOf("1"); + } else if ("Short".equals(name)) { + testValue = '2'; + expectedValue = Short.valueOf("2"); + } else if ("Integer".equals(name)) { + testValue = '3'; + expectedValue = Integer.valueOf(3); + } else if ("Long".equals(name)) { + testValue = '4'; + expectedValue = Long.valueOf(4L); + } else if ("Float".equals(name)) { + testValue = '5'; + expectedValue = Float.valueOf(5f); + } else if ("Double".equals(name)) { + testValue = '6'; + expectedValue = Double.valueOf(6d); + } else if ("BigInteger".equals(name)) { + testValue = '7'; + expectedValue = BigInteger.valueOf(7); + } else if ("BigDecimal".equals(name)) { + testValue = '8'; + expectedValue = BigDecimal.valueOf(8); + } else { + // Default Values, this should never been utilized. + testValue = '0'; + expectedValue = '1'; + } + + try { + // Coercing Character to Number types. + result = ExprEval.evaluateValueExpression("${'" + testValue + "'}", + null, expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue(result, expectedValue)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + "Coerced to " + + name + " Failed!" + NLINE + "See above for expected value." + + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elNumberToBigIntegerCoercionTest + * @assertion_ids: EL:SPEC:39.5.1.1; EL:SPEC:39.5.1.2 + * @test_Strategy: Validate that following Number types coerce to BigInteger + * and the expected value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToBigIntegerCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = BigInteger.class; + BigInteger expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = BigInteger.valueOf(Long.valueOf(BYTE)); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = BigInteger.valueOf(Long.valueOf(SHORT)); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = BigInteger.valueOf(Long.valueOf(INTEGER)); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = BigInteger.valueOf(Long.valueOf(LONG)); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = BigInteger.valueOf(Float.valueOf(FLOAT).longValue()); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = BigInteger.valueOf(Double.valueOf(DOUBLE).longValue()); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = BigInteger.valueOf(Long.valueOf(BIGINT)); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(BIGDEC)) + .toBigInteger(); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = BigInteger.valueOf(Long.valueOf("1")); + } + + try { + // Coercing Number to BigInteger type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue((BigInteger) result, expectedValue, 1)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to BigInteger Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elNumberToBigDecimalCoercionTest + * @assertion_ids: EL:SPEC:39.5.2.1; EL:SPEC:39.5.2.2 + * @test_Strategy: Validate that following Number types coerce to BigDecimal + * and the expected value is returned. + * + * Types: Byte, Short, Integer, Long, Float, Double, + * BigDecimal, BigInteger. + * + */ + public void elNumberToBigDecimalCoercionTest() throws Exception { + + boolean pass; + Object result, testValue; + Enumeration keys = numberTable.keys(); + Class expectedClass = BigDecimal.class; + BigDecimal expectedValue; + Class testClass; + String name; + + while (keys.hasMoreElements()) { + pass = false; + testClass = (Class) keys.nextElement(); + name = testClass.getSimpleName(); + + if ("Byte".equals(name)) { + testValue = (Byte) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(BYTE)); + } else if ("Short".equals(name)) { + testValue = (Short) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(SHORT)); + } else if ("Integer".equals(name)) { + testValue = (Integer) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(INTEGER)); + } else if ("Long".equals(name)) { + testValue = (Long) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(LONG)); + } else if ("Float".equals(name)) { + testValue = (Float) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Float.valueOf(FLOAT).doubleValue()); + } else if ("Double".equals(name)) { + testValue = (Double) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(DOUBLE)); + } else if ("BigInteger".equals(name)) { + testValue = (BigInteger) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(BIGINT)); + } else if ("BigDecimal".equals(name)) { + testValue = (BigDecimal) numberTable.get(testClass); + expectedValue = BigDecimal.valueOf(Double.valueOf(BIGDEC)); + } else { + // Default Values, this should never been utilized. + testValue = "0"; + expectedValue = BigDecimal.valueOf(Double.valueOf("1")); + } + + try { + // Coercing Number to BigInteger type. + result = ExprEval.evaluateValueExpression("${" + testValue + "}", null, + expectedClass); + pass = (ExprEval.compareClass(result, expectedClass) + && ExprEval.compareValue((BigDecimal) result, expectedValue, 1)); + if (!pass) + throw new Exception("TEST FAILED: pass = false" + NLINE + name + + " Coerced to BigDecimal Failed!" + NLINE + + "See above for expected value." + NLINE); + + } catch (Exception e) { + throw new Exception(e); + } + } + + } + + /** + * @testName: elCoerceToEnumTypeTest + * @assertion_ids: EL:SPEC:42.1; EL:SPEC:42.2; EL:SPEC:42.3; EL:SPEC:42.4 + * @test_Strategy: Validate that - an assignable enum type can be coerced to + * an enum - coercing a null value to an enum type returns a + * null value - coercing an empty string to an enum type + * returns a null value - coercing a string to an enum is + * successful if the string is identical to one of the enum + * values. If not, an ELException is thrown. + */ + public void elCoerceToEnumTypeTest() throws Exception { + + boolean fail = false; + boolean[] pass = { false, false, false, false, false }; + Object result = null; + + try { + // assignable types + NameValuePair[] earthNV = NameValuePair + .buildUnaryNameValue(planets.EARTH); + result = ExprEval.evaluateValueExpression("${A}", earthNV, planets.class); + pass[0] = ExprEval.compareClass(result, planets.class) + && ExprEval.compareValue(result, planets.EARTH); + + // type is null + result = ExprEval.evaluateValueExpression("${null}", null, planets.class); + pass[1] = (result == null) ? true : false; + + // type is empty string + NameValuePair[] emptyNV = NameValuePair.buildUnaryNameValue(""); + result = ExprEval.evaluateValueExpression("#{A}", emptyNV, planets.class); + pass[2] = (result == null) ? true : false; + + // String value that matches enum identifier + NameValuePair[] marsNV = NameValuePair.buildUnaryNameValue("MARS"); + result = ExprEval.evaluateValueExpression("${A}", marsNV, planets.class); + pass[3] = ExprEval.compareClass(result, planets.class) + && ExprEval.compareValue(result, planets.MARS); + + // String value that does not match + NameValuePair[] plutoNV = NameValuePair.buildUnaryNameValue("PLUTO"); + try { + result = ExprEval.evaluateValueExpression("${A}", plutoNV, + planets.class); + } catch (ELException e) { + pass[4] = true; + } + + } catch (Exception e) { + throw new Exception(e); + } finally { + ExprEval.cleanup(); + } + + for (int i = 0; i < pass.length; ++i) { + if (!pass[i]) { + fail = true; + TestUtil.logErr("Unexpected result for test case " + i); + } + } + + if (fail) + throw new Exception("TEST FAILED"); + } + + /** + * @testName: elCoerceToArrayTest + * @assertion_ids: EL:SPEC:81.1; EL:SPEC:81.2; EL:SPEC:81.3; EL:SPEC:81.4; + * EL:SPEC:81.5 + * @test_Strategy: Validate that - coercing a null to an array returns a null + * value, coercing an array of type T returns an array of type + * T, coercing an array coerces each member of the array to + * the expected type, coercing an array where at least one + * element cannot be coerced results in an ELException. If + * not, an ELException is thrown. + */ + public void elCoerceToArrayTest() throws Exception { + + boolean fail = false; + boolean[] pass = { false, false, false, false, false }; + Object result = null; + + try { + // If A is null, return null + ELProcessor elp0 = new ELProcessor(); + elp0.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClient", "testPrimitiveBooleanArray"); + result = elp0.eval("testPrimitiveBooleanArray(null)"); + pass[0] = ExprEval.compareClass(result, Integer.class) + && ExprEval.compareValue(result, Integer.valueOf(-1)); + + // If A is an array of T, coerce quietly + ELProcessor elp1 = new ELProcessor(); + elp1.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClient", "testPrimitiveBooleanArray"); + result = elp1.eval("testPrimitiveBooleanArray([true, false].toArray())"); + pass[1] = ExprEval.compareClass(result, Integer.class) + && ExprEval.compareValue(result, Integer.valueOf(2)); + + // If A is an array of other types, coerce each element + ELProcessor elp2 = new ELProcessor(); + elp2.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClient", "testPrimitiveBooleanArray"); + result = elp2.eval("testPrimitiveBooleanArray([\"true\", false, true, 'false', null, \"\"].toArray())"); + pass[2] = ExprEval.compareClass(result, Integer.class) + && ExprEval.compareValue(result, Integer.valueOf(6)); + + // If A is an array of other types, where at least one cannot be coerced + ELProcessor elp3 = new ELProcessor(); + elp3.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClient", "testPrimitiveBooleanArray"); + try { + result = elp3.eval("testPrimitiveBooleanArray(['true', 'false', 1234].toArray())"); + } catch (ELException e) { + pass[3] = true; + } + + // If A is not an array, error + ELProcessor elp4 = new ELProcessor(); + elp4.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClient", "testPrimitiveBooleanArray"); + try { + result = elp4.eval("testPrimitiveBooleanArray([true, false, true, false, true])"); + } catch (ELException e) { + pass[4] = true; + } + + } catch (Exception e) { + TestUtil.logErr("Testing coercion to arrays " + + "threw an Exception!" + TestUtil.NEW_LINE + "Received: " + e.toString() + TestUtil.NEW_LINE); + + throw new Exception(e); + } finally { + ExprEval.cleanup(); + } + + for (int i = 0; i < pass.length; ++i) { + if (!pass[i]) { + fail = true; + TestUtil.logErr("Unexpected result for test case " + i); + } + } + + if (fail) + throw new Exception("TEST FAILED"); + } + + + public static int testPrimitiveBooleanArray(boolean input[]) { + if (input == null) { + return -1; + } + + return input.length; + } + + + /** + * @testName: elCoerceLambdaExpressionToFunctionalInterfaceTest + * @assertion_ids: EL:SPEC:79.1; EL:SPEC:79.2; EL:SPEC:79.3 + * @test_Strategy: Validate that - a lambda expression can be coerced to a + * functional interface invocation if the parameter types + * match or can be made to match via the standard coercion + * rules. + */ + public void elCoerceLambdaExpressionToFunctionalInterfaceTest() throws Exception { + + boolean fail = false; + boolean[] pass = { false, false, false, false, false, false }; + Object result = null; + + try { + // Coercible lambda expression where filter matches + ELProcessor elp0 = new ELProcessor(); + elp0.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateString"); + result = elp0.eval("testPredicateString(x -> x.equals('data'))"); + pass[0] = ExprEval.compareClass(result, String.class) && ExprEval.compareValue(result, "PASS"); + + // Coercible lambda expression where filter does not match + ELProcessor elp1 = new ELProcessor(); + elp1.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateString"); + result = elp1.eval("testPredicateString(x -> x.equals('other'))"); + pass[1] = ExprEval.compareClass(result, String.class) && ExprEval.compareValue(result, "BLOCK"); + + // Not a lambda expression + ELProcessor elp2 = new ELProcessor(); + elp2.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateString"); + try { + result = elp2.eval("testPredicateString('notLambdaExpression')"); + } catch (ELException e) { + pass[2] = true; + } + + /* + * Note: The following tests use compareTo(). When the target object (Long or String) is examined by reflection + * both compareTo(Object) and compareTo(Long)/compareTo(String) methods will be found as potential matches. The + * method matching rules (see section 1.2.1.2 of the specification) require that overload resolution has a higher + * precedence than coercion resolution so it is always the compareTo(Object) method that will be used for the + * following tests resulting in a ClassCastException (which is wrapped in an ELException). + */ + + // Coercible lambda expression with wrong type + ELProcessor elp3 = new ELProcessor(); + elp3.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateLong"); + try { + result = elp3.eval("testPredicateLong(x -> x.compareTo('data') == 0)"); + } catch (ELException e) { + // String 'data' cannot be cast to Long + pass[3] = true; + } + + // Coercible lambda expression where filter does not match and parameter needs to be coerced + ELProcessor elp4 = new ELProcessor(); + elp4.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateString"); + try { + result = elp4.eval("testPredicateString(x -> x.compareTo(1234) == 0)"); + } catch (ELException e) { + // Long 1234 cannot be cast to String. It is coercible but that should not used here. + pass[4] = true; + } + + // Coercible lambda expression with coercible type but coercion rules mean this test fails + ELProcessor elp5 = new ELProcessor(); + elp5.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateLong"); + try { + result = elp5.eval("testPredicateLong(x -> x.compareTo('1234') == 0)"); + } catch (ELException e) { + // String '1234' cannot be cast to String. It is coercible but that should not used here. + pass[5] = true; + } + } catch (Exception e) { + TestUtil.logErr("Testing coercion of lambda expressions to functional interfaces " + + "threw an Exception!" + TestUtil.NEW_LINE + "Received: " + e.toString() + TestUtil.NEW_LINE); + + throw new Exception(e); + } finally { + ExprEval.cleanup(); + } + + for (int i = 0; i < pass.length; ++i) { + if (!pass[i]) { + fail = true; + TestUtil.logErr("Unexpected result for test case " + i); + } + } + + if (fail) + throw new Exception("TEST FAILED"); + } + + + public static String testPredicateString(Predicate filter) { + String s = "data"; + if (filter.test(s)) { + return "PASS"; + } else { + return "BLOCK"; + } + } + + public static String testPredicateLong(Predicate filter) { + Long l = Long.valueOf("1234"); + if (filter.test(l)) { + return "PASS"; + } else { + return "BLOCK"; + } + } + + /** + * @testName: elCoerceToOtherTypeTest + * @assertion_ids: EL:SPEC:43.1; EL:SPEC:43.2 + * @test_Strategy: Validate that - an assignable "other" type can be coerced + * to an "other" type. We coerce an instance of the class + * java.sql.Time to its parent class java.util.Date. - + * coercing a null value to an "other" type returns a null + * value + * + */ + public void elCoerceToOtherTypeTest() throws Exception { + + Time time = new Time(1000000000000L); + boolean pass1, pass2 = false; + + try { + NameValuePair[] timeNV = NameValuePair.buildUnaryNameValue(time); + Object result = ExprEval.evaluateValueExpression("${A}", timeNV, + Date.class); + pass1 = ExprEval.compareClass(result, Date.class) + && ExprEval.compareValue(result, (Date) time); + + result = ExprEval.evaluateValueExpression("#{null}", null, Date.class); + pass2 = (result == null) ? true : false; + + } catch (Exception e) { + throw new Exception(e); + } finally { + ExprEval.cleanup(); + } + + if (!pass1 || !pass2) + throw new Exception("TEST FAILED"); + + } + + // ------------------------------------------------- private methods + + /** + * The HashTable is of this format. + * + * Key = Test Class Value = Test Value + */ + private void initializeNumberTable() { + numberTable = new Hashtable(); + + numberTable.put(Byte.class, Byte.valueOf(BYTE)); + numberTable.put(Short.class, Short.valueOf(SHORT)); + numberTable.put(Integer.class, Integer.valueOf(INTEGER)); + numberTable.put(Long.class, Long.valueOf(LONG)); + numberTable.put(Float.class, Float.valueOf(FLOAT)); + numberTable.put(Double.class, Double.valueOf(DOUBLE)); + numberTable.put(BigInteger.class, BigInteger.valueOf(Long.valueOf(BIGINT))); + numberTable.put(BigDecimal.class, + BigDecimal.valueOf(Double.valueOf(BIGDEC))); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/coercion/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/coercion/build.xml new file mode 100644 index 0000000000..d6e7579e48 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/coercion/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClient.java new file mode 100644 index 0000000000..8296efa073 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/ELClient.java @@ -0,0 +1,744 @@ +/* + * Copyright (c) 2013, 2021 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.collectionoperators; + +import java.lang.reflect.Array; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.harness.EETest.Fault; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.DataBase; +import com.sun.ts.tests.el.common.util.ELTestUtil; + +import jakarta.el.ELProcessor; + +public class ELClient extends ServiceEETest { + + private ELProcessor elp; + + private DataBase database; + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elCollectionMapFilterTest + * + * @assertion_ids: EL:SPEC:53; EL:SPEC:53.1; EL:SPEC:53.2; EL:SPEC:53.3; + * EL:SPEC:59; EL:SPEC:59.1; EL:SPEC:58.1; EL:SPEC:58.2 + * + * @test_Strategy: Test to make sure the 'map'& "filter' operator works + * properly. + * + * @since: 3.0 + * + */ + public void elCollectionMapFilterTest() throws Exception { + buildELContext(); + + String[] expr1 = { "[Toy Story, 10.0]", "[History of Golf, 11.0]" }; + + String[] expr2 = { "20", "30", "40" }; + + testIterable("map-filter-one", + "products.stream().filter(p->p.unitPrice >= 10 && " + + "p.unitPrice < 12).sorted(" + + "(p,q)->p.unitPrice-q.unitPrice).map(" + + "p->[p.name,p.unitPrice]).toList()", + expr1); + + testIterable("map-filter-two", + "[1,2,3,4].stream().filter(i->i > 1).map(i->i*10).toList()", expr2); + + } // End elCollectionMapFilterTest + + /** + * @testName: elCollectionMinTest + * + * @assertion_ids: EL:SPEC:72; EL:SPEC:72.1; EL:SPEC:72.2 + * + * @test_Strategy: Test to make sure the 'min' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionMinTest() throws Exception { + buildELContext(); + + testStream("min", "[2,3,1,5].stream().min().get()", Long.valueOf(1)); + elp.eval("comparing = map->(x,y)->map(x).compareTo(map(y))"); + testStream("min", "[3,2,1].stream().min((i,j)->i-j).get()", + Long.valueOf(1)); + testStream("min", + "customers.stream().min((x,y)->x.orders.size()-y.orders.size()).get().name", + "Charlie Yeh"); + elp.eval("comparing = map->(x,y)->map(x).compareTo(map(y))"); + testStream("min", + "customers.stream().min(comparing(c->c.orders.size())).get().name", + "Charlie Yeh"); + + } // End elCollectionMinTest() + + /** + * @testName: elCollectionMaxTest + * + * @assertion_ids: EL:SPEC:71; EL:SPEC:71.1; EL:SPEC:71.2 + * + * @test_Strategy: Test to make sure the 'max' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionMaxTest() throws Exception { + buildELContext(); + + testStream("max", "[2,3,1,5].stream().max().get()", Long.valueOf(5)); + testStream("max", "['xy', 'xyz', 'abc'].stream().max().get()", "xyz"); + testStream("max", "[2].stream().max((i,j)->i-j).get()", Long.valueOf(2)); + elp.eval("comparing = map->(x,y)->map(x).compareTo(map(y))"); + testStream("max", + "customers.stream().max((x,y)->x.orders.size()-y.orders.size()).get().name", + "John Doe"); + testStream("max", + "customers.stream().max(comparing(c->c.orders.size())).get().name", + "John Doe"); + + } // End elCollectionMaxTest() + + /** + * @testName: elCollectionDistinctTest + * + * @assertion_ids: EL:SPEC:61; EL:SPEC:61.1 + * + * @test_Strategy: Test to make sure the 'distinct' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionDistinctTest() throws Exception { + buildELContext(); + + this.testIterable("distinct", + " ['a', 'b', 'b', 'c'].stream().distinct().toList()", + new String[] { "a", "b", "c" }); + + } // End elCollectionDistinctTest() + + /** + * @testName: elCollectionForEachTest + * + * @assertion_ids: EL:SPEC:63; EL:SPEC:63.1 + * + * @test_Strategy: Test to make sure the 'forEach' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionForEachTest() throws Exception { + buildELContext(); + + String expr1[] = { "Eagle", "Coming Home", "Greatest Hits", + "History of Golf", "Toy Story", "iSee" }; + + testIterable("forEach", + "lst = []; products.stream().forEach(p->lst.add(p.name)); lst", expr1); + + } // End elCollectionForEachTest() + + /** + * @testName: elCollectionFindFirstTest + * + * @assertion_ids: EL:SPEC:78; EL:SPEC:78.1; EL:SPEC:62; EL:SPEC:62.1; + * EL:SPEC:62.2 + * + * @test_Strategy: Test to make sure the 'findFirst' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionFindFirstTest() throws Exception { + buildELContext(); + + String[] expr1 = { "Product: 200, Eagle, book, 12.5, 100" }; + + testIterable("findFirst", + "products.stream().sorted(p->p.unitPrice).findFirst().get()", expr1); + + } // End elCollectionFindFirstTest() + + /** + * @testName: elCollectionLimitTest + * + * @assertion_ids: EL:SPEC:66; EL:SPEC:66.1 + * + * @test_Strategy: Test to make sure the 'limit' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionLimitTest() throws Exception { + buildELContext(); + + String[] expr1 = { "[Product: 202, Greatest Hits, cd, 6.5, 200]" }; + + String[] expr2 = { "Product: 202, Greatest Hits, cd, 6.5, 200", + "Product: 201, Coming Home, dvd, 8.0, 50", }; + + testIterable("limit", + "products.stream().sorted((p,q)->p.unitPrice-q.unitPrice)." + + "limit(1).toList()", + expr1); + + testIterable("limit", + "products.stream().sorted((p,q)->p.unitPrice-q.unitPrice)." + + "limit(2).toList()", + expr2); + + } // End elCollectionLimitTest() + + /** + * testName: elCollectionAnyMatchTest + * + * @assertion_ids: EL:SPEC:75; EL:SPEC:75.1 + * + * @test_Strategy: Test to make sure the 'anyMatch' operator works properly. + * + * @since: 3.0 + * + * Bug 20438221 : Commented the test for now + */ + public void elCollectionAnyMatchTest() throws Exception { + buildELContext(); + + testIterable("anyMatch_True", + "products.stream().anyMatch(p->p.unitPrice >= 10)", true); + + testIterable("anyMatch_False", + "products.stream().anyMatch(p->p.unitPrice == 100)", false); + + } // End elCollectionAnyMatchTest() + + /** + * testName: elCollectionNoneMatchTest + * + * @assertion_ids: EL:SPEC:77; EL:SPEC:77.1 + * + * @test_Strategy: Test to make sure the 'noneMatch' operator works properly. + * + * @since: 3.0 + * + * Bug 20438221 : Commented the test for now + */ + public void elCollectionNoneMatchTest() throws Exception { + buildELContext(); + + testIterable("noneMatch_False", + "products.stream().noneMatch(p->p.unitPrice >= 10)", false); + + testIterable("noneMatch_True", + "products.stream().noneMatch(p->p.unitPrice == 100)", true); + + } // End elCollectionNoneMatchTest() + + /** + * testName: elCollectionAllMatchTest + * + * @assertion_ids: EL:SPEC:76; EL:SPEC:76.1 + * + * @test_Strategy: Test to make sure the 'allMatch' operator works properly. + * + * @since: 3.0 + * + * Bug 20438221 : Commented the test for now. + */ + public void elCollectionAllMatchTest() throws Exception { + buildELContext(); + + testIterable("allMatch_true", + "products.stream().allMatch(p->p.unitPrice >= 1)", true); + + testIterable("allMatch_false", + "products.stream().allMatch(p->p.unitPrice == 100)", false); + + } // End elCollectionAllMatchTest() + + /** + * @testName: elCollectionSumTest + * + * @assertion_ids: EL:SPEC:74; EL:SPEC:74.1 + * + * @test_Strategy: Test to make sure the 'sum' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionSumTest() throws Exception { + buildELContext(); + + testIterable("sum", "['10', '12', '13'].stream().sum()", + new String[] { "35" }); + + testIterable("sum_Empty", "[].stream().sum()", new String[] { "0" }); + + } // End elCollectionSumTest() + + /** + * @testName: elCollectionCountTest + * + * @assertion_ids: EL:SPEC:79; EL:SPEC:79.1 + * + * @test_Strategy: Test to make sure the 'count' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionCountTest() throws Exception { + buildELContext(); + + testIterable("count", "[1,2,3,4,5].stream().count()", new String[] { "5" }); + + } // End elCollectionCountTest() + + /** + * @testName: elCollectionAverageTest + * + * @assertion_ids: EL:SPEC:73; EL:SPEC:73.1 + * + * @test_Strategy: Test to make sure the 'average' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionAverageTest() throws Exception { + + buildELContext(); + + this.testStream("average_ints", "ints.stream().average().get()", + Double.valueOf(4.5)); + + } // End elCollectionAverageTest() + + /** + * @testName: elCollectionToArrayTest + * + * @assertion_ids: EL:SPEC:68; EL:SPEC:68.1 + * + * @test_Strategy: Test to make sure the 'toArray' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionToArrayTest() throws Exception { + buildELContext(); + + String[] expr1 = { "Product: 200, Eagle, book, 12.5, 100", + "Product: 205, iSee, book, 12.5, 150", + "Product: 203, History of Golf, book, 11.0, 30", + "Product: 202, Greatest Hits, cd, 6.5, 200", + "Product: 204, Toy Story, dvd, 10.0, 1000", + "Product: 201, Coming Home, dvd, 8.0, 50" }; + + this.testArray("toArray", + "products.stream().sorted(p->p.unitPrice).toArray()", expr1); + + }// End elCollectionToArrayTest() + + /** + * @testName: elCollectionReduceTest + * + * @assertion_ids: EL:SPEC:70; EL:SPEC:70.1; EL:SPEC:70.2; EL:SPEC:56.2; + * EL:SPEC:56.3 + * + * @test_Strategy: Test to make sure the 'reduce' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionReduceTest() throws Exception { + buildELContext(); + + testStream("reduce-one", "[1,2,3,4,5].stream().reduce(0, (l,r)->l+r)", + Long.valueOf(15)); + testStream("reduce-two", "[1,2,3,4,5].stream().reduce((l,r)->l+r).get()", + Long.valueOf(15)); + testStream("reduce-three", "[].stream().reduce((l,r)->l+r).orElse(101)", + Long.valueOf(101)); + testStream("reduce-four", + "[].stream().reduce((l,r)->l+r).orElseGet(()->101)", Long.valueOf(101)); + testStream("reduce-five", + "c = 0; [1,2,3,4,5,6].stream().reduce(0, (l,r)->(c = c+1; " + + "c % 2 == 0? l+r: l-r))", + Long.valueOf(3)); + + }// End elCollectionReduceTest() + + /** + * @testName: elCollectionSubStreamTest + * + * @assertion_ids: EL:SPEC:67; EL:SPEC:67.1; EL:SPEC:67.2 + * + * @test_Strategy: Test to make sure the 'substream' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionSubStreamTest() throws Exception { + buildELContext(); + + String[] expr1 = { "2", "3", "4" }; + + testIterable("substream-one", "[0,1,2,3,4].stream().substream(2).toList()", + expr1); + testIterable("substream-two", + "[0,1,2,3,4,5,6].stream().substream(2,5).toList()", expr1); + + }// End elCollectionSubStreamTest() + + /** + * @testName: elCollectionPeekTest + * + * @assertion_ids: EL:SPEC:4; EL:SPEC:64.1 + * + * @test_Strategy: Test to make sure the 'peek' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionPeekTest() throws Exception { + buildELContext(); + + String expr1[] = { "1", "2", "3", "4" }; + + testIterable("peek-one", + "lst = []; [1,2,3,4].stream().peek(i->lst.add(i)).toList()", expr1); + testIterable("peek-two", "lst.stream().toList()", expr1); + + }// End elCollectionPeekTest() + + /** + * @testName: elCollectionFlatMapTest + * + * @assertion_ids: EL:SPEC:60; EL:SPEC:60.1 + * + * @test_Strategy: Test to make sure the 'flatMap' operator works properly. + * + * @since: 3.0 + * + */ + public void elCollectionFlatMapTest() throws Exception { + buildELContext(); + + String[] expr1 = { "Order: 10, 100, 2/18/2010, 20.8", + "Order: 11, 100, 5/3/2011, 34.5", "Order: 12, 100, 8/2/2011, 210.75", + "Order: 13, 101, 1/15/2011, 50.23", + "Order: 14, 101, 1/3/2012, 126.77" }; + + testIterable("flatMap", + "customers.stream().filter(c->c.country=='USA').flatMap(" + + "c->c.orders.stream()).toList()", + expr1); + + }// End elCollectionFlatMapTest() + + + /** + * @testName: elCollectionSetLiteralTest + * @assertion_ids: EL:SPEC:51; EL:SPEC:51.1; EL:SPEC:51.2; EL:SPEC:51.3; + * @test+Strategy: Verify that a value in a literal List constructed from + * variables can be retrieved using the associated index. + */ + public void elCollectionSetLiteralTest() throws Exception { + boolean pass = false; + + try { + ELProcessor elp = new ELProcessor(); + + String valueA = "myValueA"; + String valueB = "myValueB"; + + elp.setVariable("aaa", "'" + valueA + "'"); + elp.setVariable("bbb", "'" + valueB + "'"); + + Boolean result = (Boolean) elp.eval("{aaa,bbb}.contains(aaa)"); + + pass = result.booleanValue(); + } catch (Exception e) { + pass = false; + TestUtil.logErr("Construction and use of a valid Set literal threw an Exception!" + + TestUtil.NEW_LINE + "Received: " + e.toString() + TestUtil.NEW_LINE); + + e.printStackTrace(); + } + + if (!pass) { + throw new Exception("TEST FAILED!"); + } + } + + + /** + * @testName: elCollectionListLiteralTest + * @assertion_ids: EL:SPEC:52; EL:SPEC:52.1; EL:SPEC:52.2; EL:SPEC:52.3; + * @test+Strategy: Verify that a value in a literal List constructed from + * variables can be retrieved using the associated index. + */ + public void elCollectionListLiteralTest() throws Exception { + boolean pass = false; + + try { + ELProcessor elp = new ELProcessor(); + + String valueA = "myValueA"; + String valueB = "myValueB"; + + elp.setVariable("aaa", "'" + valueA + "'"); + elp.setVariable("bbb", "'" + valueB + "'"); + + Object result = elp.eval("[aaa,bbb].get(1)"); + + pass = valueB.equals(result); + } catch (Exception e) { + pass = false; + TestUtil.logErr("Construction and use of a valid List literal threw an Exception!" + + TestUtil.NEW_LINE + "Received: " + e.toString() + TestUtil.NEW_LINE); + + e.printStackTrace(); + } + + if (!pass) { + throw new Exception("TEST FAILED!"); + } + } + + + /** + * @testName: elCollectionMapLiteralTest + * @assertion_ids: EL:SPEC:53; EL:SPEC:53.1; EL:SPEC:53.2; EL:SPEC:53.3; + * @test+Strategy: Verify that a value in a literal Map constructed from + * variables can be retrieved using the associated key. + */ + public void elCollectionMapLiteralTest() throws Exception { + boolean pass = false; + + try { + ELProcessor elp = new ELProcessor(); + + String key = "myKey"; + String value = "myValue"; + + elp.setVariable("aaa", "'" + key + "'"); + elp.setVariable("bbb", "'" + value + "'"); + + Object result = elp.eval("{aaa:bbb}.get(aaa)"); + + pass = value.equals(result); + } catch (Exception e) { + pass = false; + TestUtil.logErr("Construction and use of a valid Map literal threw an Exception!" + + TestUtil.NEW_LINE + "Received: " + e.toString() + TestUtil.NEW_LINE); + + e.printStackTrace(); + } + + if (!pass) { + throw new Exception("TEST FAILED!"); + } + } + + + // --------------------------- private methods + + private void logLine(String s) { + TestUtil.logMsg(s); + } + + private void buildELContext() { + elp = new ELProcessor(); + database = new DataBase(); + + database.init(); + elp.defineBean("customers", database.getCustomers()); + elp.defineBean("products", database.getProducts()); + elp.defineBean("orders", database.getOrders()); + elp.defineBean("ints", database.getInts()); + } + + /** + * Test a Collection query that returns an Iterable. + * + * @param name + * The Name of the test + * @param query + * The EL query string + * @param expected + * The expected result of the Iterable. The array element should + * equal the Iterable element, when enumerated. + */ + private void testIterable(String name, String query, String[] expected) + throws Exception { + String result; + String golden; + int explength = 0; + + if (expected != null) { + explength = expected.length; + } + + logLine("=== Testing " + name + " ==="); + logLine(query); + Object ret = elp.eval(query); + int indx = 0; + logLine(" = returns ="); + + if (expected == null) { + + if (!(ret == null)) { + throw new Exception("TEST FAILED, Unexpected Value!" + ELTestUtil.NL + + "Expected: null"); + + } else { + logLine(" null "); + } + + } else if (expected.length == 1) { + golden = expected[0]; + result = ret.toString(); + logLine(" " + result); + + if (!golden.equals(result)) { + throw new Exception("TEST FAILED, Unexpected Value!" + ELTestUtil.NL + + "Expected: " + golden + ELTestUtil.NL + "Received: " + result); + } + + } else { + for (Object item : (Iterable) ret) { + result = item.toString(); + golden = expected[indx++]; + logLine(" " + result); + + if (!golden.equals(result)) { + throw new Exception("TEST FAILED, Unexpected Value!" + ELTestUtil.NL + + "Expected: " + golden + ELTestUtil.NL + "Received: " + result); + } + } + + if (indx != explength) { + throw new Exception(ELTestUtil.FAIL + " lenght incorrect!" + ELTestUtil.NL + + "Expected: " + explength + ELTestUtil.NL + "Found: " + indx); + } + } + } + + /** + * + * @param name + * The Name of the test. + * + * @param query + * The EL query string + * @param expected + * The expected boolean value for the given query. + * + * @throws Exception + */ + private void testIterable(String name, String query, Boolean expected) + throws Exception { + + this.testIterable(name, query, new String[] { expected.toString() }); + } + + /** + * Test a Collection query that returns a Array + * + * @param name + * The Name of the test + * @param query + * The EL query string + * @param expected + * The expected result of the Array. The element of the expected + * array should equals the resulted array. + */ + private void testArray(String name, String query, String[] expected) + throws Exception { + logLine("=== Test " + name + "==="); + logLine(query); + + Object arry = elp.eval(query); + String item; + String golden; + + int gldLength = Array.getLength(arry); + logLine(" = returns ="); + + if (gldLength != expected.length) { + throw new Exception( + ELTestUtil.FAIL + " lenght incorrect!" + ELTestUtil.NL + "Expected: " + + expected.length + ELTestUtil.NL + "Found: " + gldLength); + } + + for (int indx = 0; gldLength < indx; indx++) { + item = (String) Array.get(arry, indx); + golden = expected[indx]; + + if (item.equals(golden)) { + logLine(" " + item); + + } else { + throw new Exception(ELTestUtil.FAIL + ELTestUtil.NL + "Expected: " + item + + ELTestUtil.NL + "Received: " + golden); + } + } + + } + + private void testStream(String name, String query, Object exp_value) + throws Exception { + + logLine("=== Testing " + name + " ==="); + + Object result = elp.eval(query); + logLine("EL Quuery String: '" + query + "' -returns: " + result + "(" + + result.getClass() + ")"); + + // Test expected value. + if (!exp_value.equals(result)) { + throw new Exception(ELTestUtil.FAIL + ELTestUtil.NL + "Expected: " + exp_value + + ELTestUtil.NL + "Received: " + result); + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/build.xml new file mode 100644 index 0000000000..7d7ca01c84 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/collectionoperators/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClient.java new file mode 100644 index 0000000000..165918a7b3 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/ELClient.java @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.concatoperator; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Iterator; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ELTestUtil; +import com.sun.ts.tests.el.common.util.TestNum; +import com.sun.ts.tests.el.common.util.Validator; + +import jakarta.el.ELProcessor; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elBigDecimalConcatenationTest + * + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * + * @test_Strategy: Validate that if one of the operands is BigDecimal that the + * operator is '+=' that both operands are coerced to type + * String and concatenated. + * + * Equations tested: BigDecimal += BigDecimal BigDecimal += + * Double BigDecimal += Float BigDecimal += String + * containing".", "e", or "E" BigDecimal += BigInteger + * BigDecimal += Integer BigDecimal += Long BigDecimal += + * Short BigDecimal += Byte + */ + public void elBigDecimalConcatenationTest() throws Exception { + + BigDecimal testValue = BigDecimal.valueOf(10.531); + /* + * The expected result is actually computed in the testBigDecimal method for + * the '+=' operator! + */ + Validator.testBigDecimal(testValue, null, "+="); + + } + + /** + * @testName: elBigIntegerConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate that if one of the operands is BigInteger that the + * operator is '+=' that both operands are coerced to type + * String and concatenated. + * + * Equations tested: BigInteger += BigInteger BigInteger += + * Integer BigInteger += Long BigInteger += Short BigInteger + * += Byte + */ + public void elBigIntegerConcatenationTest() throws Exception { + + BigInteger testValue = BigInteger.valueOf(10531); + /* + * The expected result is actually computed in the testBigInteger method for + * the '+=' operator! + */ + Validator.testBigInteger(testValue, null, "+="); + + } + + /** + * @testName: elFloatConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate when the operator is '+=' that the operands are + * coerced to Strings and the result is a Concatenation. + * + * Equations tested: Float + Double Float + Float Float + + * String containing ".", "e", or "E" Float + BigInteger Float + * + Integer Float + Long Float + Short Float + Byte + */ + public void elFloatConcatenationTest() throws Exception { + + // For each float in this List. + for (Iterator it = TestNum.getFloatList().iterator(); it.hasNext();) { + Float testValue = (Float) it.next(); + /* + * The expected result is actually computed in the testFloat method for + * the '+=' operator! + */ + Validator.testFloat(testValue, null, "+="); + } + + } + + /** + * @testName: elDoubleConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate when the operator is '+=' that the operands are + * coerced to Strings and the result is a Concatenation. + * + * Equations tested: Double += Double Double += String + * containing ".", "e", or "E" Double += BigInteger Double += + * Integer Double += Long Double += Short Double += Byte + */ + public void elDoubleConcatenationTest() throws Exception { + + Double testValue = Double.valueOf(2.5); + /* + * The expected result is actually computed in the testDouble method for the + * '+=' operator! + */ + Validator.testDouble(testValue, null, "+="); + + } + + /** + * @testName: elLongConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate when the operator is '+=' that the operands are + * coerced to Strings and the result is a Concatenation. + * + * Equations tested: Long += Integer Long += Long Long += + * Short Long += Byte + */ + public void elLongConcatenationTest() throws Exception { + + Long testValue = Long.valueOf(25000); + /* + * The expected result is actually computed in the testLong method for the + * '+=' operator! + */ + Validator.testLong(testValue, null, "+="); + + } + + /** + * @testName: elIntegerConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate when the operator is '+=' that the operands are + * coerced to Strings and the result is a Concatenation. + * + * Equations tested: Integer += Integer Integer += Short + * Integer += Byte + */ + public void elIntegerConcatenationTest() throws Exception { + + Integer testValue = Integer.valueOf(25); + /* + * The expected result is actually computed in the testInteger method for + * the '+=' operator! + */ + Validator.testInteger(testValue, null, "+="); + + } + + /** + * @testName: elShortConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate when the operator is '+=' that the operands are + * coerced to Strings and the result is a Concatenation. + * + * Equations tested: Short += Short Short += Byte + */ + public void elShortConcatenationTest() throws Exception { + + Short testValue = Short.valueOf("2"); + /* + * The expected result is actually computed in the testShort method for the + * '+=' operator! + */ + Validator.testShort(testValue, null, "+="); + + } + + /** + * @testName: elByteConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate that if the operator is '+=' that both operands + * are coerced to String and the result is a Concatenation of + * the operands. + * + * Equations tested: Byte += Byte + */ + public void elByteConcatenationTest() throws Exception { + + Byte testValue = Byte.valueOf("2"); + /* + * The expected result is actually computed in the testByte method for the + * '+=' operator! + */ + Validator.testByte(testValue, null, "+="); + + } + + /** + * @testName: elBooleanConcatenationTest + * @assertion_ids: EL:SPEC:38; EL:SPEC:47.1; EL:SPEC:47.1.1; EL:SPEC:47.1.2 + * @test_Strategy: Validate when the operator is '+=' that both operands are + * coerced to Strings and that they result is a Concatenation + * of the operands. + * + * Equations tested: Boolean += String Boolean += Boolean + * + */ + public void elBooleanConcatenationTest() throws Exception { + + /* + * The expected result is actually computed in the testBoolean method for + * the '+=' operator! + */ + Validator.testBoolean(false, "true", null, "+="); + Validator.testBoolean(false, true, null, "+="); + + } + + // ------------------------------------------------------- private methods + private void logLine(String s) { + TestUtil.logTrace(s); + } + + /** + * Test a query for the correct value. + * + * @param name + * The Name of the test + * @param query + * The EL query string + * @param expected + * The expected result of the query. + */ + private void testQuery(String name, String query, String expected) + throws Exception { + ELProcessor elp = new ELProcessor(); + + logLine("=== Testing " + name + " ==="); + logLine(query); + + logLine(" = returns ="); + Object ret = elp.eval(query); + + if (!expected.equals(ret.toString())) { + + throw new Exception( + ELTestUtil.FAIL + " Unexpected Value!" + ELTestUtil.NL + "Expected: " + + expected + ELTestUtil.NL + "Received: " + ret.toString()); + + } + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/build.xml new file mode 100644 index 0000000000..6302e1223b --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/concatoperator/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClient.java new file mode 100644 index 0000000000..4041966cf6 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/ELClient.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.conditionaloperator; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; +import com.sun.ts.tests.el.common.util.NameValuePair; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + private final boolean[] deferred = { true, false }; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + /* + * @testName: elConditionalStringTest + * + * @assertion_ids: EL:SPEC:26.1.1; EL:SPEC:26.1.2 + * + * @test_Strategy: Validate that if a String is passed with the conditional + * operator, the type is coerced to Boolean and the operator is applied. + * + * Example Equation: ${true ? true : false} + */ + public void elConditionalStringTest() throws Exception { + + this.testConditionals("true", true); + this.testConditionals("false", false); + + } + + /* + * @testName: elConditionalBooleanTest + * + * @assertion_ids: EL:SPEC:26.1.1; EL:SPEC:26.1.2 + * + * @test_Strategy: Validate that if a Boolean is passed with the conditional + * operator, that the operator is applied. + * + * Example Equation: ${true ? true : false} + */ + public void elConditionalBooleanTest() throws Exception { + + this.testConditionals(true, true); + this.testConditionals(false, false); + + } + + // ---------------------------------------------------------- private methods + + private void testConditionals(String testVal, boolean expectedResult) + throws Exception { + + boolean pass = false; + + NameValuePair value[] = NameValuePair.buildConditionalNameValue(testVal, + true, false); + + try { + for (boolean tf : deferred) { + String expr = ExprEval.buildElExpr(tf, "conditional"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue((Boolean) result, expectedResult)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + } catch (Exception e) { + throw new Exception(e); + } + } + + private void testConditionals(boolean testVal, boolean expectedResult) + throws Exception { + + boolean pass = false; + + NameValuePair value[] = NameValuePair.buildConditionalNameValue(testVal, + true, false); + + try { + for (boolean tf : deferred) { + String expr = ExprEval.buildElExpr(tf, "conditional"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue((Boolean) result, expectedResult)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + } catch (Exception e) { + throw new Exception(e); + } + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/build.xml new file mode 100644 index 0000000000..c9f1377ed1 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/conditionaloperator/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClient.java new file mode 100644 index 0000000000..c2f1a4fd81 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/ELClient.java @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.emptyoperator; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; +import com.sun.ts.tests.el.common.util.NameValuePair; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + private final boolean[] deferred = { true, false }; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + /* + * @testName: elEmptyNullTest + * + * @assertion_ids: EL:SPEC:25.1 + * + * @test_Strategy: Validate that if "null" is passed with the Empty operator, + * the correct Boolean result is returned. + */ + public void elEmptyNullTest() throws Exception { + + boolean pass = false; + + String[] symbols = { "$", "#" }; + boolean expectedResult = true; + + try { + for (String prefix : symbols) { + String expr = prefix + "{empty null}"; + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + + if (result == null) { + TestUtil.logTrace("result is null"); + } else { + TestUtil.logTrace("result is " + result.toString()); + } + + pass = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue((Boolean) result, expectedResult)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + } catch (Exception e) { + throw new Exception(e); + } + + } + + /* + * @testName: elEmptyStringTest + * + * @assertion_ids: EL:SPEC:25.2; EL:SPEC:25.6 + * + * @test_Strategy: Validate that if a String is passed with the Empty + * operator, the correct Boolean result is returned. + */ + public void elEmptyStringTest() throws Exception { + + this.testEmptyOperator("", true); + + this.testEmptyOperator("something", false); + + } + + /* + * @testName: elEmptyArrayTest + * + * @assertion_ids: EL:SPEC:25.3; EL:SPEC:25.6 + * + * @test_Strategy: Validate that if a Array is passed with the Empty operator, + * the correct Boolean result is returned. + */ + public void elEmptyArrayTest() throws Exception { + + this.testEmptyOperator(new String[0], true); + + String[] testArray = { "Apple" }; + this.testEmptyOperator(testArray, false); + + } + + /* + * @testName: elEmptyMapTest + * + * @assertion_ids: EL:SPEC:25.4; EL:SPEC:25.6 + * + * @test_Strategy: Validate that if a Map is passed with the Empty operator, + * the correct Boolean result is returned. + */ + public void elEmptyMapTest() throws Exception { + + HashMap testMap = new HashMap(); + + this.testEmptyOperator(testMap, true); + + testMap.put("Fruit", "Apple"); + this.testEmptyOperator(testMap, false); + + // Clean out the Map. + testMap.clear(); + } + + /* + * @testName: elEmptyCollectionTest + * + * @assertion_ids: EL:SPEC:25.5; EL:SPEC:25.6 + * + * @test_Strategy: Validate that if a Collection is passed with the Empty + * operator, the correct Boolean result is returned. + */ + public void elEmptyCollectionTest() throws Exception { + + ArrayList testCollection = new ArrayList(); + + this.testEmptyOperator(testCollection, true); + + testCollection.add("Apple"); + this.testEmptyOperator(testCollection, false); + + // Clean out the Collection. + testCollection.clear(); + } + + // ---------------------------------------------------------- private methods + + // Test Empty operator. + private void testEmptyOperator(Object testVal, boolean expectedResult) + throws Exception { + + boolean pass = false; + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(testVal); + + try { + for (boolean tf : deferred) { + String expr = ExprEval.buildElExpr(tf, "empty"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue((Boolean) result, expectedResult)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + } catch (Exception e) { + throw new Exception(e); + } + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/build.xml new file mode 100644 index 0000000000..0b8a6f1535 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/emptyoperator/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClient.java new file mode 100644 index 0000000000..f9076aa561 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/lambda/ELClient.java @@ -0,0 +1,888 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.lambda; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.TypesBean; +import com.sun.ts.tests.el.common.util.Validator; + +import jakarta.el.ELProcessor; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logMsg("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elLambdaExprBigDecimalTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)", "func = (x,y)->x + * [operator] y; func(a, b)", "(cond->[true/false]? a + * [operator] b: a [operator] 2)(a)" + * + * Variable A - BigDecimal + * + * Variable B - Rotating through the following types: + * BigDecimal, BigInteger, Integer, Float, Long, Short, + * Double, Byte + * + * Excluded: none + * + * @since: 3.0 + * + */ + public void elLambdaExprBigDecimalTest() throws Exception { + String comparitorA = "BigDecimal"; + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + // (+ operator) + this.runLambdaExpressions("+", BigDecimal.valueOf(2), comparitorA, bValue, + bName); + + // (- operator) + this.runLambdaExpressions("-", BigDecimal.valueOf(0), comparitorA, bValue, + bName); + + // (* operator) + this.runLambdaExpressions("*", BigDecimal.valueOf(1), comparitorA, bValue, + bName); + + // (/ operator) + this.runLambdaExpressions("/", BigDecimal.valueOf(1), comparitorA, bValue, + bName); + + // (div operator) + this.runLambdaExpressions("div", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + // (% operator) + this.runLambdaExpressions("%", Double.valueOf(0), comparitorA, bValue, + bName); + + // (mod operator) + this.runLambdaExpressions("mod", Double.valueOf(0), comparitorA, bValue, + bName); + } + + } // End elLambdaExprBigDecimalTest + + /** + * @testName: elLambdaExprFloatTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)", "func = (x,y)->x + * [operator] y; func(a, b)", "(cond->[true/false]? a + * [operator] b: a [operator] 2)(a)" + * + * Variable A - Float + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal + * + * @since: 3.0 + * + */ + public void elLambdaExprFloatTest() throws Exception { + String comparitorA = "Float"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if (excludeList.contains(bName)) { + TestUtil.logMsg("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + + if ("BigInteger".equals(bName)) { + // (+ operator) + this.runLambdaExpressions("+", BigDecimal.valueOf(2), comparitorA, + bValue, bName); + + // (- operator) + this.runLambdaExpressions("-", BigDecimal.valueOf(0), comparitorA, + bValue, bName); + + // (* operator) + this.runLambdaExpressions("*", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + // (/ operator) + this.runLambdaExpressions("/", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + // (div operator) + this.runLambdaExpressions("div", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + } else { + // (+ operator) + this.runLambdaExpressions("+", Double.valueOf(2), comparitorA, bValue, + bName); + + // (- operator) + this.runLambdaExpressions("-", Double.valueOf(0), comparitorA, bValue, + bName); + + // (* operator) + this.runLambdaExpressions("*", Double.valueOf(1), comparitorA, bValue, + bName); + + // (/ operator) + this.runLambdaExpressions("/", Double.valueOf(1), comparitorA, bValue, + bName); + + // (div operator) + this.runLambdaExpressions("div", Double.valueOf(1), comparitorA, + bValue, bName); + + } + + /* + * The same for all other tested data types. + */ + + // (% operator) + this.runLambdaExpressions("%", Double.valueOf(0), comparitorA, bValue, + bName); + + // (mod operator) + this.runLambdaExpressions("mod", Double.valueOf(0), comparitorA, bValue, + bName); + } + } + + } // End elLambdaExprFloatTest + + /** + * @testName: elLambdaExprDoubleTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)", "func = (x,y)->x + * [operator] y; func(a, b)", "(cond->[true/false]? a + * [operator] b: a [operator] 2)(a)" + * + * Variable A - Double + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, Float + * + * @since: 3.0 + * + */ + public void elLambdaExprDoubleTest() throws Exception { + String comparitorA = "Double"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("Float"); + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if (excludeList.contains(bName)) { + TestUtil.logMsg("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + if ("BigInteger".equals(bName)) { + // (+ operator) + this.runLambdaExpressions("+", BigDecimal.valueOf(2), comparitorA, + bValue, bName); + + // (- operator) + this.runLambdaExpressions("-", BigDecimal.valueOf(0), comparitorA, + bValue, bName); + + // (* operator) + this.runLambdaExpressions("*", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + // (/ operator) + this.runLambdaExpressions("/", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + // (div operator) + this.runLambdaExpressions("div", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + } else { + // (+ operator) + this.runLambdaExpressions("+", Double.valueOf(2), comparitorA, bValue, + bName); + + // (- operator) + this.runLambdaExpressions("-", Double.valueOf(0), comparitorA, bValue, + bName); + + // (* operator) + this.runLambdaExpressions("*", Double.valueOf(1), comparitorA, bValue, + bName); + + // (/ operator) + this.runLambdaExpressions("/", Double.valueOf(1), comparitorA, bValue, + bName); + + // (div operator) + this.runLambdaExpressions("div", Double.valueOf(1), comparitorA, + bValue, bName); + + } + + /* + * The same for all other tested data types. + */ + + // (% operator) + this.runLambdaExpressions("%", Double.valueOf(0), comparitorA, bValue, + bName); + + // (mod operator) + this.runLambdaExpressions("mod", Double.valueOf(0), comparitorA, bValue, + bName); + } + } + + } // End elLambdaExprDoubleTest + + /** + * @testName: elLambdaExprBigIntegerTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)" + * + * Variable A - BigInteger + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, Float, Double + * + * @since: 3.0 + * + */ + public void elLambdaExprBigIntegerTest() throws Exception { + String comparitorA = "BigInteger"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logMsg("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + // (+ operator) + this.runLambdaExpressions("+", BigInteger.valueOf(2), comparitorA, + bValue, bName); + + // (- operator) + this.runLambdaExpressions("-", BigInteger.valueOf(0), comparitorA, + bValue, bName); + + // (* operator) + this.runLambdaExpressions("*", BigInteger.valueOf(1), comparitorA, + bValue, bName); + + // (/ operator) + this.runLambdaExpressions("/", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + // (div operator) + this.runLambdaExpressions("div", BigDecimal.valueOf(1), comparitorA, + bValue, bName); + + // (% operator) + this.runLambdaExpressions("%", BigInteger.valueOf(0), comparitorA, + bValue, bName); + + // (mod operator) + this.runLambdaExpressions("mod", BigInteger.valueOf(0), comparitorA, + bValue, bName); + } + } + + } // End elLambdaExprBigIntegerTest + + /** + * @testName: elLambdaExprIntegerTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)" + * + * Variable A - Integer + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double + * + * @since: 3.0 + * + */ + public void elLambdaExprIntegerTest() throws Exception { + String comparitorA = "Integer"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logMsg("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + // (+ operator) + this.runLambdaExpressions("+", Long.valueOf(2), comparitorA, bValue, + bName); + + // (- operator) + this.runLambdaExpressions("-", Long.valueOf(0), comparitorA, bValue, + bName); + + // (* operator) + this.runLambdaExpressions("*", Long.valueOf(1), comparitorA, bValue, + bName); + + // (/ operator) + this.runLambdaExpressions("/", Double.valueOf(1), comparitorA, bValue, + bName); + + // (div operator) + this.runLambdaExpressions("div", Double.valueOf(1), comparitorA, bValue, + bName); + + // (% operator) + this.runLambdaExpressions("%", Long.valueOf(0), comparitorA, bValue, + bName); + + // (mod operator) + this.runLambdaExpressions("mod", Long.valueOf(0), comparitorA, bValue, + bName); + } + } + + } // End elLambdaExprIntegerTest + + /** + * @testName: elLambdaExprLongTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)" + * + * Variable A - Long + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer + * + * @since: 3.0 + * + */ + public void elLambdaExprLongTest() throws Exception { + String comparitorA = "Long"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logMsg("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + // (+ operator) + this.runLambdaExpressions("+", Long.valueOf(2), comparitorA, bValue, + bName); + + // (- operator) + this.runLambdaExpressions("-", Long.valueOf(0), comparitorA, bValue, + bName); + + // (* operator) + this.runLambdaExpressions("*", Long.valueOf(1), comparitorA, bValue, + bName); + + // (/ operator) + this.runLambdaExpressions("/", Double.valueOf(1), comparitorA, bValue, + bName); + + // (div operator) + this.runLambdaExpressions("div", Double.valueOf(1), comparitorA, bValue, + bName); + + // (% operator) + this.runLambdaExpressions("%", Long.valueOf(0), comparitorA, bValue, + bName); + + // (mod operator) + this.runLambdaExpressions("mod", Long.valueOf(0), comparitorA, bValue, + bName); + } + } + + } // End elLambdaExprLongTest + + /** + * @testName: elLambdaExprShortTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)" + * + * Variable A - Short + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer, + * Long + * + * @since: 3.0 + * + */ + public void elLambdaExprShortTest() throws Exception { + String comparitorA = "Short"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + excludeList.add("Long"); + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logMsg("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + // (+ operator) + this.runLambdaExpressions("+", Long.valueOf(2), comparitorA, bValue, + bName); + + // (- operator) + this.runLambdaExpressions("-", Long.valueOf(0), comparitorA, bValue, + bName); + + // (* operator) + this.runLambdaExpressions("*", Long.valueOf(1), comparitorA, bValue, + bName); + + // (/ operator) + this.runLambdaExpressions("/", Double.valueOf(1), comparitorA, bValue, + bName); + + // (div operator) + this.runLambdaExpressions("div", Double.valueOf(1), comparitorA, bValue, + bName); + + // (% operator) + this.runLambdaExpressions("%", Long.valueOf(0), comparitorA, bValue, + bName); + + // (mod operator) + this.runLambdaExpressions("mod", Long.valueOf(0), comparitorA, bValue, + bName); + } + } + + } // End elLambdaExprShortTest + + /** + * @testName: elLambdaExprByteTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expressions: "(((x, y)-> x [operator] y)(a, b))", "z = + * (x,y)->x [operator] y" "z(a, b)" + * + * Variable A - Byte + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer, + * Long, Short + * + * @since: 3.0 + * + */ + public void elLambdaExprByteTest() throws Exception { + String comparitorA = "Byte"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + excludeList.add("Long"); + excludeList.add("Short"); + + Iterator> iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logMsg("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + // (+ operator) + this.runLambdaExpressions("+", Long.valueOf(2), comparitorA, bValue, + bName); + + // (- operator) + this.runLambdaExpressions("-", Long.valueOf(0), comparitorA, bValue, + bName); + + // (* operator) + this.runLambdaExpressions("*", Long.valueOf(1), comparitorA, bValue, + bName); + + // (/ operator) + this.runLambdaExpressions("/", Double.valueOf(1), comparitorA, bValue, + bName); + + // (div operator) + this.runLambdaExpressions("div", Double.valueOf(1), comparitorA, bValue, + bName); + + // (% operator) + this.runLambdaExpressions("%", Long.valueOf(0), comparitorA, bValue, + bName); + + // (mod operator) + this.runLambdaExpressions("mod", Long.valueOf(0), comparitorA, bValue, + bName); + } + } + + } // End elLambdaExprByteTest + + /** + * @testName: elLambdaExprStringTest + * + * @assertion_ids: EL:SPEC:49.1; EL:JAVADOC:212 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: + + * + * Expression: "(((x, y)-> x cat y)(a, b))" + * + * Variable A - String + * + * Variable B - String + * + * @since: 3.0 + * + */ + public void elLambdaExprStringTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + + String aValue = "a='Testing'"; + String bValue = "b='Testing'"; + + elp.eval(aValue); + elp.eval(bValue); + + // (+= operator) + Validator.testExpression(elp, "(((x, y)-> x += y)(a, b))", "TestingTesting", + "'Testing' += 'Testing'"); + + } // End elLambdaExprStringTest + + /** + * @testName: elLambdaExprNullTest + * + * @assertion_ids: EL:SPEC:50.1; EL:SPEC:50.2; EL:SPEC:50.3; EL:SPEC:50.4; + * EL:SPEC:50.5; EL:SPEC:50.6; EL:JAVADOC:212 + * + * @test_Strategy: Evaluate the Lambda Expression, making sure the coercion + * rules are followed. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "(((x, y)-> x [operator] y)(a, b))" + * + * Variable A - null + * + * Variable B - null + * + * @since: 3.0 + * + */ + public void elLambdaExprNullTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + elp.defineBean("types", new TypesBean()); + + Long expected = Long.valueOf(0); + String aValue = "a = types.tckNull"; + String bValue = "b = types.tckNull"; + + elp.eval(aValue); + elp.eval(bValue); + String operator; + + // (+ operator) + operator = "+"; + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expected, "null + null"); + + // (- operator) + operator = "-"; + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expected, "null - null"); + + // (* operator) + operator = "*"; + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expected, "null * null"); + + // (/ operator) + operator = "/"; + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expected, "null / null"); + + // (div operator) + operator = "div"; + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expected, "null div null"); + + // (% operator) + operator = "%"; + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expected, "null % null"); + + // (mod operator) + operator = "mod"; + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expected, "null mod null"); + + } // End elLambdaExprNullTest + + // ----------------------------- private methods. + + private void runLambdaExpressions(String operator, Number expectedResult, + String aType, String comparitorB, String bName) throws Exception { + + ELProcessor elp = new ELProcessor(); + elp.defineBean("types", new TypesBean()); + + String comparitorA = "a=types.tck" + aType; + + elp.eval(comparitorA); + elp.eval(comparitorB); + + Validator.testExpression(elp, "(x->(y->x " + operator + " y)(a))(b)", + expectedResult, aType + " " + operator + " " + bName); + + Validator.testExpression(elp, "(()->y->y " + operator + " a)()(b)", + expectedResult, aType + " " + operator + " " + bName); + + Validator.testExpression(elp, + "f = (x)->(tem=x; y->tem " + operator + " y); f(a)(b)", expectedResult, + aType + " " + operator + " " + bName); + + Validator.testExpression(elp, "f = ()->y->y " + operator + " a; f()(b)", + expectedResult, aType + " " + operator + " " + bName); + + Validator.testExpression(elp, + "f = (x)->(tem=x; y->tem " + operator + " y); f(a)(b)", expectedResult, + aType + " " + operator + " " + bName); + + Validator.testExpression(elp, "(((x, y)-> x " + operator + " y)(a, b))", + expectedResult, aType + " " + operator + " " + bName); + + String zValue = "z = (x,y)->x " + operator + " y"; + elp.eval(zValue); + Validator.testExpression(elp, "z(a, b)", expectedResult, + aType + " " + operator + " " + bName); + + Validator.testExpression(elp, + "func = (x,y)->x " + operator + " y; func(a, b)", expectedResult, + aType + " " + operator + " " + bName); + + elp.eval("cond = true"); + Validator.testExpression(elp, + "(cond->true? a " + operator + " b: a " + operator + " 2)(a)", + expectedResult, aType + " " + operator + " " + bName); + + elp.eval("cond = false"); + Validator.testExpression(elp, + "(cond->false? a " + operator + " 2: a " + operator + " b)(a)", + expectedResult, aType + " " + operator + " " + bName); + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/lambda/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/lambda/build.xml new file mode 100644 index 0000000000..87a4e2626d --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/lambda/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/language/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/language/ELClient.java new file mode 100644 index 0000000000..54e500766c --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/language/ELClient.java @@ -0,0 +1,588 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.language; + +import java.util.Hashtable; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.common.el.spec.Book; +import com.sun.ts.tests.el.common.util.ExprEval; +import com.sun.ts.tests.el.common.util.ResolverType; + +import jakarta.el.ELException; + +public class ELClient extends ServiceEETest { + + private static String NLINE = System.getProperty("line.separator", "\n"); + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + // ------------------------------------------------------------- Test Methods + + /* + * @testName: poundDollarSameMeaning1Test + * + * @assertion_ids: EL:SPEC:1 + * + * @test_Strategy: Confirm that two EL expressions, identical except for the + * '$' and '#' delimiters, are evaluated the same. Case 1: base is null. + */ + public void poundDollarSameMeaning1Test() throws Exception { + + boolean pass = true; + + String testExpr = "\"foo\""; + + try { + Object dollarResult = ExprEval + .evaluateValueExpression("${" + testExpr + "}", null, String.class); + Object poundResult = ExprEval + .evaluateValueExpression("#{" + testExpr + "}", null, String.class); + + TestUtil.logTrace("Comparing ${" + dollarResult.toString() + "} " + + "to #{" + poundResult.toString() + "}"); + + pass = (ExprEval.compareClass(poundResult, String.class) + && ExprEval.compareClass(dollarResult, String.class) + && ExprEval.compareValue(poundResult, dollarResult)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: poundDollarSameMeaning2Test + * + * @assertion_ids: EL:SPEC:1 + * + * @test_Strategy: Confirm that two EL expressions, identical except for the + * '$' and '#' delimiters, are evaluated the same. Case 2: base is non-null. + */ + public void poundDollarSameMeaning2Test() throws Exception { + + boolean pass = true; + + try { + Object firstNameDollar = ExprEval.evaluateValueExpression( + "${worker.firstName}", null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + + Object firstNamePound = ExprEval.evaluateValueExpression( + "#{worker.firstName}", null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + + TestUtil.logTrace("Comparing ${" + firstNameDollar.toString() + "} to #{" + + firstNamePound.toString() + "}"); + + if (!(firstNamePound.toString().equals(firstNameDollar.toString()))) { + + TestUtil.logTrace( + "Dollar & Pound symbols return different" + "expression values!"); + pass = false; + + } + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: nestedEvalExpressionsTest + * + * @assertion_ids: EL:SPEC:2 + * + * @test_Strategy: Verify that nested eval-expressions are illegal. + */ + public void nestedEvalExpressionsTest() throws Exception { + + boolean pass = true; + String[] expr = { "${worker[${worker}]}", "${worker[#{worker}]}", + "#{worker[${worker}]}", "#{worker[#{worker}]}" }; + + for (int i = 0; i < expr.length; ++i) { + + try { + ExprEval.evaluateValueExpression(expr[i], null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + pass = false; + TestUtil.logErr("Test FAILED. No exception thrown for "); + TestUtil.logErr(expr[i]); + + } catch (ELException ee) { + // Test passes + TestUtil.logErr("Expected Exception thrown."); + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Test FAILED. " + expr[i] + " caused "); + TestUtil.logErr("an exception, but it was not an "); + TestUtil.logErr("ELException."); + TestUtil.printStackTrace(e); + } + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: mixedCompositeExpressionsTest + * + * @assertion_ids: EL:SPEC:12 + * + * @test_Strategy: Verify that composite expressions that mix the '$' and '#' + * delimiters are illegal. + */ + public void mixedCompositeExpressionsTest() throws Exception { + + boolean pass = true; + String[] expr = { "${worker}#{worker}", "#{worker}${worker}", + "${worker}#{worker}${worker}", "#{worker}${worker}#{worker}" }; + + for (int i = 0; i < expr.length; ++i) { + + try { + ExprEval.evaluateValueExpression(expr[i], null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + pass = false; + TestUtil.logErr("Test FAILED. No exception thrown for "); + TestUtil.logErr(expr[i]); + + } catch (ELException ee) { + // Test passes + TestUtil.logErr("Expected Exception thrown."); + + } catch (Exception e) { + pass = false; + TestUtil.logErr("Test FAILED. " + expr[i] + " caused "); + TestUtil.logErr("an exception, but it was not an "); + TestUtil.logErr("ELException."); + TestUtil.printStackTrace(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + } + + /* + * @testName: compositeExprEval1Test + * + * @assertion_ids: EL:SPEC:11 + * + * @test_Strategy: Verify that in a composite expression eval-expressions are + * coerced to Strings according to the EL type conversion rules and + * concatenated with any intervening literal-expressions. + */ + public void compositeExprEval1Test() throws Exception { + + boolean pass = true; + + String streetName = "${'Network Circle'}"; + String city = "${'Santa Clara'}"; + String state = "${'CA'}"; + + String expected = "4140 Network Circle, Santa Clara, CA 95054"; + + try { + Object address = ExprEval.evaluateValueExpression( + 4140 + " " + streetName + ", " + city + ", " + state + " " + 95054, + null, String.class); + + TestUtil.logTrace("Testing for Address: " + expected); + + pass = (ExprEval.compareClass(address, String.class) + && ExprEval.compareValue(address, expected)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: compositeExprEval2Test + * + * @assertion_ids: EL:SPEC:11 + * + * @test_Strategy: Verify that in a composite expression eval-expressions are + * evaluated left to right, coerced to Strings according to the EL type + * conversion rules, and concatenated with any intervening + * literal-expressions. + */ + public void compositeExprEval2Test() throws Exception { + + boolean pass = true; + + int num = 2; + String expected = "total = 3.0"; + + try { + Object div = ExprEval.evaluateValueExpression( + "total = " + "${" + num + "+2/" + num + "}", null, String.class); + + TestUtil.logTrace("Testing for: " + expected); + + pass = (ExprEval.compareClass(div, String.class) + && ExprEval.compareValue(div, expected)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: dotAndIndexOperatorsSameTest + * + * @assertion_ids: EL:SPEC:15 + * + * @test_Strategy: [DotAndIndexOperatorsSame] Verify that the dot and index + * operators are evaluated in the same way. + */ + public void dotAndIndexOperatorsSameTest() throws Exception { + + boolean pass = true; + + try { + // ELResolver empResolver = new EmployeeELResolver(); + + Object firstnameDot = ExprEval.evaluateValueExpression( + "${worker.firstName}", null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + + Object firstnameBracket = ExprEval.evaluateValueExpression( + "${worker['firstName']}", null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + + pass = firstnameDot.equals(firstnameBracket); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: elSyntaxEscapeTest + * + * @assertion_ids: EL:SPEC:8 + * + * @test_Strategy: [ELSyntaxEscape] Verify that the EL special characters '$' + * and '#' are treated as literals when preceded with '\'. + */ + public void elSyntaxEscapeTest() throws Exception { + + boolean pass = true; + + try { + Object firstnameDollar = ExprEval.evaluateValueExpression( + "\\${worker.firstName}", null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + + Object firstnamePound = ExprEval.evaluateValueExpression( + "\\#{worker.firstName}", null, String.class, + ResolverType.EMPLOYEE_ELRESOLVER); + + if (!(ExprEval.compareValue(firstnameDollar, "${worker.firstName}") + && ExprEval.compareValue(firstnamePound, "#{worker.firstName}"))) { + + TestUtil.logTrace("Escape character failed to work."); + pass = false; + } + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: literalExprEval1Test + * + * @assertion_ids: EL:SPEC:6 + * + * @test_Strategy: [LiteralExprEval] Set the value of a ValueExpression to a + * literal String type. Verify that the value retrieved when the expression is + * evaluated is a String equal to the value set. + */ + public void literalExprEval1Test() throws Exception { + + boolean pass = true; + + String exprStr = "foo"; + String expected = exprStr; + + try { + Object expr = ExprEval.evaluateValueExpression(exprStr, null, + String.class); + + pass = (ExprEval.compareClass(expr, String.class) + && ExprEval.compareValue(expr, expected)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: literalExprEval2Test + * + * @assertion_ids: EL:SPEC:6 + * + * @test_Strategy: [LiteralExprEval] Coerce a String literal to a Boolean in a + * ValueExpression. Verify that the value retrieved when the expression is + * evaluated is a Boolean of the expected value. + */ + public void literalExprEval2Test() throws Exception { + + boolean pass = true; + + String exprStr = "true"; + + try { + Object expr = ExprEval.evaluateValueExpression(exprStr, null, + Boolean.class); + + pass = (ExprEval.compareClass(expr, Boolean.class) + && ExprEval.compareValue(expr, true)); + + } catch (Exception e) { + TestUtil.printStackTrace(e); + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: literalExprAsMethodExpr1Test + * + * @assertion_ids: EL:SPEC:10 + * + * @test_Strategy: [LiteralExprAsMethodExpr] Verify that a literal-expression + * can also be used as a method expression that returns a non-void value. + */ + public void literalExprAsMethodExpr1Test() throws Exception { + + boolean pass = true; + + try { + // literal expression returning String + Class[] params = {}; + + Object value1 = ExprEval.evaluateMethodExpression("true", params, + String.class, ResolverType.VECT_ELRESOLVER); + + if (!("true".equals(value1))) { + pass = false; + TestUtil.logErr("Literal Expression, Return String Failed!"); + } + + // literal expression returning non-String value + Object value2 = ExprEval.evaluateMethodExpression("true", params, + Boolean.class, ResolverType.VECT_ELRESOLVER); + if (!((Boolean) value2).booleanValue()) { + pass = false; + TestUtil.logErr("Literal Expression, Return non-String " + "Failed!"); + } + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("Test Failed!"); + } + + /* + * @testName: literalExprAsMethodExpr2Test + * + * @assertion_ids: EL:SPEC:10 + * + * @test_Strategy: [LiteralExprAsMethodExpr] Verify that a literal-expression + * can also be used as a method expression that returns a non-void value. + * Verify that the standard coercion rules apply if the return type is not + * java.lang.String. + */ + public void literalExprAsMethodExpr2Test() throws Exception { + + boolean pass = true; + int testNum = 496; + + try { + // literal expression returning String + Class[] params = {}; + + Object value = ExprEval.evaluateMethodExpression("496", params, + Integer.class, ResolverType.VECT_ELRESOLVER); + + if (!(value instanceof Integer)) { + pass = false; + TestUtil.logErr("MethodExpression invocation does not return" + + " instance of expected class"); + } + + else if (((Integer) value).intValue() != testNum) { + pass = false; + TestUtil.logErr( + "Expected: " + testNum + NLINE + "Received: " + value.toString()); + } + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("Test Failed!"); + } + + /* + * @testName: rValueCoercion1Test + * + * @assertion_ids: EL:SPEC:3 + * + * @test_Strategy: [RValueCoercion] Set the value of a ValueExpression to a + * String type and verify that the value retrieved when the expression is + * evaluated is also a String type. + */ + public void rValueCoercion1Test() throws Exception { + boolean pass = false; + + String expr = "${foo}"; + String expected = "bar"; + + try { + Object value = ExprEval.evaluateCoerceValueExpression(expr, expected, + String.class); + + pass = (ExprEval.compareClass(value, String.class) + && ExprEval.compareValue(value, expected)); + + } catch (Exception e) { + throw new Exception(e); + } + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: rValueCoercion2Test + * + * @assertion_ids: EL:SPEC:3 + * + * @test_Strategy: [RValueCoercion] Set the value of a ValueExpression to a + * complex type and verify that the value retrieved when the expression is + * evaluated is a String type in accordance with the coercion rules. + */ + public void rValueCoercion2Test() throws Exception { + boolean pass = false; + + String expr = "${javabook}"; + String expected = "The Java Programming Language"; + + try { + Book jbook = new Book(expected, "Arnold and Gosling", "Addison Wesley", + 1996); + + Object value = ExprEval.evaluateCoerceValueExpression(expr, jbook, + String.class); + + pass = (ExprEval.compareClass(value, String.class) + && ExprEval.compareValue(value, expected)); + + } catch (Exception e) { + throw new Exception(e); + } + if (!pass) + throw new Exception("TEST FAILED!"); + } + + /* + * @testName: parseOnceEvalManyTest + * + * @assertion_ids: EL:SPEC:45 + * + * @test_Strategy: [ExprParsedEvalMany] Verify that once an expression is + * parsed, it can be evaluated multiple times, and that the result of the + * evaluation will be the same even when the EL context is modified. + */ + public void parseOnceEvalManyTest() throws Exception { + boolean pass = false; + + String expr = "${foo}"; + String expected = "bar"; + + Hashtable contextObjects = new Hashtable(); + contextObjects.put(String.class, "string context"); + contextObjects.put(Integer.class, Integer.valueOf(1)); + contextObjects.put(Boolean.class, Boolean.TRUE); + + try { + pass = ExprEval.evaluateManyValueExpression(expr, expected, String.class, + contextObjects); + + } catch (Exception e) { + throw new Exception(e); + } + if (!pass) + throw new Exception("TEST FAILED!"); + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/language/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/language/build.xml new file mode 100644 index 0000000000..995d37bed7 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/language/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/literal/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/literal/ELClient.java new file mode 100644 index 0000000000..26addb8a83 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/literal/ELClient.java @@ -0,0 +1,404 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * $Id$ + */ + +package com.sun.ts.tests.el.spec.literal; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + // ------------------------------------------------------------- Test + // Methods + + /** + * @testName: elBooleanLiteralTest + * @assertion_ids: EL:SPEC:13.1 + * @test_Strategy: Validate that the EL Boolean literal: - 'true' is evaluated + * as expected. - 'false' is evaluated as expected. + */ + public void elBooleanLiteralTest() throws Exception { + + boolean pass1, pass2; + Boolean expectedResult = Boolean.TRUE; + + // Literal true. + try { + pass1 = false; + expectedResult = Boolean.TRUE; + + Object result = ExprEval.evaluateValueExpression("${true}", null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass1 = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue(result, expectedResult)); + + } catch (Exception e) { + throw new Exception(e); + } + + // Literal false. + try { + pass2 = false; + expectedResult = Boolean.FALSE; + + Object result = ExprEval.evaluateValueExpression("${false}", null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass2 = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue(result, expectedResult)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass1) + throw new Exception("TEST FAILED: Literal true evaluated incorrectly."); + if (!pass2) + throw new Exception("TEST FAILED: Literal false evaluated " + "incorrectly."); + } + + /** + * @testName: elIntegerLiteralTest + * @assertion_ids: EL:SPEC:13.2 + * @test_Strategy: Validate that the EL Integer literal with the: - '$' is + * evaluated as expected. - '#' is evaluated as expected. + */ + public void elIntegerLiteralTest() throws Exception { + + boolean pass1, pass2; + Long expectedResult; + + List ilist = this.getIntegerList(); + + for (Iterator it = ilist.iterator(); it.hasNext();) { + Integer tInteger = (Integer) it.next(); + expectedResult = Long.valueOf(tInteger); + + // test "$" symbol + try { + pass1 = false; + + Object result = ExprEval.evaluateValueExpression( + "${" + tInteger.toString() + "}", null, Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass1 = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult)); + + } catch (Exception e) { + throw new Exception(e); + } + + // Test "#" symbol + try { + pass2 = false; + + Object result = ExprEval.evaluateValueExpression( + "#{" + tInteger.toString() + "}", null, Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass2 = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass1) + throw new Exception( + "TEST FAILED: Literal Integer \"$\" evaluated" + " incorrectly."); + if (!pass2) + throw new Exception( + "TEST FAILED: Literal Integer \"#\" evaluated" + " incorrectly."); + } + } + + /** + * @testName: elFloatingPointLiteralTest + * @assertion_ids: EL:SPEC:13.3 + * @test_Strategy: Validate that the EL Float literal with the: - '$' is + * evaluated as expected. - '#' is evaluated as expected. + */ + public void elFloatingPointLiteralTest() throws Exception { + + boolean pass1, pass2; + Float expectedResult; + + List flist = this.getFloatList(); + + for (Iterator it = flist.iterator(); it.hasNext();) { + Float tFloat = (Float) it.next(); + expectedResult = Float.valueOf(tFloat); + + // test "$" symbol + try { + pass1 = false; + + Object result = ExprEval.evaluateValueExpression( + "${" + tFloat.toString() + "}", null, Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass1 = (ExprEval.compareClass(result, Double.class) + && ExprEval.compareValue((Double) result, expectedResult, 1)); + + } catch (Exception e) { + throw new Exception(e); + } + + // Test "#" symbol + try { + pass2 = false; + + Object result = ExprEval.evaluateValueExpression( + "#{" + tFloat.toString() + "}", null, Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass2 = (ExprEval.compareClass(result, Double.class) + && ExprEval.compareValue((Double) result, expectedResult, 1)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass1) + throw new Exception( + "TEST FAILED: Literal Float \"$\" evaluated" + " incorrectly."); + if (!pass2) + throw new Exception( + "TEST FAILED: Literal Float \"#\" evaluated" + " incorrectly."); + } + } + + /** + * @testName: elStringLiteralTest + * @assertion_ids: EL:SPEC:13.4; EL:SPEC:13.5 + * @test_Strategy: Validate that the EL String literal with the: - '$' is + * evaluated as expected. - '#' is evaluated as expected. + */ + public void elStringLiteralTest() throws Exception { + + boolean pass1, pass2; + String expectedResult; + String testString; + + Hashtable sMap = this.getStringTable(); + Enumeration keys = sMap.keys(); + + while (keys.hasMoreElements()) { + + expectedResult = keys.nextElement().toString(); + testString = sMap.get(expectedResult).toString(); + + // test "$" symbol + try { + pass1 = false; + + Object result = ExprEval.evaluateValueExpression( + "${" + testString + "}", null, Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass1 = (ExprEval.compareClass(result, String.class) + && ExprEval.compareValue((String) result, expectedResult)); + + } catch (Exception e) { + throw new Exception(e); + } + + // Test "#" symbol + try { + pass2 = false; + + Object result = ExprEval.evaluateValueExpression( + "#{" + testString + "}", null, Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass2 = (ExprEval.compareClass(result, String.class) + && ExprEval.compareValue((String) result, expectedResult)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass1) + throw new Exception( + "TEST FAILED: Literal String \"$\" evaluated" + " incorrectly."); + if (!pass2) + throw new Exception( + "TEST FAILED: Literal String \"#\" evaluated" + " incorrectly."); + } + } + + /** + * @testName: elNullLiteralTest + * @assertion_ids: EL:SPEC:13.6 + * @test_Strategy: Validate that the EL 'null' literal evalutes correctly. + */ + public void elNullLiteralTest() throws Exception { + + boolean pass1, pass2; + + // Test "$" symbol + try { + Object result = ExprEval.evaluateValueExpression("${null}", null, + Object.class); + pass1 = (result == null) ? true : false; + + } catch (Exception e) { + throw new Exception(e); + } + + // Test "#" symbol + + try { + Object result = ExprEval.evaluateValueExpression("#{null}", null, + Object.class); + pass2 = (result == null) ? true : false; + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass1) + throw new Exception( + "TEST FAILED: Literal 'null' \"$\" evaluated" + " incorrectly."); + + if (!pass2) + throw new Exception( + "TEST FAILED: Literal 'null \"#\" evaluated" + " incorrectly."); + + } + + /** + * @testName: elSyntaxAsLiteralTest + * @assertion_ids: EL:SPEC:7 + * @test_Strategy: [ELSyntaxAsLiteral] Verify that to generate literal values + * that include the character sequence "${" or "#{" a + * composite expression can be used. + */ + public void elSyntaxAsLiteralTest() throws Exception { + boolean pass = false; + + // Hashtable layout. + // key - expected value + // value - test expression + Hashtable testValues = new Hashtable(); + testValues.put("${foo}", "#{'${'}foo}"); + testValues.put("${foo}", "${'${'}foo}"); + testValues.put("#{foo}", "${'#{'}foo}"); + testValues.put("#{foo}", "#{'#{'}foo}"); + + String exprStr; + String expected; + + Set tvalue = testValues.keySet(); + Iterator itr = tvalue.iterator(); + + while (itr.hasNext()) { + expected = itr.next(); + exprStr = (String) testValues.get(expected); + + try { + Object expr = ExprEval.evaluateValueExpression(exprStr, null, + String.class); + + pass = (ExprEval.compareClass(expr, String.class) + && ExprEval.compareValue(expr, expected)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED!"); + } + } + + // ---------------------------------------------------------- Private + // methods + + private List getFloatList() { + List floatList = new ArrayList(); + floatList.add(new Float("8.1F")); + floatList.add(new Float("-70.2F")); + floatList.add(new Float("8.1e4F")); + floatList.add(new Float("8.1E6F")); + floatList.add(new Float("8.1e-9F")); + floatList.add(new Float("8.1E+3F")); + floatList.add(new Float("-.72F")); + floatList.add(new Float(".999F")); + floatList.add(new Float("-.1e1F")); + floatList.add(new Float(".234E22F")); + floatList.add(new Float("-.3444e-2F")); + floatList.add(new Float(".5E+7F")); + floatList.add(new Float("-1e1F")); + floatList.add(new Float("234E2F")); + floatList.add(new Float("-3444e-2F")); + floatList.add(new Float("-3444e+2F")); + + return floatList; + } + + private List getIntegerList() { + List integerList = new ArrayList(); + integerList.add(1); + integerList.add(-2); + integerList.add(2147483647); + integerList.add(-2147483647); + + return integerList; + } + + /** + * The returned Hashtable is in the form of: "Expected String" - "Test String" + */ + private Hashtable getStringTable() { + Hashtable testStrings = new Hashtable(); + testStrings.put("string", "'string'"); + testStrings.put("str\\ing", "'str\\\\ing'"); + testStrings.put("\"catstring\"", "'\"catstring\"'"); + testStrings.put("\'pullstring\'", "'\\\'pullstring\\\''"); + + return testStrings; + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/literal/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/literal/build.xml new file mode 100644 index 0000000000..9152202584 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/literal/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClient.java new file mode 100644 index 0000000000..de6fd8235c --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/mapper/ELClient.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.mapper; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.elcontext.FuncMapperELContext; +import com.sun.ts.tests.el.common.elcontext.VarMapperELContext; +import com.sun.ts.tests.el.common.functionmapper.TCKFunctionMapper; +import com.sun.ts.tests.el.common.util.ExprEval; + +import jakarta.el.ELException; +import jakarta.el.ExpressionFactory; +import jakarta.el.ValueExpression; +import jakarta.el.VariableMapper; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + /** + * @testName: ELFunctionBindingTest + * + * @assertion_ids: EL:SPEC:31 + * @test_Strategy: [ELFunctionsBinding] Create an ELContext that uses a + * non-null FunctionMapper. Create a ValueExpression from the + * ELContext that references a function assigned by the + * FunctionMapper. Change the function mapping in the + * FunctionMapper. Show that the ValueExpression evaluates as + * before and that the original method mapped to the function + * is being invoked. + */ + + public void ELFunctionBindingTest() throws Exception { + + Class expectedClass = Integer.class; + Integer expectedValue = Integer.valueOf(10); + + // Create ValueExpressions from a function mapped by the + // FunctionMapper: Int:val() -> Integer.valueOf(String s) + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + FuncMapperELContext context = new FuncMapperELContext(); + ValueExpression vexp1 = expFactory.createValueExpression(context, + "${Int:val(10)}", Object.class); + ValueExpression vexp2 = expFactory.createValueExpression(context, + "${Int:val(\"string\")}", Object.class); + + // Make sure the expression evaluates as we expect + Object initialResult = vexp1.getValue(context); + if (!ExprEval.compareClass(initialResult, expectedClass)) { + throw new Exception("Wrong class for initial Expression evaluation"); + } + if (!ExprEval.compareValue(initialResult, expectedValue)) { + throw new Exception("Wrong value for initial Expression evaluation"); + } + + // Get the FunctionMapper and change the method mapped to Int:val + TCKFunctionMapper mapper = (TCKFunctionMapper) context.getFunctionMapper(); + mapper.update(); + + // Now re-evaluate the expression; results should be the same + Object finalResult = vexp1.getValue(context); + if (!ExprEval.compareClass(finalResult, expectedClass)) { + throw new Exception("Wrong class for final Expression evaluation"); + } + if (!ExprEval.compareValue(finalResult, expectedValue)) { + throw new Exception("Wrong value for final Expression evaluation"); + } + + // Verify the method bound to the function behaves as expected for + // invalid arguments + try { + vexp2.getValue(context); + + } catch (Throwable t) { + if (!(t instanceof ELException)) { + TestUtil.logErr("Expected ELException to be thrown"); + TestUtil.logErr("instead threw " + t.toString()); + TestUtil.printStackTrace(t); + throw new Exception("ELException not thrown"); + } + Throwable cause = t.getCause(); + if (!(cause instanceof NumberFormatException)) { + TestUtil.logErr("Expected cause to be NumberFormatException"); + TestUtil.logErr("instead cause is " + cause.toString()); + TestUtil.printStackTrace(cause); + throw new Exception("NumberFormatException not cause"); + } + } + } + + /** + * @testName: ELVariableBindingTest + * + * @assertion_ids: EL:SPEC:34 + * @test_Strategy: [ELVariablesBinding] Create an ELContext that uses a + * non-null VariableMapper. Create a ValueExpression from the + * ELContext that references a variable assigned by the + * VariableMapper. Remove the assignment from the + * VariableMapper. Verify that the ValueExpression evaluates + * as before. + */ + + public void ELVariableBindingTest() throws Exception { + + Class expectedClass = Double.class; + Double expectedValue = Double.valueOf(10.0); + + // Create a ValueExpression and use it to set a variable + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + VarMapperELContext context = new VarMapperELContext(testProps); + VariableMapper varMapper = context.getVariableMapper(); + ValueExpression vexp1 = expFactory.createValueExpression(context, "#{1e1}", + Object.class); + varMapper.setVariable("ten", vexp1); + + // Make sure the variable evaluates as we expect + ValueExpression vexp2 = varMapper.resolveVariable("ten"); + Object initialResult = vexp2.getValue(context); + if (!ExprEval.compareClass(initialResult, expectedClass)) { + throw new Exception("Wrong class for initial Expression evaluation"); + } + if (!ExprEval.compareValue(initialResult, expectedValue)) { + throw new Exception("Wrong value for initial Expression evaluation"); + } + + // Remove the variable assignment + varMapper.setVariable("ten", null); + + // Now re-evaluate the variable; results should be the same + Object finalResult = vexp2.getValue(context); + if (!ExprEval.compareClass(finalResult, expectedClass)) { + throw new Exception("Wrong class for final Expression evaluation"); + } + if (!ExprEval.compareValue(finalResult, expectedValue)) { + throw new Exception("Wrong value for final Expression evaluation"); + } + + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/mapper/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/mapper/build.xml new file mode 100644 index 0000000000..c5f9904cd5 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/mapper/build.xml @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClient.java new file mode 100644 index 0000000000..b63846f19c --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/ELClient.java @@ -0,0 +1,508 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.operatorprecedence; + +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.elcontext.FuncMapperELContext; +import com.sun.ts.tests.el.common.util.ExprEval; + +import jakarta.el.ELException; +import jakarta.el.ExpressionFactory; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + private static final String[] MODOPER = { "%", "mod" }; + + private static final String[] DIVOPER = { "/", "div" }; + + private static final String[] ANDOPER = { "&&", "and" }; + + private static final String[] OROPER = { "||", "or" }; + + private final boolean[] deferred = { true, false }; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + /* + * @testName: elMultiPreBinaryTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "*" is evaluated before "+" "*" is evaluated before "-" + */ + public void elMultiPreBinaryTest() throws Exception { + + this.testOrderPrecedence("{1 + 5 * 2}", Long.valueOf(11)); + this.testOrderPrecedence("{1 - 5 * 2}", Long.valueOf(-9)); + + } + + /* + * @testName: elDivPreBinaryTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "div, /" is evaluated before "+" "div, /" is evaluated before + * "-" + */ + public void elDivPreBinaryTest() throws Exception { + + for (String s : DIVOPER) { + this.testOrderPrecedence("{1 + 4 " + s + " 2}", Double.valueOf(3)); + this.testOrderPrecedence("{1 - 4 " + s + " 2}", Double.valueOf(-1)); + } + + } + + /* + * @testName: elModPreBinaryTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "mod, %" is evaluated before "+" "mod, %" is evaluated before + * "-" + */ + public void elModPreBinaryTest() throws Exception { + + for (String s : MODOPER) { + this.testOrderPrecedence("{1 + 7 " + s + " 2}", Long.valueOf(2)); + this.testOrderPrecedence("{1 - 7 " + s + " 2}", Long.valueOf(0)); + } + + } + + /* + * @testName: elMultiPreRelationalTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "*" is evaluated before ">" "*" is evaluated before "<" "*" + * is evaluated before ">=" "*" is evaluated before "<=" "*" is evaluated + * before "lt" "*" is evaluated before "gt" "*" is evaluated before "le" "*" + * is evaluated before "ge" + * + * "*" is evaluated before "==" "*" is evaluated before "!=" "*" is evaluated + * before "eq" "*" is evaluated before "ne" + */ + public void elMultiPreRelationalTest() throws Exception { + + this.testOrderPrecedence("{6 > 5 * 2}", false); + this.testOrderPrecedence("{3 * 2 < 8}", true); + this.testOrderPrecedence("{6 >= 5 * 2}", false); + this.testOrderPrecedence("{6 * 2 <= 12}", true); + this.testOrderPrecedence("{5 * 1 gt 6}", false); + this.testOrderPrecedence("{6 lt 5 * 2}", true); + this.testOrderPrecedence("{5 * 1 ge 6}", false); + this.testOrderPrecedence("{6 le 5 * 2}", true); + + this.testOrderPrecedence("{5 == 5 * 2}", false); + this.testOrderPrecedence("{5 * 2 != 10}", false); + this.testOrderPrecedence("{10 eq 5 * 2}", true); + this.testOrderPrecedence("{15 * 1 ne 1}", true); + + } + + /* + * @testName: elDivPreRelationalTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "div, /" is evaluated before ">" "div, /" is evaluated before + * "<" "div, /" is evaluated before ">=" "div, /" is evaluated before "<=" + * "div, /" is evaluated before "lt" "div, /" is evaluated before "gt" + * "div, /" is evaluated before "le" "div, /" is evaluated before "ge" + * + * "div, /" is evaluated before "==" "div, /" is evaluated before "!=" + * "div, /" is evaluated before "eq" "div, /" is evaluated before "ne" + */ + public void elDivPreRelationalTest() throws Exception { + + for (String s : DIVOPER) { + this.testOrderPrecedence("{3 > 4 " + s + " 2}", true); + this.testOrderPrecedence("{12 " + s + " 2 < 5}", false); + this.testOrderPrecedence("{4 >= 6 " + s + " 24}", true); + this.testOrderPrecedence("{16 " + s + " 2 <= 5}", false); + this.testOrderPrecedence("{6 gt 5 " + s + " 2}", true); + this.testOrderPrecedence("{12 " + s + " 1 lt 5}", false); + this.testOrderPrecedence("{6 ge 5 " + s + " 2}", true); + this.testOrderPrecedence("{50 " + s + " 2 le 5}", false); + + this.testOrderPrecedence("{1 == 2 " + s + " 2}", true); + this.testOrderPrecedence("{10 " + s + " 5 != 5}", true); + this.testOrderPrecedence("{5 eq 5 " + s + " 2}", false); + this.testOrderPrecedence("{2 ne 4 " + s + " 2}", false); + } + + } + + /* + * @testName: elModPreRelationalTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "mod, %" is evaluated before ">" "mod, %" is evaluated before + * "<" "mod, %" is evaluated before ">=" "mod, %" is evaluated before "<=" + * "mod, %" is evaluated before "lt" "mod, %" is evaluated before "gt" + * "mod, %" is evaluated before "le" "mod, %" is evaluated before "ge" + * + * "mod, %" is evaluated before "==" "mod, %" is evaluated before "!=" + * "mod, %" is evaluated before "eq" "mod, %" is evaluated before "ne" + */ + public void elModPreRelationalTest() throws Exception { + + for (String s : MODOPER) { + this.testOrderPrecedence("{4 " + s + " 15 > 1}", true); + this.testOrderPrecedence("{5 < 6 " + s + " 2}", false); + this.testOrderPrecedence("{6 " + s + " 29 >= 5}", true); + this.testOrderPrecedence("{6 <= 5 " + s + " 2}", false); + this.testOrderPrecedence("{3 " + s + " 8 gt 1}", true); + this.testOrderPrecedence("{6 lt 5 " + s + " 2}", false); + this.testOrderPrecedence("{8 " + s + " 5 ge 2}", true); + this.testOrderPrecedence("{6 le 5 " + s + " 2}", false); + + this.testOrderPrecedence("{3 " + s + " 2 == 1}", true); + this.testOrderPrecedence("{5 != 5 " + s + " 2}", true); + this.testOrderPrecedence("{6 " + s + " 2 eq 5}", false); + this.testOrderPrecedence("{2 ne 5 " + s + " 3}", false); + } + + } + + /* + * @testName: elMultiEqualPreAndTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "*, ==" is evaluated before "&&, and" + */ + public void elMultiEqualPreAndTest() throws Exception { + + for (String a : ANDOPER) { + this.testOrderPrecedence("{10 == 5 * 2 " + a + " 6 * 2 == 15}", false); + this.testOrderPrecedence("{10 == 5 * 2 " + a + " 6 * 2 == 12}", true); + } + + } + + /* + * @testName: elDivEqualPreAndTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "div, /, ==" is evaluated before "&&, and" + */ + public void elDivEqualPreAndTest() throws Exception { + + for (String d : DIVOPER) { + for (String a : ANDOPER) { + this.testOrderPrecedence( + "{12 " + d + " 2 == 6 " + a + " 10 " + d + " 2 == 5}", true); + this.testOrderPrecedence( + "{12 " + d + " 3 == 6 " + a + " 10 " + d + " 2 == 5}", false); + } + } + + } + + /* + * @testName: elModEqualPreAndTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "mod, %, ==" is evaluated before "&&, and" + */ + public void elModEqualPreAndTest() throws Exception { + + for (String m : MODOPER) { + for (String a : ANDOPER) { + this.testOrderPrecedence( + "{15 " + m + " 4 == 3 " + a + " 3 " + m + " 3 == 0}", true); + this.testOrderPrecedence( + "{15 " + m + " 3 == 3 " + a + " 3 " + m + " 3 == 0}", false); + } + } + + } + + /* + * @testName: elMultiEqualOrCondTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "*, ==" is evaluated before "||, or" + */ + public void elMultiEqualOrCondTest() throws Exception { + + for (String o : OROPER) { + this.testOrderPrecedence("{10 == 5 * 2 " + o + " 6 * 2 == 15}", true); + this.testOrderPrecedence("{10 == 5 * 5 " + o + " 6 * 2 == 12}", true); + this.testOrderPrecedence("{10 == 5 * 5 " + o + " 6 * 6 == 12}", false); + } + + } + + /* + * @testName: elDivEqualPreOrTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "div, /, ==" is evaluated before "||, or" + */ + public void elDivEqualPreOrTest() throws Exception { + + for (String d : DIVOPER) { + for (String o : OROPER) { + this.testOrderPrecedence( + "{12 " + d + " 2 == 6 " + o + " 10 " + d + " 5 == 5}", true); + this.testOrderPrecedence( + "{12 " + d + " 3 == 6 " + o + " 10 " + d + " 2 == 5}", true); + this.testOrderPrecedence( + "{12 " + d + " 3 == 6 " + o + " 10 " + d + " 5 == 5}", false); + } + } + + } + + /* + * @testName: elModEqualPreOrTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "mod, %, ==" is evaluated before "||, or" + */ + public void elModEqualPreOrTest() throws Exception { + + for (String m : MODOPER) { + for (String o : OROPER) { + this.testOrderPrecedence( + "{15 " + m + " 4 == 3 " + o + " 4 " + m + " 3 == 0}", true); + this.testOrderPrecedence( + "{15 " + m + " 3 == 3 " + o + " 3 " + m + " 3 == 0}", true); + this.testOrderPrecedence( + "{15 " + m + " 3 == 3 " + o + " 8 " + m + " 3 == 0}", false); + } + } + } + + /* + * @testName: elMultiEqualPreCondTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "*" is evaluated before "? :" + */ + public void elMultiEqualPreCondTest() throws Exception { + + // These tests are designed to return the false if correct. + this.testOrderPrecedence("{5 * 2 == 10 ? false : true}", false); + this.testOrderPrecedence("{5 * 5 == 10 ? false : true}", true); + + } + + /* + * @testName: elDivEqualPreCondTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "div, /, ==" is evaluated before "? :" + */ + public void elDivEqualPreCondTest() throws Exception { + + // These tests are designed to return the false if correct. + for (String d : DIVOPER) { + this.testOrderPrecedence("{20 " + d + " 2 == 10 ? false : true}", false); + this.testOrderPrecedence("{24 " + d + " 2 == 10 ? false : true}", true); + } + } + + /* + * @testName: elModEqualPreCondTest + * + * @assertion_ids: EL:SPEC:28 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "mod, %, ==" is evaluated before "||, or" + */ + public void elModEqualPreCondTest() throws Exception { + + for (String m : MODOPER) { + this.testOrderPrecedence("{21 " + m + " 2 == 1 ? false : true}", false); + this.testOrderPrecedence("{15 " + m + " 3 == 3 ? false : true}", true); + } + } + + /* + * @testName: elParenPreBinaryTest + * + * @assertion_ids: EL:SPEC:28; EL:SPEC:27 + * + * @test_Strategy: Validate that the order of precedence is followed when an + * EL Expression is evaluated. + * + * Rules tested: "( )" is evaluated before "+" "( )" is evaluated before "-" + * "( )" is evaluated before "*" "( )" is evaluated before "/" "( )" is + * evaluated before "%" + */ + public void elParenPreBinaryTest() throws Exception { + + // "+" tests + this.testOrderPrecedence("{(2 + 3) - 10}", Long.valueOf(-5)); + this.testOrderPrecedence("{10 - (2 + 3)}", Long.valueOf(5)); + + // "-" tests + this.testOrderPrecedence("{(1 - 5) + 2}", Long.valueOf(-2)); + this.testOrderPrecedence("{2 + (5 - 1)}", Long.valueOf(6)); + + // "*" tests + this.testOrderPrecedence("{(1 + 5) * 2}", Long.valueOf(12)); + this.testOrderPrecedence("{2 * (1 + 5)}", Long.valueOf(12)); + + // "/" tests + this.testOrderPrecedence("{(4 + 4) / 2}", Double.valueOf(4)); + this.testOrderPrecedence("{2 / (4 + 4)}", Double.valueOf(0.25)); + + // "%" tests + this.testOrderPrecedence("{(2 + 7) % 2}", Long.valueOf(1)); + this.testOrderPrecedence("{18 % (8 + 7)}", Long.valueOf(3)); + + } + + /* + * @testName: functionPrecedenceTest + * + * @assertion_ids: EL:SPEC:29 + * + * @test_Strategy: Validate that qualified functions with a namespace prefix + * have precedence over the operators by constructing an expression which + * cannot be parsed due to this rule. + */ + public void functionPrecedenceTest() throws Exception { + + boolean pass = false; + + ExpressionFactory expFactory = ExpressionFactory.newInstance(); + FuncMapperELContext context = new FuncMapperELContext(); + expFactory.createValueExpression(context, "${Int:val(10)}", Object.class); + try { + expFactory.createValueExpression(context, "${a?Int:val(10)}", + Object.class); + } catch (ELException ex) { + pass = true; + } + + if (!pass) + throw new Exception("function precedence failed"); + + } + + // ---------------------------------------------------------- private methods + + private void testOrderPrecedence(String testExpr, Object expectedResult) + throws Exception { + + boolean pass = false; + + String[] symbol = { "$", "#" }; + String expr; + + try { + for (String prefix : symbol) { + expr = prefix + testExpr; + + TestUtil.logTrace("Expression to test: " + expr); + + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareValue(result, expectedResult)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + } catch (Exception e) { + throw new Exception(e); + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/build.xml new file mode 100644 index 0000000000..9bf7238220 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/operatorprecedence/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClient.java new file mode 100644 index 0000000000..89277b0ac5 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/ELClient.java @@ -0,0 +1,2365 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * $Id$ + */ + +package com.sun.ts.tests.el.spec.relationaloperator; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.List; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; +import com.sun.ts.tests.el.common.util.NameValuePair; +import com.sun.ts.tests.el.common.util.TestNum; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + private List numberList; + + private enum TestEnum { + APPLE, PEAR + }; + + // Data Type to test String Coercion. + private static final DougType DT = new DougType(); + + private static final NickType NT = new NickType(); + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + numberList = TestNum.getNumberList(); + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elEqualOperandLessThanOrEqualTest + * @assertion_ids: EL:SPEC:21.1 + * @test_Strategy: Validate that if the operands in an EL <= or le operation + * are equal, the result is true. + */ + public void elEqualOperandLessThanOrEqualTest() throws Exception { + + boolean pass = false; + + try { + // Expression One + String expr1 = ExprEval.buildElExpr(false, "<="); + TestUtil.logTrace("first expression to be evaluated is " + expr1); + + NameValuePair values1[] = NameValuePair + .buildNameValuePair(new Float(-1.0f), new Float(-1.0)); + + Object result1 = ExprEval.evaluateValueExpression(expr1, values1, + Boolean.class); + TestUtil.logTrace("first result is " + result1.toString()); + + // Expression Two + String expr2 = ExprEval.buildElExpr(true, "le"); + TestUtil.logTrace("second expression to be evaluated is " + expr2); + + NameValuePair values2[] = NameValuePair + .buildNameValuePair(new BigDecimal("1.0"), BigDecimal.ONE); + Object result2 = ExprEval.evaluateValueExpression(expr2, values2, + Boolean.class); + + TestUtil.logTrace("second result is " + result2.toString()); + + pass = (ExprEval.compareClass(result1, Boolean.class) + && ExprEval.compareValue((Boolean) result1, Boolean.TRUE) + && ExprEval.compareClass(result2, Boolean.class) + && ExprEval.compareValue((Boolean) result2, Boolean.TRUE)); + + } catch (Exception e) { + throw new Exception(e); + } finally { + ExprEval.cleanup(); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elEqualOperandGreaterThanOrEqualTest + * @assertion_ids: EL:SPEC:21.1 + * @test_Strategy: Validate that if the operands in an EL >= or ge operation + * are equal, the result is true. + */ + public void elEqualOperandGreaterThanOrEqualTest() throws Exception { + + boolean pass = false; + + try { + // Expression One + String expr1 = ExprEval.buildElExpr(false, ">="); + TestUtil.logTrace("first expression to be evaluated is " + expr1); + + NameValuePair values1[] = NameValuePair + .buildNameValuePair(new Float(-1.0f), new Float(-1.0)); + + Object result1 = ExprEval.evaluateValueExpression(expr1, values1, + Boolean.class); + TestUtil.logTrace("first result is " + result1.toString()); + + // Expression Two + String expr2 = ExprEval.buildElExpr(true, "ge"); + TestUtil.logTrace("second expression to be evaluated is " + expr2); + + NameValuePair values2[] = NameValuePair + .buildNameValuePair(new BigInteger("1010"), BigInteger.TEN); + + Object result2 = ExprEval.evaluateValueExpression(expr2, values2, + Boolean.class); + TestUtil.logTrace("second result is " + result2.toString()); + + pass = (ExprEval.compareClass(result1, Boolean.class) + && ExprEval.compareValue((Boolean) result1, Boolean.TRUE) + && ExprEval.compareClass(result2, Boolean.class) + && ExprEval.compareValue((Boolean) result2, Boolean.TRUE)); + + } catch (Exception e) { + throw new Exception(e); + } finally { + ExprEval.cleanup(); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elNullOperandLessThanOrEqualTest + * @assertion_ids: EL:SPEC:21.2 + * @test_Strategy: Validate that if one of the operands in an EL <= or le + * operation is null, the result is false. + */ + public void elNullOperandLessThanOrEqualTest() throws Exception { + + boolean pass = false; + + try { + + Object result1 = ExprEval.evaluateValueExpression("${1 <= nullValue}", + null, Object.class); + TestUtil.logTrace("first result is " + result1.toString()); + + Object result2 = ExprEval.evaluateValueExpression("#{2 le nullValue}", + null, Object.class); + TestUtil.logTrace("second result is " + result2.toString()); + + pass = (ExprEval.compareClass(result1, Boolean.class) + && ExprEval.compareValue((Boolean) result1, Boolean.FALSE) + && ExprEval.compareClass(result2, Boolean.class) + && ExprEval.compareValue((Boolean) result2, Boolean.FALSE)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elNullOperandGreaterThanOrEqualTest + * @assertion_ids: EL:SPEC:21.2 + * @test_Strategy: Validate that if one of the operands in an EL >= or ge + * operation is null, the result is false. + */ + public void elNullOperandGreaterThanOrEqualTest() throws Exception { + + boolean pass = false; + + try { + + Object result1 = ExprEval.evaluateValueExpression("${1 >= nullValue}", + null, Object.class); + TestUtil.logTrace("first result is " + result1.toString()); + + Object result2 = ExprEval.evaluateValueExpression("#{2 ge nullValue}", + null, Object.class); + TestUtil.logTrace("second result is " + result2.toString()); + + pass = (ExprEval.compareClass(result1, Boolean.class) + && ExprEval.compareValue((Boolean) result1, Boolean.FALSE) + && ExprEval.compareClass(result2, Boolean.class) + && ExprEval.compareValue((Boolean) result2, Boolean.FALSE)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + + /** + * @testName: elNullOperandNotEqualTest + * @assertion_ids: EL:SPEC:22.2 + * @test_Strategy: Validate that if one of the operands is null in an EL !=, + * ne operation return true. + */ + public void elNullOperandNotEqualTest() throws Exception { + + boolean pass = false; + + try { + + Object result1 = ExprEval.evaluateValueExpression("${1 != nullValue}", + null, Object.class); + TestUtil.logTrace("first result is " + result1.toString()); + + Object result2 = ExprEval.evaluateValueExpression("#{2 ne nullValue}", + null, Object.class); + TestUtil.logTrace("second result is " + result2.toString()); + + pass = (ExprEval.compareClass(result1, Boolean.class) + && ExprEval.compareValue((Boolean) result1, Boolean.TRUE) + && ExprEval.compareClass(result2, Boolean.class) + && ExprEval.compareValue((Boolean) result2, Boolean.TRUE)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } // End elNullOperandNotEqualTest + + /** + * @testName: elNullOperandEqualTest + * @assertion_ids: EL:SPEC:22.2 + * @test_Strategy: Validate that if one of the operands is null in an EL =, eq + * operation return false. + */ + public void elNullOperandEqualTest() throws Exception { + + boolean pass = false; + + try { + + Object result1 = ExprEval.evaluateValueExpression("${1 == nullValue}", + null, Object.class); + TestUtil.logTrace("first result is " + result1.toString()); + + Object result2 = ExprEval.evaluateValueExpression("#{2 eq nullValue}", + null, Object.class); + TestUtil.logTrace("second result is " + result2.toString()); + + pass = (ExprEval.compareClass(result1, Boolean.class) + && ExprEval.compareValue((Boolean) result1, Boolean.FALSE) + && ExprEval.compareClass(result2, Boolean.class) + && ExprEval.compareValue((Boolean) result2, Boolean.FALSE)); + + } catch (Exception e) { + throw new Exception(e); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } // End elNullOperandEqualTest + + /** + * @testName: elBigDecimalLessThanTest + * @assertion_ids: EL:SPEC:21.3 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is a BigDecimal, the result is coerced to + * BigDecimal and the correct boolean value is returned. + * + * Equations tested: BigDecimal "<" & "lt" BigDecimal + * BigDecimal "<" & "lt" Double BigDecimal "<" & "lt" Float + * BigDecimal "<" & "lt" BigInteger BigDecimal "<" & "lt" + * Integer BigDecimal "<" & "lt" Long BigDecimal "<" & "lt" + * Short BigDecimal "<" & "lt" Byte + */ + public void elBigDecimalLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(10.531), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(1.0000), false, "lt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(0.531), true, "lt"); + + } + + /** + * @testName: elBigDecimalLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.3 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is a BigDecimal, the result is coerced to + * BigDecimal and the correct boolean value is returned. + * + * Equations tested: BigDecimal "<=" & "le" BigDecimal + * BigDecimal "<=" & "le" Double BigDecimal "<=" & "le" Float + * BigDecimal "<=" & "le" BigInteger BigDecimal "<=" & "le" + * Integer BigDecimal "<=" & "le" Long BigDecimal "<=" & "le" + * Short BigDecimal "<=" & "le" Byte + */ + public void elBigDecimalLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(10.531), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(1.0000), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(-10.531), true, "<="); + } + + /** + * @testName: elBigDecimalGreaterThanTest + * @assertion_ids: EL:SPEC:21.3 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is a BigDecimal, the result is coerced to + * BigDecimal and the correct boolean value is returned. + * + * Equations tested: BigDecimal ">" & "gt" BigDecimal + * BigDecimal ">" & "gt" Double BigDecimal ">" & "gt" Float + * BigDecimal ">" & "gt" BigInteger BigDecimal ">" & "gt" + * Integer BigDecimal ">" & "gt" Long BigDecimal ">" & "gt" + * Short BigDecimal ">" & "gt" Byte + */ + public void elBigDecimalGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(10.531), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(1.0000), false, ">"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(0.531), false, "gt"); + + } + + /** + * @testName: elBigDecimalGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.3 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is a BigDecimal, the result is coerced to + * BigDecimal and the correct boolean value is returned. + * + * Equations tested: BigDecimal ">=" & "ge" BigDecimal + * BigDecimal ">=" & "ge" Double BigDecimal ">=" & "ge" Float + * BigDecimal ">=" & "ge" BigInteger BigDecimal ">=" & "ge" + * Integer BigDecimal ">=" & "ge" Long BigDecimal ">=" & "ge" + * Short BigDecimal ">=" & "ge" Byte + */ + public void elBigDecimalGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(10.531), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(1.0000), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(-1.0000), false, "ge"); + + } + + /** + * @testName: elBigDecimalEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.3.1 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is a BigDecimal, the result is coerced to + * BigDecimal and the correct boolean value is returned. + * + * Equations tested: BigDecimal "==" & "eq" BigDecimal + * BigDecimal "==" & "eq" Double BigDecimal "==" & "eq" Float + * BigDecimal "==" & "eq" BigInteger BigDecimal "==" & "eq" + * Integer BigDecimal "==" & "eq" Long BigDecimal "==" & "eq" + * Short BigDecimal "==" & "eq" Byte + */ + public void elBigDecimalEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(10.531), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(1), true, "eq"); + + } + + /** + * @testName: elBigDecimalNotEqualToTest + * @assertion_ids: EL:SPEC:22.3.2 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is a BigDecimal, the result is coerced to + * BigDecimal and the correct boolean value is returned. + * + * Equations tested: BigDecimal "!=" & "ne" BigDecimal + * BigDecimal "!=" & "ne" Double BigDecimal "!=" & "ne" Float + * BigDecimal "!=" & "ne" BigInteger BigDecimal "!=" & "ne" + * Integer BigDecimal "!=" & "ne" Long BigDecimal "!=" & "ne" + * Short BigDecimal "!=" & "ne" Byte + */ + public void elBigDecimalNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(10.531), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigDecimal.valueOf(1), false, "ne"); + + } + + /** + * @testName: elFloatLessThanTest + * @assertion_ids: EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is a Float, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Float "<" & "lt" Double Float "<" & "lt" + * Float Float "<" & "lt" BigInteger Float "<" & "lt" Integer + * Float "<" & "lt" Long Float "<" & "lt" Short Float "<" & + * "lt" Byte + */ + public void elFloatLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(10f), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Float.valueOf(1f), false, "<"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(-10f), true, "lt"); + + } + + /** + * @testName: elFloatLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is a Float, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Float "<=" & "le" Double Float "<=" & + * "le" Float Float "<=" & "le" BigInteger Float "<=" & "le" + * Integer Float "<=" & "le" Long Float "<=" & "le" Short + * Float "<=" & "le" Byte + */ + public void elFloatLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(10f), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Float.valueOf(1f), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(-10f), true, "<="); + } + + /** + * @testName: elFloatGreaterThanTest + * @assertion_ids: EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is a Float, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Float ">" & "gt" Double Float ">" & "gt" + * Float Float ">" & "gt" BigInteger Float ">" & "gt" Integer + * Float ">" & "gt" Long Float ">" & "gt" Short Float ">" & + * "gt" Byte + */ + public void elFloatGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(10531f), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Float.valueOf(1f), false, ">"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(-531f), false, "gt"); + + } + + /** + * @testName: elFloatGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is a Float, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Float ">=" & "ge" Double Float ">=" & + * "ge" Float Float ">=" & "ge" BigInteger Float ">=" & "ge" + * Integer Float ">=" & "ge" Long Float ">=" & "ge" Short + * Float ">=" & "ge" Byte + */ + public void elFloatGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(10531f), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Float.valueOf(1f), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(Float.valueOf(-1f), false, "ge"); + + } + + /** + * @testName: elFloatEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.4 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is a Float, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Float "==" & "eq" Double Float "==" & + * "eq" Float Float "==" & "eq" BigInteger Float "==" & "eq" + * Integer Float "==" & "eq" Long Float "==" & "eq" Short + * Float "==" & "eq" Byte + */ + public void elFloatEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(10531), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Float.valueOf(1), true, "eq"); + + } + + /** + * @testName: elFloatNotEqualToTest + * @assertion_ids: EL:SPEC:22.4 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is a Float, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Float "!=" & "ne" Double Float "!=" & + * "ne" Float Float "!=" & "ne" BigInteger Float "!=" & "ne" + * Integer Float "!=" & "ne" Long Float "!=" & "ne" Short + * Float "!=" & "ne" Byte + */ + public void elFloatNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Float.valueOf(10531), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Float.valueOf(1), false, "ne"); + + } + + /** + * @testName: elDoubleLessThanTest + * @assertion_ids: EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is a Double, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Double "<" & "lt" Double Double "<" & + * "lt" BigInteger Double "<" & "lt" Integer Double "<" & "lt" + * Long Double "<" & "lt" Short Double "<" & "lt" Byte + */ + public void elDoubleLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(2.5), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Double.valueOf(1.0), false, "lt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(-2.5), true, "lt"); + + } + + /** + * @testName: elDoubleLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is a Double, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Double "<=" & "le" Double Double "<=" & + * "le" BigInteger Double "<=" & "le" Integer Double "<=" & + * "le" Long Double "<=" & "le" Short Double "<=" & "le" Byte + */ + public void elDoubleLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(2.5), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Double.valueOf(1.0), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(-1.5), true, "<="); + } + + /** + * @testName: elDoubleGreaterThanTest + * @assertion_ids: EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is a Double, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Double ">" & "gt" Double Double ">" & + * "gt" BigInteger Double ">" & "gt" Integer Double ">" & "gt" + * Long Double ">" & "gt" Short Double ">" & "gt" Byte + */ + public void elDoubleGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(10.5), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Double.valueOf(1.0), false, "gt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(-10.5), false, "gt"); + + } + + /** + * @testName: elDoubleGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.4 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is a Double, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Double ">=" & "ge" Double Double ">=" & + * "ge" BigInteger Double ">=" & "ge" Integer Double ">=" & + * "ge" Long Double ">=" & "ge" Short Double ">=" & "ge" Byte + */ + public void elDoubleGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(10.0), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Double.valueOf(1.0), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(Double.valueOf(-10.0), false, "ge"); + + } + + /** + * @testName: elDoubleEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.4 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is a Double, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Double "==" & "eq" Double Double "==" & + * "eq" BigInteger Double "==" & "eq" Integer Double "==" & + * "eq" Long Double "==" & "eq" Short Double "==" & "eq" Byte + */ + public void elDoubleEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(10531), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Double.valueOf(1.00), true, "eq"); + + } + + /** + * @testName: elDoubleNotEqualToTest + * @assertion_ids: EL:SPEC:22.4 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is a Double, the result is coerced to Double and + * the correct boolean value is returned. + * + * Equations tested: Double "!=" & "ne" Double Double "!=" & + * "ne" BigInteger Double "!=" & "ne" Integer Double "!=" & + * "ne" Long Double "!=" & "ne" Short Double "!=" & "ne" Byte + */ + public void elDoubleNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Double.valueOf(10531), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Double.valueOf(1), false, "ne"); + + } + + /** + * @testName: elBigIntegerLessThanTest + * @assertion_ids: EL:SPEC:21.5 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is a BigInteger, the result is coerced to + * BigInteger and the correct boolean value is returned. + * + * Equations tested: BigInteger "<" & "lt" BigInteger + * BigInteger "<" & "lt" Integer BigInteger "<" & "lt" Long + * BigInteger "<" & "lt" Short BigInteger "<" & "lt" Byte + */ + public void elBigIntegerLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(10531), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(1), false, "lt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(-10531), true, "lt"); + + } + + /** + * @testName: elBigIntegerLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.5 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is a BigInteger, the result is coerced to + * BigInteger and the correct boolean value is returned. + * + * Equations tested: BigInteger "<=" & "le" BigInteger + * BigInteger "<=" & "le" Integer BigInteger "<=" & "le" Long + * BigInteger "<=" & "le" Short BigInteger "<=" & "le" Byte + */ + public void elBigIntegerLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(10531), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(1), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(-10531), true, "<="); + } + + /** + * @testName: elBigIntegerGreaterThanTest + * @assertion_ids: EL:SPEC:21.5 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is a BigInteger, the result is coerced to + * BigInteger and the correct boolean value is returned. + * + * Equations tested: BigInteger ">" & "gt" BigInteger + * BigInteger ">" & "gt" Integer BigInteger ">" & "gt" Long + * BigInteger ">" & "gt" Short BigInteger ">" & "gt" Byte + */ + public void elBigIntegerGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(10531), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(1), false, "gt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(-10531), false, "gt"); + + } + + /** + * @testName: elBigIntegerGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.5 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is a BigInteger, the result is coerced to + * BigInteger and the correct boolean value is returned. + * + * Equations tested: BigInteger ">=" & "ge" BigInteger + * BigInteger ">=" & "ge" Integer BigInteger ">=" & "ge" Long + * BigInteger ">=" & "ge" Short BigInteger ">=" & "ge" Byte + */ + public void elBigIntegerGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(10531), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(1), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(-10531), false, "ge"); + + } + + /** + * @testName: elBigIntegerEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.5.1 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is a BigInteger, the result is coerced to + * BigInteger and the correct boolean value is returned. + * + * Equations tested: BigInteger "==" & "eq" BigInteger + * BigInteger "==" & "eq" Integer BigInteger "==" & "eq" Long + * BigInteger "==" & "eq" Short BigInteger "==" & "eq" Byte + */ + public void elBigIntegerEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(10531), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(1), true, "eq"); + + } + + /** + * @testName: elBigIntegerNotEqualToTest + * @assertion_ids: EL:SPEC:22.5.2 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is a BigInteger, the result is coerced to + * BigInteger and the correct boolean value is returned. + * + * Equations tested: BigInteger "!=" & "ne" BigInteger + * BigInteger "!=" & "ne" Integer BigInteger "!=" & "ne" Long + * BigInteger "!=" & "ne" Short BigInteger "!=" & "ne" Byte + */ + public void elBigIntegerNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(10531), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(BigInteger.valueOf(1), false, "ne"); + + } + + /** + * @testName: elLongLessThanTest + * @assertion_ids: EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is a Long, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Long "<" & "lt" Integer Long "<" & "lt" + * Long Long "<" & "lt" Short Long "<" & "lt" Byte + */ + public void elLongLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(25000), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Long.valueOf(1), false, "<"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(-25000), true, "lt"); + + } + + /** + * @testName: elLongLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is a Long, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Long "<=" & "le" Integer Long "<=" & "le" + * Long Long "<=" & "le" Short Long "<=" & "le" Byte + */ + public void elLongLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(25000), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Long.valueOf(1), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(-25000), true, "<="); + } + + /** + * @testName: elLongGreaterThanTest + * @assertion_ids: EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is a Long, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Long ">" & "gt" Integer Long ">" & "gt" + * Long Long ">" & "gt" Short Long ">" & "gt" Byte + */ + public void elLongGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(10531), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Long.valueOf(1), false, ">"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(-10531), false, "gt"); + + } + + /** + * @testName: elLongGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is a Long, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Long ">=" & "ge" Integer Long ">=" & "ge" + * Long Long ">=" & "ge" Short Long ">=" & "ge" Byte + */ + public void elLongGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(25000), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Long.valueOf(1), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(Long.valueOf(-25000), false, "ge"); + + } + + /** + * @testName: elLongEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is a Long, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Long "==" & "eq" Integer Long "==" & "eq" + * Long Long "==" & "eq" Short Long "==" & "eq" Byte + */ + public void elLongEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(25000), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Long.valueOf(1), true, "eq"); + + } + + /** + * @testName: elLongNotEqualToTest + * @assertion_ids: EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is a Long, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Long "!=" & "ne" Integer Long "!=" & "ne" + * Long Long "!=" & "ne" Short Long "!=" & "ne" Byte + */ + public void elLongNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Long.valueOf(25000), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Long.valueOf(1), false, "ne"); + + } + + /** + * @testName: elIntegerLessThanTest + * @assertion_ids: EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is an Integer, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Integer "<" & "lt" Integer Integer "<" & + * "lt" Short Integer "<" & "lt" Byte + */ + public void elIntegerLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(25), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(1), false, "lt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(-25), true, "lt"); + + } + + /** + * @testName: elIntegerLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is an Integer, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Integer "<=" & "le" Integer Integer "<=" + * & "le" Short Integer "<=" & "le" Byte + */ + public void elIntegerLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(25), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(1), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(-25), true, "<="); + } + + /** + * @testName: elIntegerGreaterThanTest + * @assertion_ids: EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is an Integer, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Integer ">" & "gt" Integer Integer ">" & + * "gt" Short Integer ">" & "gt" Byte + */ + public void elIntegerGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(105), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(1), false, "gt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(-105), false, "gt"); + + } + + /** + * @testName: elIntegerGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is an Integer, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Integer ">=" & "ge" Integer Integer ">=" + * & "ge" Short Integer ">=" & "ge" Byte + */ + public void elIntegerGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(250), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(1), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(-250), false, "ge"); + + } + + /** + * @testName: elIntegerEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is an Integer, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Integer "==" & "eq" Integer Integer "==" + * & "eq" Short Integer "==" & "eq" Byte + */ + public void elIntegerEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(25), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(1), true, "eq"); + + } + + /** + * @testName: elIntegerNotEqualToTest + * @assertion_ids: EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is an Integer, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Integer "!=" & "ne" Integer Integer "!=" + * & "ne" Short Integer "!=" & "ne" Byte + */ + public void elIntegerNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(25), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Integer.valueOf(1), false, "ne"); + + } + + /** + * @testName: elShortLessThanTest + * @assertion_ids: EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is an Short, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Short "<" & "lt" Short Short "<" & "lt" + * Byte + */ + public void elShortLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("2"), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Short.valueOf("1"), false, "<"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("-2"), true, "lt"); + + } + + /** + * @testName: elShortLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is an Short, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Short "<=" & "le" Short Short "<=" & "le" + * Byte + */ + public void elShortLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("2"), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Short.valueOf("1"), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("-2"), true, "<="); + } + + /** + * @testName: elShortGreaterThanTest + * @assertion_ids: EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is an Short, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Short ">" & "gt" Short Short ">" & "gt" + * Byte + */ + public void elShortGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("2"), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Short.valueOf("1"), false, ">"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("-2"), false, "gt"); + + } + + /** + * @testName: elShortGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is an Short, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Short ">=" & "ge" Short Short ">=" & "ge" + * Byte + */ + public void elShortGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("2"), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Short.valueOf("1"), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(Short.valueOf("-2"), false, "ge"); + + } + + /** + * @testName: elShortEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is an Short, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Short "==" & "eq" Short Short "==" & "eq" + * Byte + */ + public void elShortEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("2"), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Short.valueOf("1"), true, "eq"); + + } + + /** + * @testName: elShortNotEqualToTest + * @assertion_ids: EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is an Short, the result is coerced to Long and + * the correct boolean value is returned. + * + * Equations tested: Short "!=" & "ne" Short Short "!=" & "ne" + * Byte + */ + public void elShortNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Short.valueOf("2"), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Short.valueOf("1"), false, "ne"); + + } + + /** + * @testName: elByteLessThanTest + * @assertion_ids: EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is an Byte, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Byte "<" & "lt" Byte + */ + public void elByteLessThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("2"), false, "<"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("1"), false, "lt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("-2"), true, "lt"); + + } + + /** + * @testName: elByteLessThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is an Byte, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Byte "<=" & "le" Byte + */ + public void elByteLessThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("2"), false, "<="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("1"), true, "le"); + + // Value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("-2"), true, "<="); + } + + /** + * @testName: elByteGreaterThanTest + * @assertion_ids: EL:SPEC:21.1 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is an Byte, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Byte ">" & "gt" Byte + */ + public void elByteGreaterThanTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("2"), true, ">"); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("1"), false, "gt"); + + // value passed in is smaller than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("-2"), false, "gt"); + + } + + /** + * @testName: elByteGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.1; EL:SPEC:21.6 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is an Byte, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Byte ">=" & "ge" Byte + */ + public void elByteGreaterThanEqualTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("2"), true, ">="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("1"), true, "ge"); + + // value passed in is smaller than the COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("-2"), false, "ge"); + + } + + /** + * @testName: elByteEqualToTest + * @assertion_ids: EL:SPEC:22.1; EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is an Byte, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Byte "==" & "eq" Byte + */ + public void elByteEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("2"), false, "=="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("1"), true, "eq"); + + } + + /** + * @testName: elByteNotEqualToTest + * @assertion_ids: EL:SPEC:22.6 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is an Byte, the result is coerced to Long and the + * correct boolean value is returned. + * + * Equations tested: Byte "!=" & "ne" Byte + */ + public void elByteNotEqualToTest() throws Exception { + + // Value passed in is larger than COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("2"), true, "!="); + + // value passed in is equal to the COMPARATOR. + this.testOperatorBoolean(Byte.valueOf("1"), false, "ne"); + + } + + /** + * @testName: elStringLessThanTest + * @assertion_ids: EL:SPEC:21.7 + * @test_Strategy: Validate that if one of the operands in an EL "<" or "lt" + * operation is an String, that both operands are coerced to + * type String and the correct boolean value is returned. + * + * Equations tested: String "<" & "lt" String + */ + public void elStringLessThanTest() throws Exception { + + // Value A is less than value B. (true) + this.testOperatorBoolean("Alpha", DT, true, "<"); + + // Value A is less than value B. (false) + this.testOperatorBoolean("Beta", DT, false, "lt"); + + // Value A is less than value B. (true) + this.testOperatorBoolean("Gamma", DT, false, "lt"); + + } + + /** + * @testName: elStringLessThanEqualTest + * @assertion_ids: EL:SPEC:21.7 + * @test_Strategy: Validate that if one of the operands in an EL "<=" or "le" + * operation is a String, that both operands are coerced to + * type String and the correct boolean value is returned. + * + * Equations tested: String "<=" & "le" String + */ + public void elStringLessThanEqualTest() throws Exception { + + // Value A is less than or equal to value B. (false) + this.testOperatorBoolean("Gamma", DT, false, "<="); + + // Value A is less than or equal to value B. (true) + this.testOperatorBoolean("Beta", DT, true, "le"); + + // Value A is less than or equal to value B. (true) + this.testOperatorBoolean("Alpha", DT, true, "<="); + } + + /** + * @testName: elStringGreaterThanTest + * @assertion_ids: EL:SPEC:21.7 + * @test_Strategy: Validate that if one of the operands in an EL ">" or "gt" + * operation is an String, that both operands are coerced to + * type String and the correct boolean value is returned. + * + * Equations tested: String ">" & "gt" String + */ + public void elStringGreaterThanTest() throws Exception { + + // Value A is greater than value B. (false) + this.testOperatorBoolean("Gamma", DT, true, ">"); + + // Value A greater than value B. (false) + this.testOperatorBoolean("Beta", DT, false, "gt"); + + // Value A is greater than value B. (false) + this.testOperatorBoolean("Alpha", DT, false, "gt"); + + } + + /** + * @testName: elStringGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.7 + * @test_Strategy: Validate that if one of the operands in an EL ">=" or "ge" + * operation is an String, that both operands are coerced to + * type String and the correct boolean value is returned. + * + * Equations tested: String ">=" & "ge" String + */ + public void elStringGreaterThanEqualTest() throws Exception { + + // Value A is greater than or equal to value B. (true) + this.testOperatorBoolean("Gamma", DT, true, ">="); + + // Value A is greater than or equal to value B. (true) + this.testOperatorBoolean("Beta", DT, true, "ge"); + + // Value A is greater than or equal to value B. (false) + this.testOperatorBoolean("Alpha", DT, false, "ge"); + + } + + /** + * @testName: elStringEqualToTest + * @assertion_ids: EL:SPEC:22.9 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is an String, that both operands are coerced to + * type String and the correct boolean value is returned. + * + * Equations tested: String "==" & "eq" String + */ + public void elStringEqualToTest() throws Exception { + + // Value A is equal to value B. (true) + this.testOperatorBoolean("Beta", DT, true, "=="); + + // Value A is smaller than value B. (false) + this.testOperatorBoolean("Alpha", DT, false, "eq"); + + } + + /** + * @testName: elStringNotEqualToTest + * @assertion_ids: EL:SPEC:22.9 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is an String, that both operands are coerced to + * type String and the correct boolean value is returned. + * + * Equations tested: String "!=" & "ne" String + */ + public void elStringNotEqualToTest() throws Exception { + + // Value A is not equal to value B. (true) + this.testOperatorBoolean("Alpha", DT, true, "!="); + + // Value A is not equal to value B. (false) + this.testOperatorBoolean("Beta", DT, false, "ne"); + + } + + /** + * @testName: elOtherLessThanTest + * @assertion_ids: EL:SPEC:21.8.2 + * @test_Strategy: Validate that if operand A in an EL "<" or "lt" operation + * is comparable, the result A.compareTo(B) is returned. + * + * Equation example: DougType "<" & "lt" NickType + */ + public void elOtherLessThanTest() throws Exception { + + // Value A is less than value B. (true) + this.testOperatorBoolean(DT, NT, true, "<"); + + // Value A is less than value B. (false) + this.testOperatorBoolean(DT, DT, false, "lt"); + + // Value A is less than value B. (false) + this.testOperatorBoolean(NT, DT, false, "lt"); + + } + + /** + * @testName: elOtherLessThanEqualTest + * @assertion_ids: EL:SPEC:21.8.2 + * @test_Strategy: Validate that if operand A in an EL "<=" or "le" operation + * is comparable, the result A.compareTo(B) is returned. + * + * Equation example: DougType "<=" & "le" NickType + */ + public void elOtherLessThanEqualTest() throws Exception { + + // Value A is less than or equal to value B. (false) + this.testOperatorBoolean(NT, DT, false, "<="); + + // Value A is less than or equal to value B. (true) + this.testOperatorBoolean(DT, DT, true, "le"); + + // Value A is less than or equal to value B. (true) + this.testOperatorBoolean(DT, NT, true, "<="); + } + + /** + * @testName: elOtherGreaterThanTest + * @assertion_ids: EL:SPEC:21.8.2 + * @test_Strategy: Validate that if operand A in an EL ">" or "gt" operation + * is comparable, the result A.compareTo(B) is returned. + * + * Equation example: DougType "<" & "gt" NickType + */ + public void elOtherGreaterThanTest() throws Exception { + + // Value A is greater than value B. (true) + this.testOperatorBoolean(NT, DT, true, ">"); + + // Value A greater than value B. (false) + this.testOperatorBoolean(DT, DT, false, "gt"); + + // Value A is greater than value B. (false) + this.testOperatorBoolean(DT, NT, false, "gt"); + + } + + /** + * @testName: elOtherGreaterThanEqualTest + * @assertion_ids: EL:SPEC:21.8.2 + * @test_Strategy: Validate that if operand A in an EL ">=" or "ge" operation + * is comparable, the result A.compareTo(B) is returned. + * + * Equations tested: DougType ">=" & "ge" NickType + */ + public void elOtherGreaterThanEqualTest() throws Exception { + + // Value A is greater than or equal to value B. (true) + this.testOperatorBoolean(NT, DT, true, ">="); + + // Value A is greater than or equal to value B. (true) + this.testOperatorBoolean(DT, DT, true, "ge"); + + // Value A is greater than or equal to value B. (false) + this.testOperatorBoolean(DT, NT, false, "ge"); + + } + + /** + * @testName: elOtherEqualToTest + * @assertion_ids: EL:SPEC:22.11 + * @test_Strategy: Validate that if operand A in an EL "==" or "eq" operation + * is comparable, the result A.equals(B) is returned. + * + * Equations Example: DougType "==" & "eq" NickType + */ + public void elOtherEqualToTest() throws Exception { + + // Value A is equal to value B. (true) + this.testOperatorBoolean(DT, DT, true, "=="); + + // Value A is smaller than value B. (false) + this.testOperatorBoolean(DT, NT, false, "eq"); + + } + + /** + * @testName: elOtherNotEqualToTest + * @assertion_ids: EL:SPEC:22.11 + * @test_Strategy: Validate that if operand A in an EL "!=" or "ne" operation + * is comparable, the result A.equals(B) is returned. + * + * Equation Example: DougType "!=" & "ne" NickType + */ + public void elOtherNotEqualToTest() throws Exception { + + // Value A is not equal to value B. (true) + this.testOperatorBoolean(DT, NT, true, "!="); + + // Value A is not equal to value B. (false) + this.testOperatorBoolean(DT, DT, false, "ne"); + + } + + /** + * @testName: elBooleanEqualToTest + * @assertion_ids: EL:SPEC:22.7 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is an Boolean, that both operands are coerced to + * type Boolean and the correct boolean value is returned. + * + * Equations tested: Boolean "==" & "eq" String + */ + public void elBooleanEqualToTest() throws Exception { + + // Value A is equal to value B. (true) + this.testOperatorBoolean("true", true, true, "=="); + + // Value A is smaller than value B. (false) + this.testOperatorBoolean("false", true, false, "eq"); + + } + + /** + * @testName: elBooleanNotEqualToTest + * @assertion_ids: EL:SPEC:22.7 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is an Boolean, that both operands are coerced to + * type Boolean and the correct boolean value is returned. + * + * Equations tested: String "!=" & "ne" String + */ + public void elBooleanNotEqualToTest() throws Exception { + + // Value A is not equal to value B. (true) + this.testOperatorBoolean("false", true, true, "!="); + + // Value A is not equal to value B. (false) + this.testOperatorBoolean("false", false, false, "ne"); + + } + + /** + * @testName: elEnumEqualToTest + * @assertion_ids: EL:SPEC:22.8 + * @test_Strategy: Validate that if one of the operands in an EL "==" or "eq" + * operation is an Enum, that both operands are coerced to + * type Enum and the correct boolean value is returned. + * + * Example Equation: Enum "==" String or Integer + */ + public void elEnumEqualToTest() throws Exception { + + // Value A is equal to value B. (true) + this.testOperatorBoolean(TestEnum.APPLE, "APPLE", true, "=="); + this.testOperatorBoolean(TestEnum.PEAR, "PEAR", true, "eq"); + + // Value A is not equal to value B. (false) + this.testOperatorBoolean(TestEnum.PEAR, "APPLE", false, "=="); + this.testOperatorBoolean(TestEnum.APPLE, "PEAR", false, "eq"); + } + + /** + * @testName: elEnumNotEqualToTest + * @assertion_ids: EL:SPEC:22.8 + * @test_Strategy: Validate that if one of the operands in an EL "!=" or "ne" + * operation is an Enum, that both operands are coerced to + * type String and the correct boolean value is returned. + * + * Example Equation: Enum "!=" & "ne" Enum + */ + public void elEnumNotEqualToTest() throws Exception { + + // Value A is not equal to value B. (true) + this.testOperatorBoolean(TestEnum.APPLE, "PEAR", true, "!="); + this.testOperatorBoolean(TestEnum.PEAR, "APPLE", true, "ne"); + + // Value A is not equal to value B. (false) + this.testOperatorBoolean(TestEnum.APPLE, "APPLE", false, "!="); + this.testOperatorBoolean(TestEnum.PEAR, "PEAR", false, "ne"); + } + + // ---------------------------------------------------------- private + // methods + + /** + * This method is used to validate an expression that has at least one + * BigDecimal in it. We pass in one of the operands(testVal), the other + * operand is automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. ">, >=, + * <, <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(BigDecimal testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil.logTrace( + "*** Start " + "\"" + "BigDecimal" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + // We don't test numeric strings + if (!(testNum instanceof Number)) + continue; + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace("types are " + "BigDecimal" + " and " + + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil.logTrace( + "*** End " + "\"" + "BigDecimal" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one + * BigInteger in it. We pass in one of the operands(testVal), the other + * operand is automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. >, >=, <, + * <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(BigInteger testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil.logTrace( + "*** Start " + "\"" + "BigInteger" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + // We don't test numeric strings + if (!(testNum instanceof Number)) + continue; + + if ((testNum instanceof BigDecimal) || (testNum instanceof Float) + || (testNum instanceof Double)) { + String skipType = testNum.getClass().getSimpleName(); + TestUtil.logTrace("Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace("types are " + "BigInteger" + " and " + + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil.logTrace( + "*** End " + "\"" + "BigInteger" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one Float + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. ">, >=, + * <, <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(Float testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil.logTrace( + "*** Start " + "\"" + "Float" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + // We don't test numeric strings + if (!(testNum instanceof Number)) + continue; + + if ((testNum instanceof BigDecimal)) { + String skipType = testNum.getClass().getSimpleName(); + TestUtil.logTrace("Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace( + "types are " + "Float" + " and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil.logTrace( + "*** End " + "\"" + "Float" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one Double + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. ">, >=, + * <, <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(Double testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil.logTrace( + "*** Start " + "\"" + "Double" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + // We don't test numeric strings + if (!(testNum instanceof Number)) + continue; + + if ((testNum instanceof BigDecimal || testNum instanceof Float)) { + String skipType = testNum.getClass().getSimpleName(); + TestUtil.logTrace("Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace( + "types are " + "Double" + " and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil.logTrace( + "*** End " + "\"" + "Double" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one Long in + * it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. ">, >=, + * <, <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(Long testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil + .logTrace("*** Start " + "\"" + "Long" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + // We don't test numeric strings + if (!(testNum instanceof Number)) + continue; + + if ((testNum instanceof BigDecimal || testNum instanceof Float + || testNum instanceof BigInteger || testNum instanceof Double)) { + String skipType = testNum.getClass().getSimpleName(); + TestUtil.logTrace("Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace( + "types are " + "Long" + " and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil + .logTrace("*** End " + "\"" + "Long" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one Integer + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. ">, >=, + * <, <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(Integer testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil.logTrace( + "*** Start " + "\"" + "Integer" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + // We don't test numeric strings + if (!(testNum instanceof Number)) + continue; + + if ((testNum instanceof BigDecimal || testNum instanceof Float + || testNum instanceof BigInteger || testNum instanceof Long + || testNum instanceof Double)) { + String skipType = testNum.getClass().getSimpleName(); + TestUtil.logTrace("Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace( + "types are " + "Integer" + " and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil.logTrace( + "*** End " + "\"" + "Integer" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one Short + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. ">, >=, + * <, <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(Short testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil.logTrace( + "*** Start " + "\"" + "Short" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + if (!(testNum instanceof Short || testNum instanceof Byte)) { + String skipType = testNum.getClass().getSimpleName(); + TestUtil.logTrace("Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace( + "types are " + "Short" + " and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil.logTrace( + "*** End " + "\"" + "Short" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one Byte in + * it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. >, >=, <, + * <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(Byte testVal, Boolean expectedVal, + String booleanOperator) throws Exception { + + boolean pass; + + for (int i = 0; numberList.size() > i; i++) { + TestUtil + .logTrace("*** Start " + "\"" + "Byte" + "\"" + " Test Sequence ***"); + + Object testNum = numberList.get(i); + + if (!(testNum instanceof Byte)) { + String skipType = testNum.getClass().getSimpleName(); + TestUtil.logTrace("Skip " + skipType + " Data type already " + + "tested for this in the " + skipType + " tests."); + continue; + } + + NameValuePair values[] = NameValuePair.buildNameValuePair(testVal, + testNum); + + try { + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace( + "types are " + "Byte" + " and " + testNum.getClass().getName()); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil + .logTrace("*** End " + "\"" + "Byte" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + } + + /** + * This method is used to validate an expression that has at least one String + * in it. We pass in one of the operands(testVal), the other operand is + * automatically picked up from the numberList. + * + * @param testVal + * - One of the operands used in the expression. + * @param expectedVal + * - expected result. + * @param booleanOperator + * - The operator in which the operands are compared. (i.e. ">, >=, + * <, <=, gt, ge, lt, le, ==, !=, eq, ne) + * @throws com.sun.ts.lib.harness.EETest.Fault + */ + private void testOperatorBoolean(Object testValOne, Object testValTwo, + Boolean expectedVal, String booleanOperator) throws Exception { + + boolean pass; + + NameValuePair values[] = NameValuePair.buildNameValuePair(testValOne, + testValTwo); + + try { + TestUtil.logTrace( + "*** Start " + "\"" + "String" + "\"" + " Test Sequence ***"); + + String expr = ExprEval.buildElExpr(false, booleanOperator); + TestUtil.logTrace("expression to be evaluated is " + expr); + TestUtil.logTrace("types are " + "String and String"); + + Object result = ExprEval.evaluateValueExpression(expr, values, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + + pass = (ExprEval.compareClass(result, Boolean.class) + && (((Boolean) result).equals(expectedVal))); + + } catch (Exception e) { + throw new Exception(e); + + } finally { + ExprEval.cleanup(); + TestUtil + .logTrace("*** End " + "\"" + "String" + "\"" + " Test Sequence ***"); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } + + // ---------------------------------------------------- Inner Classes + + private static class DougType implements Comparable { + + @Override + public String toString() { + + return "Beta"; + } + + public int compareTo(Object o) { + + if (o == null) + return -1; + return this.toString().compareTo(o.toString()); + } + + @Override + public boolean equals(Object o) { + + // test for null. + if (o == null) + return false; + + /* + * Since all DougType are staticly set to "Beta" All DougTypes are + * considered equal, and any other object is not. + */ + return (o instanceof DougType); + + } + + @Override + public int hashCode() { + return 42; + } + + } + + private static class NickType implements Comparable { + + @Override + public String toString() { + return "Gamma"; + } + + public int compareTo(Object o) { + + if (o == null) + return -1; + return this.toString().compareTo(o.toString()); + } + + @Override + public boolean equals(Object o) { + + // test for null. + if (o == null) + return false; + + /* + * Since all NickType are statically set to "Gamma" All NickTypes are + * considered equal, and any other object is not. + */ + return (o instanceof NickType); + + } + + @Override + public int hashCode() { + return 42; + } + + } + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/build.xml new file mode 100644 index 0000000000..babe4d0723 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/relationaloperator/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClient.java new file mode 100644 index 0000000000..3164484479 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/ELClient.java @@ -0,0 +1,857 @@ +/* + * Copyright (c) 2012, 2020 Oracle and/or its affiliates and others. + * All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.semicolonoperator; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.TypesBean; +import com.sun.ts.tests.el.common.util.Validator; + +import jakarta.el.ELProcessor; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + // does nothing at this point + } + + /** + * @testName: elSemiColonOperatorBigDecimalTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: To evaluate A;B, A is first evaluated, and its value is + * discarded. B is then evaluated and its value is returned. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckBigDecimal; a [operator] b" + * + * Variable A - BigDecimal + * + * Variable B - Rotating through the following types: + * BigDecimal, BigInteger, Integer, Float, Long, Short, + * Double, Byte + * + * Excluded: none + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorBigDecimalTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "BigDecimal"; + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a = types.tckBigDecimal; a + b", + BigDecimal.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckBigDecimal; a * b", + BigDecimal.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckBigDecimal; a - b", + BigDecimal.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckBigDecimal; a / b", + BigDecimal.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckBigDecimal; a div b", + BigDecimal.valueOf(1), comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a = types.tckBigDecimal; a % b", + Double.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a = types.tckBigDecimal; a mod b", + Double.valueOf(0), comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + + } // End elSemiColonOperatorBigDecimalTest + + /** + * @testName: elSemiColonOperatorFloatTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckFloat; a [operator] b" + * + * Variable A - Float + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorFloatTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Float"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if (excludeList.contains(bName)) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + elp.eval(bValue); + + if ("BigInteger".equals(bName)) { + // (+ operator) + Validator.testExpression(elp, "a = types.tckFloat; a + b", + BigDecimal.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckFloat; a * b", + BigDecimal.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckFloat; a - b", + BigDecimal.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckFloat; a / b", + BigDecimal.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckFloat; a div b", + BigDecimal.valueOf(1), comparitorA + " div " + bName); + + } else { + // (+ operator) + Validator.testExpression(elp, "a = types.tckFloat; a + b", + Double.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckFloat; a * b", + Double.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckFloat; a - b", + Double.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckFloat; a / b", + Double.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckFloat; a div b", + Double.valueOf(1), comparitorA + " div " + bName); + + } + + // The same for all other tested data types. + + // (% operator) + Validator.testExpression(elp, "a = types.tckFloat; a % b", + Double.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a = types.tckFloat; a mod b", + Double.valueOf(0), comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elSemiColonOperatorFloatTest + + /** + * @testName: elSemiColonOperatorDoubleTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckDouble; a [operator] b" + * + * Variable A - Double + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, Float + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorDoubleTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Double"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if (excludeList.contains(bName)) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + elp.eval(bValue); + + if ("BigInteger".equals(bName)) { + // (+ operator) + Validator.testExpression(elp, "a = types.tckDouble; a + b", + BigDecimal.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckDouble; a * b", + BigDecimal.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckDouble; a - b", + BigDecimal.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckDouble; a / b", + BigDecimal.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckDouble; a div b", + BigDecimal.valueOf(1), comparitorA + " div " + bName); + + } else { + // (+ operator) + Validator.testExpression(elp, "a = types.tckDouble; a + b", + Double.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckDouble; a * b", + Double.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckDouble; a - b", + Double.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckDouble; a / b", + Double.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckDouble; a div b", + Double.valueOf(1), comparitorA + " div " + bName); + + } + + // The same for all other tested data types. + + // (% operator) + Validator.testExpression(elp, "a = types.tckDouble; a % b", + Double.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a = types.tckDouble; a mod b", + Double.valueOf(0), comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elSemiColonOperatorDoubleTest + + /** + * @testName: elSemiColonOperatorBigIntegerTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckBigInteger; a [operator] b" + * + * Variable A - BigInteger + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, Float, Double + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorBigIntegerTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "BigInteger"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a = types.tckBigInteger; a + b", + BigInteger.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckBigInteger; a * b", + BigInteger.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckBigInteger; a - b", + BigInteger.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckBigInteger; a / b", + BigDecimal.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckBigInteger; a div b", + BigDecimal.valueOf(1), comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a = types.tckBigInteger; a % b", + BigInteger.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a = types.tckBigInteger; a mod b", + BigInteger.valueOf(0), comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elSemiColonOperatorBigIntegerTest + + /** + * @testName: elSemiColonOperatorIntegerTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckInteger; a [operator] b" + * + * Variable A - Integer + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorIntegerTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Integer"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a = types.tckInteger; a + b", + Long.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckInteger; a * b", + Long.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckInteger; a - b", + Long.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckInteger; a / b", + Double.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckInteger; a div b", + Double.valueOf(1), comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a = types.tckInteger; a % b", + Long.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a = types.tckInteger; a mod b", + Long.valueOf(0), comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elSemiColonOperatorIntegerTest + + /** + * @testName: elSemiColonOperatorLongTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckLong; a [operator] b" + * + * Variable A - Long + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorLongTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Long"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a = types.tckLong; a + b", + Long.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckLong; a * b", + Long.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckLong; a - b", + Long.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckLong; a / b", + Double.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckLong; a div b", + Double.valueOf(1), comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a = types.tckLong; a % b", + Long.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a = types.tckLong; a mod b", + Long.valueOf(0), comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elSemiColonOperatorLongTest + + /** + * @testName: elSemiColonOperatorShortTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckShort; a [operator] b" + * + * Variable A - Short + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer, + * Long + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorShortTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Short"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + excludeList.add("Long"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a = types.tckShort; a + b", + Long.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckShort; a * b", + Long.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckShort; a - b", + Long.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckShort; a / b", + Double.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckShort; a div b", + Double.valueOf(1), comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a = types.tckShort; a % b", + Long.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a mod b", Long.valueOf(0), + comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elSemiColonOperatorShortTest + + /** + * @testName: elSemiColonOperatorByteTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = types.tckByte; a [operator] b" + * + * Variable A - Byte + * + * Variable B - Rotating through the following types: Integer, + * Float, Long, Short, Double, Byte + * + * Exclude: BigDecimal, BigInteger, Float, Double, Integer, + * Long, Short + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorByteTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + String comparitorA = "Byte"; + + // excluded data types. + List excludeList = new ArrayList(); + excludeList.add("BigDecimal"); + excludeList.add("BigInteger"); + excludeList.add("Integer"); + excludeList.add("Double"); + excludeList.add("Float"); + excludeList.add("Long"); + excludeList.add("Short"); + + Iterator> iter; + + elp.defineBean("types", new TypesBean()); + + iter = TypesBean.getNumberMap().keySet().iterator(); + while (iter.hasNext()) { + Class bType = iter.next(); + String bValue = TypesBean.getNumberMap().get(bType); + String bName = bType.getSimpleName(); + + if ((excludeList.contains(bName))) { + TestUtil.logTrace("*** Skipping " + comparitorA + " with " + bName + + ", Already Tested in " + bName + " Test Sequence ***"); + + } else { + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a = types.tckByte; a + b", + Long.valueOf(2), comparitorA + " + " + bName); + + // (* operator) + Validator.testExpression(elp, "a = types.tckByte; a * b", + Long.valueOf(1), comparitorA + " * " + bName); + + // (- operator) + Validator.testExpression(elp, "a = types.tckByte; a - b", + Long.valueOf(0), comparitorA + " - " + bName); + + // (/ operator) + Validator.testExpression(elp, "a = types.tckByte; a / b", + Double.valueOf(1), comparitorA + " / " + bName); + + // (div operator) + Validator.testExpression(elp, "a = types.tckByte; a div b", + Double.valueOf(1), comparitorA + " div " + bName); + + // (% operator) + Validator.testExpression(elp, "a = types.tckByte; a % b", + Long.valueOf(0), comparitorA + " % " + bName); + + // (mod operator) + Validator.testExpression(elp, "a = types.tckByte; a mod b", + Long.valueOf(0), comparitorA + " mod " + bName); + + // Clean variables... + elp.eval("a = null"); + elp.eval("b = null"); + } + } + + } // End elSemiColonOperatorByteTest + + /** + * @testName: elSemiColonOperatorNullTest + * + * @assertion_ids: EL:SPEC:49.1 + * + * @test_Strategy: Validate that when we have variable A set to a specific + * data type that we coerce and receive back the correct value + * and Class type. + * + * Operators: +, -, *, /, div, %, mod + * + * Expression: "a = null; a [operator] b" + * + * Variable A - null + * + * Variable B - null + * + * @since: 3.0 + * + */ + public void elSemiColonOperatorNullTest() throws Exception { + + ELProcessor elp = new ELProcessor(); + elp.defineBean("types", new TypesBean()); + + Long expected = Long.valueOf(0); + String bValue = "b = types.tckNull"; + + elp.eval(bValue); + + // (+ operator) + Validator.testExpression(elp, "a = null; a + b", expected, "null + null"); + + // (- operator) + Validator.testExpression(elp, "a = null; a - b", expected, "null - null"); + + // (* operator) + Validator.testExpression(elp, "a = null; a * b", expected, "null * null"); + + // (/ operator) + Validator.testExpression(elp, "a = null; a / b", expected, "null / null"); + + // (div operator) + Validator.testExpression(elp, "a = null; a div b", expected, + "null div null"); + + // (% operator) + Validator.testExpression(elp, "a = null; a % b", expected, "null % null"); + + // (mod operator) + Validator.testExpression(elp, "a = null; a mod b", expected, + "null mod null"); + + } // End elSemiColonOperatorNullTest + +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/build.xml new file mode 100644 index 0000000000..0571616580 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/semicolonoperator/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClient.java b/el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClient.java new file mode 100644 index 0000000000..bf29b85123 --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/ELClient.java @@ -0,0 +1,540 @@ +/* + * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * $Id$ + */ + +package com.sun.ts.tests.el.spec.unaryoperator; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Properties; + +import com.sun.ts.lib.harness.Status; +import com.sun.ts.lib.harness.ServiceEETest; +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.el.common.util.ExprEval; +import com.sun.ts.tests.el.common.util.NameValuePair; + +public class ELClient extends ServiceEETest { + + Properties testProps; + + private final boolean[] deferred = { true, false }; + + public static void main(String[] args) { + ELClient theTests = new ELClient(); + Status s = theTests.run(args, System.out, System.err); + s.exit(); + } + + public void setup(String[] args, Properties p) throws Exception { + TestUtil.logTrace("Setup method called"); + this.testProps = p; + } + + public void cleanup() throws Exception { + } + + /* + * @testName: elNullUnaryTest + * + * @assertion_ids: EL:SPEC:20.1 + * + * @test_Strategy: Validate that if null is passed with the unary minus + * operator, the result is (Long) 0. Test both ${-null} & #{-null} + */ + public void elNullUnaryTest() throws Exception { + + boolean pass = false; + String[] symbols = { "$", "#" }; + + Long expectedResult = Long.valueOf("0"); + + try { + for (String prefix : symbols) { + String expr = prefix + "{-null}"; + TestUtil.logTrace("expression to be evaluated is " + expr); + + Object result = ExprEval.evaluateValueExpression(expr, null, + Object.class); + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult, 0)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elBigDecimalUnaryTest + * + * @assertion_ids: EL:SPEC:20.2 + * + * @test_Strategy: Validate that if a BigDecimal A is passed with the unary + * minus operator (-), the result is A.negate(). Test both ${- value} & #{- + * value} + */ + public void elBigDecimalUnaryTest() throws Exception { + + boolean pass = false; + + BigDecimal bd = BigDecimal.valueOf(10.0); + BigDecimal expectedResult = BigDecimal.valueOf(-10.0); + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(bd); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, BigDecimal.class) + && ExprEval.compareValue((BigDecimal) result, expectedResult, 0)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elBigIntegerUnaryTest + * + * @assertion_ids: EL:SPEC:20.2 + * + * @test_Strategy: Validate that if a BigInteger A is passed with the unary + * minus operator (-), the result is A.negate(). Test both ${- value} & #{- + * value} + */ + public void elBigIntegerUnaryTest() throws Exception { + + boolean pass = false; + + BigInteger bi = BigInteger.valueOf(100); + BigInteger expectedResult = BigInteger.valueOf(-100); + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(bi); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, BigInteger.class) + && ExprEval.compareValue((BigInteger) result, expectedResult, 0)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elDoubleStringUnaryTest + * + * @assertion_ids: EL:SPEC:20.3.1 + * + * @test_Strategy: Validate that if a String is passed with the unary minus + * operator (-), the result is as follows: - If the String contains ".", "e", + * or "E" coerce to Double, apply operator. + * + * Test both ${- value} & #{- value} + */ + public void elDoubleStringUnaryTest() throws Exception { + + boolean pass = false; + + String[] values = { "10.0", "10E0", "10e0" }; + + Double expectedResult = Double.valueOf("-10"); + + try { + for (boolean tf : deferred) { + for (String val : values) { + NameValuePair value[] = NameValuePair.buildUnaryNameValue(val); + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Double.class) + && ExprEval.compareValue((Double) result, expectedResult)); + } + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elLongStringUnaryTest + * + * @assertion_ids: EL:SPEC:20.3.2 + * + * @test_Strategy: Validate that if a String is passed with the unary minus + * operator (-), the result is as follows: - If the String does not contain + * ".", "e", or "E" coerce to Long, apply operator. + * + * Test both ${- value} & #{- value} + */ + public void elLongStringUnaryTest() throws Exception { + + boolean pass = false; + + String val = "100"; + + Long expectedResult = Long.valueOf("-100"); + + try { + for (boolean tf : deferred) { + NameValuePair value[] = NameValuePair.buildUnaryNameValue(val); + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elByteUnaryTest + * + * @assertion_ids: EL:SPEC:20.4.1 + * + * @test_Strategy: Validate that if a Byte is passed with the unary minus + * operator (-), the type is retained and the operator is applied. + * + * Test both ${- value} & #{- value} + */ + public void elByteUnaryTest() throws Exception { + + boolean pass = false; + + byte num = 1; + byte expectedResult = -1; + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(num); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Byte.class) + && ExprEval.compareValue((Byte) result, expectedResult)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elShortUnaryTest + * + * @assertion_ids: EL:SPEC:20.4.1 + * + * @test_Strategy: Validate that if a Short is passed with the unary minus + * operator (-), the type is retained and the operator is applied. + * + * Test both ${- value} & #{- value} + */ + public void elShortUnaryTest() throws Exception { + + boolean pass = false; + + short num = 1; + short expectedResult = -1; + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(num); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Short.class) + && ExprEval.compareValue((Short) result, expectedResult)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elIntegerUnaryTest + * + * @assertion_ids: EL:SPEC:20.4.1 + * + * @test_Strategy: Validate that if an Integer is passed with the unary minus + * operator (-), the type is retained and the operator is applied. + * + * Test both ${- value} & #{- value} + */ + public void elIntegerUnaryTest() throws Exception { + + boolean pass = false; + + int num = 1; + int expectedResult = -1; + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(num); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Integer.class) + && ExprEval.compareValue((Integer) result, expectedResult)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elLongUnaryTest + * + * @assertion_ids: EL:SPEC:20.4.1 + * + * @test_Strategy: Validate that if a Long is passed with the unary minus + * operator (-), the type is retained and the operator is applied. + * + * Test both ${- value} & #{- value} + */ + public void elLongUnaryTest() throws Exception { + + boolean pass = false; + + long num = 10000; + long expectedResult = -10000; + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(num); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Long.class) + && ExprEval.compareValue((Long) result, expectedResult)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elFloatUnaryTest + * + * @assertion_ids: EL:SPEC:20.4.1 + * + * @test_Strategy: Validate that if a Float is passed with the unary minus + * operator (-), the type is retained and the operator is applied. + * + * Test both ${- value} & #{- value} + */ + public void elFloatUnaryTest() throws Exception { + + boolean pass = false; + + float num = 10000f; + float expectedResult = -10000f; + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(num); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Float.class) + && ExprEval.compareValue((Float) result, expectedResult, 0)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elDoubleUnaryTest + * + * @assertion_ids: EL:SPEC:20.4.1 + * + * @test_Strategy: Validate that if a Double is passed with the unary minus + * operator (-), the type is retained and the operator is applied. + * + * Test both ${- value} & #{- value} + */ + public void elDoubleUnaryTest() throws Exception { + + boolean pass = false; + + double num = 10000.0; + double expectedResult = -10000.0; + + NameValuePair value[] = NameValuePair.buildUnaryNameValue(num); + + try { + for (boolean tf : deferred) { + + String expr = ExprEval.buildElExpr(tf, "unary_minus"); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Double.class) + && ExprEval.compareValue((Double) result, expectedResult)); + } + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + + } catch (Exception e) { + throw new Exception(e); + } + } + + /* + * @testName: elBooleanUnaryFalseTest + * + * @assertion_ids: EL:SPEC:24.1.1 + * + * @test_Strategy: Validate that if a String("false") is passed with the unary + * "not" operator, the type is coerced to Boolean and the operator is applied. + * + * Equations Tested: ${not value} & #{not value} ${! value} & #{! value} + */ + public void elBooleanUnaryFalseTest() throws Exception { + + this.testUnary("false", true); + + } + + /* + * @testName: elBooleanUnaryTrueTest + * + * @assertion_ids: EL:SPEC:24.1.1 + * + * @test_Strategy: Validate that if a String("true") is passed with the unary + * "not" operator, the type is coerced to Boolean and the operator is applied. + * + * Equations Tested: ${not value} & #{not value} ${! value} & #{! value} + */ + public void elBooleanUnaryTrueTest() throws Exception { + + this.testUnary("true", false); + + } + + // ---------------------------------------------------------- private methods + + private void testUnary(String testVal, boolean expectedResult) throws Exception { + + boolean pass = false; + + String[] operator = { "unary_not", "unary_bang" }; + NameValuePair value[] = NameValuePair.buildUnaryNameValue(testVal); + + try { + for (boolean tf : deferred) { + for (String op : operator) { + String expr = ExprEval.buildElExpr(tf, op); + Object result = ExprEval.evaluateValueExpression(expr, value, + Object.class); + + TestUtil.logTrace("result is " + result.toString()); + pass = (ExprEval.compareClass(result, Boolean.class) + && ExprEval.compareValue((Boolean) result, expectedResult)); + + if (!pass) + throw new Exception("TEST FAILED: pass = false"); + } + } + } catch (Exception e) { + throw new Exception(e); + } + } +} diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/build.xml b/el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/build.xml new file mode 100644 index 0000000000..1c70fbe41a --- /dev/null +++ b/el/src/main/java/com/sun/ts/tests/el/spec/unaryoperator/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index e2049cf6bf..2558476fe3 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ ejb30-ws ejb32 el + el-tck integration javaee javamail