commit | author | age
|
380afa
|
1 |
/* |
JM |
2 |
* Copyright 2012 John Crygier |
|
3 |
* Copyright 2012 gitblit.com |
|
4 |
* |
|
5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 |
* you may not use this file except in compliance with the License. |
|
7 |
* You may obtain a copy of the License at |
|
8 |
* |
|
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10 |
* |
|
11 |
* Unless required by applicable law or agreed to in writing, software |
|
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 |
* See the License for the specific language governing permissions and |
|
15 |
* limitations under the License. |
|
16 |
*/ |
cca55e
|
17 |
package com.gitblit.tests; |
JC |
18 |
|
4a5a55
|
19 |
import static org.junit.Assert.assertEquals; |
cca55e
|
20 |
|
JC |
21 |
import org.eclipse.jgit.lib.Repository; |
|
22 |
import org.eclipse.jgit.lib.StoredConfig; |
|
23 |
import org.junit.After; |
|
24 |
import org.junit.AfterClass; |
|
25 |
import org.junit.Before; |
|
26 |
import org.junit.BeforeClass; |
|
27 |
import org.junit.Test; |
|
28 |
|
4a5a55
|
29 |
import com.gitblit.Constants; |
cca55e
|
30 |
import com.gitblit.GitBlit; |
JC |
31 |
import com.gitblit.models.RepositoryModel; |
|
32 |
|
|
33 |
public class RepositoryModelTest { |
|
34 |
|
|
35 |
private static boolean wasStarted = false; |
|
36 |
|
|
37 |
@BeforeClass |
|
38 |
public static void startGitBlit() throws Exception { |
|
39 |
wasStarted = GitBlitSuite.startGitblit() == false; |
|
40 |
} |
|
41 |
|
|
42 |
@AfterClass |
|
43 |
public static void stopGitBlit() throws Exception { |
|
44 |
if (wasStarted == false) |
|
45 |
GitBlitSuite.stopGitblit(); |
|
46 |
} |
|
47 |
|
|
48 |
@Before |
|
49 |
public void initializeConfiguration() throws Exception{ |
|
50 |
Repository r = GitBlitSuite.getHelloworldRepository(); |
fee060
|
51 |
StoredConfig config = r.getConfig(); |
cca55e
|
52 |
|
380afa
|
53 |
config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); |
JM |
54 |
config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "commitMessageRegEx", "\\d"); |
|
55 |
config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "anotherProperty", "Hello"); |
cca55e
|
56 |
|
JC |
57 |
config.save(); |
|
58 |
} |
|
59 |
|
|
60 |
@After |
|
61 |
public void teardownConfiguration() throws Exception { |
|
62 |
Repository r = GitBlitSuite.getHelloworldRepository(); |
fee060
|
63 |
StoredConfig config = r.getConfig(); |
cca55e
|
64 |
|
380afa
|
65 |
config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); |
cca55e
|
66 |
config.save(); |
JC |
67 |
} |
|
68 |
|
|
69 |
@Test |
|
70 |
public void testGetCustomProperty() throws Exception { |
|
71 |
RepositoryModel model = GitBlit.self().getRepositoryModel( |
|
72 |
GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
|
73 |
|
08d86d
|
74 |
assertEquals("\\d", model.customFields.get("commitMessageRegEx")); |
JC |
75 |
assertEquals("Hello", model.customFields.get("anotherProperty")); |
cca55e
|
76 |
} |
JC |
77 |
|
|
78 |
@Test |
|
79 |
public void testSetCustomProperty() throws Exception { |
|
80 |
RepositoryModel model = GitBlit.self().getRepositoryModel( |
|
81 |
GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
|
82 |
|
08d86d
|
83 |
assertEquals("\\d", model.customFields.get("commitMessageRegEx")); |
JC |
84 |
assertEquals("Hello", model.customFields.get("anotherProperty")); |
cca55e
|
85 |
|
08d86d
|
86 |
assertEquals("Hello", model.customFields.put("anotherProperty", "GoodBye")); |
4a5a55
|
87 |
GitBlit.self().updateRepositoryModel(model.name, model, false); |
cca55e
|
88 |
|
4a5a55
|
89 |
model = GitBlit.self().getRepositoryModel( |
JC |
90 |
GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
|
91 |
|
08d86d
|
92 |
assertEquals("\\d", model.customFields.get("commitMessageRegEx")); |
JC |
93 |
assertEquals("GoodBye", model.customFields.get("anotherProperty")); |
cca55e
|
94 |
} |
JC |
95 |
|
|
96 |
} |