1 package de.spring.example.persistence.repository;
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.junit.Assert.assertThat;
6 import java.time.OffsetDateTime;
8 import javax.inject.Inject;
10 import org.junit.Test;
11 import org.junit.runner.RunWith;
12 import org.springframework.test.context.ContextConfiguration;
13 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14 import org.springframework.transaction.annotation.Transactional;
16 import de.spring.example.persistence.domain.Ad;
18 @RunWith(SpringJUnit4ClassRunner.class)
19 @ContextConfiguration( {"classpath*:spring-configuration/*.xml",
20 "classpath*:spring-configuration-h2-test/*.xml"} )
22 public class AdRespositoryShould {
24 public static final Long COMPANY_ID = 2L;
25 public static final Long COMPANY_CATEG_ID = 3L;
26 public static final String AD_MOBILE_IMAGE = "slippers.jpg";
27 public static final OffsetDateTime CREATED_AT = OffsetDateTime.now().minusDays(1);
28 public static final OffsetDateTime UPDATED_AT = OffsetDateTime.now();
31 AdRepository adRepository;
36 Ad createdAd = adRepository.save(ad);
38 Ad storedAd = adRepository.findOne(createdAd.getId());
40 assertThat(createdAd, is(storedAd));
44 find_one_ad_by_id_using_native_query() {
46 Ad createdAd = adRepository.save(ad);
48 Ad storedAd = adRepository.findByIdNativeQuery(createdAd.getId());
50 assertThat(createdAd, is(storedAd));
54 find_one_ad_by_id_using_named_query() {
56 Ad createdAd = adRepository.save(ad);
58 Ad storedAd = adRepository.findByIdQuery(createdAd.getId());
60 assertThat(createdAd, is(storedAd));
63 private static final Ad createAd() {
64 return new Ad(null, null, COMPANY_ID, COMPANY_CATEG_ID, AD_MOBILE_IMAGE,
65 CREATED_AT, UPDATED_AT);