remove hello package
This commit is contained in:
parent
d6e3450e2b
commit
d2778ddc78
|
@ -1,55 +0,0 @@
|
|||
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<Member> 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<Member> 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<Member> delete(@PathVariable(value = "id") long id) {
|
||||
// memberRepository.delete(id);
|
||||
// return memberRepository.findAll();
|
||||
// }
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package hello;
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
// }
|
||||
//}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
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<Member,Long> {
|
||||
// List<Member> findByNameAndAgeLessThan(String name, int age);
|
||||
//
|
||||
// @Query("select t from Member t where name=:name and age < :age")
|
||||
// List<Member> findByNameAndAgeLessThanSQL(@Param("name") String name, @Param("age") int age);
|
||||
//
|
||||
// List<Member> findByNameAndAgeLessThanOrderByAgeDesc(String name, int age);
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
package hello;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.loafle.bridge.Application;
|
||||
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<Member> 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<Member> 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<Member> 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<Member> 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)));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package hello.repository;
|
||||
|
||||
import com.loafle.bridge.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<Member> l = repo.findAll();
|
||||
Member m = l.get(0);
|
||||
repo.delete(m.getId());
|
||||
assertEquals(repo.findAll().size(),4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update() {
|
||||
List<Member> l = repo.findAll();
|
||||
Member m = l.get(0);
|
||||
m.setName("TTTTT");
|
||||
|
||||
Member n = repo.save(m);
|
||||
assertEquals(m.getName(),n.getName());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user