summaryrefslogtreecommitdiffstats
path: root/src/test/java/com
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-24 21:28:27 -0500
committerJames Moger <james.moger@gitblit.com>2013-11-29 11:05:51 -0500
commitf8f6aa4d07cdfaaf23e24bf9eaf0a5fb9b437dda (patch)
tree6b3d2edcfdaf17853e9946bf0db510d4d24d35ae /src/test/java/com
parent8d88096236fe70b850a29f548432299a866886e6 (diff)
downloadgitblit-f8f6aa4d07cdfaaf23e24bf9eaf0a5fb9b437dda.tar.gz
gitblit-f8f6aa4d07cdfaaf23e24bf9eaf0a5fb9b437dda.zip
Update unit tests for refactored architecture
Change-Id: I04639db977c515e5e1090ef8f0e1ce858820cb03
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitSuite.java25
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitTest.java2
-rw-r--r--src/test/java/com/gitblit/tests/GitServletTest.java18
-rw-r--r--src/test/java/com/gitblit/tests/GroovyScriptTest.java4
-rw-r--r--src/test/java/com/gitblit/tests/LuceneExecutorTest.java6
-rw-r--r--src/test/java/com/gitblit/tests/RpcTests.java4
6 files changed, 40 insertions, 19 deletions
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java
index 57e94e51..7fc6fe0e 100644
--- a/src/test/java/com/gitblit/tests/GitBlitSuite.java
+++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java
@@ -65,6 +65,8 @@ import com.gitblit.utils.JGitUtils;
ModelUtilsTest.class, JnaUtilsTest.class })
public class GitBlitSuite {
+ public static final File BASEFOLDER = new File("data");
+
public static final File REPOSITORIES = new File("data/git");
public static final File SETTINGS = new File("src/test/config/test-gitblit.properties");
@@ -83,30 +85,35 @@ public class GitBlitSuite {
private static AtomicBoolean started = new AtomicBoolean(false);
- public static Repository getHelloworldRepository() throws Exception {
+ public static Repository getHelloworldRepository() {
return getRepository("helloworld.git");
}
- public static Repository getTicgitRepository() throws Exception {
+ public static Repository getTicgitRepository() {
return getRepository("ticgit.git");
}
- public static Repository getJGitRepository() throws Exception {
+ public static Repository getJGitRepository() {
return getRepository("test/jgit.git");
}
- public static Repository getAmbitionRepository() throws Exception {
+ public static Repository getAmbitionRepository() {
return getRepository("test/ambition.git");
}
- public static Repository getGitectiveRepository() throws Exception {
+ public static Repository getGitectiveRepository() {
return getRepository("test/gitective.git");
}
- private static Repository getRepository(String name) throws Exception {
- File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
- Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
- return repository;
+ private static Repository getRepository(String name) {
+ try {
+ File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
+ Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
+ return repository;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
}
public static boolean startGitblit() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/GitBlitTest.java b/src/test/java/com/gitblit/tests/GitBlitTest.java
index 692afb76..d3913513 100644
--- a/src/test/java/com/gitblit/tests/GitBlitTest.java
+++ b/src/test/java/com/gitblit/tests/GitBlitTest.java
@@ -156,7 +156,7 @@ public class GitBlitTest extends GitblitUnitTest {
assertEquals(5, settings().getInteger("realm.userService", 5));
assertTrue(settings().getBoolean("git.enableGitServlet", false));
- assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), settings().getString("realm.userService", null));
+ assertEquals("src/test/config/test-users.conf", settings().getString("realm.userService", null));
assertEquals(5, settings().getInteger("realm.minPasswordLength", 0));
List<String> mdExtensions = settings().getStrings("web.markdownExtensions");
assertTrue(mdExtensions.size() > 0);
diff --git a/src/test/java/com/gitblit/tests/GitServletTest.java b/src/test/java/com/gitblit/tests/GitServletTest.java
index b197a915..bc392885 100644
--- a/src/test/java/com/gitblit/tests/GitServletTest.java
+++ b/src/test/java/com/gitblit/tests/GitServletTest.java
@@ -624,18 +624,28 @@ public class GitServletTest extends GitblitUnitTest {
private void testRefChange(AccessPermission permission, Status expectedCreate, Status expectedDelete, Status expectedRewind) throws Exception {
+ final String originName = "ticgit.git";
+ final String forkName = "refchecks/ticgit.git";
+ final String workingCopy = "refchecks/ticgit-wc";
+
+
+ // lower access restriction on origin repository
+ RepositoryModel origin = repositories().getRepositoryModel(originName);
+ origin.accessRestriction = AccessRestrictionType.NONE;
+ repositories().updateRepositoryModel(origin.name, origin, false);
+
UserModel user = getUser();
delete(user);
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);
// fork from original to a temporary bare repo
- File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit.git");
+ File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName);
if (refChecks.exists()) {
FileUtils.delete(refChecks, FileUtils.RECURSIVE);
}
CloneCommand clone = Git.cloneRepository();
- clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
+ clone.setURI(url + "/" + originName);
clone.setDirectory(refChecks);
clone.setBare(true);
clone.setCloneAllBranches(true);
@@ -643,7 +653,7 @@ public class GitServletTest extends GitblitUnitTest {
GitBlitSuite.close(clone.call());
// elevate repository to clone permission
- RepositoryModel model = repositories().getRepositoryModel("refchecks/ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel(forkName);
switch (permission) {
case VIEW:
model.accessRestriction = AccessRestrictionType.CLONE;
@@ -663,7 +673,7 @@ public class GitServletTest extends GitblitUnitTest {
repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
- File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit-wc");
+ File local = new File(GitBlitSuite.REPOSITORIES, workingCopy);
if (local.exists()) {
FileUtils.delete(local, FileUtils.RECURSIVE);
}
diff --git a/src/test/java/com/gitblit/tests/GroovyScriptTest.java b/src/test/java/com/gitblit/tests/GroovyScriptTest.java
index 1b5b0f39..ff40972f 100644
--- a/src/test/java/com/gitblit/tests/GroovyScriptTest.java
+++ b/src/test/java/com/gitblit/tests/GroovyScriptTest.java
@@ -338,6 +338,10 @@ public class GroovyScriptTest extends GitblitUnitTest {
return dv;
}
+ public int getInteger(String key, int defaultValue) {
+ return defaultValue;
+ }
+
public void sendMail(String subject, String message, Collection<String> toAddresses) {
messages.add(new MockMail(subject, message, toAddresses));
}
diff --git a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java
index 8ffe8469..319c09c1 100644
--- a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java
+++ b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java
@@ -48,8 +48,8 @@ public class LuceneExecutorTest extends GitblitUnitTest {
private LuceneService newLuceneExecutor() {
MemorySettings settings = new MemorySettings();
settings.put(Keys.git.repositoriesFolder, GitBlitSuite.REPOSITORIES);
- RuntimeManager runtime = new RuntimeManager(settings);
- UserManager users = new UserManager(runtime);
+ RuntimeManager runtime = new RuntimeManager(settings, GitBlitSuite.BASEFOLDER).start();
+ UserManager users = new UserManager(runtime).start();
RepositoryManager repos = new RepositoryManager(runtime, users);
return new LuceneService(settings, repos);
}
@@ -78,7 +78,7 @@ public class LuceneExecutorTest extends GitblitUnitTest {
}
@Test
- public void testIndex() throws Exception {
+ public void testIndex() {
// reindex helloworld
Repository repository = GitBlitSuite.getHelloworldRepository();
RepositoryModel model = newRepositoryModel(repository);
diff --git a/src/test/java/com/gitblit/tests/RpcTests.java b/src/test/java/com/gitblit/tests/RpcTests.java
index e1ba9072..ced1a130 100644
--- a/src/test/java/com/gitblit/tests/RpcTests.java
+++ b/src/test/java/com/gitblit/tests/RpcTests.java
@@ -32,7 +32,7 @@ import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
import com.gitblit.Constants.PermissionType;
import com.gitblit.Constants.RegistrantType;
-import com.gitblit.GitBlitException.NotAllowedException;
+import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.GitBlitException.UnauthorizedException;
import com.gitblit.Keys;
import com.gitblit.models.FederationModel;
@@ -104,7 +104,7 @@ public class RpcTests extends GitblitUnitTest {
UserModel user = null;
try {
user = RpcUtils.getUser("admin", url, null, null);
- } catch (NotAllowedException e) {
+ } catch (ForbiddenException e) {
}
assertNull("Server allows anyone to get user!", user);