Closed starksm64 closed 1 month ago
@scottmarlow is it easy enough to get the throws type?
One potential problem I see with this example is that there are testName comments in the com.sun.ts.tests.ejb30.assembly.librarydirectory.custom.Client
class that refer to methods in the com.sun.ts.tests.ejb30.assembly.common.ClientBase
base class. For example, the remoteAddByHelloEJBFromAssemblyBean
method. The base class method does use a different throws type, and is marked with the testName tag in the method comment:
/*
* testName: remoteAddByHelloEJBFromAssemblyBean
*
* @assertion_ids:
*
* @test_Strategy: hello ejb is packaged as a standalone ejb module and
* deployed separately. It client view jar is packaged inside current ear and
* referenced by both appclient and ejb jar thru MANIFEST.MF appclient ->
* assemblyBean -> helloBean
*/
public void remoteAddByHelloEJBFromAssemblyBean() throws Exception {
String result = remoteAssemblyBean.callHelloBean();
if (result != null) {
TLogger.log("Got expected result: " + result);
} else {
throw new Exception(
"Expecting a non-null result from remoteAssemblyBean.callHelloBean(), but got null.");
}
}
@scottmarlow see the standalone JavaTestNameVisitor class I'm using in the javafx app to parse the test method names. This is a standalone usage of the JavaParser from openrewrite without any rewrite rules usage to simply gather the method names from the class.
I figured out how to get the references to superclass methods that are not overriden by looking at the block end comments. See the visitBlock(J.Block block, ExecutionContext executionContext)
method. This does not go to the superclass method to try to get the correct throws type. It just assumes Exception for now.
Just as an fyi.
https://github.com/jakartaee/platform-tck/blob/main/ejb30/src/main/java/com/sun/ts/tests/ejb30/assembly/appres/appclientejb/Client.java#L125 is an example of two tests that do not throw an exception and for that reason, I will allow the case of zero exceptions (currently I throw an exception if there are zero exceptions or more than one exceptions being thrown).
If we hit any cases of tests throwing more than one exception, we can retool for that by not failing and also update TestMethodInfo to allow multiple exceptions to be thrown.
https://github.com/jakartaee/platform-tck/blob/main/ejb30/src/main/java/com/sun/ts/tests/ejb30/bb/async/common/annotated/AnnotatedClientBase.java#L153 is a test method that does have two exceptions in the throws clause.
If there are going to be a non-trivial number of custom exceptions on test methods, we will need to update the api to take the method name and exception type to throw, e.g., something like
Should we close this issue and open a new one for allowing multiple exceptions in the throws clause like https://github.com/jakartaee/platform-tck/blob/main/ejb30/src/main/java/com/sun/ts/tests/ejb30/bb/async/common/annotated/AnnotatedClientBase.java#L153?
I think this issue can be closed as complete. You can already just passing multiple exceptions to the throwsException string as that is just output as is with a "throws " in front of it. Here is an example of two exceptions that works:
@Test
public void testejb32_lite_timer_basic_concurrency() throws IOException {
TestPackageInfoBuilder builder = new TestPackageInfoBuilder(tsHome);
List<TestMethodInfo> testMethods = Arrays.asList(
new TestMethodInfo("lookupTimerService", "InterruptedException, java.util.concurrent.ExecutionException"),
new TestMethodInfo("writeLockTimeout", "")
);
Class<?> baseTestClass = com.sun.ts.tests.ejb32.lite.timer.basic.concurrency.Client.class;
TestPackageInfo packageInfo = builder.buildTestPackgeInfoEx(baseTestClass, testMethods);
System.out.println(packageInfo);
System.out.println(packageInfo.getTestClientFiles());
}
The com.sun.ts.tests.ejb30.assembly.librarydirectory.custom.Client is throwing a custom com.sun.ts.tests.ejb30.common.helper.TestFailedException, and this breaks the code generation as the overriden method does not have the correct throws clause.
If there are going to be a non-trivial number of custom exceptions on test methods, we will need to update the api to take the method name and exception type to throw, e.g., something like:
and then TestPackageInfoBuilder#buildTestPackgeInfo would be:
Here is the Client code: