James Moger
2011-06-02 a125cf6876e0edc5a2498df57a9df06d60b1f572
commit | author | age
ec97f7 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
28d6b2 16 package com.gitblit.tests;
JM 17
18 import java.util.List;
19
20 import junit.framework.TestCase;
21
22 import com.gitblit.GitBlit;
23 import com.gitblit.models.RepositoryModel;
24 import com.gitblit.models.UserModel;
25
26 public class GitBlitTest extends TestCase {
27
28     public void testRepositoryModel() throws Exception {
29         List<String> repositories = GitBlit.self().getRepositoryList();
30         assertTrue("Repository list is empty!", repositories.size() > 0);
db653a 31         assertTrue(
JM 32                 "Missing Helloworld repository!",
33                 repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()
34                         .getName()));
35         RepositoryModel model = GitBlit.self().getRepositoryModel(
36                 GitBlitSuite.getHelloworldRepository().getDirectory().getName());
28d6b2 37         assertTrue("Helloworld model is null!", model != null);
db653a 38         assertTrue(model.toString().equals(
JM 39                 GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
28d6b2 40     }
db653a 41
28d6b2 42     public void testUserModel() throws Exception {
JM 43         List<String> users = GitBlit.self().getAllUsernames();
44         assertTrue("No users found!", users.size() > 0);
45         assertTrue("Admin not found", users.contains("admin"));
46         UserModel model = GitBlit.self().getUserModel("admin");
47         assertTrue(model.toString().equals("admin"));
48         assertTrue("Admin missing #admin role!", model.canAdmin);
49         model.canAdmin = false;
50         assertFalse("Admin should not hae #admin!", model.canAdmin);
51         String repository = GitBlitSuite.getHelloworldRepository().getDirectory().getName();
52         assertFalse("Admin can still access repository!", model.canAccessRepository(repository));
53         model.addRepository(repository);
54         assertTrue("Admin can't access repository!", model.canAccessRepository(repository));
55     }
56 }