Search in sources :

Example 31 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.

the class ResourceInformationTest method onRelationshipFieldSearchShouldReturnExistingField.

@Test
public void onRelationshipFieldSearchShouldReturnExistingField() throws NoSuchFieldException {
    ResourceField result = sut.findRelationshipFieldByName("value");
    assertThat(result.getUnderlyingName()).isEqualTo("value");
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Test(org.junit.Test)

Example 32 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.

the class FieldOrderedComparatorTest method onNoOrderShouldPersistInsertionOrder.

@Test
public void onNoOrderShouldPersistInsertionOrder() throws Exception {
    // GIVEN
    Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] {}, false));
    // WHEN
    fields.add(fieldB);
    fields.add(fieldA);
    // THEN
    assertThat(fields).containsSequence(fieldB, fieldA);
}
Also used : FieldOrderedComparator(io.crnk.core.engine.internal.utils.FieldOrderedComparator) ResourceField(io.crnk.core.engine.information.resource.ResourceField) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 33 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.

the class FieldOrderedComparatorTest method onAlphabeticOrderShouldSortCorrectly.

@Test
public void onAlphabeticOrderShouldSortCorrectly() throws Exception {
    // GIVEN
    Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] {}, true));
    // WHEN
    fields.add(fieldB);
    fields.add(fieldA);
    // THEN
    assertThat(fields).containsSequence(fieldA, fieldB);
}
Also used : FieldOrderedComparator(io.crnk.core.engine.internal.utils.FieldOrderedComparator) ResourceField(io.crnk.core.engine.information.resource.ResourceField) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 34 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.

the class FieldOrderedComparatorTest method onOneFieldShouldSortCorrectly.

@Test
public void onOneFieldShouldSortCorrectly() throws Exception {
    // GIVEN
    Set<ResourceField> fields = new TreeSet<>(new FieldOrderedComparator(new String[] { "b" }, false));
    // WHEN
    fields.add(fieldA);
    fields.add(fieldB);
    // THEN
    assertThat(fields).containsSequence(fieldB, fieldA);
}
Also used : FieldOrderedComparator(io.crnk.core.engine.internal.utils.FieldOrderedComparator) ResourceField(io.crnk.core.engine.information.resource.ResourceField) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 35 with ResourceField

use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.

the class MetaModule method registerRepositories.

protected void registerRepositories(DefaultResourceInformationProvider informationBuilder, Set<Class<? extends MetaElement>> metaClasses) {
    Supplier<MetaLookup> lookupSupplier = new Supplier<MetaLookup>() {

        @Override
        public MetaLookup get() {
            return getLookup();
        }
    };
    for (Class<? extends MetaElement> metaClass : metaClasses) {
        context.addRepository(new MetaResourceRepositoryImpl<>(lookupSupplier, metaClass));
        HashSet<Class<? extends MetaElement>> targetResourceClasses = new HashSet<>();
        ResourceInformation information = informationBuilder.build(metaClass);
        for (ResourceField relationshipField : information.getRelationshipFields()) {
            if (!MetaElement.class.isAssignableFrom(relationshipField.getElementType())) {
                throw new IllegalStateException("only MetaElement relations supported, got " + relationshipField);
            }
            targetResourceClasses.add((Class<? extends MetaElement>) relationshipField.getElementType());
        }
        for (Class<? extends MetaElement> targetResourceClass : targetResourceClasses) {
            context.addRepository(new MetaRelationshipRepositoryImpl(lookupSupplier, metaClass, targetResourceClass));
        }
    }
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaElement(io.crnk.meta.model.MetaElement) ResourceField(io.crnk.core.engine.information.resource.ResourceField) MetaRelationshipRepositoryImpl(io.crnk.meta.internal.MetaRelationshipRepositoryImpl) Supplier(io.crnk.core.utils.Supplier) HashSet(java.util.HashSet)

Aggregations

ResourceField (io.crnk.core.engine.information.resource.ResourceField)109 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)75 Test (org.junit.Test)41 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)36 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)13 QuerySpec (io.crnk.core.queryspec.QuerySpec)11 ArrayList (java.util.ArrayList)9 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)8 Response (io.crnk.core.engine.dispatcher.Response)8 Resource (io.crnk.core.engine.document.Resource)8 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)8 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)8 HashSet (java.util.HashSet)8 Document (io.crnk.core.engine.document.Document)7 Task (io.crnk.core.mock.models.Task)7 Serializable (java.io.Serializable)7 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)6 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)6 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)6