Search in sources :

Example 1 with StringProperty

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;
}
Also used : StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 2 with StringProperty

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;
}
Also used : StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 3 with StringProperty

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

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");
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass) StringProperty(com.xpn.xwiki.objects.StringProperty) StringListProperty(com.xpn.xwiki.objects.StringListProperty) Test(org.junit.Test)

Example 5 with StringProperty

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()));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty) Mock(org.jmock.Mock) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

StringProperty (com.xpn.xwiki.objects.StringProperty)14 BaseProperty (com.xpn.xwiki.objects.BaseProperty)7 Test (org.junit.Test)6 BaseObject (com.xpn.xwiki.objects.BaseObject)4 StringListProperty (com.xpn.xwiki.objects.StringListProperty)4 DBListClass (com.xpn.xwiki.objects.classes.DBListClass)3 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)2 ListProperty (com.xpn.xwiki.objects.ListProperty)2 StringClass (com.xpn.xwiki.objects.classes.StringClass)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Query (org.hibernate.Query)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseCollection (com.xpn.xwiki.objects.BaseCollection)1 BaseStringProperty (com.xpn.xwiki.objects.BaseStringProperty)1 IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)1 LargeStringProperty (com.xpn.xwiki.objects.LargeStringProperty)1