From fbb47767c38fd470e992b9efbe7eefeda299804e Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Mon, 2 Jun 2025 22:16:33 -0700 Subject: [PATCH 1/2] Removed DBRef for retrocompatibility with latest AC versions --- pom.xml | 12 ++++- .../ac/controller/AdminController.java | 4 +- .../switcherapi/ac/model/domain/Account.java | 4 +- .../ac/model/mapper/AccountMapper.java | 9 ++-- .../switcherapi/ac/repository/AccountDao.java | 2 +- .../ac/service/AccountService.java | 12 ++--- .../ac/service/ValidatorBasicService.java | 16 +++---- .../validator/AbstractValidatorService.java | 6 ++- .../validator/ValidatorBuilderService.java | 6 ++- .../validator/ValidatorNativeBuilder.java | 7 +-- .../validator/ValidatorRuntimeBuilder.java | 9 ++-- .../beans/AbstractActiveCheckValidator.java | 5 ++- .../validator/beans/ValidateRateLimit.java | 8 ++-- .../github/switcherapi/ac/PlanUtilsTests.java | 3 ++ .../AdminAccountControllerTests.java | 23 ++++++---- .../controller/AdminAuthControllerTests.java | 13 ++++-- .../AdminGitHubAuthControllerTests.java | 8 +++- .../AdminPlanControllerErrorTests.java | 5 ++- .../ac/controller/ApiControllerTests.java | 3 ++ .../ac/controller/ApiResourcesTests.java | 3 ++ .../ac/controller/PlanControllerTests.java | 5 ++- ...tcherRelayCacheLimiterControllerTests.java | 3 ++ .../SwitcherRelayControllerErrorTests.java | 2 +- .../SwitcherRelayControllerTests.java | 18 +++++++- .../fixture/ControllerTestUtils.java | 44 +++++++++++++++---- .../ac/service/AccountServiceTest.java | 9 +++- .../ac/service/GitHubServiceTest.java | 3 ++ .../ac/service/ValidatorBasicServiceTest.java | 3 ++ .../ValidatorNativeBuilderServiceTest.java | 3 ++ .../ValidatorRuntimeBuilderServiceTest.java | 3 ++ .../switcherapi/ac/util/FileUtilTest.java | 3 ++ .../switcherapi/ac/util/SanitizerTest.java | 3 ++ .../nativeimage/NativeReflectConfigTest.java | 3 ++ src/test/resources/junit-platform.properties | 3 ++ 34 files changed, 196 insertions(+), 67 deletions(-) create mode 100644 src/test/resources/junit-platform.properties diff --git a/pom.xml b/pom.xml index e522fde..07520c3 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.github.switcherac switcher-ac - 1.0.10 + 1.1.0-SNAPSHOT Switcher Account Control Account Control Service for Switcher API @@ -71,6 +71,7 @@ 0.10.6 3.14.0 + 3.5.3 5.1.0.4751 0.8.13 @@ -317,6 +318,15 @@ org.springframework.boot spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + suites + + diff --git a/src/main/java/com/github/switcherapi/ac/controller/AdminController.java b/src/main/java/com/github/switcherapi/ac/controller/AdminController.java index f305fe5..f6bd78f 100644 --- a/src/main/java/com/github/switcherapi/ac/controller/AdminController.java +++ b/src/main/java/com/github/switcherapi/ac/controller/AdminController.java @@ -2,7 +2,6 @@ import com.github.switcherapi.ac.model.dto.AccountDTO; import com.github.switcherapi.ac.model.dto.GitHubAuthDTO; -import com.github.switcherapi.ac.model.mapper.AccountMapper; import com.github.switcherapi.ac.service.AccountService; import com.github.switcherapi.ac.service.AdminService; import io.swagger.v3.oas.annotations.Operation; @@ -51,8 +50,7 @@ public ResponseEntity logout(@RequestHeader(HttpHeaders.AUTHORIZATION) S @PatchMapping(value = "/account/change/{adminId}") public ResponseEntity changeAccountPlan(@PathVariable(value="adminId") String adminId, @RequestParam String plan) { - final var account = accountService.createAccount(adminId, plan); - return ResponseEntity.ok(AccountMapper.createCopy(account)); + return ResponseEntity.ok(accountService.createAccount(adminId, plan)); } } diff --git a/src/main/java/com/github/switcherapi/ac/model/domain/Account.java b/src/main/java/com/github/switcherapi/ac/model/domain/Account.java index dbf5141..f24567b 100644 --- a/src/main/java/com/github/switcherapi/ac/model/domain/Account.java +++ b/src/main/java/com/github/switcherapi/ac/model/domain/Account.java @@ -6,7 +6,6 @@ import lombok.NoArgsConstructor; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.index.Indexed; -import org.springframework.data.mongodb.core.mapping.DBRef; import org.springframework.data.mongodb.core.mapping.Document; @JsonInclude(Include.NON_NULL) @@ -21,8 +20,7 @@ public class Account { @Indexed(unique = true) private String adminId; - @DBRef - private Plan plan; + private String plan; public Account(String adminId) { this.adminId = adminId; diff --git a/src/main/java/com/github/switcherapi/ac/model/mapper/AccountMapper.java b/src/main/java/com/github/switcherapi/ac/model/mapper/AccountMapper.java index 3fa30d3..713544a 100644 --- a/src/main/java/com/github/switcherapi/ac/model/mapper/AccountMapper.java +++ b/src/main/java/com/github/switcherapi/ac/model/mapper/AccountMapper.java @@ -1,17 +1,16 @@ package com.github.switcherapi.ac.model.mapper; import com.github.switcherapi.ac.model.domain.Account; +import com.github.switcherapi.ac.model.domain.Plan; import com.github.switcherapi.ac.model.dto.AccountDTO; -import com.github.switcherapi.ac.model.dto.PlanDTO; import lombok.AccessLevel; import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class AccountMapper { - - public static AccountDTO createCopy(Account from) { - final var plan = new PlanDTO(from.getPlan().getId(), from.getPlan().getName(), from.getPlan().getAttributes()); - return new AccountDTO(from.getId(), from.getAdminId(), plan); + + public static AccountDTO map(Account account, Plan plan) { + return new AccountDTO(account.getId(), account.getAdminId(), PlanMapper.createCopy(plan)); } } diff --git a/src/main/java/com/github/switcherapi/ac/repository/AccountDao.java b/src/main/java/com/github/switcherapi/ac/repository/AccountDao.java index 9aee9ff..a2953c1 100644 --- a/src/main/java/com/github/switcherapi/ac/repository/AccountDao.java +++ b/src/main/java/com/github/switcherapi/ac/repository/AccountDao.java @@ -38,7 +38,7 @@ public List findByPlanName(String planName) { if (Objects.nonNull(planFound)) { final var query = new Query(); - query.addCriteria(Criteria.where("plan").is(planFound)); + query.addCriteria(Criteria.where("plan").is(planFound.getId())); return mongoTemplate.find(query, Account.class); } diff --git a/src/main/java/com/github/switcherapi/ac/service/AccountService.java b/src/main/java/com/github/switcherapi/ac/service/AccountService.java index 75fa0d0..a2c476d 100644 --- a/src/main/java/com/github/switcherapi/ac/service/AccountService.java +++ b/src/main/java/com/github/switcherapi/ac/service/AccountService.java @@ -2,6 +2,8 @@ import com.github.switcherapi.ac.model.domain.Account; import com.github.switcherapi.ac.model.domain.PlanType; +import com.github.switcherapi.ac.model.dto.AccountDTO; +import com.github.switcherapi.ac.model.mapper.AccountMapper; import com.github.switcherapi.ac.repository.AccountDao; import com.github.switcherapi.ac.repository.PlanDao; import org.springframework.http.HttpStatus; @@ -26,11 +28,11 @@ public AccountService(PlanDao planDao, AccountDao accountDao) { this.accountDao = accountDao; } - public Account createAccount(String adminId) { + public AccountDTO createAccount(String adminId) { return createAccount(adminId, PlanType.DEFAULT.name()); } - public Account createAccount(String adminId, String planName) { + public AccountDTO createAccount(String adminId, String planName) { final var plan = Optional.ofNullable(planDao.findByName(planName)) .orElseThrow(() -> new ResponseStatusException( HttpStatus.NOT_FOUND, String.format(PLAN_NAME_NOT_FOUND.getValue(), planName))); @@ -38,10 +40,10 @@ public Account createAccount(String adminId, String planName) { var account = Optional.ofNullable(accountDao.findByAdminId(adminId)) .orElse(new Account(adminId)); - account.setPlan(plan); + account.setPlan(plan.getId()); accountDao.getAccountRepository().save(account); - return account; + return AccountMapper.map(account, plan); } public void updateAccountPlan(String adminId, String planName) { @@ -50,7 +52,7 @@ public void updateAccountPlan(String adminId, String planName) { HttpStatus.NOT_FOUND, String.format(PLAN_NAME_NOT_FOUND.getValue(), planName))); final var account = getAccountByAdminId(adminId); - account.setPlan(plan); + account.setPlan(plan.getId()); accountDao.getAccountRepository().save(account); } diff --git a/src/main/java/com/github/switcherapi/ac/service/ValidatorBasicService.java b/src/main/java/com/github/switcherapi/ac/service/ValidatorBasicService.java index fee9d81..0eca365 100644 --- a/src/main/java/com/github/switcherapi/ac/service/ValidatorBasicService.java +++ b/src/main/java/com/github/switcherapi/ac/service/ValidatorBasicService.java @@ -1,11 +1,9 @@ package com.github.switcherapi.ac.service; -import com.github.switcherapi.ac.model.domain.Account; -import com.github.switcherapi.ac.model.domain.Feature; -import com.github.switcherapi.ac.model.domain.FeaturePayload; -import com.github.switcherapi.ac.model.domain.PlanAttribute; +import com.github.switcherapi.ac.model.domain.*; import com.github.switcherapi.ac.model.dto.ResponseRelayDTO; import com.github.switcherapi.ac.repository.AccountDao; +import com.github.switcherapi.ac.repository.PlanDao; import com.github.switcherapi.ac.service.validator.AbstractValidatorService; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -18,13 +16,15 @@ @Service public class ValidatorBasicService extends AbstractValidatorService { - protected ValidatorBasicService(AccountDao accountDao) { - super(accountDao); + protected ValidatorBasicService(AccountDao accountDao, PlanDao planDao) { + super(accountDao, planDao); } @Override protected ResponseRelayDTO executeValidator(final Account account) { - final var maxPlanValue = account.getPlan().getAttributes().stream() + var plan = planDao.getPlanRepository().findById(account.getPlan()).orElse(Plan.loadDefault()); + + final var maxPlanValue = plan.getAttributes().stream() .filter(attrib -> attrib.getFeature().equals(getParam(FEATURE))) .findFirst().orElseGet(() -> PlanAttribute.builder().build()); @@ -54,7 +54,7 @@ protected void validateRequest(FeaturePayload request) { private boolean validate(Object value) { if (value instanceof Boolean) { final var boolValue = Boolean.parseBoolean(value.toString()); - return Boolean.FALSE.equals(boolValue); + return !boolValue; } if (value instanceof Integer) { diff --git a/src/main/java/com/github/switcherapi/ac/service/validator/AbstractValidatorService.java b/src/main/java/com/github/switcherapi/ac/service/validator/AbstractValidatorService.java index 830bb0c..2581e0b 100644 --- a/src/main/java/com/github/switcherapi/ac/service/validator/AbstractValidatorService.java +++ b/src/main/java/com/github/switcherapi/ac/service/validator/AbstractValidatorService.java @@ -4,6 +4,7 @@ import com.github.switcherapi.ac.model.domain.FeaturePayload; import com.github.switcherapi.ac.model.dto.ResponseRelayDTO; import com.github.switcherapi.ac.repository.AccountDao; +import com.github.switcherapi.ac.repository.PlanDao; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; @@ -18,10 +19,13 @@ public abstract class AbstractValidatorService { protected final AccountDao accountDao; + protected final PlanDao planDao; + protected Map params; - protected AbstractValidatorService(AccountDao accountDao) { + protected AbstractValidatorService(AccountDao accountDao, PlanDao planDao) { this.accountDao = accountDao; + this.planDao = planDao; } /** diff --git a/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorBuilderService.java b/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorBuilderService.java index 5170dd5..814a670 100644 --- a/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorBuilderService.java +++ b/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorBuilderService.java @@ -3,6 +3,7 @@ import com.github.switcherapi.ac.model.domain.FeaturePayload; import com.github.switcherapi.ac.model.dto.ResponseRelayDTO; import com.github.switcherapi.ac.repository.AccountDao; +import com.github.switcherapi.ac.repository.PlanDao; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; @@ -15,8 +16,11 @@ public abstract class ValidatorBuilderService { protected final AccountDao accountDao; - protected ValidatorBuilderService(AccountDao accountDao) { + protected final PlanDao planDao; + + protected ValidatorBuilderService(AccountDao accountDao, PlanDao planDao) { this.accountDao = accountDao; + this.planDao = planDao; } public ResponseRelayDTO runValidator(FeaturePayload request) { diff --git a/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorNativeBuilder.java b/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorNativeBuilder.java index 2dac634..034ccdf 100644 --- a/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorNativeBuilder.java +++ b/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorNativeBuilder.java @@ -1,6 +1,7 @@ package com.github.switcherapi.ac.service.validator; import com.github.switcherapi.ac.repository.AccountDao; +import com.github.switcherapi.ac.repository.PlanDao; import com.github.switcherapi.ac.service.validator.beans.ValidateRateLimit; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -13,14 +14,14 @@ @ConditionalOnProperty(value = "service.validators.native", havingValue = "true") public class ValidatorNativeBuilder extends ValidatorBuilderService { - public ValidatorNativeBuilder(AccountDao accountDao) { - super(accountDao); + public ValidatorNativeBuilder(AccountDao accountDao, PlanDao planDao) { + super(accountDao, planDao); this.initializeValidators(); } @Override protected void initializeValidators() { - validatorHandlers.put(RATE_LIMIT_VALIDATOR, new ValidateRateLimit(accountDao)); + validatorHandlers.put(RATE_LIMIT_VALIDATOR, new ValidateRateLimit(accountDao, planDao)); } } diff --git a/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorRuntimeBuilder.java b/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorRuntimeBuilder.java index 50d168e..6bfa554 100644 --- a/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorRuntimeBuilder.java +++ b/src/main/java/com/github/switcherapi/ac/service/validator/ValidatorRuntimeBuilder.java @@ -1,6 +1,7 @@ package com.github.switcherapi.ac.service.validator; import com.github.switcherapi.ac.repository.AccountDao; +import com.github.switcherapi.ac.repository.PlanDao; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -20,8 +21,8 @@ public class ValidatorRuntimeBuilder extends ValidatorBuilderService { private final AutowireCapableBeanFactory autowireCapableBeanFactory; - public ValidatorRuntimeBuilder(AutowireCapableBeanFactory autowireCapableBeanFactory, AccountDao accountDao) { - super(accountDao); + public ValidatorRuntimeBuilder(AutowireCapableBeanFactory autowireCapableBeanFactory, AccountDao accountDao, PlanDao planDao) { + super(accountDao, planDao); this.autowireCapableBeanFactory = autowireCapableBeanFactory; this.initializeValidators(); } @@ -45,7 +46,9 @@ private void cacheValidator(String controllerClassName) { if (Objects.nonNull(validatorAnnotation)) { var sValidator = validatorClass.getAnnotation(SwitcherValidator.class); - var validatorService = (AbstractValidatorService) validatorClass.getConstructor(AccountDao.class).newInstance(this.accountDao); + var validatorService = (AbstractValidatorService) validatorClass + .getConstructor(AccountDao.class, PlanDao.class) + .newInstance(this.accountDao, this.planDao); autowireCapableBeanFactory.autowireBean(validatorService); validatorHandlers.put(sValidator.value(), validatorService); diff --git a/src/main/java/com/github/switcherapi/ac/service/validator/beans/AbstractActiveCheckValidator.java b/src/main/java/com/github/switcherapi/ac/service/validator/beans/AbstractActiveCheckValidator.java index c40d0a2..298d83e 100644 --- a/src/main/java/com/github/switcherapi/ac/service/validator/beans/AbstractActiveCheckValidator.java +++ b/src/main/java/com/github/switcherapi/ac/service/validator/beans/AbstractActiveCheckValidator.java @@ -3,6 +3,7 @@ import static com.github.switcherapi.ac.service.validator.SwitcherValidatorParams.ADMINID; import com.github.switcherapi.ac.repository.AccountDao; +import com.github.switcherapi.ac.repository.PlanDao; import org.springframework.http.HttpStatus; import org.springframework.util.Assert; import org.springframework.web.server.ResponseStatusException; @@ -14,8 +15,8 @@ public abstract class AbstractActiveCheckValidator extends AbstractValidatorService { - protected AbstractActiveCheckValidator(AccountDao accountDao) { - super(accountDao); + protected AbstractActiveCheckValidator(AccountDao accountDao, PlanDao planDao) { + super(accountDao, planDao); } @Override diff --git a/src/main/java/com/github/switcherapi/ac/service/validator/beans/ValidateRateLimit.java b/src/main/java/com/github/switcherapi/ac/service/validator/beans/ValidateRateLimit.java index 0e62919..f071be1 100644 --- a/src/main/java/com/github/switcherapi/ac/service/validator/beans/ValidateRateLimit.java +++ b/src/main/java/com/github/switcherapi/ac/service/validator/beans/ValidateRateLimit.java @@ -2,9 +2,11 @@ import com.github.switcherapi.ac.model.domain.Account; import com.github.switcherapi.ac.model.domain.Feature; +import com.github.switcherapi.ac.model.domain.Plan; import com.github.switcherapi.ac.model.dto.Metadata; import com.github.switcherapi.ac.model.dto.ResponseRelayDTO; import com.github.switcherapi.ac.repository.AccountDao; +import com.github.switcherapi.ac.repository.PlanDao; import com.github.switcherapi.ac.service.validator.SwitcherValidator; @SwitcherValidator(ValidateRateLimit.RATE_LIMIT_VALIDATOR) @@ -12,13 +14,13 @@ public class ValidateRateLimit extends AbstractActiveCheckValidator { public static final String RATE_LIMIT_VALIDATOR = "rate_limit"; - public ValidateRateLimit(AccountDao accountDao) { - super(accountDao); + public ValidateRateLimit(AccountDao accountDao, PlanDao planDao) { + super(accountDao, planDao); } @Override protected ResponseRelayDTO executeValidator(final Account account) { - final var plan = account.getPlan(); + final var plan = planDao.getPlanRepository().findById(account.getPlan()).orElse(Plan.loadDefault()); final var max = Integer.parseInt(plan.getFeature(Feature.RATE_LIMIT).getValue().toString()); return ResponseRelayDTO.success(Metadata.builder().rateLimit(max).build()); diff --git a/src/test/java/com/github/switcherapi/ac/PlanUtilsTests.java b/src/test/java/com/github/switcherapi/ac/PlanUtilsTests.java index 8c03787..09f3722 100644 --- a/src/test/java/com/github/switcherapi/ac/PlanUtilsTests.java +++ b/src/test/java/com/github/switcherapi/ac/PlanUtilsTests.java @@ -6,6 +6,8 @@ import com.github.switcherapi.ac.model.dto.PlanDTO; import com.github.switcherapi.ac.model.mapper.PlanMapper; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import java.util.Arrays; import java.util.List; @@ -13,6 +15,7 @@ import static com.github.switcherapi.ac.model.domain.Feature.*; import static org.assertj.core.api.Assertions.assertThat; +@Execution(ExecutionMode.CONCURRENT) class PlanUtilsTests { @Test diff --git a/src/test/java/com/github/switcherapi/ac/controller/AdminAccountControllerTests.java b/src/test/java/com/github/switcherapi/ac/controller/AdminAccountControllerTests.java index 74a0c8e..de905fa 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/AdminAccountControllerTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/AdminAccountControllerTests.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -28,9 +30,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest @AutoConfigureDataMongo @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class AdminAccountControllerTests { @Autowired AdminService adminService; @@ -72,7 +75,8 @@ void testServices() { void shouldChangeAccountPlan() throws Exception { //validate before var account = accountService.getAccountByAdminId(ADMIN_ID); - assertThat(account.getPlan().getName()).isEqualTo(PlanType.DEFAULT.name()); + var planDefault = planService.getPlanByName(PlanType.DEFAULT.name()); + assertThat(account.getPlan()).isEqualTo(planDefault.getId()); //test var json = this.mockMvc.perform(patch("/admin/v1/account/change/{adminId}", ADMIN_ID) @@ -87,18 +91,20 @@ void shouldChangeAccountPlan() throws Exception { var accountDto = new ObjectMapper().readValue(json, AccountDTO.class); assertThat(accountDto.adminId()).isEqualTo(ADMIN_ID); assertThat(accountDto.plan().name()).isEqualTo("BASIC"); - + account = accountService.getAccountByAdminId(ADMIN_ID); - assertThat(account.getPlan().getName()).isEqualTo("BASIC"); + var planBasic = planService.getPlanByName("BASIC"); + assertThat(account.getPlan()).isEqualTo(planBasic.getId()); } @Test void shouldChangeAccountPlan_afterDeletingPlan() throws Exception { //given - var account = accountService.createAccount(ADMIN_ID, "BASIC"); + var accountDto = accountService.createAccount(ADMIN_ID, "BASIC"); //validate before - assertThat(account.getPlan().getName()).isEqualTo("BASIC"); + var planBasic = planService.getPlanByName("BASIC"); + assertThat(accountDto.plan().id()).isEqualTo(planBasic.getId()); //test this.mockMvc.perform(delete("/plan/v2/delete") @@ -109,8 +115,9 @@ void shouldChangeAccountPlan_afterDeletingPlan() throws Exception { .andExpect(status().isOk()) .andExpect(content().string("Plan deleted")); - account = accountService.getAccountByAdminId(ADMIN_ID); - assertThat(account.getPlan().getName()).isEqualTo(PlanType.DEFAULT.name()); + var account = accountService.getAccountByAdminId(ADMIN_ID); + var planDefault = planService.getPlanByName(PlanType.DEFAULT.name()); + assertThat(account.getPlan()).isEqualTo(planDefault.getId()); } @Test diff --git a/src/test/java/com/github/switcherapi/ac/controller/AdminAuthControllerTests.java b/src/test/java/com/github/switcherapi/ac/controller/AdminAuthControllerTests.java index 50a3fc0..be3a18c 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/AdminAuthControllerTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/AdminAuthControllerTests.java @@ -9,6 +9,8 @@ import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -30,18 +32,20 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @AutoConfigureDataMongo @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class AdminAuthControllerTests { @Autowired AdminRepository adminRepository; @Autowired AdminService adminService; @Autowired JwtTokenService jwtService; @Autowired MockMvc mockMvc; - + + private static final String GITHUB_ID = String.format("mock_github_id_%s", System.currentTimeMillis()); private Pair tokens; @BeforeEach void setup() { - final var admin = adminService.createAdminAccount("123456"); + final var admin = adminService.createAdminAccount(GITHUB_ID); tokens = jwtService.generateToken(admin.getId()); adminService.updateAdminAccountToken(admin, tokens.getLeft()); } @@ -61,7 +65,7 @@ void shouldRefreshToken() throws Exception { .andReturn().getResponse().getContentAsString(); var authDto = new ObjectMapper().readValue(json, GitHubAuthDTO.class); - assertThat(authDto.admin().gitHubId()).isEqualTo("123456"); + assertThat(authDto.admin().gitHubId()).isEqualTo(GITHUB_ID); assertThat(authDto.token()).isNotEqualTo(tokens.getLeft()); assertThat(authDto.refreshToken()).isNotEqualTo(tokens.getRight()); } @@ -88,6 +92,7 @@ void shouldNotRefreshToken_missingToken() throws Exception { } @SwitcherTest(key = "SWITCHER_AC_ADM", result = false) + @Execution(ExecutionMode.SAME_THREAD) void shouldNotRefreshToken_accountUnauthorized() throws Exception { var count = new CountDownLatch(1); assertFalse(count.await(1, TimeUnit.SECONDS)); @@ -121,7 +126,7 @@ void shouldLogout() throws Exception { .andDo(print()) .andExpect(status().isOk()); - var admin = adminRepository.findByGitHubId("123456"); + var admin = adminRepository.findByGitHubId(GITHUB_ID); assertThat(admin.getToken()).isNull(); } diff --git a/src/test/java/com/github/switcherapi/ac/controller/AdminGitHubAuthControllerTests.java b/src/test/java/com/github/switcherapi/ac/controller/AdminGitHubAuthControllerTests.java index 57e8054..7c15469 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/AdminGitHubAuthControllerTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/AdminGitHubAuthControllerTests.java @@ -13,6 +13,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; @@ -33,9 +35,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest @AutoConfigureDataMongo @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class AdminGitHubAuthControllerTests { @Autowired MockMvc mockMvc; @@ -71,6 +74,7 @@ void testSwitchers() { } @SwitcherTest(key = SwitcherFeatures.SWITCHER_AC_ADM) + @Execution(ExecutionMode.SAME_THREAD) void shouldLoginWithGitHub() throws Exception { //given givenGitHubToken(); @@ -93,6 +97,7 @@ void shouldLoginWithGitHub() throws Exception { } @SwitcherTest(key = SwitcherFeatures.SWITCHER_AC_ADM, result = false) + @Execution(ExecutionMode.SAME_THREAD) void shouldNotLoginWithGitHub_accountNotAllowed() throws Exception { //given givenGitHubToken(); @@ -134,6 +139,7 @@ void shouldNotGetGitHubToken_serviceUnavailable() throws Exception { } @SwitcherTest(key = SwitcherFeatures.SWITCHER_AC_ADM, result = false) + @Execution(ExecutionMode.SAME_THREAD) void shouldNotLoginWithGitHub_invalidCode() throws Exception { //given givenResponseInvalidCode(); diff --git a/src/test/java/com/github/switcherapi/ac/controller/AdminPlanControllerErrorTests.java b/src/test/java/com/github/switcherapi/ac/controller/AdminPlanControllerErrorTests.java index b6b6aae..7418de2 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/AdminPlanControllerErrorTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/AdminPlanControllerErrorTests.java @@ -5,6 +5,8 @@ import com.google.gson.Gson; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -23,9 +25,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest @AutoConfigureDataMongo @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class AdminPlanControllerErrorTests { @Mock private PlanService mockPlanService; diff --git a/src/test/java/com/github/switcherapi/ac/controller/ApiControllerTests.java b/src/test/java/com/github/switcherapi/ac/controller/ApiControllerTests.java index a4e10a5..15ad092 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/ApiControllerTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/ApiControllerTests.java @@ -7,6 +7,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -14,6 +16,7 @@ @SpringBootTest @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class ApiControllerTests { @Autowired MockMvc mockMvc; diff --git a/src/test/java/com/github/switcherapi/ac/controller/ApiResourcesTests.java b/src/test/java/com/github/switcherapi/ac/controller/ApiResourcesTests.java index 1473bf9..32f94e5 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/ApiResourcesTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/ApiResourcesTests.java @@ -6,6 +6,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -21,6 +23,7 @@ @SpringBootTest @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class ApiResourcesTests { @Autowired AdminService adminService; diff --git a/src/test/java/com/github/switcherapi/ac/controller/PlanControllerTests.java b/src/test/java/com/github/switcherapi/ac/controller/PlanControllerTests.java index 1041c0d..0f061a0 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/PlanControllerTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/PlanControllerTests.java @@ -10,6 +10,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -29,9 +31,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest @AutoConfigureDataMongo @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class PlanControllerTests extends ControllerTestUtils { @Autowired AdminService adminService; diff --git a/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayCacheLimiterControllerTests.java b/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayCacheLimiterControllerTests.java index 68d4268..5fb0eea 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayCacheLimiterControllerTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayCacheLimiterControllerTests.java @@ -8,6 +8,8 @@ import com.github.switcherapi.ac.service.PlanService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -21,6 +23,7 @@ @SpringBootTest @AutoConfigureDataMongo @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) @TestPropertySource(properties = { "service.cache.enabled=true", "service.cache.duration=1" diff --git a/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerErrorTests.java b/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerErrorTests.java index 1de9606..10be7e0 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerErrorTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerErrorTests.java @@ -25,7 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureDataMongo @AutoConfigureMockMvc class SwitcherRelayControllerErrorTests { diff --git a/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerTests.java b/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerTests.java index 56e7cd8..de5b3af 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerTests.java +++ b/src/test/java/com/github/switcherapi/ac/controller/SwitcherRelayControllerTests.java @@ -9,6 +9,8 @@ import com.github.switcherapi.ac.service.PlanService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -27,9 +29,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest @AutoConfigureDataMongo @AutoConfigureMockMvc +@Execution(ExecutionMode.CONCURRENT) class SwitcherRelayControllerTests extends ControllerTestUtils { @Autowired AccountService accountService; @@ -152,6 +155,19 @@ void shouldBeOkWhenValidate_unlimitedUseFeature() throws Exception { 10000, expectedResponse, 200); } + @Test + void shouldNotBeOkWhenValidate_payloadMalformed() throws Exception { + //given + givenAccount("masteradminid"); + + var plan = Plan.loadDefault(); + planService.createPlan(plan); + + //test + var expectedResponse = ResponseRelayDTO.fail("com.google.gson.stream.MalformedJsonException"); + this.assertValidate500(SWITCHER.getValue(), expectedResponse); + } + @Test void shouldReturnTrue() throws Exception { //given diff --git a/src/test/java/com/github/switcherapi/ac/controller/fixture/ControllerTestUtils.java b/src/test/java/com/github/switcherapi/ac/controller/fixture/ControllerTestUtils.java index f27c0ea..ad071ab 100644 --- a/src/test/java/com/github/switcherapi/ac/controller/fixture/ControllerTestUtils.java +++ b/src/test/java/com/github/switcherapi/ac/controller/fixture/ControllerTestUtils.java @@ -3,8 +3,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.switcherapi.ac.model.domain.FeaturePayload; -import com.github.switcherapi.ac.model.domain.PlanType; import com.github.switcherapi.ac.model.domain.Plan; +import com.github.switcherapi.ac.model.domain.PlanType; import com.github.switcherapi.ac.model.dto.PlanDTO; import com.github.switcherapi.ac.model.dto.RequestRelayDTO; import com.github.switcherapi.ac.model.dto.ResponseRelayDTO; @@ -17,6 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.AssertionsKt.assertNotNull; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -43,14 +45,21 @@ protected void assertValidate(String adminId, String featureName, var request = new RequestRelayDTO(null, gson.toJson(feature)); //test - this.mockMvc.perform(post("/switcher/v1/validate") - .contentType(MediaType.APPLICATION_JSON) - .header(HttpHeaders.AUTHORIZATION, "Bearer relay_token") - .with(csrf()) - .content(gson.toJson(request))) - .andDo(print()) - .andExpect(status().is(expectedStatus)) - .andExpect(content().string(containsString(gson.toJson(expectedResponse)))); + performValidatePost(expectedResponse, expectedStatus, request); + } + + protected void assertValidate500(String featureName, ResponseRelayDTO expectedResponse) throws Exception { + //given + var feature = FeaturePayload.builder() + .feature(featureName) + .owner("masteradminid") + .total(10000) + .build(); + + var request = new RequestRelayDTO(null, gson.toJson(feature) + "}"); + + //test + performValidatePost(expectedResponse, 500, request); } protected void assertLimiter(String value, ResponseRelayDTO expectedResponse, @@ -84,4 +93,21 @@ protected void assertDtoResponse(Plan planObj, String response) assertThat(planDto.name()).isEqualTo(planObj.getName()); } + private void performValidatePost(ResponseRelayDTO expectedResponse, int expectedStatus, RequestRelayDTO request) throws Exception { + var response = this.mockMvc.perform(post("/switcher/v1/validate") + .contentType(MediaType.APPLICATION_JSON) + .header(HttpHeaders.AUTHORIZATION, "Bearer relay_token") + .with(csrf()) + .content(gson.toJson(request))) + .andDo(print()) + .andExpect(status().is(expectedStatus)) + .andReturn(); + + assertNotNull(response.getResponse()); + + var responseObject = gson.fromJson(response.getResponse().getContentAsString(), ResponseRelayDTO.class); + assertEquals(expectedResponse.result(), responseObject.result()); + assertThat(String.valueOf(responseObject.message())).contains(String.valueOf(expectedResponse.message())); + } + } diff --git a/src/test/java/com/github/switcherapi/ac/service/AccountServiceTest.java b/src/test/java/com/github/switcherapi/ac/service/AccountServiceTest.java index c94fbab..a687e51 100644 --- a/src/test/java/com/github/switcherapi/ac/service/AccountServiceTest.java +++ b/src/test/java/com/github/switcherapi/ac/service/AccountServiceTest.java @@ -4,6 +4,8 @@ import com.github.switcherapi.ac.model.domain.PlanType; import com.github.switcherapi.ac.model.domain.Plan; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.web.server.ResponseStatusException; @@ -16,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @SpringBootTest +@Execution(ExecutionMode.CONCURRENT) class AccountServiceTest { @Autowired AccountService accountService; @@ -28,12 +31,14 @@ void shouldUpdateAccount() { givenPlan(); var account = accountService.getAccountByAdminId("adminid"); - assertEquals(PlanType.DEFAULT.toString(), account.getPlan().getName()); + var planDefault = planService.getPlanByName(PlanType.DEFAULT.toString()); + assertEquals(account.getPlan(), planDefault.getId()); //test accountService.updateAccountPlan("adminid", "PLAN_2"); + var planTwo = planService.getPlanByName("PLAN_2"); account = accountService.getAccountByAdminId("adminid"); - assertEquals("PLAN_2", account.getPlan().getName()); + assertEquals(account.getPlan(), planTwo.getId()); } @Test diff --git a/src/test/java/com/github/switcherapi/ac/service/GitHubServiceTest.java b/src/test/java/com/github/switcherapi/ac/service/GitHubServiceTest.java index 8114c83..f10516a 100644 --- a/src/test/java/com/github/switcherapi/ac/service/GitHubServiceTest.java +++ b/src/test/java/com/github/switcherapi/ac/service/GitHubServiceTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.http.MediaType; import org.springframework.web.server.ResponseStatusException; @@ -21,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @Slf4j +@Execution(ExecutionMode.CONCURRENT) public class GitHubServiceTest { private final ObjectMapper mapper = new ObjectMapper(); diff --git a/src/test/java/com/github/switcherapi/ac/service/ValidatorBasicServiceTest.java b/src/test/java/com/github/switcherapi/ac/service/ValidatorBasicServiceTest.java index da7e63b..81e3fb0 100644 --- a/src/test/java/com/github/switcherapi/ac/service/ValidatorBasicServiceTest.java +++ b/src/test/java/com/github/switcherapi/ac/service/ValidatorBasicServiceTest.java @@ -5,6 +5,8 @@ import com.github.switcherapi.ac.model.domain.Plan; import com.github.switcherapi.ac.model.domain.PlanAttribute; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -21,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.*; @SpringBootTest +@Execution(ExecutionMode.CONCURRENT) class ValidatorBasicServiceTest { @Autowired diff --git a/src/test/java/com/github/switcherapi/ac/service/ValidatorNativeBuilderServiceTest.java b/src/test/java/com/github/switcherapi/ac/service/ValidatorNativeBuilderServiceTest.java index 7776d3b..75efdf0 100644 --- a/src/test/java/com/github/switcherapi/ac/service/ValidatorNativeBuilderServiceTest.java +++ b/src/test/java/com/github/switcherapi/ac/service/ValidatorNativeBuilderServiceTest.java @@ -3,6 +3,8 @@ import com.github.switcherapi.ac.model.domain.FeaturePayload; import com.github.switcherapi.ac.service.validator.ValidatorBuilderService; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.web.server.ResponseStatusException; @@ -12,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @SpringBootTest(properties = {"service.validators.native=true"}) +@Execution(ExecutionMode.CONCURRENT) class ValidatorNativeBuilderServiceTest { @Autowired diff --git a/src/test/java/com/github/switcherapi/ac/service/ValidatorRuntimeBuilderServiceTest.java b/src/test/java/com/github/switcherapi/ac/service/ValidatorRuntimeBuilderServiceTest.java index ed74f5d..cd587e6 100644 --- a/src/test/java/com/github/switcherapi/ac/service/ValidatorRuntimeBuilderServiceTest.java +++ b/src/test/java/com/github/switcherapi/ac/service/ValidatorRuntimeBuilderServiceTest.java @@ -3,6 +3,8 @@ import com.github.switcherapi.ac.model.domain.FeaturePayload; import com.github.switcherapi.ac.service.validator.ValidatorBuilderService; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.web.server.ResponseStatusException; @@ -12,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @SpringBootTest(properties = {"service.validators.native=false"}) +@Execution(ExecutionMode.CONCURRENT) class ValidatorRuntimeBuilderServiceTest { @Autowired diff --git a/src/test/java/com/github/switcherapi/ac/util/FileUtilTest.java b/src/test/java/com/github/switcherapi/ac/util/FileUtilTest.java index 293d706..feedf8e 100644 --- a/src/test/java/com/github/switcherapi/ac/util/FileUtilTest.java +++ b/src/test/java/com/github/switcherapi/ac/util/FileUtilTest.java @@ -2,10 +2,13 @@ import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +@Execution(ExecutionMode.CONCURRENT) class FileUtilTest { @Test diff --git a/src/test/java/com/github/switcherapi/ac/util/SanitizerTest.java b/src/test/java/com/github/switcherapi/ac/util/SanitizerTest.java index 0fb1345..395d8f9 100644 --- a/src/test/java/com/github/switcherapi/ac/util/SanitizerTest.java +++ b/src/test/java/com/github/switcherapi/ac/util/SanitizerTest.java @@ -2,12 +2,15 @@ import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import java.util.List; import static com.github.switcherapi.ac.util.Sanitizer.*; import static org.junit.jupiter.api.Assertions.assertEquals; +@Execution(ExecutionMode.CONCURRENT) class SanitizerTest { @Test diff --git a/src/test/java/metainf/nativeimage/NativeReflectConfigTest.java b/src/test/java/metainf/nativeimage/NativeReflectConfigTest.java index a84bf79..ed2b21f 100644 --- a/src/test/java/metainf/nativeimage/NativeReflectConfigTest.java +++ b/src/test/java/metainf/nativeimage/NativeReflectConfigTest.java @@ -3,6 +3,8 @@ import com.google.gson.Gson; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import java.nio.file.Files; import java.nio.file.Path; @@ -11,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertTrue; +@Execution(ExecutionMode.CONCURRENT) class NativeReflectConfigTest { private static final Path reflectPath = Path.of("src/main/resources/META-INF/native-image/reflect-config.json"); diff --git a/src/test/resources/junit-platform.properties b/src/test/resources/junit-platform.properties new file mode 100644 index 0000000..a29b29b --- /dev/null +++ b/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +junit.jupiter.execution.parallel.enabled=true +junit.jupiter.execution.parallel.config.strategy=fixed +junit.jupiter.execution.parallel.config.fixed.parallelism=1 \ No newline at end of file From 49a6571f83f35b7b3a18ca03f0efe2f71a009116 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Mon, 2 Jun 2025 22:21:50 -0700 Subject: [PATCH 2/2] ci: updated master workflow for v1 --- .github/workflows/master.yml | 74 ++---------------------------------- 1 file changed, 4 insertions(+), 70 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 8d3aaf4..db95244 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -1,10 +1,10 @@ -name: Master CI +name: Master v1 CI on: push: - branches: [ master ] + branches: [ master-1 ] pull_request: - branches: [ master ] + branches: [ master-1 ] jobs: build-test: @@ -28,70 +28,4 @@ jobs: - name: Build/Test & SonarCloud Scan run: mvn -B clean verify -Pcoverage,sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - docker: - name: Publish Docker Image - needs: [ build-test ] - runs-on: ubuntu-latest - if: success() && github.ref == 'refs/heads/master' - - outputs: - digest: ${{ steps.docker_build.outputs.digest }} - - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v6 - with: - push: true -# file: ./Dockerfile.native - platforms: linux/amd64,linux/arm64 - tags: ${{ secrets.DOCKERHUB_USERNAME }}/switcher-ac:latest - - update-kustomize: - name: Deploy - needs: [ docker ] - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: 'master' - - - name: Checkout Kustomize - uses: actions/checkout@v4 - with: - token: ${{ secrets.ARGOCD_PAT }} - repository: switcherapi/switcher-deployment - ref: master - - - name: Set up arkade-get - uses: alexellis/arkade-get@master - with: - kubectl: latest - kustomize: latest - - - name: Update GitOps repository - run: | - cd switcher-ac/base - echo RELEASE_TIME=`date` > environment-properties.env - kustomize edit set image trackerforce/switcher-ac:latest=trackerforce/switcher-ac@${{ needs.docker.outputs.digest }} - git config --global user.email "${{ github.actor }}@users.noreply.github.com" - git config --global user.name "${{ github.actor }}" - git add . - git commit -m "[argocd] switcher-ac: ${{ needs.docker.outputs.digest }}" - git push \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file