Skip to content

Apache Causeway™ software is a framework for rapidly developing domain-driven apps in Java. This repo contains a sample app to use as a template for getting you started.

License

Notifications You must be signed in to change notification settings

apache/causeway-app-simpleapp

SimpleApp

badge badge

This is a simple Apache Causeway application, structured so that it can be used as a starting point for developing your own applications.

It consists of:

  • a single module, which you can refactor for your own domain, or take a copy of in order to ensure that your application is properly modular

  • configuration to bring in some of the more commonly used extensions: secman, command log, audit trail, execution log, session logger, flyway,quartz and excel download.

You can easily remove these extensions (or add others) in the AppManifest.

Tip

If all you want is get a feel for what the framework is all about, then take a look at the HelloWorld starter app, which has the bare minimum of configuration.

Quick start

  • install prereqs:

  • download and unzip

    APP=simpleapp
    BRANCH=master
    
    REPO=causeway-app-$APP
    curl "https://codeload.github.com/apache/$REPO/zip/$BRANCH" | jar xv
    mv $REPO-$BRANCH $REPO
    cd $REPO
  • Build using Maven:

    mvn clean install
  • Download the spring-instrument.jar for load-time weaving (discussed in more detail below):

    mvn dependency:get -DgroupId=org.springframework -DartifactId=spring-instrument -Dversion=XXX

    Change "XXX" to the value that ${spring-framework.version} resolves to in the webapp pom.xml

  • Run using Maven:

    mvn -pl webapp spring-boot:run
  • Browse to http://localhost:8080.

  • Login using:

    • either the secman superuser:

      • username: secman-admin

      • password: pass

    • or as a regular user:

      • username: sven

      • password: pass

    The app runs with H2 running in-memory, with sample data set up using fixture scripts.

  • Build a Docker image

    export REVISION=...                 #(1)
    export DOCKER_REGISTRY_USERNAME     #(2)
    export DOCKER_REGISTRY_PASSWORD     #(3)
    
    mvn -pl webapp -Ddocker jib:build
    1. used as the image tag

    2. Docker Hub registry username

    3. Docker Hub registry password

      To push to another container registry, change the <image> tag in the pom.xml

Application Structure

The following table explains the contents of each of the directories:

Directory Description

module-simple

Holds the "simple" module, consisting of the SimpleObject entity and supporting services.

Tip

Larger applications should consist of multiple modules; each such module can be copied from this starter module.

module-simple-tests

Holds the unit- and integration tests for module-simple.

webapp

Holds the bootstrapping classes, along with application-level scoped services and home page.

The pom.xml also provides goals to run the app from the command line, or to be assembled into a Docker image.

webapp-tests

Contains application-wide integration tests.

It’s more common for tests to reside within the same module, but we moved them into their own Maven modules because it makes them easier to be temporarily excluded, eg during initial explorations/prototyping.

ORM Support

This version of the application uses EclipseLink JPA as its ORM, configured with load-time weaving. This requires that the application be run with a Java agent.

The spring-boot plugin is configured to run with this agent already. If you want to run from an IDE:

  • first, you might wish to copy the file locally:

    cp ~/.m2/repository/org/springframework/spring-instrument/XXX/spring-instrument-XXX.jar lib/spring-instrument.jar

    Change "XXX" to the value that ${spring-framework.version} resolves to in the webapp pom.xml

  • Then specify the agent as a VM option:

    -javaagent:lib/spring-instrument.jar

Testing

The application has both unit tests and integration tests.

Table 1. Testing types
Test type Report Phase Skip using

Unit test

target/surefire-unittest-reports

test

-DskipUTs

Integ test

target/surefire-integtest-reports

integration-test

-DskipITs

These outputs can for example be processed within/published by a continuous pipeline.

Translations

Apache Causeway supports i18n using GNU .po files. 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).

Flyway

The application also demonstrates how to use Flyway to migrate the database schema.

By default the app runs using an in-memory database. The Flyway example is activated using the "SQLSERVER" Spring Boot profile, eg:

mvn -Dspring.profiles.active=SQLSERVER -pl webapp install
mvn -Dspring.profiles.active=SQLSERVER -pl webapp spring-boot:run

This causes the properties defined in config/application-SQLSERVER.properties file to be used in preference to those in the default config/application.properties file. It defines the following:

  • spring.flyway.url, spring.flyway.user and spring.flyway.password

    The presence of these is enough to enable the Flyway integration

  • spring.flyway.enabled

    This is explicitly set to true, to override the value in the default config/application.properties.

  • causeway.persistence.jdo-datanucleus.impl.datanucleus.schema.autoCreateAll

    This is set to false, also overriding the value in the default config/application.properties. It instructs the JDO/DataNucleus object store not to automatically create any tables etc.

The Spring Boot profile is also used to add the dependency to the SQL Server driver is included (it is hidden behind a Maven profile).

The prerequisites to try this out are a SQL Server database running on localhost and with the credentials as specified in config/application-SQLSERVER.properties; adjust as necessary.

About

Apache Causeway™ software is a framework for rapidly developing domain-driven apps in Java. This repo contains a sample app to use as a template for getting you started.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published