Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade project to Java EE 7 (+ TomEE 7 webprofile) #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mojavelinux
Copy link

  • upgrade to TomEE 7.0.2 webprofile
  • switch to the Java EE 7 API (TomEE provided)
  • add Arquillian BOM
  • upgrade to Arquillian 1.1.11.Final
  • set Java source/target compatibility to 1.8
  • use JAX-RS 2 client API in tests
  • add JAX-RS 2 client API and providers to test runtime
  • annotate Arquillian test with @RunAsClient
  • add JAX-RS application initializer (required for portability)
  • upgrade Gradle wrapper to 3.2.1
  • fix Gradle build, add Arquillian dependencies
  • rename ColorService to ColorResource
  • use consistent project name
  • exclude version from name of war file
  • update instructions in README
  • fix AsciiDoc syntax in README
  • stub in TomEE remote adapter and configuration for tests

@mojavelinux
Copy link
Author

@dblevins Here's your xmas gift from me and the Arquillian family! 👽 🎄 🎁

You may want to create a javaee-7 branch upstream so master doesn't shadow the setup for Java EE 6 (and break the reference in the blog post). You could also move master to a javaee-6 branch and make this version the master. I'm fine with either approach, as long as this version is accessible.

/**
* Reusable utility method
* Move to a shared class or replace with equivalent
*/
public static String slurp(final InputStream in) throws IOException {
private String slurp(final InputStream in) throws IOException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed using response.readEntity(String.class), no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course! Thanks for the tip.

client.register(Class.forName(JSON_PROVIDER_CLASS));
}
catch (ClassNotFoundException e) {}
return client.build().target(webappUrl.toURI()).path(getApplicationPath());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to close the client ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

final ClientBuilder client = ClientBuilder.newBuilder();
try {
// client side
client.register(Class.forName(JSON_PROVIDER_CLASS));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not using "new" since the class is hardcoded? In embedded mode we should also inherit from the provider by default IIRC (not in remote indeed but you used embedded adapter there)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stubbed in support in the pom for switching to the remote adapter, so I made the test portable. I didn't reference the JohnzonProvider directly so that the class would compile without any adapters or extra jars on the classpath.

*/
@RunWith(Arquillian.class)
public class ColorServiceTest extends Assert {
@RunAsClient

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not testable=false which avoids to pollute the war and run as client implicitely (or both if you want it to be obvious)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what @RunAsClient does. If it's set on the class, it automatically implies testable=false on all deployments. You only need the testable flag if you're trying to mix client and server test cases in the same test class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. It turns out that despite the fact that Aslak and I discussed this, it doesn't seem to have ever been implemented in core. So the testable=false is still required to keep the test class from being deployed. But we will want @RunAsClient so that the tests are executed from outside the server.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes cause with some component like warp you need to enrich the archive but run on client side. Issue is only the naming of "testable" which should have been "enrichable" or something like that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. The annotation needs work. It's too ambiguous at the moment. We'll take it upstream.

<groupId>org.apache.openejb</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>${tomee.version}</version>
<groupId>org.apache.geronimo.specs</groupId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt be needed in embedded mode, which dependency do we miss to require it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency, as well as cxf-rt-rs-client and johnzon-jaxrs, are required for running the test with TomEE remote. I've moved these dependencies to a comment block and documented when they need to be enable. You are correct that they are not required to run the test on embedded.

<version>${tomee.version}</version>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${cxf.version}</version>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, should be in tomee jaxrs transitively fetched by arquillian adapter

<!-- NOTE JAX-RS JSON integration must be provided on client side -->
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jaxrs</artifactId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, should be in tomee jaxrs transitively fetched by arquillian adapter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, only needed for the remote adapter. The reason for the very specific dependencies for that scenario was to limit number of items on the classpath. I figured out exactly which jars were needed.

@mojavelinux
Copy link
Author

Thanks for the feedback! I'll make the necessary updates.

@mojavelinux
Copy link
Author

I've updated the project.

I kept the configuration for the TomEE remote adapter in place, but put it in comments so it's easy to swap in. Personally, I prefer to test on a server that's isolated from the test so the dependencies and classpath of the server don't leak into my test. For me, it's more clear what's going on this way.

(Btw, the TomEE remote adapter should really be named TomEE managed. As far as I'm concerned, TomEE doesn't have a remote adapter).

- upgrade to TomEE 7.0.2 webprofile
- switch to the Java EE 7 API (TomEE provided)
- add Arquillian BOM
- upgrade to Arquillian 1.1.11.Final
- set Java source/target compatibility to 1.8
- use JAX-RS 2 client API in tests
- add JAX-RS 2 client API and providers to test runtime
- annotate Arquillian test with @RunAsClient
- add JAX-RS application initializer (required for portability)
- upgrade Gradle wrapper to 3.2.1
- fix Gradle build, add Arquillian dependencies
- rename ColorService to ColorResource
- use consistent project name
- exclude version from name of war file generated by Maven
- update instructions in README
- fix AsciiDoc syntax in README
- stub in TomEE remote adapter and configuration for tests
@rmannibucau
Copy link

Looks good to me now (will not discuss more the provider point even if portability doesn't exist in this area until we have jsonb by default).

@dblevins how do you want to manage the branches? Personally I'm fine getting this PR on master and updating the post with links using the commit sha but 2 branches are ok too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants