Search in sources :

Example 1 with PropertyValues

use of org.xwiki.rest.model.jaxb.PropertyValues 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 PropertyValues

use of org.xwiki.rest.model.jaxb.PropertyValues in project xwiki-platform by xwiki.

the class DBListClassPropertyValuesProviderTest method getValuesMixedWithUsed.

@Test
public void getValuesMixedWithUsed() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference();
    PropertyValues values = new PropertyValues();
    PropertyValue red = new PropertyValue();
    red.setValue("red");
    red.setMetaData(new HashMap<String, Object>());
    red.getMetaData().put("label", "Red");
    values.getPropertyValues().add(red);
    when(this.authorExecutor.call(any(), eq(authorReference))).thenReturn(values);
    Query query = mock(Query.class);
    QueryParameter queryParameter = mock(QueryParameter.class);
    when(this.usedValuesQueryBuilder.build(dbListClass)).thenReturn(query);
    when(query.bindValue("text")).thenReturn(queryParameter);
    when(queryParameter.anyChars()).thenReturn(queryParameter);
    when(queryParameter.literal("bar")).thenReturn(queryParameter);
    when(query.execute()).thenReturn(Arrays.asList(new Object[] { "blue", 21L }, new Object[] { "red", 17L }));
    assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 3, "bar"));
    verify(query).setLimit(2);
    verify(query).addFilter(this.mocker.getInstance(QueryFilter.class, "text"));
    verify(queryParameter, times(2)).anyChars();
    assertEquals(2, values.getPropertyValues().size());
    assertEquals("red", values.getPropertyValues().get(0).getValue());
    assertEquals(17L, values.getPropertyValues().get(0).getMetaData().get("count"));
    assertEquals("blue", values.getPropertyValues().get(1).getValue());
    assertEquals(21L, values.getPropertyValues().get(1).getMetaData().get("count"));
}
Also used : QueryParameter(org.xwiki.query.QueryParameter) QueryFilter(org.xwiki.query.QueryFilter) PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) Query(org.xwiki.query.Query) PropertyValue(org.xwiki.rest.model.jaxb.PropertyValue) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 3 with PropertyValues

use of org.xwiki.rest.model.jaxb.PropertyValues in project xwiki-platform by xwiki.

the class DefaultClassPropertyValuesProviderTest method getValues.

@Test
public void getValues() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    ClassPropertyValuesProvider dbListValuesProvider = mock(ClassPropertyValuesProvider.class);
    ComponentManager contextComponentManager = this.mocker.getInstance(ComponentManager.class, "context");
    PropertyValues values = new PropertyValues();
    when(contextComponentManager.getInstance(ClassPropertyValuesProvider.class, "DBList")).thenReturn(dbListValuesProvider);
    when(dbListValuesProvider.getValues(propertyReference, 13, "one", "two")).thenReturn(values);
    assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 13, "one", "two"));
}
Also used : ClassPropertyValuesProvider(org.xwiki.rest.resources.classes.ClassPropertyValuesProvider) PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) ComponentManager(org.xwiki.component.manager.ComponentManager) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 4 with PropertyValues

use of org.xwiki.rest.model.jaxb.PropertyValues in project xwiki-platform by xwiki.

the class UsersClassPropertyValuesProviderTest method getValuesLocal.

@Test
public void getValuesLocal() throws Exception {
    when(this.wikiUserManager.getUserScope(this.classReference.getWikiReference().getName())).thenReturn(UserScope.LOCAL_ONLY);
    DocumentReference aliceReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.allowedValuesQuery.execute()).thenReturn(Collections.singletonList(new Object[] { aliceReference, " Alice One " }));
    when(this.xcontext.getWiki().getDocument(aliceReference, this.xcontext)).thenReturn(mock(XWikiDocument.class, "alice"));
    QueryFilter documentFilter = this.mocker.getInstance(QueryFilter.class, "document");
    QueryFilter viewableFilter = this.mocker.getInstance(QueryFilter.class, "viewable");
    List<QueryFilter> filters = mock(List.class);
    DocumentReference bobReference = new DocumentReference("wiki", "Users", "Bob");
    when(this.usedValuesQuery.getFilters()).thenReturn(filters);
    when(this.usedValuesQuery.execute()).thenReturn(Arrays.asList(new Object[] { bobReference, 17L }, new Object[] { aliceReference, 3L }));
    EntityReferenceSerializer<String> compactSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "compact");
    when(compactSerializer.serialize(aliceReference, this.classReference.getWikiReference())).thenReturn("Users.Alice");
    when(compactSerializer.serialize(bobReference, this.classReference.getWikiReference())).thenReturn("Users.Bob");
    when(this.xcontext.getWiki().getURL(aliceReference, this.xcontext)).thenReturn("url/to/alice");
    when(this.xcontext.getWiki().getURL(bobReference, this.xcontext)).thenReturn("url/to/bob");
    XWikiDocument bobProfile = mock(XWikiDocument.class);
    XWikiAttachment bobAvatar = mock(XWikiAttachment.class);
    AttachmentReference bobAvatarReference = new AttachmentReference("somePhoto.png", bobReference);
    when(this.xcontext.getWiki().getDocument(bobReference, this.xcontext)).thenReturn(bobProfile);
    when(bobProfile.getStringValue("avatar")).thenReturn(bobAvatarReference.getName());
    when(bobProfile.getAttachment("somePhoto.png")).thenReturn(bobAvatar);
    when(bobAvatar.isImage(this.xcontext)).thenReturn(true);
    when(bobAvatar.getReference()).thenReturn(bobAvatarReference);
    when(this.xcontext.getWiki().getURL(bobAvatarReference, "download", "width=30&height=30&keepAspectRatio=true", null, this.xcontext)).thenReturn("url/to/bob/avatar");
    PropertyValues values = this.mocker.getComponentUnderTest().getValues(this.propertyReference, 5, "foo");
    assertEquals(2, values.getPropertyValues().size());
    assertEquals("Users.Alice", values.getPropertyValues().get(0).getValue());
    assertEquals("Alice One", values.getPropertyValues().get(0).getMetaData().get("label"));
    assertEquals(3L, values.getPropertyValues().get(0).getMetaData().get("count"));
    assertEquals("url/to/noavatar.png", values.getPropertyValues().get(0).getMetaData().get("icon"));
    assertEquals("url/to/alice", values.getPropertyValues().get(0).getMetaData().get("url"));
    assertEquals("Users.Bob", values.getPropertyValues().get(1).getValue());
    assertEquals("Bob", values.getPropertyValues().get(1).getMetaData().get("label"));
    assertEquals(17L, values.getPropertyValues().get(1).getMetaData().get("count"));
    assertEquals("url/to/bob/avatar", values.getPropertyValues().get(1).getMetaData().get("icon"));
    assertEquals("url/to/bob", values.getPropertyValues().get(1).getMetaData().get("url"));
    verify(this.allowedValuesQuery, never()).setWiki(any(String.class));
    verify(this.allowedValuesQuery, times(1)).execute();
    verify(filters).clear();
    verify(this.usedValuesQuery).addFilter(documentFilter);
    verify(this.usedValuesQuery).addFilter(viewableFilter);
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) QueryFilter(org.xwiki.query.QueryFilter) PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with PropertyValues

use of org.xwiki.rest.model.jaxb.PropertyValues in project xwiki-platform by xwiki.

the class DBListClassPropertyValuesProviderTest method getValuesAllowed.

@Test
public void getValuesAllowed() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference();
    PropertyValues values = new PropertyValues();
    when(this.authorExecutor.call(any(), eq(authorReference))).thenReturn(values);
    assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 3));
    assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 0, "text"));
}
Also used : PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

PropertyValues (org.xwiki.rest.model.jaxb.PropertyValues)10 Test (org.junit.Test)8 DocumentReference (org.xwiki.model.reference.DocumentReference)7 ClassPropertyReference (org.xwiki.model.reference.ClassPropertyReference)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 PropertyValue (org.xwiki.rest.model.jaxb.PropertyValue)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 QueryFilter (org.xwiki.query.QueryFilter)2 Link (org.xwiki.rest.model.jaxb.Link)2 ClassPropertyValuesProvider (org.xwiki.rest.resources.classes.ClassPropertyValuesProvider)2 DBListClass (com.xpn.xwiki.objects.classes.DBListClass)1 URI (java.net.URI)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1 WikiReference (org.xwiki.model.reference.WikiReference)1 Query (org.xwiki.query.Query)1 QueryParameter (org.xwiki.query.QueryParameter)1 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)1