use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class BaseControllerTest method prepare.
@Before
public void prepare() {
modificationFilter = Mockito.spy(new ResourceModificationFilterBase());
modificationFilters = Arrays.asList(modificationFilter);
CrnkBoot boot = new CrnkBoot();
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.boot();
objectMapper = boot.getObjectMapper();
resourceRegistry = boot.getResourceRegistry();
moduleRegistry = boot.getModuleRegistry();
pathBuilder = new PathBuilder(resourceRegistry);
typeParser = moduleRegistry.getTypeParser();
documentMapper = boot.getDocumentMapper();
MockRepositoryUtil.clear();
emptyTaskQuery = new QuerySpecAdapter(new QuerySpec(Task.class), resourceRegistry);
emptyProjectQuery = new QuerySpecAdapter(new QuerySpec(Project.class), resourceRegistry);
emptyUserQuery = new QuerySpecAdapter(new QuerySpec(User.class), resourceRegistry);
emptyComplexPojoQuery = new QuerySpecAdapter(new QuerySpec(ComplexPojo.class), resourceRegistry);
emptyMemorandumQuery = new QuerySpecAdapter(new QuerySpec(Memorandum.class), resourceRegistry);
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class AbstractIncludeBehaviorTest method setup.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
super.setup();
ResourceRepositoryAdapter hierarchicalTaskRepository = resourceRegistry.findEntry(HierarchicalTask.class).getResourceRepository(null);
h = new HierarchicalTask();
h.setId(1L);
h.setName("");
h0 = new HierarchicalTask();
h0.setId(2L);
h0.setName("0");
h0.setParent(h);
h1 = new HierarchicalTask();
h1.setId(3L);
h1.setName("1");
h1.setParent(h);
h11 = new HierarchicalTask();
h11.setId(4L);
h11.setName("11");
h11.setParent(h1);
h.setChildren(Arrays.asList(h0, h1));
h0.setChildren(new ArrayList<HierarchicalTask>());
h1.setChildren(Arrays.asList(h11));
h11.setChildren(new ArrayList<HierarchicalTask>());
QueryAdapter emptyQueryAdapter = new QuerySpecAdapter(new QuerySpec(HierarchicalTask.class), resourceRegistry);
hierarchicalTaskRepository.create(h, emptyQueryAdapter);
hierarchicalTaskRepository.create(h0, emptyQueryAdapter);
hierarchicalTaskRepository.create(h1, emptyQueryAdapter);
hierarchicalTaskRepository.create(h11, emptyQueryAdapter);
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class PerTypeIncludeBehaviorTest method includeParentChildren.
@Test
public void includeParentChildren() throws Exception {
QuerySpec querySpec = new QuerySpec(HierarchicalTask.class);
querySpec.includeRelation(Arrays.asList("parent", "children"));
Document document = mapper.toDocument(toResponse(h11), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship parentRelationship = taskResource.getRelationships().get("parent");
assertNotNull(parentRelationship);
assertNotNull(parentRelationship.getSingleData());
ResourceIdentifier parentResource = parentRelationship.getSingleData().get();
assertNotNull(h1.getId().toString(), parentResource.getId());
List<Resource> included = document.getIncluded();
// both parent and children recursively included
assertEquals(3, included.size());
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class PerTypeIncludeBehaviorTest method includeCyclicParent.
@Test
public void includeCyclicParent() throws Exception {
h.setParent(h1);
QuerySpec querySpec = new QuerySpec(HierarchicalTask.class);
querySpec.includeRelation(Arrays.asList("parent"));
Document document = mapper.toDocument(toResponse(h1), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship parentRelationship = taskResource.getRelationships().get("parent");
assertNotNull(parentRelationship);
assertNotNull(parentRelationship.getSingleData());
ResourceIdentifier parentResource = parentRelationship.getSingleData().get();
assertNotNull(h.getId().toString(), parentResource.getId());
List<Resource> included = document.getIncluded();
assertEquals(1, included.size());
assertNotNull(h.getId().toString(), included.get(0).getId());
Relationship rootParent = included.get(0).getRelationships().get("parent");
assertTrue(rootParent.getSingleData().isPresent());
assertNotNull(h1.getId().toString(), rootParent.getSingleData().get().getId());
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class RepositoryFilterTest method prepare.
@Before
public void prepare() {
boot = new CrnkBoot();
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
SimpleModule filterModule = new SimpleModule("filter");
filterModule.addRepositoryFilter(filter);
boot.addModule(filterModule);
boot.boot();
resourceRegistry = boot.getResourceRegistry();
querySpec = new QuerySpec(User.class);
querySpec.setPagingSpec(new OffsetLimitPagingSpec());
queryAdapter = new QuerySpecAdapter(querySpec, resourceRegistry);
scheduleInfo = resourceRegistry.getEntry(Schedule.class).getResourceInformation();
RegistryEntry userEntry = resourceRegistry.getEntry(User.class);
resourceAdapter = userEntry.getResourceRepository(null);
projectRelationAdapter = userEntry.getRelationshipRepository("assignedProjects", null);
taskRelationAdapter = userEntry.getRelationshipRepository("assignedTasks", null);
userInfo = userEntry.getResourceInformation();
UserRepository resourceRepository = (UserRepository) resourceAdapter.getResourceRepository();
user1 = new User();
user1.setId(1L);
resourceRepository.save(user1);
user2 = new User();
user2.setId(2L);
resourceRepository.save(user2);
UserToProjectRepository userProjectRepository = (UserToProjectRepository) ((AnnotatedRelationshipRepositoryAdapter<?, ?, ?, ?>) projectRelationAdapter.getRelationshipRepository()).getImplementationObject();
userProjectRepository.setRelation(user1, 11L, "assignedProjects");
UserToTaskRepository userTaskRepository = new UserToTaskRepository();
userTaskRepository.addRelations(user1, Arrays.asList(21L), "assignedTasks");
userTaskRepository.addRelations(user2, Arrays.asList(22L), "assignedTasks");
assignedTasksField = resourceRegistry.getEntry(User.class).getResourceInformation().findRelationshipFieldByName("assignedTasks");
assignedProjectsField = resourceRegistry.getEntry(User.class).getResourceInformation().findRelationshipFieldByName("assignedProjects");
}
Aggregations