Search in sources :

Example 1 with NumberClass

use of com.xpn.xwiki.objects.classes.NumberClass in project xwiki-platform by xwiki.

the class ListMetaClass method addPresentationMetaProperties.

/**
 * Adds the meta properties that control how the XClass property is displayed in edit and view mode.
 */
private void addPresentationMetaProperties() {
    StaticListClass displayTypeClass = new StaticListClass(this);
    displayTypeClass.setName("displayType");
    displayTypeClass.setPrettyName("Display Type");
    displayTypeClass.setValues("input|select|radio|checkbox");
    safeput(displayTypeClass.getName(), displayTypeClass);
    BooleanClass multiSelectClass = newCheckBox(false);
    multiSelectClass.setName("multiSelect");
    multiSelectClass.setPrettyName("Multiple Select");
    safeput(multiSelectClass.getName(), multiSelectClass);
    BooleanClass pickerClass = newCheckBox(true);
    pickerClass.setName("picker");
    pickerClass.setPrettyName("Use Suggest");
    safeput(pickerClass.getName(), pickerClass);
    NumberClass sizeClass = new NumberClass(this);
    sizeClass.setName("size");
    sizeClass.setPrettyName("Size");
    sizeClass.setSize(5);
    sizeClass.setNumberType("integer");
    safeput(sizeClass.getName(), sizeClass);
    addValueSeparatorMetaProperties();
    StaticListClass sortClass = new StaticListClass(this);
    sortClass.setName("sort");
    sortClass.setPrettyName("Sort");
    sortClass.setValues("none|id|value");
    safeput(sortClass.getName(), sortClass);
}
Also used : StaticListClass(com.xpn.xwiki.objects.classes.StaticListClass) BooleanClass(com.xpn.xwiki.objects.classes.BooleanClass) NumberClass(com.xpn.xwiki.objects.classes.NumberClass)

Example 2 with NumberClass

use of com.xpn.xwiki.objects.classes.NumberClass in project xwiki-platform by xwiki.

the class PropertyConverterTest method doubleToInteger.

/**
 * @see XWIKI-8649: Error when changing the number type of a field from an application
 */
@Test
public void doubleToInteger() throws Exception {
    // The number property whose type has changed from Double to Integer.
    NumberClass numberClass = mock(NumberClass.class);
    IntegerProperty integerProperty = mock(IntegerProperty.class);
    when(numberClass.newProperty()).thenReturn(integerProperty);
    when(numberClass.getNumberType()).thenReturn("integer");
    DoubleProperty doubleProperty = mock(DoubleProperty.class);
    when(doubleProperty.getValue()).thenReturn(3.5);
    assertEquals(integerProperty, this.mocker.getComponentUnderTest().convertProperty(doubleProperty, numberClass));
    verify(integerProperty).setValue(3);
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) NumberClass(com.xpn.xwiki.objects.classes.NumberClass) DoubleProperty(com.xpn.xwiki.objects.DoubleProperty) Test(org.junit.Test)

Example 3 with NumberClass

use of com.xpn.xwiki.objects.classes.NumberClass in project xwiki-platform by xwiki.

the class PropertyConverterTest method stringToNumber.

@Test
public void stringToNumber() throws Exception {
    StringProperty stringProperty = new StringProperty();
    stringProperty.setValue("one");
    NumberClass numberClass = mock(NumberClass.class);
    when(numberClass.newProperty()).thenReturn(new IntegerProperty());
    when(numberClass.fromString(stringProperty.toText())).thenReturn(null);
    when(numberClass.getName()).thenReturn("age");
    when(numberClass.getClassName()).thenReturn("Some.Class");
    assertNull(this.mocker.getComponentUnderTest().convertProperty(stringProperty, numberClass));
    verify(this.mocker.getMockedLogger()).warn("Incompatible data migration when changing field [{}] of class [{}]", "age", "Some.Class");
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) StringProperty(com.xpn.xwiki.objects.StringProperty) NumberClass(com.xpn.xwiki.objects.classes.NumberClass) Test(org.junit.Test)

Example 4 with NumberClass

use of com.xpn.xwiki.objects.classes.NumberClass in project xwiki-platform by xwiki.

the class PropertyConverterTest method unsetDoubleToInteger.

@Test
public void unsetDoubleToInteger() throws Exception {
    NumberClass numberClass = mock(NumberClass.class);
    DoubleProperty unsetDoubleProperty = mock(DoubleProperty.class, "unset");
    assertNull(this.mocker.getComponentUnderTest().convertProperty(unsetDoubleProperty, numberClass));
}
Also used : NumberClass(com.xpn.xwiki.objects.classes.NumberClass) DoubleProperty(com.xpn.xwiki.objects.DoubleProperty) Test(org.junit.Test)

Example 5 with NumberClass

use of com.xpn.xwiki.objects.classes.NumberClass in project xwiki-platform by xwiki.

the class DocumentInstanceOutputFilterStreamTest method testImportDocumentsWithoutLocaleAndRevision.

@Test
public void testImportDocumentsWithoutLocaleAndRevision() throws FilterException, XWikiException, ParseException {
    DocumentInstanceOutputProperties outputProperties = new DocumentInstanceOutputProperties();
    outputProperties.setVersionPreserved(true);
    outputProperties.setVerbose(false);
    importFromXML("document1-2", outputProperties);
    XWikiDocument document = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), this.oldcore.getXWikiContext());
    Assert.assertFalse(document.isNew());
    Assert.assertEquals(Locale.ENGLISH, document.getDefaultLocale());
    Assert.assertEquals(new DocumentReference("wiki", "space", "parent"), document.getParentReference());
    Assert.assertEquals("customclass", document.getCustomClass());
    Assert.assertEquals("title", document.getTitle());
    Assert.assertEquals("defaultTemplate", document.getDefaultTemplate());
    Assert.assertEquals("validationScript", document.getValidationScript());
    Assert.assertEquals(new Syntax(new SyntaxType("syntax", "syntax"), "1.0"), document.getSyntax());
    Assert.assertEquals(true, document.isHidden());
    Assert.assertEquals("content", document.getContent());
    Assert.assertEquals(new DocumentReference("wiki", "XWiki", "creator"), document.getCreatorReference());
    Assert.assertEquals(toDate("2000-01-01 00:00:00.0 UTC"), document.getCreationDate());
    Assert.assertEquals(new DocumentReference("wiki", "XWiki", "author"), document.getAuthorReference());
    Assert.assertEquals(toDate("2000-01-02 00:00:00.0 UTC"), document.getDate());
    Assert.assertEquals(toDate("2000-01-03 00:00:00.0 UTC"), document.getContentUpdateDate());
    Assert.assertEquals(new DocumentReference("wiki", "XWiki", "contentAuthor"), document.getContentAuthorReference());
    Assert.assertEquals(true, document.isMinorEdit());
    Assert.assertEquals("comment", document.getComment());
    Assert.assertEquals("1.1", document.getVersion());
    // Attachment
    Assert.assertEquals(1, document.getAttachmentList().size());
    XWikiAttachment attachment = document.getAttachment("attachment.txt");
    Assert.assertEquals("attachment.txt", attachment.getFilename());
    Assert.assertEquals(10, attachment.getLongSize());
    Assert.assertTrue(Arrays.equals(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, attachment.getContent(this.oldcore.getXWikiContext())));
    Assert.assertEquals("XWiki.attachmentAuthor", attachment.getAuthor());
    Assert.assertEquals(toDate("2000-01-05 00:00:00.0 UTC"), attachment.getDate());
    Assert.assertEquals("1.1", attachment.getVersion());
    Assert.assertEquals("attachment comment", attachment.getComment());
    // XClass
    BaseClass xclass = document.getXClass();
    Assert.assertEquals("customClass", xclass.getCustomClass());
    Assert.assertEquals("customMapping", xclass.getCustomMapping());
    Assert.assertEquals("defaultViewSheet", xclass.getDefaultViewSheet());
    Assert.assertEquals("defaultEditSheet", xclass.getDefaultEditSheet());
    Assert.assertEquals("defaultWeb", xclass.getDefaultWeb());
    Assert.assertEquals("nameField", xclass.getNameField());
    Assert.assertEquals("validationScript", xclass.getValidationScript());
    Assert.assertEquals(1, xclass.getFieldList().size());
    NumberClass numberFiled = (NumberClass) xclass.getField("prop1");
    Assert.assertEquals("prop1", numberFiled.getName());
    Assert.assertEquals(false, numberFiled.isDisabled());
    Assert.assertEquals(1, numberFiled.getNumber());
    Assert.assertEquals("long", numberFiled.getNumberType());
    Assert.assertEquals("Prop1", numberFiled.getPrettyName());
    Assert.assertEquals(30, numberFiled.getSize());
    Assert.assertEquals(false, numberFiled.isUnmodifiable());
    // Objects
    Map<DocumentReference, List<BaseObject>> objects = document.getXObjects();
    Assert.assertEquals(2, objects.size());
    // Object 1
    List<BaseObject> documentObjects = objects.get(new DocumentReference("wiki", "space", "page"));
    Assert.assertEquals(1, documentObjects.size());
    BaseObject documentObject = documentObjects.get(0);
    Assert.assertEquals(0, documentObject.getNumber());
    Assert.assertEquals(new DocumentReference("wiki", "space", "page"), documentObject.getXClassReference());
    Assert.assertEquals("e2167721-2a64-430c-9520-bac1c0ee68cb", documentObject.getGuid());
    Assert.assertEquals(1, documentObject.getFieldList().size());
    Assert.assertEquals(1, documentObject.getIntValue("prop1"));
    // Object 2
    List<BaseObject> otherObjects = objects.get(new DocumentReference("wiki", "otherspace", "otherclass"));
    Assert.assertEquals(1, otherObjects.size());
    BaseObject otherObject = otherObjects.get(0);
    Assert.assertEquals(0, otherObject.getNumber());
    Assert.assertEquals(new DocumentReference("wiki", "otherspace", "otherclass"), otherObject.getXClassReference());
    Assert.assertEquals("8eaeac52-e2f2-47b2-87e1-bc6909597b39", otherObject.getGuid());
    Assert.assertEquals(1, otherObject.getFieldList().size());
    Assert.assertEquals(2, otherObject.getIntValue("prop2"));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentInstanceOutputProperties(org.xwiki.filter.instance.output.DocumentInstanceOutputProperties) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) NumberClass(com.xpn.xwiki.objects.classes.NumberClass) List(java.util.List) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test) AbstractInstanceFilterStreamTest(com.xpn.xwiki.internal.filter.AbstractInstanceFilterStreamTest)

Aggregations

NumberClass (com.xpn.xwiki.objects.classes.NumberClass)6 Test (org.junit.Test)5 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 AbstractInstanceFilterStreamTest (com.xpn.xwiki.internal.filter.AbstractInstanceFilterStreamTest)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2 DoubleProperty (com.xpn.xwiki.objects.DoubleProperty)2 IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 List (java.util.List)2 DocumentInstanceOutputProperties (org.xwiki.filter.instance.output.DocumentInstanceOutputProperties)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 Syntax (org.xwiki.rendering.syntax.Syntax)2 SyntaxType (org.xwiki.rendering.syntax.SyntaxType)2 StringProperty (com.xpn.xwiki.objects.StringProperty)1 BooleanClass (com.xpn.xwiki.objects.classes.BooleanClass)1 StaticListClass (com.xpn.xwiki.objects.classes.StaticListClass)1