commit | author | age
|
831469
|
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 |
*/
|
|
16 |
package com.gitblit.tests;
|
|
17 |
|
7e8873
|
18 |
import static org.junit.Assert.assertEquals;
|
JM |
19 |
|
831469
|
20 |
import java.io.IOException;
|
JM |
21 |
import java.util.Date;
|
|
22 |
import java.util.HashMap;
|
|
23 |
import java.util.Map;
|
7e8873
|
24 |
import java.util.concurrent.atomic.AtomicBoolean;
|
831469
|
25 |
|
7e8873
|
26 |
import org.junit.AfterClass;
|
JM |
27 |
import org.junit.BeforeClass;
|
|
28 |
import org.junit.Test;
|
831469
|
29 |
|
JM |
30 |
import com.gitblit.Constants.AccessRestrictionType;
|
4aafd4
|
31 |
import com.gitblit.Constants.FederationProposalResult;
|
831469
|
32 |
import com.gitblit.Constants.FederationRequest;
|
JM |
33 |
import com.gitblit.Constants.FederationToken;
|
dd9ae7
|
34 |
import com.gitblit.models.FederationProposal;
|
831469
|
35 |
import com.gitblit.models.RepositoryModel;
|
JM |
36 |
import com.gitblit.utils.FederationUtils;
|
93f0b1
|
37 |
import com.gitblit.utils.JsonUtils;
|
831469
|
38 |
|
7e8873
|
39 |
public class FederationTests {
|
831469
|
40 |
|
7e8873
|
41 |
String url = GitBlitSuite.url;
|
JM |
42 |
String account = GitBlitSuite.account;
|
|
43 |
String password = GitBlitSuite.password;
|
831469
|
44 |
|
7e8873
|
45 |
private static final AtomicBoolean started = new AtomicBoolean(false);
|
831469
|
46 |
|
7e8873
|
47 |
@BeforeClass
|
JM |
48 |
public static void startGitblit() throws Exception {
|
|
49 |
started.set(GitBlitSuite.startGitblit());
|
831469
|
50 |
}
|
JM |
51 |
|
7e8873
|
52 |
@AfterClass
|
JM |
53 |
public static void stopGitblit() throws Exception {
|
|
54 |
if (started.get()) {
|
|
55 |
GitBlitSuite.stopGitblit();
|
|
56 |
}
|
831469
|
57 |
}
|
JM |
58 |
|
7e8873
|
59 |
@Test
|
831469
|
60 |
public void testProposal() throws Exception {
|
JM |
61 |
// create dummy repository data
|
|
62 |
Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();
|
|
63 |
for (int i = 0; i < 5; i++) {
|
|
64 |
RepositoryModel model = new RepositoryModel();
|
|
65 |
model.accessRestriction = AccessRestrictionType.VIEW;
|
|
66 |
model.description = "cloneable repository " + i;
|
|
67 |
model.lastChange = new Date();
|
|
68 |
model.owner = "adminuser";
|
|
69 |
model.name = "repo" + i + ".git";
|
|
70 |
model.size = "5 MB";
|
|
71 |
model.hasCommits = true;
|
|
72 |
repositories.put(model.name, model);
|
|
73 |
}
|
|
74 |
|
dd9ae7
|
75 |
FederationProposal proposal = new FederationProposal("http://testurl", FederationToken.ALL,
|
JM |
76 |
"testtoken", repositories);
|
|
77 |
|
831469
|
78 |
// propose federation
|
7e8873
|
79 |
assertEquals("proposal refused", FederationUtils.propose(url, proposal),
|
4aafd4
|
80 |
FederationProposalResult.NO_PROPOSALS);
|
831469
|
81 |
}
|
JM |
82 |
|
7e8873
|
83 |
@Test
|
831469
|
84 |
public void testPullRepositories() throws Exception {
|
JM |
85 |
try {
|
7e8873
|
86 |
String requrl = FederationUtils.asLink(url, "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c",
|
31abc2
|
87 |
FederationRequest.PULL_REPOSITORIES);
|
7e8873
|
88 |
String json = JsonUtils.retrieveJsonString(requrl, null, null);
|
831469
|
89 |
} catch (IOException e) {
|
JM |
90 |
if (!e.getMessage().contains("403")) {
|
|
91 |
throw e;
|
|
92 |
}
|
|
93 |
}
|
|
94 |
}
|
|
95 |
}
|