diff --git a/build.gradle b/build.gradle index 16493aa68a..d60cee8ea2 100644 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,7 @@ dependencies { implementation 'com.epam.reportportal:commons' implementation 'com.epam.reportportal:plugin-api:5.11.1' } else { - implementation 'com.github.reportportal:commons-dao:c5ebfac' + implementation 'com.github.reportportal:commons-dao:69da66d' implementation 'com.github.reportportal:commons:7f23a5f' implementation 'com.github.reportportal:plugin-api:d1c0f0e' } diff --git a/src/main/java/com/epam/ta/reportportal/core/project/impl/OrganizationProjectHandlerImpl.java b/src/main/java/com/epam/ta/reportportal/core/project/impl/OrganizationProjectHandlerImpl.java index 6821659c01..11061035f8 100644 --- a/src/main/java/com/epam/ta/reportportal/core/project/impl/OrganizationProjectHandlerImpl.java +++ b/src/main/java/com/epam/ta/reportportal/core/project/impl/OrganizationProjectHandlerImpl.java @@ -155,7 +155,8 @@ public OrganizationProjectInfo createProject(Long orgId, ProjectDetails projectD } var projectKey = organization.getSlug() + "." + projectDetails.getSlug(); - Optional existProject = projectRepository.findByKey(projectKey); + Optional existProject = + projectRepository.findByNameAndOrganizationId(projectDetails.getName(), orgId); expect(existProject, not(isPresent())).verify(ErrorType.PROJECT_ALREADY_EXISTS, projectKey); var projectToSave = generateProjectBody(orgId, projectDetails, projectKey); diff --git a/src/test/java/com/epam/ta/reportportal/ws/controller/OrganizationProjectControllerTest.java b/src/test/java/com/epam/ta/reportportal/ws/controller/OrganizationProjectControllerTest.java index 3bfd11825e..c9d9097f7b 100644 --- a/src/test/java/com/epam/ta/reportportal/ws/controller/OrganizationProjectControllerTest.java +++ b/src/test/java/com/epam/ta/reportportal/ws/controller/OrganizationProjectControllerTest.java @@ -24,7 +24,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.epam.reportportal.api.model.OffsetRequest.OrderEnum; -import com.epam.reportportal.api.model.OrganizationProfilesPage; import com.epam.reportportal.api.model.OrganizationProjectsPage; import com.epam.reportportal.api.model.SearchCriteriaRQ; import com.epam.reportportal.api.model.SearchCriteriaSearchCriteria; @@ -144,4 +143,23 @@ void createProject(String name, String slug, String expectSlug) throws Exception .andExpect(jsonPath("$.slug").value(expectSlug)); } + + @Test + void createDuplicateProjectFails() throws Exception { + JsonObject jsonBody = new JsonObject(); + jsonBody.addProperty("name", "uniq_name_123"); + + mockMvc.perform(post("/organizations/1/projects") + .contentType(MediaType.APPLICATION_JSON) + .with(token(oAuthHelper.getSuperadminToken())) + .content(jsonBody.toString())) + .andExpect(status().isOk()); + + mockMvc.perform(post("/organizations/1/projects") + .contentType(MediaType.APPLICATION_JSON) + .with(token(oAuthHelper.getSuperadminToken())) + .content(jsonBody.toString())) + .andExpect(status().is4xxClientError()); + } + }