Skip to content

Commit

Permalink
EPMRPP-97288 fix issue types query
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Jan 16, 2025
1 parent 65cbed9 commit 345a82d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@
import com.epam.reportportal.auth.entity.item.issue.IssueType;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
* Repository interface for managing IssueType entities. Extends the ReportPortalRepository
* interface to provide CRUD operations.
*
* @author Siarhei Hrabko
* @see ReportPortalRepository
* @see IssueType
* @see Long
*/
public interface IssueTypeRepository extends ReportPortalRepository<IssueType, Long> {

@Query(value = "SELECT from issue_type it join public.issue_group ig on it.issue_group_id = ig.issue_group_id where it.locator in (:TestItemIssueGroup.values())", nativeQuery = true)
List<IssueType> getDefaultIssueTypes();
@Query(value = """
SELECT * from issue_type it
join public.issue_group ig on it.issue_group_id = ig.issue_group_id
where it.locator in (:locators)
""",
nativeQuery = true)
List<IssueType> getDefaultIssueTypes(@Param("locators") List<String> locators);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.epam.reportportal.auth.entity.Metadata;
import com.epam.reportportal.auth.entity.enums.ProjectAttributeEnum;
import com.epam.reportportal.auth.entity.enums.ProjectType;
import com.epam.reportportal.auth.entity.enums.TestItemIssueGroup;
import com.epam.reportportal.auth.entity.project.Project;
import com.epam.reportportal.auth.entity.project.ProjectRole;
import com.epam.reportportal.auth.entity.user.ProjectUser;
Expand Down Expand Up @@ -108,8 +109,12 @@ public Project generatePersonalProject(User user) {
.collect(Collectors.toSet());
project.setProjectAttributes(
defaultProjectAttributes(project, attributeRepository.findAllByNameIn(attrs)));

var locators = Arrays.stream(TestItemIssueGroup.values())
.map(TestItemIssueGroup::getLocator)
.toList();
project.setProjectIssueTypes(
defaultIssueTypes(project, issueTypeRepository.getDefaultIssueTypes()));
defaultIssueTypes(project, issueTypeRepository.getDefaultIssueTypes(locators)));

return project;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package com.epam.auth.reportportal;
package com.epam.reportportal;

import com.epam.auth.reportportal.config.TestConfig;
import com.epam.reportportal.auth.config.TestConfig;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -27,8 +27,6 @@
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
Expand Down Expand Up @@ -65,6 +63,11 @@ public abstract class BaseTest {
.withAccessToHost(true)
.withDatabaseName("reportportal");

static {
applyMigrationScripts();
postgres.start();
log.info("PostgreSQL container started on port: {}", postgres.getFirstMappedPort());
}

@SneakyThrows
private static void applyMigrationScripts() {
Expand Down Expand Up @@ -109,17 +112,6 @@ private static void applyMigrationScripts() {
}
}

@BeforeAll
static void beforeAll() {
applyMigrationScripts();
postgres.start();
log.info("PostgreSQL container started on port: {}", postgres.getFirstMappedPort());
}

@AfterAll
static void afterAll() {
postgres.stop();
}

@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.epam.auth.reportportal.config;
package com.epam.reportportal.auth.config;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2025 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.auth.dao;

import com.epam.reportportal.BaseTest;
import com.epam.reportportal.auth.entity.enums.TestItemIssueGroup;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

class IssueTypeRepositoryTest extends BaseTest {

@Autowired
IssueTypeRepository issueTypeRepository;

@Test
void getDefaultIssueTypes() {
var locators = Arrays.stream(TestItemIssueGroup.values())
.map(TestItemIssueGroup::getLocator)
.toList();

var issueTypes = issueTypeRepository.getDefaultIssueTypes(locators);

Assertions.assertFalse(issueTypes.isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2025 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.auth.dao;

import com.epam.reportportal.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

class UserRepositoryCustomImplTest extends BaseTest {

@Autowired
UserRepository userRepository;

@Test
void findUserDetails() {
var user = userRepository.findByLogin("superadmin")
.orElseThrow();
Assertions.assertEquals("superadmin", user.getLogin());
}

@Test
void findUserDetailsNotFound() {
var user = userRepository.findByLogin("notfound");
Assertions.assertTrue(user.isEmpty());
}

}

0 comments on commit 345a82d

Please sign in to comment.