use of org.xwiki.model.reference.ClassPropertyReference 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.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class DefaultClassPropertyValuesProviderTest method getValuesForMissingProperty.
@Test
public void getValuesForMissingProperty() throws Exception {
ClassPropertyReference propertyReference = new ClassPropertyReference("status", this.classReference);
EntityReferenceSerializer<String> entityReferenceSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
when(entityReferenceSerializer.serialize(propertyReference)).thenReturn("status reference");
try {
this.mocker.getComponentUnderTest().getValues(propertyReference, 13);
fail();
} catch (XWikiRestException expected) {
assertEquals("No such property [status reference].", expected.getMessage());
}
}
use of org.xwiki.model.reference.ClassPropertyReference 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.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class SolrFieldStringEntityReferenceResolverTest method resolve.
@Test
public void resolve() throws Exception {
EntityReferenceProvider currentEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class, "current");
when(currentEntityReferenceProvider.getDefaultReference(EntityType.WIKI)).thenReturn(new WikiReference("test"));
EntityReferenceResolver<String> resolver = mocker.getComponentUnderTest();
DocumentReference documentReference = new DocumentReference("test", Arrays.asList("My App", "Code", "Model"), "A Class");
assertEquals(new ClassPropertyReference("title", documentReference), new ClassPropertyReference(resolver.resolve("My App.Code.Model.A Class.title", EntityType.CLASS_PROPERTY)));
documentReference = new DocumentReference("test", Arrays.asList("My.App", "Co.de"), "A.Class");
assertEquals(new ClassPropertyReference("ti.tle", documentReference), new ClassPropertyReference(resolver.resolve("My..App.Co..de.A..Class.ti..tle", EntityType.CLASS_PROPERTY)));
assertEquals(new SpaceReference("0.9", new SpaceReference("a..z", new WikiReference("test"))), new SpaceReference(resolver.resolve("a....z.0..9", EntityType.SPACE)));
// Relative reference resolved based on the given parameters.
assertEquals(new ClassPropertyReference("title", new DocumentReference("foo", Arrays.asList("Code", "Model"), "A Class")), new ClassPropertyReference(resolver.resolve("Code.Model.A Class.title", EntityType.CLASS_PROPERTY, new SpaceReference("My App", new WikiReference("foo")))));
// Relative reference resolve based on the current entity.
when(currentEntityReferenceProvider.getDefaultReference(EntityType.SPACE)).thenReturn(new EntityReference("Code", EntityType.SPACE, new EntityReference("My App", EntityType.SPACE, null)));
assertEquals(new ClassPropertyReference("title", new DocumentReference("bar", Arrays.asList("My App", "Code"), "A Class")), new ClassPropertyReference(resolver.resolve("A Class.title", EntityType.CLASS_PROPERTY, new WikiReference("bar"))));
}
use of org.xwiki.model.reference.ClassPropertyReference in project xwiki-platform by xwiki.
the class SolrFieldStringEntityReferenceSerializerTest method serialize.
@Test
public void serialize() {
assertNull(serializer.serialize(null));
assertEquals("math.My App.Code.Some Class.title", serializer.serialize(new ClassPropertyReference("title", new DocumentReference("math", Arrays.asList("My App", "Code"), "Some Class"))));
assertEquals("ma..th.My..App.Co....de.Some..Class.ti..tle", serializer.serialize(new ClassPropertyReference("ti.tle", new DocumentReference("ma.th", Arrays.asList("My.App", "Co..de"), "Some.Class"))));
}
Aggregations