Search in sources :

Example 11 with TaskRepository

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

the class ResourceFieldContributorTest method checkInclusionUponRequest.

@Test
public void checkInclusionUponRequest() {
    TaskRepository repo = new TaskRepository();
    Task task = new Task();
    task.setId(1L);
    task.setName("someTask");
    repo.save(task);
    HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
    HttpRequestContextProvider httpRequestContextProvider = boot.getModuleRegistry().getHttpRequestContextProvider();
    HttpRequestContext request = Mockito.mock(HttpRequestContext.class);
    httpRequestContextProvider.onRequestStarted(request);
    Map<String, Set<String>> parameters = new HashMap<>();
    parameters.put("include", Sets.newHashSet("contributedProject"));
    Response response = requestDispatcher.dispatchRequest("tasks", "GET", parameters, null, null);
    Document document = response.getDocument();
    Resource resource = document.getCollectionData().get().get(0);
    Assert.assertEquals("1", resource.getId());
    Assert.assertEquals("tasks", resource.getType());
    Assert.assertEquals("someTask", resource.getAttributes().get("name").asText());
    Relationship relationship = resource.getRelationships().get("contributedProject");
    Assert.assertNotNull(relationship);
    ResourceIdentifier relationshipId = relationship.getSingleData().get();
    Assert.assertEquals("projects", relationshipId.getType());
    Assert.assertEquals("11", relationshipId.getId());
    List<Resource> included = document.getIncluded();
    Assert.assertEquals(1, included.size());
    Resource includedResource = included.get(0);
    Assert.assertEquals("projects", includedResource.getType());
    Assert.assertEquals("11", includedResource.getId());
    Assert.assertEquals("someProject", includedResource.getAttributes().get("name").asText());
}
Also used : Task(io.crnk.core.mock.models.Task) Set(java.util.Set) HashMap(java.util.HashMap) ProjectToTaskRepository(io.crnk.core.mock.repository.ProjectToTaskRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) Resource(io.crnk.core.engine.document.Resource) Document(io.crnk.core.engine.document.Document) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) Response(io.crnk.core.engine.dispatcher.Response) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) Relationship(io.crnk.core.engine.document.Relationship) HttpRequestContext(io.crnk.core.engine.http.HttpRequestContext) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider) Test(org.junit.Test)

Example 12 with TaskRepository

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

the class RepositoryInstanceBuilderTest method onExistingInstanceShouldReturnValue.

@Test
public void onExistingInstanceShouldReturnValue() throws Exception {
    // GIVEN
    RepositoryInstanceBuilder<TaskRepository> sut = new RepositoryInstanceBuilder<>(new SampleJsonServiceLocator(), TaskRepository.class);
    // WHEN
    TaskRepository result = sut.buildRepository();
    // THEN
    assertThat(sut.getRepositoryClass()).isEqualTo(TaskRepository.class);
    assertThat(result).isInstanceOf(TaskRepository.class);
}
Also used : TaskRepository(io.crnk.core.mock.repository.TaskRepository) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) Test(org.junit.Test)

Example 13 with TaskRepository

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

the class RepositoryInstanceBuilderTest method onNullInstanceShouldThrowException.

@Test(expected = RepositoryInstanceNotFoundException.class)
public void onNullInstanceShouldThrowException() throws Exception {
    // GIVEN
    RepositoryInstanceBuilder<TaskRepository> sut = new RepositoryInstanceBuilder<>(new JsonServiceLocator() {

        @Override
        public <T> T getInstance(Class<T> clazz) {
            return null;
        }
    }, TaskRepository.class);
    // WHEN
    sut.buildRepository();
}
Also used : TaskRepository(io.crnk.core.mock.repository.TaskRepository) JsonServiceLocator(io.crnk.legacy.locator.JsonServiceLocator) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) 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