blob: 709082d30e7a36dd36fb0570125cef336df92fa9 [file] [log] [blame]
= SimpleApp
:toc:
This is a simple link:http://isis.apache.org[Apache Isis] application, but structured so it can be used as a starting point for developing your own applications.
== Quick start
* install prereqs:
** Java 8 LTS (eg link:https://adoptopenjdk.net/[Adopt OpenJDK] distribution)
** Maven 3.6 or later (http://maven.apache.org/download.cgi[download])
* download and unzip
+
[source,bash]
----
REPO=isis-app-simpleapp
BRANCH=master
curl "https://codeload.github.com/apache/$REPO/zip/$BRANCH" > $REPO-$BRANCH.zip
unzip $REPO-$BRANCH.zip
mv $REPO-$BRANCH $REPO
cd $REPO
----
* Build using Maven:
+
[source,bash]
----
mvn clean install
----
* Run using Maven:
+
[source,bash]
----
mvn -pl webapp spring-boot:run
----
* Login using:
** username: `sven`
** password: `pass`
The app runs with H2 running in-memory, with sample data set up using link:https://isis.apache.org/guides/ugtst.html#_ugtst_fixture-scripts[fixture scripts].
== Application Structure
The following table explains the contents of each of the directories:
[width="100%",options="header,footer",stripes="none",cols="2a,4a"]
|====================
|Directory
|Description
|`module-simple`
|Holds the "simple" module, consisting of the `SimpleObject` entity and supporting services.
It also contains module-specific unit- and integration tests.
[TIP]
====
Larger applications should consist of multiple modules; each such module can be copied from this starter module.
====
|`webapp`
|Holds the bootstrapping classes, along with application-level scoped services and home page.
It also contains application-wide integration tests/BDD specs, and lockdown tests.
The `pom.xml` also provides goals to run the app from the command line, or to be assembled into a Docker image.
|====================
== Development
Apache Isis uses DataNucleus as its ORM, which requires that any entities are "enhanced", a post-compile process.
Normally this is done as part of a "mvn clean install", but the entities can also be enhanced explicity using:
[source,bash]
----
mvn -pl module-simple datanucleus:enhance -o
----
This is useful to know if the application or integration test fails to bootstrap, complaining of "unenhanced entities".
TIP: You can also use `enhance-all.sh`
== Testing
The application has three types of tests.
Each of these generates its own set of tests, and each can be disabled through a system property.
.Testing types
[cols="5a,12m,6m,3m", options="header"]
|===
| Test type
| Report
| Phase
| Skip using
| Unit test
| target/surefire-unittest-reports
| test
| -DskipUTs
| Integ test
| target/surefire-integtest-reports
| integration-test
| -DskipITs
| BDD (Cucumber) specs
| target/surefire-integbddspecs-reports
| integration-test
| -DskipBS
|===
The test reports format are in XML and basic HTML format.
In addition:
`target/cucumber-html-reports/overview-features.html`::
BDD (Cucumber) specification reports, as an interactive website
These outputs can for example be processed within/published by a continuous pipeline pipeline.
=== Lockdown Tests
Lockdown tests capture the state of the system, so that changes to that system can be captured and confirmed.
There are two lockdown tests:
* the metamodel (serialized as XML)
+
This is expected to change whenever the domain logic is changed, but generally should _not_ change when the Apache Isis framework is upgraded.
* Maven dependencies (serialized as flat files)
+
This should only change when dependencies are bumped or new dependencies added.
The lockdown tests are implemented as link:https://approvaltests.com/[approval test]s, meaning that the current state is compared to an "approved" state.
If there are no differences then the test passes.
If there are differences then the test fails, and a diff is shown using any available `diff` tool.
The lockdown tests are disabled by default, and are enabled with system properties.
* to compare the current metamodel with the previously approved metamodel:
+
[source,bash]
----
mvn integration-test -Dmetamodel.lockdown
----
* to compare the current Maven dependencies with the previously approved dependencies:
+
[source,bash]
----
mvn test -Dmavendeps.lockdown
----
When there are differences, the current state is written to the `current` subdirectory.
If the current state is approved, it should be copied over to the corresponding `approved` subdirectory.
== Docker
To package up the application as a docker image and push to a Docker registry:
* set `$DOCKER_REGISTRY_USERNAME` and `$DOCKER_REGISTRY_PASSWORD` environment variables
* modify the `to/image` configuration property for the link:https://github.com/GoogleContainerTools/jib[jib-maven-plugin] in the `pom.xml`
+
The default value is `docker.io/apacheisis/simpleapp:latest`:
** change `docker.io` prefix to push to a registry other than Docker hub
** change `apacheisis/simpleapp` to the name of your app.
* package up the app with the `docker` profile:
+
[source,bash]
----
mvn -pl webapp -DskipTests -Ddocker package
----
Variants:
* to specify Docker registry credentials through some other mechanism, configure the `pom.xml` for `maven-jib-plugin` (it supports a link:https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#authentication-methods[variety of ways] to specify credentials)
* to override the image at the command line, use `-Dimage=...`.
To run a docker image previously packaged:
[source,bash]
----
docker pull apacheisis/simpleapp:latest
docker container run -d -p 8080:8080 apacheisis/simpleapp:latest
----
This can then be accessed at link:http://localhost:8080[localhost:8080].
=== Externalized Configuration
The Docker image is configured to run in the `/run/secrets` directory.
Configuration can be therefore be externalized by defining an `application.properties` secret for the Kubernetes or Docker Swarm cluster.
Spring Boot will use these settings in preference to the configuration properties defined in `classpath:config/application.properties`, see link:https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config[Spring docs].
== Translations
Apache Isis supports i18n using link:https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html[GNU .po file]s.
The `WEB-INF/translations.po` is the fallback (an empty value means that the key is used "as-is"), while `WEB-INF/translations-XX.po` files provide translations for each "XX" locale.
Translations are required for all domain classes and all members (actions, properties and collections) of all classes.
This information is available from the metamodel, and so a new template `translations.po` is generated as a side-effect of running the integration tests (through a log4j2 logger).
A good integration test to run is `ValidateDomainModel_IntegTest`.
In addition, translations are required for any validation messages triggered by the test.
Running an integration tests that trigger validations will result in these messages being captured as keys, for example `Smoke_IntegTest`.
The generated file should be merged with any existing translations in `WEB-INF/translations.po`, and translations obtained for any new keys (there are numerous online services that support the format).