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");
}
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());
}
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;
}
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;
}
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());
}
Aggregations