Search in sources :

Example 1 with WikiPropertyGroup

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());
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject) WikiPropertyGroup(org.xwiki.wiki.properties.WikiPropertyGroup) Test(org.junit.Test)

Example 2 with WikiPropertyGroup

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;
}
Also used : WikiPropertyGroup(org.xwiki.wiki.properties.WikiPropertyGroup)

Example 3 with WikiPropertyGroup

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);
        }
    }
}
Also used : WikiPropertyGroupProvider(org.xwiki.wiki.properties.WikiPropertyGroupProvider) WikiPropertyGroup(org.xwiki.wiki.properties.WikiPropertyGroup)

Example 4 with WikiPropertyGroup

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"));
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiPropertyGroup(org.xwiki.wiki.properties.WikiPropertyGroup) Test(org.junit.Test)

Example 5 with WikiPropertyGroup

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"));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiPropertyGroup(org.xwiki.wiki.properties.WikiPropertyGroup) Test(org.junit.Test)

Aggregations

WikiPropertyGroup (org.xwiki.wiki.properties.WikiPropertyGroup)5 Test (org.junit.Test)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)1 WikiPropertyGroupProvider (org.xwiki.wiki.properties.WikiPropertyGroupProvider)1 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)1