-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
480 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/com/i8ai/training/store/api/ExistenceControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.i8ai.training.store.api; | ||
|
||
import com.i8ai.training.store.service.ExistenceService; | ||
import com.i8ai.training.store.service.data.Existence; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@WebMvcTest(ExistenceController.class) | ||
class ExistenceControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private ExistenceService existenceService; | ||
|
||
@Test | ||
void testGetAllProductsExistenceInMain() throws Exception { | ||
List<Existence> existences = Arrays.asList(Existence.builder().build(), Existence.builder().build()); | ||
given(existenceService.getAllProductsExistenceInMain()).willReturn(existences); | ||
|
||
mockMvc.perform(get("/existence")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").isArray()) | ||
.andExpect(jsonPath("$[0]").exists()) | ||
.andExpect(jsonPath("$[1]").exists()); | ||
} | ||
|
||
@Test | ||
void testGetProductExistenceInMain() throws Exception { | ||
Existence existence = Existence.builder().build(); | ||
given(existenceService.getProductExistenceInMain(anyLong())).willReturn(existence); | ||
|
||
mockMvc.perform(get("/existence/1")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").exists()); | ||
} | ||
|
||
@Test | ||
void testGetProductExistenceInAllShops() throws Exception { | ||
List<Existence> existences = Arrays.asList(Existence.builder().build(), Existence.builder().build()); | ||
given(existenceService.getProductExistenceInAllShops(anyLong())).willReturn(existences); | ||
|
||
mockMvc.perform(get("/existence/1/shop")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").isArray()) | ||
.andExpect(jsonPath("$[0]").exists()) | ||
.andExpect(jsonPath("$[1]").exists()); | ||
} | ||
|
||
@Test | ||
void testGetProductExistenceInShop() throws Exception { | ||
Existence existence = Existence.builder().build(); | ||
given(existenceService.getProductExistenceInShop(anyLong(), anyLong())).willReturn(existence); | ||
|
||
mockMvc.perform(get("/existence/1/shop/1")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").exists()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/com/i8ai/training/store/api/LotControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.i8ai.training.store.api; | ||
|
||
import com.i8ai.training.store.model.Lot; | ||
import com.i8ai.training.store.service.LotService; | ||
import com.i8ai.training.store.util.TestUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@WebMvcTest(LotController.class) | ||
class LotControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private LotService lotService; | ||
|
||
@Test | ||
void testGetLots() throws Exception { | ||
List<Lot> lots = Arrays.asList(Lot.builder().build(), Lot.builder().build()); | ||
|
||
given(lotService.getLots(null, null, null)).willReturn(lots); | ||
|
||
mockMvc.perform(get("/lot")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").isArray()) | ||
.andExpect(jsonPath("$[0]").exists()) | ||
.andExpect(jsonPath("$[1]").exists()); | ||
} | ||
|
||
@Test | ||
void testRegisterLot() throws Exception { | ||
Lot newLot = Lot.builder().build(); | ||
Lot savedLot = Lot.builder().build(); | ||
given(lotService.registerLot(any(Lot.class))).willReturn(savedLot); | ||
|
||
mockMvc.perform(post("/lot") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(TestUtils.asJsonString(newLot))) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").exists()); | ||
} | ||
|
||
@Test | ||
void testDeleteLot() throws Exception { | ||
doNothing().when(lotService).deleteLot(anyLong()); | ||
|
||
mockMvc.perform(delete("/lot/1")) | ||
.andExpect(status().isOk()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/test/java/com/i8ai/training/store/api/PackControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.i8ai.training.store.api; | ||
|
||
import com.i8ai.training.store.model.Pack; | ||
import com.i8ai.training.store.service.PackService; | ||
import com.i8ai.training.store.util.TestUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@WebMvcTest(PackController.class) | ||
class PackControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private PackService packService; | ||
|
||
@Test | ||
void testGetPacks() throws Exception { | ||
List<Pack> packs = Arrays.asList(Pack.builder().build(), Pack.builder().build()); | ||
given(packService.getPacks(null, null, null, null)).willReturn(packs); | ||
|
||
mockMvc.perform(get("/pack")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").isArray()) | ||
.andExpect(jsonPath("$[0]").exists()) | ||
.andExpect(jsonPath("$[1]").exists()); | ||
} | ||
|
||
@Test | ||
void testRegisterPack() throws Exception { | ||
Pack newPack = Pack.builder().build(); | ||
Pack savedPack = Pack.builder().build(); | ||
given(packService.registerPack(any(Pack.class))).willReturn(savedPack); | ||
|
||
mockMvc.perform(post("/pack") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(TestUtils.asJsonString(newPack))) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$").exists()); | ||
} | ||
|
||
@Test | ||
void testDeletePack() throws Exception { | ||
doNothing().when(packService).deletePack(anyLong()); | ||
|
||
mockMvc.perform(delete("/pack/1")) | ||
.andExpect(status().isOk()); | ||
} | ||
} |
Oops, something went wrong.