@Test public void onEvent() throws Exception { when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki"); XWikiDocument doc = mock(XWikiDocument.class); BaseObject obj1 = mock(BaseObject.class); BaseObject obj2 = mock(BaseObject.class); List<BaseObject> objList = new ArrayList<>(); DocumentReference ssxDocRef = new DocumentReference("wiki", "XWiki", "StyleSheetExtension"); when(doc.getXObjects(eq(ssxDocRef))).thenReturn(objList); objList.add(obj1); objList.add(null); objList.add(obj2); when(obj1.getStringValue("contentType")).thenReturn("CSS"); when(obj2.getStringValue("contentType")).thenReturn("LESS"); when(obj2.getNumber()).thenReturn(2); DocumentReference documentReference = new DocumentReference("wiki", "Space", "Doc"); when(doc.getDocumentReference()).thenReturn(documentReference); ComponentManager rootComponentManager = mock(ComponentManager.class); Utils.setComponentManager(rootComponentManager); ComponentManager contextComponentManager = mock(ComponentManager.class); when(rootComponentManager.getInstance(ComponentManager.class, "context")).thenReturn(contextComponentManager); EntityReferenceSerializer entityReferenceSerializer = mock(EntityReferenceSerializer.class); when(contextComponentManager.getInstance(EntityReferenceSerializer.TYPE_STRING, "compactwiki")) .thenReturn(entityReferenceSerializer); when(entityReferenceSerializer.serialize(any(EntityReference.class), any(EntityReference.class))) .thenReturn("objName"); ObjectPropertyReference objPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, 2, documentReference)); LESSObjectPropertyResourceReference lessObjectPropertyResourceReference = new LESSObjectPropertyResourceReference(objPropertyReference, null, null); when(lessResourceReferenceFactory.createReferenceForXObjectProperty(eq(objPropertyReference))) .thenReturn(lessObjectPropertyResourceReference); mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), doc, new Object()); verify(lessResourcesCache, atLeastOnce()).clearFromLESSResource(lessObjectPropertyResourceReference); verify(colorThemeCache, atLeastOnce()).clearFromLESSResource(lessObjectPropertyResourceReference); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; String currentWiki = wikiDescriptorManager.getCurrentWikiId(); DocumentReference ssxDocRef = new DocumentReference(currentWiki, "XWiki", "StyleSheetExtension"); List<BaseObject> ssxObjects = document.getXObjects(ssxDocRef); if (ssxObjects != null && !ssxObjects.isEmpty()) { for (BaseObject obj : ssxObjects) { if (obj == null) { continue; } if ("LESS".equals(obj.getStringValue("contentType"))) { ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, obj.getNumber(), document.getDocumentReference())); LESSResourceReference lessResourceReference = lessResourceReferenceFactory.createReferenceForXObjectProperty(objectPropertyReference); lessResourcesCache.clearFromLESSResource(lessResourceReference); colorThemeCache.clearFromLESSResource(lessResourceReference); } } } }
SSXListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; String currentWiki = wikiDescriptorManager.getCurrentWikiId(); DocumentReference ssxDocRef = new DocumentReference(currentWiki, "XWiki", "StyleSheetExtension"); List<BaseObject> ssxObjects = document.getXObjects(ssxDocRef); if (ssxObjects != null && !ssxObjects.isEmpty()) { for (BaseObject obj : ssxObjects) { if (obj == null) { continue; } if ("LESS".equals(obj.getStringValue("contentType"))) { ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, obj.getNumber(), document.getDocumentReference())); LESSResourceReference lessResourceReference = lessResourceReferenceFactory.createReferenceForXObjectProperty(objectPropertyReference); lessResourcesCache.clearFromLESSResource(lessResourceReference); colorThemeCache.clearFromLESSResource(lessResourceReference); } } } } }
SSXListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; String currentWiki = wikiDescriptorManager.getCurrentWikiId(); DocumentReference ssxDocRef = new DocumentReference(currentWiki, "XWiki", "StyleSheetExtension"); List<BaseObject> ssxObjects = document.getXObjects(ssxDocRef); if (ssxObjects != null && !ssxObjects.isEmpty()) { for (BaseObject obj : ssxObjects) { if (obj == null) { continue; } if ("LESS".equals(obj.getStringValue("contentType"))) { ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, obj.getNumber(), document.getDocumentReference())); LESSResourceReference lessResourceReference = lessResourceReferenceFactory.createReferenceForXObjectProperty(objectPropertyReference); lessResourcesCache.clearFromLESSResource(lessResourceReference); colorThemeCache.clearFromLESSResource(lessResourceReference); } } } }  }
SSXListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; String currentWiki = wikiDescriptorManager.getCurrentWikiId(); DocumentReference ssxDocRef = new DocumentReference(currentWiki, "XWiki", "StyleSheetExtension"); List<BaseObject> ssxObjects = document.getXObjects(ssxDocRef); if (ssxObjects != null && !ssxObjects.isEmpty()) { for (BaseObject obj : ssxObjects) { if (obj == null) { continue; } if ("LESS".equals(obj.getStringValue("contentType"))) { ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, obj.getNumber(), document.getDocumentReference())); LESSResourceReference lessResourceReference = lessResourceReferenceFactory.createReferenceForXObjectProperty(objectPropertyReference); lessResourcesCache.clearFromLESSResource(lessResourceReference); colorThemeCache.clearFromLESSResource(lessResourceReference); } } } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); }
SSXListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument document = (XWikiDocument) source; String currentWiki = wikiDescriptorManager.getCurrentWikiId(); DocumentReference ssxDocRef = new DocumentReference(currentWiki, "XWiki", "StyleSheetExtension"); List<BaseObject> ssxObjects = document.getXObjects(ssxDocRef); if (ssxObjects != null && !ssxObjects.isEmpty()) { for (BaseObject obj : ssxObjects) { if (obj == null) { continue; } if ("LESS".equals(obj.getStringValue("contentType"))) { ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, obj.getNumber(), document.getDocumentReference())); LESSResourceReference lessResourceReference = lessResourceReferenceFactory.createReferenceForXObjectProperty(objectPropertyReference); lessResourcesCache.clearFromLESSResource(lessResourceReference); colorThemeCache.clearFromLESSResource(lessResourceReference); } } } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }