| | |
| | | package com.gitblit.tests; |
| | | |
| | | import static org.junit.Assert.*; |
| | | import static org.junit.Assert.assertEquals; |
| | | |
| | | import org.eclipse.jgit.lib.Repository; |
| | | import org.eclipse.jgit.lib.StoredConfig; |
| | |
| | | import org.junit.BeforeClass; |
| | | import org.junit.Test; |
| | | |
| | | import com.gitblit.Constants; |
| | | import com.gitblit.GitBlit; |
| | | import com.gitblit.models.RepositoryModel; |
| | | import com.gitblit.utils.JGitUtils; |
| | |
| | | public static void startGitBlit() throws Exception { |
| | | wasStarted = GitBlitSuite.startGitblit() == false; |
| | | |
| | | oldSection = RepositoryModel.CUSTOM_DEFINED_PROP_SECTION; |
| | | oldSubSection = RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION; |
| | | oldSection = Constants.CUSTOM_DEFINED_PROP_SECTION; |
| | | oldSubSection = Constants.CUSTOM_DEFINED_PROP_SUBSECTION; |
| | | |
| | | RepositoryModel.CUSTOM_DEFINED_PROP_SECTION = "RepositoryModelTest"; |
| | | RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION = "RepositoryModelTestSubSection"; |
| | | Constants.CUSTOM_DEFINED_PROP_SECTION = "RepositoryModelTest"; |
| | | Constants.CUSTOM_DEFINED_PROP_SUBSECTION = "RepositoryModelTestSubSection"; |
| | | } |
| | | |
| | | @AfterClass |
| | |
| | | if (wasStarted == false) |
| | | GitBlitSuite.stopGitblit(); |
| | | |
| | | RepositoryModel.CUSTOM_DEFINED_PROP_SECTION = oldSection; |
| | | RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION = oldSubSection; |
| | | Constants.CUSTOM_DEFINED_PROP_SECTION = oldSection; |
| | | Constants.CUSTOM_DEFINED_PROP_SUBSECTION = oldSubSection; |
| | | } |
| | | |
| | | @Before |
| | |
| | | Repository r = GitBlitSuite.getHelloworldRepository(); |
| | | StoredConfig config = JGitUtils.readConfig(r); |
| | | |
| | | config.unsetSection(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION); |
| | | config.setString(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION, "commitMessageRegEx", "\\d"); |
| | | config.setString(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION, "anotherProperty", "Hello"); |
| | | config.unsetSection(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION); |
| | | config.setString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, "commitMessageRegEx", "\\d"); |
| | | config.setString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, "anotherProperty", "Hello"); |
| | | |
| | | config.save(); |
| | | } |
| | |
| | | Repository r = GitBlitSuite.getHelloworldRepository(); |
| | | StoredConfig config = JGitUtils.readConfig(r); |
| | | |
| | | config.unsetSection(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION); |
| | | config.unsetSection(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION); |
| | | config.save(); |
| | | } |
| | | |
| | |
| | | RepositoryModel model = GitBlit.self().getRepositoryModel( |
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
| | | |
| | | assertEquals("\\d", model.getCustomProperty("commitMessageRegEx")); |
| | | assertEquals("Hello", model.getCustomProperty("anotherProperty")); |
| | | assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); |
| | | assertEquals("Hello", model.userDefinedProperties.get("anotherProperty")); |
| | | } |
| | | |
| | | @Test |
| | |
| | | RepositoryModel model = GitBlit.self().getRepositoryModel( |
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
| | | |
| | | assertEquals("\\d", model.getCustomProperty("commitMessageRegEx")); |
| | | assertEquals("Hello", model.getCustomProperty("anotherProperty")); |
| | | assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); |
| | | assertEquals("Hello", model.userDefinedProperties.get("anotherProperty")); |
| | | |
| | | assertEquals("Hello", model.setCustomProperty("anotherProperty", "GoodBye")); |
| | | assertEquals("Hello", model.userDefinedProperties.put("anotherProperty", "GoodBye")); |
| | | GitBlit.self().updateRepositoryModel(model.name, model, false); |
| | | |
| | | assertEquals("\\d", model.getCustomProperty("commitMessageRegEx")); |
| | | assertEquals("GoodBye", model.getCustomProperty("anotherProperty")); |
| | | model = GitBlit.self().getRepositoryModel( |
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
| | | |
| | | assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); |
| | | assertEquals("GoodBye", model.userDefinedProperties.get("anotherProperty")); |
| | | } |
| | | |
| | | } |