Commit b39c03f429000e323c7eca832b3b4e23c2e88bb8

Authored by Herik dos Santos Lorenção
1 parent e9f6ac76
Exists in master

Adicionando códigos

codigos/backend/mvnw
... ... @@ -68,7 +68,7 @@ esac
68 68  
69 69 if [ -z "$JAVA_HOME" ] ; then
70 70 if [ -r /etc/gentoo-release ] ; then
71   - JAVA_HOME=`java-config --jre-home`
  71 + JAVA_HOME=`java-edu.ifes.ci.si.les.srh.config --jre-home`
72 72 fi
73 73 fi
74 74  
... ...
codigos/backend/mvnw.cmd
... ... @@ -108,10 +108,10 @@ cd "%EXEC_DIR%"
108 108  
109 109 :endDetectBaseDir
110 110  
111   -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
  111 +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.edu.ifes.ci.si.les.srh.config" goto endReadAdditionalConfig
112 112  
113 113 @setlocal EnableExtensions EnableDelayedExpansion
114   -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
  114 +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.edu.ifes.ci.si.les.srh.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 115 @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 116  
117 117 :endReadAdditionalConfig
... ...
codigos/backend/src/main/java/edu/ifes/ci/si/les/srh/config/DevConfig.java 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +package edu.ifes.ci.si.les.srh.config;
  2 +
  3 +import edu.ifes.ci.si.les.srh.services.DBService;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.beans.factory.annotation.Value;
  6 +import org.springframework.context.annotation.Bean;
  7 +
  8 +import java.text.ParseException;
  9 +
  10 +public class DevConfig {
  11 + @Autowired
  12 + private DBService dbService;
  13 +
  14 + @Value("${spring.jpa.hibernate.ddl-auto}")
  15 + private String strategy;
  16 +
  17 + @Bean
  18 + public boolean instatiateDatabase() throws ParseException {
  19 + if (!"create".equals(strategy)) {
  20 + return false;
  21 + }
  22 + dbService.instantiateTestDatabase();
  23 + return true;
  24 + }
  25 +}
... ...
codigos/backend/src/main/java/edu/ifes/ci/si/les/srh/config/TestConfig.java 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +package edu.ifes.ci.si.les.srh.config;
  2 +
  3 +import edu.ifes.ci.si.les.srh.services.DBService;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.context.annotation.Bean;
  6 +import org.springframework.context.annotation.Configuration;
  7 +import org.springframework.context.annotation.Profile;
  8 +
  9 +import java.text.ParseException;
  10 +
  11 +@Configuration
  12 +@Profile("test")
  13 +public class TestConfig {
  14 + @Autowired
  15 + private DBService dbService;
  16 +
  17 + @Bean
  18 + public boolean instatiateDatabase() throws ParseException {
  19 + dbService.instantiateTestDatabase();
  20 + return true;
  21 + }
  22 +}
... ...
codigos/backend/src/main/java/edu/ifes/ci/si/les/srh/services/DBService.java 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +package edu.ifes.ci.si.les.srh.services;
  2 +
  3 +import edu.ifes.ci.si.les.srh.builder.TagBuilder;
  4 +import edu.ifes.ci.si.les.srh.model.Tag;
  5 +import edu.ifes.ci.si.les.srh.repository.TagRepository;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +
  8 +import java.text.ParseException;
  9 +import java.util.Arrays;
  10 +
  11 +public class DBService {
  12 + @Autowired
  13 + private TagRepository tagRepository;
  14 +
  15 + public void instantiateTestDatabase() throws ParseException {
  16 + Tag tag = buildTag(1, "Tag 1");
  17 + Tag tag2 = buildTag(2, "Tag 2");
  18 +
  19 + tagRepository.saveAll(Arrays.asList(tag, tag2));
  20 + }
  21 +
  22 + private Tag buildTag(Integer id, String name) {
  23 + return TagBuilder.aTag()
  24 + .withId(id)
  25 + .withName(name)
  26 + .build();
  27 + }
  28 +}
... ...
codigos/backend/src/main/resources/application-test.properties 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +# server.port=${port:8080}
  2 +spring.datasource.url=jdbc:h2:mem:testdb
  3 +spring.datasource.username=sa
  4 +spring.datasource.password=
  5 +spring.jpa.show_sql=true
  6 +spring.jpa.properties.hibernate.format_sql=true
0 7 \ No newline at end of file
... ...
codigos/backend/src/main/resources/application.properties
1   -# datasource
2   -spring.datasource.driverClassName=org.postgresql.Driver
  1 +# jpa
3 2 spring.datasource.url=jdbc:postgresql://localhost:5432/srh_les
  3 +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
4 4 spring.datasource.username=postgres
5 5 spring.datasource.password=postgres
6   -
7   -# jpa
8   -spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
9   -spring.jpa.hibernate.ddl-auto=drop-and-create
  6 +spring.jpa.hibernate.ddl-auto=create
10 7 spring.jpa.properties.hibernate.show_sql=true
11   -spring.jpa.properties.hibernate.format_sql=true
12 8 \ No newline at end of file
  9 +spring.jpa.properties.hibernate.format_sql=true
  10 +spring.profiles.active=dev
13 11 \ No newline at end of file
... ...