Search in sources :

Example 16 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class DataStoreConcurrencyTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    File workingDirectory = tmp.newFolder("repo");
    File userHomeDirectory = tmp.newFolder("home");
    TestPlatform platform = new TestPlatform(workingDirectory);
    platform.setUserHome(userHomeDirectory);
    Context injector = new CLITestContextBuilder(platform).build();
    GeoGIG geogig = new GeoGIG(injector);
    geogig.command(InitOp.class).call();
    geogig.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.name").setValue("gabriel").call();
    geogig.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.email").setValue("gabriel@roldan.example.com").call();
    store = new GeoGigDataStore(geogig);
    store.createSchema(pointType);
    editThreads = Executors.newFixedThreadPool(writeThreadCount, new ThreadFactoryBuilder().setNameFormat("edit-thread-%d").build());
    readThreads = Executors.newFixedThreadPool(readThreadCount, new ThreadFactoryBuilder().setNameFormat("read-thread-%d").build());
    initialCommitCount = copyOf(store.getGeogig().command(LogOp.class).call()).size();
}
Also used : Context(org.locationtech.geogig.api.Context) InitOp(org.locationtech.geogig.api.porcelain.InitOp) TestPlatform(org.locationtech.geogig.api.TestPlatform) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) GeoGigDataStore(org.locationtech.geogig.geotools.data.GeoGigDataStore) File(java.io.File) CLITestContextBuilder(org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder) GeoGIG(org.locationtech.geogig.api.GeoGIG) Before(org.junit.Before)

Example 17 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class ImportOpTest method testDeleteException.

@Test
public void testDeleteException() throws Exception {
    WorkingTree workTree = mock(WorkingTree.class);
    Context cmdl = mock(Context.class);
    when(cmdl.workingTree()).thenReturn(workTree);
    doThrow(new RuntimeException("Exception")).when(workTree).delete(any(String.class));
    ImportOp importOp = new ImportOp();
    importOp.setContext(cmdl);
    importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
    importOp.setAll(true);
    exception.expect(GeoToolsOpException.class);
    importOp.call();
}
Also used : Context(org.locationtech.geogig.api.Context) WorkingTree(org.locationtech.geogig.repository.WorkingTree) Test(org.junit.Test)

Example 18 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class InitOpTest method testReinitializeExistingRepo.

@Test
public void testReinitializeExistingRepo() throws Exception {
    when(injector.repository()).thenReturn(mockRepo);
    Optional<Ref> absent = Optional.absent();
    when(mockRefParse.call()).thenReturn(absent);
    Repository created = init.call();
    assertSame(mockRepo, created);
    verify(mockUpdateRef, times(3)).call();
    verify(mockUpdateSymRef, times(1)).call();
    assertTrue(new File(workingDir, ".geogig").exists());
    assertTrue(new File(workingDir, ".geogig").isDirectory());
    Ref master = new Ref(Ref.MASTER, ObjectId.forString("hash me"));
    when(mockRefParse.call()).thenReturn(Optional.of(master));
    Context injector = mock(Context.class);
    when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse);
    when(injector.platform()).thenReturn(platform);
    when(injector.repository()).thenReturn(mockRepo);
    init.setContext(injector);
    assertTrue(ResolveGeogigDir.lookup(platform.pwd()).isPresent());
    assertNotNull(init.call());
    verify(platform, atLeastOnce()).pwd();
    assertTrue(ResolveGeogigDir.lookup(platform.pwd()).isPresent());
    verify(injector, never()).command(eq(UpdateRef.class));
    verify(injector, never()).command(eq(UpdateSymRef.class));
    assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID));
}
Also used : Context(org.locationtech.geogig.api.Context) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) Repository(org.locationtech.geogig.repository.Repository) RefParse(org.locationtech.geogig.api.plumbing.RefParse) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) File(java.io.File) Test(org.junit.Test)

Example 19 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class DepthSearchTest method setUp.

@Before
public void setUp() throws IOException {
    File envHome = tempFolder.getRoot();
    Platform testPlatform = new TestPlatform(envHome);
    Context injector = Guice.createInjector(Modules.override(new GeogigModule()).with(new MemoryModule(testPlatform))).getInstance(Context.class);
    fakeGeogig = new GeoGIG(injector);
    Repository fakeRepo = fakeGeogig.getOrCreateRepository();
    odb = fakeRepo.objectDatabase();
    search = new DepthSearch(odb);
    RevTreeBuilder root = new RevTreeBuilder(odb);
    root = addTree(root, "path/to/tree1", "node11", "node12", "node13");
    root = addTree(root, "path/to/tree2", "node21", "node22", "node23");
    root = addTree(root, "tree3", "node31", "node32", "node33");
    RevTree rootTree = root.build();
    odb.put(rootTree);
    rootTreeId = rootTree.getId();
}
Also used : Context(org.locationtech.geogig.api.Context) TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) TestPlatform(org.locationtech.geogig.api.TestPlatform) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) File(java.io.File) GeogigModule(org.locationtech.geogig.di.GeogigModule) MemoryModule(org.locationtech.geogig.api.MemoryModule) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree) Before(org.junit.Before)

Example 20 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class Diff method run.

/**
     * Runs the command and builds the appropriate response
     * 
     * @param context - the context to use for this command
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    if (oldRefSpec == null || oldRefSpec.trim().isEmpty()) {
        throw new CommandSpecException("No old ref spec");
    }
    final Context geogig = this.getCommandLocator(context);
    final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(oldRefSpec).setNewVersion(newRefSpec).setFilter(pathFilter).call();
    context.setResponseContent(new CommandResponse() {

        @Override
        public void write(ResponseWriter out) throws Exception {
            out.start();
            if (showGeometryChanges) {
                out.writeGeometryChanges(geogig, diff, page, elementsPerPage);
            } else {
                out.writeDiffEntries("diff", page * elementsPerPage, elementsPerPage, diff);
            }
            out.finish();
        }
    });
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

Context (org.locationtech.geogig.api.Context)52 CommandContext (org.locationtech.geogig.web.api.CommandContext)24 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)24 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)24 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)16 ObjectId (org.locationtech.geogig.api.ObjectId)13 File (java.io.File)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)9 NodeRef (org.locationtech.geogig.api.NodeRef)8 Ref (org.locationtech.geogig.api.Ref)8 Before (org.junit.Before)7 RevCommit (org.locationtech.geogig.api.RevCommit)7 Optional (com.google.common.base.Optional)6 Platform (org.locationtech.geogig.api.Platform)6 RevTree (org.locationtech.geogig.api.RevTree)6 TestPlatform (org.locationtech.geogig.api.TestPlatform)6 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)5 GeogigModule (org.locationtech.geogig.di.GeogigModule)5 MemoryModule (org.locationtech.geogig.api.MemoryModule)4 RevFeature (org.locationtech.geogig.api.RevFeature)4