diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d9e33990cc..4b77b566579 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Sep 21 13:03:28 CEST 2014 +#Sun Sep 21 13:09:15 CEST 2014 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip diff --git a/ontrack-it-utils/src/main/java/net/nemerosa/ontrack/it/AbstractITTestSupport.java b/ontrack-it-utils/src/main/java/net/nemerosa/ontrack/it/AbstractITTestSupport.java index 3e67cab67a6..5f0884aaca3 100644 --- a/ontrack-it-utils/src/main/java/net/nemerosa/ontrack/it/AbstractITTestSupport.java +++ b/ontrack-it-utils/src/main/java/net/nemerosa/ontrack/it/AbstractITTestSupport.java @@ -1,17 +1,11 @@ package net.nemerosa.ontrack.it; import net.nemerosa.ontrack.common.RunProfile; -import net.nemerosa.ontrack.model.security.*; -import net.nemerosa.ontrack.model.structure.*; +import net.nemerosa.ontrack.model.structure.NameDescription; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import org.springframework.security.authentication.TestingAuthenticationToken; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.context.SecurityContextImpl; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; @@ -19,10 +13,6 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; -import java.util.Optional; -import java.util.concurrent.Callable; - import static net.nemerosa.ontrack.test.TestUtils.uid; @RunWith(SpringJUnit4ClassRunner.class) @@ -33,12 +23,6 @@ @ActiveProfiles(profiles = {RunProfile.UNIT_TEST}) public abstract class AbstractITTestSupport extends AbstractJUnit4SpringContextTests { - @Autowired - protected AccountService accountService; - - @Autowired - protected StructureService structureService; - @Configuration @Profile(RunProfile.UNIT_TEST) @ComponentScan("net.nemerosa.ontrack") @@ -53,133 +37,4 @@ public static NameDescription nameDescription() { ); } - protected Account doCreateAccount() throws Exception { - return asUser().with(AccountManagement.class).call(() -> { - String name = uid("A"); - return accountService.create( - new AccountInput( - name, - "Test " + name, - name + "@test.com", - "test", - Collections.emptyList() - ) - ); - }); - } - - protected Project doCreateProject() throws Exception { - return doCreateProject(nameDescription()); - } - - protected Project doCreateProject(NameDescription nameDescription) throws Exception { - return asUser().with(ProjectCreation.class).call(() -> structureService.newProject( - Project.of(nameDescription) - )); - } - - protected Branch doCreateBranch() throws Exception { - return doCreateBranch(doCreateProject(), nameDescription()); - } - - protected Branch doCreateBranch(Project project, NameDescription nameDescription) throws Exception { - return asUser().with(project.id(), BranchCreate.class).call(() -> structureService.newBranch( - Branch.of(project, nameDescription) - )); - } - - protected UserCall asUser() { - return new UserCall(); - } - - protected AccountCall asAccount(Account account) { - return new AccountCall(account); - } - - protected T view(ProjectEntity projectEntity, Callable callable) throws Exception { - return asUser().with(projectEntity.projectId(), ProjectView.class).call(callable); - } - - protected static interface ContextCall { - T call(Callable call) throws Exception; - } - - protected static abstract class AbstractContextCall implements ContextCall { - - @Override - public T call(Callable call) throws Exception { - // Gets the current context - SecurityContext oldContext = SecurityContextHolder.getContext(); - try { - // Sets the new context - contextSetup(); - // Call - return call.call(); - } finally { - // Restores the context - SecurityContextHolder.setContext(oldContext); - } - } - - protected abstract void contextSetup(); - } - - protected static class AccountCall extends AbstractContextCall { - - protected final Account account; - - public AccountCall(Account account) { - this.account = account; - } - - public AccountCall(String name, SecurityRole role) { - this(Account.of(name, name, name + "@test.com", role, AuthenticationSource.none())); - } - - @Override - protected void contextSetup() { - SecurityContext context = new SecurityContextImpl(); - TestingAuthenticationToken authentication = new TestingAuthenticationToken( - (AccountHolder) () -> account, - "", - account.getRole().name() - ); - context.setAuthentication(authentication); - SecurityContextHolder.setContext(context); - } - } - - protected static class UserCall extends AccountCall { - - public UserCall() { - super("user", SecurityRole.USER); - } - - public UserCall with(Class fn) { - account.withGlobalRole( - Optional.of( - new GlobalRole( - "test", "Test global role", "", - Collections.singleton(fn), - Collections.emptySet() - ) - ) - ); - return this; - } - - public UserCall with(int projectId, Class fn) { - account.withProjectRole( - new ProjectRoleAssociation( - projectId, - new ProjectRole( - "test", "Test", "", - Collections.singleton(fn) - ) - ) - ); - return this; - } - - } } diff --git a/ontrack-it-utils/src/main/java/net/nemerosa/ontrack/it/AbstractServiceTestSupport.java b/ontrack-it-utils/src/main/java/net/nemerosa/ontrack/it/AbstractServiceTestSupport.java new file mode 100644 index 00000000000..8faebbca6df --- /dev/null +++ b/ontrack-it-utils/src/main/java/net/nemerosa/ontrack/it/AbstractServiceTestSupport.java @@ -0,0 +1,154 @@ +package net.nemerosa.ontrack.it; + +import net.nemerosa.ontrack.model.security.*; +import net.nemerosa.ontrack.model.structure.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.TestingAuthenticationToken; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.context.SecurityContextImpl; + +import java.util.Collections; +import java.util.Optional; +import java.util.concurrent.Callable; + +import static net.nemerosa.ontrack.test.TestUtils.uid; + +public abstract class AbstractServiceTestSupport extends AbstractITTestSupport { + + @Autowired + protected AccountService accountService; + + @Autowired + protected StructureService structureService; + + protected Account doCreateAccount() throws Exception { + return asUser().with(AccountManagement.class).call(() -> { + String name = uid("A"); + return accountService.create( + new AccountInput( + name, + "Test " + name, + name + "@test.com", + "test", + Collections.emptyList() + ) + ); + }); + } + + protected Project doCreateProject() throws Exception { + return doCreateProject(nameDescription()); + } + + protected Project doCreateProject(NameDescription nameDescription) throws Exception { + return asUser().with(ProjectCreation.class).call(() -> structureService.newProject( + Project.of(nameDescription) + )); + } + + protected Branch doCreateBranch() throws Exception { + return doCreateBranch(doCreateProject(), nameDescription()); + } + + protected Branch doCreateBranch(Project project, NameDescription nameDescription) throws Exception { + return asUser().with(project.id(), BranchCreate.class).call(() -> structureService.newBranch( + Branch.of(project, nameDescription) + )); + } + + protected UserCall asUser() { + return new UserCall(); + } + + protected AccountCall asAccount(Account account) { + return new AccountCall(account); + } + + protected T view(ProjectEntity projectEntity, Callable callable) throws Exception { + return asUser().with(projectEntity.projectId(), ProjectView.class).call(callable); + } + + protected static interface ContextCall { + T call(Callable call) throws Exception; + } + + protected static abstract class AbstractContextCall implements ContextCall { + + @Override + public T call(Callable call) throws Exception { + // Gets the current context + SecurityContext oldContext = SecurityContextHolder.getContext(); + try { + // Sets the new context + contextSetup(); + // Call + return call.call(); + } finally { + // Restores the context + SecurityContextHolder.setContext(oldContext); + } + } + + protected abstract void contextSetup(); + } + + protected static class AccountCall extends AbstractContextCall { + + protected final Account account; + + public AccountCall(Account account) { + this.account = account; + } + + public AccountCall(String name, SecurityRole role) { + this(Account.of(name, name, name + "@test.com", role, AuthenticationSource.none())); + } + + @Override + protected void contextSetup() { + SecurityContext context = new SecurityContextImpl(); + TestingAuthenticationToken authentication = new TestingAuthenticationToken( + (AccountHolder) () -> account, + "", + account.getRole().name() + ); + context.setAuthentication(authentication); + SecurityContextHolder.setContext(context); + } + } + + protected static class UserCall extends AccountCall { + + public UserCall() { + super("user", SecurityRole.USER); + } + + public UserCall with(Class fn) { + account.withGlobalRole( + Optional.of( + new GlobalRole( + "test", "Test global role", "", + Collections.singleton(fn), + Collections.emptySet() + ) + ) + ); + return this; + } + + public UserCall with(int projectId, Class fn) { + account.withProjectRole( + new ProjectRoleAssociation( + projectId, + new ProjectRole( + "test", "Test", "", + Collections.singleton(fn) + ) + ) + ); + return this; + } + + } +} diff --git a/ontrack-repository-impl/src/test/java/net/nemerosa/ontrack/repository/AbstractRepositoryTestSupport.java b/ontrack-repository-impl/src/test/java/net/nemerosa/ontrack/repository/AbstractRepositoryTestSupport.java new file mode 100644 index 00000000000..73038e1061e --- /dev/null +++ b/ontrack-repository-impl/src/test/java/net/nemerosa/ontrack/repository/AbstractRepositoryTestSupport.java @@ -0,0 +1,7 @@ +package net.nemerosa.ontrack.repository; + +import net.nemerosa.ontrack.it.AbstractITTestSupport; + +public abstract class AbstractRepositoryTestSupport extends AbstractITTestSupport { + +} diff --git a/ontrack-repository-impl/src/test/java/net/nemerosa/ontrack/repository/StructureJdbcRepositoryIT.java b/ontrack-repository-impl/src/test/java/net/nemerosa/ontrack/repository/StructureJdbcRepositoryIT.java index 1dd2525c402..c03ac1a10e8 100644 --- a/ontrack-repository-impl/src/test/java/net/nemerosa/ontrack/repository/StructureJdbcRepositoryIT.java +++ b/ontrack-repository-impl/src/test/java/net/nemerosa/ontrack/repository/StructureJdbcRepositoryIT.java @@ -1,6 +1,5 @@ package net.nemerosa.ontrack.repository; -import net.nemerosa.ontrack.it.AbstractITTestSupport; import net.nemerosa.ontrack.model.structure.Branch; import net.nemerosa.ontrack.model.structure.ID; import net.nemerosa.ontrack.model.structure.Project; @@ -10,7 +9,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -public class StructureJdbcRepositoryIT extends AbstractITTestSupport { +public class StructureJdbcRepositoryIT extends AbstractRepositoryTestSupport { @Autowired private StructureRepository repository; diff --git a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/BuildFilterServiceIT.java b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/BuildFilterServiceIT.java index 883355ccb4f..7371bec0232 100644 --- a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/BuildFilterServiceIT.java +++ b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/BuildFilterServiceIT.java @@ -1,6 +1,7 @@ package net.nemerosa.ontrack.service; import net.nemerosa.ontrack.it.AbstractITTestSupport; +import net.nemerosa.ontrack.it.AbstractServiceTestSupport; import net.nemerosa.ontrack.json.JsonUtils; import net.nemerosa.ontrack.model.Ack; import net.nemerosa.ontrack.model.buildfilter.BuildFilterResource; @@ -19,7 +20,7 @@ import static org.junit.Assert.*; -public class BuildFilterServiceIT extends AbstractITTestSupport { +public class BuildFilterServiceIT extends AbstractServiceTestSupport { @Autowired private BuildFilterService buildFilterService; diff --git a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/AccountServiceIT.java b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/AccountServiceIT.java index 4e111718566..4b2a2451983 100644 --- a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/AccountServiceIT.java +++ b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/AccountServiceIT.java @@ -1,6 +1,6 @@ package net.nemerosa.ontrack.service.security; -import net.nemerosa.ontrack.it.AbstractITTestSupport; +import net.nemerosa.ontrack.it.AbstractServiceTestSupport; import net.nemerosa.ontrack.model.security.*; import net.nemerosa.ontrack.model.structure.Project; import net.nemerosa.ontrack.model.structure.StructureService; @@ -13,7 +13,7 @@ import static org.junit.Assert.*; -public class AccountServiceIT extends AbstractITTestSupport { +public class AccountServiceIT extends AbstractServiceTestSupport { @Autowired private AccountService accountService; diff --git a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SecurityServiceIT.java b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SecurityServiceIT.java index 04e9356f064..5ae0c4f3362 100644 --- a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SecurityServiceIT.java +++ b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SecurityServiceIT.java @@ -1,6 +1,6 @@ package net.nemerosa.ontrack.service.security; -import net.nemerosa.ontrack.it.AbstractITTestSupport; +import net.nemerosa.ontrack.it.AbstractServiceTestSupport; import net.nemerosa.ontrack.model.security.Account; import net.nemerosa.ontrack.model.security.SecurityService; import org.junit.Test; @@ -9,7 +9,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -public class SecurityServiceIT extends AbstractITTestSupport { +public class SecurityServiceIT extends AbstractServiceTestSupport { @Autowired private SecurityService securityService; diff --git a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SettingsServiceIT.java b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SettingsServiceIT.java index f391ba0611b..fe829af01e1 100644 --- a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SettingsServiceIT.java +++ b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/SettingsServiceIT.java @@ -1,6 +1,6 @@ package net.nemerosa.ontrack.service.security; -import net.nemerosa.ontrack.it.AbstractITTestSupport; +import net.nemerosa.ontrack.it.AbstractServiceTestSupport; import net.nemerosa.ontrack.model.security.GlobalSettings; import net.nemerosa.ontrack.model.settings.SecuritySettings; import net.nemerosa.ontrack.model.settings.SettingsService; @@ -10,7 +10,7 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; -public class SettingsServiceIT extends AbstractITTestSupport { +public class SettingsServiceIT extends AbstractServiceTestSupport { @Autowired private SettingsService settingsService; diff --git a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/StructureServiceIT.java b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/StructureServiceIT.java index 08d7d9b247a..fc5ebc636d7 100644 --- a/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/StructureServiceIT.java +++ b/ontrack-service/src/test/java/net/nemerosa/ontrack/service/security/StructureServiceIT.java @@ -1,6 +1,6 @@ package net.nemerosa.ontrack.service.security; -import net.nemerosa.ontrack.it.AbstractITTestSupport; +import net.nemerosa.ontrack.it.AbstractServiceTestSupport; import net.nemerosa.ontrack.model.exceptions.ImageFileSizeException; import net.nemerosa.ontrack.model.exceptions.ImageTypeNotAcceptedException; import net.nemerosa.ontrack.model.security.*; @@ -14,7 +14,7 @@ import static org.junit.Assert.*; -public class StructureServiceIT extends AbstractITTestSupport { +public class StructureServiceIT extends AbstractServiceTestSupport { @Autowired private StructureService structureService; diff --git a/ontrack-ui/src/test/java/net/nemerosa/ontrack/boot/ui/AbstractWebTestSupport.java b/ontrack-ui/src/test/java/net/nemerosa/ontrack/boot/ui/AbstractWebTestSupport.java index cf568564eaa..f3ed01a4263 100644 --- a/ontrack-ui/src/test/java/net/nemerosa/ontrack/boot/ui/AbstractWebTestSupport.java +++ b/ontrack-ui/src/test/java/net/nemerosa/ontrack/boot/ui/AbstractWebTestSupport.java @@ -1,10 +1,10 @@ package net.nemerosa.ontrack.boot.ui; import net.nemerosa.ontrack.boot.Application; -import net.nemerosa.ontrack.it.AbstractITTestSupport; +import net.nemerosa.ontrack.it.AbstractServiceTestSupport; import org.springframework.boot.test.SpringApplicationConfiguration; @SpringApplicationConfiguration(classes = Application.class) -public abstract class AbstractWebTestSupport extends AbstractITTestSupport { +public abstract class AbstractWebTestSupport extends AbstractServiceTestSupport { }