Search in sources :

Example 16 with ClassPropertyReference

use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.

the class DBListClassPropertyValuesProviderTest method getValuesMixedWithoutUsed.

@Test
public void getValuesMixedWithoutUsed() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference();
    PropertyValues values = new PropertyValues();
    values.getPropertyValues().add(new PropertyValue());
    when(this.authorExecutor.call(any(), eq(authorReference))).thenReturn(values);
    assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 1, "foo"));
    assertEquals(1, values.getPropertyValues().size());
    verify(this.usedValuesQueryBuilder, never()).build(any());
}
Also used : PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) PropertyValue(org.xwiki.rest.model.jaxb.PropertyValue) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 17 with ClassPropertyReference

use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.

the class DBListClassPropertyValuesProviderTest method configure.

@Before
public void configure() throws Exception {
    super.configure();
    addProperty("category", this.dbListClass, true);
    addProperty("date", new DateClass(), false);
    when(this.xcontext.getWiki().getDocument(new ClassPropertyReference("status", this.classReference), this.xcontext)).thenReturn(this.classDocument);
    this.entityReferenceSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    this.authorExecutor = this.mocker.getInstance(AuthorExecutor.class);
    DefaultParameterizedType listQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, ListClass.class);
}
Also used : DateClass(com.xpn.xwiki.objects.classes.DateClass) AuthorExecutor(org.xwiki.security.authorization.AuthorExecutor) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Before(org.junit.Before)

Example 18 with ClassPropertyReference

use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.

the class DefaultClassPropertyValuesProviderTest method getValuesWithMissingProvider.

@Test
public void getValuesWithMissingProvider() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    ComponentManager contextComponentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(contextComponentManager.getInstance(ClassPropertyValuesProvider.class, "DBList")).thenThrow(new ComponentLookupException("Component not found."));
    try {
        this.mocker.getComponentUnderTest().getValues(propertyReference, 13, "one");
        fail();
    } catch (XWikiRestException expected) {
        assertEquals("There's no value provider registered for the [DBList] property type.", expected.getMessage());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 19 with ClassPropertyReference

use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.

the class ClassPropertyValuesResourceImpl method getClassPropertyValues.

@Override
public PropertyValues getClassPropertyValues(String wikiName, String className, String propertyName, Integer limit, List<String> filterParameters) throws XWikiRestException {
    DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName));
    ClassPropertyReference classPropertyReference = new ClassPropertyReference(propertyName, classReference);
    if (!this.authorization.hasAccess(Right.VIEW, classPropertyReference)) {
        throw new WebApplicationException(Status.UNAUTHORIZED);
    }
    if (!exists(classPropertyReference)) {
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    URI propertyURI = Utils.createURI(this.uriInfo.getBaseUri(), ClassPropertyResource.class, wikiName, className, propertyName);
    Link propertyLink = this.objectFactory.createLink();
    propertyLink.setHref(propertyURI.toString());
    propertyLink.setRel(Relations.PROPERTY);
    PropertyValues propertyValues = this.propertyValuesProvider.getValues(classPropertyReference, limit, filterParameters.toArray());
    propertyValues.getLinks().add(propertyLink);
    return propertyValues;
}
Also used : PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) WebApplicationException(javax.ws.rs.WebApplicationException) WikiReference(org.xwiki.model.reference.WikiReference) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) URI(java.net.URI) DocumentReference(org.xwiki.model.reference.DocumentReference) Link(org.xwiki.rest.model.jaxb.Link)

Aggregations

ClassPropertyReference (org.xwiki.model.reference.ClassPropertyReference)19 Test (org.junit.Test)12 DocumentReference (org.xwiki.model.reference.DocumentReference)7 PropertyValues (org.xwiki.rest.model.jaxb.PropertyValues)5 EntityReference (org.xwiki.model.reference.EntityReference)4 XWikiRestException (org.xwiki.rest.XWikiRestException)4 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 ComponentManager (org.xwiki.component.manager.ComponentManager)2 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)2 WikiReference (org.xwiki.model.reference.WikiReference)2 Query (org.xwiki.query.Query)2 PropertyValue (org.xwiki.rest.model.jaxb.PropertyValue)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiException (com.xpn.xwiki.XWikiException)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1 DateClass (com.xpn.xwiki.objects.classes.DateClass)1 ListClass (com.xpn.xwiki.objects.classes.ListClass)1