|
| 1 | +package com.epam.ta.reportportal.core.tms.controller.integration; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 6 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
| 7 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 8 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; |
| 9 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
| 10 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; |
| 11 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
| 12 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 13 | + |
| 14 | +import com.epam.ta.reportportal.core.tms.db.entity.TmsMilestone; |
| 15 | +import com.epam.ta.reportportal.core.tms.db.entity.TmsTestPlan; |
| 16 | +import com.epam.ta.reportportal.core.tms.db.repository.TmsTestPlanRepository; |
| 17 | +import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanAttributeRQ; |
| 18 | +import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanRQ; |
| 19 | +import com.epam.ta.reportportal.ws.BaseMvcTest; |
| 20 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 23 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 24 | +import org.springframework.beans.factory.annotation.Autowired; |
| 25 | +import org.springframework.http.MediaType; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Optional; |
| 28 | +import org.springframework.test.context.jdbc.Sql; |
| 29 | + |
| 30 | +/** |
| 31 | + * @author <a href="mailto:[email protected]">Konstantin Shaplyko</a> |
| 32 | + */ |
| 33 | +@Sql("/db/tms/tms-product-version/tms-test-plan-fill.sql") |
| 34 | +@ExtendWith(MockitoExtension.class) |
| 35 | +public class TmsTestPlanIntegrationTest extends BaseMvcTest { |
| 36 | + |
| 37 | + @Autowired |
| 38 | + private TmsTestPlanRepository testPlanRepository; |
| 39 | + |
| 40 | + @Test |
| 41 | + void createTestPlanIntegrationTest() throws Exception { |
| 42 | + TmsTestPlanAttributeRQ attribute = new TmsTestPlanAttributeRQ(); |
| 43 | + attribute.setValue("value3"); |
| 44 | + attribute.setAttributeId(3L); |
| 45 | + |
| 46 | + TmsTestPlanRQ tmsTestPlan = new TmsTestPlanRQ(); |
| 47 | + tmsTestPlan.setName("name3"); |
| 48 | + tmsTestPlan.setDescription("description3"); |
| 49 | + tmsTestPlan.setEnvironmentId(3L); |
| 50 | + tmsTestPlan.setProductVersionId(3L); |
| 51 | + tmsTestPlan.setMilestoneIds(List.of(3L)); |
| 52 | + tmsTestPlan.setAttributes(List.of(attribute)); |
| 53 | + |
| 54 | + ObjectMapper mapper = new ObjectMapper(); |
| 55 | + String jsonContent = mapper.writeValueAsString(tmsTestPlan); |
| 56 | + |
| 57 | + mockMvc.perform(post("/project/3/tms/test-plan") |
| 58 | + .contentType("application/json") |
| 59 | + .content(jsonContent) |
| 60 | + .with(token(oAuthHelper.getSuperadminToken()))) |
| 61 | + .andExpect(status().isOk()); |
| 62 | + |
| 63 | + Optional<TmsTestPlan> testPlan = testPlanRepository.findById(1L); |
| 64 | + |
| 65 | + assertTrue(testPlan.isPresent()); |
| 66 | + assertEquals(tmsTestPlan.getName(), testPlan.get().getName()); |
| 67 | + assertEquals(tmsTestPlan.getDescription(), testPlan.get().getDescription()); |
| 68 | + assertEquals(tmsTestPlan.getEnvironmentId(), testPlan.get().getEnvironment().getId()); |
| 69 | + TmsMilestone[] versionArray = testPlan.get().getMilestones() |
| 70 | + .toArray(new TmsMilestone[0]); |
| 71 | + assertEquals(tmsTestPlan.getMilestoneIds().get(0), versionArray[0].getId()); |
| 72 | + assertEquals(tmsTestPlan.getProductVersionId(), testPlan.get().getProductVersion().getId()); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + void getTestPlansByCriteriaIntegrationTest() throws Exception { |
| 77 | + Optional<TmsTestPlan> testPlan = testPlanRepository.findById(4L); |
| 78 | + |
| 79 | + mockMvc.perform(get("/project/4/tms/test-plan") |
| 80 | + .param("environmentId", "4") |
| 81 | + .param("productVersionId", "4") |
| 82 | + .param("page", "0") |
| 83 | + .param("size", "1") |
| 84 | + .with(token(oAuthHelper.getSuperadminToken()))) |
| 85 | + .andExpect(status().isOk()) |
| 86 | + .andExpect(jsonPath("$.content[0].id").value(testPlan.get().getId())) |
| 87 | + .andExpect(jsonPath("$.content[0].name").value(testPlan.get().getName())) |
| 88 | + .andExpect(jsonPath("$.content[0].description").value(testPlan.get().getDescription())) |
| 89 | + .andExpect(jsonPath("$.content[0].environment.id").value(testPlan.get() |
| 90 | + .getEnvironment().getId())) |
| 91 | + .andExpect(jsonPath("$.content[0].productVersion.id").value(testPlan.get() |
| 92 | + .getProductVersion().getId())); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + void updateTestPlanIntegrationTest() throws Exception { |
| 97 | + TmsTestPlanAttributeRQ attribute = new TmsTestPlanAttributeRQ(); |
| 98 | + attribute.setValue("value5"); |
| 99 | + attribute.setAttributeId(5L); |
| 100 | + |
| 101 | + TmsTestPlanRQ tmsTestPlan = new TmsTestPlanRQ(); |
| 102 | + tmsTestPlan.setName("updated_name5"); |
| 103 | + tmsTestPlan.setDescription("updated_name5"); |
| 104 | + tmsTestPlan.setEnvironmentId(4L); |
| 105 | + tmsTestPlan.setProductVersionId(4L); |
| 106 | + tmsTestPlan.setMilestoneIds(List.of(4L)); |
| 107 | + tmsTestPlan.setAttributes(List.of(attribute)); |
| 108 | + |
| 109 | + ObjectMapper mapper = new ObjectMapper(); |
| 110 | + String jsonContent = mapper.writeValueAsString(tmsTestPlan); |
| 111 | + |
| 112 | + mockMvc.perform(put("/project/5/tms/test-plan/5") |
| 113 | + .contentType("application/json") |
| 114 | + .content(jsonContent) |
| 115 | + .with(token(oAuthHelper.getSuperadminToken()))) |
| 116 | + .andExpect(status().isOk()); |
| 117 | + |
| 118 | + Optional<TmsTestPlan> testPlan = testPlanRepository.findById(5L); |
| 119 | + |
| 120 | + assertTrue(testPlan.isPresent()); |
| 121 | + assertEquals(tmsTestPlan.getName(), testPlan.get().getName()); |
| 122 | + assertEquals(tmsTestPlan.getDescription(), testPlan.get().getDescription()); |
| 123 | + assertEquals(tmsTestPlan.getEnvironmentId(), testPlan.get().getEnvironment().getId()); |
| 124 | + TmsMilestone[] versionArray = testPlan.get().getMilestones() |
| 125 | + .toArray(new TmsMilestone[0]); |
| 126 | + assertEquals(tmsTestPlan.getMilestoneIds().get(0), versionArray[0].getId()); |
| 127 | + assertEquals(tmsTestPlan.getProductVersionId(), testPlan.get().getProductVersion().getId()); |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + void getTestPlanByIdIntegrationTest() throws Exception { |
| 132 | + Optional<TmsTestPlan> testPlan = testPlanRepository.findById(5L); |
| 133 | + |
| 134 | + mockMvc.perform(get("/project/5/tms/test-plan/5") |
| 135 | + .with(token(oAuthHelper.getSuperadminToken()))) |
| 136 | + .andExpect(status().isOk()) |
| 137 | + .andExpect(jsonPath("$.id").value(testPlan.get().getId())) |
| 138 | + .andExpect(jsonPath("$.name").value(testPlan.get().getName())) |
| 139 | + .andExpect(jsonPath("$.description").value(testPlan.get().getDescription())) |
| 140 | + .andExpect(jsonPath("$.environment.id").value(testPlan.get().getEnvironment().getId())) |
| 141 | + .andExpect(jsonPath("$.productVersion.id").value(testPlan.get() |
| 142 | + .getProductVersion().getId())); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + void deleteTestPlanIntegrationTest() throws Exception { |
| 147 | + |
| 148 | + mockMvc.perform(delete("/project/6/tms/test-plan/6") |
| 149 | + .contentType(MediaType.APPLICATION_JSON) |
| 150 | + .with(token(oAuthHelper.getSuperadminToken()))) |
| 151 | + .andExpect(status().isOk()); |
| 152 | + |
| 153 | + assertFalse(testPlanRepository.findById(6L).isPresent()); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + void patchTestPlanTest() throws Exception { |
| 158 | + TmsTestPlanAttributeRQ attributQ = new TmsTestPlanAttributeRQ(); |
| 159 | + attributQ.setValue("value5"); |
| 160 | + attributQ.setAttributeId(5L); |
| 161 | + |
| 162 | + TmsTestPlanRQ tmsTestPlan = new TmsTestPlanRQ(); |
| 163 | + tmsTestPlan.setName("updated_name5"); |
| 164 | + tmsTestPlan.setDescription("updated_name5"); |
| 165 | + tmsTestPlan.setEnvironmentId(4L); |
| 166 | + tmsTestPlan.setProductVersionId(4L); |
| 167 | + tmsTestPlan.setMilestoneIds(List.of(4L)); |
| 168 | + tmsTestPlan.setAttributes(List.of(attributQ)); |
| 169 | + |
| 170 | + ObjectMapper mapper = new ObjectMapper(); |
| 171 | + String jsonContent = mapper.writeValueAsString(tmsTestPlan); |
| 172 | + |
| 173 | + mockMvc.perform(patch("/project/5/tms/test-plan/5") |
| 174 | + .contentType("application/json") |
| 175 | + .content(jsonContent) |
| 176 | + .with(token(oAuthHelper.getSuperadminToken()))) |
| 177 | + .andExpect(status().isOk()); |
| 178 | + |
| 179 | + Optional<TmsTestPlan> testPlan = testPlanRepository.findById(5L); |
| 180 | + |
| 181 | + assertTrue(testPlan.isPresent()); |
| 182 | + assertEquals(tmsTestPlan.getName(), testPlan.get().getName()); |
| 183 | + assertEquals(tmsTestPlan.getDescription(), testPlan.get().getDescription()); |
| 184 | + assertEquals(tmsTestPlan.getEnvironmentId(), testPlan.get().getEnvironment().getId()); |
| 185 | + TmsMilestone[] versionArray = testPlan.get().getMilestones() |
| 186 | + .toArray(new TmsMilestone[0]); |
| 187 | + assertEquals(tmsTestPlan.getMilestoneIds().get(0), versionArray[0].getId()); |
| 188 | + assertEquals(tmsTestPlan.getProductVersionId(), testPlan.get().getProductVersion().getId()); |
| 189 | + } |
| 190 | +} |
0 commit comments