@Override
 public void setUp() {
   defaults = GWCConfig.getOldDefaults();
   defaultVectorInfo = TileLayerInfoUtil.create(defaults);
   defaultVectorInfo.getMimeFormats().clear();
   defaultVectorInfo.getMimeFormats().addAll(defaults.getDefaultVectorCacheFormats());
 }
 /**
  * LayerInfo has been created, add a matching {@link GeoServerTileLayer}
  *
  * @see CatalogLayerEventListener#handleAddEvent
  * @see GWC#add(GeoServerTileLayer)
  */
 void createTileLayer(final LayerInfo layerInfo) {
   GWCConfig defaults = mediator.getConfig();
   if (defaults.isSane() && defaults.isCacheLayersByDefault()) {
     GridSetBroker gridSetBroker = mediator.getGridSetBroker();
     GeoServerTileLayer tileLayer = new GeoServerTileLayer(layerInfo, defaults, gridSetBroker);
     mediator.add(tileLayer);
   }
 }
Exemple #3
0
  @Test
  public void testAutoConfigureLayers() throws Exception {
    {
      GWCConfig insaneDefaults = new GWCConfig();
      insaneDefaults.setMetaTilingX(-1);
      assertFalse(insaneDefaults.isSane());
      try {
        mediator.autoConfigureLayers(Arrays.asList(tileLayer.getName()), insaneDefaults);
      } catch (IllegalArgumentException e) {
        assertTrue(true);
      }
    }

    try {
      mediator.autoConfigureLayers(Arrays.asList(tileLayer.getName()), defaults);
      fail("expected IAE, layer exists");
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    LayerInfo layer2 = mockLayer("layer2", new String[] {}, PublishedType.RASTER);
    LayerGroupInfo group2 = mockGroup("group2", layer, layer2);

    when(catalog.getLayerByName(eq(tileLayerName(layer2)))).thenReturn(layer2);
    when(catalog.getLayerGroupByName(eq(tileLayerName(group2)))).thenReturn(group2);

    List<String> layerNames = Arrays.asList(tileLayerName(layer2), tileLayerName(group2));

    when(tld.addLayer(any(GeoServerTileLayer.class))).thenReturn(config);
    mediator.autoConfigureLayers(layerNames, defaults);

    GeoServerTileLayerInfo expected1 =
        new GeoServerTileLayer(layer2, defaults, gridSetBroker).getInfo();
    GeoServerTileLayerInfo expected2 =
        new GeoServerTileLayer(group2, defaults, gridSetBroker).getInfo();

    ArgumentCaptor<GeoServerTileLayer> addCaptor =
        ArgumentCaptor.forClass(GeoServerTileLayer.class);

    verify(tld, times(2)).addLayer(addCaptor.capture());
    verify(config, times(2)).save();

    GeoServerTileLayerInfo actual1 = addCaptor.getAllValues().get(0).getInfo();
    GeoServerTileLayerInfo actual2 = addCaptor.getAllValues().get(1).getInfo();

    assertEquals(expected1, actual1);
    assertEquals(expected2, actual2);
  }
  /**
   * Creates a cached tile layer from the given Layer
   *
   * @param info the layer to cache
   * @param defaults default configuration
   */
  public static GeoServerTileLayerInfoImpl loadOrCreate(
      final LayerInfo layerInfo, final GWCConfig defaults) {
    GeoServerTileLayerInfoImpl info = LegacyTileLayerInfoLoader.load(layerInfo);
    if (info == null) {
      info = create(defaults);
      final ResourceInfo resource = layerInfo.getResource();
      if (resource instanceof FeatureTypeInfo) {
        info.getMimeFormats().clear();
        info.getMimeFormats().addAll(defaults.getDefaultVectorCacheFormats());
      } else if (resource instanceof CoverageInfo) {
        info.getMimeFormats().clear();
        info.getMimeFormats().addAll(defaults.getDefaultCoverageCacheFormats());
      }

      checkAutomaticStyles(layerInfo, info);
    }
    info.setName(tileLayerName(layerInfo));
    info.setId(layerInfo.getId());
    return info;
  }
Exemple #5
0
  @Test
  public void testIsServiceEnabled() {
    Service service = mock(Service.class);

    when(service.getPathName()).thenReturn("wms");
    defaults.setWMSCEnabled(true);
    assertTrue(mediator.isServiceEnabled(service));
    defaults.setWMSCEnabled(false);
    assertFalse(mediator.isServiceEnabled(service));

    when(service.getPathName()).thenReturn("tms");
    defaults.setTMSEnabled(true);
    assertTrue(mediator.isServiceEnabled(service));
    defaults.setTMSEnabled(false);
    assertFalse(mediator.isServiceEnabled(service));

    when(service.getPathName()).thenReturn("wmts");
    defaults.setWMTSEnabled(true);
    assertTrue(mediator.isServiceEnabled(service));
    defaults.setWMTSEnabled(false);
    assertFalse(mediator.isServiceEnabled(service));

    when(service.getPathName()).thenReturn("somethingElse");
    assertTrue(mediator.isServiceEnabled(service));
  }
Exemple #6
0
  @Before
  public void setUp() throws Exception {
    catalog = mock(Catalog.class);
    layer = mockLayer("testLayer", new String[] {"style1", "style2"}, PublishedType.RASTER);
    layerGroup = mockGroup("testGroup", layer);
    mockCatalog();

    defaults = GWCConfig.getOldDefaults();

    gwcConfigPersister = mock(GWCConfigPersister.class);
    when(gwcConfigPersister.getConfig()).thenReturn(defaults);

    storageBroker = mock(StorageBroker.class);
    gridSetBroker = new GridSetBroker(true, true);

    tileLayerInfo = TileLayerInfoUtil.loadOrCreate(layer, defaults);
    tileLayerGroupInfo = TileLayerInfoUtil.loadOrCreate(layerGroup, defaults);

    tileLayer = new GeoServerTileLayer(layer, gridSetBroker, tileLayerInfo);
    tileLayerGroup = new GeoServerTileLayer(layerGroup, gridSetBroker, tileLayerGroupInfo);

    tld = mock(TileLayerDispatcher.class);
    mockTileLayerDispatcher();

    config = mock(Configuration.class);
    tileBreeder = mock(TileBreeder.class);
    quotaStore = mock(QuotaStore.class);
    diskQuotaMonitor = mock(DiskQuotaMonitor.class);
    when(diskQuotaMonitor.getQuotaStore()).thenReturn(quotaStore);
    owsDispatcher = mock(Dispatcher.class);

    storageFinder = mock(DefaultStorageFinder.class);
    jdbcStorage = mock(JDBCConfigurationStorage.class);

    mediator =
        new GWC(
            gwcConfigPersister,
            storageBroker,
            tld,
            gridSetBroker,
            tileBreeder,
            diskQuotaMonitor,
            owsDispatcher,
            catalog,
            storageFinder,
            jdbcStorage);

    GWC.set(mediator);
  }
 /**
  * If either a {@link LayerInfo} or {@link LayerGroupInfo} has been added to the {@link Catalog} ,
  * create a corresponding GWC TileLayer depending on the value of {@link
  * GWCConfig#isCacheLayersByDefault()}.
  *
  * @see org.geoserver.catalog.event.CatalogListener#handleAddEvent
  * @see GWC#createLayer(LayerInfo)
  * @see GWC#createLayer(LayerGroupInfo)
  */
 public void handleAddEvent(CatalogAddEvent event) throws CatalogException {
   GWCConfig config = mediator.getConfig();
   boolean sane = config.isSane();
   boolean cacheLayersByDefault = config.isCacheLayersByDefault();
   if (!cacheLayersByDefault) {
     return;
   }
   if (!sane) {
     log.info(
         "Ignoring auto-creation of tile layer for "
             + event.getSource()
             + ": global gwc settings are not sane");
   }
   Object obj = event.getSource();
   // We only handle layers here. Layer groups are initially empty
   if (obj instanceof LayerInfo) {
     log.finer("Handling add event: " + obj);
     LayerInfo layerInfo = (LayerInfo) obj;
     createTileLayer(layerInfo);
   } else if (obj instanceof LayerGroupInfo) {
     LayerGroupInfo lgi = (LayerGroupInfo) obj;
     createTileLayer(lgi);
   }
 }
  public void testLoadLayerGroup() {
    LayerGroupInfoImpl lg = mockGroup("tesGroup", mockLayer("L1"), mockLayer("L2"));

    assertNull(LegacyTileLayerInfoLoader.load(lg));
    GeoServerTileLayerInfo info = defaultVectorInfo;
    info.getMimeFormats().clear();
    info.getMimeFormats().addAll(defaults.getDefaultOtherCacheFormats());

    LegacyTileLayerInfoLoader.save(info, lg.getMetadata());

    GeoServerTileLayerInfo actual;
    actual = LegacyTileLayerInfoLoader.load(lg);

    info.setId(lg.getId());
    info.setName(GWC.tileLayerName(lg));
    assertEquals(info, actual);
  }
  /**
   * Creates a default tile layer info based on the global defaults, public only for unit testing
   * purposes.
   */
  public static GeoServerTileLayerInfoImpl create(GWCConfig defaults) {

    GeoServerTileLayerInfoImpl info = new GeoServerTileLayerInfoImpl();

    info.setEnabled(defaults.isCacheLayersByDefault());
    info.setAutoCacheStyles(defaults.isCacheNonDefaultStyles());

    for (String gsetId : defaults.getDefaultCachingGridSetIds()) {
      XMLGridSubset subset = new XMLGridSubset();
      subset.setGridSetName(gsetId);
      info.getGridSubsets().add(subset);
    }

    info.getMimeFormats().addAll(defaults.getDefaultOtherCacheFormats());

    info.setGutter(defaults.getGutter());
    info.setMetaTilingX(defaults.getMetaTilingX());
    info.setMetaTilingY(defaults.getMetaTilingY());
    info.setInMemoryCached(true);

    return info;
  }