diff --git a/pom.xml b/pom.xml index 1c468ca..7c70db7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.vality service-parent-pom - 2.1.5 + 2.1.8 org-manager @@ -16,18 +16,19 @@ org-manager - 15 - 15 + 17 + 17 UTF-8 UTF-8 8022 8080 8023 ${server.port} ${server.rest.port} ${management.port} - 5.6.2 + 5.6.12 17.0.0 4.34.0 1.19-8707f87-server + 2.32.0 @@ -71,6 +72,12 @@ org.springframework.boot spring-boot-starter + + + org.yaml + snakeyaml + + org.springframework.boot @@ -186,7 +193,7 @@ org.postgresql postgresql - 42.3.3 + 42.4.3 org.flywaydb @@ -195,13 +202,18 @@ com.google.guava guava - 31.1-jre + 32.0.0-jre org.openapitools jackson-databind-nullable 0.2.2 + + org.yaml + snakeyaml + 2.0 + @@ -222,6 +234,12 @@ 3.1.1 test + + com.github.tomakehurst + wiremock-jre8-standalone + ${wiremock-jre8-standalone.version} + test + io.jsonwebtoken jjwt @@ -231,7 +249,7 @@ org.testcontainers postgresql - 1.17.0 + 1.19.1 test @@ -240,6 +258,12 @@ + + org.testcontainers + junit-jupiter + 1.19.1 + test + diff --git a/src/main/java/dev/vality/orgmanager/converter/BouncerContextConverter.java b/src/main/java/dev/vality/orgmanager/converter/BouncerContextConverter.java index 1cedaa8..f6926fb 100644 --- a/src/main/java/dev/vality/orgmanager/converter/BouncerContextConverter.java +++ b/src/main/java/dev/vality/orgmanager/converter/BouncerContextConverter.java @@ -11,6 +11,7 @@ import dev.vality.orgmanager.entity.OrganizationEntity; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -48,8 +49,12 @@ public class BouncerContextConverter { public OrgRole toOrgRole(MemberRoleEntity entity) { return new OrgRole() .setId(entity.getRoleId()) - .setScope(new OrgRoleScope() - .setShop(new Entity().setId(entity.getResourceId()))); + .setScope(Objects.nonNull(entity.getResourceId()) + ? new OrgRoleScope() + .setShop( + new Entity() + .setId(entity.getResourceId())) + : null); } } diff --git a/src/test/java/dev/vality/orgmanager/converter/BouncerContextConverterTest.java b/src/test/java/dev/vality/orgmanager/converter/BouncerContextConverterTest.java index 5d8c8a0..fda2882 100644 --- a/src/test/java/dev/vality/orgmanager/converter/BouncerContextConverterTest.java +++ b/src/test/java/dev/vality/orgmanager/converter/BouncerContextConverterTest.java @@ -46,6 +46,23 @@ class BouncerContextConverterTest { assertEquals(expected, actual); } + @Test + void shouldConvertToOrgRoleWithoutScope() { + MemberRoleEntity entity = MemberRoleEntity.builder() + .id("id") + .roleId("Administrator") + .organizationId("org") + .build(); + + OrgRole actual = converter.toOrgRole(entity); + + OrgRole expected = new OrgRole() + .setId(RoleId.ADMINISTRATOR.getValue()) + .setScope(null); + + assertEquals(expected, actual); + } + @Test void shouldConvertToMember() { Set organizationEntities = Set.of(TestObjectFactory.buildOrganization()); diff --git a/src/test/java/dev/vality/orgmanager/repository/AbstractRepositoryTest.java b/src/test/java/dev/vality/orgmanager/repository/AbstractRepositoryTest.java index d27f53c..2b05c7a 100644 --- a/src/test/java/dev/vality/orgmanager/repository/AbstractRepositoryTest.java +++ b/src/test/java/dev/vality/orgmanager/repository/AbstractRepositoryTest.java @@ -1,27 +1,27 @@ package dev.vality.orgmanager.repository; import dev.vality.orgmanager.OrgManagerApplication; -import org.junit.ClassRule; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import org.springframework.transaction.annotation.Transactional; import org.testcontainers.containers.PostgreSQLContainer; - -import java.time.Duration; +import org.testcontainers.utility.DockerImageName; @ActiveProfiles("test") @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {OrgManagerApplication.class}) -@ContextConfiguration(initializers = InvitationRepositoryTest.Initializer.class) public abstract class AbstractRepositoryTest { + private static final String POSTGRESQL_IMAGE_NAME = "postgres"; + private static final String POSTGRESQL_VERSION = "13.6"; + @Autowired protected InvitationRepository invitationRepository; @@ -54,24 +54,34 @@ public abstract class AbstractRepositoryTest { organizationRoleRepository.deleteAll(); } - @ClassRule - @SuppressWarnings("rawtypes") - public static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:13.6") - .withStartupTimeout(Duration.ofMinutes(5)); + @BeforeAll + static void beforeAll() { + TestPropertyValues.of( + "spring.datasource.url=" + postgres.getJdbcUrl(), + "spring.datasource.username=" + postgres.getUsername(), + "spring.datasource.password=" + postgres.getPassword(), + "spring.flyway.url=" + postgres.getJdbcUrl(), + "spring.flyway.user=" + postgres.getUsername(), + "spring.flyway.password=" + postgres.getPassword()); - public static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext configurableApplicationContext) { - postgres.start(); - TestPropertyValues.of( - "spring.datasource.url=" + postgres.getJdbcUrl(), - "spring.datasource.username=" + postgres.getUsername(), - "spring.datasource.password=" + postgres.getPassword(), - "spring.flyway.url=" + postgres.getJdbcUrl(), - "spring.flyway.user=" + postgres.getUsername(), - "spring.flyway.password=" + postgres.getPassword()) - .and(configurableApplicationContext.getEnvironment().getActiveProfiles()) - .applyTo(configurableApplicationContext); - } + } + + @SuppressWarnings("rawtypes") + static PostgreSQLContainer postgres = new PostgreSQLContainer<>(DockerImageName + .parse(POSTGRESQL_IMAGE_NAME) + .withTag(POSTGRESQL_VERSION)); + + static { + postgres.start(); + } + + @DynamicPropertySource + static void configureProperties(DynamicPropertyRegistry registry) { + registry.add("spring.datasource.url", postgres::getJdbcUrl); + registry.add("spring.datasource.username", postgres::getUsername); + registry.add("spring.datasource.password", postgres::getPassword); + registry.add("spring.flyway.url", postgres::getJdbcUrl); + registry.add("spring.flyway.user", postgres::getUsername); + registry.add("spring.flyway.password", postgres::getPassword); } }