Search in sources :

Example 6 with ClassPropertyReference

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"));
}
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 7 with ClassPropertyReference

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());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 8 with ClassPropertyReference

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"));
}
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 9 with ClassPropertyReference

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"))));
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 10 with ClassPropertyReference

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"))));
}
Also used : ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

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