title: Spring Boot / Spring Data integration tests
body: <p>Didn't manage to configure Spring Boot for integration testing. Cold you please take a look at the code below:</p>
  
  <p><strong>Entities</strong></p>
  
  <pre><code>@Entity(name = "Item")
  @Table(name = "item")
  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  @Getter @Setter @NoArgsConstructor
  public class Item extends CoreEntity {
  
      @Embedded
      protected CurrencyAmount amount;
  
      @Column(name = "operation_time")
      protected ZonedDateTime operationTime;
  
      @Column(name = "description")
      protected String description;
  
      @ManyToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = "category_id")
      protected ItemCategory category;
  
  }
  
  
  
  @Entity(name = "Income")
  @Table(name = "income")
  @Getter @Setter @NoArgsConstructor
  public class Income extends Item {
  
      @ManyToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = "budget_id")
      private Budget budget;
  
      ...
  
  }
  </code></pre>
  
  <p><strong>Repository</strong></p>
  
  <pre><code>@Repository("incomeDao")
  public interface IncomeDao extends JpaRepository&lt;Income, Long&gt; {
  }
  </code></pre>
  
  <p><strong>Test configuration</strong></p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories(basePackages = "dao.item")
  @EntityScan(basePackages = {"model"})
  @PropertySource("classpath:application.properties")
  @EnableTransactionManagement
  public class DaoTestConfiguration {
  
      @Autowired
      private Environment environment;
  
      public DataSource getDataSource() {
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName(environment.getProperty("spring.datasource.driver-class-name"));
          dataSource.setUrl(environment.getProperty("spring.datasource.url"));
          dataSource.setUsername(environment.getProperty("spring.datasource.username"));
          dataSource.setPassword(environment.getProperty("spring.datasource.password"));
          return dataSource;
      }
  
  }
  </code></pre>
  
  <p><strong>Application properties</strong></p>
  
  <pre><code>spring.datasource.driver-class-name=org.h2.Driver
  spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
  spring.datasource.username=sa
  spring.datasource.password=sa
  </code></pre>
  
  <p><strong>Test case</strong></p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringBootTest(classes = DaoTestConfiguration.class)
  @DataJpaTest
  public class IncomeDaoTest {
  
      @Autowired
      private IncomeDao incomeDao;
  
      @Test
      public void testSave() {
          Budget budget = Budget.getBulider().setMonth(Month.NOVEMBER).build();
          ItemCategory category = ItemCategory.getBuilder()
                  .setItemGroup(ItemGroup.INCOME)
                  .setCathegoryName("Salary")
                  .build();
          Income income = Income.getBuilder()
                  .setBudget(budget)
                  .setCurrencyAmount(new CurrencyAmount(Currency.getInstance("USD"), BigDecimal.TEN))
                  .setDescription("Monthly salary")
                  .setItemCategory(category)
                  .setOperationTime(ZonedDateTime.of(2017, 1, 12, 12, 0, 0, 0, ZoneId.of("UTC")))
                  .build();
          incomeDao.save(income);
  
          assertThat(incomeDao.findAll()).containsExactly(income);
      }
  }
  </code></pre>
  
  <p>I tried a different configuration (its last edition), but all the time I get the same exception:</p>
  
  <pre><code>Caused by: org.h2.jdbc.JdbcSQLException: Таблица "INCOME" не найдена
  Table "INCOME" not found; SQL statement:
  insert into income (model/amount, currency, category_id, description, operation_time, budget_id, id) values (?, ?, ?, ?, ?, ?, ?) [42102-196]
  </code></pre>
  
  <p>More over the nature of the exception is strange as the main idea to let spring boot to auto-generate schema according to entity annotations. Thus, at the moment of insertion spring had to create table but looks that it didn't. If someone give an idea what I did wrong or if somebody already faced such an issue - please let me knkow. Thanks.</p>