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