Search in sources :

Example 1 with InMemoryRepositoryManager

use of com.google.gerrit.testutil.InMemoryRepositoryManager in project gerrit by GerritCodeReview.

the class RepoSequenceTest method setUp.

@Before
public void setUp() throws Exception {
    repoManager = new InMemoryRepositoryManager();
    project = new Project.NameKey("project");
    repoManager.createRepository(project);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) Before(org.junit.Before)

Example 2 with InMemoryRepositoryManager

use of com.google.gerrit.testutil.InMemoryRepositoryManager in project gerrit by GerritCodeReview.

the class SchemaUpdaterTest method update.

@Test
public void update() throws OrmException, FileNotFoundException, IOException {
    db.create();
    final Path site = Paths.get(UUID.randomUUID().toString());
    final SitePaths paths = new SitePaths(site);
    SchemaUpdater u = Guice.createInjector(new FactoryModule() {

        @Override
        protected void configure() {
            TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
            };
            bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
            bind(Key.get(schemaFactory, ReviewDbFactory.class)).toInstance(db);
            bind(SitePaths.class).toInstance(paths);
            Config cfg = new Config();
            cfg.setString("user", null, "name", "Gerrit Code Review");
            cfg.setString("user", null, "email", "gerrit@localhost");
            //
            bind(Config.class).annotatedWith(//
            GerritServerConfig.class).toInstance(cfg);
            //
            bind(PersonIdent.class).annotatedWith(//
            GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
            bind(AllProjectsName.class).toInstance(new AllProjectsName("All-Projects"));
            bind(AllUsersName.class).toInstance(new AllUsersName("All-Users"));
            bind(GitRepositoryManager.class).toInstance(new InMemoryRepositoryManager());
            //
            bind(String.class).annotatedWith(//
            AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
            bind(DataSourceType.class).to(InMemoryH2Type.class);
            bind(SystemGroupBackend.class);
            install(new ConfigNotesMigration.Module());
        }
    }).getInstance(SchemaUpdater.class);
    for (SchemaVersion s = u.getLatestSchemaVersion(); s.getVersionNbr() > 1; s = s.getPrior()) {
        try {
            assertThat(s.getPrior().getVersionNbr()).named("schema %s has prior version %s. Not true that", s.getVersionNbr(), s.getPrior().getVersionNbr()).isEqualTo(s.getVersionNbr() - 1);
        } catch (ProvisionException e) {
            // version.
            break;
        }
    }
    u.update(new UpdateUI() {

        @Override
        public void message(String msg) {
        }

        @Override
        public boolean yesno(boolean def, String msg) {
            return def;
        }

        @Override
        public boolean isBatch() {
            return true;
        }

        @Override
        public void pruneSchema(StatementExecutor e, List<String> pruneList) throws OrmException {
            for (String sql : pruneList) {
                e.execute(sql);
            }
        }
    });
    db.assertSchemaVersion();
    final SystemConfig sc = db.getSystemConfig();
    assertThat(sc.sitePath).isEqualTo(paths.site_path.toAbsolutePath().toString());
}
Also used : SystemConfig(com.google.gerrit.reviewdb.client.SystemConfig) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) SystemConfig(com.google.gerrit.reviewdb.client.SystemConfig) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SitePaths(com.google.gerrit.server.config.SitePaths) StatementExecutor(com.google.gwtorm.server.StatementExecutor) ProvisionException(com.google.inject.ProvisionException) TypeLiteral(com.google.inject.TypeLiteral) OrmException(com.google.gwtorm.server.OrmException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) Path(java.nio.file.Path) SchemaFactory(com.google.gwtorm.server.SchemaFactory) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ConfigNotesMigration(com.google.gerrit.server.notedb.ConfigNotesMigration) AllUsersName(com.google.gerrit.server.config.AllUsersName) Test(org.junit.Test)

Example 3 with InMemoryRepositoryManager

use of com.google.gerrit.testutil.InMemoryRepositoryManager in project gerrit by GerritCodeReview.

the class WalkSorterTest method setUp.

@Before
public void setUp() {
    userId = new Account.Id(1);
    repoManager = new InMemoryRepositoryManager();
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) Before(org.junit.Before)

Example 4 with InMemoryRepositoryManager

use of com.google.gerrit.testutil.InMemoryRepositoryManager in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method missingRepo.

@Test
public void missingRepo() throws Exception {
    // NoteDb can't have a change without a repo.
    assume().that(notesMigration.enabled()).isFalse();
    ChangeControl ctl = insertChange();
    Project.NameKey name = ctl.getProject().getNameKey();
    ((InMemoryRepositoryManager) repoManager).deleteRepository(name);
    assertProblems(ctl, null, problem("Destination repository not found: " + name));
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) ChangeControl(com.google.gerrit.server.project.ChangeControl) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with InMemoryRepositoryManager

use of com.google.gerrit.testutil.InMemoryRepositoryManager in project gerrit by GerritCodeReview.

the class RefControlTest method setUp.

@Before
public void setUp() throws Exception {
    repoManager = new InMemoryRepositoryManager();
    projectCache = new ProjectCache() {

        @Override
        public ProjectState getAllProjects() {
            return get(allProjectsName);
        }

        @Override
        public ProjectState getAllUsers() {
            return null;
        }

        @Override
        public ProjectState get(Project.NameKey projectName) {
            return all.get(projectName);
        }

        @Override
        public void evict(Project p) {
        }

        @Override
        public void remove(Project p) {
        }

        @Override
        public Iterable<Project.NameKey> all() {
            return Collections.emptySet();
        }

        @Override
        public Iterable<Project.NameKey> byName(String prefix) {
            return Collections.emptySet();
        }

        @Override
        public void onCreateProject(Project.NameKey newProjectName) {
        }

        @Override
        public Set<AccountGroup.UUID> guessRelevantGroupUUIDs() {
            return Collections.emptySet();
        }

        @Override
        public ProjectState checkedGet(Project.NameKey projectName) throws IOException {
            return all.get(projectName);
        }

        @Override
        public void evict(Project.NameKey p) {
        }
    };
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    try {
        Repository repo = repoManager.createRepository(allProjectsName);
        ProjectConfig allProjects = new ProjectConfig(new Project.NameKey(allProjectsName.get()));
        allProjects.load(repo);
        LabelType cr = Util.codeReview();
        allProjects.getLabelSections().put(cr.getName(), cr);
        add(allProjects);
    } catch (IOException | ConfigInvalidException e) {
        throw new RuntimeException(e);
    }
    db = schemaFactory.open();
    singleVersionListener.start();
    try {
        schemaCreator.create(db);
    } finally {
        singleVersionListener.stop();
    }
    Cache<SectionSortCache.EntryKey, SectionSortCache.EntryVal> c = CacheBuilder.newBuilder().build();
    sectionSorter = new PermissionCollection.Factory(new SectionSortCache(c));
    parent = new ProjectConfig(parentKey);
    parent.load(newRepository(parentKey));
    add(parent);
    local = new ProjectConfig(localKey);
    local.load(newRepository(localKey));
    add(local);
    local.getProject().setParentName(parentKey);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return null;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
    changeControlFactory = injector.getInstance(ChangeControl.Factory.class);
}
Also used : Set(java.util.Set) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CurrentUser(com.google.gerrit.server.CurrentUser) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) Injector(com.google.inject.Injector) LabelType(com.google.gerrit.common.data.LabelType) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) RequestContext(com.google.gerrit.server.util.RequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) IOException(java.io.IOException) AllUsersNameProvider(com.google.gerrit.server.config.AllUsersNameProvider) AllProjectsNameProvider(com.google.gerrit.server.config.AllProjectsNameProvider) Provider(com.google.inject.Provider) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) InMemoryRepositoryManager.newRepository(com.google.gerrit.testutil.InMemoryRepositoryManager.newRepository) Repository(org.eclipse.jgit.lib.Repository) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Before(org.junit.Before)

Aggregations

InMemoryRepositoryManager (com.google.gerrit.testutil.InMemoryRepositoryManager)8 Before (org.junit.Before)6 Project (com.google.gerrit.reviewdb.client.Project)5 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)2 Account (com.google.gerrit.reviewdb.client.Account)2 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)2 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)2 AllUsersName (com.google.gerrit.server.config.AllUsersName)2 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)2 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)2 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 LabelType (com.google.gerrit.common.data.LabelType)1 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)1 MetricMaker (com.google.gerrit.metrics.MetricMaker)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 SystemConfig (com.google.gerrit.reviewdb.client.SystemConfig)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 InternalUser (com.google.gerrit.server.InternalUser)1 AccountCache (com.google.gerrit.server.account.AccountCache)1