Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblykat committed Mar 29, 2024
2 parents f17866a + b13b667 commit a704b2e
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.*;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void createCustomerTest() throws Exception {

// Step 4: Perform the request and get the response and assert.
mockMvc.perform(request)
.andDo(print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.firstName").value("Jackie"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.*;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void createProductTest() throws Exception {

// Step 4: Perform the request and get the response and assert.
mockMvc.perform(request)
.andDo(print())
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.category").value("Electronics"))
Expand Down
280 changes: 145 additions & 135 deletions src/test/java/sg/com/smartinventory/controllers/ReviewControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import org.mockito.InjectMocks;
import org.mockito.Mock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -75,174 +79,180 @@ void teardown() {
private ReviewServiceImpl reviewService;

@Test
//<<<<<<< SIS-39
// <<<<<<< SIS-39
@DisplayName("Get Review Test by Id")
public void getReviewTest() throws Exception {
// Setup
// for now, setup is created in DataLoader. need fix

// 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();
// >>>>>>> main
// ======= // = = = 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();
// >>>>>>> main

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

// Perform the request (Execute + Assert)
mockMvc.perform(requestBuilder)
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.id").value(2));
}
//<<<<<<< SIS-39
// =======
// <<<<<<< SIS-39
// =======

// @DisplayName("Get All Reviews")
// @Test
// public void getAllReviewsTest() throws Exception {
// test_logger.info("Starting test: " + getCurrentMethodName() + ". ");

// // Step 1: Create a Review objects.
// 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// test_logger.info("Starting test: " + getCurrentMethodName() + ". ");

// // Step 1: Create a Review objects.
// 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// }

// @DisplayName("Get One Review")
// @Test
// public void getOneReviewTest() 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// }

// @DisplayName("Update Review")
// @Test
// public void updateReviewTest() 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// }

// @DisplayName("Delete Review")
// @Test
// public void deleteReviewTest() 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// 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));

// test_logger.info("Ending test: " + getCurrentMethodName() + ". ");
// }
// >>>>>>> main
}
// >>>>>>> main
}
Loading

0 comments on commit a704b2e

Please sign in to comment.