Merge branch 'master' of https://github.com/juliuskrah/tutorials into juliuskrah-master
This commit is contained in:
commit
8066195a85
|
@ -6,8 +6,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class DemoApplication {
|
public class DemoApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.setProperty("spring.config.name", "demo");
|
System.setProperty("spring.config.name", "demo");
|
||||||
SpringApplication.run(DemoApplication.class, args);
|
SpringApplication.run(DemoApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,33 +8,32 @@ import javax.persistence.Id;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Foo implements Serializable {
|
public class Foo implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public Foo() {
|
public Foo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Foo(String name) {
|
public Foo(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Integer id) {
|
public void setId(Integer id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,5 +4,5 @@ import org.baeldung.boot.model.Foo;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface FooRepository extends JpaRepository<Foo, Integer> {
|
public interface FooRepository extends JpaRepository<Foo, Integer> {
|
||||||
public Foo findByName(String name);
|
public Foo findByName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
public class DemoApplicationTests {
|
public class DemoApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() {
|
public void contextLoads() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,19 +15,20 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public class FooRepositoryTest extends DemoApplicationTests {
|
public class FooRepositoryTest extends DemoApplicationTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private FooRepository fooRepository;
|
private FooRepository fooRepository;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
fooRepository.save(new Foo("Foo"));
|
fooRepository.save(new Foo("Foo"));
|
||||||
fooRepository.save(new Foo("Bar"));
|
fooRepository.save(new Foo("Bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindByName() {
|
||||||
|
Foo foo = fooRepository.findByName("Bar");
|
||||||
|
assertThat(foo, notNullValue());
|
||||||
|
assertThat(foo.getId(), is(2));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFindByName() {
|
|
||||||
Foo foo = fooRepository.findByName("Bar");
|
|
||||||
assertThat(foo, notNullValue());
|
|
||||||
assertThat(foo.getId(), is(2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue