Search in sources :

Example 1 with DBListClass

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

the class ClassPropertyValuesResourceImplTest method getClassPropertyValues.

@Test
public void getClassPropertyValues() throws Exception {
    when(this.authorization.hasAccess(Right.VIEW, this.propertyReference)).thenReturn(true);
    when(this.xclass.get("status")).thenReturn(new DBListClass());
    PropertyValues values = new PropertyValues();
    ClassPropertyValuesProvider propertyValuesProvider = this.mocker.getInstance(ClassPropertyValuesProvider.class);
    when(propertyValuesProvider.getValues(this.propertyReference, 6, "one", "two")).thenReturn(values);
    assertSame(values, this.resource.getClassPropertyValues("wiki", "Path.To.Class", "status", 6, Arrays.asList("one", "two")));
    assertEquals(1, values.getLinks().size());
    Link propertyLink = values.getLinks().get(0);
    assertEquals("/xwiki/rest/wikis/wiki/classes/Path.To.Class/properties/status", propertyLink.getHref());
    assertEquals(Relations.PROPERTY, propertyLink.getRel());
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass) ClassPropertyValuesProvider(org.xwiki.rest.resources.classes.ClassPropertyValuesProvider) PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) Link(org.xwiki.rest.model.jaxb.Link) Test(org.junit.Test)

Example 2 with DBListClass

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

the class WatchListClassDocumentInitializer method addWatchedElementField.

/**
 * @param xclass the class to add to
 * @param name the name of the property to add
 * @param prettyName the pretty name of the property to add
 */
private void addWatchedElementField(BaseClass xclass, String name, String prettyName) {
    xclass.addDBListField(name, prettyName, 80, true, null);
    // Set the input display type in order to easily debug from the object editor.
    DBListClass justAddedProperty = (DBListClass) xclass.get(name);
    justAddedProperty.setDisplayType(ListClass.DISPLAYTYPE_INPUT);
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass)

Example 3 with DBListClass

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

the class PropertyConverterTest method multipleToSingleSelectOnEmptyDBList.

@Test
public void multipleToSingleSelectOnEmptyDBList() 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);
    StringListProperty emptyListProperty = mock(StringListProperty.class);
    when(emptyListProperty.getValue()).thenReturn(Arrays.asList());
    assertNull(this.mocker.getComponentUnderTest().convertProperty(emptyListProperty, dbListClass));
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass) StringListProperty(com.xpn.xwiki.objects.StringListProperty) Test(org.junit.Test)

Example 4 with DBListClass

use of com.xpn.xwiki.objects.classes.DBListClass 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 DBListClass

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

the class DefaultDBListQueryBuilderTest method build.

@Test
public void build() throws Exception {
    DBListClass dbListClass = new DBListClass();
    DefaultParameterizedType dbListQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, DBListClass.class);
    QueryBuilder<DBListClass> explicitlyAllowedValuesQueryBuilder = this.mocker.getInstance(dbListQueryBuilderType, "explicitlyAllowedValues");
    QueryBuilder<DBListClass> implicitlyAllowedValuesQueryBuilder = this.mocker.getInstance(dbListQueryBuilderType, "implicitlyAllowedValues");
    Query explicitlyAllowedValuesQuery = mock(Query.class, "explicit");
    when(explicitlyAllowedValuesQueryBuilder.build(dbListClass)).thenReturn(explicitlyAllowedValuesQuery);
    Query implicitlyAllowedValuesQuery = mock(Query.class, "implicit");
    when(implicitlyAllowedValuesQueryBuilder.build(dbListClass)).thenReturn(implicitlyAllowedValuesQuery);
    assertSame(implicitlyAllowedValuesQuery, this.mocker.getComponentUnderTest().build(dbListClass));
    dbListClass.setSql("test");
    assertSame(explicitlyAllowedValuesQuery, this.mocker.getComponentUnderTest().build(dbListClass));
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass) Query(org.xwiki.query.Query) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Aggregations

DBListClass (com.xpn.xwiki.objects.classes.DBListClass)8 Test (org.junit.Test)6 StringListProperty (com.xpn.xwiki.objects.StringListProperty)3 StringProperty (com.xpn.xwiki.objects.StringProperty)3 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1 PropertyMetaClass (com.xpn.xwiki.objects.meta.PropertyMetaClass)1 Before (org.junit.Before)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 Query (org.xwiki.query.Query)1 QueryManager (org.xwiki.query.QueryManager)1 Link (org.xwiki.rest.model.jaxb.Link)1 PropertyValues (org.xwiki.rest.model.jaxb.PropertyValues)1 ClassPropertyValuesProvider (org.xwiki.rest.resources.classes.ClassPropertyValuesProvider)1 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)1