- 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.model
package create aBook
entity 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.model
package create aLanguage
enumeration. - In the
src/main/resources/META-INF
directory create apersistence.xml
file for thebookStorePU
persistence 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_ALL
andCOUNT_ALL
) to theBook
entity - In the
com.pluralsight.bookstore.repository
package create aBookRepository
transactional 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/java
directory create acom.pluralsight.bookstore.repository
package with aBookRepositoryTest
test 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.xml
file for test purpose - Add the
src/test/resources/arquillian.xml
file for Arquillian test with thearquillian-wildfly-remote
qualifier - Startup WildFly and run
mvn clean test
so 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
Book
entity add constraints on the attributes title, description, unitCost, isbn and publicationDate - In the
BookRepository
add constraints to the parameter of the methods find and delete - In the
BookRepositoryTest
add extra methods to check the constraints are working shouldFailCreatingABookWithNullTitle, shouldFailCreatingABookWithLowUnitCostTitle, shouldFailCreatingABookWithNullISBN, shouldFailInvokingFindByIdWithNull and shouldFailInvokingDeleteWithNull - Startup WildFly and run
mvn clean test
so 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.util
create the new beanIsbnGenerator
with agenerateNumber
returning a random ISBN number - The
BookRepository
uses injection to get a reference of theIsbnGenerator
bean that it uses in thecreate
method - For injection to work, create an empty
src/main/webapp/WEB-INF/beans.xml
file - 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.rest
package create theJAXRSConfiguration
class to configure the REST api to theapi
web root - In the
com.pluralsight.bookstore.rest
package create theBookEndpoint
and define the methods createBook (POST), getBook (GET), deleteBook (DELETE), getBooks (GET) and countBooks (GET) - In the directory
src/main/resources
create animport.sql
to add data to the database (make sure to add asql-load-script-source
property in thepersistence.xml
file
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
BookEndpoint
add 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 thetarget
directorymvn 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/