Commit f7a0fe63 by Rubén Ramírez

feat: [Test]: Añadidas configuraciones y etiquetas para poder hacer los tests

parent 5c9aabed
...@@ -53,6 +53,21 @@ ...@@ -53,6 +53,21 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -2,8 +2,15 @@ package com.ujaen.tfg.mangaffinity; ...@@ -2,8 +2,15 @@ package com.ujaen.tfg.mangaffinity;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
@SpringBootApplication @SpringBootApplication(scanBasePackages={
"com.ujaen.tfg.mangaffinity.servicios",
"com.ujaen.tfg.mangaffinity.repositorios",
"com.ujaen.tfg.mangaffinity.rest",
// "com.ujaen.tfg.mangaffinity.seguridad"
})
@EntityScan(basePackages="com.ujaen.tfg.mangaffinity")
public class MangAffinityApplication { public class MangAffinityApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
package com.ujaen.tfg.mangaffinity.config;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import javax.sql.DataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;
import java.util.Properties;
@TestConfiguration
public class JpaTestConfig {
@Bean
public DataSource dataSource() {
return DataSourceBuilder.create()
.driverClassName("org.h2.Driver")
.url("jdbc:h2:mem:mangaffinity;MODE=MYSQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1")
.username("sa")
.password("")
.build();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan("com.ujaen.tfg.mangaffinity.entidades");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
properties.setProperty("hibernate.show_sql", "true");
em.setJpaProperties(properties);
return em;
}
}
spring:
datasource:
url: jdbc:h2:mem:mangaffinity;DB_CLOSE_DELAY=-1
driver-class-name: org.h2.Driver
username: sa
password:
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
show_sql: true
sql:
init:
mode: always
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment