use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.
the class AbstractJpaTest method setup.
@Before
public void setup() {
ModuleRegistry moduleRegistry = new ModuleRegistry();
moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost:1234"));
resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
module = JpaModule.newServerModule(emFactory, em, transactionRunner);
setupModule(module);
moduleRegistry.addModule(new JacksonModule(new ObjectMapper()));
moduleRegistry.addModule(new CoreModule());
moduleRegistry.addModule(module);
moduleRegistry.setServiceDiscovery(new EmptyServiceDiscovery());
moduleRegistry.init(new ObjectMapper());
queryFactory = createQueryFactory(em);
module.setQueryFactory(queryFactory);
clear();
for (int i = 0; i < numTestEntities; i++) {
TestEmbeddedIdEntity idEntity = new TestEmbeddedIdEntity();
idEntity.setId(new TestIdEmbeddable(i, "test" + i));
idEntity.setLongValue(100L + i);
em.persist(idEntity);
RelatedEntity related = new RelatedEntity();
related.setId(100L + i);
related.setStringValue("related" + i);
em.persist(related);
TestAnyType anyValue = new TestAnyType();
if (i == 0)
anyValue.setValue("first");
else
anyValue.setValue(i);
TestEmbeddable embValue = new TestEmbeddable();
embValue.setEmbIntValue(i);
embValue.setEmbStringValue("emb" + i);
embValue.setNestedValue(new TestNestedEmbeddable(i == 0));
embValue.setAnyValue(anyValue);
TestEntity test = new TestEntity();
test.setStringValue("test" + i);
test.setId((long) i);
test.setLongValue(i);
test.setEmbValue(embValue);
// left join sorting
if (i != numTestEntities - 1) {
test.setOneRelatedValue(related);
test.getMapValue().put("a", "a" + i);
test.getMapValue().put("b", "b" + i);
test.getMapValue().put("c", "c" + i);
}
em.persist(test);
// inheritance
SingleTableBaseEntity singleTableBase = new SingleTableBaseEntity();
singleTableBase.setId((long) i);
singleTableBase.setStringValue("base" + i);
em.persist(singleTableBase);
SingleTableChildEntity singleTableChild = new SingleTableChildEntity();
singleTableChild.setId((long) i + numTestEntities);
singleTableChild.setStringValue("child" + i);
singleTableChild.setIntValue(i);
em.persist(singleTableChild);
JoinedTableBaseEntity joinedTableBase = new JoinedTableBaseEntity();
joinedTableBase.setId((long) i);
joinedTableBase.setStringValue("base" + i);
em.persist(joinedTableBase);
JoinedTableChildEntity joinedTableChild = new JoinedTableChildEntity();
joinedTableChild.setId((long) i + numTestEntities);
joinedTableChild.setStringValue("child" + i);
joinedTableChild.setIntValue(i);
em.persist(joinedTableChild);
TablePerClassBaseEntity tablePerClassBase = new TablePerClassBaseEntity();
tablePerClassBase.setId((long) i);
tablePerClassBase.setStringValue("base" + i);
em.persist(tablePerClassBase);
TablePerClassChildEntity tablePerClassChild = new TablePerClassChildEntity();
tablePerClassChild.setId((long) i + numTestEntities);
tablePerClassChild.setStringValue("child" + i);
tablePerClassChild.setIntValue(i);
em.persist(tablePerClassChild);
}
em.flush();
em.clear();
queryFactory = createQueryFactory(em);
module.setQueryFactory(queryFactory);
}
use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.
the class CrnkBoot method setupResourceRegistry.
private ResourceRegistryPart setupResourceRegistry() {
Map<String, ResourceRegistryPart> registryParts = moduleRegistry.getRegistryParts();
ResourceRegistryPart rootPart;
if (registryParts.isEmpty()) {
rootPart = new DefaultResourceRegistryPart();
} else {
HierarchicalResourceRegistryPart hierarchialPart = new HierarchicalResourceRegistryPart();
for (Map.Entry<String, ResourceRegistryPart> entry : registryParts.entrySet()) {
hierarchialPart.putPart(entry.getKey(), entry.getValue());
}
if (!registryParts.containsKey("")) {
moduleRegistry.getContext().addRegistryPart("", new DefaultResourceRegistryPart());
}
rootPart = hierarchialPart;
}
resourceRegistry = new ResourceRegistryImpl(rootPart, moduleRegistry);
return rootPart;
}
use of io.crnk.core.engine.internal.registry.ResourceRegistryImpl in project crnk-framework by crnk-project.
the class OffsetLimitPagingBehaviorTest method testBuild.
@Test
public void testBuild() {
PagingBehavior pagingBehavior = new OffsetLimitPagingBehavior();
OffsetLimitPagingSpec pagingSpec = new OffsetLimitPagingSpec(0L, 10L);
ModuleRegistry moduleRegistry = new ModuleRegistry();
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
QuerySpec spec = new QuerySpec(Task.class);
QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(spec, resourceRegistry);
querySpecAdapter.setPagingSpec(pagingSpec);
PagingSpecUrlBuilder urlBuilder = mock(PagingSpecUrlBuilder.class);
when(urlBuilder.build(any(QuerySpecAdapter.class))).thenReturn("http://some.org");
DefaultPagedMetaInformation pagedMetaInformation = new DefaultPagedMetaInformation();
pagedMetaInformation.setTotalResourceCount(30L);
ResourceList resourceList = new DefaultResourceList(pagedMetaInformation, null);
for (int i = 0; i < 30; i++) {
resourceList.add(new Task());
}
PagedLinksInformation pagedLinksInformation = new DefaultPagedLinksInformation();
pagingBehavior.build(pagedLinksInformation, resourceList, querySpecAdapter, urlBuilder);
assertThat(pagedLinksInformation.getFirst(), equalTo("http://some.org"));
assertThat(pagedLinksInformation.getNext(), equalTo("http://some.org"));
assertNull(pagedLinksInformation.getPrev());
assertThat(pagedLinksInformation.getLast(), equalTo("http://some.org"));
}
Aggregations