commit a70dd7aadf6be2a6afdeccce3ab7c67e65044cc8 Author: jackdaw Date: Tue Nov 15 11:13:55 2016 +0900 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..45f0edd --- /dev/null +++ b/.gitignore @@ -0,0 +1,72 @@ +# Created by .ignore support plugin (hsz.mobi) +### Maven template +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +### Java template +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +.gitignore 제거할 예정 +.idea/ 제거할 예정 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..df8e478 --- /dev/null +++ b/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + com.loafle + bridge + 1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 1.4.2.RELEASE + + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-rest + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-actuator + + + com.h2database + h2 + + + org.springframework.boot + spring-boot-starter-jetty + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-releases + https://repo.spring.io/libs-release + + + + + spring-releases + https://repo.spring.io/libs-release + + + + \ No newline at end of file diff --git a/src/main/java/Application.java b/src/main/java/Application.java new file mode 100644 index 0000000..5e4b74f --- /dev/null +++ b/src/main/java/Application.java @@ -0,0 +1,34 @@ +package hello; + + +//import org.h2.server.web.WebServlet; + +import org.h2.server.web.WebServlet; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.PropertySource; + +/** + * Created by jackdaw on 16. 11. 9. + */ + +//@EntityScan(basePackages="hello") +//@EnableJpaRepositories(basePackages = "hello") +@PropertySource({"classpath:database.properties"}) +@SpringBootApplication +public class Application { + + static public void main(String[] args) { + SpringApplication.run(Application.class,args); + System.out.println("Spring Boot Started.."); + } + @Bean + public ServletRegistrationBean h2servletRegistration() { + ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet()); + registration.addUrlMappings("/console/*"); + return registration; + } + +} diff --git a/src/main/java/com/loafle/bridge/collector/controller/CollectorController.java b/src/main/java/com/loafle/bridge/collector/controller/CollectorController.java new file mode 100644 index 0000000..325556a --- /dev/null +++ b/src/main/java/com/loafle/bridge/collector/controller/CollectorController.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.collector.controller; + +/** + * Created by root on 16. 11. 15. + */ +public class CollectorController { +} diff --git a/src/main/java/com/loafle/bridge/collector/entity/Collector.java b/src/main/java/com/loafle/bridge/collector/entity/Collector.java new file mode 100644 index 0000000..51c2a10 --- /dev/null +++ b/src/main/java/com/loafle/bridge/collector/entity/Collector.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.collector.entity; + +/** + * Created by root on 16. 11. 15. + */ +public class Collector { +} diff --git a/src/main/java/com/loafle/bridge/collector/repository/CollectorRepository.java b/src/main/java/com/loafle/bridge/collector/repository/CollectorRepository.java new file mode 100644 index 0000000..aecd290 --- /dev/null +++ b/src/main/java/com/loafle/bridge/collector/repository/CollectorRepository.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.collector.repository; + +/** + * Created by root on 16. 11. 15. + */ +public class CollectorRepository { +} diff --git a/src/main/java/com/loafle/bridge/discovering/controller/DiscoveringController.java b/src/main/java/com/loafle/bridge/discovering/controller/DiscoveringController.java new file mode 100644 index 0000000..6c5c25d --- /dev/null +++ b/src/main/java/com/loafle/bridge/discovering/controller/DiscoveringController.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discovering.controller; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveringController { +} diff --git a/src/main/java/com/loafle/bridge/discovering/entity/Discovering.java b/src/main/java/com/loafle/bridge/discovering/entity/Discovering.java new file mode 100644 index 0000000..57b08fc --- /dev/null +++ b/src/main/java/com/loafle/bridge/discovering/entity/Discovering.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discovering.entity; + +/** + * Created by root on 16. 11. 15. + */ +public class Discovering { +} diff --git a/src/main/java/com/loafle/bridge/discovering/repository/DiscoveringRepository.java b/src/main/java/com/loafle/bridge/discovering/repository/DiscoveringRepository.java new file mode 100644 index 0000000..db003f9 --- /dev/null +++ b/src/main/java/com/loafle/bridge/discovering/repository/DiscoveringRepository.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discovering.repository; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveringRepository { +} diff --git a/src/main/java/com/loafle/bridge/discoveryhost/controller/DiscoveryHostController.java b/src/main/java/com/loafle/bridge/discoveryhost/controller/DiscoveryHostController.java new file mode 100644 index 0000000..b7b80aa --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryhost/controller/DiscoveryHostController.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryhost.controller; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryHostController { +} diff --git a/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java b/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java new file mode 100644 index 0000000..0d46681 --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryhost.entity; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryHost { +} diff --git a/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java b/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java new file mode 100644 index 0000000..927db2c --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryhost.repository; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryHostRepository { +} diff --git a/src/main/java/com/loafle/bridge/discoveryport/controller/DiscoveryPortController.java b/src/main/java/com/loafle/bridge/discoveryport/controller/DiscoveryPortController.java new file mode 100644 index 0000000..eb96ecf --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryport/controller/DiscoveryPortController.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryport.controller; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryPortController { +} diff --git a/src/main/java/com/loafle/bridge/discoveryport/entity/DiscoveryPort.java b/src/main/java/com/loafle/bridge/discoveryport/entity/DiscoveryPort.java new file mode 100644 index 0000000..570a73f --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryport/entity/DiscoveryPort.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryport.entity; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryPort { +} diff --git a/src/main/java/com/loafle/bridge/discoveryport/repository/DiscoveryPortRepository.java b/src/main/java/com/loafle/bridge/discoveryport/repository/DiscoveryPortRepository.java new file mode 100644 index 0000000..1df4db2 --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryport/repository/DiscoveryPortRepository.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryport.repository; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryPortRepository { +} diff --git a/src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java b/src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java new file mode 100644 index 0000000..69bb0b4 --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryservice.controller; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryServiceController { +} diff --git a/src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java b/src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java new file mode 100644 index 0000000..774b5dc --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryservice.entity; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryService { +} diff --git a/src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java b/src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java new file mode 100644 index 0000000..6e0b671 --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryservice.repository; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryServiceRepository { +} diff --git a/src/main/java/com/loafle/bridge/discoveryzone/controller/DiscoveryZoneController.java b/src/main/java/com/loafle/bridge/discoveryzone/controller/DiscoveryZoneController.java new file mode 100644 index 0000000..39dc7cb --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryzone/controller/DiscoveryZoneController.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryzone.controller; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryZoneController { +} diff --git a/src/main/java/com/loafle/bridge/discoveryzone/entity/DiscoveryZone.java b/src/main/java/com/loafle/bridge/discoveryzone/entity/DiscoveryZone.java new file mode 100644 index 0000000..e16286a --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryzone/entity/DiscoveryZone.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryzone.entity; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryZone { +} diff --git a/src/main/java/com/loafle/bridge/discoveryzone/repository/DiscoveryZoneRepository.java b/src/main/java/com/loafle/bridge/discoveryzone/repository/DiscoveryZoneRepository.java new file mode 100644 index 0000000..b6694aa --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryzone/repository/DiscoveryZoneRepository.java @@ -0,0 +1,7 @@ +package com.loafle.bridge.discoveryzone.repository; + +/** + * Created by root on 16. 11. 15. + */ +public class DiscoveryZoneRepository { +} diff --git a/src/main/java/hello/HelloController.java b/src/main/java/hello/HelloController.java new file mode 100644 index 0000000..c2bc6c8 --- /dev/null +++ b/src/main/java/hello/HelloController.java @@ -0,0 +1,55 @@ +package hello; + +import hello.entity.Member; +import hello.repository.MemberRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * Created by jackdaw on 16. 11. 9. + */ +@RestController +public class HelloController { + + @Autowired + MemberRepository memberRepository; + +// @RequestMapping("/member") +// public List index() { +// return memberRepository.findAll(); +// } + + @RequestMapping(value = "/member/{id}", method = RequestMethod.GET) + public Member get(@PathVariable(value = "id") long id) { + return memberRepository.findOne(id); + } + + @RequestMapping(value = "/member", method = RequestMethod.GET) + @ResponseBody + public List getList() { + return memberRepository.findAll(); + } + +// @RequestMapping(value = "/member/{id}", method = RequestMethod.PATCH) +// @ResponseBody +// public Member patch(@PathVariable(value = "id") long id, @RequestBody Member member) { +// memberRepository.save(member); +// return member; +// } +// +// @RequestMapping(value = "/member/{id}", method = RequestMethod.PUT) +// @ResponseBody +// public Member update(@PathVariable(value = "id") long id, @RequestBody Member member) { +// memberRepository.save(member); +// return member; +// } +// +// @RequestMapping(value = "/member/{id}", method = RequestMethod.DELETE) +// @ResponseBody +// public List delete(@PathVariable(value = "id") long id) { +// memberRepository.delete(id); +// return memberRepository.findAll(); +// } +} diff --git a/src/main/java/hello/JPAConfiguration.java b/src/main/java/hello/JPAConfiguration.java new file mode 100644 index 0000000..11671fe --- /dev/null +++ b/src/main/java/hello/JPAConfiguration.java @@ -0,0 +1,23 @@ +package hello; + +import hello.entity.Member; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.rest.core.config.RepositoryRestConfiguration; +import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; + + +/** + * Created by jackdaw on 16. 11. 11. + */ +@Configuration +public class JPAConfiguration extends RepositoryRestMvcConfiguration { + + @Override + protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + config.exposeIdsFor(Member.class); + //config.setDefaultMediaType(MediaType.APPLICATION_JSON); + //config.useHalAsDefaultJsonMediaType(false); + + } +} + diff --git a/src/main/java/hello/entity/Member.java b/src/main/java/hello/entity/Member.java new file mode 100644 index 0000000..1fda6a3 --- /dev/null +++ b/src/main/java/hello/entity/Member.java @@ -0,0 +1,60 @@ +package hello.entity; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import javax.persistence.*; + +/** + * Created by jackdaw on 16. 11. 10. + */ + +@Entity +@JsonIgnoreProperties(ignoreUnknown = true) +public class Member { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @Column + private String name; + + @Column + private int age; + + public Member() {} + + public Member(String name, int age) { + this.name = name; + this.age = age; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return "[" + id + "] name = " + name + ", age = " + age; + } + +} diff --git a/src/main/java/hello/repository/MemberRepository.java b/src/main/java/hello/repository/MemberRepository.java new file mode 100644 index 0000000..4657b03 --- /dev/null +++ b/src/main/java/hello/repository/MemberRepository.java @@ -0,0 +1,19 @@ +package hello.repository; + +import hello.entity.Member; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +/** + * Created by jackdaw on 16. 11. 10. + */ + +@RepositoryRestResource(collectionResourceRel = "member", path = "member") +public interface MemberRepository extends JpaRepository { +// List findByNameAndAgeLessThan(String name, int age); +// +// @Query("select t from Member t where name=:name and age < :age") +// List findByNameAndAgeLessThanSQL(@Param("name") String name, @Param("age") int age); +// +// List findByNameAndAgeLessThanOrderByAgeDesc(String name, int age); +} diff --git a/src/main/resources/database.properties b/src/main/resources/database.properties new file mode 100644 index 0000000..79b2b47 --- /dev/null +++ b/src/main/resources/database.properties @@ -0,0 +1,15 @@ +## DataSource configuration +spring.datasource.url=jdbc:h2:file:~/data/test +spring.datasource.username=sa +spring.datasource.password=qwe123 +spring.datasource.driver-class-name=org.h2.Driver + +#spring.datasource.url=jdbc:mysql://192.168.1.215:3306/test_db?charset=utf8&parseTime=True&loc=Local +#spring.datasource.username=root +#spring.datasource.password=qwe123 + +## Hibernate configuration +spring.jpa.database=h2 +spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy +spring.jpa.show-sql=true \ No newline at end of file diff --git a/src/test/java/hello/HelloControllerTest.java b/src/test/java/hello/HelloControllerTest.java new file mode 100644 index 0000000..53e5776 --- /dev/null +++ b/src/test/java/hello/HelloControllerTest.java @@ -0,0 +1,154 @@ +package hello; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import hello.entity.Member; +import hello.repository.MemberRepository; +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.WebIntegrationTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +/** + * Created by jackdaw on 16. 11. 10. + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Application.class) +@WebIntegrationTest +public class HelloControllerTest { + + private MockMvc mockMvc; +// @Autowired +// MemberRe controller; + @Autowired + MemberRepository repo; + Logger logger = Logger.getLogger(this.getClass()); + + @Before + public void setUp() throws Exception { + mockMvc = standaloneSetup(repo).build(); + repo.save(new Member("1",1)); + repo.save(new Member("2",2)); + repo.save(new Member("2",2)); + } + + private String jsonStringFromObject(Object object) throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(object); + } + + @After + public void tearDown() throws Exception { + repo.deleteAll(); + } + + @Test + public void index() throws Exception { + + String jsonString = jsonStringFromObject(repo.findAll()); + logger.info(jsonString); + mockMvc.perform(get("/member")).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(content().string(equalTo(jsonString))); + } + + @Test + public void getMember() throws Exception { + List list = repo.findAll(); + String jsonString = this.jsonStringFromObject(list.get(0)); + logger.info(jsonString); + mockMvc.perform(get("/member/{id}", list.get(0).getId())) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(content().string(equalTo(jsonString))); + } + + @Test + public void createMember() throws Exception { + Member b = new Member("111",1111); + String jsonString = this.jsonStringFromObject(b); + + MvcResult result = mockMvc.perform(post("/member") + .contentType(MediaType.APPLICATION_JSON) + .content(jsonString)) + .andExpect(status().isOk()) + .andReturn(); + + logger.info(result.getResponse().getContentAsString()); + } + + @Test + public void patchMember() throws Exception { + List list = repo.findAll(); + String jsonString = this.jsonStringFromObject(list.get(0)); + logger.info(jsonString); + list.get(0).setName("test"); + list.get(0).setAge(9999); + jsonString = this.jsonStringFromObject(list.get(0)); + + + MvcResult result = mockMvc.perform( + patch("/member/{id}",list.get(0).getId()). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)). + andExpect(status().isOk()). + andReturn(); + logger.info(result.getResponse().getContentAsString()); + } + + @Test + public void updateMember() throws Exception { + List list = repo.findAll(); + String jsonString = this.jsonStringFromObject(list.get(0)); + logger.info(jsonString); + list.get(0).setName("test"); + list.get(0).setAge(9999); + jsonString = this.jsonStringFromObject(list.get(0)); + + + MvcResult result = mockMvc.perform( + put("/member/{id}",list.get(0).getId()). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)). + andExpect(status().isOk()). + andReturn(); + logger.info(result.getResponse().getContentAsString()); + } + + @Test + public void deleteMember() throws Exception { + List list = repo.findAll(); + + long id = list.get(0).getId(); + String jsonString = this.jsonStringFromObject(list); + + list.remove(0); + String compareString = this.jsonStringFromObject(list); + + mockMvc.perform(delete("/member/{id}", id) + .content(jsonString)) + .andExpect(status().isOk()) + .andExpect(content().string(equalTo(compareString))); + + + + + } + +} \ No newline at end of file diff --git a/src/test/java/hello/repository/MemberRepositoryTest.java b/src/test/java/hello/repository/MemberRepositoryTest.java new file mode 100644 index 0000000..5dd8fab --- /dev/null +++ b/src/test/java/hello/repository/MemberRepositoryTest.java @@ -0,0 +1,73 @@ +package hello.repository; + +import hello.Application; +import hello.entity.Member; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * Created by jackdaw on 16. 11. 10. + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Application.class) +public class MemberRepositoryTest { + @Autowired + MemberRepository repo; + + @Before + public void setup() { + repo.deleteAll(); + repo.save(new Member("1",1)); + repo.save(new Member("2",2)); + repo.save(new Member("3",3)); + repo.save(new Member("4",4)); + repo.save(new Member("5",5)); + } + + @After + public void down() { + repo.deleteAll(); + } + + @Test + public void create() { + Member m = new Member("test",1); + Member n = repo.save(m); + + assertEquals(m.getId(),n.getId()); + } + + @Test + public void getAll() { + assertEquals(repo.findAll().size(),5); + } + + @Test + public void delete() { + List l = repo.findAll(); + Member m = l.get(0); + repo.delete(m.getId()); + assertEquals(repo.findAll().size(),4); + } + + @Test + public void update() { + List l = repo.findAll(); + Member m = l.get(0); + m.setName("TTTTT"); + + Member n = repo.save(m); + assertEquals(m.getName(),n.getName()); + } + +} \ No newline at end of file