-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
610 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
crnk-client/src/test/java/io/crnk/client/inheritance/SamePathInheritanceClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.crnk.client.inheritance; | ||
|
||
import io.crnk.client.AbstractClientTest; | ||
import io.crnk.client.inheritance.repositories.cyclic.CyclicResourceARepository; | ||
import io.crnk.client.inheritance.repositories.cyclic.CyclicResourceBRespository; | ||
import io.crnk.client.inheritance.repositories.cyclic.CyclicResourceCRepository; | ||
import io.crnk.client.inheritance.repositories.related.RelatedResourceARepository; | ||
import io.crnk.client.inheritance.repositories.related.RelatedResourceBRepository; | ||
import io.crnk.client.inheritance.resources.cyclic.CyclicResourceA; | ||
import io.crnk.client.inheritance.resources.related.RelatedResourceA; | ||
import io.crnk.client.inheritance.resources.related.RelatedResourceAsub1; | ||
import io.crnk.core.module.SimpleModule; | ||
import io.crnk.core.queryspec.QuerySpec; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Examples makes use of Inheritance of resources that share a common resource path. Make sure it correctly handles | ||
* multiple resources with same path and able to find fields on subtypes. | ||
* | ||
* @author syri. | ||
*/ | ||
public class SamePathInheritanceClientTest extends AbstractClientTest { | ||
|
||
|
||
@Override | ||
protected TestApplication configure() { | ||
TestApplication app = super.configure(); | ||
SimpleModule cyclicModule = new SimpleModule("crnk-test"); | ||
cyclicModule.addRepository(new CyclicResourceARepository()); | ||
cyclicModule.addRepository(new CyclicResourceBRespository()); | ||
cyclicModule.addRepository(new CyclicResourceCRepository()); | ||
cyclicModule.addRepository(new RelatedResourceARepository()); | ||
cyclicModule.addRepository(new RelatedResourceBRepository()); | ||
app.getFeature().addModule(cyclicModule); | ||
return app; | ||
} | ||
|
||
@Test | ||
public void testInheritedRelation() { | ||
QuerySpec querySpec = new QuerySpec(RelatedResourceA.class); | ||
RelatedResourceA resource = client.getRepositoryForType(RelatedResourceA.class).findOne(1L, querySpec); | ||
RelatedResourceAsub1 subResource = (RelatedResourceAsub1) resource; | ||
Assert.assertEquals(1, subResource.getRelatedResourceBS().size()); | ||
} | ||
|
||
@Test | ||
public void testCyclicRelationsRepository() { | ||
// Crash | ||
client.getRepositoryForType(CyclicResourceA.class); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
crnk-client/src/test/java/io/crnk/client/inheritance/repositories/RepositoryData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.crnk.client.inheritance.repositories; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import io.crnk.client.inheritance.resources.related.RelatedResourceA; | ||
import io.crnk.client.inheritance.resources.related.RelatedResourceAsub1; | ||
import io.crnk.client.inheritance.resources.related.RelatedResourceB; | ||
|
||
/* | ||
* @author syri. | ||
*/ | ||
public class RepositoryData { | ||
|
||
public static final List<RelatedResourceA> RESOURCE_A_LIST; | ||
|
||
public static final List<RelatedResourceB> RESOURCE_B_LIST; | ||
|
||
static { | ||
RelatedResourceAsub1 relatedResourceAsub1 = new RelatedResourceAsub1(); | ||
relatedResourceAsub1.setId(1L); | ||
|
||
RelatedResourceB relatedResourceB = new RelatedResourceB(); | ||
relatedResourceB.setId(10L); | ||
|
||
relatedResourceAsub1.setRelatedResourceBS(Collections.singletonList(relatedResourceB)); | ||
relatedResourceB.setRelatedResourceAsub1(relatedResourceAsub1); | ||
|
||
RESOURCE_A_LIST = Collections.singletonList(relatedResourceAsub1); | ||
RESOURCE_B_LIST = Collections.singletonList(relatedResourceB); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...c/test/java/io/crnk/client/inheritance/repositories/cyclic/CyclicResourceARepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.crnk.client.inheritance.repositories.cyclic; | ||
|
||
import java.util.Collections; | ||
|
||
import io.crnk.client.inheritance.resources.cyclic.CyclicResourceA; | ||
import io.crnk.core.queryspec.QuerySpec; | ||
import io.crnk.core.repository.ResourceRepositoryBase; | ||
import io.crnk.core.resource.list.ResourceList; | ||
|
||
/* | ||
* @author syri. | ||
*/ | ||
public class CyclicResourceARepository extends ResourceRepositoryBase<CyclicResourceA, Long> { | ||
|
||
public CyclicResourceARepository() { | ||
super(CyclicResourceA.class); | ||
} | ||
|
||
@Override | ||
public ResourceList<CyclicResourceA> findAll(QuerySpec querySpec) { | ||
return querySpec.apply(Collections.emptyList()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../test/java/io/crnk/client/inheritance/repositories/cyclic/CyclicResourceBRespository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.crnk.client.inheritance.repositories.cyclic; | ||
|
||
import java.util.Collections; | ||
|
||
import io.crnk.client.inheritance.resources.cyclic.CyclicResourceB; | ||
import io.crnk.core.queryspec.QuerySpec; | ||
import io.crnk.core.repository.ResourceRepositoryBase; | ||
import io.crnk.core.resource.list.ResourceList; | ||
|
||
/* | ||
* @author syri. | ||
*/ | ||
public class CyclicResourceBRespository extends ResourceRepositoryBase<CyclicResourceB, Long> { | ||
|
||
public CyclicResourceBRespository() { | ||
super(CyclicResourceB.class); | ||
} | ||
|
||
@Override | ||
public ResourceList<CyclicResourceB> findAll(QuerySpec querySpec) { | ||
return querySpec.apply(Collections.emptyList()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...c/test/java/io/crnk/client/inheritance/repositories/cyclic/CyclicResourceCRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.crnk.client.inheritance.repositories.cyclic; | ||
|
||
import java.util.Collections; | ||
|
||
import io.crnk.client.inheritance.resources.cyclic.CyclicResourceC; | ||
import io.crnk.core.queryspec.QuerySpec; | ||
import io.crnk.core.repository.ResourceRepositoryBase; | ||
import io.crnk.core.resource.list.ResourceList; | ||
|
||
/* | ||
* @author syri. | ||
*/ | ||
public class CyclicResourceCRepository extends ResourceRepositoryBase<CyclicResourceC, Long> { | ||
|
||
public CyclicResourceCRepository() { | ||
super(CyclicResourceC.class); | ||
} | ||
|
||
@Override | ||
public ResourceList<CyclicResourceC> findAll(QuerySpec querySpec) { | ||
return querySpec.apply(Collections.emptyList()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...test/java/io/crnk/client/inheritance/repositories/related/RelatedResourceARepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.crnk.client.inheritance.repositories.related; | ||
|
||
import io.crnk.client.inheritance.repositories.RepositoryData; | ||
import io.crnk.client.inheritance.resources.related.RelatedResourceA; | ||
import io.crnk.core.queryspec.QuerySpec; | ||
import io.crnk.core.repository.ResourceRepositoryBase; | ||
import io.crnk.core.resource.list.ResourceList; | ||
|
||
/* | ||
* @author syri. | ||
*/ | ||
public class RelatedResourceARepository extends ResourceRepositoryBase<RelatedResourceA, Long> { | ||
|
||
public RelatedResourceARepository() { | ||
super(RelatedResourceA.class); | ||
} | ||
|
||
@Override | ||
public ResourceList<RelatedResourceA> findAll(QuerySpec querySpec) { | ||
return querySpec.apply(RepositoryData.RESOURCE_A_LIST); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...test/java/io/crnk/client/inheritance/repositories/related/RelatedResourceBRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.crnk.client.inheritance.repositories.related; | ||
|
||
import io.crnk.client.inheritance.repositories.RepositoryData; | ||
import io.crnk.client.inheritance.resources.related.RelatedResourceB; | ||
import io.crnk.core.queryspec.QuerySpec; | ||
import io.crnk.core.repository.ResourceRepositoryBase; | ||
import io.crnk.core.resource.list.ResourceList; | ||
|
||
/* | ||
* @author syri. | ||
*/ | ||
public class RelatedResourceBRepository extends ResourceRepositoryBase<RelatedResourceB, Long> { | ||
|
||
public RelatedResourceBRepository() { | ||
super(RelatedResourceB.class); | ||
} | ||
|
||
@Override | ||
public ResourceList<RelatedResourceB> findAll(QuerySpec querySpec) { | ||
return querySpec.apply(RepositoryData.RESOURCE_B_LIST); | ||
} | ||
} |
Oops, something went wrong.