Skip to content

Commit

Permalink
Update ReviewControllerTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblykat authored Mar 25, 2024
1 parent 268a1b8 commit cf05b1c
Showing 1 changed file with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,34 @@ public void getReviewTest() throws Exception {
// Build the GET request
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/reviews/2");
//======= // = = = DATA INTEGRITY VIOLATION EXCEPTION = = =
public void createReviewTest() throws Exception {
test_logger.info("Starting test: " + getCurrentMethodName() + ". ");

// Step 1: Create a Review object.
Review newReview = Review.builder().category("Electronics")
.reviewContent("Great smartphone with excellent features. ").rating(5).customerId(1)
.productId(2).build();

// Step 2: Convert the Java object to JSON using ObjectMapper.
String newReviewAsJSON = objectMapper.writeValueAsString(newReview);

// Step 3: Build the request.
RequestBuilder request = MockMvcRequestBuilders.post("/reviews")
.contentType(MediaType.APPLICATION_JSON)
.content(newReviewAsJSON);

// Step 4: Perform the request and get the response and assert.
mockMvc.perform(request)
// MvcResult Result = mockMvc.perform(request)
// .andDo(print -> test_logger.error("Starting Request: createReviewTest. "))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.category").value("Electronics"))
.andExpect(jsonPath("$.rating").value(5));
// .andDo(print -> test_logger.error("Customer's id: {}",
// print.getResponse().getContentAsString()))
// .andDo(print -> test_logger.error("Starting Request: createReviewTest. "))
// .andReturn();
// public void createReviewTest() throws Exception {
// test_logger.info("Starting test: " + getCurrentMethodName() + ". ");

// // Step 1: Create a Review object.
// Review newReview = Review.builder().category("Electronics")
// .reviewContent("Great smartphone with excellent features. ").rating(5).customerId(1)
// .productId(2).build();

// // Step 2: Convert the Java object to JSON using ObjectMapper.
// String newReviewAsJSON = objectMapper.writeValueAsString(newReview);

// // Step 3: Build the request.
// RequestBuilder request = MockMvcRequestBuilders.post("/reviews")
// .contentType(MediaType.APPLICATION_JSON)
// .content(newReviewAsJSON);

// // Step 4: Perform the request and get the response and assert.
// mockMvc.perform(request)
// // MvcResult Result = mockMvc.perform(request)
// // .andDo(print -> test_logger.error("Starting Request: createReviewTest. "))
// .andExpect(status().isCreated())
// .andExpect(content().contentType(MediaType.APPLICATION_JSON))
// .andExpect(jsonPath("$.category").value("Electronics"))
// .andExpect(jsonPath("$.rating").value(5));
// // .andDo(print -> test_logger.error("Customer's id: {}",
// // print.getResponse().getContentAsString()))
// // .andDo(print -> test_logger.error("Starting Request: createReviewTest. "))
// // .andReturn();
// >>>>>>> main

// when(reviewService.getReview(2L)).thenReturn(testReview);
Expand Down

0 comments on commit cf05b1c

Please sign in to comment.