Skip to content

Commit

Permalink
Add TCK tests for default method support in BeanELResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Dec 20, 2021
1 parent d0220f2 commit 9c9b056
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 2009, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -89,6 +89,80 @@ public void beanELResolverTest() throws Fault {
TestUtil.logTrace(buf.toString());
}

// Disabled until EL #168 is addressed
//
// /**
// * @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 Fault {
//
// 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 Fault(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 Fault {

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 Fault(ELTestUtil.FAIL + buf.toString());
}
TestUtil.logTrace(buf.toString());
}

/**
* @testName: beanELResolverInvokeTest
* @assertion_ids: EL:JAVADOC:9; EL:JAVADOC:11; EL:JAVADOC:12; EL:JAVADOC:13;
Expand Down
5 changes: 3 additions & 2 deletions src/com/sun/ts/tests/el/common/util/SimpleBean.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved.
* 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
Expand All @@ -18,7 +19,7 @@

import java.io.Serializable;

public class SimpleBean implements Serializable {
public class SimpleBean implements Serializable, SimpleInterface {

private String fullName = "Doug Donahue"; // Default Setting

Expand Down
30 changes: 30 additions & 0 deletions src/com/sun/ts/tests/el/common/util/SimpleInterface.java
Original file line number Diff line number Diff line change
@@ -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) {
}
}

0 comments on commit 9c9b056

Please sign in to comment.