public void fireModified( CatalogInfo object, List propertyNames, List oldValues, List newValues) { CatalogModifyEventImpl event = new CatalogModifyEventImpl(); event.setSource(object); event.setPropertyNames(propertyNames); event.setOldValues(oldValues); event.setNewValues(newValues); event(event); }
protected void setUp() throws Exception { mockMediator = mock(GWC.class); mockStyle = mock(StyleInfo.class); when(mockStyle.getName()).thenReturn(STYLE_NAME); mockResourceInfo = mock(FeatureTypeInfo.class); when(mockResourceInfo.prefixedName()).thenReturn(PREFIXED_RESOURCE_NAME); mockLayerInfo = mock(LayerInfo.class); when(mockLayerInfo.getResource()).thenReturn(mockResourceInfo); mockTileLayer = mock(GeoServerTileLayer.class); mockTileLayerInfo = mock(GeoServerTileLayerInfoImpl.class); ImmutableSet<String> empty = ImmutableSet.of(); when(mockTileLayerInfo.cachedStyles()).thenReturn(empty); when(mockTileLayer.getLayerInfo()).thenReturn(mockLayerInfo); when(mockTileLayer.getInfo()).thenReturn(mockTileLayerInfo); when(mockTileLayer.getName()).thenReturn(PREFIXED_RESOURCE_NAME); when(mockMediator.getTileLayersForStyle(eq(STYLE_NAME))).thenReturn( Collections.singletonList(mockTileLayer)); listener = new CatalogStyleChangeListener(mockMediator); styleNameModifyEvent = new CatalogModifyEventImpl(); styleNameModifyEvent.setSource(mockStyle); styleNameModifyEvent.setPropertyNames(Arrays.asList("name")); styleNameModifyEvent.setOldValues(Arrays.asList(STYLE_NAME)); styleNameModifyEvent.setNewValues(Arrays.asList(STYLE_NAME_MODIFIED)); }
public void testIgnorableChange() throws Exception { // not a name change styleNameModifyEvent.setPropertyNames(Arrays.asList("fileName")); listener.handleModifyEvent(styleNameModifyEvent); // name didn't change at all styleNameModifyEvent.setPropertyNames(Arrays.asList("name")); styleNameModifyEvent.setOldValues(Arrays.asList(STYLE_NAME)); styleNameModifyEvent.setNewValues(Arrays.asList(STYLE_NAME)); listener.handleModifyEvent(styleNameModifyEvent); // not a style change styleNameModifyEvent.setSource(mock(LayerInfo.class)); listener.handleModifyEvent(styleNameModifyEvent); // a change in the name of the default style should not cause a truncate verify(mockMediator, never()).truncateByLayerAndStyle(anyString(), anyString()); // nor a save, as the default style name is dynamic verify(mockMediator, never()).save((GeoServerTileLayer) anyObject()); verify(mockTileLayer, never()).getInfo(); verify(mockTileLayerInfo, never()).cachedStyles(); }
@Test public void testCatalogModifyEventHandling() throws Exception { // create a catalog modify event that include properties of type catalog CatalogModifyEventImpl catalogModifyEvent = new CatalogModifyEventImpl(); catalogModifyEvent.setPropertyNames( Arrays.asList("propertyA", "propertyB", "propertyC", "propertyD")); catalogModifyEvent.setOldValues(Arrays.asList("value", new CatalogImpl(), 50, null)); catalogModifyEvent.setNewValues( Arrays.asList("new_value", new CatalogImpl(), null, new CatalogImpl())); // serialise the event and deserialize it JMSCatalogModifyEventHandlerSPI handler = new JMSCatalogModifyEventHandlerSPI(0, null, new XStream(), null); String serializedEvent = handler.createHandler().serialize(catalogModifyEvent); CatalogEvent newEvent = handler.createHandler().deserialize(serializedEvent); // check the deserialized event assertThat(newEvent, notNullValue()); assertThat(newEvent, instanceOf(CatalogModifyEvent.class)); CatalogModifyEvent newModifyEvent = (CatalogModifyEvent) newEvent; // check properties names assertThat(newModifyEvent.getPropertyNames().size(), is(2)); assertThat( newModifyEvent.getPropertyNames(), CoreMatchers.hasItems("propertyA", "propertyC")); // check old values assertThat(newModifyEvent.getOldValues().size(), is(2)); assertThat(newModifyEvent.getOldValues(), CoreMatchers.hasItems("value", 50)); // check new values assertThat(newModifyEvent.getNewValues().size(), is(2)); assertThat(newModifyEvent.getNewValues(), CoreMatchers.hasItems("new_value", null)); } }