|
@RunWith(SpringJUnit4ClassRunner.class) |
|
@ContextConfiguration( |
|
classes = { ApplicationConfig.class, WebMvcContextConfiguration.class } |
|
, loader = AnnotationConfigWebContextLoader.class) |
|
@WebAppConfiguration |
|
@Transactional(readOnly=true) |
|
public class TestAPIController { |
|
|
|
@Autowired |
|
protected WebApplicationContext wac; |
|
|
|
private MockMvc mockMvc; |
|
|
|
@Mock |
|
CategoryService categoryService; |
|
|
|
@Mock |
|
PromotionService promotionService; |
|
|
|
@Mock |
|
DisplayInfoService displayInfoService; |
|
|
|
@Mock |
|
ProductService productService; |
|
|
|
@Mock |
|
ReservationService reservationService; |
|
|
|
@InjectMocks |
|
APIController apiController; |
|
|
|
@Before |
|
public void setUp() throws Exception { |
|
MockitoAnnotations.initMocks(this); |
|
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); |
|
} |
|
|
|
@Test |
|
@Ignore |
|
public void getCategories() throws Exception { |
|
mockMvc.perform(MockMvcRequestBuilders.get("/api/categories")) |
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
.andDo(MockMvcResultHandlers.print()); |
|
} |
|
|
|
@Test |
|
@Ignore |
|
public void getPromotions() throws Exception { |
|
mockMvc.perform(MockMvcRequestBuilders.get("/api/promotions")) |
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
.andDo(MockMvcResultHandlers.print()); |
|
} |
|
|
|
@Test |
|
@Ignore |
|
public void getProducts() throws Exception { |
|
mockMvc.perform( |
|
MockMvcRequestBuilders.get("/api/products/") |
|
.param("categoryId" , "0").param("start", "0")) |
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
.andDo(MockMvcResultHandlers.print()); |
|
} |
|
|
|
@Test |
|
@Ignore |
|
public void getDisplayInfo() throws Exception { |
|
int displayInfoId = 1; |
|
mockMvc.perform(MockMvcRequestBuilders.get("/api/products/" + displayInfoId)) |
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
.andDo(MockMvcResultHandlers.print()); |
|
} |
|
|
|
|
|
Map<String, Object> reservationParam = new HashMap<>(); |
|
|
|
@Before |
|
@Ignore |
|
public void setReservationParam() { |
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); |
|
Calendar temp = Calendar.getInstance(); |
|
temp.add(Calendar.DAY_OF_MONTH, (int) ((Math.random() * 5))); |
|
|
|
reservationParam.put("displayInfoId" , 1); |
|
reservationParam.put("productId" , 1); |
|
reservationParam.put("reservationEmail" , "seok@connect.co.kr"); |
|
reservationParam.put("reservationName" , "석래"); |
|
reservationParam.put("reservationTelephone" , "010-0000-0001"); |
|
reservationParam.put("reservationYearMonthDay", sdf.format(temp.getTime())); |
|
List<Map<String, Object>> prices = new ArrayList<>(); |
|
Map<String, Object> price = new HashMap<>(); |
|
price.put("count", 1); |
|
price.put("productPriceId", 1); |
|
|
|
if(price.size() > 0) { |
|
prices.add(price); |
|
} |
|
reservationParam.put("prices", prices); |
|
} |
|
|
|
private MediaType contentType = |
|
new MediaType( |
|
MediaType.APPLICATION_JSON.getType(), |
|
MediaType.APPLICATION_JSON.getSubtype(), |
|
Charset.forName("utf8")); |
|
|
|
/** |
|
* @Date : 2019. 12. 7. |
|
* @Description |
|
* Post용 테스트 케이스 작성 필요 |
|
* @throws Exception |
|
*/ |
|
@Test |
|
@Ignore |
|
@Transactional(readOnly=false) |
|
public void postReservation() throws Exception { |
|
this.mockMvc.perform( |
|
MockMvcRequestBuilders.post("/api/reservations") |
|
.contentType(contentType)) |
|
.andDo(MockMvcResultHandlers.print()) |
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
; |
|
} |
|
|
|
@Test |
|
// @Ignore |
|
public void getReservations() throws Exception { |
|
String reservationEmail = "kimjinsu@connect.co.kr"; |
|
this.mockMvc.perform( |
|
MockMvcRequestBuilders.get("/api/reservations") |
|
.param("resrvEmail", reservationEmail)) |
|
.andExpect(MockMvcResultMatchers.status().isOk()) |
|
.andDo(MockMvcResultHandlers.log()) |
|
.andDo(MockMvcResultHandlers.print()); |
|
|
|
} |
|
} |