/hwa-game-time-log

Individual Project: Hobby Web App // Game Time Log

Primary LanguageJavaMIT LicenseMIT

Hobby Web App: GameTimeLog

My second individual project with QA, started as an Academy Trainee. This project's state during my time in the Academy can be found in a fork to my personal account here.

This application aims to be a "Game Time Log" where users can perform CRUD functions on themselves and records of their game sessions. It is currently for demo purposes only, showcasing my knowledge of Spring & connecting a working back-end to a front-end via API calls.

Table of Contents

  1. About the Project
  2. Project Status
  3. Getting Started
    1. Dependencies
    2. Building
    3. Installation
    4. Usage
  4. Release Process
    1. Versioning
    2. How to Get Help
  5. Further Reading
  6. Contributing
  7. License
  8. Authors
  9. Acknowledgements

About the Project

MVP: A functional ‘front-end’ web app (and integrated APIs) which connects to a back-end written in Java, and a relational database. I chose to make a "Game Time Log" because I wanted an app to help manage the time I spent playing games, so that I could spend some time each week playing a new game, instead of the same old games.

Technology used in the project...
  • Back-end: Java source code using Spring libraries
  • Database: SQL database hosted on Google Cloud Platform
  • Front-end: html, css and javascript
  • Source Control: Git
  • IDE: IntelliJ Ultimate
  • Testing: using a combination of Junit, Mockito and Selenium
  • Maven to build and integrate with...
  • Jenkins as part of my CI Pipeline to send to...
  • Sonarqube (hosted on a Google Cloud VM) and...
  • Nexus (artifact repository).

Kanban Board for QA Project: github boards

Presentation about the project: on google slides

Please see the docs folder for the other documentation that is not linked in the 'design' column of the Kanban Board.

Back to top

Project Status

Current release: v0.2.2 - in development

Test Coverage: For src/main/java: 97% // Sonarqube: 0% // Overall: 98%

For test reports please see the docs folder.

Jenkins Status (CI Pipeline):

Trainer's Nexus&Sonar (master): Build Status // My Sonar (dev): Build Status

Back to top

Getting Started

Dependencies

What things you need to install the software and where to find them.

To Run

  • Java SE 8 (or later) to run the jar file.

  • Maven to create the jar-file and run.

  • A relational database to configure the application to (my GCP instance is no longer live). A Google Cloud Platform instance will require the least application config, however you can also use mySQL, h2. Other databases will require changing the pom.xml as well as application.properties

  • You can use the command line to run the program but git & git bash are nice to have.

  • For the front end it's preferred that you have a Chrome browser (if you want to make use of my app shortcut).

To Develop

When you open the project in an IDE to develop, the pom.xml file should allow your IDE to automatically download the required dependencies (libraries).

The main IDE that I used for this project was IntelliJ Ultimate
Postman was used to test my API calls before writing them in JavaScript.
I recommend Visual Studio Code for the front-end, but any text editor is fine.
As part of the CI pipeline for this project I used Jenkins.

Links for Dependencies Java latest version here, Maven here, mySQL here, Git & Git Bash here, IntelliJ Ultimate here, Visual Studio Code here, Jenkins here, Postman here, Google Chrome here.

Getting the Source

This project is hosted on GitHub. You can clone this project directly using this command:

git clone git@github.com:CarolineS-QA/hwa-game-time-log.git

Back to top

Building

How to build my project:

Built With

Maven - Dependency Management

  • Clone the repo to your machine.
  • Open the cmd line / git bash inside the repo file directory.
  • Run the following commands:

mvn clean package

mvn spring-boot:run

As a Spring app, running the jar with java -jar FileName.jar won't work (at least not without some config).

Note: If my GCP instance is no longer active, you will need a database on your machine set up to connect to, and configured in application.properties before running the above commands. When you run the second command the program will run, launching the Spring boot application. You can then navigate to localhost:8181 via a browser or my shortcut provided in this repo, to reach the home page of the web interface. The app will run until you trigger the /shutdownAppContext API call (click the red button on the home page).

Running the tests

The easiest way to run all my existing tests is to right click on test/java/com.qa.hwq in your IDE and select Run tests in 'com.qa.hwa' or Run tests in 'com.qa.hwa' with Coverage

Run All Tests

Back to top

Unit Tests

JUnit is used for unit tests. A unit test will test individual methods within a class for functionality. Below is a simple Unit Test for my UserDTO class:

    @Before
    public void SetUp()
    {
        sessionDTOs = new ArrayList<>();
        zeroDuration = Duration.ofDays(0);
        userWithId = new UserDTO(1L, "testUser", zeroDuration, zeroDuration, zeroDuration, sessionDTOs);
    }

    @Test
    public void notEqualsWithNull() {
        assertNotEquals(null, userWithId);
    }

In IntelliJ, as you write tests annotated with @Test, it gives you the option to run tests in a class, or individual Tests. Just look for the green arrows in the margins.

Run All Unit Tests in a class Run a specific Unit Test

Back to top

Integration Tests

Mockito is used for intergration testing, but can also be applied to certain unit tests. It tests how different classes interact with each other. By 'mocking' the functions that a method/class relies on we can see how the code we are testing works by assuming the parts it relies on work too.

//Mockito Unit Test
    @Test
    public void readAllSessionsTest() {
        when(repo.findAll()).thenReturn(gameSessionList);
        when(this.mapper.map(testSessionWithId, GameSessionDTO.class)).thenReturn(sessionDTO);
        assertEquals(this.service.readAllSessions(), gameSessionDTOList);
        verify(repo, times(1)).findAll();
    }

//Integration Test
@Test
    public void deleteGameSessionTest(){
        assertThat(this.service.deleteGameSession(this.testSessionWithId.getSessionId())).isFalse();
    }

In IntelliJ, as you write tests annotated with @Test, it gives you the option to run tests in a class, or individual Tests. Just look for the green arrows in the margins.

Run all integration Tests Run a single integration Test

Back to top

User acceptance Tests (with Selenium)

Selenium uses the chromedriver.exe included in this repository to run automated tests mocking use of the front-end. I have included the extent-report.xml and dependencies required to get easy to read test reports in the form of html files.

Checkout my selenium-tests branch for examples of the tests in this project - it's not included in the master because it doesn't agree with Jenkins just yet...

Or take a look at my selenium-testing repo which has other examples.

Static analysis

Sonarqube is used for static analysis. I used it to see how well my code conformed to an industry standard, the amount of coverage for my tests, and also highlighting bugs and security warnings.

mvn clean package
sonar:sonar -Dsonar.host.url=http://YourVMForSonarQubeIP:PORT/ -Dsonar.login.admin=admin -Dsonar.password=admin

SonarQube example

Back to top

Installation

Installing Demo

How to get a development environment running:

  • Clone the repo to your machine. (fork it first if you want to make changes for yourself).
  • Open git bash (git should already be initalised if you clone it otherwise use git init).
  • It's recommended that you start making changes on a new branch git checkout -b NAME-OF-YOUR-BRANCH
  • Open as an existing maven project in the IDE of your choice
  • You'll probably want to check the application.properties file in src/main/resources first
  • You can change the database connection details and port the web app is hosted on here
  • Once configured, you can start developing!
  • Find the App file in src/main/java/com.qa.hwa
  • There should be an option to run the application
  • When the application is running, you can open your browser to localhost:PORT or test the API calls in postman.

Example of getting some data out of the system with Postman:

Postman createUser

Should response with:

{
    "userId": 1,
    "username": "testGamer",
    "totalTimePlayed": 0.0,
    "freeTime": 24.000000000,
    "timeRemaining": 24.000000000,
    "gameSessions": []
}

JSON for sending /createGameSession

{
	"gameName": "Hello World",
	"user":
	{
		"userId": 1,
		"username": "testGamer"
	},
	"timePlayed": 7,
	"timeOfSession": "2007-12-03T10:15:30"
}

Responds with:

{
    "sessionId": 1,
    "user": "testGamer",
    "gameName": "Hello World",
    "timeOfSession": "2007-12-03T10:15:30",
    "timePlayed": 7.000000000
}

If you /getUserByUsername/testGamer

{
     "userId": 1,
     "username": "testGamer",
     "totalTimePlayed": 0.0,
     "freeTime": 24.000000000,
     "timeRemaining": 24.000000000,
     "gameSessions": [
         {
             "sessionId": 1,
             "user": "testGamer",
             "gameName": "Hello World",
             "timeOfSession": "2007-12-03T10:15:30",
             "timePlayed": 7.000000000
         }
     ]
 }

On development localhost:8181 page: Development web interface

Remember you can Ctrl + Shift + I to inspect and reach the developer's console.

Back to top

Usage

This project is a demo for using the Spring library & API calls.

Back to top

Release Process

This project is in development, for demo purposes only and not yet at 'release' stage.

Versioning

We use SemVer for versioning. For a list of available versions, see the repository tag list.

Back to top

How to get help

If you have questions related to this project you can email me at carstracode@gmail.com

Further Reading

Spring:

Front-end:

Back to top

Contributing

Currently not accepting contributions due to the nature of this project being an individual project and part of my Academy training. However, soon I may be open to contributions.

Please review CONTRIBUTING.md for details on our code of conduct and development process (this is currently in development).

Back to top

License

This project is licensed under the MIT license - see the LICENSE.md file for details

For help in Choosing a license

Back to top

Authors

  • Caroline Strasenburgh

Acknowledgements

Back to top