Search in sources :

Example 6 with IntegerProperty

use of com.xpn.xwiki.objects.IntegerProperty 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 7 with IntegerProperty

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

the class BooleanClassTest method testLocalization.

/**
 * Test localization.
 */
@Test
public void testLocalization() throws Exception {
    // Setup
    ContextualLocalizationManager contextualLocalizationManager = this.mocker.getMocker().registerMockComponent(ContextualLocalizationManager.class);
    when(contextualLocalizationManager.getTranslationPlain("Some.Class_prop_0")).thenReturn("Nay");
    when(contextualLocalizationManager.getTranslationPlain("Some.Class_prop_1")).thenReturn("Aye");
    when(contextualLocalizationManager.getTranslationPlain("Some.Class_prop_2")).thenReturn("Dunno");
    when(contextualLocalizationManager.getTranslationPlain("yesno_0")).thenReturn("No");
    when(contextualLocalizationManager.getTranslationPlain("yesno_1")).thenReturn("Yes");
    when(contextualLocalizationManager.getTranslationPlain("truefalse_0")).thenReturn("False");
    when(contextualLocalizationManager.getTranslationPlain("truefalse_1")).thenReturn("True");
    when(contextualLocalizationManager.getTranslationPlain("active_0")).thenReturn("Inactive");
    when(contextualLocalizationManager.getTranslationPlain("active_1")).thenReturn("Active");
    when(contextualLocalizationManager.getTranslationPlain("allow_0")).thenReturn("Deny");
    when(contextualLocalizationManager.getTranslationPlain("allow_1")).thenReturn("Allow");
    DocumentReference classReference = new DocumentReference(this.mocker.getXWikiContext().getWikiId(), "Some", "Class");
    EntityReferenceSerializer<String> entityReferenceSerializer = this.mocker.getMocker().registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "local");
    when(entityReferenceSerializer.serialize(classReference)).thenReturn("Some.Class");
    // Create a Boolean meta-property and an associated object with a property instance
    BooleanClass metaProperty = new BooleanClass();
    BaseClass cls = new BaseClass();
    BaseObject obj = new BaseObject();
    IntegerProperty prop = new IntegerProperty();
    prop.setValue(0);
    obj.safeput("prop", prop);
    cls.setDocumentReference(classReference);
    metaProperty.setObject(cls);
    StringBuffer out = new StringBuffer();
    // Test the default translations, should be the default "yesno" display type
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("No", out.toString());
    out.setLength(0);
    prop.setValue(1);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("Yes", out.toString());
    out.setLength(0);
    prop.setValue(2);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("---", out.toString());
    // Test translations when display type is "active"
    metaProperty.setDisplayType("active");
    out.setLength(0);
    prop.setValue(0);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("Inactive", out.toString());
    out.setLength(0);
    prop.setValue(1);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("Active", out.toString());
    out.setLength(0);
    prop.setValue(2);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("---", out.toString());
    // Test translations when display type is the non-existing "blacktive"
    metaProperty.setDisplayType("blacktive");
    out.setLength(0);
    prop.setValue(0);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("0", out.toString());
    out.setLength(0);
    prop.setValue(1);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("1", out.toString());
    out.setLength(0);
    prop.setValue(2);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("---", out.toString());
    // Test translations with the full classname_prop_value format
    metaProperty.setName("prop");
    out.setLength(0);
    prop.setValue(0);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("Nay", out.toString());
    out.setLength(0);
    prop.setValue(1);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("Aye", out.toString());
    out.setLength(0);
    prop.setValue(2);
    metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
    assertEquals("Dunno", out.toString());
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) ContextualLocalizationManager(org.xwiki.localization.ContextualLocalizationManager) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 8 with IntegerProperty

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

the class NumberClass method newProperty.

@Override
public BaseProperty newProperty() {
    String ntype = getNumberType();
    BaseProperty property;
    if (ntype.equals("integer")) {
        property = new IntegerProperty();
    } else if (ntype.equals("float")) {
        property = new FloatProperty();
    } else if (ntype.equals("double")) {
        property = new DoubleProperty();
    } else {
        property = new LongProperty();
    }
    property.setName(getName());
    return property;
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) LongProperty(com.xpn.xwiki.objects.LongProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty) FloatProperty(com.xpn.xwiki.objects.FloatProperty) DoubleProperty(com.xpn.xwiki.objects.DoubleProperty)

Example 9 with IntegerProperty

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

the class BooleanClass method newProperty.

@Override
public BaseProperty newProperty() {
    BaseProperty property = new IntegerProperty();
    property.setName(getName());
    return property;
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 10 with IntegerProperty

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

the class BooleanClass method displayCheckboxEdit.

public void displayCheckboxEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    org.apache.ecs.xhtml.input check = new input(input.checkbox, prefix + name, 1);
    check.setAttributeFilter(new XMLAttributeValueFilter());
    check.setID(prefix + name);
    check.setDisabled(isDisabled());
    // If the (visible) checkbox is unchecked, it will not post anything back so the hidden input by the same
    // name will post back 0 and the save function will save the first entry it finds.
    org.apache.ecs.xhtml.input checkNo = new input(input.hidden, prefix + name, 0);
    checkNo.setAttributeFilter(new XMLAttributeValueFilter());
    try {
        IntegerProperty prop = (IntegerProperty) object.safeget(name);
        if (prop != null) {
            Integer ivalue = (Integer) prop.getValue();
            if (ivalue != null) {
                int value = ivalue.intValue();
                if (value == 1) {
                    check.setChecked(true);
                } else if (value == 0) {
                    check.setChecked(false);
                }
            } else {
                int value = getDefaultValue();
                if (value == 1) {
                    check.setChecked(true);
                } else {
                    check.setChecked(false);
                }
            }
        }
    } catch (Exception e) {
        // This should not happen
        e.printStackTrace();
    }
    buffer.append(check.toString());
    buffer.append(checkNo.toString());
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input)

Aggregations

IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)10 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)3 Test (org.junit.Test)3 BaseProperty (com.xpn.xwiki.objects.BaseProperty)2 DoubleProperty (com.xpn.xwiki.objects.DoubleProperty)2 NumberClass (com.xpn.xwiki.objects.classes.NumberClass)2 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 FloatProperty (com.xpn.xwiki.objects.FloatProperty)1 LongProperty (com.xpn.xwiki.objects.LongProperty)1 StringProperty (com.xpn.xwiki.objects.StringProperty)1 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)1 org.apache.ecs.xhtml.label (org.apache.ecs.xhtml.label)1 org.apache.ecs.xhtml.option (org.apache.ecs.xhtml.option)1 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)1 ContextualLocalizationManager (org.xwiki.localization.ContextualLocalizationManager)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1