diff --git a/docs/images/08-Crosscutting-Concepts-Structure-EN.png b/docs/images/08-Crosscutting-Concepts-Structure-EN.png deleted file mode 100644 index 5598a0b..0000000 Binary files a/docs/images/08-Crosscutting-Concepts-Structure-EN.png and /dev/null differ diff --git a/docs/images/08_api_jacoco_tests.png b/docs/images/08_api_jacoco_tests.png new file mode 100644 index 0000000..d21dbc8 Binary files /dev/null and b/docs/images/08_api_jacoco_tests.png differ diff --git a/docs/images/08_category_gatling_test_01.png b/docs/images/08_category_gatling_test_01.png new file mode 100644 index 0000000..3d32bf1 Binary files /dev/null and b/docs/images/08_category_gatling_test_01.png differ diff --git a/docs/images/08_category_gatling_test_02.png b/docs/images/08_category_gatling_test_02.png new file mode 100644 index 0000000..7dd20d5 Binary files /dev/null and b/docs/images/08_category_gatling_test_02.png differ diff --git a/docs/images/08_category_gatling_test_03.png b/docs/images/08_category_gatling_test_03.png new file mode 100644 index 0000000..ede4818 Binary files /dev/null and b/docs/images/08_category_gatling_test_03.png differ diff --git a/docs/images/08_cypress-tool.png b/docs/images/08_cypress-tool.png new file mode 100644 index 0000000..60f7aec Binary files /dev/null and b/docs/images/08_cypress-tool.png differ diff --git a/docs/images/08_cypress_test_running.png b/docs/images/08_cypress_test_running.png new file mode 100644 index 0000000..2b543be Binary files /dev/null and b/docs/images/08_cypress_test_running.png differ diff --git a/docs/images/08_cypress_tool_tests.png b/docs/images/08_cypress_tool_tests.png new file mode 100644 index 0000000..8517f67 Binary files /dev/null and b/docs/images/08_cypress_tool_tests.png differ diff --git a/docs/images/08_java_tests.png b/docs/images/08_java_tests.png new file mode 100644 index 0000000..6eef143 Binary files /dev/null and b/docs/images/08_java_tests.png differ diff --git a/docs/images/08_jest_unit_test.png b/docs/images/08_jest_unit_test.png new file mode 100644 index 0000000..5efb638 Binary files /dev/null and b/docs/images/08_jest_unit_test.png differ diff --git a/docs/images/08_question_gatling_test_01.png b/docs/images/08_question_gatling_test_01.png new file mode 100644 index 0000000..77dcd8f Binary files /dev/null and b/docs/images/08_question_gatling_test_01.png differ diff --git a/docs/images/08_question_gatling_test_02.png b/docs/images/08_question_gatling_test_02.png new file mode 100644 index 0000000..fd2954a Binary files /dev/null and b/docs/images/08_question_gatling_test_02.png differ diff --git a/docs/images/08_question_gatling_test_03.png b/docs/images/08_question_gatling_test_03.png new file mode 100644 index 0000000..6b2257c Binary files /dev/null and b/docs/images/08_question_gatling_test_03.png differ diff --git a/docs/images/08_user_gatling_test_01.png b/docs/images/08_user_gatling_test_01.png new file mode 100644 index 0000000..d4812d7 Binary files /dev/null and b/docs/images/08_user_gatling_test_01.png differ diff --git a/docs/images/08_user_gatling_test_02.png b/docs/images/08_user_gatling_test_02.png new file mode 100644 index 0000000..3c88feb Binary files /dev/null and b/docs/images/08_user_gatling_test_02.png differ diff --git a/docs/images/08_user_gatling_test_03.png b/docs/images/08_user_gatling_test_03.png new file mode 100644 index 0000000..6027050 Binary files /dev/null and b/docs/images/08_user_gatling_test_03.png differ diff --git a/docs/src/08_concepts.adoc b/docs/src/08_concepts.adoc index bd9a492..8f837d1 100644 --- a/docs/src/08_concepts.adoc +++ b/docs/src/08_concepts.adoc @@ -79,10 +79,33 @@ To test API code, Postman was used during the whole development of the work, to ==== Unit tests Unit testing was carried out on both the backend and frontend using different technologies to test all the necessary components or modules. -The use of Mock for the backend and the use of jest for the frontend. + +The backend has been tested with Jacoco and Java unit tests with Mockito: +image:08_api_jacoco_tests.png["Jacoco tests"] +image:08_java_tests.png["Unit tests"] + +The frontend has used Jest for its unit tests: +image:08_jest_unit_test.png["Jest tests"] ==== Integration tests -The integration tests were carried out in test containers with a test database built in these test containers for the adapter layer. It does not make sense to do integration tests on another layer. +The integration tests were carried out in test containers with a test database built in these test containers for the adapter layer. It does not make sense to do integration tests on another layer. This tests was launcher with Jacoco anda java unit test too. ==== e2e tests For the e2e tests as well as the unit tests and in order to test the application to the maximum, they were carried out both in the frontend with cypress and in the backend with test container again. + +E2E cypress tests: +image:08_cypress-tool.png["Cypress tool"] +image:08_cypress_tool_tests.png["Cypress tool tests"] +image:08_cypress_test_running.png["Cypress test running"] + +==== load tests +For the load tests, the Gatling tool has been used to measure and monitor the application's times in different scenarios: +image:08_category_gatling_test_01.png["Category gatling 01"] +image:08_category_gatling_test_02.png["Category gatling 02"] +image:08_category_gatling_test_03.png["Category gatling 03"] +image:08_question_gatling_test_01.png["Question gatling 01"] +image:08_question_gatling_test_02.png["Question gatling 02"] +image:08_question_gatling_test_03.png["Question gatling 03"] +image:08_user_gatling_test_01.png["User gatling 01"] +image:08_user_gatling_test_02.png["User gatling 02"] +image:08_user_gatling_test_03.png["User gatling 03"] diff --git a/syg-backend/SYG-mysql-adapter/src/test/java/syg/mysql/adapter/integration/QuestionAdapterIT.java b/syg-backend/SYG-mysql-adapter/src/test/java/syg/mysql/adapter/integration/QuestionAdapterIT.java index 977f52f..032f6b9 100644 --- a/syg-backend/SYG-mysql-adapter/src/test/java/syg/mysql/adapter/integration/QuestionAdapterIT.java +++ b/syg-backend/SYG-mysql-adapter/src/test/java/syg/mysql/adapter/integration/QuestionAdapterIT.java @@ -99,6 +99,6 @@ void generate_wikidata_question() { questionAdapter.generatedQuestions(); List questionsAfterGenerate = questionAdapter.findAll(); - assertEquals(219, IterableUtil.sizeOf(questionsAfterGenerate)); + assertEquals(218, IterableUtil.sizeOf(questionsAfterGenerate)); } } diff --git a/syg-backend/SYG-rest-controller/pom.xml b/syg-backend/SYG-rest-controller/pom.xml index 85e5693..7df6457 100644 --- a/syg-backend/SYG-rest-controller/pom.xml +++ b/syg-backend/SYG-rest-controller/pom.xml @@ -32,5 +32,10 @@ SYG-domain 0.0.1-SNAPSHOT + + io.gatling.highcharts + gatling-charts-highcharts + test + \ No newline at end of file diff --git a/syg-backend/SYG-rest-controller/src/test/java/simulations/CategoryGatlingTests.java b/syg-backend/SYG-rest-controller/src/test/java/simulations/CategoryGatlingTests.java new file mode 100644 index 0000000..da1e4b2 --- /dev/null +++ b/syg-backend/SYG-rest-controller/src/test/java/simulations/CategoryGatlingTests.java @@ -0,0 +1,31 @@ +package simulations; + +import static io.gatling.javaapi.core.CoreDsl.*; +import static io.gatling.javaapi.http.HttpDsl.*; + +import io.gatling.javaapi.core.*; +import io.gatling.javaapi.http.*; + +public class CategoryGatlingTests extends Simulation { + + private static final String BASE_URL = "http://localhost:8080"; + + HttpProtocolBuilder httpProtocol = http.baseUrl(BASE_URL).acceptHeader("application/json") + .contentTypeHeader("application/json"); + + ScenarioBuilder findAllCategories = scenario("Encuentra todas las categorias") + .exec(http("findAllCategories").get("/category").check(status().is(200))); + ScenarioBuilder findCategoryById = scenario("Encuentra una categoria por id") + .exec(http("findCategoryById").get("/category/id?id=1").check(status().is(200))); + { + setUp(findAllCategories.injectOpen( + // Incrementa el nĂºmero de usuarios rĂ¡pidamente + incrementUsersPerSec(5).times(12) // Incremento de usuarios por segundo 12 veces (1 minuto) + .eachLevelLasting(5) // Cada nivel dura 5 segundos + .startingFrom(10) // Comienza con 10 usuarios por segundo + ), findCategoryById.injectOpen( + incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10))).protocols(httpProtocol) + .maxDuration(300); + + } +} diff --git a/syg-backend/SYG-rest-controller/src/test/java/simulations/QuestionGatlingTests.java b/syg-backend/SYG-rest-controller/src/test/java/simulations/QuestionGatlingTests.java new file mode 100644 index 0000000..8cff835 --- /dev/null +++ b/syg-backend/SYG-rest-controller/src/test/java/simulations/QuestionGatlingTests.java @@ -0,0 +1,30 @@ +package simulations; + +import static io.gatling.javaapi.core.CoreDsl.*; +import static io.gatling.javaapi.http.HttpDsl.*; + +import io.gatling.javaapi.core.*; +import io.gatling.javaapi.http.*; + +public class QuestionGatlingTests extends Simulation { + + private static final String BASE_URL = "http://localhost:8080"; + + HttpProtocolBuilder httpProtocol = http.baseUrl(BASE_URL).acceptHeader("application/json") + .contentTypeHeader("application/json"); + + ScenarioBuilder findAllQuestions = scenario("Encuentra todas las preguntas") + .exec(http("findAllQuestions").get("/question").check(status().is(200))); + ScenarioBuilder findQuestionById = scenario("Encuentra una pregunta por su id") + .exec(http("findQuestionById").get("/question/id?id=200").check(status().is(200))); + ScenarioBuilder findQuestionByCategory = scenario("Encuentra una pregunta por su categoria") + .exec(http("findQuestionByCategory").get("/question/category?categoryId=1").check(status().is(200))); + { + setUp(findAllQuestions.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)), + findQuestionById.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)), + findQuestionByCategory + .injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10))) + .protocols(httpProtocol).maxDuration(300); + + } +} diff --git a/syg-backend/SYG-rest-controller/src/test/java/simulations/UserGatlingTests.java b/syg-backend/SYG-rest-controller/src/test/java/simulations/UserGatlingTests.java new file mode 100644 index 0000000..89ac758 --- /dev/null +++ b/syg-backend/SYG-rest-controller/src/test/java/simulations/UserGatlingTests.java @@ -0,0 +1,26 @@ +package simulations; + +import static io.gatling.javaapi.core.CoreDsl.*; +import static io.gatling.javaapi.http.HttpDsl.*; + +import io.gatling.javaapi.core.*; +import io.gatling.javaapi.http.*; + +public class UserGatlingTests extends Simulation { + + private static final String BASE_URL = "http://localhost:8080"; + + HttpProtocolBuilder httpProtocol = http.baseUrl(BASE_URL).acceptHeader("application/json") + .contentTypeHeader("application/json"); + + ScenarioBuilder findUserById = scenario("Encuentra un usuario por su uuid").exec( + http("findUserById").get("/user/userId?id=4366fdc8-b32d-46bc-9df8-2e8ce68f0743").check(status().is(200))); + ScenarioBuilder findUserByName = scenario("Encuentra un usuario por nombre") + .exec(http("findUserByName").get("/user/name/?userName=alvaro").check(status().is(200))); + + { + setUp(findUserById.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10)), + findUserByName.injectOpen(incrementUsersPerSec(5).times(12).eachLevelLasting(5).startingFrom(10))) + .protocols(httpProtocol).maxDuration(300); + } +} diff --git a/syg-backend/pom.xml b/syg-backend/pom.xml index 4a4c0a3..1a29c7f 100644 --- a/syg-backend/pom.xml +++ b/syg-backend/pom.xml @@ -27,6 +27,11 @@ SYG-bootstrap/target/site/jacoco-aggregate/jacoco.xml SYG-bootstrap/**, SYG-domain/src/main/java/syg/domain/model/** + 3.11.3 + 4.9.4 + 3.13.0 + 3.3.1 + 3.4.1 @@ -78,6 +83,12 @@ ${junit-jupiter.version} test + + io.gatling.highcharts + gatling-charts-highcharts + ${gatling.version} + test + @@ -187,6 +198,28 @@ sonar-maven-plugin 3.11.0.3922 + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + maven-resources-plugin + ${maven-resources-plugin.version} + + + maven-jar-plugin + ${maven-jar-plugin.version} + + + io.gatling + gatling-maven-plugin + ${gatling-maven-plugin.version} + + + + +