Exemplo n.º 1
0
  @RunTestSetup
  @Test
  public void testGeoServerReload() throws Exception {
    Catalog cat = getCatalog();
    FeatureTypeInfo lakes =
        cat.getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
    assertFalse("foo".equals(lakes.getTitle()));

    GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader());
    File info = dd.findResourceFile(lakes);
    // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml");

    FileReader in = new FileReader(info);
    Element dom = ReaderUtils.parse(in);
    Element title = ReaderUtils.getChildElement(dom, "title");
    title.getFirstChild().setNodeValue("foo");

    OutputStream output = new FileOutputStream(info);
    try {
      TransformerFactory.newInstance()
          .newTransformer()
          .transform(new DOMSource(dom), new StreamResult(output));
    } finally {
      output.close();
    }

    getGeoServer().reload();
    lakes =
        cat.getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
    assertEquals("foo", lakes.getTitle());
  }
Exemplo n.º 2
0
  @Test
  public void testCacheClearing() throws IOException {
    cleared = false;
    ResourcePool pool =
        new ResourcePool(getCatalog()) {
          @Override
          public void clear(FeatureTypeInfo info) {
            cleared = true;
            super.clear(info);
          }
        };
    FeatureTypeInfo info =
        getCatalog()
            .getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());

    assertNotNull(pool.getFeatureType(info));
    info.setTitle("changed");

    assertFalse(cleared);
    getCatalog().save(info);
    assertTrue(cleared);

    cleared = false;
    assertNotNull(pool.getFeatureType(info));

    for (LayerInfo l : getCatalog().getLayers(info)) {
      getCatalog().remove(l);
    }
    getCatalog().remove(info);
    assertTrue(cleared);
  }
Exemplo n.º 3
0
 /**
  * Test that the {@link FeatureType} cache returns the same instance every time. This is assumed
  * by some nasty code in other places that tampers with the CRS. If a new {@link FeatureType} is
  * constructed for the same {@link FeatureTypeInfo}, Bad Things Happen (TM).
  */
 @Test
 public void testFeatureTypeCacheInstance() throws Exception {
   ResourcePool pool = ResourcePool.create(getCatalog());
   FeatureTypeInfo info =
       getCatalog()
           .getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
   FeatureType ft1 = pool.getFeatureType(info);
   FeatureType ft2 = pool.getFeatureType(info);
   FeatureType ft3 = pool.getFeatureType(info);
   assertSame(ft1, ft2);
   assertSame(ft1, ft3);
 }
Exemplo n.º 4
0
  @Test
  public void testAttributeCache() throws Exception {
    final Catalog catalog = getCatalog();
    ResourcePool pool = ResourcePool.create(catalog);

    // clean up the lakes type
    FeatureTypeInfo oldInfo =
        catalog.getFeatureTypeByName(
            MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
    List<LayerInfo> layers = catalog.getLayers(oldInfo);
    for (LayerInfo layerInfo : layers) {
      catalog.remove(layerInfo);
    }
    catalog.remove(oldInfo);

    // rebuild as new
    CatalogBuilder builder = new CatalogBuilder(catalog);
    builder.setStore(
        catalog.getStoreByName(MockData.CITE_PREFIX, MockData.CITE_PREFIX, DataStoreInfo.class));
    FeatureTypeInfo info =
        builder.buildFeatureType(
            new NameImpl(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()));

    // non persisted state, caching should not occurr
    List<AttributeTypeInfo> att1 = pool.getAttributes(info);
    List<AttributeTypeInfo> att2 = pool.getAttributes(info);
    assertNotSame(att1, att2);
    assertEquals(att1, att2);

    // save it, making it persistent
    catalog.add(info);

    // first check caching actually works against persisted type infos
    List<AttributeTypeInfo> att3 = pool.getAttributes(info);
    List<AttributeTypeInfo> att4 = pool.getAttributes(info);
    assertSame(att3, att4);
    assertNotSame(att1, att3);
    assertEquals(att1, att3);
  }