Search in sources :

Example 71 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class DefaultQueryParamsSerializerTest method check.

private void check(String expectedUrl, Object id, QueryParams queryParams) {
    RegistryEntry entry = resourceRegistry.getEntryForClass(Task.class);
    String actualUrl = urlBuilder.buildUrl(entry.getResourceInformation(), id, queryParams);
    assertEquals(expectedUrl, actualUrl);
}
Also used : RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 72 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class RegistryEntryTest method onValidParentShouldReturnTrue.

@Test
public void onValidParentShouldReturnTrue() throws Exception {
    // GIVEN
    RegistryEntry thing = new RegistryEntry(newResourceEntry(Thing.class, "things"));
    RegistryEntry document = new RegistryEntry(newResourceEntry(Document.class, "documents"));
    document.setParentRegistryEntry(thing);
    RegistryEntry memorandum = new RegistryEntry(newResourceEntry(Memorandum.class, "memorandum"));
    memorandum.setParentRegistryEntry(document);
    // WHEN
    boolean result = memorandum.isParent(thing);
    // THEN
    assertThat(result).isTrue();
}
Also used : Memorandum(io.crnk.core.mock.models.Memorandum) Document(io.crnk.core.mock.models.Document) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Thing(io.crnk.core.mock.models.Thing) Test(org.junit.Test)

Example 73 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class RegistryEntryTest method onInvalidParentShouldReturnFalse.

@Test
public void onInvalidParentShouldReturnFalse() throws Exception {
    // GIVEN
    RegistryEntry document = new RegistryEntry(newResourceEntry(Document.class, "documents"));
    RegistryEntry task = new RegistryEntry(newResourceEntry(Task.class, "tasks"));
    // WHEN
    boolean result = document.isParent(task);
    // THEN
    assertThat(result).isFalse();
}
Also used : Task(io.crnk.core.mock.models.Task) Document(io.crnk.core.mock.models.Document) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 74 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class RegistryEntryTest method onInvalidRelationshipClassShouldThrowException.

@Test
public void onInvalidRelationshipClassShouldThrowException() throws Exception {
    // GIVEN
    ResourceRepositoryInformation repositoryInformation = newRepositoryInformation(Task.class, "tasks");
    ResourceField relationshipField = repositoryInformation.getResourceInformation().get().findFieldByUnderlyingName("tasks");
    Map relRepos = new HashMap<>();
    relRepos.put(relationshipField, new DirectResponseRelationshipEntry(new RepositoryInstanceBuilder(new SampleJsonServiceLocator(), TaskToProjectRepository.class)));
    RegistryEntry sut = new RegistryEntry(new DirectResponseResourceEntry(null, repositoryInformation), relRepos);
    // THEN
    expectedException.expect(ResourceFieldNotFoundException.class);
    // WHEN
    sut.getRelationshipRepository("users", null);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) HashMap(java.util.HashMap) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) HashMap(java.util.HashMap) Map(java.util.Map) RepositoryInstanceBuilder(io.crnk.legacy.registry.RepositoryInstanceBuilder) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 75 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class HasNextBasedPagedLinksInformationTest method setup.

@Before
public void setup() {
    HasNextPageTestRepository.clear();
    super.setup();
    RegistryEntry registryEntry = resourceRegistry.getEntry(Task.class);
    HasNextPageTestRepository repo = (HasNextPageTestRepository) registryEntry.getResourceRepository(null).getResourceRepository();
    repo = Mockito.spy(repo);
    adapter = registryEntry.getResourceRepository(null);
    QueryAdapter queryAdapter = new QuerySpecAdapter(querySpec(), resourceRegistry);
    for (long i = 0; i < 5; i++) {
        Task task = new Task();
        task.setId(i);
        task.setName("myTask");
        adapter.create(task, queryAdapter);
    }
}
Also used : Task(io.crnk.core.mock.models.Task) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Before(org.junit.Before)

Aggregations

RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)119 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)60 Test (org.junit.Test)38 ResourceField (io.crnk.core.engine.information.resource.ResourceField)36 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)19 QuerySpec (io.crnk.core.queryspec.QuerySpec)18 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 Serializable (java.io.Serializable)14 Task (io.crnk.core.mock.models.Task)13 Response (io.crnk.core.engine.dispatcher.Response)12 Document (io.crnk.core.engine.document.Document)11 Resource (io.crnk.core.engine.document.Resource)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)9 FilterSpec (io.crnk.core.queryspec.FilterSpec)9 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)8 Before (org.junit.Before)8 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)6