Esempio n. 1
0
  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;
  }
Esempio n. 2
0
  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;
  }