* initial commit

* fixed formatting

* formatting changes

* test fix
This commit is contained in:
majajoksovic 2020-10-02 19:23:50 +02:00 committed by GitHub
parent b9dbeb6c58
commit d3744f7694
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,10 @@
#spring.datasource.url=jdbc:h2:file:C:/data/demodb
#spring.datasource.url=jdbc:h2:file:~/demodb
spring.datasource.url=jdbc:h2:file:./src/main/resources/db/demodb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.path=/h2-console

View File

@ -0,0 +1,52 @@
package com.baeldung.persistent;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.h2db.auto.configuration.AutoConfigurationDemo;
@ActiveProfiles("persistent-on")
@RunWith(SpringRunner.class)
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
@SpringBootTest(classes = AutoConfigurationDemo.class)
public class FilesLocationUnitTest {
@BeforeClass
public static void beforeClass() {
}
@Test(expected = Test.None.class)
public void whenApplicationStarted_thenEmbeddedDbSubfolderCreated() {
File subdirectory = new File("src/main/resources/db");
System.out.println(subdirectory.getAbsolutePath());
assertTrue(subdirectory.exists());
assertTrue(subdirectory.isDirectory());
}
@Test(expected = Test.None.class)
public void whenApplicationStarted_thenEmbeddedDbFilesCreated() {
File dbFile = new File("src/main/resources/db/demodb.mv.db");
System.out.println(dbFile.getAbsolutePath());
assertTrue(dbFile.exists());
assertTrue(dbFile.isFile());
}
@AfterClass
public static void cleanUp() {
File dbFile = new File("src/main/resources/db/demodb.mv.db");
dbFile.deleteOnExit();
}
}