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);
  }
  @Before
  public void setUp() throws URISyntaxException, IOException {
    outputFormat = new HTMLFeatureInfoOutputFormat(getWMS());

    currentTemplate = "test_content.ftl";
    // configure template loader
    GeoServerTemplateLoader templateLoader =
        new GeoServerTemplateLoader(this.getClass(), getDataDirectory()) {

          @Override
          public Object findTemplateSource(String path) throws IOException {
            String templatePath;
            if (path.toLowerCase().contains("content")) {
              templatePath = currentTemplate;

            } else {
              templatePath = "empty.ftl";
            }
            try {
              return new File(this.getClass().getResource(templateFolder + templatePath).toURI());
            } catch (URISyntaxException e) {
              return null;
            }
          }
        };
    outputFormat.templateLoader = templateLoader;

    // test request with some parameters to use in templates
    Request request = new Request();
    parameters = new HashMap<String, Object>();
    parameters.put("LAYER", "testLayer");
    Map<String, String> env = new HashMap<String, String>();
    env.put("TEST1", "VALUE1");
    env.put("TEST2", "VALUE2");
    parameters.put("ENV", env);
    request.setKvp(parameters);

    Dispatcher.REQUEST.set(request);

    final FeatureTypeInfo featureType = getFeatureTypeInfo(MockData.PRIMITIVEGEOFEATURE);

    fcType = WfsFactory.eINSTANCE.createFeatureCollectionType();
    fcType.getFeature().add(featureType.getFeatureSource(null, null).getFeatures());

    // fake layer list
    List<MapLayerInfo> queryLayers = new ArrayList<MapLayerInfo>();
    LayerInfo layerInfo = new LayerInfoImpl();
    layerInfo.setType(PublishedType.VECTOR);
    ResourceInfo resourceInfo = new FeatureTypeInfoImpl(null);
    NamespaceInfo nameSpace = new NamespaceInfoImpl();
    nameSpace.setPrefix("topp");
    nameSpace.setURI("http://www.topp.org");
    resourceInfo.setNamespace(nameSpace);
    layerInfo.setResource(resourceInfo);
    MapLayerInfo mapLayerInfo = new MapLayerInfo(layerInfo);
    queryLayers.add(mapLayerInfo);
    getFeatureInfoRequest = new GetFeatureInfoRequest();
    getFeatureInfoRequest.setQueryLayers(queryLayers);
  }
Exemple #3
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);
    }
  }
  @BeforeClass
  public static void setUpData() throws Exception {
    MonitorDAO dao = new MemoryMonitorDAO();
    new MonitorTestData(dao).setup();

    MonitorConfig mc =
        new MonitorConfig() {

          @Override
          public MonitorDAO createDAO() {
            MonitorDAO dao = new MemoryMonitorDAO();
            try {
              new MonitorTestData(dao).setup();
              return dao;
            } catch (java.text.ParseException e) {
              throw new RuntimeException(e);
            }
          }

          @Override
          public BboxMode getBboxMode() {
            return BboxMode.FULL;
          }
        };

    GeoServer gs = createMock(GeoServer.class);
    monitor = new Monitor(mc);
    monitor.setServer(gs);

    catalog = new CatalogImpl();

    expect(gs.getCatalog()).andStubReturn(catalog);
    replay(gs);

    NamespaceInfo ns = catalog.getFactory().createNamespace();
    ns.setPrefix("acme");
    ns.setURI("http://acme.org");
    catalog.add(ns);
    DataStoreInfo ds = catalog.getFactory().createDataStore();
    FeatureTypeInfo ftFoo = catalog.getFactory().createFeatureType();
    ftFoo.setName("foo");
    ftFoo.setSRS("EPSG:4326");
    ftFoo.setNamespace(ns);
    ftFoo.setStore(ds);
    catalog.add(ftFoo);
    FeatureTypeInfo ftBar = catalog.getFactory().createFeatureType();
    ftBar.setName("bar");
    ftBar.setSRS("EPSG:3348");
    ftBar.setNamespace(ns);
    ftBar.setStore(ds);
    catalog.add(ftBar);
  }
  @Test
  public void testRemoveNamespace() throws Exception {
    NamespaceInfo ws = dao.getCatalog().getFactory().createNamespace();
    ws.setPrefix("baz");
    ws.setURI("http://baz.org");
    dao.add(ws);

    assertNotNull(dao.getNamespaceByPrefix("baz"));
    int n = dao.getNamespaces().size();

    dao.remove(ws);
    assertNull(dao.getNamespaceByPrefix("baz"));
    assertEquals(n - 1, dao.getNamespaces().size());
  }
  @Test
  public void testModifyNamespace() throws Exception {
    NamespaceInfo ws = dao.getCatalog().getFactory().createNamespace();
    ws.setPrefix("foo");
    ws.setURI("http://foo.org");
    dao.add(ws);

    ws = dao.getNamespaceByPrefix("foo");
    ws.setPrefix("bar");
    dao.save(ws);

    assertNull(dao.getNamespaceByPrefix("foo"));
    assertNotNull(dao.getNamespaceByPrefix("bar"));
  }
  @Test
  public void testAddNamespace() throws Exception {
    assertEquals(0, dao.getNamespaces().size());

    NamespaceInfo ws = dao.getCatalog().getFactory().createNamespace();
    ws.setPrefix("acme");
    ws.setURI("http://acme.com");
    assertNull(ws.getId());

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

    assertEquals(1, dao.getNamespaces().size());
    assertEquals(ws, dao.getNamespace(ws.getId()));
  }