From 3f5f19e18377ba01e5cb7753eff0305a4423b4b8 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:20:52 +0100 Subject: [PATCH 001/122] Test sonar cloud --- .github/workflows/unit-tests-push.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/unit-tests-push.yml diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml new file mode 100644 index 00000000..c6da6575 --- /dev/null +++ b/.github/workflows/unit-tests-push.yml @@ -0,0 +1,20 @@ +name: Unit tests +on: + push: + branches: + - master + - unit-tests + pull_request: + types: [opened, synchronize, reopened] +jobs: + unit-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Analyze with SonarCloud + uses: sonarsource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From d75eada2043577166c719fa0b8916e7089fc78ad Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:25:00 +0100 Subject: [PATCH 002/122] Test sonar cloud --- .github/workflows/unit-tests-push.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index c6da6575..930e0e4a 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -10,11 +10,13 @@ jobs: unit-tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v1 + - name: Set up JDK + uses: actions/setup-java@v1 with: - fetch-depth: 0 + java-version: '17' - name: Analyze with SonarCloud - uses: sonarsource/sonarcloud-github-action@master + run: ./mvnw -B verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From e26079997a4a92bdcdf547df5af5873d945cceca Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:27:00 +0100 Subject: [PATCH 003/122] Test sonar cloud --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 930e0e4a..82cb36c1 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -16,7 +16,7 @@ jobs: with: java-version: '17' - name: Analyze with SonarCloud - run: ./mvnw -B verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN + run: mvnw -B verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From 7b31bc744a4d341368c09671be79b8c8e1dec6f6 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:40:19 +0100 Subject: [PATCH 004/122] Test sonar cloud --- .github/workflows/unit-tests-push.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 82cb36c1..bf511d6b 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -16,7 +16,8 @@ jobs: with: java-version: '17' - name: Analyze with SonarCloud - run: mvnw -B verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN + run: chmod +x mvnw + run: ./mvnw -B verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file From e349dc9d02cabdde7fb5bc1468c3d6cc32063eb3 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:41:15 +0100 Subject: [PATCH 005/122] Test sonar cloud --- .github/workflows/unit-tests-push.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index bf511d6b..1545068e 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -15,8 +15,9 @@ jobs: uses: actions/setup-java@v1 with: java-version: '17' - - name: Analyze with SonarCloud + - name: Add exec permission to mvnw run: chmod +x mvnw + - name: Analyze with SonarCloud run: ./mvnw -B verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 62f8c060e3993ded58debaa7e4abdc5520249bd3 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:11:31 +0100 Subject: [PATCH 006/122] Test sonar cloud --- .github/workflows/unit-tests-push.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 1545068e..a7c71c38 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -9,6 +9,15 @@ on: jobs: unit-tests: runs-on: ubuntu-latest + services: + mysql: + image: mysql:latest + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: test_database + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - uses: actions/checkout@v1 - name: Set up JDK @@ -17,8 +26,9 @@ jobs: java-version: '17' - name: Add exec permission to mvnw run: chmod +x mvnw - - name: Analyze with SonarCloud - run: ./mvnw -B verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN + - name: Build and test + run: | + ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 0a09eb5a54116cbed2f553efef76af7402c9e87f Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:15:10 +0100 Subject: [PATCH 007/122] Test mysql connection for testing --- src/test/resources/application-test.properties | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/test/resources/application-test.properties diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties new file mode 100644 index 00000000..af5627f0 --- /dev/null +++ b/src/test/resources/application-test.properties @@ -0,0 +1,8 @@ +# Deploy in HTTPS +server.port=443 + +#spring.datasource.url=jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE} +#spring.datasource.username=${MYSQL_USER} +#spring.datasource.password=${MYSQL_PASSWORD} +#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.jpa.hibernate.ddl-auto=create \ No newline at end of file From ed0b325c0880ab3187181bf169a5890ceab1c12a Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:16:47 +0100 Subject: [PATCH 008/122] Test mysql connection for testing --- src/main/resources/application-test.properties | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/resources/application-test.properties diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 00000000..af5627f0 --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1,8 @@ +# Deploy in HTTPS +server.port=443 + +#spring.datasource.url=jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE} +#spring.datasource.username=${MYSQL_USER} +#spring.datasource.password=${MYSQL_PASSWORD} +#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.jpa.hibernate.ddl-auto=create \ No newline at end of file From 15d11baaa01fe2226d4e7ff342de970ec93779fe Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:19:13 +0100 Subject: [PATCH 009/122] Test mysql connection for testing --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index a7c71c38..cc5503af 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root + ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -Dspring.jpa.hibernate.ddl-auto=create env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From ecd26ccd40198ddb3c82b4b674a169c5228bbc3b Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:24:45 +0100 Subject: [PATCH 010/122] Test mysql connection for testing --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index cc5503af..845ea112 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -Dspring.jpa.hibernate.ddl-auto=create + ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -Dspring.jpa.hibernate.ddl-auto=create env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From d2cbb9eb597943ee66776336550c8ea7571dd609 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:27:33 +0100 Subject: [PATCH 011/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- src/main/resources/application-test.properties | 8 -------- src/test/resources/application-test.properties | 8 -------- 3 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 src/main/resources/application-test.properties delete mode 100644 src/test/resources/application-test.properties diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 845ea112..b995b924 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -Dspring.jpa.hibernate.ddl-auto=create + ./mvnw -B -e clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties deleted file mode 100644 index af5627f0..00000000 --- a/src/main/resources/application-test.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Deploy in HTTPS -server.port=443 - -#spring.datasource.url=jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE} -#spring.datasource.username=${MYSQL_USER} -#spring.datasource.password=${MYSQL_PASSWORD} -#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.jpa.hibernate.ddl-auto=create \ No newline at end of file diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties deleted file mode 100644 index af5627f0..00000000 --- a/src/test/resources/application-test.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Deploy in HTTPS -server.port=443 - -#spring.datasource.url=jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE} -#spring.datasource.username=${MYSQL_USER} -#spring.datasource.password=${MYSQL_PASSWORD} -#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.jpa.hibernate.ddl-auto=create \ No newline at end of file From ff22cdc4639e14dd3590741d528c88b40fbd9a12 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:36:24 +0100 Subject: [PATCH 012/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index b995b924..04e14216 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B -e clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B -e -X clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 1dfa6329a0e060b12f0d50f7e1810c6f9397d753 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:40:47 +0100 Subject: [PATCH 013/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 04e14216..407429a4 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B -e -X clean verify sonar:sonar -Dsonar.projectKey=wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B -e -X clean verify sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 77d35b451737d273ecc4138a95d74fac29c4197a Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:42:54 +0100 Subject: [PATCH 014/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 407429a4..0c74e67f 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B -e -X clean verify sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B clean verify sonar:sonar -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From eeaa9924bf3f5f95cf09f5454ffff42ce72f6103 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:46:35 +0100 Subject: [PATCH 015/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 0c74e67f..b0e26820 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.organization=Arquisoft -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B clean verify sonar:sonar -Dsonar.organization=Arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 9ca2045b89010d41b4fa161c4abcbcf0793a6cb1 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:58:42 +0100 Subject: [PATCH 016/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index b0e26820..8440e862 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.organization=Arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From c25ff9e40fc40b4db2bc51edd4314d0bb395759d Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 03:00:44 +0100 Subject: [PATCH 017/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 8440e862..40d13265 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=Arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 5d21b6b324a5174a7d77a0838e239e00caea2884 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 10 Mar 2024 03:02:57 +0100 Subject: [PATCH 018/122] Enable full error stacktrace --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 40d13265..35a787f2 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,7 +28,7 @@ jobs: run: chmod +x mvnw - name: Build and test run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 05d0827d2ed81c5f1eafc3a279aaca4431415495 Mon Sep 17 00:00:00 2001 From: uo288061 Date: Sat, 16 Mar 2024 11:49:12 +0100 Subject: [PATCH 019/122] French language added, flags removed, now the button that changes the language has the current language as text --- src/main/resources/messages.properties | 2 + src/main/resources/messages_en.properties | 2 + src/main/resources/messages_es.properties | 2 + src/main/resources/messages_fr.properties | 113 ++++++++++++++++++ .../resources/static/images/if_spain_flag.png | Bin 509 -> 0 bytes .../resources/static/images/if_uk_flag.png | Bin 628 -> 0 bytes .../resources/templates/fragments/nav.html | 8 +- 7 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/messages_fr.properties delete mode 100644 src/main/resources/static/images/if_spain_flag.png delete mode 100644 src/main/resources/static/images/if_uk_flag.png diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 91f16553..7e06c3a2 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -11,6 +11,8 @@ navbar.ranking.player=Tu ranking personal navbar.changeLanguage=Idioma navbar.toEnglish=Inglés navbar.toSpanish=Español +navbar.toFrench=Francés +navbar.currentLanguage=Español # Buttons for non-authenticated users navbar.signup=Regístrate diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index dac6c716..da0f6d41 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -11,6 +11,8 @@ navbar.ranking.player=Your personal ranking navbar.changeLanguage=Language navbar.toEnglish=English navbar.toSpanish=Spanish +navbar.toFrench=French +navbar.currentLanguage=English # Buttons for non-authenticated users navbar.signup=Sign Up diff --git a/src/main/resources/messages_es.properties b/src/main/resources/messages_es.properties index b2269e1b..276da2f8 100644 --- a/src/main/resources/messages_es.properties +++ b/src/main/resources/messages_es.properties @@ -11,6 +11,8 @@ navbar.ranking.player=Tu ranking personal navbar.changeLanguage=Idioma navbar.toEnglish=Inglés navbar.toSpanish=Español +navbar.toFrench=Francés +navbar.currentLanguage=Español # Buttons for non-authenticated users navbar.signup=Regístrate diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties new file mode 100644 index 00000000..2be98b7c --- /dev/null +++ b/src/main/resources/messages_fr.properties @@ -0,0 +1,113 @@ +# -------------------Statements for the nav.html file---------------------- +navbar.home=Accueil +navbar.play=Jouer +navbar.game1=Jeu 1 +navbar.game2=Jeu 2 +navbar.history=Historique +navbar.ranking=Classement +navbar.ranking.global=Classement mondial +navbar.ranking.player=Votre classement personnel +navbar.changeLanguage=Langue +navbar.toEnglish=Anglais +navbar.toSpanish=Espagnol +navbar.toFrench=Français +navbar.currentLanguage=Français + +navbar.signup=S'inscrire +navbar.login=Se connecter +navbar.profile.apikey=Clé d'API + +# Buttons for authenticated users +navbar.profile=Profil +navbar.logout=Se déconnecter + + +# -------------------Statements for the footer.html file--------------------- +footer.copyright=© ASW - Groupe 04 B +footer.nav=Menu de navigation + +# -------------------Statements for the error.html file--------------------- +error.page.title=Erreur ! +error.status=Statut : +error.message=Message d'erreur : +error.error=Erreur : + +# -------------------Statements for the index.html file--------------------- +index.heading=WIQ +index.subtitle=Répondez aux questions correctement et GAGNEZ !!! +index.button=JOUER + +# -------------------Statements for the home.html file--------------------- +home.heading=Bienvenue +home.private_zone=Ceci est une zone privée du site +home.authenticated_as=Utilisateur authentifié en tant que : +home.apikey.title=Clé d'API +home.apikey.description=Ceci est votre clé d'API. Utilisez-la pour accéder aux ressources de l'API de WIQ. +home.apikey.missing=Vous n'avez pas de clé d'API. Obtenez-la en cliquant sur ce bouton. +home.apikey.create=Obtenir une clé + +# -------------------Statements for the login.html file--------------------- +login.username.label=Nom d'utilisateur : +login.username.placeholder=Exemple : utilisateurwiki +login.password.label=Mot de passe : +login.password.placeholder=Motdepasse_Exemple +login.submit=Se connecter +login.error=Erreur : +login.title=Identifiez-vous +login.register=Pas encore de compte ? Inscrivez-vous ici + +# -------------------Statements for the signup.html file--------------------- +signup.username.label=Nom d'utilisateur : +signup.username.placeholder=utilisateurwiki +signup.email.label=Adresse e-mail : +signup.email.placeholder=test@test.com +signup.password.label=Mot de passe : +signup.password.placeholder=Entrez le mot de passe +signup.passwordConfirm.label=Confirmer le mot de passe : +signup.passwordConfirm.placeholder=Confirmez le mot de passe +signup.submit=S'inscrire +signup.title=Inscrivez-vous + +# -------------------Statements for the playerRanking.html and GlobalRanking.html file--------------------- +ranking.title=Classement +ranking.position=Position +ranking.score=Score +ranking.date=Date +ranking.player=Joueur +ranking.question.right=Réponses correctes +ranking.question.wrong=Réponses incorrectes +ranking.time=Temps + +# -------------------Statements for the apiHome.html file--------------------- +api.doc.title=Documentation de l'API +api.doc.description=Ceci est la documentation de l'API de WIQ. Vous pouvez trouver ici des informations sur les ressources disponibles, les paramètres qu'elles acceptent et des exemples d'utilisation. +api.doc.table.parameters=Paramètres +api.doc.table.description=Description +api.doc.table.example=Exemple +api.doc.endpoints.players.title=Point de terminaison /api/players +api.doc.endpoints.players.description=Renvoie une liste de joueurs filtrée selon les critères spécifiés. +api.doc.endpoints.questions.title=Point de terminaison /api/questions +api.doc.endpoints.questions.description=Renvoie une liste de questions filtrée selon les critères spécifiés. +api.doc.exampleRequest=Exemple de requête +api.doc.exampleResponse=Exemple de réponse +api.doc.apikey=Clé d'API (obligatoire) + +api.doc.player.username=Nom d'utilisateur (optionnel) +api.doc.player.email=Adresse e-mail (optionnel) +api.doc.player.id=Identifiant du joueur dans le système (optionnel) +api.doc.player.usernames=Noms d'utilisateur, séparés par des virgules (optionnel) +api.doc.player.emails=Adresses e-mail, séparées par des virgules (optionnel) + +api.doc.question.category=Catégorie (optionnel). Nom ou ID de la catégorie. +api.doc.question.id=ID de la question (optionnel) +api.doc.question.statement=Énoncé de la question (optionnel). Texte que l'énoncé de la question doit contenir. + +# -------------------Statements for the game fragments--------------------- +correctAnswer.result=Réponse correcte, continuez comme ça ! +failedAnswer.result=Réponse incorrecte, ne vous découragez pas et continuez à essayer. +timeRunOut.result=Temps écoulé ! Ne vous inquiétez pas, continuez à essayer. +game.continue=Question suivante +answer.correct=La réponse correcte était : +game.points=Points : +game.finish=Le jeu est terminé. Votre score est : + diff --git a/src/main/resources/static/images/if_spain_flag.png b/src/main/resources/static/images/if_spain_flag.png deleted file mode 100644 index 36b30d754af5da2e8fd40ea11d79b59c1945bba2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 509 zcmVA#CW|K6rSdgL zJ>(!YNRg)0l2)j0nws70&M0AbKuAKs2Y#2~<;U~B!w`hg$jFC#Ab>C#)&kGL%Dbsz z^G3BgAH{tT0a1V*Enp2;D2T9DufLX6*jz%N57B^{K*9osX<}Yr-h0*kMSH1y0WeIq zg-zpe<>R_l(YGED03F~kO_v@an_EY;cDsahfnUJSe`b^KeLS#0;+jDL5zVJNG~Tp` zcLNq5%yIdCg#m6}W35FoAWm0^fPmVo0DmgRtOxjyUsAq%huX6MP-(O)Q()499uN+4 zx_O<}+a2=DvqbrM+VyjP->w1?4g?@G=mXXrF`sDUW`VsQGwiM2qV(wzs&Hc1_ofDJ zF9SfMDio)4%$@noway`h;~t-vGHv4`fR{Vzlw9Y^@&;utQn`H!i>1guD>O4yg7B^FZ+6UHz z(yZ@k@qNF7)*4ZYaU{kNM-kiGE%CJe!vFFI5T2|-P$JU$00000NkvXXu0mjfE1=}% diff --git a/src/main/resources/static/images/if_uk_flag.png b/src/main/resources/static/images/if_uk_flag.png deleted file mode 100644 index 0291e298271ca9ce02fec12fca5809c2719413a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 628 zcmV-)0*n2LP)AcnX9HbU7QRpLJX%6qmTw8l7z%dfnp>f8I>(+5#c5w;UY9uKR=IkB8(oHLQ}hd7-%-tkHq7kX=s{;0C86ubE(P81@1d-WVqdGGtr2*6p6*i z8F)qlRTi3@1aAQrfITH`c&oY?jMzzf;b-Vt2PQEDF$`4Mf`g=&e%?2>Q&M+-Y3C*; zRgj&VN$aV!uRE#%E+7k7%gRgxV;W!u9BQtN4n$Y|JO2Z`Q|9GKdtW60 O0000 From 0ca6a86020835440666b2b22f6356f925063bcba Mon Sep 17 00:00:00 2001 From: uo288061 Date: Sat, 16 Mar 2024 12:03:40 +0100 Subject: [PATCH 020/122] changes in signup.html --- src/main/resources/templates/player/signup.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/player/signup.html b/src/main/resources/templates/player/signup.html index 6f6bec08..93525fdd 100644 --- a/src/main/resources/templates/player/signup.html +++ b/src/main/resources/templates/player/signup.html @@ -14,7 +14,9 @@

+ th:placeholder="#{signup.username.placeholder}" + th:value="${user.username}" + required="true"/>
@@ -22,7 +24,9 @@

+ th:placeholder="#{signup.email.placeholder}" + th:value="${user.email}" + required="true" />
From 29e19e49e8d5d5212dbbaa2456d0da53a142ec40 Mon Sep 17 00:00:00 2001 From: uo288061 Date: Sat, 16 Mar 2024 12:45:20 +0100 Subject: [PATCH 021/122] added error message on login --- src/main/resources/messages.properties | 2 +- src/main/resources/messages_en.properties | 2 +- src/main/resources/messages_es.properties | 2 +- src/main/resources/messages_fr.properties | 2 +- src/main/resources/templates/player/login.html | 6 +++++- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 7e06c3a2..06e28cf3 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -53,7 +53,7 @@ login.username.placeholder=Ejemplo: wikiuser login.password.label=Contraseña: login.password.placeholder=Password_Ejemplo login.sumbit=Iniciar sesión -login.error=Error: +login.error=Error: Usuario o contraseña incorrectos login.title=Identifícate login.register=¿No tienes cuenta? Regístrate aquí diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index da0f6d41..7d663d90 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -53,7 +53,7 @@ login.username.placeholder=Example: wikiuser login.password.label=Password: login.password.placeholder=Password_Example login.sumbit=Log in -login.error=Error: +login.error=Error: Incorrect username or password login.title=Log in login.register=Don't have an account? Sign up here diff --git a/src/main/resources/messages_es.properties b/src/main/resources/messages_es.properties index 276da2f8..40491b13 100644 --- a/src/main/resources/messages_es.properties +++ b/src/main/resources/messages_es.properties @@ -54,7 +54,7 @@ login.username.placeholder=Ejemplo: wikiuser login.password.label=Contraseña: login.password.placeholder=Password_Ejemplo login.sumbit=Iniciar sesión -login.error=Error: +login.error=Error: Usuario o contraseña incorrectos login.title=Identifícate login.register=¿No tienes cuenta? Regístrate aquí diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties index 2be98b7c..90021f7e 100644 --- a/src/main/resources/messages_fr.properties +++ b/src/main/resources/messages_fr.properties @@ -52,7 +52,7 @@ login.username.placeholder=Exemple : utilisateurwiki login.password.label=Mot de passe : login.password.placeholder=Motdepasse_Exemple login.submit=Se connecter -login.error=Erreur : +login.error=Erreur : Nom d'utilisateur ou mot de passe incorrect login.title=Identifiez-vous login.register=Pas encore de compte ? Inscrivez-vous ici diff --git a/src/main/resources/templates/player/login.html b/src/main/resources/templates/player/login.html index baf00d09..1a2311f1 100644 --- a/src/main/resources/templates/player/login.html +++ b/src/main/resources/templates/player/login.html @@ -7,7 +7,11 @@
- + +

From 7a5942c0b991ccdee574e21cbdc35f1952cd83c5 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:07:52 +0100 Subject: [PATCH 022/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 94 ++++++++++++++++--- .../com/uniovi/WiqEs04bApplicationTests.java | 13 --- .../java/com/uniovi/Wiq_IntegrationTests.java | 17 ++++ src/test/java/com/uniovi/Wiq_UnitTests.java | 17 ++++ 4 files changed, 116 insertions(+), 25 deletions(-) delete mode 100644 src/test/java/com/uniovi/WiqEs04bApplicationTests.java create mode 100644 src/test/java/com/uniovi/Wiq_IntegrationTests.java create mode 100644 src/test/java/com/uniovi/Wiq_UnitTests.java diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 35a787f2..895c182c 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -1,34 +1,104 @@ -name: Unit tests +name: Continuous Integration + on: push: branches: - master - unit-tests + - develop pull_request: types: [opened, synchronize, reopened] + jobs: unit-tests: runs-on: ubuntu-latest services: mysql: - image: mysql:latest + image: mysql:8.3 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: test_database ports: - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + options: >- + --health-cmd="mysqladmin ping --silent" + --health-interval=10s + --health-timeout=5s + --health-retries=5 steps: - - uses: actions/checkout@v1 - - name: Set up JDK - uses: actions/setup-java@v1 + - uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 with: java-version: '17' - - name: Add exec permission to mvnw - run: chmod +x mvnw - - name: Build and test - run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + - name: Cache Maven + uses: actions/cache@v2 + with: + path: | + ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Run unit tests + run: ./mvnw test -Dgroups="unit" + env: + SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: root + + integration-tests: + needs: unit-tests + runs-on: ubuntu-latest + services: + mysql: + image: mysql:8.3 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: test_database + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping --silent" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + - name: Set up Chrome + uses: browser-actions/setup-chrome@latest + - name: Set up ChromeDriver + uses: browser-actions/setup-chromedriver@latest + - name: Cache Maven + uses: actions/cache@v2 + with: + path: | + ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Run integration tests with Selenium + run: ./mvnw test -Dgroups="integration" + env: + SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: root + + sonarcloud-analysis: + needs: unit-tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: SonarCloud analysis + uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/src/test/java/com/uniovi/WiqEs04bApplicationTests.java b/src/test/java/com/uniovi/WiqEs04bApplicationTests.java deleted file mode 100644 index 35eacaa0..00000000 --- a/src/test/java/com/uniovi/WiqEs04bApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.uniovi; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class WiqEs04bApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java new file mode 100644 index 00000000..65f624c3 --- /dev/null +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -0,0 +1,17 @@ +package com.uniovi; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; + +@SpringBootTest +@Tag("integration") +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +class Wiq_IntegrationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java new file mode 100644 index 00000000..b5145541 --- /dev/null +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -0,0 +1,17 @@ +package com.uniovi; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; + +@SpringBootTest +@Tag("unit") +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +class Wiq_UnitTests { + + @Test + void contextLoads() { + } + +} From 2481cf0d6a130c211fdd26f53bf3b84eb62070a2 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:10:50 +0100 Subject: [PATCH 023/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 895c182c..4a1028be 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -1,4 +1,4 @@ -name: Continuous Integration +name: Application tests on: push: @@ -28,7 +28,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v1 with: java-version: '17' - name: Cache Maven @@ -65,7 +65,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v1 with: java-version: '17' - name: Set up Chrome From 2fd46cb83ab766bca4a1e7eb3ea5aa10471edd6d Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:10:57 +0100 Subject: [PATCH 024/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 4a1028be..86e03887 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -93,9 +93,8 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v1 with: - distribution: 'temurin' java-version: '17' - name: SonarCloud analysis uses: SonarSource/sonarcloud-github-action@master From 1f7721d7cc28d2b83ec3396f927b9f8cd95c2f38 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:13:03 +0100 Subject: [PATCH 025/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 86e03887..9adb33cf 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -39,6 +39,8 @@ jobs: key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- + - name: Add exec permission to mvnw + run: chmod +x mvnw - name: Run unit tests run: ./mvnw test -Dgroups="unit" env: @@ -80,6 +82,8 @@ jobs: key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- + - name: Add exec permission to mvnw + run: chmod +x mvnw - name: Run integration tests with Selenium run: ./mvnw test -Dgroups="integration" env: From 271b9da6a794482d35a54c156a4bb2715480e400 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:16:49 +0100 Subject: [PATCH 026/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 29 +++++++-------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 9adb33cf..8aa98bbb 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -14,17 +14,13 @@ jobs: runs-on: ubuntu-latest services: mysql: - image: mysql:8.3 + image: mysql:latest env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: test_database ports: - 3306:3306 - options: >- - --health-cmd="mysqladmin ping --silent" - --health-interval=10s - --health-timeout=5s - --health-retries=5 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - uses: actions/checkout@v2 - name: Set up JDK 17 @@ -42,28 +38,21 @@ jobs: - name: Add exec permission to mvnw run: chmod +x mvnw - name: Run unit tests - run: ./mvnw test -Dgroups="unit" - env: - SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database - SPRING_DATASOURCE_USERNAME: root - SPRING_DATASOURCE_PASSWORD: root + run: ./mvnw test -Dgroups="unit" -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver integration-tests: needs: unit-tests runs-on: ubuntu-latest services: mysql: - image: mysql:8.3 + image: mysql:latest env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: test_database ports: - 3306:3306 - options: >- - --health-cmd="mysqladmin ping --silent" - --health-interval=10s - --health-timeout=5s - --health-retries=5 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: - uses: actions/checkout@v2 - name: Set up JDK 17 @@ -85,11 +74,7 @@ jobs: - name: Add exec permission to mvnw run: chmod +x mvnw - name: Run integration tests with Selenium - run: ./mvnw test -Dgroups="integration" - env: - SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database - SPRING_DATASOURCE_USERNAME: root - SPRING_DATASOURCE_PASSWORD: root + run: ./mvnw test -Dgroups="integration" -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver sonarcloud-analysis: needs: unit-tests From 6a0384a01e6fd20993e3eea3937ec4ad8c94a8f7 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:24:19 +0100 Subject: [PATCH 027/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 8aa98bbb..e5a915ae 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -62,7 +62,7 @@ jobs: - name: Set up Chrome uses: browser-actions/setup-chrome@latest - name: Set up ChromeDriver - uses: browser-actions/setup-chromedriver@latest + uses: nanasess/setup-chromedriver@v2 - name: Cache Maven uses: actions/cache@v2 with: From 74e2218323221c0e33d0a6c5bfdc90b2431525a2 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:01:35 +0100 Subject: [PATCH 028/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 65 +--------- pom.xml | 17 ++- .../services/InsertSampleDataService.java | 10 +- .../java/com/uniovi/Wiq_IntegrationTests.java | 42 ++++++- src/test/java/com/uniovi/Wiq_UnitTests.java | 5 + .../java/com/uniovi/util/SeleniumUtils.java | 119 ++++++++++++++++++ 6 files changed, 191 insertions(+), 67 deletions(-) create mode 100644 src/test/java/com/uniovi/util/SeleniumUtils.java diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index e5a915ae..5845bc1d 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -10,38 +10,7 @@ on: types: [opened, synchronize, reopened] jobs: - unit-tests: - runs-on: ubuntu-latest - services: - mysql: - image: mysql:latest - env: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: test_database - ports: - - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: '17' - - name: Cache Maven - uses: actions/cache@v2 - with: - path: | - ~/.m2 - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - name: Add exec permission to mvnw - run: chmod +x mvnw - - name: Run unit tests - run: ./mvnw test -Dgroups="unit" -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - - integration-tests: - needs: unit-tests + app-tests-analyze: runs-on: ubuntu-latest services: mysql: @@ -59,34 +28,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: '17' - - name: Set up Chrome - uses: browser-actions/setup-chrome@latest - - name: Set up ChromeDriver - uses: nanasess/setup-chromedriver@v2 - - name: Cache Maven - uses: actions/cache@v2 - with: - path: | - ~/.m2 - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - name: Add exec permission to mvnw run: chmod +x mvnw - - name: Run integration tests with Selenium - run: ./mvnw test -Dgroups="integration" -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - - sonarcloud-analysis: - needs: unit-tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: '17' - - name: SonarCloud analysis - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + - name: Run all tests with sonar analysis + run: | + ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file diff --git a/pom.xml b/pom.xml index 86487ac8..e604b79b 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,22 @@ commons-validator 1.7 - + + org.seleniumhq.selenium + selenium-java + 4.1.0 + + + + io.github.bonigarcia + webdrivermanager + 5.0.3 + + + org.apache.httpcomponents.client5 + httpclient5 + 5.1 + diff --git a/src/main/java/com/uniovi/services/InsertSampleDataService.java b/src/main/java/com/uniovi/services/InsertSampleDataService.java index 71253e4e..9248c2fb 100644 --- a/src/main/java/com/uniovi/services/InsertSampleDataService.java +++ b/src/main/java/com/uniovi/services/InsertSampleDataService.java @@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.EventListener; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -31,22 +32,29 @@ public class InsertSampleDataService { private final CategoryService categoryService; private final QuestionRepository questionRepository; private final GameSessionRepository gameSessionRepository; + private Environment environment; private Logger log = LoggerFactory.getLogger(InsertSampleDataService.class);; public InsertSampleDataService(PlayerService playerService, QuestionService questionService, CategoryService categoryService, QuestionRepository questionRepository, - GameSessionRepository gameSessionRepository) { + GameSessionRepository gameSessionRepository, Environment environment) { this.playerService = playerService; this.questionService = questionService; this.categoryService = categoryService; this.questionRepository = questionRepository; this.gameSessionRepository = gameSessionRepository; + this.environment = environment; } @Transactional @EventListener(ApplicationReadyEvent.class) // Uncomment this line to insert sample data on startup public void insertSampleQuestions() { + if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> (env.equalsIgnoreCase("test")))) { + log.info("Test profile active, skipping sample data insertion"); + return; + } + if (!playerService.getUserByEmail("test@test.com").isPresent()) { PlayerDto player = new PlayerDto(); player.setEmail("test@test.com"); diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 65f624c3..9c07cca9 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -1,17 +1,51 @@ package com.uniovi; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; +import io.github.bonigarcia.wdm.WebDriverManager; +import org.junit.jupiter.api.*; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.firefox.FirefoxDriver; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest @Tag("integration") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +@ActiveProfiles("test") class Wiq_IntegrationTests { + static final String URL = "http://localhost:3000/"; - @Test - void contextLoads() { + static WebDriver driver; + + @BeforeAll + static public void begin() { + WebDriverManager.firefoxdriver().setup(); + driver = new FirefoxDriver(); + driver.navigate().to(URL); + } + + @BeforeEach + void setup() { + driver.navigate().to(URL); + } + + @AfterEach + void tearDown() { + driver.manage().deleteAllCookies(); + } + + @AfterAll + static public void end() { + //Cerramos el navegador al finalizar las pruebas + driver.quit(); } + @Test + @Order(1) + void testHome() { + // Check the title + Assertions.assertEquals("Wikigame", driver.getTitle()); + } } diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index b5145541..69e128cc 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -1,13 +1,18 @@ package com.uniovi; +import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest @Tag("unit") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +@ActiveProfiles("test") class Wiq_UnitTests { @Test diff --git a/src/test/java/com/uniovi/util/SeleniumUtils.java b/src/test/java/com/uniovi/util/SeleniumUtils.java new file mode 100644 index 00000000..21723d3b --- /dev/null +++ b/src/test/java/com/uniovi/util/SeleniumUtils.java @@ -0,0 +1,119 @@ +package com.uniovi.util; + + +import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.time.Duration; +import java.util.List; + +public class SeleniumUtils { + /** + * Aborta si el "texto" no está presente en la página actual + * @param driver: apuntando al navegador abierto actualmente. + * @param text: texto a buscar + */ + static public void textIsPresentOnPage(WebDriver driver, String text) + { + List list = driver.findElements(By.xpath("//*[contains(text(),'" + text + "')]")); + Assertions.assertTrue(list.size() > 0, "Texto " + text + " no localizado!"); + } + + /** + * Aborta si el "texto" está presente en la página actual + * @param driver: apuntando al navegador abierto actualmente. + * @param text: texto a buscar + */ + static public void textIsNotPresentOnPage(WebDriver driver, String text) + { + List list = driver.findElements(By.xpath("//*[contains(text(),'" + text + "')]")); + Assertions.assertEquals(0, list.size(), "Texto " + text + " no está presente !"); + } + + /** + * Aborta si el "texto" está presente en la página actual tras timeout segundos. + * @param driver: apuntando al navegador abierto actualmente. + * @param text: texto a buscar + * @param timeout: el tiempo máximo que se esperará por la aparición del texto a buscar + */ + static public void waitTextIsNotPresentOnPage(WebDriver driver, String text, int timeout) + { + Boolean resultado = + (new WebDriverWait(driver, Duration.ofSeconds(timeout))).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[contains(text(),'" + text + "')]"))); + + Assertions.assertTrue(resultado); + } + + + /** + * Espera por la visibilidad de un elemento/s en la vista actualmente cargandose en driver. Para ello se empleará una consulta xpath. + * @param driver: apuntando al navegador abierto actualmente. + * @param xpath: consulta xpath. + * @param timeout: el tiempo máximo que se esperará por la aparición del elemento a buscar con xpath + * @return Se retornará la lista de elementos resultantes de la búsqueda con xpath. + */ + static public List waitLoadElementsByXpath(WebDriver driver, String xpath, int timeout) + { + WebElement result = + (new WebDriverWait(driver, Duration.ofSeconds(timeout))).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath))); + Assertions.assertNotNull(result); + return driver.findElements(By.xpath(xpath)); + } + + /** + * Espera por la visibilidad de un elemento/s en la vista actualmente cargandose en driver. Para ello se empleará una consulta xpath + * según varios criterios.. + * + * @param driver: apuntando al navegador abierto actualmente. + * @param criterio: "id" or "class" or "text" or "@attribute" or "free". Si el valor de criterio es free es una expresion xpath completa. + * @param text: texto correspondiente al criterio. + * @param timeout: el tiempo máximo que se esperará por la apareción del elemento a buscar con criterio/text. + * @return Se retornará la lista de elementos resultantes de la búsqueda. + */ + static public List waitLoadElementsBy(WebDriver driver, String criterio, String text, int timeout) + { + String searchCriterio; + switch (criterio) { + case "id": + searchCriterio = "//*[contains(@id,'" + text + "')]"; + break; + case "class": + searchCriterio = "//*[contains(@class,'" + text + "')]"; + break; + case "text": + searchCriterio = "//*[contains(text(),'" + text + "')]"; + break; + case "free": + searchCriterio = text; + break; + default: + searchCriterio = "//*[contains(" + criterio + ",'" + text + "')]"; + break; + } + + return waitLoadElementsByXpath(driver, searchCriterio, timeout); + } + + + /** + * PROHIBIDO USARLO PARA VERSIÓN FINAL. + * Esperar "segundos" durante la ejecucion del navegador + * @param driver: apuntando al navegador abierto actualmente. + * @param seconds: Segundos de bloqueo de la ejecución en el navegador. + */ + static public void waitSeconds(WebDriver driver, int seconds){ + + //noinspection SynchronizationOnLocalVariableOrMethodParameter + synchronized(driver){ + try { + driver.wait(seconds * 1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} From ca48a0518ec9e0a4ac99eff5645240835e663433 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:07:42 +0100 Subject: [PATCH 029/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 4 ++++ src/test/java/com/uniovi/Wiq_IntegrationTests.java | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 5845bc1d..17c7b776 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,6 +28,10 @@ jobs: uses: actions/setup-java@v1 with: java-version: '17' + - name: Install Firefox + run: | + sudo apt-get update + sudo apt-get install -y firefox - name: Add exec permission to mvnw run: chmod +x mvnw - name: Run all tests with sonar analysis diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 9c07cca9..a723381a 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -5,6 +5,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -19,10 +20,13 @@ class Wiq_IntegrationTests { static WebDriver driver; + @BeforeAll static public void begin() { WebDriverManager.firefoxdriver().setup(); - driver = new FirefoxDriver(); + FirefoxOptions options = new FirefoxOptions(); + options.addArguments("--headless"); // Run Firefox in headless mode + driver = new FirefoxDriver(options); driver.navigate().to(URL); } From 06361aec452cf051363660c0342dd556cde26ad5 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:13:45 +0100 Subject: [PATCH 030/122] Test unit tests --- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index a723381a..5af98222 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -25,6 +25,7 @@ class Wiq_IntegrationTests { static public void begin() { WebDriverManager.firefoxdriver().setup(); FirefoxOptions options = new FirefoxOptions(); + options.setCapability("marionette", true); options.addArguments("--headless"); // Run Firefox in headless mode driver = new FirefoxDriver(options); driver.navigate().to(URL); From 5f626ae542e261e493f36ae68077224eb4e3f47d Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:18:41 +0100 Subject: [PATCH 031/122] Test unit tests --- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 5af98222..a723381a 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -25,7 +25,6 @@ class Wiq_IntegrationTests { static public void begin() { WebDriverManager.firefoxdriver().setup(); FirefoxOptions options = new FirefoxOptions(); - options.setCapability("marionette", true); options.addArguments("--headless"); // Run Firefox in headless mode driver = new FirefoxDriver(options); driver.navigate().to(URL); From 4435f1b42d49fb6ab2d73147e249ad6e08800469 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:23:40 +0100 Subject: [PATCH 032/122] Test unit tests --- .../java/com/uniovi/Wiq_IntegrationTests.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index a723381a..eff19faf 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -19,30 +19,23 @@ class Wiq_IntegrationTests { static final String URL = "http://localhost:3000/"; static WebDriver driver; + static WebDriverManager manager; - - @BeforeAll - static public void begin() { - WebDriverManager.firefoxdriver().setup(); - FirefoxOptions options = new FirefoxOptions(); - options.addArguments("--headless"); // Run Firefox in headless mode - driver = new FirefoxDriver(options); + @BeforeEach + public void begin() { + manager = WebDriverManager.firefoxdriver(); + driver = manager.create(); driver.navigate().to(URL); } @BeforeEach void setup() { - driver.navigate().to(URL); + } @AfterEach void tearDown() { driver.manage().deleteAllCookies(); - } - - @AfterAll - static public void end() { - //Cerramos el navegador al finalizar las pruebas driver.quit(); } From d3b1ec835ed3994fb9a31b57c76fbeb81f4de33a Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:31:35 +0100 Subject: [PATCH 033/122] Test unit tests --- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index eff19faf..145e30bd 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -19,20 +19,16 @@ class Wiq_IntegrationTests { static final String URL = "http://localhost:3000/"; static WebDriver driver; - static WebDriverManager manager; @BeforeEach public void begin() { - manager = WebDriverManager.firefoxdriver(); - driver = manager.create(); + WebDriverManager.firefoxdriver().setup(); + FirefoxOptions options = new FirefoxOptions(); + options.addArguments("--headless"); // Optional: Use this if you want to run tests headlessly + driver = new FirefoxDriver(options); // Use the options when creating the WebDriver instance driver.navigate().to(URL); } - @BeforeEach - void setup() { - - } - @AfterEach void tearDown() { driver.manage().deleteAllCookies(); From 10decf03bf29a75a2d39e2eeef17fa5a9e7d539f Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 18 Mar 2024 23:48:09 +0100 Subject: [PATCH 034/122] Test unit tests --- .github/workflows/unit-tests-push.yml | 4 ---- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 17c7b776..5845bc1d 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -28,10 +28,6 @@ jobs: uses: actions/setup-java@v1 with: java-version: '17' - - name: Install Firefox - run: | - sudo apt-get update - sudo apt-get install -y firefox - name: Add exec permission to mvnw run: chmod +x mvnw - name: Run all tests with sonar analysis diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 145e30bd..27288e59 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -24,8 +24,8 @@ class Wiq_IntegrationTests { public void begin() { WebDriverManager.firefoxdriver().setup(); FirefoxOptions options = new FirefoxOptions(); - options.addArguments("--headless"); // Optional: Use this if you want to run tests headlessly - driver = new FirefoxDriver(options); // Use the options when creating the WebDriver instance + options.addArguments("--headless"); + driver = new FirefoxDriver(options); driver.navigate().to(URL); } From 500a363f8617158321b34d18e3356951b1688f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 19 Mar 2024 09:06:02 +0100 Subject: [PATCH 035/122] Fix some styling issues --- .github/workflows/unit-tests-push.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 5845bc1d..841e31ee 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -24,12 +24,37 @@ jobs: steps: - uses: actions/checkout@v2 + + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: | + ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-m2 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: java-version: '17' + - name: Add exec permission to mvnw run: chmod +x mvnw + + - name: Compile the application + run: ./mvnw -B clean install -DskipTests=true + + - name: Start the application + run: ./mvnw spring-boot:run & + env: + SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: root + SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.cj.jdbc.Driver + - name: Run all tests with sonar analysis run: | - ./mvnw -B clean verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file + ./mvnw -B verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + env: + SPRING_PROFILES_ACTIVE: test \ No newline at end of file From 3e066d3b334fc5c290613493a38b0b3a5cedeb0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 19 Mar 2024 09:15:16 +0100 Subject: [PATCH 036/122] Test no headless --- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 27288e59..97e6a924 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -24,7 +24,7 @@ class Wiq_IntegrationTests { public void begin() { WebDriverManager.firefoxdriver().setup(); FirefoxOptions options = new FirefoxOptions(); - options.addArguments("--headless"); + //options.addArguments("--headless"); driver = new FirefoxDriver(options); driver.navigate().to(URL); } From ce547442ae2d78ad4ed3c227222accd8dc27bd95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 19 Mar 2024 09:47:15 +0100 Subject: [PATCH 037/122] Test no headless --- .github/workflows/unit-tests-push.yml | 3 ++- .../java/com/uniovi/Wiq_IntegrationTests.java | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 841e31ee..11deb24d 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -57,4 +57,5 @@ jobs: run: | ./mvnw -B verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver env: - SPRING_PROFILES_ACTIVE: test \ No newline at end of file + SPRING_PROFILES_ACTIVE: test + headless: true \ No newline at end of file diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 97e6a924..7a22e2ca 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -6,7 +6,9 @@ import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -20,12 +22,19 @@ class Wiq_IntegrationTests { static WebDriver driver; + @Autowired + Environment env; + @BeforeEach public void begin() { WebDriverManager.firefoxdriver().setup(); - FirefoxOptions options = new FirefoxOptions(); - //options.addArguments("--headless"); - driver = new FirefoxDriver(options); + if (env.getProperty("headless") != null && env.getProperty("headless").equals("true")) { + FirefoxOptions options = new FirefoxOptions(); + options.addArguments("--headless"); + driver = new FirefoxDriver(options); + } else { + driver = new FirefoxDriver(); + } driver.navigate().to(URL); } From 572d8b326d9e002feb2896d4a9482106e7eb064e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 19 Mar 2024 09:50:34 +0100 Subject: [PATCH 038/122] Tests fail case --- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 7a22e2ca..02e396ed 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -12,6 +12,8 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import static org.junit.jupiter.api.Assertions.fail; + @SpringBootTest @Tag("integration") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @@ -49,5 +51,6 @@ void tearDown() { void testHome() { // Check the title Assertions.assertEquals("Wikigame", driver.getTitle()); + fail(); } } From 4303d3efa009496bf6e1dd5dc00c21ca3c54da88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 19 Mar 2024 09:53:58 +0100 Subject: [PATCH 039/122] Finish test framework --- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 02e396ed..f2dddaa9 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -51,6 +51,5 @@ void tearDown() { void testHome() { // Check the title Assertions.assertEquals("Wikigame", driver.getTitle()); - fail(); } } From d9596cd9784e95d0b7d547c1e474ea2bd7469a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 19 Mar 2024 10:05:05 +0100 Subject: [PATCH 040/122] Finish test framework --- .../java/com/uniovi/Wiq_IntegrationTests.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index f2dddaa9..84552d69 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -29,13 +29,15 @@ class Wiq_IntegrationTests { @BeforeEach public void begin() { - WebDriverManager.firefoxdriver().setup(); - if (env.getProperty("headless") != null && env.getProperty("headless").equals("true")) { - FirefoxOptions options = new FirefoxOptions(); - options.addArguments("--headless"); - driver = new FirefoxDriver(options); - } else { - driver = new FirefoxDriver(); + if (driver == null) { + WebDriverManager.firefoxdriver().setup(); + if (env.getProperty("headless") != null && env.getProperty("headless").equals("true")) { + FirefoxOptions options = new FirefoxOptions(); + options.addArguments("--headless"); + driver = new FirefoxDriver(options); + } else { + driver = new FirefoxDriver(); + } } driver.navigate().to(URL); } @@ -43,6 +45,10 @@ public void begin() { @AfterEach void tearDown() { driver.manage().deleteAllCookies(); + } + + @AfterAll + public static void end() { driver.quit(); } @@ -52,4 +58,11 @@ void testHome() { // Check the title Assertions.assertEquals("Wikigame", driver.getTitle()); } + + @Test + @Order(12) + void testHome2() { + // Check the title + Assertions.assertEquals("Wikigame", driver.getTitle()); + } } From 940dab1f2553e21126b9166792510c1cc7271c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 19 Mar 2024 10:05:20 +0100 Subject: [PATCH 041/122] Remove extra test test --- src/test/java/com/uniovi/Wiq_IntegrationTests.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 84552d69..074e43e3 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -58,11 +58,4 @@ void testHome() { // Check the title Assertions.assertEquals("Wikigame", driver.getTitle()); } - - @Test - @Order(12) - void testHome2() { - // Check the title - Assertions.assertEquals("Wikigame", driver.getTitle()); - } } From b8ea7570fa89f7abf201361806de49a0351a1c52 Mon Sep 17 00:00:00 2001 From: uo288061 Date: Tue, 19 Mar 2024 14:49:31 +0100 Subject: [PATCH 042/122] questions in French --- .../generators/geography/BorderQuestionGenerator.java | 1 + .../generators/geography/CapitalQuestionGenerator.java | 1 + .../generators/geography/ContinentQuestionGeneration.java | 1 + src/main/java/com/uniovi/entities/Question.java | 2 ++ .../java/com/uniovi/services/InsertSampleDataService.java | 8 ++++++++ .../java/com/uniovi/services/impl/GameSessionImpl.java | 2 +- 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java b/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java index f791f1e5..f65d61ac 100644 --- a/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java +++ b/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java @@ -10,6 +10,7 @@ public class BorderQuestionGenerator extends AbstractGeographyGenerator{ { put("en", "Which countries share a border with "); put("es", "¿Con qué países comparte frontera "); + put("fr", "Avec quels pays partage-t-il une frontière "); } }; private Set usedCountries = new HashSet<>(); diff --git a/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java b/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java index e5d91727..b546759b 100644 --- a/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java +++ b/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java @@ -12,6 +12,7 @@ public class CapitalQuestionGenerator extends AbstractGeographyGenerator{ { put("en", "What is the capital of "); put("es", "¿Cuál es la capital de "); + put("fr", "Quelle est la capitale de "); } }; diff --git a/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java b/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java index b1d476ae..fcb83e11 100644 --- a/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java +++ b/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java @@ -11,6 +11,7 @@ public class ContinentQuestionGeneration extends AbstractGeographyGenerator{ { put("en", "In which continent is "); put("es", "¿En qué continente se encuentra "); + put("fr", "Sur quel continent est-il situé "); } }; diff --git a/src/main/java/com/uniovi/entities/Question.java b/src/main/java/com/uniovi/entities/Question.java index 27dc8dbc..ea66844d 100644 --- a/src/main/java/com/uniovi/entities/Question.java +++ b/src/main/java/com/uniovi/entities/Question.java @@ -23,6 +23,8 @@ public class Question implements JsonEntity { public static final String ENGLISH = "en"; public static final String SPANISH = "es"; + public static final String FRENCH = "fr"; + @Id @GeneratedValue diff --git a/src/main/java/com/uniovi/services/InsertSampleDataService.java b/src/main/java/com/uniovi/services/InsertSampleDataService.java index 71253e4e..816f5bad 100644 --- a/src/main/java/com/uniovi/services/InsertSampleDataService.java +++ b/src/main/java/com/uniovi/services/InsertSampleDataService.java @@ -74,6 +74,14 @@ public void insertSampleQuestions() { List questionsEs = allQuestionGenerator.getQuestions(); questionsEs.forEach(questionService::addNewQuestion); + allQuestionGenerator = new MultipleQuestionGenerator( + new ContinentQuestionGeneration(categoryService, Question.FRENCH), + new CapitalQuestionGenerator(categoryService, Question.FRENCH), + new BorderQuestionGenerator(categoryService, Question.FRENCH) + ); + List questionsFr = allQuestionGenerator.getQuestions(); + questionsFr.forEach(questionService::addNewQuestion); + log.info("Sample questions inserted"); } } diff --git a/src/main/java/com/uniovi/services/impl/GameSessionImpl.java b/src/main/java/com/uniovi/services/impl/GameSessionImpl.java index bed23a3f..d7e2ad3a 100644 --- a/src/main/java/com/uniovi/services/impl/GameSessionImpl.java +++ b/src/main/java/com/uniovi/services/impl/GameSessionImpl.java @@ -16,7 +16,7 @@ @Service public class GameSessionImpl implements GameSessionService { - public static final Integer NORMAL_GAME_QUESTION_NUM = 20; + public static final Integer NORMAL_GAME_QUESTION_NUM = 4; private final GameSessionRepository gameSessionRepository; private final QuestionService questionService; From 6577f42d17d8d8e60d896b8db35c210278611bcc Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Mon, 1 Apr 2024 00:32:33 +0200 Subject: [PATCH 043/122] Add cucumber for integration tests --- pom.xml | 18 +++++++ .../java/com/uniovi/CucumberRunnerTest.java | 10 ++++ .../java/com/uniovi/CucumberWiqContext.java | 17 ++++++ .../java/com/uniovi/Wiq_IntegrationTests.java | 54 ++++--------------- .../com/uniovi/steps/NavigateHomeStep.java | 25 +++++++++ .../com/uniovi/util/FirefoxWebDriver.java | 47 ++++++++++++++++ .../java/com/uniovi/util/SeleniumUtils.java | 1 + src/test/resources/features/home_page.feature | 5 ++ 8 files changed, 134 insertions(+), 43 deletions(-) create mode 100644 src/test/java/com/uniovi/CucumberRunnerTest.java create mode 100644 src/test/java/com/uniovi/CucumberWiqContext.java create mode 100644 src/test/java/com/uniovi/steps/NavigateHomeStep.java create mode 100644 src/test/java/com/uniovi/util/FirefoxWebDriver.java create mode 100644 src/test/resources/features/home_page.feature diff --git a/pom.xml b/pom.xml index e604b79b..d02bd850 100644 --- a/pom.xml +++ b/pom.xml @@ -88,6 +88,24 @@ httpclient5 5.1 + + io.cucumber + cucumber-java + 7.14.0 + test + + + io.cucumber + cucumber-junit + 7.14.0 + test + + + io.cucumber + cucumber-spring + 7.14.0 + test + diff --git a/src/test/java/com/uniovi/CucumberRunnerTest.java b/src/test/java/com/uniovi/CucumberRunnerTest.java new file mode 100644 index 00000000..3d9bcc15 --- /dev/null +++ b/src/test/java/com/uniovi/CucumberRunnerTest.java @@ -0,0 +1,10 @@ +package com.uniovi; + +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions(plugin = {"pretty"}, features = "src/test/resources/features") +public class CucumberRunnerTest { +} diff --git a/src/test/java/com/uniovi/CucumberWiqContext.java b/src/test/java/com/uniovi/CucumberWiqContext.java new file mode 100644 index 00000000..74b8d362 --- /dev/null +++ b/src/test/java/com/uniovi/CucumberWiqContext.java @@ -0,0 +1,17 @@ +package com.uniovi; + +import com.uniovi.util.FirefoxWebDriver; +import io.cucumber.java.After; +import org.openqa.selenium.WebDriver; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; + +public class CucumberWiqContext { + WebDriver driver; + + @Bean(name="webdriver", destroyMethod = "close") + public WebDriver webDriver() { + driver = new FirefoxWebDriver(); + return driver; + } +} diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index 074e43e3..f7da1ced 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -1,61 +1,29 @@ package com.uniovi; -import io.github.bonigarcia.wdm.WebDriverManager; +import com.uniovi.util.FirefoxWebDriver; +import io.cucumber.java.After; +import io.cucumber.spring.CucumberContextConfiguration; import org.junit.jupiter.api.*; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.core.env.Environment; +import org.springframework.context.annotation.Bean; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; import static org.junit.jupiter.api.Assertions.fail; @SpringBootTest @Tag("integration") -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @ActiveProfiles("test") -class Wiq_IntegrationTests { - static final String URL = "http://localhost:3000/"; - - static WebDriver driver; +@CucumberContextConfiguration +@ContextConfiguration(classes = CucumberWiqContext.class) +public class Wiq_IntegrationTests { + protected static final String URL = "http://localhost:3000/"; @Autowired - Environment env; - - @BeforeEach - public void begin() { - if (driver == null) { - WebDriverManager.firefoxdriver().setup(); - if (env.getProperty("headless") != null && env.getProperty("headless").equals("true")) { - FirefoxOptions options = new FirefoxOptions(); - options.addArguments("--headless"); - driver = new FirefoxDriver(options); - } else { - driver = new FirefoxDriver(); - } - } - driver.navigate().to(URL); - } - - @AfterEach - void tearDown() { - driver.manage().deleteAllCookies(); - } - - @AfterAll - public static void end() { - driver.quit(); - } - - @Test - @Order(1) - void testHome() { - // Check the title - Assertions.assertEquals("Wikigame", driver.getTitle()); - } + protected WebDriver driver; } diff --git a/src/test/java/com/uniovi/steps/NavigateHomeStep.java b/src/test/java/com/uniovi/steps/NavigateHomeStep.java new file mode 100644 index 00000000..acec65b0 --- /dev/null +++ b/src/test/java/com/uniovi/steps/NavigateHomeStep.java @@ -0,0 +1,25 @@ +package com.uniovi.steps; + +import com.uniovi.*; +import io.cucumber.java.After; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import org.junit.jupiter.api.Assertions; + +public class NavigateHomeStep extends Wiq_IntegrationTests { + + @Given("I am in the home page") + public void i_am_in_the_home_page() { + driver.navigate().to(URL); + } + + @Then("I should see the title {string}") + public void i_should_see_the_title(String title) { + Assertions.assertEquals(title, driver.getTitle()); + } + + @After + public void cleanUpAfterScenario() { + driver.manage().deleteAllCookies(); + } +} diff --git a/src/test/java/com/uniovi/util/FirefoxWebDriver.java b/src/test/java/com/uniovi/util/FirefoxWebDriver.java new file mode 100644 index 00000000..f2139971 --- /dev/null +++ b/src/test/java/com/uniovi/util/FirefoxWebDriver.java @@ -0,0 +1,47 @@ +package com.uniovi.util; + +import io.github.bonigarcia.wdm.WebDriverManager; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.support.events.EventFiringWebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FirefoxWebDriver extends EventFiringWebDriver { + + private static final WebDriver webdriver; + private static final Logger logger = LoggerFactory.getLogger(FirefoxWebDriver.class); + + private static final Thread CLOSE_THREAD = new Thread() { + @Override + public void run() { + webdriver.close(); + } + }; + + static { + WebDriverManager.firefoxdriver().setup(); + if (System.getenv("headless") != null && System.getenv("headless").equals("true")) { + FirefoxOptions options = new FirefoxOptions(); + options.addArguments("--headless"); + webdriver = new FirefoxDriver(options); + } else { + webdriver = new FirefoxDriver(); + } + + Runtime.getRuntime().addShutdownHook(CLOSE_THREAD); + } + + public FirefoxWebDriver() { + super(webdriver); + } + + @Override + public void close() { + if (Thread.currentThread() != CLOSE_THREAD) { + logger.info("You shouldn't close this WebDriver. It's shared and will close when the JVM exits."); + } + super.close(); + } +} diff --git a/src/test/java/com/uniovi/util/SeleniumUtils.java b/src/test/java/com/uniovi/util/SeleniumUtils.java index 21723d3b..2ad04cbb 100644 --- a/src/test/java/com/uniovi/util/SeleniumUtils.java +++ b/src/test/java/com/uniovi/util/SeleniumUtils.java @@ -12,6 +12,7 @@ import java.util.List; public class SeleniumUtils { + /** * Aborta si el "texto" no está presente en la página actual * @param driver: apuntando al navegador abierto actualmente. diff --git a/src/test/resources/features/home_page.feature b/src/test/resources/features/home_page.feature new file mode 100644 index 00000000..986c0454 --- /dev/null +++ b/src/test/resources/features/home_page.feature @@ -0,0 +1,5 @@ +Feature: I enter the webpage + + Scenario: I see the title + Given I am in the home page + Then I should see the title "Wikigame" \ No newline at end of file From 85b27744fffe0b75f3c8e72aeede96b3f6c8cf1b Mon Sep 17 00:00:00 2001 From: UO287568 Date: Mon, 1 Apr 2024 17:53:43 +0200 Subject: [PATCH 044/122] PlayerServiceImpl.addNewPlayer() unit tests --- src/test/java/com/uniovi/Wiq_UnitTests.java | 82 ++++++++++++++++++++- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index 69e128cc..9c01f36e 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -1,10 +1,14 @@ package com.uniovi; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; +import com.uniovi.dto.*; +import com.uniovi.entities.*; +import com.uniovi.repositories.*; +import com.uniovi.services.*; +import com.uniovi.services.impl.*; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -15,8 +19,78 @@ @ActiveProfiles("test") class Wiq_UnitTests { + @Autowired + PlayerRepository playerRepository; + @Autowired + RoleRepository roleRepository; + @Autowired + PasswordEncoder passwordEncoder; + @Test void contextLoads() { } + @Test + @Order(1) + void PlayerServiceImpl_addNewPlayer_UsedEmail() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + Player p1 = new Player("a", "abcd@gmai.com", "1234"); + playerRepository.save(p1); + + PlayerDto dto = new PlayerDto("b", "abcd@gmail.com", "1221", "1221", null); + + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> playerService.addNewPlayer(dto)); + Assertions.assertEquals("Email already in use", exception.getMessage()); + } + + @Test + @Order(2) + void PlayerServiceImpl_addNewPlayer_UsedUsername() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + Player p1 = new Player("a", "abcd@gmai.com", "1234"); + playerRepository.save(p1); + + PlayerDto dto = new PlayerDto("a", "a@gmail.com", "1221", "1221", null); + + IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> playerService.addNewPlayer(dto)); + Assertions.assertEquals("Username already in use", exception.getMessage()); + } + + @Test + @Order(3) + void PlayerServiceImpl_addNewPlayer_AddedCorrectly() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + PlayerDto dto = new PlayerDto("a", "a@gmail.com", "1221", "1221", null); + + Player player = playerService.addNewPlayer(dto); + + Assertions.assertNotNull(player); + Assertions.assertEquals(dto.getUsername(), player.getUsername()); + Assertions.assertEquals(dto.getEmail(), player.getEmail()); + Assertions.assertTrue(passwordEncoder.matches(dto.getPassword(), player.getPassword())); + } + + @Test + @Order(4) + void PlayerServiceImpl_addNewPlayer_RoleExists() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + PlayerDto dto = new PlayerDto("a", "a@gmail.com", "1221", "1221", new String[]{"ROLE_USER"}); + roleService.addRole(new RoleDto(dto.getRoles()[0])); + + Player player = playerService.addNewPlayer(dto); + + Assertions.assertNotNull(player); + Assertions.assertEquals(dto.getUsername(), player.getUsername()); + Assertions.assertEquals(dto.getEmail(), player.getEmail()); + Assertions.assertTrue(passwordEncoder.matches(dto.getPassword(), player.getPassword())); + } + } From 3052d26fbb703fc8d9a500dcf328b7be4d8643ef Mon Sep 17 00:00:00 2001 From: uo287545 Date: Mon, 1 Apr 2024 23:16:55 +0200 Subject: [PATCH 045/122] Fixed the SonarLint errors for the AbstractQuestionGenerator except the one about threads. --- .../generators/AbstractQuestionGenerator.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java b/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java index 81006a95..f38e8726 100644 --- a/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java +++ b/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java @@ -6,10 +6,6 @@ import com.uniovi.entities.Category; import com.uniovi.entities.Question; import com.uniovi.services.CategoryService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - import java.net.URI; import java.net.URLEncoder; import java.net.http.HttpClient; @@ -22,7 +18,7 @@ public abstract class AbstractQuestionGenerator implements QuestionGenerator{ private List questions = new ArrayList<>(); protected final CategoryService categoryService; - private String query; + protected String statement; protected String language; @@ -51,7 +47,7 @@ public List getQuestions() { try { String endpointUrl = "https://query.wikidata.org/sparql?query=" + - URLEncoder.encode(this.getQuery(), StandardCharsets.UTF_8.toString()) + + URLEncoder.encode(this.getQuery(), StandardCharsets.UTF_8) + "&format=json"; HttpRequest request = HttpRequest.newBuilder() @@ -72,12 +68,14 @@ public List getQuestions() { List options = this.generateOptions(resultsNode, result); String correctAnswer = this.generateCorrectAnswer(result); - String statement = this.getQuestionSubject(result); - questionGenerator(statement, options, correctAnswer, this.getCategory()); + String questionStatement = this.getQuestionSubject(result); + questionGenerator(questionStatement, options, correctAnswer, this.getCategory()); } + } catch (InterruptedException e) { + throw new QuestionGeneratorException("Generation of questions was interrupted"); } catch (Exception e) { - throw new RuntimeException(e); + throw new QuestionGeneratorException("An error occurred while generating questions"); } return questions; @@ -87,4 +85,10 @@ public List getQuestions() { protected abstract String generateCorrectAnswer(JsonNode result); protected abstract String getQuestionSubject(JsonNode result); + + private static class QuestionGeneratorException extends RuntimeException { + public QuestionGeneratorException(String message) { + super(message); + } + } } From c04b889f1dd483d64bd4ee6ade20da1f25369270 Mon Sep 17 00:00:00 2001 From: uo287545 Date: Mon, 1 Apr 2024 23:18:15 +0200 Subject: [PATCH 046/122] Fixed the SonarLint errors for the WiqEs04bApplication.java. --- src/main/java/com/uniovi/WiqEs04bApplication.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/uniovi/WiqEs04bApplication.java b/src/main/java/com/uniovi/WiqEs04bApplication.java index 7cd90279..5bfb46bc 100644 --- a/src/main/java/com/uniovi/WiqEs04bApplication.java +++ b/src/main/java/com/uniovi/WiqEs04bApplication.java @@ -1,12 +1,7 @@ package com.uniovi; -import jakarta.persistence.Persistence; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication public class WiqEs04bApplication { From 9e34f40212a7ab9b3ae104c0518dfde04aea8105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= <31128562+Pelayori@users.noreply.github.com> Date: Mon, 1 Apr 2024 23:23:39 +0200 Subject: [PATCH 047/122] Unit tests (#162) * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Fix multiple cucumber scenarios. Persistent webdriver session * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back --- .github/workflows/unit-tests-push.yml | 9 ++- pom.xml | 73 +++++++++++++++++++ .../services/InsertSampleDataService.java | 5 ++ src/main/resources/application.properties | 1 + src/test/java/com/uniovi/CucumberHooks.java | 17 +++++ ...nnerTest.java => CucumberRunnerTests.java} | 4 +- .../java/com/uniovi/CucumberWiqContext.java | 17 ----- .../java/com/uniovi/Wiq_IntegrationTests.java | 23 +++--- src/test/java/com/uniovi/Wiq_UnitTests.java | 21 ++++-- .../com/uniovi/steps/NavigateHomeStep.java | 22 +++++- .../com/uniovi/util/FirefoxWebDriver.java | 21 ------ .../java/com/uniovi/util/SeleniumUtils.java | 1 - src/test/resources/features/home_page.feature | 7 +- 13 files changed, 158 insertions(+), 63 deletions(-) create mode 100644 src/test/java/com/uniovi/CucumberHooks.java rename src/test/java/com/uniovi/{CucumberRunnerTest.java => CucumberRunnerTests.java} (68%) delete mode 100644 src/test/java/com/uniovi/CucumberWiqContext.java diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index 11deb24d..f64fe892 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -46,16 +46,19 @@ jobs: run: ./mvnw -B clean install -DskipTests=true - name: Start the application - run: ./mvnw spring-boot:run & + run: | + ./mvnw spring-boot:run & + sleep 15 env: SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/test_database SPRING_DATASOURCE_USERNAME: root SPRING_DATASOURCE_PASSWORD: root SPRING_DATASOURCE_DRIVER_CLASS_NAME: com.mysql.cj.jdbc.Driver - + - name: Check listening ports + run: ss -tuln - name: Run all tests with sonar analysis run: | - ./mvnw -B verify sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + ./mvnw -B org.jacoco:jacoco-maven-plugin:prepare-agent clean test sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -Dtest="com.uniovi.Wiq_UnitTests,com.uniovi.CucumberRunnerTests" env: SPRING_PROFILES_ACTIVE: test headless: true \ No newline at end of file diff --git a/pom.xml b/pom.xml index d02bd850..65f9bebe 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,9 @@ wiq_es04b 17 + src/main/java,src/test/resources/features + ${project.basedir}/target/jacoco.exec + ${project.basedir}/target/site/jacoco/jacoco.xml @@ -33,6 +36,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.jupiter + junit-jupiter-engine + + org.projectlombok @@ -106,13 +115,77 @@ 7.14.0 test + + io.cucumber + cucumber-junit-platform-engine + 7.14.0 + test + + + org.jacoco + jacoco-maven-plugin + 0.8.11 + + + + prepare-agent + + + + report + test + + report + + + + jacoco-merge + verify + + merge + + + + + ${project.build.directory} + + *.exec + + + + ${project.build.directory}/jacoco-merged.exec + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + **/Wiq_UnitTests.java + **/CucumberRunnerTests.java + + + org.springframework.boot spring-boot-maven-plugin + + + + + -javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/0.8.11/org.jacoco.agent-0.8.11-runtime.jar=output=tcpserver,address=*,port=6300,includes=* + + + + + diff --git a/src/main/java/com/uniovi/services/InsertSampleDataService.java b/src/main/java/com/uniovi/services/InsertSampleDataService.java index 9248c2fb..fce3766e 100644 --- a/src/main/java/com/uniovi/services/InsertSampleDataService.java +++ b/src/main/java/com/uniovi/services/InsertSampleDataService.java @@ -55,6 +55,11 @@ public void insertSampleQuestions() { return; } + generateSampleData(); + } + + @Transactional + public void generateSampleData() { if (!playerService.getUserByEmail("test@test.com").isPresent()) { PlayerDto player = new PlayerDto(); player.setEmail("test@test.com"); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6785d07b..c7dd0e75 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,6 @@ # Port 3000 for testing, local deployment server.port=3000 +server.address=0.0.0.0 # HSQL db spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver diff --git a/src/test/java/com/uniovi/CucumberHooks.java b/src/test/java/com/uniovi/CucumberHooks.java new file mode 100644 index 00000000..359f9e82 --- /dev/null +++ b/src/test/java/com/uniovi/CucumberHooks.java @@ -0,0 +1,17 @@ +package com.uniovi; + +import io.cucumber.java.After; +import io.cucumber.java.AfterAll; +import io.cucumber.java.Scenario; + +public class CucumberHooks extends Wiq_IntegrationTests { + @After + public void cleanUpAfterScenario(Scenario scenario) { + driver.manage().deleteAllCookies(); + } + + @AfterAll + public static void before_or_after_all() { + driver.quit(); + } +} diff --git a/src/test/java/com/uniovi/CucumberRunnerTest.java b/src/test/java/com/uniovi/CucumberRunnerTests.java similarity index 68% rename from src/test/java/com/uniovi/CucumberRunnerTest.java rename to src/test/java/com/uniovi/CucumberRunnerTests.java index 3d9bcc15..328e229d 100644 --- a/src/test/java/com/uniovi/CucumberRunnerTest.java +++ b/src/test/java/com/uniovi/CucumberRunnerTests.java @@ -3,8 +3,10 @@ import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; @RunWith(Cucumber.class) @CucumberOptions(plugin = {"pretty"}, features = "src/test/resources/features") -public class CucumberRunnerTest { +@SpringBootTest +public class CucumberRunnerTests { } diff --git a/src/test/java/com/uniovi/CucumberWiqContext.java b/src/test/java/com/uniovi/CucumberWiqContext.java deleted file mode 100644 index 74b8d362..00000000 --- a/src/test/java/com/uniovi/CucumberWiqContext.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.uniovi; - -import com.uniovi.util.FirefoxWebDriver; -import io.cucumber.java.After; -import org.openqa.selenium.WebDriver; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; - -public class CucumberWiqContext { - WebDriver driver; - - @Bean(name="webdriver", destroyMethod = "close") - public WebDriver webDriver() { - driver = new FirefoxWebDriver(); - return driver; - } -} diff --git a/src/test/java/com/uniovi/Wiq_IntegrationTests.java b/src/test/java/com/uniovi/Wiq_IntegrationTests.java index f7da1ced..2b265f0b 100644 --- a/src/test/java/com/uniovi/Wiq_IntegrationTests.java +++ b/src/test/java/com/uniovi/Wiq_IntegrationTests.java @@ -1,18 +1,12 @@ package com.uniovi; import com.uniovi.util.FirefoxWebDriver; -import io.cucumber.java.After; import io.cucumber.spring.CucumberContextConfiguration; import org.junit.jupiter.api.*; import org.openqa.selenium.WebDriver; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; - -import static org.junit.jupiter.api.Assertions.fail; @SpringBootTest @Tag("integration") @@ -20,10 +14,21 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @ActiveProfiles("test") @CucumberContextConfiguration -@ContextConfiguration(classes = CucumberWiqContext.class) public class Wiq_IntegrationTests { protected static final String URL = "http://localhost:3000/"; - @Autowired - protected WebDriver driver; + protected static WebDriver driver; + + public Wiq_IntegrationTests() { + driver = webDriver(); + } + + public WebDriver webDriver() { + if (driver != null) { + return driver; + } + + driver = new FirefoxWebDriver(); + return driver; + } } diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index 69e128cc..f1003da9 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -1,22 +1,29 @@ package com.uniovi; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; +import com.uniovi.entities.Player; +import com.uniovi.services.PlayerService; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import java.util.List; + +import java.util.Optional; @SpringBootTest @Tag("unit") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @ActiveProfiles("test") -class Wiq_UnitTests { +public class Wiq_UnitTests { + @Autowired + private PlayerService playerService; @Test - void contextLoads() { + @Order(1) + public void testPlayerService() { + List players = playerService.getUsersByRole("ROLE_USER"); + Assertions.assertEquals(0, players.size()); } - } diff --git a/src/test/java/com/uniovi/steps/NavigateHomeStep.java b/src/test/java/com/uniovi/steps/NavigateHomeStep.java index acec65b0..f0652924 100644 --- a/src/test/java/com/uniovi/steps/NavigateHomeStep.java +++ b/src/test/java/com/uniovi/steps/NavigateHomeStep.java @@ -1,10 +1,19 @@ package com.uniovi.steps; import com.uniovi.*; +import com.uniovi.util.SeleniumUtils; import io.cucumber.java.After; +import io.cucumber.java.AfterAll; +import io.cucumber.java.Scenario; +import io.cucumber.java.en.And; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; public class NavigateHomeStep extends Wiq_IntegrationTests { @@ -18,8 +27,15 @@ public void i_should_see_the_title(String title) { Assertions.assertEquals(title, driver.getTitle()); } - @After - public void cleanUpAfterScenario() { - driver.manage().deleteAllCookies(); + @When("I click the register button") + public void i_click_the_register_button() { + List elems = SeleniumUtils.waitLoadElementsBy(driver, "@href", "signup", 5); + elems.get(0).click(); + } + + @Then("I should see the register page") + public void i_should_see_the_register_page() { + SeleniumUtils.waitLoadElementsBy(driver, "h2", "Regístrate", 5); + SeleniumUtils.textIsPresentOnPage(driver, "Regístrate"); } } diff --git a/src/test/java/com/uniovi/util/FirefoxWebDriver.java b/src/test/java/com/uniovi/util/FirefoxWebDriver.java index f2139971..dc8d340e 100644 --- a/src/test/java/com/uniovi/util/FirefoxWebDriver.java +++ b/src/test/java/com/uniovi/util/FirefoxWebDriver.java @@ -5,20 +5,9 @@ import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.support.events.EventFiringWebDriver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class FirefoxWebDriver extends EventFiringWebDriver { - private static final WebDriver webdriver; - private static final Logger logger = LoggerFactory.getLogger(FirefoxWebDriver.class); - - private static final Thread CLOSE_THREAD = new Thread() { - @Override - public void run() { - webdriver.close(); - } - }; static { WebDriverManager.firefoxdriver().setup(); @@ -29,19 +18,9 @@ public void run() { } else { webdriver = new FirefoxDriver(); } - - Runtime.getRuntime().addShutdownHook(CLOSE_THREAD); } public FirefoxWebDriver() { super(webdriver); } - - @Override - public void close() { - if (Thread.currentThread() != CLOSE_THREAD) { - logger.info("You shouldn't close this WebDriver. It's shared and will close when the JVM exits."); - } - super.close(); - } } diff --git a/src/test/java/com/uniovi/util/SeleniumUtils.java b/src/test/java/com/uniovi/util/SeleniumUtils.java index 2ad04cbb..aee85f0c 100644 --- a/src/test/java/com/uniovi/util/SeleniumUtils.java +++ b/src/test/java/com/uniovi/util/SeleniumUtils.java @@ -101,7 +101,6 @@ static public List waitLoadElementsBy(WebDriver driver, String crite /** - * PROHIBIDO USARLO PARA VERSIÓN FINAL. * Esperar "segundos" durante la ejecucion del navegador * @param driver: apuntando al navegador abierto actualmente. * @param seconds: Segundos de bloqueo de la ejecución en el navegador. diff --git a/src/test/resources/features/home_page.feature b/src/test/resources/features/home_page.feature index 986c0454..0c9f5a92 100644 --- a/src/test/resources/features/home_page.feature +++ b/src/test/resources/features/home_page.feature @@ -2,4 +2,9 @@ Feature: I enter the webpage Scenario: I see the title Given I am in the home page - Then I should see the title "Wikigame" \ No newline at end of file + Then I should see the title "Wikigame" + + Scenario: I click register + Given I am in the home page + When I click the register button + Then I should see the register page \ No newline at end of file From f87b89892f84cfef6cc45e27cface5e0e1e0689f Mon Sep 17 00:00:00 2001 From: UO287568 Date: Mon, 1 Apr 2024 23:52:51 +0200 Subject: [PATCH 048/122] PlayerServiceImpl getUsers, getUserByEmail y getUserByUsername unit tests --- src/test/java/com/uniovi/Wiq_UnitTests.java | 94 +++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index 9c01f36e..f8429c10 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -12,6 +12,10 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + @SpringBootTest @Tag("unit") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @@ -93,4 +97,94 @@ void PlayerServiceImpl_addNewPlayer_RoleExists() { Assertions.assertTrue(passwordEncoder.matches(dto.getPassword(), player.getPassword())); } + @Test + @Order(5) + void PlayerServiceImpl_getUsers_ReturnsPlayersList() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + List players = new ArrayList<>(); + players.add(new Player("a", "a@gmail.com", "1a")); + players.add(new Player("b", "b@gmail.com", "1b")); + + playerRepository.save(new Player("a", "a@gmail.com", "1a")); + playerRepository.save(new Player("b", "b@gmail.com", "1b")); + + List result = playerService.getUsers(); + + Assertions.assertEquals(players.size(), result.size()); + for (int i = 0; i < players.size(); i++) { + Assertions.assertEquals(players.get(i), result.get(i)); + } + } + + @Test + @Order(6) + void PlayerServiceImpl_getUsers_ReturnsEmptyList() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + List result = playerService.getUsers(); + + Assertions.assertEquals(0, result.size()); + } + + @Test + @Order(7) + void PlayerServiceImpl_getUserByEmail_ReturnsPlayer() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + String email = "a@gmail.com"; + Player player = new Player("a", email, "password"); + + playerRepository.save(player); + + Optional result = playerService.getUserByEmail(email); + + Assertions.assertEquals(player, result.orElse(null)); + } + + @Test + @Order(8) + void PlayerServiceImpl_getUserByEmail_ReturnsEmpty() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + String email = "nonexist@gmail.com"; + + Optional result = playerService.getUserByEmail(email); + + Assertions.assertEquals(Optional.empty(), result); + } + + @Test + @Order(9) + void PlayerServiceImpl_getUserByUsername_ReturnsPlayer() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + String username = "abc"; + Player player = new Player(username, "a@gmail,com", "password"); + + playerRepository.save(player); + + Optional result = playerService.getUserByUsername(username); + + Assertions.assertEquals(player, result.orElse(null)); + } + + @Test + @Order(10) + void PlayerServiceImpl_getUserByUsername_ReturnsEmpty() { + RoleService roleService = new RoleServiceImpl(roleRepository); + PlayerServiceImpl playerService = new PlayerServiceImpl(playerRepository, roleService, passwordEncoder); + + String username = "nonexist"; + + Optional result = playerService.getUserByUsername(username); + + Assertions.assertEquals(Optional.empty(), result); + } + } From ce51616385f76f05cf821324f17745defd990443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= <31128562+Pelayori@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:02:10 +0200 Subject: [PATCH 049/122] Unit tests (#163) * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Test coverage fix * Fix multiple cucumber scenarios. Persistent webdriver session * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Test run integration tests * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Add caching back * Fix some tests * Fix some tests * Fix some tests --- .github/workflows/unit-tests-push.yml | 2 +- pom.xml | 54 +++++++++++++++---- src/main/java/com/uniovi/entities/Role.java | 2 +- .../services/InsertSampleDataService.java | 17 +++--- src/test/java/com/uniovi/Wiq_UnitTests.java | 4 +- 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/.github/workflows/unit-tests-push.yml b/.github/workflows/unit-tests-push.yml index f64fe892..a05c42bd 100644 --- a/.github/workflows/unit-tests-push.yml +++ b/.github/workflows/unit-tests-push.yml @@ -58,7 +58,7 @@ jobs: run: ss -tuln - name: Run all tests with sonar analysis run: | - ./mvnw -B org.jacoco:jacoco-maven-plugin:prepare-agent clean test sonar:sonar -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -Dtest="com.uniovi.Wiq_UnitTests,com.uniovi.CucumberRunnerTests" + ./mvnw -B org.jacoco:jacoco-maven-plugin:prepare-agent clean test sonar:sonar -DEXCLUDE_JUNIT=true -Dsonar.projectKey=Arquisoft_wiq_es04b -Dsonar.organization=arquisoft -Dsonar.branch.name=${{ github.ref }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dspring.profiles.active=test -Dspring.datasource.url=jdbc:mysql://localhost:3306/test_database -Dspring.datasource.username=root -Dspring.datasource.password=root -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -Dtest="com.uniovi.Wiq_UnitTests,com.uniovi.CucumberRunnerTests" env: SPRING_PROFILES_ACTIVE: test headless: true \ No newline at end of file diff --git a/pom.xml b/pom.xml index 65f9bebe..54cdb311 100644 --- a/pom.xml +++ b/pom.xml @@ -32,17 +32,6 @@ org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.jupiter - junit-jupiter-engine - - - org.projectlombok lombok @@ -189,5 +178,48 @@ + + + + exclude-junit + + + env.EXCLUDE_JUNIT + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.jupiter + junit-jupiter-engine + + + + + + + + include-junit + + true + + !env.EXCLUDE_JUNIT + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + diff --git a/src/main/java/com/uniovi/entities/Role.java b/src/main/java/com/uniovi/entities/Role.java index deaa4b6a..c767c425 100644 --- a/src/main/java/com/uniovi/entities/Role.java +++ b/src/main/java/com/uniovi/entities/Role.java @@ -16,7 +16,7 @@ public class Role { @Id private String name; - @ManyToMany(mappedBy = "roles") + @ManyToMany(mappedBy = "roles", fetch = FetchType.EAGER) private Set players = new HashSet<>(); public Role(String name) { diff --git a/src/main/java/com/uniovi/services/InsertSampleDataService.java b/src/main/java/com/uniovi/services/InsertSampleDataService.java index fce3766e..f05dc00c 100644 --- a/src/main/java/com/uniovi/services/InsertSampleDataService.java +++ b/src/main/java/com/uniovi/services/InsertSampleDataService.java @@ -50,6 +50,15 @@ public InsertSampleDataService(PlayerService playerService, QuestionService ques @Transactional @EventListener(ApplicationReadyEvent.class) // Uncomment this line to insert sample data on startup public void insertSampleQuestions() { + if (!playerService.getUserByEmail("test@test.com").isPresent()) { + PlayerDto player = new PlayerDto(); + player.setEmail("test@test.com"); + player.setUsername("test"); + player.setPassword("test"); + player.setRoles(new String[]{"ROLE_USER"}); + playerService.generateApiKey(playerService.addNewPlayer(player)); + } + if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> (env.equalsIgnoreCase("test")))) { log.info("Test profile active, skipping sample data insertion"); return; @@ -60,14 +69,6 @@ public void insertSampleQuestions() { @Transactional public void generateSampleData() { - if (!playerService.getUserByEmail("test@test.com").isPresent()) { - PlayerDto player = new PlayerDto(); - player.setEmail("test@test.com"); - player.setUsername("test"); - player.setPassword("test"); - player.setRoles(new String[]{"ROLE_USER"}); - playerService.generateApiKey(playerService.addNewPlayer(player)); - } questionRepository.deleteAll(); diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index f1003da9..f96806f0 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -9,8 +9,6 @@ import org.springframework.test.context.ActiveProfiles; import java.util.List; -import java.util.Optional; - @SpringBootTest @Tag("unit") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @@ -24,6 +22,6 @@ public class Wiq_UnitTests { @Order(1) public void testPlayerService() { List players = playerService.getUsersByRole("ROLE_USER"); - Assertions.assertEquals(0, players.size()); + Assertions.assertEquals(1, players.size()); } } From 5b7dac3b93e1e454e0d3aad1e194670fb81b9df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iker=20=C3=81lvarez=20Fern=C3=A1ndez?= Date: Tue, 2 Apr 2024 13:14:53 +0200 Subject: [PATCH 050/122] Fixed SecurityHotSpots --- .../components/generators/AbstractQuestionGenerator.java | 3 +++ .../generators/geography/BorderQuestionGenerator.java | 1 - .../generators/geography/CapitalQuestionGenerator.java | 1 - .../generators/geography/ContinentQuestionGeneration.java | 1 - .../java/com/uniovi/services/impl/QuestionServiceImpl.java | 6 ++++-- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java b/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java index f38e8726..7c534d91 100644 --- a/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java +++ b/src/main/java/com/uniovi/components/generators/AbstractQuestionGenerator.java @@ -14,11 +14,14 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Random; public abstract class AbstractQuestionGenerator implements QuestionGenerator{ private List questions = new ArrayList<>(); protected final CategoryService categoryService; + protected Random random = new Random(); + protected String statement; protected String language; diff --git a/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java b/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java index f791f1e5..fca48c95 100644 --- a/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java +++ b/src/main/java/com/uniovi/components/generators/geography/BorderQuestionGenerator.java @@ -33,7 +33,6 @@ private List getAllBorderingCountries(JsonNode resultsNode, String corre private List selectRandomIncorrectBorderingCountries(List allBorderingCountries, String correctCountry, int count) { List incorrectBorderingCountries = new ArrayList<>(); - Random random = new Random(); while (incorrectBorderingCountries.size() < count && allBorderingCountries.size() > 0) { int randomIndex = random.nextInt(allBorderingCountries.size()); String selectedBorderingCountry = allBorderingCountries.remove(randomIndex); diff --git a/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java b/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java index e5d91727..b926a6a3 100644 --- a/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java +++ b/src/main/java/com/uniovi/components/generators/geography/CapitalQuestionGenerator.java @@ -48,7 +48,6 @@ private List getAllCapitals(JsonNode resultsNode, String correctCapital) private List selectRandomIncorrectCapitals(List allCapitals, String correctCapital, int count) { List incorrectCapitals = new ArrayList<>(); - Random random = new Random(); while (incorrectCapitals.size() < count && allCapitals.size() > 0) { int randomIndex = random.nextInt(allCapitals.size()); String selectedCapital = allCapitals.remove(randomIndex); diff --git a/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java b/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java index b1d476ae..9b09dacb 100644 --- a/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java +++ b/src/main/java/com/uniovi/components/generators/geography/ContinentQuestionGeneration.java @@ -34,7 +34,6 @@ private List getAllContinents(JsonNode resultsNode, String correctContin private List selectRandomIncorrectContinents(List allContinents, String correctContinent, int count) { List incorrectContinents = new ArrayList<>(); - Random random = new Random(); while (incorrectContinents.size() < count && allContinents.size() > 0) { int randomIndex = random.nextInt(allContinents.size()); String selectedCapital = allContinents.remove(randomIndex); diff --git a/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java b/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java index d45c1b5f..6caf6b60 100644 --- a/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java +++ b/src/main/java/com/uniovi/services/impl/QuestionServiceImpl.java @@ -14,11 +14,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.Random; @Service public class QuestionServiceImpl implements QuestionService { private final QuestionRepository questionRepository; + private final Random random = new Random(); public QuestionServiceImpl(QuestionRepository questionRepository) { this.questionRepository = questionRepository; @@ -47,9 +49,9 @@ public List getRandomQuestions(int num) { .filter(question -> question.getLanguage().equals(LocaleContextHolder.getLocale().getLanguage())).toList(); List res = new ArrayList<>(); for (int i = 0; i < num; i++) { - int idx = (int) (Math.random() * allQuestions.size()); + int idx = random.nextInt(allQuestions.size()); while (allQuestions.get(idx).hasEmptyOptions()){ - idx = (int) (Math.random() * allQuestions.size()); + idx = random.nextInt(allQuestions.size()); } res.add(allQuestions.get(idx)); } From 8ac8de23d067ed9f10eafd6636ae84a595d328d8 Mon Sep 17 00:00:00 2001 From: uo288061 Date: Tue, 2 Apr 2024 20:44:55 +0200 Subject: [PATCH 051/122] basics units tests for questions generator --- .../services/InsertSampleDataService.java | 2 +- src/test/java/com/uniovi/Wiq_UnitTests.java | 76 ++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uniovi/services/InsertSampleDataService.java b/src/main/java/com/uniovi/services/InsertSampleDataService.java index 1ac58636..cfab4b6d 100644 --- a/src/main/java/com/uniovi/services/InsertSampleDataService.java +++ b/src/main/java/com/uniovi/services/InsertSampleDataService.java @@ -34,7 +34,7 @@ public class InsertSampleDataService { private final GameSessionRepository gameSessionRepository; private Environment environment; - private Logger log = LoggerFactory.getLogger(InsertSampleDataService.class);; + private Logger log = LoggerFactory.getLogger(InsertSampleDataService.class); public InsertSampleDataService(PlayerService playerService, QuestionService questionService, CategoryService categoryService, QuestionRepository questionRepository, diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index f96806f0..7dec4912 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -1,7 +1,15 @@ package com.uniovi; +import com.uniovi.components.generators.geography.BorderQuestionGenerator; +import com.uniovi.components.generators.geography.CapitalQuestionGenerator; +import com.uniovi.components.generators.geography.ContinentQuestionGeneration; import com.uniovi.entities.Player; +import com.uniovi.entities.Question; +import com.uniovi.services.AnswerService; +import com.uniovi.services.CategoryService; import com.uniovi.services.PlayerService; +import com.uniovi.services.QuestionService; +import com.uniovi.services.impl.QuestionServiceImpl; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -9,6 +17,10 @@ import org.springframework.test.context.ActiveProfiles; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + @SpringBootTest @Tag("unit") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @@ -17,11 +29,73 @@ public class Wiq_UnitTests { @Autowired private PlayerService playerService; - + @Autowired + private AnswerService answerService; + @Autowired + private QuestionService questionService; + @Autowired + private CategoryService categoryService; @Test @Order(1) public void testPlayerService() { List players = playerService.getUsersByRole("ROLE_USER"); Assertions.assertEquals(1, players.size()); } + @Test + @Order(2) + public void testQuestions(){ + List questions = questionService.getAllQuestions(); + Assertions.assertEquals(3802,questions.size()); + + } + @Test + @Order(2) + public void testRandomQuestions(){ + List questions = questionService.getRandomQuestions(5); + Assertions.assertEquals(5,questions.size()); + } + + @Test + @Order(3) + public void testBorderQuestionsGenerator(){ + BorderQuestionGenerator borderQuestionGenerator=new BorderQuestionGenerator(categoryService,Question.SPANISH); + List questions = borderQuestionGenerator.getQuestions(); + Assertions.assertEquals(855,questions.size()); + + for (Question question : questions) { + Assertions.assertNotNull(question.getCorrectAnswer()); + Assertions.assertEquals(4, question.getOptions().size()); + Assertions.assertTrue(question.getOptions().contains(question.getCorrectAnswer())); + } + } + + @Test + @Order(4) + public void testCapitalQuestionsGenerator(){ + CapitalQuestionGenerator capitalQuestionGenerator=new CapitalQuestionGenerator(categoryService,Question.SPANISH); + List questions = capitalQuestionGenerator.getQuestions(); + Assertions.assertEquals(206,questions.size()); + + for (Question question : questions) { + Assertions.assertNotNull(question.getCorrectAnswer()); + Assertions.assertEquals(4, question.getOptions().size()); + Assertions.assertTrue(question.getOptions().contains(question.getCorrectAnswer())); + } + } + + @Test + @Order(5) + public void testContinentQuestionsGenerator(){ + ContinentQuestionGeneration continentQuestionGenerator=new ContinentQuestionGeneration(categoryService,Question.SPANISH); + List questions = continentQuestionGenerator.getQuestions(); + Assertions.assertEquals(207,questions.size()); + + for (Question question : questions) { + Assertions.assertNotNull(question.getCorrectAnswer()); + Assertions.assertEquals(4, question.getOptions().size()); + Assertions.assertTrue(question.getOptions().contains(question.getCorrectAnswer())); + } + } + + } From 9feed5767c19bd401c5efbbae2330cd594001940 Mon Sep 17 00:00:00 2001 From: uo288061 Date: Wed, 3 Apr 2024 19:22:54 +0200 Subject: [PATCH 052/122] units tests for Associations class --- .../com/uniovi/entities/Associations.java | 8 +- src/test/java/com/uniovi/Wiq_UnitTests.java | 125 +++++++++++++++++- 2 files changed, 128 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/uniovi/entities/Associations.java b/src/main/java/com/uniovi/entities/Associations.java index 28493169..e0a578a9 100644 --- a/src/main/java/com/uniovi/entities/Associations.java +++ b/src/main/java/com/uniovi/entities/Associations.java @@ -121,10 +121,16 @@ public static void addAnswer(Question question, List answer) { * @param answer The answer */ public static void removeAnswer(Question question, List answer) { - question.getOptions().remove(answer); + question.getOptions().removeAll(answer); for (Answer a : answer) { a.setQuestion(null); } } + //public static void removeAnswer(Question question, List answer) { + // question.getOptions().remove(answer); + //for (Answer a : answer) { + // a.setQuestion(null); + //} + //} } } diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index 7dec4912..4e9a6853 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -3,8 +3,7 @@ import com.uniovi.components.generators.geography.BorderQuestionGenerator; import com.uniovi.components.generators.geography.CapitalQuestionGenerator; import com.uniovi.components.generators.geography.ContinentQuestionGeneration; -import com.uniovi.entities.Player; -import com.uniovi.entities.Question; +import com.uniovi.entities.*; import com.uniovi.services.AnswerService; import com.uniovi.services.CategoryService; import com.uniovi.services.PlayerService; @@ -15,10 +14,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; + +import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertNotNull; @SpringBootTest @@ -97,5 +97,122 @@ public void testContinentQuestionsGenerator(){ } } + @Test + @Order(6) + public void testAddRole() { + Player player = new Player("name","email","password"); + Role role = new Role(); + Associations.PlayerRole.addRole(player, role); + Assertions.assertTrue(player.getRoles().contains(role)); + Assertions.assertTrue(role.getPlayers().contains(player)); + } + + @Test + @Order(7) + public void testRemoveRole() { + Player player = new Player("name","email","password"); + Role role = new Role(); + Associations.PlayerRole.addRole(player, role); + Associations.PlayerRole.removeRole(player, role); + Assertions.assertFalse(player.getRoles().contains(role)); + Assertions.assertFalse(role.getPlayers().contains(player)); + } + + @Test + @Order(8) + public void testAddApiKey() { + Player player = new Player("name","email","password"); + ApiKey apiKey = new ApiKey(); + Associations.PlayerApiKey.addApiKey(player, apiKey); + Assertions.assertEquals(player.getApiKey(), apiKey); + Assertions.assertEquals(apiKey.getPlayer(), player); + } + + @Test + @Order(9) + public void testRemoveApiKey() { + Player player = new Player("name","email","password"); + ApiKey apiKey = new ApiKey(); + Associations.PlayerApiKey.addApiKey(player, apiKey); + Associations.PlayerApiKey.removeApiKey(player, apiKey); + assertNull(player.getApiKey()); + assertNull(apiKey.getPlayer()); + } + + @Test + @Order(9) + public void testAddAccessLog() { + ApiKey apiKey = new ApiKey(); + RestApiAccessLog accessLog = new RestApiAccessLog(); + Associations.ApiKeyAccessLog.addAccessLog(apiKey, accessLog); + Assertions.assertTrue(apiKey.getAccessLogs().contains(accessLog)); + Assertions.assertEquals(accessLog.getApiKey(), apiKey); + } + + @Test + @Order(10) + public void testRemoveAccessLog() { + ApiKey apiKey = new ApiKey(); + RestApiAccessLog accessLog = new RestApiAccessLog(); + Associations.ApiKeyAccessLog.addAccessLog(apiKey, accessLog); + Associations.ApiKeyAccessLog.removeAccessLog(apiKey, accessLog); + Assertions.assertFalse(apiKey.getAccessLogs().contains(accessLog)); + Assertions.assertNull(accessLog.getApiKey()); + } + + @Test + @Order(11) + public void testAddGameSession() { + Player player = new Player("name","email","password"); + GameSession gameSession = new GameSession(); + Associations.PlayerGameSession.addGameSession(player, gameSession); + assertTrue(player.getGameSessions().contains(gameSession)); + assertEquals(gameSession.getPlayer(), player); + } + + @Test + @Order(12) + public void testRemoveGameSession() { + Player player = new Player("name","email","password"); + GameSession gameSession = new GameSession(); + Associations.PlayerGameSession.addGameSession(player, gameSession); + Associations.PlayerGameSession.removeGameSession(player, gameSession); + Assertions.assertFalse(player.getGameSessions().contains(gameSession)); + Assertions.assertNull(gameSession.getPlayer()); + } + + @Test + @Order(13) + public void testAddAnswer() { + Question question = new Question(); + List answers = new ArrayList<>(); + Answer answer1 = new Answer(); + Answer answer2 = new Answer(); + answers.add(answer1); + answers.add(answer2); + Associations.QuestionAnswers.addAnswer(question, answers); + assertTrue(question.getOptions().contains(answer1)); + assertTrue(question.getOptions().contains(answer2)); + assertEquals(answer1.getQuestion(), question); + assertEquals(answer2.getQuestion(), question); + } + + @Test + @Order(14) + public void testRemoveAnswer() { + Question question = new Question(); + List answers = new ArrayList<>(); + Answer answer1 = new Answer(); + Answer answer2 = new Answer(); + answers.add(answer1); + answers.add(answer2); + Associations.QuestionAnswers.addAnswer(question, answers); + Associations.QuestionAnswers.removeAnswer(question, answers); + Assertions.assertFalse(question.getOptions().contains(answer1)); + Assertions.assertFalse(question.getOptions().contains(answer2)); + Assertions.assertNull(answer1.getQuestion()); + Assertions.assertNull(answer2.getQuestion()); + } + } From 5f28ad34b65546abde089767055d5d755fc9bd5d Mon Sep 17 00:00:00 2001 From: uo288061 Date: Wed, 3 Apr 2024 20:10:45 +0200 Subject: [PATCH 053/122] units tests for Category class --- src/test/java/com/uniovi/Wiq_UnitTests.java | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index 4e9a6853..d8bb4346 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -1,5 +1,6 @@ package com.uniovi; +import com.fasterxml.jackson.databind.JsonNode; import com.uniovi.components.generators.geography.BorderQuestionGenerator; import com.uniovi.components.generators.geography.CapitalQuestionGenerator; import com.uniovi.components.generators.geography.ContinentQuestionGeneration; @@ -16,7 +17,9 @@ import org.springframework.test.context.ActiveProfiles; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -214,5 +217,37 @@ public void testRemoveAnswer() { Assertions.assertNull(answer2.getQuestion()); } + @Test + @Order(15) + public void testCategoryCreation() { + Category category = new Category("Test Category", "This is a test category"); + Assertions.assertEquals("Test Category", category.getName()); + Assertions.assertEquals("This is a test category", category.getDescription()); + } + + @Test + @Order(16) + public void testJsonGeneration() { + Category category = new Category("Test Category", "This is a test category"); + JsonNode json = category.toJson(); + Assertions.assertEquals("Test Category", json.get("name").asText()); + Assertions.assertEquals("This is a test category", json.get("description").asText()); + } + + @Test + @Order(17) + public void testQuestionAssociation() { + Category category = new Category("Test Category", "This is a test category"); + Question question = new Question(); + question.setCategory(category); + + Set questions = new HashSet<>(); + questions.add(question); + category.setQuestions(questions); + + Assertions.assertEquals(1, category.getQuestions().size()); + Assertions.assertTrue(category.getQuestions().contains(question)); + } + } From 026223d491bd18810682da19b9f53998ff801808 Mon Sep 17 00:00:00 2001 From: uo288061 Date: Wed, 3 Apr 2024 20:17:16 +0200 Subject: [PATCH 054/122] units tests for Category class --- src/test/java/com/uniovi/Wiq_UnitTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index d8bb4346..5a4b0d94 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -133,13 +133,13 @@ public void testAddApiKey() { @Test @Order(9) - public void testRemoveApiKey() { + void testRemoveApiKey() { Player player = new Player("name","email","password"); ApiKey apiKey = new ApiKey(); Associations.PlayerApiKey.addApiKey(player, apiKey); Associations.PlayerApiKey.removeApiKey(player, apiKey); - assertNull(player.getApiKey()); - assertNull(apiKey.getPlayer()); + Assertions.assertNull(player.getApiKey()); + Assertions.assertNull(apiKey.getPlayer()); } @Test From 9df19db020c8f62d389bc4e4b012fbf345ebe1fb Mon Sep 17 00:00:00 2001 From: uo288061 Date: Wed, 3 Apr 2024 21:33:27 +0200 Subject: [PATCH 055/122] units tests for GameSession class --- src/test/java/com/uniovi/Wiq_UnitTests.java | 90 +++++++++++++++++++-- 1 file changed, 83 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index 5a4b0d94..9bd149b7 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -9,13 +9,13 @@ import com.uniovi.services.CategoryService; import com.uniovi.services.PlayerService; import com.uniovi.services.QuestionService; -import com.uniovi.services.impl.QuestionServiceImpl; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -169,8 +169,8 @@ public void testAddGameSession() { Player player = new Player("name","email","password"); GameSession gameSession = new GameSession(); Associations.PlayerGameSession.addGameSession(player, gameSession); - assertTrue(player.getGameSessions().contains(gameSession)); - assertEquals(gameSession.getPlayer(), player); + Assertions.assertTrue(player.getGameSessions().contains(gameSession)); + Assertions.assertEquals(gameSession.getPlayer(), player); } @Test @@ -194,10 +194,10 @@ public void testAddAnswer() { answers.add(answer1); answers.add(answer2); Associations.QuestionAnswers.addAnswer(question, answers); - assertTrue(question.getOptions().contains(answer1)); - assertTrue(question.getOptions().contains(answer2)); - assertEquals(answer1.getQuestion(), question); - assertEquals(answer2.getQuestion(), question); + Assertions.assertTrue(question.getOptions().contains(answer1)); + Assertions.assertTrue(question.getOptions().contains(answer2)); + Assertions.assertEquals(answer1.getQuestion(), question); + Assertions.assertEquals(answer2.getQuestion(), question); } @Test @@ -249,5 +249,81 @@ public void testQuestionAssociation() { Assertions.assertTrue(category.getQuestions().contains(question)); } + @Test + @Order(18) + public void testAnswerToJson() { + Question question = new Question(); + question.setId(1L); + + Answer answer = new Answer("Sample Answer", true); + answer.setQuestion(question); + answer.setId(1L); + + JsonNode json = answer.toJson(); + + Assertions.assertEquals(1L, json.get("id").asLong()); + Assertions.assertEquals("Sample Answer", json.get("text").asText()); + Assertions.assertTrue(json.get("correct").asBoolean()); + Assertions.assertEquals(1L, json.get("question").asLong()); + } + + @Test + @Order(19) + public void testAddQuestion_Correct() { + Player player = new Player("name","email","password"); + List questions = new ArrayList<>(); + GameSession gameSession = new GameSession(player, questions); + + int initialScore = gameSession.getScore(); + gameSession.addQuestion(true, 20); + Assertions.assertEquals(initialScore + 30, gameSession.getScore()); + Assertions.assertEquals(1, gameSession.getCorrectQuestions()); + Assertions.assertEquals(1, gameSession.getTotalQuestions()); + } + + @Test + @Order(20) + public void testAddQuestion_Incorrect() { + Player player = new Player("name","email","password"); + List questions = new ArrayList<>(); + GameSession gameSession = new GameSession(player, questions); + + int initialScore = gameSession.getScore(); + gameSession.addQuestion(false, 20); + Assertions.assertEquals(initialScore, gameSession.getScore()); + Assertions.assertEquals(0, gameSession.getCorrectQuestions()); + Assertions.assertEquals(1, gameSession.getTotalQuestions()); + } + + @Test + @Order(20) + public void testAddAnsweredQuestion() { + Player player = new Player("name","email","password"); + List questions = new ArrayList<>(); + Question question = new Question(); + questions.add(question); + GameSession gameSession = new GameSession(player, questions); + + Assertions.assertTrue(gameSession.getQuestionsToAnswer().contains(question)); + Assertions.assertFalse(gameSession.getAnsweredQuestions().contains(question)); + gameSession.addAnsweredQuestion(question); + Assertions.assertFalse(gameSession.getQuestionsToAnswer().contains(question)); + Assertions.assertTrue(gameSession.getAnsweredQuestions().contains(question)); + } + + @Test + @Order(21) + public void testGetDuration() { + LocalDateTime createdAt = LocalDateTime.of(2022, 1, 1, 10, 0); // Assuming game started at 10:00 AM + LocalDateTime finishTime = LocalDateTime.of(2022, 1, 1, 10, 5); // Assuming game finished at 10:05 AM + Player player = new Player("name","email","password"); + List questions = new ArrayList<>(); + GameSession gameSession = new GameSession(player, questions); + gameSession.setCreatedAt(createdAt); + gameSession.setFinishTime(finishTime); + + Assertions.assertEquals("00:05:00", gameSession.getDuration()); + } + } From 85cd6843aa30f94001a648fea893d3db32593a87 Mon Sep 17 00:00:00 2001 From: uo287545 Date: Thu, 4 Apr 2024 19:06:47 +0200 Subject: [PATCH 056/122] Added cucumber scenarios --- src/test/resources/features/home_page.feature | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/test/resources/features/home_page.feature b/src/test/resources/features/home_page.feature index 0c9f5a92..1993d72d 100644 --- a/src/test/resources/features/home_page.feature +++ b/src/test/resources/features/home_page.feature @@ -1,10 +1,30 @@ -Feature: I enter the webpage +Feature: I enter the webpage without being logged in Scenario: I see the title Given I am in the home page + Given I am not logged in Then I should see the title "Wikigame" Scenario: I click register Given I am in the home page + Given I am not logged in When I click the register button - Then I should see the register page \ No newline at end of file + Then I should see the register page + + Scenario: I click login + Given I am in the home page + Given I am not logged in + When I click the login button + Then I should see the login page + + Scenario: I click play + Given I am in the home page + Given I am not logged in + When I click the play button + Then I should see the login page + + Scenario: I click global ranking + Given I am in the home page + Given I am not logged in + When I click the global ranking button + Then I should see the global ranking page From 00efa0a399196a35ec352939912f1655f5950b9c Mon Sep 17 00:00:00 2001 From: uo287545 Date: Thu, 4 Apr 2024 19:17:51 +0200 Subject: [PATCH 057/122] Fixed some deprecated Thymeleaf properties --- src/main/resources/templates/player/signup.html | 2 +- src/main/resources/templates/ranking/globalRanking.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/player/signup.html b/src/main/resources/templates/player/signup.html index 93525fdd..af9c659e 100644 --- a/src/main/resources/templates/player/signup.html +++ b/src/main/resources/templates/player/signup.html @@ -54,6 +54,6 @@

-