LayerInfo createLayer(ResourceInfo r, String name, NamespaceInfo ns) { String lId = newId(); StyleInfo s = styles.peekLast(); final LayerInfo l = createNiceMock(LayerInfo.class); layers.add(l); expect(l.getId()).andReturn(lId).anyTimes(); expect(l.getName()).andReturn(name).anyTimes(); expect(l.getType()).andReturn(LayerInfo.Type.VECTOR).anyTimes(); expect(l.getResource()).andReturn(r).anyTimes(); expect(l.getDefaultStyle()).andReturn(s).anyTimes(); expect(l.isEnabled()).andReturn(true).anyTimes(); expect(l.isAdvertised()).andReturn(true).anyTimes(); expect(catalog.getLayer(lId)).andReturn(l).anyTimes(); expect(catalog.getLayerByName(name)).andReturn(l).anyTimes(); expect(catalog.getLayerByName(ns.getPrefix() + ":" + name)).andReturn(l).anyTimes(); expect(catalog.getLayerByName(new NameImpl(ns.getPrefix(), name))).andReturn(l).anyTimes(); expect(catalog.getLayerByName(new NameImpl(ns.getURI(), name))).andReturn(l).anyTimes(); expect(catalog.getLayers(r)).andReturn(Arrays.asList(l)).anyTimes(); l.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(l); } }) .anyTimes(); callback.onLayer(name, l, this); return l; }
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); }
@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); }
public MockCatalogBuilder dataStore(String name) { String dsId = newId(); final WorkspaceInfo ws = workspaces.peekLast(); final NamespaceInfo ns = namespaces.peekLast(); final DataStoreInfo ds = createNiceMock(DataStoreInfo.class); dataStores.add(ds); initStore(ds, DataStoreInfo.class, dsId, name, ws); // setup the property data store final File propDir = new File(dataDirRoot, name); HashMap cxParams = new HashMap(); cxParams.put(PropertyDataStoreFactory.DIRECTORY.key, propDir); cxParams.put(PropertyDataStoreFactory.NAMESPACE.key, ns.getURI()); expect(ds.getConnectionParameters()).andReturn(cxParams).anyTimes(); try { expect(ds.getDataStore(null)) .andAnswer( (IAnswer) new IAnswer<DataAccess>() { @Override public DataAccess answer() throws Throwable { return new PropertyDataStore(propDir, ns.getURI()); } }) .anyTimes(); } catch (IOException e) { } expect(catalog.getDataStore(dsId)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(name)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(ws.getName(), name)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(ws, name)).andReturn(ds).anyTimes(); ds.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ds); } }) .anyTimes(); callback.onStore(name, ds, ws, this); replay(ds); return this; }
@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 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()); }
@Override protected String handleObjectPost(Object object) throws Exception { String workspace = getAttribute("workspace"); DataStoreInfo ds = (DataStoreInfo) object; if (ds.getWorkspace() != null) { // ensure the specifried workspace matches the one dictated by the uri WorkspaceInfo ws = (WorkspaceInfo) ds.getWorkspace(); if (!workspace.equals(ws.getName())) { throw new RestletException( "Expected workspace " + workspace + " but client specified " + ws.getName(), Status.CLIENT_ERROR_FORBIDDEN); } } else { ds.setWorkspace(catalog.getWorkspaceByName(workspace)); } ds.setEnabled(true); // if no namespace parameter set, set it // TODO: we should really move this sort of thing to be something central if (!ds.getConnectionParameters().containsKey("namespace")) { WorkspaceInfo ws = ds.getWorkspace(); NamespaceInfo ns = catalog.getNamespaceByPrefix(ws.getName()); if (ns == null) { ns = catalog.getDefaultNamespace(); } if (ns != null) { ds.getConnectionParameters().put("namespace", ns.getURI()); } } // attempt to set the datastore type try { DataAccessFactory factory = DataStoreUtils.aquireFactory(ds.getConnectionParameters()); ds.setType(factory.getDisplayName()); } catch (Exception e) { LOGGER.warning("Unable to determine datastore type from connection parameters"); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "", e); } } catalog.validate((DataStoreInfo) object, false).throwIfInvalid(); catalog.add((DataStoreInfo) object); LOGGER.info("POST data store " + ds.getName()); return ds.getName(); }
/** * 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); } }
@Test public void testDefaultNamespace() throws Exception { testAddNamespace(); assertNull(dao.getDefaultNamespace()); NamespaceInfo ws = dao.getNamespaceByPrefix("acme"); dao.setDefaultNamespace(ws); assertNotNull(dao.getDefaultNamespace()); assertEquals("acme", dao.getDefaultNamespace().getName()); ws = dao.getCatalog().getFactory().createNamespace(); ws.setPrefix("bam"); dao.add(ws); dao.setDefaultNamespace(ws); assertEquals("bam", dao.getDefaultNamespace().getName()); dao.setDefaultNamespace(null); assertNull(dao.getDefaultNamespace()); }
public MockCatalogBuilder workspace(String name, String uri) { String wsId = newId(); String nsId = newId(); final WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); workspaces.add(ws); expect(ws.getId()).andReturn(wsId).anyTimes(); expect(ws.getName()).andReturn(name).anyTimes(); expect(ws.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(catalog.getWorkspace(wsId)).andReturn(ws).anyTimes(); expect(catalog.getWorkspaceByName(name)).andReturn(ws).anyTimes(); final NamespaceInfo ns = createNiceMock(NamespaceInfo.class); namespaces.add(ns); expect(ns.getId()).andReturn(nsId).anyTimes(); expect(ns.getName()).andReturn(name).anyTimes(); expect(ns.getPrefix()).andReturn(name).anyTimes(); expect(ns.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(catalog.getNamespace(nsId)).andReturn(ns).anyTimes(); expect(catalog.getNamespaceByPrefix(name)).andReturn(ns).anyTimes(); expect(catalog.getNamespaceByURI(uri)).andReturn(ns).anyTimes(); ws.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ws); } }) .anyTimes(); ns.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ns); } }) .anyTimes(); callback.onWorkspace(name, ws, this); replay(ws, ns); return this; }
@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())); }
<T extends ResourceInfo> void initResource( T r, Class<T> clazz, String rId, String name, StoreInfo s, NamespaceInfo ns, String srs, ProjectionPolicy projPolicy, ReferencedEnvelope envelope, ReferencedEnvelope latLonEnvelope) { expect(r.getId()).andReturn(rId).anyTimes(); expect(r.getName()).andReturn(name).anyTimes(); expect(r.getQualifiedName()).andReturn(new NameImpl(ns.getURI(), name)).anyTimes(); expect(r.getNativeName()).andReturn(name).anyTimes(); expect(r.getQualifiedNativeName()).andReturn(new NameImpl(ns.getURI(), name)).anyTimes(); expect(r.getTitle()).andReturn(name).anyTimes(); expect(r.getAbstract()).andReturn("abstract about " + name).anyTimes(); expect(r.getStore()).andReturn(s).anyTimes(); expect(r.getNamespace()).andReturn(ns).anyTimes(); srs = srs != null ? srs : "EPSG:4326"; expect(r.getSRS()).andReturn(srs).anyTimes(); try { expect(r.getNativeCRS()).andReturn(CRS.decode(srs)); } catch (Exception e) { throw new RuntimeException(e); } expect(r.getKeywords()).andReturn((List) Arrays.asList(new Keyword(name))).anyTimes(); expect(r.isEnabled()).andReturn(true).anyTimes(); expect(r.isAdvertised()).andReturn(true).anyTimes(); expect(r.getProjectionPolicy()).andReturn(projPolicy).anyTimes(); expect(r.getLatLonBoundingBox()).andReturn(latLonEnvelope).anyTimes(); ; expect(r.getNativeBoundingBox()).andReturn(envelope).anyTimes(); expect(catalog.getResource(rId, clazz)).andReturn(r).anyTimes(); expect(catalog.getResourceByName(ns.getPrefix() + ":" + name, clazz)).andReturn(r).anyTimes(); expect(catalog.getResourceByName(ns.getPrefix() + ":" + name, ResourceInfo.class)) .andReturn(r) .anyTimes(); expect(catalog.getResourceByName(name, clazz)).andReturn(r).anyTimes(); expect(catalog.getResourceByName(name, ResourceInfo.class)).andReturn(r).anyTimes(); expect(catalog.getResourceByName(new NameImpl(ns.getPrefix(), name), clazz)) .andReturn(r) .anyTimes(); expect(catalog.getResourceByName(new NameImpl(ns.getPrefix(), name), ResourceInfo.class)) .andReturn(r) .anyTimes(); expect(catalog.getResourceByName(new NameImpl(ns.getURI(), name), clazz)) .andReturn(r) .anyTimes(); expect(catalog.getResourceByName(new NameImpl(ns.getURI(), name), ResourceInfo.class)) .andReturn(r) .anyTimes(); expect(catalog.getResourceByName(ns, name, clazz)).andReturn(r).andReturn(r).anyTimes(); expect(catalog.getResourceByName(ns, name, ResourceInfo.class)) .andReturn(r) .andReturn(r) .anyTimes(); expect(catalog.getResourceByName(ns.getPrefix(), name, clazz)).andReturn(r).anyTimes(); expect(catalog.getResourceByName(ns.getPrefix(), name, ResourceInfo.class)) .andReturn(r) .anyTimes(); // expect(catalog.getResourceByName(or(eq(ns.getPrefix()), eq(ns.getURI())), name, // clazz)).andReturn(r).anyTimes(); expect(catalog.getResourceByStore(s, name, clazz)).andReturn(r).anyTimes(); expect(catalog.getResourceByStore(s, name, ResourceInfo.class)).andReturn(r).anyTimes(); }
public MockCatalogBuilder coverage(QName qName, String fileName, String srs, Class scope) { scope = scope != null ? scope : getClass(); String cId = newId(); final CoverageStoreInfo cs = coverageStores.peekLast(); NamespaceInfo ns = namespaces.peekLast(); final String name = qName.getLocalPart(); File dir = new File(dataDirRoot, name); dir.mkdir(); try { IOUtils.copy(scope.getResourceAsStream(fileName), new File(dir, fileName)); } catch (IOException e) { throw new RuntimeException(e); } // initialize the mock by actually building a real one first CatalogBuilder cb = new CatalogBuilder(new CatalogImpl()); cb.setStore(cs); GridCoverage2DReader reader = cs.getFormat().getReader(cs.getURL()); if (reader == null) { throw new RuntimeException("No reader for " + cs.getURL()); } CoverageInfo real = null; try { real = cb.buildCoverage(reader, null); } catch (Exception e) { throw new RuntimeException(e); } final CoverageInfo c = createNiceMock(CoverageInfo.class); coverages.add(c); final List<CoverageInfo> coverageList = coverages; if (srs == null) { srs = real.getSRS(); } initResource( c, CoverageInfo.class, cId, name, cs, ns, srs, real.getProjectionPolicy(), real.getNativeBoundingBox(), real.getLatLonBoundingBox()); expect(c.getDefaultInterpolationMethod()) .andReturn(real.getDefaultInterpolationMethod()) .anyTimes(); expect(c.getDimensions()).andReturn(real.getDimensions()).anyTimes(); expect(c.getGrid()).andReturn(real.getGrid()).anyTimes(); expect(c.getInterpolationMethods()).andReturn(real.getInterpolationMethods()).anyTimes(); expect(c.getRequestSRS()).andReturn(real.getRequestSRS()).anyTimes(); expect(c.getResponseSRS()).andReturn(real.getResponseSRS()).anyTimes(); try { expect(c.getGridCoverageReader(null, null)).andReturn(reader).anyTimes(); } catch (IOException e) { } expect(catalog.getCoverageByName(or(eq(name), eq(ns.getPrefix() + ":" + name)))) .andReturn(c) .anyTimes(); expect( catalog.getCoverageByName( or(eq(new NameImpl(ns.getPrefix(), name)), eq(new NameImpl(ns.getURI(), name))))) .andReturn(c) .anyTimes(); expect(catalog.getCoverageByName(ns, name)).andReturn(c).anyTimes(); expect(catalog.getCoverageByName(ns.getPrefix(), name)).andReturn(c).anyTimes(); // expect(catalog.getFeatureTypeByName(or(eq(ns.getPrefix()), eq(ns.getURI())), name)) // .andReturn(ft).anyTimes(); // expect(catalog.getCoverageByStore(cs, name)).andReturn(c).anyTimes(); expect(catalog.getCoveragesByStore(cs)).andReturn(coverageList).anyTimes(); expect(catalog.getCoverageByCoverageStore(cs, name)).andReturn(c).anyTimes(); c.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(c); } }) .anyTimes(); callback.onResource(name, c, cs, this); replay(c, createLayer(c, name, ns)); return this; }
public String getNameSpacePrefix(final String nsUri) { Catalog catalog = getCatalog(); NamespaceInfo ns = catalog.getNamespaceByURI(nsUri); return ns == null ? null : ns.getPrefix(); }
private void handleRename( final GeoServerTileLayerInfo tileLayerInfo, final CatalogInfo source, final List<String> changedProperties, final List<Object> oldValues, final List<Object> newValues) { final int nameIndex = changedProperties.indexOf("name"); final int namespaceIndex = changedProperties.indexOf("namespace"); String oldLayerName; String newLayerName; if (source instanceof ResourceInfo) { // covers LayerInfo, CoverageInfo, and WMSLayerInfo // must cover prefix:name final ResourceInfo resourceInfo = (ResourceInfo) source; final NamespaceInfo currNamespace = resourceInfo.getNamespace(); final NamespaceInfo oldNamespace; if (namespaceIndex > -1) { // namespace changed oldNamespace = (NamespaceInfo) oldValues.get(namespaceIndex); } else { oldNamespace = currNamespace; } newLayerName = resourceInfo.prefixedName(); if (nameIndex > -1) { oldLayerName = (String) oldValues.get(nameIndex); } else { oldLayerName = resourceInfo.getName(); } oldLayerName = oldNamespace.getPrefix() + ":" + oldLayerName; } else { // it's a layer group, no need to worry about namespace oldLayerName = tileLayerInfo.getName(); newLayerName = tileLayerName((LayerGroupInfo) source); } if (!oldLayerName.equals(newLayerName)) { tileLayerInfo.setName(newLayerName); // notify the mediator of the rename so it changes the name of the layer in GWC without // affecting its caches GridSetBroker gridSetBroker = mediator.getGridSetBroker(); final GeoServerTileLayer oldTileLayer = (GeoServerTileLayer) mediator.getTileLayerByName(oldLayerName); checkState( null != oldTileLayer, "hanldeRename: old tile layer not found: '" + oldLayerName + "'. New name: '" + newLayerName + "'"); final GeoServerTileLayer modifiedTileLayer; if (oldTileLayer.getLayerInfo() != null) { LayerInfo layerInfo = oldTileLayer.getLayerInfo(); modifiedTileLayer = new GeoServerTileLayer(layerInfo, gridSetBroker, tileLayerInfo); } else { LayerGroupInfo layerGroup = oldTileLayer.getLayerGroupInfo(); modifiedTileLayer = new GeoServerTileLayer(layerGroup, gridSetBroker, tileLayerInfo); } mediator.save(modifiedTileLayer); } }
@Override public void setObject(Object object) { NamespaceInfo namespaceInfo = (NamespaceInfo) object; String nsUri = namespaceInfo.getURI(); super.setObject(nsUri); }
public MockCatalogBuilder featureType( final String name, String srs, ProjectionPolicy projPolicy, ReferencedEnvelope envelope, ReferencedEnvelope latLonEnvelope) { String ftId = newId(); final DataStoreInfo ds = dataStores.peekLast(); NamespaceInfo ns = namespaces.peekLast(); final FeatureTypeInfo ft = createNiceMock(FeatureTypeInfo.class); featureTypes.add(ft); initResource( ft, FeatureTypeInfo.class, ftId, name, ds, ns, srs, projPolicy, envelope, latLonEnvelope); expect(ft.getNumDecimals()).andReturn(8); // setup the property file data File propDir = new File(dataDirRoot, ds.getName()); propDir.mkdirs(); String fileName = name + ".properties"; try { IOUtils.copy(getClass().getResourceAsStream(fileName), new File(propDir, fileName)); } catch (IOException e) { throw new RuntimeException(e); } try { expect(ft.getFeatureType()) .andAnswer( new IAnswer<FeatureType>() { @Override public FeatureType answer() throws Throwable { return ((DataStore) ds.getDataStore(null)).getSchema(name); } }) .anyTimes(); expect(ft.getFeatureSource(null, null)) .andAnswer( (IAnswer) new IAnswer<FeatureSource>() { @Override public FeatureSource answer() throws Throwable { return ((DataStore) ds.getDataStore(null)).getFeatureSource(name); } }) .anyTimes(); } catch (IOException e) { } expect(catalog.getFeatureTypeByName(or(eq(name), eq(ns.getPrefix() + ":" + name)))) .andReturn(ft) .anyTimes(); expect( catalog.getFeatureTypeByName( or(eq(new NameImpl(ns.getPrefix(), name)), eq(new NameImpl(ns.getURI(), name))))) .andReturn(ft) .anyTimes(); expect(catalog.getFeatureTypeByName(ns, name)).andReturn(ft).anyTimes(); expect(catalog.getFeatureTypeByName(ns.getPrefix(), name)).andReturn(ft).anyTimes(); // expect(catalog.getFeatureTypeByName(or(eq(ns.getPrefix()), eq(ns.getURI())), name)) // .andReturn(ft).anyTimes(); expect(catalog.getFeatureTypeByStore(ds, name)).andReturn(ft).anyTimes(); expect(catalog.getFeatureTypeByDataStore(ds, name)).andReturn(ft).anyTimes(); ft.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ft); } }) .anyTimes(); callback.onResource(name, ft, ds, this); replay(ft, createLayer(ft, name, ns)); return this; }
public String getNamespaceByPrefix(final String prefix) { Catalog catalog = getCatalog(); NamespaceInfo namespaceInfo = catalog.getNamespaceByPrefix(prefix); return namespaceInfo == null ? null : namespaceInfo.getURI(); }