GithubHelp home page GithubHelp logo

faisalazam / ynami Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 489.2 MB

YNaMi -> Why Not Me: Template project to help with future projects. It aims to provide a template with web layout, database, database migrations, testing, feature toggles, security etc.

Home Page: https://faisalazam.github.io/YNaMi/

Java 81.13% CSS 1.14% HTML 5.56% JavaScript 7.37% Gherkin 3.55% Shell 0.82% XSLT 0.43%
database-migrations feature-flags integration-testing java security spring-boot unit-testing web-layout gherkin html-css-javascript

ynami's Introduction

Why Not Me!!!

Why Not Me!!! (YNaMi)

Purpose of this awsomazing project is to have such a template which implements the best software development practices, and structures the software code in a manner that we can just use this template and start adding out classes in those locations.

Testing

Talking about best practices and fear free software development, see how the test package looks like below:

test-package.png

It'll setup the following testing strategies:

Running tests from IDE

I guess, since Java 17, we need to add the following to VM options in order to use reflection.

Changes has already been accordingly in the pom.xml file, but don't forget to add the following to VM options if running this application from IDE:

--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED

But since the spring boot upgrade, seems like we don't need to set them in the VM options nor in the spring-boot-maven-plugin in pom.xml file.

And add the following to run the integration tests from the IDE:

--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.text=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
--add-opens java.desktop/java.awt.font=ALL-UNNAMED

Maven spring-boot:run profiles

  • There are some profiles setup which can be used to choose datasource while starting up spring-boot app.
  • To see the list of configured profiles, run mvn help:all-profiles
    • Configured profiles (in pom.xml file) are:

      Profile ID Profile Description
      h2 mvn spring-boot:run -Ph2 will start the sprin boot application with H2 datasource
      mysql mvn spring-boot:run -Pmysql will start the sprin boot application with MySql datasource

An alternate approach to this is to use the following command:

mvn spring-boot:run -Dspring-boot.run.arguments="--ynami.spring.datasource.profile=mysql"

In order to achieve that, spring-boot-maven-plugin plugin should be configured as below:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <jvmArguments>${spring.datasource.type.jvmArguments}</jvmArguments>
    </configuration>
</plugin>

And the value for spring.datasource.type.jvmArguments with be either of the following:

-Dynami.spring.datasource.profile=h2
-Dynami.spring.datasource.profile=mysql

Learn more about [Maven Profiles][maven-profiles-url]

Maven test profiles

  • There are some profiles setup which can be used switch on/off certain things.
  • To see the list of configured profiles, run mvn help:all-profiles
    • Configured profiles (in pom.xml file) are:

      Profile ID Profile Description
      ut It'll run only the unit tests
      it It'll run only the integration tests
      uit It'll run both the unit and the integration tests
      nt It'll run no tests at all (skipping execution of all tests).

In order to run the integration tests with particular datasource, combine the it profile with either h2 or mysql profile as below:

mvn clean integration-test -P it,h2 --file pom.xml

OR

mvn clean integration-test -P it,mysql --file pom.xml

Learn more about [Maven Profiles][maven-profiles-url]

Running Single Test

Single test can be run like that but without specifying the testing profiles mentioned above. h2 or mysql profile can be mentioned but if testing profile is mentioned, then it'll run that profile too.

mvn test -Dtest="Sample*Test"
mvn test -Dtest=SampleControllerTest
mvn test -Dtest="SampleControllerTest"
mvn test -Dtest="SampleControllerTest,SampleFeatureControllerTest"
mvn test -Dtest="SampleControllerTest#shouldGetAllSamples"
mvn test -Dtest="SampleControllerTest#shouldGetAllSamples+shouldGetSampleById"

And integration tests:

mvn test -Dtest=SampleControllerIntegrationTest
mvn test -Dtest=SampleControllerIntegrationTest -Dynami.spring.datasource.profile=h2
mvn test -Dtest=SampleControllerIntegrationTest -Dynami.spring.datasource.profile=mysql
mvn test -Dtest=SampleControllerIntegrationTest -Ph2 # Doesn't work as it runs all the tests (ut, it, mt, at, bt...)
mvn test -Dtest="SampleServiceIntegrationTest#shouldVerifyTheRetrievalOfElementById" -Dynami.spring.datasource.profile=h2

Or

mvn integration-test -Dtest="SampleControllerIntegrationTest"
mvn integration-test -Dtest="SampleControllerIntegrationTest" -Dynami.spring.datasource.profile=h2
mvn integration-test -Dtest="SampleControllerIntegrationTest" -Dynami.spring.datasource.profile=mysql
mvn integration-test -Dtest="SampleControllerIntegrationTest" -Ph2 # Doesn't work as it runs all the tests (ut, it, mt, at, bt...)
mvn integration-test -Dtest="SampleControllerIntegrationTest#shouldGetAllSamples"

Setting up H2

Click here for the details

Setting up Data Sources in IntelliJ

Click here for the details

Docker Setup (MySQL etc.)

Click here for the details

Flyway - Database Migrations

Click here for the details

Issues faced during the JAVA upgrade

Click here for the details

Issues faced during the SpringBoot upgrade

Click here for the details

Checksums for SQL files

Checksums are used in order to ensure that the SQL db migration scripts are not changed. It's to encourage to write a new migration script if any more change/update is required instead of touching the existing migration scripts.

To generate checksum for the newly add SQL db migration script, just run the DBMigrationScriptsChecksumTest test. The test will fail printing on the console something like below:

*****************************************************************************************
New DB migration/s has/ve been added. The following line/s MUST be added to checksums.txt

V004__create_auditentry_and_auditentryarchive_tables.sql,370a9d48d1ba9fcd47515b6d223727a0

*****************************************************************************************
You MUST add the new checksum/s value/s to the checksums.txt file
*****************************************************************************************

Copy the file name along with the checksum from that output and add it to the end of the checksums.txt file.

ynami's People

Contributors

faisalazam avatar

Watchers

 avatar

ynami's Issues

Application is not accessible on H2

Hit -> https://localhost:8443/ynami/

Access to localhost was denied

You don't have authorisation to view this page.

HTTP ERROR 403

It is happening due to to the CsrfFilter (present in the DefaultSecurityFilterChain) which is somehow not getting disabled from the SecurityConfig class. CsrfFilter is not present in the DefaultSecurityFilterChain when the app is started with mysql from intellij. Behaviour is same when the server is started from within intellij/terminal regardless of whether through maven or not.

Hitting the app url is not even logging any logs once the server has started.

MySql - named primary key contraint

Creating db table in MySql with specified name for the primary key constraint, will simplify primary key verification in migration tests as it is just hardcoded to "PRIMARY" at the moment.

Naming does not work in MySql but works fine in H2. If we don't specify name, then the test will fail with H2 as H2 will assign a random name then.

Penetration Testing - Upgrade ZAP

Penetration Testing - Upgrade ZAP and ensure its running fine in CI. It's green in CI at the moment as it is not running any penetration tests.

README - content inside blockquotes is not properly formatted

README - content inside blockquotes is not properly rendered and badly formatted in GitHub. But the content looks fine on local.

Also, the images are not shown in the site generated via 'mvn site', that might be path issue as the images might not be at the proper place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.