use of org.xwiki.wiki.properties.WikiPropertyGroup in project xwiki-platform by xwiki.
the class WikiTemplatePropertyGroupProviderTest method get.
@Test
public void get() throws Exception {
XWikiDocument descriptorDocument = mock(XWikiDocument.class);
when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenReturn(descriptorDocument);
BaseObject object = mock(BaseObject.class);
when(descriptorDocument.getXObject(eq(WikiTemplateClassDocumentInitializer.SERVER_CLASS))).thenReturn(object);
when(object.getIntValue("iswikitemplate", 0)).thenReturn(1);
// Test
WikiPropertyGroup result = mocker.getComponentUnderTest().get("wikiId");
// Verify
assertEquals(true, result.get("isTemplate"));
assertTrue(result instanceof WikiTemplatePropertyGroup);
assertTrue(((WikiTemplatePropertyGroup) result).isTemplate());
XWikiDocument descriptorDocument2 = mock(XWikiDocument.class);
when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId2")).thenReturn(descriptorDocument2);
BaseObject object2 = mock(BaseObject.class);
when(descriptorDocument2.getXObject(eq(WikiTemplateClassDocumentInitializer.SERVER_CLASS))).thenReturn(object2);
when(object2.getIntValue("iswikitemplate", 0)).thenReturn(0);
// Test
WikiPropertyGroup result2 = mocker.getComponentUnderTest().get("wikiId2");
// Verify
assertEquals(false, result2.get("isTemplate"));
assertTrue(result2 instanceof WikiTemplatePropertyGroup);
assertFalse(((WikiTemplatePropertyGroup) result2).isTemplate());
}
use of org.xwiki.wiki.properties.WikiPropertyGroup in project xwiki-platform by xwiki.
the class WikiDescriptor method clone.
@Override
public WikiDescriptor clone() {
WikiDescriptor descriptor;
try {
descriptor = (WikiDescriptor) super.clone();
} catch (CloneNotSupportedException e) {
// Supposed to be impossible
descriptor = new WikiDescriptor(getDescription(), getDefaultAlias());
}
// Clone aliases
descriptor.aliases = new ArrayList<>(this.aliases);
// Clone properties
descriptor.propertyGroups = new HashMap<>(this.propertyGroups.size());
for (WikiPropertyGroup group : this.propertyGroups.values()) {
descriptor.propertyGroups.put(group.getId(), group.clone());
}
return descriptor;
}
use of org.xwiki.wiki.properties.WikiPropertyGroup in project xwiki-platform by xwiki.
the class DefaultWikiPropertyGroupManager method saveForDescriptor.
@Override
public void saveForDescriptor(WikiDescriptor descriptor) throws WikiPropertyGroupException {
String wikiId = descriptor.getId();
for (String propertyGroupName : propertyGroupProviders.keySet()) {
WikiPropertyGroup group = descriptor.getPropertyGroup(propertyGroupName);
if (group != null) {
WikiPropertyGroupProvider provider = propertyGroupProviders.get(propertyGroupName);
provider.save(group, wikiId);
}
}
}
use of org.xwiki.wiki.properties.WikiPropertyGroup in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorManagerTest method testCacheProtection.
@Test
public void testCacheProtection() throws WikiManagerException, ComponentLookupException {
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("xwiki", "xwiki");
descriptor.setPrettyName("pretty name");
WikiPropertyGroup propertyGroup = new WikiPropertyGroup("group");
propertyGroup.set("property", "value");
descriptor.addPropertyGroup(propertyGroup);
when(cache.getFromId("xwiki")).thenReturn(descriptor);
when(cache.getFromAlias("xwiki")).thenReturn(descriptor);
WikiDescriptorManager wikiDescriptorManager = this.mocker.getComponentUnderTest();
// Modify the descriptor without saving it
wikiDescriptorManager.getById("xwiki").setPrettyName("changed pretty name");
assertEquals("pretty name", wikiDescriptorManager.getById("xwiki").getPrettyName());
wikiDescriptorManager.getById("xwiki").getPropertyGroup("group").set("property", "modified value");
assertEquals("value", wikiDescriptorManager.getById("xwiki").getPropertyGroup("group").get("property"));
// Modify the descriptor without saving it
wikiDescriptorManager.getByAlias("xwiki").setPrettyName("changed pretty name");
assertEquals("pretty name", wikiDescriptorManager.getByAlias("xwiki").getPrettyName());
wikiDescriptorManager.getByAlias("xwiki").getPropertyGroup("group").set("property", "modified value");
assertEquals("value", wikiDescriptorManager.getByAlias("xwiki").getPropertyGroup("group").get("property"));
// Modify the descriptor without saving it
wikiDescriptorManager.getMainWikiDescriptor().setPrettyName("changed pretty name");
assertEquals("pretty name", wikiDescriptorManager.getMainWikiDescriptor().getPrettyName());
wikiDescriptorManager.getMainWikiDescriptor().getPropertyGroup("group").set("property", "modified value");
assertEquals("value", wikiDescriptorManager.getMainWikiDescriptor().getPropertyGroup("group").get("property"));
}
use of org.xwiki.wiki.properties.WikiPropertyGroup in project xwiki-platform by xwiki.
the class WikiTemplatePropertyGroupProviderTest method getWhenNoObject.
@Test
public void getWhenNoObject() throws Exception {
XWikiDocument descriptorDocument = mock(XWikiDocument.class);
when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenReturn(descriptorDocument);
// Test
WikiPropertyGroup result = mocker.getComponentUnderTest().get("wikiId");
// Verify
assertEquals(false, result.get("isTemplate"));
}
Aggregations