From acae997e0b1ae00c29cdfbe674ad9dd48454d800 Mon Sep 17 00:00:00 2001 From: Fernando Ferreira de Lima Filho <fferreiralf@ufrn.edu.br> Date: Sun, 17 Jul 2022 13:49:18 -0300 Subject: [PATCH] test: setup unit tst --- ...ven__mysql_mysql_connector_java_5_1_39.xml | 13 ------ ..._org_apiguardian_apiguardian_api_1_1_2.xml | 13 ++++++ ..._org_junit_jupiter_junit_jupiter_5_8_1.xml | 13 ++++++ ..._junit_jupiter_junit_jupiter_api_5_8_1.xml | 13 ++++++ ...nit_jupiter_junit_jupiter_engine_5_8_1.xml | 13 ++++++ ...nit_jupiter_junit_jupiter_params_5_8_1.xml | 13 ++++++ ..._platform_junit_platform_commons_1_8_1.xml | 13 ++++++ ...t_platform_junit_platform_engine_1_8_1.xml | 13 ++++++ ...Maven__org_opentest4j_opentest4j_1_2_0.xml | 13 ++++++ ...rg_postgresql_postgresql_9_4_1211_jre7.xml | 13 ++++++ .idea/vcs.xml | 6 +++ source/pom.xml | 16 ++++++- .../com/userfront/config/SecurityConfig.java | 7 +-- .../src/main/resources/application.properties | 10 ++--- .../userfront/service/AccountServiceTest.java | 43 +++++++++++++++++++ 15 files changed, 190 insertions(+), 22 deletions(-) delete mode 100644 .idea/libraries/Maven__mysql_mysql_connector_java_5_1_39.xml create mode 100644 .idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml create mode 100644 .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml create mode 100644 .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml create mode 100644 .idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml create mode 100644 .idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml create mode 100644 .idea/libraries/Maven__org_postgresql_postgresql_9_4_1211_jre7.xml create mode 100644 .idea/vcs.xml create mode 100644 source/src/test/java/com/userfront/service/AccountServiceTest.java diff --git a/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_39.xml b/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_39.xml deleted file mode 100644 index 18e6ec9..0000000 --- a/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_39.xml +++ /dev/null @@ -1,13 +0,0 @@ -<component name="libraryTable"> - <library name="Maven: mysql:mysql-connector-java:5.1.39"> - <CLASSES> - <root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar!/" /> - </CLASSES> - <JAVADOC> - <root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39-javadoc.jar!/" /> - </JAVADOC> - <SOURCES> - <root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39-sources.jar!/" /> - </SOURCES> - </library> -</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml new file mode 100644 index 0000000..6ac1c42 --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.apiguardian:apiguardian-api:1.1.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml new file mode 100644 index 0000000..987e7d4 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.junit.jupiter:junit-jupiter:5.8.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml new file mode 100644 index 0000000..4910ca9 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml new file mode 100644 index 0000000..85ab9ad --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml new file mode 100644 index 0000000..8675273 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml new file mode 100644 index 0000000..3417208 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.junit.platform:junit-platform-commons:1.8.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml new file mode 100644 index 0000000..f19b408 --- /dev/null +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.junit.platform:junit-platform-engine:1.8.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml new file mode 100644 index 0000000..fbc1b16 --- /dev/null +++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.opentest4j:opentest4j:1.2.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_postgresql_postgresql_9_4_1211_jre7.xml b/.idea/libraries/Maven__org_postgresql_postgresql_9_4_1211_jre7.xml new file mode 100644 index 0000000..be620ea --- /dev/null +++ b/.idea/libraries/Maven__org_postgresql_postgresql_9_4_1211_jre7.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.postgresql:postgresql:9.4.1211.jre7"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/postgresql/postgresql/9.4.1211.jre7/postgresql-9.4.1211.jre7.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/postgresql/postgresql/9.4.1211.jre7/postgresql-9.4.1211.jre7-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/postgresql/postgresql/9.4.1211.jre7/postgresql-9.4.1211.jre7-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/source/pom.xml b/source/pom.xml index 2a7a96d..0eaf901 100644 --- a/source/pom.xml +++ b/source/pom.xml @@ -25,6 +25,7 @@ </properties> <dependencies> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> @@ -59,8 +60,21 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + </exclusion> + </exclusions> </dependency> - </dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>5.8.1</version> + <scope>test</scope> + </dependency> + + </dependencies> <build> <finalName>bank-service</finalName> diff --git a/source/src/main/java/com/userfront/config/SecurityConfig.java b/source/src/main/java/com/userfront/config/SecurityConfig.java index 6f3612b..7e48b62 100644 --- a/source/src/main/java/com/userfront/config/SecurityConfig.java +++ b/source/src/main/java/com/userfront/config/SecurityConfig.java @@ -43,15 +43,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/contact/**", "/error/**/*", "/console/**", - "/signup" + "/signup", + "/swagger-ui-custom.html" }; @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests(). -// antMatchers("/**"). - antMatchers(PUBLIC_MATCHERS). + antMatchers("/**"). +// antMatchers(PUBLIC_MATCHERS). permitAll().anyRequest().authenticated(); http diff --git a/source/src/main/resources/application.properties b/source/src/main/resources/application.properties index 3f89c48..2657793 100644 --- a/source/src/main/resources/application.properties +++ b/source/src/main/resources/application.properties @@ -1,7 +1,7 @@ -spring.datasource.url= jdbc:postgresql://db-postgres-online-bank/onlinebanking -spring.datasource.username=root -spring.datasource.password=root +spring.datasource.url= jdbc:postgresql://localhost:5432/onlinebanking +spring.datasource.username=postgres +spring.datasource.password=postgres spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect -spring.jpa.show-sql = true -spring.jpa.hibernate.ddl-auto = update +spring.jpa.show-sql =true +spring.jpa.hibernate.ddl-auto=update diff --git a/source/src/test/java/com/userfront/service/AccountServiceTest.java b/source/src/test/java/com/userfront/service/AccountServiceTest.java new file mode 100644 index 0000000..1f9ff41 --- /dev/null +++ b/source/src/test/java/com/userfront/service/AccountServiceTest.java @@ -0,0 +1,43 @@ +package com.userfront.service; + + +import com.userfront.UserFrontApplication; +import com.userfront.UserFrontApplicationTests; +import com.userfront.dao.PrimaryAccountDao; +import com.userfront.dao.SavingsAccountDao; +import com.userfront.domain.PrimaryAccount; +import com.userfront.service.UserServiceImpl.AccountServiceImpl; +import org.junit.Assert; +import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.math.BigDecimal; + + +public class AccountServiceTest { + + @Test + public void createPrimaryAccount() { + AccountServiceImpl accountService = Mockito.mock(AccountServiceImpl.class); + + PrimaryAccount primaryAccount = new PrimaryAccount(); + primaryAccount.setAccountBalance(new BigDecimal(0.0)); + primaryAccount.setAccountNumber(1); + + Mockito.when(accountService.createPrimaryAccount()) + .thenReturn(primaryAccount); + PrimaryAccount primaryAccountResult = accountService.createPrimaryAccount(); + Assert.assertEquals(primaryAccountResult.getAccountBalance(), new BigDecimal(0.0)); + } + +} -- GitLab