Search in sources :

Example 1 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class JsonApiRequestProcessorTest method setup.

@Before
public void setup() {
    TaskRepository.clear();
    boot = new CrnkBoot();
    boot.addModule(new Module() {

        @Override
        public String getModuleName() {
            return "test";
        }

        @Override
        public void setupModule(ModuleContext context) {
            moduleContext = context;
        }
    });
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost:8080"));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.boot();
    Task task = new Task();
    task.setId(1L);
    task.setName("SomeTask");
    task.setLinksInformation(new TaskLinks());
    TaskRepository tasks = new TaskRepository();
    tasks.save(task);
    processor = new JsonApiRequestProcessor(moduleContext);
    requestContextBase = Mockito.mock(HttpRequestContextBase.class);
    requestContext = new HttpRequestContextBaseAdapter(requestContextBase);
    HttpRequestContextProvider requestContextProvider = boot.getModuleRegistry().getHttpRequestContextProvider();
    requestContextProvider.onRequestStarted(requestContext);
}
Also used : HttpRequestContextBaseAdapter(io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter) Task(io.crnk.core.mock.models.Task) TaskRepository(io.crnk.core.mock.repository.TaskRepository) JsonApiRequestProcessor(io.crnk.core.engine.internal.http.JsonApiRequestProcessor) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Module(io.crnk.core.module.Module) TaskLinks(io.crnk.core.mock.models.TaskLinks) Before(org.junit.Before)

Example 2 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class ImplicitOwnerBasedRelationshipRepositoryTest method setup.

@Before
public void setup() {
    MockRepositoryUtil.clear();
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.getEntry(RelationIdTestResource.class);
    relRepository = new ImplicitOwnerBasedRelationshipRepository(RelationIdTestResource.class, Schedule.class);
    relRepository.setResourceRegistry(resourceRegistry);
    taskProjectRepository = new ImplicitOwnerBasedRelationshipRepository(Task.class, Project.class);
    taskProjectRepository.setResourceRegistry(resourceRegistry);
    testRepository = (RelationIdTestRepository) entry.getResourceRepository().getResourceRepository();
    testRepository.setResourceRegistry(resourceRegistry);
    resource = new RelationIdTestResource();
    resource.setId(2L);
    resource.setName("relationId");
    testRepository.create(resource);
    scheduleRepository = new ScheduleRepositoryImpl();
    schedule3 = new Schedule();
    schedule3.setId(3L);
    schedule3.setName("schedule");
    scheduleRepository.create(schedule3);
    for (int i = 0; i < 10; i++) {
        schedule = new Schedule();
        schedule.setId(4L + i);
        schedule.setName("schedule");
        scheduleRepository.create(schedule);
        projectRepository = new ProjectRepository();
        project = new Project();
        project.setId(42L + i);
        project.setName("project");
        projectRepository.save(project);
        taskRepository = new TaskRepository();
        task = new Task();
        task.setId(13L + i);
        task.setName("task");
        taskRepository.save(task);
    }
}
Also used : Task(io.crnk.core.mock.models.Task) ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ScheduleRepositoryImpl(io.crnk.core.mock.repository.ScheduleRepositoryImpl) Project(io.crnk.core.mock.models.Project) CrnkBoot(io.crnk.core.boot.CrnkBoot) ImplicitOwnerBasedRelationshipRepository(io.crnk.core.repository.implicit.ImplicitOwnerBasedRelationshipRepository) Schedule(io.crnk.core.mock.models.Schedule) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) RelationIdTestResource(io.crnk.core.mock.models.RelationIdTestResource) Before(org.junit.Before)

Example 3 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class OppositeFowardingRelationshipRepositoryTest method checkFindOneTargetFromCollection.

@Test
public void checkFindOneTargetFromCollection() {
    TaskRepository taskRepository = new TaskRepository();
    Task task = new Task();
    task.setId(13L);
    task.setName("task");
    taskRepository.save(task);
    ProjectRepository projectRepository = new ProjectRepository();
    Project project = new Project();
    project.setId(42L);
    project.setName("project");
    project.setTasks(Arrays.asList(task));
    projectRepository.save(project);
    relRepository = new ForwardingRelationshipRepository(Task.class, null, ForwardingDirection.OPPOSITE, ForwardingDirection.OPPOSITE);
    relRepository.setResourceRegistry(resourceRegistry);
    QuerySpec querySpec = new QuerySpec(Task.class);
    Project foundProject = (Project) relRepository.findOneTarget(13L, "project", querySpec);
    Assert.assertEquals(42L, foundProject.getId().longValue());
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) ForwardingRelationshipRepository(io.crnk.core.repository.foward.ForwardingRelationshipRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 4 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class OppositeFowardingRelationshipRepositoryTest method checkFindTargetWithNotLoadedRelationship.

@Test
public void checkFindTargetWithNotLoadedRelationship() {
    TaskRepository taskRepository = new TaskRepository();
    Task task = new Task();
    task.setId(13L);
    task.setName("task");
    taskRepository.save(task);
    ProjectRepository projectRepository = new ProjectRepository();
    Project project = new Project();
    project.setId(42L);
    project.setName("project");
    project.setTasks(null);
    projectRepository.save(project);
    relRepository = new ForwardingRelationshipRepository(Task.class, null, ForwardingDirection.OPPOSITE, ForwardingDirection.OPPOSITE);
    relRepository.setResourceRegistry(resourceRegistry);
    QuerySpec querySpec = new QuerySpec(Task.class);
    try {
        relRepository.findOneTarget(13L, "project", querySpec);
        Assert.fail();
    } catch (IllegalStateException e) {
        Assert.assertTrue(e.getMessage().contains("field tasks is null for"));
    }
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) ForwardingRelationshipRepository(io.crnk.core.repository.foward.ForwardingRelationshipRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 5 with TaskRepository

use of io.crnk.core.mock.repository.TaskRepository in project crnk-framework by crnk-project.

the class OppositeFowardingRelationshipRepositoryTest method checkFindTargetWithInvalidNullReturnId.

@Test
public void checkFindTargetWithInvalidNullReturnId() {
    TaskRepository taskRepository = new TaskRepository();
    Task task = new Task();
    task.setId(13L);
    task.setName("task");
    taskRepository.save(task);
    ProjectRepository projectRepository = new ProjectRepository();
    Project project = new Project();
    project.setId(42L);
    project.setName("project");
    project.setTasks(Arrays.asList(task));
    projectRepository.save(project);
    // manipulate
    task.setId(null);
    relRepository = new ForwardingRelationshipRepository(Task.class, null, ForwardingDirection.OPPOSITE, ForwardingDirection.OPPOSITE);
    relRepository.setResourceRegistry(resourceRegistry);
    QuerySpec querySpec = new QuerySpec(Task.class);
    try {
        relRepository.findOneTarget(13L, "project", querySpec);
        Assert.fail();
    } catch (IllegalStateException e) {
        Assert.assertTrue(e.getMessage().contains("id is null"));
    }
}
Also used : Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) ProjectRepository(io.crnk.core.mock.repository.ProjectRepository) ForwardingRelationshipRepository(io.crnk.core.repository.foward.ForwardingRelationshipRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Aggregations

TaskRepository (io.crnk.core.mock.repository.TaskRepository)13 Task (io.crnk.core.mock.models.Task)10 Test (org.junit.Test)9 ProjectRepository (io.crnk.core.mock.repository.ProjectRepository)8 Project (io.crnk.core.mock.models.Project)7 ForwardingRelationshipRepository (io.crnk.core.repository.foward.ForwardingRelationshipRepository)6 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)5 CrnkBoot (io.crnk.core.boot.CrnkBoot)4 Before (org.junit.Before)4 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)3 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)3 Response (io.crnk.core.engine.dispatcher.Response)2 Document (io.crnk.core.engine.document.Document)2 Relationship (io.crnk.core.engine.document.Relationship)2 Resource (io.crnk.core.engine.document.Resource)2 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)2 Schedule (io.crnk.core.mock.models.Schedule)2