@Test @DisplayName("DataSourceのBeanが正しく定義されている") public void dataSourceTest() { Method dataSourceMethod = assertDoesNotThrow(() -> DataSourceConfig.class.getMethod("dataSource")); assertNotNull(dataSourceMethod.getAnnotation(Bean.class), "annotation required"); EmbeddedDatabase dataSource = new DataSourceConfig().dataSource(); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); assertAll("SQL files are not executed correctly", () -> assertEquals(5, JdbcTestUtils.countRowsInTable(jdbcTemplate, "customer")), () -> assertEquals(3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "account")), () -> assertEquals(3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "account_authority")) ); }
public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .setScriptEncoding(StandardCharsets.UTF_8.name()) .addScript("classpath:/schema.sql") .addScript("classpath:/data.sql") .setType(EmbeddedDatabaseType.H2) .build(); }
DataSourceConfig { public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .setScriptEncoding(StandardCharsets.UTF_8.name()) .addScript("classpath:/schema.sql") .addScript("classpath:/data.sql") .setType(EmbeddedDatabaseType.H2) .build(); } }
DataSourceConfig { public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .setScriptEncoding(StandardCharsets.UTF_8.name()) .addScript("classpath:/schema.sql") .addScript("classpath:/data.sql") .setType(EmbeddedDatabaseType.H2) .build(); }  }
DataSourceConfig { public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .setScriptEncoding(StandardCharsets.UTF_8.name()) .addScript("classpath:/schema.sql") .addScript("classpath:/data.sql") .setType(EmbeddedDatabaseType.H2) .build(); }  EmbeddedDatabase dataSource(); }
DataSourceConfig { public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .setScriptEncoding(StandardCharsets.UTF_8.name()) .addScript("classpath:/schema.sql") .addScript("classpath:/data.sql") .setType(EmbeddedDatabaseType.H2) .build(); }  EmbeddedDatabase dataSource();  }