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