James Moger
2012-06-15 01774948d84794d1d9c216f9a6859d7f150815d5
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 import com.gitblit.utils.JGitUtils;
33
34 public class RepositoryModelTest {
35     
36     private static boolean wasStarted = false;
37     
38     @BeforeClass
39     public static void startGitBlit() throws Exception {
40         wasStarted = GitBlitSuite.startGitblit() == false;
41     }
42     
43     @AfterClass
44     public static void stopGitBlit() throws Exception {
45         if (wasStarted == false)
46             GitBlitSuite.stopGitblit();
47     }
48     
49     @Before
50     public void initializeConfiguration() throws Exception{
51         Repository r = GitBlitSuite.getHelloworldRepository();
52         StoredConfig config = JGitUtils.readConfig(r);
53         
380afa 54         config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS);
JM 55         config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "commitMessageRegEx", "\\d");
56         config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "anotherProperty", "Hello");
cca55e 57         
JC 58         config.save();
59     }
60     
61     @After
62     public void teardownConfiguration() throws Exception {
63         Repository r = GitBlitSuite.getHelloworldRepository();
64         StoredConfig config = JGitUtils.readConfig(r);
65         
380afa 66         config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS);
cca55e 67         config.save();
JC 68     }
69
70     @Test
71     public void testGetCustomProperty() throws Exception {
72         RepositoryModel model = GitBlit.self().getRepositoryModel(
73                 GitBlitSuite.getHelloworldRepository().getDirectory().getName());
74         
08d86d 75         assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
JC 76         assertEquals("Hello", model.customFields.get("anotherProperty"));
cca55e 77     }
JC 78     
79     @Test
80     public void testSetCustomProperty() throws Exception {
81         RepositoryModel model = GitBlit.self().getRepositoryModel(
82                 GitBlitSuite.getHelloworldRepository().getDirectory().getName());
83         
08d86d 84         assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
JC 85         assertEquals("Hello", model.customFields.get("anotherProperty"));
cca55e 86         
08d86d 87         assertEquals("Hello", model.customFields.put("anotherProperty", "GoodBye"));
4a5a55 88         GitBlit.self().updateRepositoryModel(model.name, model, false);
cca55e 89         
4a5a55 90         model = GitBlit.self().getRepositoryModel(
JC 91                 GitBlitSuite.getHelloworldRepository().getDirectory().getName());
92         
08d86d 93         assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
JC 94         assertEquals("GoodBye", model.customFields.get("anotherProperty"));
cca55e 95     }
JC 96
97 }