import java.util.HashMap;
import java.util.Map;
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.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.alibaba.fastjson.JSON;
import com.joshvm.commons.constant.URLConstants;
import com.joshvm.service.db.mongo.util.TestUtil;
import com.joshvm.service.mongo.ServiceMongoApplication;
@SpringBootTest(classes = { ServiceMongoApplication.class })
@RunWith(SpringRunner.class)
public class CertControllerTest {
private MockMvc mockMvc;
@Autowired
WebApplicationContext context;
@Before
public void before() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}
/**
* @throws Exception
*/
@Test
public void testSearch() throws Exception {
@SuppressWarnings("serial")
Map<String, Object> params = new HashMap<String, Object>() {
{
put("certNumber", "7d");
put("name", "file_name");
put("page", 1);
put("rows", 2);
}
};
String content = JSON.toJSONString(params);
String url = URLConstants.ServiceMongoURL.ControllerCertURL.SEARCH_FULL;
RequestBuilder builder = MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON).content(content);
try {
MvcResult result = mockMvc.perform(builder).andReturn();
TestUtil.printResult(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}