mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
improve repository manager test base
This commit is contained in:
@@ -179,7 +179,8 @@ public class AbstractTestBase
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clears Shiro's thread state, ensuring the thread remains clean for future test execution.
|
||||
* Clears Shiro's thread state, ensuring the thread remains clean for
|
||||
* future test execution.
|
||||
*/
|
||||
protected void clearSubject()
|
||||
{
|
||||
@@ -242,8 +243,6 @@ public class AbstractTestBase
|
||||
subjectThreadState.bind();
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -35,11 +35,15 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.ManagerTestBase;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -354,6 +358,22 @@ public abstract class RepositoryManagerTestBase
|
||||
assertEquals(2, hook.eventsReceived);
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setAdminSubject()
|
||||
{
|
||||
Subject admin = MockUtil.createAdminSubject();
|
||||
|
||||
setSubject(admin);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.google.inject.Provider;
|
||||
|
||||
import org.apache.shiro.authz.Permission;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
@@ -46,6 +47,7 @@ import org.mockito.stubbing.Answer;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserTestData;
|
||||
import sonia.scm.web.security.DummyWebSecurityContext;
|
||||
import sonia.scm.web.security.WebSecurityContext;
|
||||
|
||||
@@ -119,6 +121,24 @@ public class MockUtil
|
||||
return subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Subject createUserSubject()
|
||||
{
|
||||
SimplePrincipalCollection collection = new SimplePrincipalCollection();
|
||||
User user = UserTestData.createTrillian();
|
||||
|
||||
collection.add(user.getName(), "junit");
|
||||
collection.add(user, "junit");
|
||||
|
||||
return new Subject.Builder().principals(collection).authenticated(
|
||||
true).buildSubject();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,9 +37,6 @@ package sonia.scm.repository;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.Type;
|
||||
@@ -48,7 +45,6 @@ import sonia.scm.repository.xml.XmlRepositoryDAO;
|
||||
import sonia.scm.security.DefaultKeyGenerator;
|
||||
import sonia.scm.store.JAXBStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -96,20 +92,6 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
|
||||
assertNull(m.getFromUri("/git/project1/test-3/ka/some/path"));
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setAdminSubject()
|
||||
{
|
||||
Subject admin = MockUtil.createAdminSubject();
|
||||
|
||||
setSubject(admin);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user