Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2d719f18ba
|
@ -4,19 +4,38 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by root on 16. 11. 15.
|
* Created by root on 16. 11. 15.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
public class CollectorController {
|
public class CollectorController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CollectorRepository repository;
|
private CollectorRepository repository;
|
||||||
|
|
||||||
@RequestMapping(value = "/collector/{productId}", method = RequestMethod.GET)
|
@RequestMapping(value = "/collector/{productId}", method = RequestMethod.GET)
|
||||||
public Collector get(@PathVariable(value = "productId") String productId) {
|
public Collector getByProductId(@PathVariable String productId) {
|
||||||
return repository.findByPID(productId);
|
return repository.findByPID(productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/test", method = RequestMethod.GET)
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
Collector c = new Collector();
|
||||||
|
c.setVersion("1.0.0");
|
||||||
|
c.setConfigPath("/root");
|
||||||
|
c.setInstallDate(new Date());
|
||||||
|
c.setUpdateDate(new Date());
|
||||||
|
c.setLicenseDueDate(new Date());
|
||||||
|
c.setProductId("1111111");
|
||||||
|
repository.save(c);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.loafle.bridge.collector;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.loafle.bridge.Application;
|
||||||
|
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 java.util.Date;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
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 root on 16. 11. 16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = Application.class)
|
||||||
|
@WebIntegrationTest
|
||||||
|
public class CollectorControllerTest {
|
||||||
|
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CollectorRepository repo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CollectorController controller;
|
||||||
|
|
||||||
|
Logger l = Logger.getLogger(this.getClass());
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void Before() {
|
||||||
|
|
||||||
|
mockMvc = standaloneSetup(controller).build();
|
||||||
|
Collector c = new Collector();
|
||||||
|
c.setVersion("1.0.0");
|
||||||
|
c.setConfigPath("/root");
|
||||||
|
c.setInstallDate(new Date());
|
||||||
|
c.setUpdateDate(new Date());
|
||||||
|
c.setLicenseDueDate(new Date());
|
||||||
|
c.setProductId("1111111");
|
||||||
|
repo.save(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void After() {
|
||||||
|
repo.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String jsonStringFromObject(Object object) throws JsonProcessingException {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
return mapper.writeValueAsString(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void TestGetCollectorbyProductionId () throws Exception {
|
||||||
|
|
||||||
|
Collector c = repo.findAll().get(0);
|
||||||
|
String jsonString = jsonStringFromObject(c);
|
||||||
|
l.debug("!!!!!!!!" + jsonString);
|
||||||
|
mockMvc.perform(get("/collector/{productId}", c.getProductId()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(content().string(equalTo(jsonString)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.loafle.bridge.collector;
|
||||||
import com.loafle.bridge.Application;
|
import com.loafle.bridge.Application;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -29,16 +30,17 @@ public class CollectorRepositoryTest {
|
||||||
Logger l = Logger.getLogger(this.getClass());
|
Logger l = Logger.getLogger(this.getClass());
|
||||||
|
|
||||||
|
|
||||||
// @Before
|
@Before
|
||||||
// public void Before() {
|
public void Before() {
|
||||||
// Collector c = new Collector();
|
Collector c = new Collector();
|
||||||
// c.setCollectorVersion("1.0.0");
|
c.setVersion("1.0.0");
|
||||||
// c.setConfigPath("/root");
|
c.setConfigPath("/root");
|
||||||
// c.setInstalledDate(new Date());
|
c.setInstallDate(new Date());
|
||||||
// c.setLicenseDueDate(new Date());
|
c.setUpdateDate(new Date());
|
||||||
// c.setProductId("1111111");
|
c.setLicenseDueDate(new Date());
|
||||||
// repo.save(c);
|
c.setProductId("1111111");
|
||||||
// }
|
repo.save(c);
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void After() {
|
public void After() {
|
||||||
|
@ -63,4 +65,23 @@ public class CollectorRepositoryTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void TestBefore() {
|
||||||
|
assertEquals(1, repo.findAll().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void TestFindByProductId() {
|
||||||
|
|
||||||
|
Collector c = repo.findAll().get(0);
|
||||||
|
Collector find = repo.findByPID(c.getProductId());
|
||||||
|
assertEquals(c.getId(),find.getId());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user