Search in sources :

Example 6 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class MultiBaseLocalDiskRepositoryManagerTest method setUp.

@Before
public void setUp() throws IOException {
    site = new SitePaths(TempFileUtil.createTempDirectory().toPath());
    site.resolve("git").toFile().mkdir();
    cfg = new Config();
    cfg.setString("gerrit", null, "basePath", "git");
    configMock = createNiceMock(RepositoryConfig.class);
    expect(configMock.getAllBasePaths()).andReturn(new ArrayList<Path>()).anyTimes();
    replay(configMock);
    repoManager = new MultiBaseLocalDiskRepositoryManager(site, cfg, configMock);
}
Also used : RepositoryConfig(com.google.gerrit.server.config.RepositoryConfig) Config(org.eclipse.jgit.lib.Config) RepositoryConfig(com.google.gerrit.server.config.RepositoryConfig) ArrayList(java.util.ArrayList) SitePaths(com.google.gerrit.server.config.SitePaths) Before(org.junit.Before)

Example 7 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class LibrariesTest method create.

@Test
public void create() throws Exception {
    final SitePaths site = new SitePaths(Paths.get("."));
    final ConsoleUI ui = createStrictMock(ConsoleUI.class);
    final StaleLibraryRemover remover = createStrictMock(StaleLibraryRemover.class);
    replay(ui);
    Libraries lib = new Libraries(new Provider<LibraryDownloader>() {

        @Override
        public LibraryDownloader get() {
            return new LibraryDownloader(ui, site, remover);
        }
    }, Collections.<String>emptyList(), false);
    assertNotNull(lib.mysqlDriver);
    verify(ui);
}
Also used : SitePaths(com.google.gerrit.server.config.SitePaths) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) Test(org.junit.Test)

Example 8 with SitePaths

use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.

the class UpgradeFrom2_0_xTest method upgrade.

@Test
public void upgrade() throws IOException, ConfigInvalidException {
    final Path p = newSitePath();
    final SitePaths site = new SitePaths(p);
    assertTrue(site.isNew);
    FileUtil.mkdirsOrDie(site.etc_dir, "Failed to create");
    for (String n : UpgradeFrom2_0_x.etcFiles) {
        Files.write(p.resolve(n), ("# " + n + "\n").getBytes(UTF_8));
    }
    FileBasedConfig old = new FileBasedConfig(p.resolve("gerrit.config").toFile(), FS.DETECTED);
    old.setString("ldap", null, "username", "ldap.user");
    old.setString("ldap", null, "password", "ldap.s3kr3t");
    old.setString("sendemail", null, "smtpUser", "email.user");
    old.setString("sendemail", null, "smtpPass", "email.s3kr3t");
    old.save();
    final InMemorySecureStore secureStore = new InMemorySecureStore();
    final InitFlags flags = new InitFlags(site, secureStore, Collections.<String>emptyList(), false);
    final ConsoleUI ui = createStrictMock(ConsoleUI.class);
    Section.Factory sections = new Section.Factory() {

        @Override
        public Section get(String name, String subsection) {
            return new Section(flags, site, secureStore, ui, name, subsection);
        }
    };
    expect(ui.yesno(eq(true), eq("Upgrade '%s'"), eq(p.toAbsolutePath().normalize()))).andReturn(true);
    replay(ui);
    UpgradeFrom2_0_x u = new UpgradeFrom2_0_x(site, flags, ui, sections);
    assertTrue(u.isNeedUpgrade());
    u.run();
    assertFalse(u.isNeedUpgrade());
    verify(ui);
    for (String n : UpgradeFrom2_0_x.etcFiles) {
        if ("gerrit.config".equals(n) || "secure.config".equals(n)) {
            continue;
        }
        try (InputStream in = Files.newInputStream(site.etc_dir.resolve(n))) {
            assertEquals("# " + n + "\n", new String(ByteStreams.toByteArray(in), UTF_8));
        }
    }
    FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
    cfg.load();
    assertEquals("email.user", cfg.getString("sendemail", null, "smtpUser"));
    assertNull(cfg.getString("sendemail", null, "smtpPass"));
    assertEquals("email.s3kr3t", secureStore.get("sendemail", null, "smtpPass"));
    assertEquals("ldap.user", cfg.getString("ldap", null, "username"));
    assertNull(cfg.getString("ldap", null, "password"));
    assertEquals("ldap.s3kr3t", secureStore.get("ldap", null, "password"));
    u.run();
}
Also used : Path(java.nio.file.Path) InitFlags(com.google.gerrit.pgm.init.api.InitFlags) InputStream(java.io.InputStream) SitePaths(com.google.gerrit.server.config.SitePaths) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Section(com.google.gerrit.pgm.init.api.Section) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) Test(org.junit.Test)

Aggregations

SitePaths (com.google.gerrit.server.config.SitePaths)8 Config (org.eclipse.jgit.lib.Config)4 Path (java.nio.file.Path)3 Test (org.junit.Test)3 ConsoleUI (com.google.gerrit.pgm.init.api.ConsoleUI)2 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)2 Injector (com.google.inject.Injector)2 Before (org.junit.Before)2 CommentLinkInfo (com.google.gerrit.extensions.api.projects.CommentLinkInfo)1 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)1 InitFlags (com.google.gerrit.pgm.init.api.InitFlags)1 Section (com.google.gerrit.pgm.init.api.Section)1 SystemConfig (com.google.gerrit.reviewdb.client.SystemConfig)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 PrologEnvironment (com.google.gerrit.rules.PrologEnvironment)1 RulesCache (com.google.gerrit.rules.RulesCache)1 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)1 AllProjectsName (com.google.gerrit.server.config.AllProjectsName)1 AllUsersName (com.google.gerrit.server.config.AllUsersName)1 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)1