Sebastian Sdorra avatar Sebastian Sdorra committed a51a6d1

improve repository manager test base

Comments (0)

Files changed (4)

scm-test/src/main/java/sonia/scm/AbstractTestBase.java

   //~--- 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()
   {
     subjectThreadState.bind();
   }
 
-  ;
-
   //~--- fields ---------------------------------------------------------------
 
   /** Field description */

scm-test/src/main/java/sonia/scm/repository/RepositoryManagerTestBase.java

 
 //~--- 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.*;
 
     assertEquals(2, hook.eventsReceived);
   }
 
+  //~--- set methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   */
+  @Before
+  public void setAdminSubject()
+  {
+    Subject admin = MockUtil.createAdminSubject();
+
+    setSubject(admin);
+  }
+
+  //~--- methods --------------------------------------------------------------
+
   /**
    * Method description
    *

scm-test/src/main/java/sonia/scm/util/MockUtil.java

 
 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;
 
 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;
 
     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 ----------------------------------------------------------
 
   /**

scm-webapp/src/test/java/sonia/scm/repository/DefaultRepositoryManagerTest.java

 
 import com.google.inject.Provider;
 
-import org.apache.shiro.subject.Subject;
-
-import org.junit.Before;
 import org.junit.Test;
 
 import sonia.scm.Type;
 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.*;
 
     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 --------------------------------------------------------------
 
   /**
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.