Exemplo n.º 1
0
  @Test
  public void testModifyWorkspace() throws Exception {
    WorkspaceInfo ws = dao.getCatalog().getFactory().createWorkspace();
    ws.setName("foo");
    dao.add(ws);

    ws = dao.getWorkspaceByName("foo");
    ws.setName("bar");
    dao.save(ws);

    assertNull(dao.getWorkspaceByName("foo"));
    assertNotNull(dao.getWorkspaceByName("bar"));
  }
  private void configureGeogigDataStore() throws Exception {

    helper.insertAndAdd(helper.lines1);
    helper.getGeogig().command(CommitOp.class).call();

    Catalog catalog = getCatalog();
    CatalogFactory factory = catalog.getFactory();
    NamespaceInfo ns = factory.createNamespace();
    ns.setPrefix(WORKSPACE);
    ns.setURI(NAMESPACE);
    catalog.add(ns);
    WorkspaceInfo ws = factory.createWorkspace();
    ws.setName(ns.getName());
    catalog.add(ws);

    DataStoreInfo ds = factory.createDataStore();
    ds.setEnabled(true);
    ds.setDescription("Test Geogig DataStore");
    ds.setName(STORE);
    ds.setType(GeoGigDataStoreFactory.DISPLAY_NAME);
    ds.setWorkspace(ws);
    Map<String, Serializable> connParams = ds.getConnectionParameters();

    Optional<URI> geogigDir = helper.getGeogig().command(ResolveGeogigURI.class).call();
    File repositoryUrl = new File(geogigDir.get()).getParentFile();
    assertTrue(repositoryUrl.exists() && repositoryUrl.isDirectory());

    connParams.put(GeoGigDataStoreFactory.REPOSITORY.key, repositoryUrl);
    connParams.put(GeoGigDataStoreFactory.DEFAULT_NAMESPACE.key, ns.getURI());
    catalog.add(ds);

    DataStoreInfo dsInfo = catalog.getDataStoreByName(WORKSPACE, STORE);
    assertNotNull(dsInfo);
    assertEquals(GeoGigDataStoreFactory.DISPLAY_NAME, dsInfo.getType());
    DataAccess<? extends FeatureType, ? extends Feature> dataStore = dsInfo.getDataStore(null);
    assertNotNull(dataStore);
    assertTrue(dataStore instanceof GeoGigDataStore);

    FeatureTypeInfo fti = factory.createFeatureType();
    fti.setNamespace(ns);
    fti.setCatalog(catalog);
    fti.setStore(dsInfo);
    fti.setSRS("EPSG:4326");
    fti.setName("Lines");
    fti.setAdvertised(true);
    fti.setEnabled(true);
    fti.setCqlFilter("INCLUDE");
    fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
    ReferencedEnvelope bounds = new ReferencedEnvelope(-180, 180, -90, 90, CRS.decode("EPSG:4326"));
    fti.setNativeBoundingBox(bounds);
    fti.setLatLonBoundingBox(bounds);
    catalog.add(fti);

    fti = catalog.getFeatureType(fti.getId());

    FeatureSource<? extends FeatureType, ? extends Feature> featureSource;
    featureSource = fti.getFeatureSource(null, null);
    assertNotNull(featureSource);
  }
Exemplo n.º 3
0
  @Test
  public void testRemoveWorkspace() throws Exception {
    WorkspaceInfo ws = dao.getCatalog().getFactory().createWorkspace();
    ws.setName("baz");
    dao.add(ws);

    assertNotNull(dao.getWorkspaceByName("baz"));
    int n = dao.getWorkspaces().size();

    dao.remove(ws);
    assertNull(dao.getWorkspaceByName("baz"));
    assertEquals(n - 1, dao.getWorkspaces().size());
  }
Exemplo n.º 4
0
  @Test
  public void testAddWorkspace() throws Exception {
    assertEquals(0, dao.getWorkspaces().size());

    WorkspaceInfo ws = dao.getCatalog().getFactory().createWorkspace();
    ws.setName("acme");
    assertNull(ws.getId());

    dao.add(ws);
    assertNotNull(ws.getId());

    assertEquals(1, dao.getWorkspaces().size());
    assertEquals(ws, dao.getWorkspace(ws.getId()));
  }
Exemplo n.º 5
0
  /**
   * Adds a workspace to the test setup.
   *
   * @param name The name of the workspace.
   * @param uri The namespace uri associated with the workspace.
   */
  public void addWorkspace(String name, String uri, Catalog catalog) {

    WorkspaceInfo ws = catalog.getWorkspaceByName(name);
    if (ws == null) {
      ws = catalog.getFactory().createWorkspace();
      ws.setName(name);
      catalog.add(ws);
    }

    NamespaceInfo ns = catalog.getNamespaceByPrefix(name);
    if (ns == null) {
      ns = catalog.getFactory().createNamespace();
      ns.setPrefix(name);
      ns.setURI(uri);
      catalog.add(ns);
    } else {
      ns.setURI(uri);
      catalog.save(ns);
    }
  }
Exemplo n.º 6
0
  @Test
  public void testDefaultWorkspace() throws Exception {
    testAddWorkspace();

    assertNull(dao.getDefaultWorkspace());
    WorkspaceInfo ws = dao.getWorkspaceByName("acme");
    dao.setDefaultWorkspace(ws);

    assertNotNull(dao.getDefaultWorkspace());
    assertEquals("acme", dao.getDefaultWorkspace().getName());

    ws = dao.getCatalog().getFactory().createWorkspace();
    ws.setName("bam");
    dao.add(ws);
    dao.setDefaultWorkspace(ws);

    assertEquals("bam", dao.getDefaultWorkspace().getName());

    dao.setDefaultWorkspace(null);
    assertNull(dao.getDefaultWorkspace());
  }
  // Would have put this on GeoServerImplTest, but it depends on WMS and WFS InfoImpl classes
  // which would lead to circular dependencies.
  @SuppressWarnings("unchecked")
  @Test
  public void testTypedServicesWithWorkspace() throws Exception {
    // Make a workspace
    WorkspaceInfo ws1 = geoServer.getCatalog().getFactory().createWorkspace();
    ws1.setName("TEST-WORKSPACE-1");
    geoServer.getCatalog().add(ws1);

    // Make a service for that workspace
    ServiceInfo ws1wms = new org.geoserver.wms.WMSInfoImpl();
    ws1wms.setWorkspace(ws1);
    ws1wms.setName("WMS1");
    ws1wms.setTitle("WMS for WS1");
    geoServer.add(ws1wms);

    // Make a second for that workspace
    ServiceInfo ws1wfs = new org.geoserver.wfs.WFSInfoImpl();
    ws1wfs.setWorkspace(ws1);
    ws1wfs.setName("WFS1");
    ws1wfs.setTitle("WFS for WS1");
    geoServer.add(ws1wfs);

    // Make a global service
    ServiceInfo gwms = new org.geoserver.wms.WMSInfoImpl();
    gwms.setName("WMSG");
    gwms.setTitle("Global WMS");
    geoServer.add(gwms);

    // Make a second global service
    ServiceInfo gwfs = new org.geoserver.wfs.WFSInfoImpl();
    gwfs.setName("WFSG");
    gwfs.setTitle("Global WFS");
    geoServer.add(gwfs);

    // Make a workspace
    WorkspaceInfo ws2 = geoServer.getCatalog().getFactory().createWorkspace();
    ws2.setName("TEST-WORKSPACE-2");
    geoServer.getCatalog().add(ws2);

    // Make a service for that workspace
    ServiceInfo ws2wms = new org.geoserver.wms.WMSInfoImpl();
    ws2wms.setWorkspace(ws2);
    ws2wms.setName("WMS2");
    ws2wms.setTitle("WMS for WS2");
    geoServer.add(ws2wms);

    // Make a second for that workspace
    ServiceInfo ws2wfs = new org.geoserver.wfs.WFSInfoImpl();
    ws2wfs.setWorkspace(ws2);
    ws2wfs.setName("WFS2");
    ws2wfs.setTitle("WFS for WS2");
    geoServer.add(ws2wfs);

    // Check that we get the services we expect to
    assertThat(geoServer.getService(org.geoserver.wms.WMSInfo.class), equalTo(gwms));
    assertThat(geoServer.getService(org.geoserver.wfs.WFSInfo.class), equalTo(gwfs));
    assertThat(
        (Collection<ServiceInfo>) geoServer.getServices(),
        allOf(hasItems(gwms, gwfs), not(hasItems(ws1wms, ws1wfs, ws2wms, ws2wfs))));
    assertThat(geoServer.getService(ws1, org.geoserver.wms.WMSInfo.class), equalTo(ws1wms));
    assertThat(geoServer.getService(ws1, org.geoserver.wfs.WFSInfo.class), equalTo(ws1wfs));
    assertThat(
        (Collection<ServiceInfo>) geoServer.getServices(ws1),
        allOf(hasItems(ws1wms, ws1wfs), not(hasItems(gwms, gwfs, ws2wms, ws2wfs))));
    assertThat(geoServer.getService(ws2, org.geoserver.wms.WMSInfo.class), equalTo(ws2wms));
    assertThat(geoServer.getService(ws2, org.geoserver.wfs.WFSInfo.class), equalTo(ws2wfs));
    assertThat(
        (Collection<ServiceInfo>) geoServer.getServices(ws2),
        allOf(hasItems(ws2wms, ws2wfs), not(hasItems(gwms, gwfs, ws1wms, ws1wfs))));
  }