Adam Bien's Weblog

Vanilla Java EE Productivity In Costa Rica

Marvin (@mmongecr), could you please introduce yourself?

My name is Marvin Monge, I am a Senior Java Developer and SysAdmin at Flecha Roja Technologies, Oracle Certified Professional Java SE 6 Programmer, Oracle Certified Professional Java SE 7 Programmer, Oracle Certified Expert Java EE 6 Java Persistence API Developer, Oracle WebLogic Server 12c Certified Implementation Specialist and Oracle Linux Certified Implementation Specialist.

I have been programming since 2005, started with Oracle Forms & Reports, PL/SQL and Oracle Database. Then I moved for a while to LAMP websites and then to Oracle Apex. I always was interested in Java but the opportunity to learn never showed up until I reached Flecha Roja Technologies.

Flecha Roja was a partner of my employer at that time and I saw lots of interesting things they developed. I wanted to work with them, but I did not had the required Java knowledge. After a recommendation of my friend I was hired by Flecha Roja's CTO Gerardo Arroyo. And I started to polish my Java skills. At that time Flecha Roja used Java EE 5 with Seam.

In that time Java EE 5 was harder than Java EE 7 nowadays, a lot of boilerplate code and XML config files. I learned the basics of Java and Java EE 5 thanks to Gerardo Arroyo.

Then I improved my skills with the unlimited help of Flecha Roja. They bought me every book and certification exam that I asked for. For Flecha Roja the interest in learning is the most important skill of an employee.

Today I'm preparing myself for the Oracle Certified Professional Java SE 8 Programmer exam and learning about AngularJS, Microservices, Docker, Kubernetes and the Red Hat JBoss products.

At the workshops.adam-bien.com in MUC you told us about a big Java EE cluster. What is the aim of the application?

It is a solution (many Java/Java EE 5 applications) that connects to some heterogeneous databases (Oracle DB, IBM DB2, MS SQL Server and IBM Mainframe) to gather information about real properties and goods used in a shopping cart, the products sold are certificated documents. You buy the quantity of documents you want and you keep them in an inventory. You can generate the document with the appropriate parameters to get the required information at any time. The applications also haves free consultations to gather information without certification.

The solution exposes SOAP webservices consumed by the shopping cart and for integrations with other government entities.

There are around 13 applications that exposes webservices for data gathering and integration, 4 web applications (some for final users and others for administration and reporting) and 8 Java applications that runs with Linux crontabs for some alerts, deferred processes and data synchronization.

How popular is Java / Java EE in Costa Rica?

Java is very popular and it's taught at almost all universities.

Java EE is getting more and more popular, but many programmers are still using the outdated J2EE patterns.

Which application servers, tools and IDEs are you using?

Application Servers:

  • JBoss EAP 6.4.x and Wildfly 10
  • Oracle Weblogic 12c
  • IBM Web Application Server 7 (Legacy)

Tools:

  • Docker Toolbox
  • Paw
  • Atom
  • MacDown
  • Dash for OSX
  • OWASP ZAP
  • Oracle Data Modeler
  • Git
  • Maven

IDEs:

  • Netbeans 8.1

How important is the Java EE standard to you? Is your code dependent on application server specific features?

No, my code is Java EE standard. Sometimes I have to tune Weblogic or JBoss for better performance. Such changes can be reversed in seconds and source code is rarely affected at all.

You attended the workshops.adam-bien.com in Munich with attendees from all over the world. What surprised you the most?

Well..., here in Costa Rica I never heard about Vaadin been used in any project but some days before my trip to Europe our company was contacted from a client in Colombia to check some performance problems with an old Vaadin application running on Weblogic. It surprised me to see how many attendees use Vaadin for develop and the great tips you were giving about the best way to separate the business logic from the Vaadin UI with a REST API to prevent problems later with new versions or the possible migration to Java EE. It was a great experience hear from everyone what they were doing and the problems that they were facing.

Is Java EE productive? What is your opinion?

For me, Java EE is a complete productive platform. You can create a complete application without any other dependency than javaee-api. It's pretty quick to develop with Java EE, and the Java language is beautiful :-) and keeps getting better!

Is you company hiring Java EE developers?

Yes, we are hiring Java EE developers and actually we hired 3 Junior Java Developers two weeks ago and I have been training them in Java EE.

If you are a Java EE developer with experience and you want to work at Costa Rica, please apply at info@flecharoja.com.

Any links you would like to share with us?

Marvin, thank you for the interview!


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Injecting Properties Into Java EE Applications

To make basic datatypes injectable into POJOs, like:


    @Inject
    private String greeting;

    @Inject
    private int intValue;


...you will have to expose them first. The name of field may act as the lookup key:


//...

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

public class Configurator {

	//...

    @Inject
    Instance<Map<String, String>> initialValues;

    public void init() {
        this.store = //...
        for (Map<String, String> initial : initialValues) {
            this.store.putAll(initial);
        }
    }


    @Produces
    public String getString(InjectionPoint ip) {
        String className = ip.getMember().getDeclaringClass().getName();
        String key = className + "." + ip.getMember().getName();
        String fieldName = computeKeyName(ip.getAnnotated(), key);
        return this.store.get(fieldName);
    }

    String computeKeyName(Annotated annotated, String key) {
        Configurable annotation = annotated.getAnnotation(Configurable.class);
        return annotation == null ? key : annotation.value();

    }

    @Produces
    public long getLong(InjectionPoint ip) {
        String stringValue = getString(ip);
        if (stringValue == null) {
            return 0;
        }
        return Long.parseLong(stringValue);
    }
}


The conventional field name as lookup key can be overridden with an annotation:

    @Inject
    @Configurable("msg")
	String message;


The annotation is expects a single string which is going to be used as a key:


@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Configurable {
    String value();
}

Now you only need to expose a datasource of your choice as Map<String, String>, like e.g. environment variables or System-properties to make them injectable:


import javax.enterprise.inject.Produces;

public class Initializer {

    @Produces
    public Map<String, String> getInitialConfiguration() {
    	//...fetch properties from wherever you like
    }
}

"How to inject properties into Java EE apps" was one of the questions in the recent airhacks.tv.

The code above was taken from JCache Configurator for Java EE -- a one-class Java EE framework. See also the Java Magazine article Convention Over Configuration in Java EE 6.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Is It Possible To Create You Own JSR? -- An Interview About Java Community Process (JCP) with Heather VanCura

Heather please introduce yourself.

I lead the JCP Program Management Office (PMO) at Oracle, and am responsible for the day-to-day nurturing, support, and growth of the community, including the JCP.org web site, JSR management, community building, events, marketing, communications, and membership. I am also a leader of the global Adopt-a-JSR programs, working with Java User Groups (JUGs) around the world. In 2014, I took on the role of serving as Spec Lead of JSR 364, Broadening JCP Membership, which is evolving the JCP program itself. For JCP updates follow @jcp_org on Twitter. You can also find me @heathervc.

What is the relation between JCP and Oracle?

Oracle has a permanent seat on the JCP Executive Committee (EC), and together with the other EC members, the EC votes on the work of the Expert Groups and evolves the JCP itself. The EC is led by a non-voting Chair from the PMO; the PMO is the group within Oracle that is responsible for administering the JCP and chairing the EC. The EC does not micro-manage the day-to-day workings of Expert Groups - the EC has the opportunity to review the work of each Expert Group at well-defined points as their specifications proceed through the JCP program. The primary function of the EC is to ensure that specifications do not overlap or conflict with one another and that the specifications meet the needs of the industry segment for which they are being written.

How democratic is JCP? How much power has the community?

Anyone with an internet connection can review and comment on draft specifications and JSR proposals on JCP.org. Anyone with an internet connection and an e-mail address can register as a user of the site. Any registered user can nominate himself for an Expert Group (but must be JCP Members to serve), maintain a watch list of JSRs of interest,request to be associated with an existing JCP Member, or become a JCP Member. Any organization or individual which has signed a Java Specification Participation Agreement (JSPA) has become a JCP Member.

JCP Members can propose new JSRs, serve on Expert Groups, vote in the annual Executive Committee elections process, and run for a seat on an Executive Committee.

How hard is the introduction of a new JSR by an individual?

Any full JCP Member can submit a Java Specification Request (JSR) for approval by the EC. The Specification Lead is a representative of a JCP Member who leads a group of experts in developing a specification described in a JSR, and is responsible for delivering the Specification, the Reference Implementation (RI), and the Technology Compatibility Kit (TCK) for the JSR. These things together are a substantial software deliverable, and it does take quite a bit of effort on the part of the Individual, but there are a few Individuals that have successfully led JSRs to completion.

Some JSRs are in "maintenance mode". How much changes or additions are allowed? When it is better to introduce a new JSR?

Maintenance is for making minor changes to a JSR once it has completed the Final Release of the specification. Maintenance is an optional stage, since Spec Leads may choose to complete work at Final Release or present major changes or features to the specification in a new JSR. If significant changes are desired, a new JSR should be submitted by the Spec Lead. The community may submit requests for clarification, interpretation, and enhancements to the Specification by logging issues through the JSR's Issue Tracker. All changes proposed make their way into the Specification either through the Maintenance process or through a new JSR. Changes appropriate for Maintenance include bug-fixes, clarifications of the Specification, changes to the implementation of existing APIs, and implementation-specific enhancements.

Is it possible to take-over an "abandoned" or inactive JSR? Which steps are to take in such a case?

This is addressed in the JCP Process document section 1.2.4:

"There may be rare instances when members of the Expert Group feel that the Spec Lead is not acting in ways that advance the work of the Expert Group and is being unresponsive or inactive. The EG is expected to make a reasonable effort to resolve any such issues in a timely manner. However, if the situation cannot be resolved these concerns should be brought to the attention of the EC as quickly as possible so they may be proactively addressed and resolved. If the problems cannot be resolved informally, any three members of the EG may request the EC to replace the Spec Lead. All such requests must clearly state the cause of the concern and provide all necessary evidence. If the EC agrees that there is cause, it may ask the PMO to replace the Spec Lead. In the case where the Spec Lead is a Member Representative the PMO shall ask the Member to replace the Spec Lead. If the Member refuses to do so, the PMO shall seek to put in place an alternative Spec Lead, in which case the EC must conduct a transfer ballot as specified in section 5.1.2 of the JCP Process document: If no Spec Lead replacement can be found, the EC shall initiate a JSR Renewal Ballot to determine whether the JSR should be shut down. If the Maintenance Lead decides to discontinue his or her work at any time (including discontinuing maintenance activities or declining to take on the role of Spec Lead during a significant revision initiated by a new JSR) the ML, with the assistance of the PMO, should make a reasonable effort to locate another Member who is willing to take on the task. If a replacement is identified the PMO must initiate a Transfer Ballot within 30 days to enable EC members to approve the transfer of responsibilities. If the ballot succeeds, the new ML must assume his or her responsibilities within 30 days. If no replacement can be found, or if the Transfer Ballot fails, then the PMO shall declare the Specification to be Dormant and no further maintenance can be carried out. No further Transfer Ballots will be initiated by the PMO unless a Member volunteers as ML, in which case the PMO will again have 30 days to initiate a Transfer Ballot."

The JCP process is continuously changed and versioned. Who decides when it is time to introduce a new version? How frequently new versions are released?

We call this effort 'JCP.Next', and evolving the JCP program itself is addressed in Appendix A of the JCP Process Document:

Revisions to the Java Community Process (JCP) and the Java Specification Participation Agreement (JSPA) are be carried out using the Java Community Process with the following changes:

Only EC members can initiate a JSR to revise one of these documents.
The EC must approve the JSR.
The Expert Group consists of all EC members with a member of the PMO as Spec Lead.
There is no Reference Implementation or Technology Compatibility Kit to be delivered and no TCK appeals process to be defined.
There is not a specified time for new versions of the JCP program to be released, but we are listening and responding to the needs of the community over time. To give you an idea of the history, in June 2000, JCP 2.0 replaced the previous JCP 1.0 version for new submissions. Further refinements to the voting rules resulted in JCP 2.1, introduced in July 2001. A major revision of the licensing rules for the Spec, RI and TCK as well as IP policy changes and process changes was put in place by JCP 2.5, launched on October 29, 2002. The process was revised in May 2006 with the release of JCP 2.6, and in May 2009 with JCP 2.7. In October 2011 we introduced JCP 2.8 to open up the operations of JSR expert groups and increase transparency. The current version of the process is JCP 2.9, which was introduced in August 2012. We are now in the process of finalizing JCP 2.10 through JSR 364, Broadening JCP Membership.

This JSR is in Proposed Final Draft stage and is expected to complete in 2016 - a good topic for a future conversation :)!

How hard is it to change / improve the JCP process itself?

The JSR lifecycle process works very efficiently and transparently. As you can see from the timeline above, describing the evolution of the different versions of the JCP, it is an effort that takes some time working together with the developer community and the JCP EC Members, who serve as members of the JSR expert group. For minor changes, the maintenance process described earlier, can also be used for updates to the JCP program itself.

Are the differences in the governance / process / handling of the different platforms like Java EE, Java SE and Java ME?

In 2012, JCP 2.9 merged the two Executive Committees (Standard/Enterprise Edition and Micro Edition) into one single Executive Committee. The merged Executive Committee votes on all JCP 2.x JSRs now, regardless of which JCP 2.x version it is.

Many questions can also be answered in the FAQ: www.jcp.org/en/introduction/faq

Heather, thank you for the interview!


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Converting a Map Into javax.json.JsonObject with Java 8

With a custom Collector:


import java.util.Map;
import java.util.stream.Collector;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;


public interface JsonCollectors {

    public static <T> Collector<Map.Entry<T, T>, ?, JsonObjectBuilder> toJsonBuilder() {
        return Collector.of(Json::createObjectBuilder, (t, u) -> {
            t.add(String.valueOf(String.valueOf(u.getKey())), String.valueOf(u.getValue()));
        }, JsonCollectors::merge);
    }

    static JsonObjectBuilder merge(JsonObjectBuilder left, JsonObjectBuilder right) {
        JsonObjectBuilder retVal = Json.createObjectBuilder();
        JsonObject leftObject = left.build();
        JsonObject rightObject = right.build();
        leftObject.keySet().stream().forEach((key) -> retVal.add(key, leftObject.get(key)));
        rightObject.keySet().stream().forEach((key) -> retVal.add(key, rightObject.get(key)));
        return retVal;
    }
}


...a Map<String, String> can be easily converted into a JsonObject:

    public JsonObject environmentVariables() {
        Map<String, String> environment = System.getenv();
        return environment.entrySet().
        stream().
        collect(JsonCollectors.toJsonBuilder()).
		build();
    }

The sample above is taken from github.com/AdamBien/ping

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

LightFish "SkinnyFish" Payara / GlassFish monitoring tool released

LightFish v1.3.2 (aka SkinnyFish) monitoring tool is available. No major features were implemented, but the performance and resource consumption were greatly improved.

To install LightFish deploy the 364 kB WAR to Payara / GlassFish. The optional "lighview" client is also available for download.

See you at Java EE Workshops at Munich Airport, Terminal 2 and particularly at Java EE 7 Microservices. Sometimes I use LightFish to illustrate bulkheads.


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

The Only One Dependency You Need In Java EE 7

Java EE 7 projects need only one single dependency in pom.xml:


<dependency>
	<groupId>javax</groupId>
	<artifactId>javaee-api</artifactId>
	<version>7.0</version>
	<scope>provided</scope>
</dependency>

This javaee-api dependency contains all Java EE 7 APIs (from EJB, JTA, JCA over CDI to JPA), is 1.8 MB big and because the server implements the APIs, it never ships with the WAR.

Mainstream Java EE projects can be easily built with the following pom.xml:


<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.airhacks/groupId>
    <artifactId>skinny</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>skinny</finalName>
    </build>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
</project>

Gradle build script has similar length:


def WAR_NAME='skinny.war'
apply plugin: 'war'
apply plugin: 'maven'
group = 'com.airhacks'
version = '0.0.1-SNAPSHOT'

repositories {
    mavenCentral()
}
dependencies {
    providedCompile 'javax:javaee-api:7.0'
}

compileJava {
    targetCompatibility = '1.8'
    sourceCompatibility = '1.8'
}

war{
    archiveName WAR_NAME
 }

Project structure for skinny projects can be easily created with mvn archetype:generate -Dfilter=com.airhacks:javaee7-essentials-archetype.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Java EE 8 News, Documentation, Production Issues, Multiple REST Endpoints, Maven Or Gradle: 23rd Airhacks.tv Questions and Answers

The longest show with the most live viewers (134) with Java EE 8 news and questions about WildFly, JBoss, microservices (of course :-)), architecture documentation, HTTP setup, SSO (...) is online:

Any questions left? Start asking and get answers at March, 7th, 6 pm CET: ustream.tv/channel/adambien. Archive is also available: airhacks.tv.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Afraid to fly? Learn from home: airhacks.io.


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Extreme Productivity With Java EE: In 35 Days Helping 20.000 Families

Mohamed, please introduce yourself.

My name is Mohamed Taman and I am an Enterprise Architect & Software Development Manager at e-finance, Java Champions, Adopt-a-JSR, JCP member, was JCP Executive Committee member, JSR 358, 354, 364, & 363 Expert Group member, MoroccoJUG board, EGJUG leader, Oracle Egypt Architects Club board member, speaks Java, loves mobile, international speaker. Won the 11 annual JCP awards 2013 for Outstanding adopt-a-JSR participant, and Duke's Choice Award 2014, 2015.

How popular is Java / Java EE in Egypt?

Java EE is very popular in Egypt as development technology stack. 70% of projects developed in Egypt they are using Java EE as web development, also we strongly introduces Java in universities, Java community, beside after graduate institutes famously ITI which gives diplomas specifically in Java track for post graduates to cope with market needs, And we as EGJUG do this too for our strong community.

Which application servers, tools and IDEs are you using?

Me and my team recently moved to use NetBeans IDE, and JDeveloper too, using eclipse for some projects, from application servers point of view we uses IBM WebSphere in production, beside Oracle Weblogic, GlassFish, and recently trying to use Payara and Wildfly.

What are the most impressive Java EE projects you were involved so far?

Currently there are many projects I am working on around 34 Java EE projects and support others at the same time.

What are you building with Java EE right now?

I am working on a project which won 2015 duke’s choice award, as extended success of previous United Nations UNHCR/WFP Subsidy Card for refugees’ which also won duke’s choice award 2014, We have been asked to build a system that helps poor people having children listed basic education levels under Ministry of Education in each country, to get their benefits (Cache for Food (from UNWFP)) through secured cards, controlled by WFP organization and developed and operated by efinance in 2 months.

The key challenge here was the Huge System, time-to-market, lack of detailed requirements (6 modules to be developed), POS programming, and JavaFX Tablet based Application for registration (offline), Card EMV and applet / lifecycle management, and should be costless, Short time to deliver the application, risk of new technology usage.

Architected, developed, and tested in 35 days. Result; It is now live application applied to Egypt as pilot that helps 20,000 families in 2 poor cities (Louxor, and Sohag). By the end of this year will be 500,000 families covering all main Egyptian cities, and rolled out to other countries.

Is Java EE productive? What is your opinion?

Yes very productive as I have mentioned before at JavaOne 2014 strategic keynote with Cameron Burdy, especially the convention is it work by default without any configuration, “Configuration by exception”, also introduction of web profiles makes final product (war file) more light and les resource consuming, beside introduction to new JSRs that helps development standardization without using third party libraries.

How important is the Java EE standard to you? Is your code dependent on application server specific features?

As JCP member involved in many JSRs especially the new ones, The standardization means freedom of development and portability which makes it easy to migrate from app server to another smoothly, with application servers that follow the same Java EE standards.

Is you company hiring Java EE developers?

Yes indeed as Java team is a core of the Business solution software development and innovations, my department consist of the following sub-departments:

  1. Java Team (6 members will grow to 12 by the end of this year)
  2. Quality Control team (3 QC Java engineers).
  3. Architecture team
  4. System Analysis team
  5. Research & development team

Any links you would like to share with us?

  1. Duke choice award 2014
  2. Duke choice award 2015
  3. tamanmohamed.blogspot.com.eg

Mohamed, thank you for the interview! I'm already looking forward to the Duke choice awards 2016 :-)


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Configuring The EntityManager At Injection Time

To configure an EntityManager on-the-fly inject the EntityManagerFactory and expose the EntityManager with custom configuration:


public class EntityManagerConfigurator {

    @PersistenceUnit
    EntityManagerFactory emf;

    @Inject
    Map<String, String> jpaConfiguration;

    @Produces
    public EntityManager configureEm() {
        EntityManager em = emf.createEntityManager(SynchronizationType.SYNCHRONIZED, jpaConfiguration);
        System.out.println("configuredProperties = " + em.getProperties());
        return em;
    }
}

Now the EntityManager becomes injectable with @Inject:


public class WorkshopScheduler {

    @Inject
    EntityManager em;

}

The properties can be exposed via injection or read from java.util.Properties:


public class Configurator {

    @Produces
    public Map<String, String> expose() {
        Map<String, String> jpaConfiguration = new HashMap<>();
        jpaConfiguration.put("eclipselink.logging.level", "FINE");
        return jpaConfiguration;
    }
}

See also github.com/AdamBien/jc2 with github.com/AdamBien/headlands for JCache based configuration.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Integration Testing: Setting System Properties Before DeltaSpike

DeltaSpike's Test-Control Module loads the unit test after the injected classes. Therefore any configured system properties set in @Before or even @BeforeClass are not going to be considered.

To test the underlying class:


public class SystemPropertyExposer {

    @Produces
    public String expose() {
        return System.getProperty("dev");
    }

}

with e.g:


@RunWith(PropertiesLoaderTestRunner.class)
public class SystemPropertyExposerIT {

    @Inject
    String developer;

    @Test
    public void developerInjection() {
        assertThat(developer, is("duke"));
    }

}

You will have to set the property, before the initialization of SystemPropertyExposer.

This can be achieved with the following workaround:


import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
import org.junit.runners.model.InitializationError;

public class PropertiesLoaderTestRunner extends CdiTestRunner {

    static {
        System.setProperty("dev", "duke");
    }

    public PropertiesLoaderTestRunner(Class testClass) throws InitializationError {
        super(testClass);
    }

}

The sample above was pushed into: github.com/AdamBien/javaeetesting.

See you at Java EE Workshops at Munich Airport, Terminal 2 and particularly at Continuous Java EE 7 Testing and Quality.


NEW 2016: Java EE 7 Workshops: Bootstrap, Effective, Architectures, April, 4th-6th, Munich's Airport
On demand workshops: Java EE 7 Bootstrap, Effective Java EE 7 and NEW: Java EE 7 Testing are available for streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License