use of com.xpn.xwiki.objects.StringProperty in project xwiki-platform by xwiki.
the class ComputedFieldClass method newProperty.
@Override
public BaseProperty newProperty() {
BaseProperty property = new StringProperty();
property.setName(getName());
return property;
}
use of com.xpn.xwiki.objects.StringProperty in project xwiki-platform by xwiki.
the class LevelsClass method newProperty.
@Override
public BaseProperty newProperty() {
BaseProperty property = new StringProperty();
property.setName(getName());
return property;
}
use of com.xpn.xwiki.objects.StringProperty 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.StringProperty in project xwiki-platform by xwiki.
the class PropertyConverterTest method multipleToSingleSelectOnDBList.
@Test
public void multipleToSingleSelectOnDBList() throws Exception {
// The Database List property that was switched from multiple select to single select.
DBListClass dbListClass = mock(DBListClass.class);
when(dbListClass.isMultiSelect()).thenReturn(false);
StringProperty stringProperty = mock(StringProperty.class);
when(dbListClass.newProperty()).thenReturn(stringProperty);
StringListProperty stringListProperty = mock(StringListProperty.class);
when(stringListProperty.getValue()).thenReturn(Arrays.asList("one", "two"));
assertEquals(stringProperty, this.mocker.getComponentUnderTest().convertProperty(stringListProperty, dbListClass));
verify(stringProperty).setValue("one");
}
use of com.xpn.xwiki.objects.StringProperty in project xwiki-platform by xwiki.
the class XWikiTest method testValidationKeyStorage.
/**
* Check that the user validation feature works when the validation key is stored both as plain text and as a hashed
* field.
*
* @throws Exception when any exception occurs inside XWiki
*/
public void testValidationKeyStorage() throws Exception {
XWikiContext context = getContext();
context.setLanguage("en");
// Prepare the request
Mock request = mock(XWikiRequest.class);
request.stubs().method("getParameter").with(eq("xwikiname")).will(returnValue("TestUser"));
request.stubs().method("getParameter").with(eq("validkey")).will(returnValue("plaintextkey"));
context.setRequest((XWikiRequest) request.proxy());
// Prepare the user profile
XWikiDocument testUser = new XWikiDocument(new DocumentReference("Wiki", "XWiki", "TestUser"));
BaseObject userObject = (BaseObject) this.xwiki.getUserClass(context).newObject(context);
testUser.addObject("XWiki.XWikiUsers", userObject);
this.xwiki.saveDocument(testUser, context);
// Check with a correct plaintext key
BaseProperty validationKey = new StringProperty();
validationKey.setValue("plaintextkey");
userObject.safeput("validkey", validationKey);
assertEquals(0, this.xwiki.validateUser(false, getContext()));
// Check with an incorrect plaintext key
validationKey.setValue("wrong key");
assertEquals(-1, this.xwiki.validateUser(false, getContext()));
// Check with a correct hashed key
validationKey = ((PropertyClass) this.xwiki.getUserClass(context).get("validkey")).fromString("plaintextkey");
assertTrue(validationKey.getValue().toString().startsWith("hash:"));
userObject.safeput("validkey", validationKey);
assertEquals(0, this.xwiki.validateUser(false, getContext()));
// Check with an incorrect hashed key
validationKey = ((PropertyClass) this.xwiki.getUserClass(context).get("validkey")).fromString("wrong key");
assertTrue(validationKey.getValue().toString().startsWith("hash:"));
userObject.safeput("validkey", validationKey);
assertEquals(-1, this.xwiki.validateUser(false, getContext()));
}
Aggregations