- Maven build lifecycle: Maven archetype to bootstrap the basic directory structure and manage Java EE dependencies (configuration file pom.xml).
- The Domain model: Implementing the Book entity using Java Persistance API to connect to Relational Database by map entity.
- Entity management: Using Java Transaction API to implement CRUD operations (Create, Read, Update, Delete) with Java Persistence Query Language (Transaction demarcation).
- Testing: Using JUnit to test in isolation part of the code and Arquillian integration tests to test integrated systems in a system container.
- Validation: Using constraints on Object attributes and on Object method parameters to manage data by the system container.
- Dependency injection: Java bean is a managed Java EE class that benefits from servives given by the system container. Using injection annotation in order to better manage Java beans.
- REST API: Exposing REST (Representational state transfer) API using annotations in order to consume it with a client API. So that an HTTP endpoint to be an entry point for Angular.
- API documentation: Using Maven to automate the process of generating JSon contract files for documenting API and to visualize contracts with Swagger UI (User Interface).
The BookStore web application deals with books. Books are the basic domain model of the application and need to be mapped and then store into a relational database.
- In the
com.pluralsight.bookstore.modelpackage create aBookentity with an id (the primary key), a title, a description, a unitCost, an isbn, a publicationDate, nbOfPages, imagURL and a language. - In the
com.pluralsight.bookstore.modelpackage create aLanguageenumeration. - In the
src/main/resources/META-INFdirectory create apersistence.xmlfile for thebookStorePUpersistence unit.
To execute the application you have to build it (mvn clean package) and then deploy the bookstore-back.war into WildFly.
Mapping an entity to a database is not enough. We need to add a transactional repository to be able to persist, find or remove data from the relational database.
- Add two named queries (
FIND_ALLandCOUNT_ALL) to theBookentity - In the
com.pluralsight.bookstore.repositorypackage create aBookRepositorytransactional repository with methods create, find, delete, findAll and countAll.
To execute the application you have to build it (mvn clean package) and then deploy the bookstore-back.war into WildFly.
This module uses JUnit and Arquillian frameworks to test the first components of our BookStore application
- In the
src/test/javadirectory create acom.pluralsight.bookstore.repositorypackage with aBookRepositoryTesttest class. This should test the repository with methods such as shouldGetNoBook, shouldCreateABook, shouldFindTheCreatedBook, shouldGetOneBook, shouldDeleteTheCreatedBook, shouldGetNoMoreBook - Add the
src/test/resources/META-INF/test-persistence.xmlfile for test purpose - Add the
src/test/resources/arquillian.xmlfile for Arquillian test with thearquillian-wildfly-remotequalifier - Startup WildFly and run
mvn clean testso the Arquillian tests pass
To execute the application you have to build it (mvn clean package) and then deploy the bookstore-back.war into WildFly.
To make sure the data of a book is valid, this module uses Bean Validation to add constraints to the Book model and the transactional repository.
- In the
Bookentity add constraints on the attributes title, description, unitCost, isbn and publicationDate - In the
BookRepositoryadd constraints to the parameter of the methods find and delete - In the
BookRepositoryTestadd extra methods to check the constraints are working shouldFailCreatingABookWithNullTitle, shouldFailCreatingABookWithLowUnitCostTitle, shouldFailCreatingABookWithNullISBN, shouldFailInvokingFindByIdWithNull and shouldFailInvokingDeleteWithNull - Startup WildFly and run
mvn clean testso the Arquillian tests pass
To execute the application you have to build it (mvn clean package) and then deploy the bookstore-back.war into WildFly.
In object oriented programming, objects depend on others. Thanks to injection we can easily ask the container to provide the needed dependencies.
- In the package
com.pluralsight.bookstore.utilcreate the new beanIsbnGeneratorwith agenerateNumberreturning a random ISBN number - The
BookRepositoryuses injection to get a reference of theIsbnGeneratorbean that it uses in thecreatemethod - For injection to work, create an empty
src/main/webapp/WEB-INF/beans.xmlfile - Adjust the Arquillian tests so it can test injection
To execute the application you have to build it (mvn clean package) and then deploy the bookstore-back.war into WildFly.
This module adds a REST API in front of the book repository to allow HTTP calls to interact with the back-end with JSon format.
- In the
com.pluralsight.bookstore.restpackage create theJAXRSConfigurationclass to configure the REST api to theapiweb root - In the
com.pluralsight.bookstore.restpackage create theBookEndpointand define the methods createBook (POST), getBook (GET), deleteBook (DELETE), getBooks (GET) and countBooks (GET) - In the directory
src/main/resourcescreate animport.sqlto add data to the database (make sure to add asql-load-script-sourceproperty in thepersistence.xmlfile
To execute the application you have to build it (mvn clean package) and then deploy the bookstore-back.war into WildFly.
To help us developing the Angular front-end, we need to document our REST API. This module uses Swagger to generate documentation of our REST endpoint.
- In the
BookEndpointadd Swagger annotations to document all the exposed methods
To execute the application you have to build it (mvn clean package) and then deploy the bookstore-back.war into WildFly.
The BookStore application is divided into a Java EE REST back-end (bookstore-back) and an Angular front-end (bookstore-front).
The code of this module follows the Maven directory structure. The src/main/ directory contains the main source code while you will find the test class under src/test/. The pom.xml file is Maven specific and it describes the project and its dependencies.
Once Maven and a JDK 8 are installed, enter the following Maven commands:
mvn help:help: shows Maven helpmvn clean: cleans thetargetdirectorymvn compile: compiles the codemvn test: runs the test case (you need WildFly to be up and running)mvn package: packages the code into a war filemvn clean package: executes a clean and then a package
Once Wildfly is installed, deploy the war file and go to http://localhost:8080/bookstore-back/