@Test public void buildDescriptorObject() throws Exception { List<BaseObject> objects = new ArrayList<>(); BaseObject object1 = mock(BaseObject.class); BaseObject object2 = mock(BaseObject.class); BaseObject object3 = mock(BaseObject.class); objects.add(null); objects.add(object1); objects.add(object2); objects.add(null); objects.add(object3); XWikiDocument document = mock(XWikiDocument.class); DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwiki1"); when(document.getDocumentReference()).thenReturn(documentReference); when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn("subwiki1"); when(object2.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn("alias1"); when(object3.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn("alias2"); DocumentReference mainPageReference = new DocumentReference("subwiki1", "Space", "MainPage"); when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)).thenReturn("Space.MainPage"); when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME)) .thenReturn("myPrettyName"); when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER)).thenReturn("myOwner"); when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION)).thenReturn("myDescription"); DocumentReference ownerRef = new DocumentReference("subwiki1", "XWiki", "myOwner"); when(userReferenceResolver.resolve("myOwner", new WikiReference("subwiki1"))).thenReturn(ownerRef); WikiDescriptor result = this.builder.buildDescriptorObject(objects, document); assertEquals("subwiki1", result.getId()); assertEquals(3, result.getAliases().size()); assertEquals("subwiki1", result.getAliases().get(0)); assertEquals("alias1", result.getAliases().get(1)); assertEquals("alias2", result.getAliases().get(2)); assertEquals(mainPageReference, result.getMainPageReference()); assertEquals("myPrettyName", result.getPrettyName()); assertEquals("subwiki1:XWiki.myOwner", result.getOwnerId()); assertEquals("myDescription", result.getDescription()); wikiPropertyGroupManager.loadForDescriptor(any(WikiDescriptor.class)); }
@Override public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) { List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects); BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0); DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document); if (descriptor != null) { for (BaseObject serverClassObject : normalizedServerClassObjects) { if (serverClassObject != null) { String descriptorAlias = extractWikiAlias(serverClassObject); descriptor.addAlias(descriptorAlias); } } descriptor.setMainPageReference(this.referenceFactory.getReference(referenceResolver .resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)))); descriptor.setPrettyName( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME)); descriptor.setOwnerId( getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId())); descriptor.setDescription( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION)); int secure = mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_SECURE, -1); descriptor.setSecure(secure != -1 ? secure == 1 : null); descriptor.setPort(mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_PORT, -1)); try { WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get(); wikiPropertyGroupManager.loadForDescriptor(descriptor); } catch (WikiPropertyGroupException e) { logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e); } } return descriptor; }
DefaultWikiDescriptorBuilder implements WikiDescriptorBuilder { @Override public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) { List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects); BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0); DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document); if (descriptor != null) { for (BaseObject serverClassObject : normalizedServerClassObjects) { if (serverClassObject != null) { String descriptorAlias = extractWikiAlias(serverClassObject); descriptor.addAlias(descriptorAlias); } } descriptor.setMainPageReference(this.referenceFactory.getReference(referenceResolver .resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)))); descriptor.setPrettyName( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME)); descriptor.setOwnerId( getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId())); descriptor.setDescription( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION)); int secure = mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_SECURE, -1); descriptor.setSecure(secure != -1 ? secure == 1 : null); descriptor.setPort(mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_PORT, -1)); try { WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get(); wikiPropertyGroupManager.loadForDescriptor(descriptor); } catch (WikiPropertyGroupException e) { logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e); } } return descriptor; } }
DefaultWikiDescriptorBuilder implements WikiDescriptorBuilder { @Override public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) { List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects); BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0); DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document); if (descriptor != null) { for (BaseObject serverClassObject : normalizedServerClassObjects) { if (serverClassObject != null) { String descriptorAlias = extractWikiAlias(serverClassObject); descriptor.addAlias(descriptorAlias); } } descriptor.setMainPageReference(this.referenceFactory.getReference(referenceResolver .resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)))); descriptor.setPrettyName( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME)); descriptor.setOwnerId( getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId())); descriptor.setDescription( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION)); int secure = mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_SECURE, -1); descriptor.setSecure(secure != -1 ? secure == 1 : null); descriptor.setPort(mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_PORT, -1)); try { WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get(); wikiPropertyGroupManager.loadForDescriptor(descriptor); } catch (WikiPropertyGroupException e) { logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e); } } return descriptor; }  }
DefaultWikiDescriptorBuilder implements WikiDescriptorBuilder { @Override public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) { List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects); BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0); DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document); if (descriptor != null) { for (BaseObject serverClassObject : normalizedServerClassObjects) { if (serverClassObject != null) { String descriptorAlias = extractWikiAlias(serverClassObject); descriptor.addAlias(descriptorAlias); } } descriptor.setMainPageReference(this.referenceFactory.getReference(referenceResolver .resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)))); descriptor.setPrettyName( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME)); descriptor.setOwnerId( getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId())); descriptor.setDescription( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION)); int secure = mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_SECURE, -1); descriptor.setSecure(secure != -1 ? secure == 1 : null); descriptor.setPort(mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_PORT, -1)); try { WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get(); wikiPropertyGroupManager.loadForDescriptor(descriptor); } catch (WikiPropertyGroupException e) { logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e); } } return descriptor; }  @Override DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document); @Override XWikiDocument save(WikiDescriptor descriptor); }
DefaultWikiDescriptorBuilder implements WikiDescriptorBuilder { @Override public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) { List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects); BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0); DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document); if (descriptor != null) { for (BaseObject serverClassObject : normalizedServerClassObjects) { if (serverClassObject != null) { String descriptorAlias = extractWikiAlias(serverClassObject); descriptor.addAlias(descriptorAlias); } } descriptor.setMainPageReference(this.referenceFactory.getReference(referenceResolver .resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)))); descriptor.setPrettyName( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME)); descriptor.setOwnerId( getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId())); descriptor.setDescription( mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION)); int secure = mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_SECURE, -1); descriptor.setSecure(secure != -1 ? secure == 1 : null); descriptor.setPort(mainServerClassObject.getIntValue(XWikiServerClassDocumentInitializer.FIELD_PORT, -1)); try { WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get(); wikiPropertyGroupManager.loadForDescriptor(descriptor); } catch (WikiPropertyGroupException e) { logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e); } } return descriptor; }  @Override DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document); @Override XWikiDocument save(WikiDescriptor descriptor);  }