Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resourceType to QuerySpec.equals (and hashcode) #857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crnk-core/src/main/java/io/crnk/core/queryspec/QuerySpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public <T> void apply(Iterable<T> resources, ResourceList<T> resultList) {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
result = prime * result + ((filters == null) ? 0 : filters.hashCode());
result = prime * result + ((includedFields == null) ? 0 : includedFields.hashCode());
result = prime * result + ((includedRelations == null) ? 0 : includedRelations.hashCode());
Expand All @@ -167,16 +168,17 @@ public boolean equals(Object obj) {
return false;
}
QuerySpec other = (QuerySpec) obj;
return CompareUtils.isEquals(filters, other.filters) // NOSONAR
return CompareUtils.isEquals(resourceType, other.resourceType)
&& CompareUtils.isEquals(filters, other.filters) // NOSONAR
&& CompareUtils.isEquals(includedFields, other.includedFields)
&& CompareUtils.isEquals(includedRelations, other.includedRelations)
&& CompareUtils.isEquals(pagingSpec, other.pagingSpec)
&& CompareUtils.isEquals(typeRelatedSpecs, other.typeRelatedSpecs)
&& CompareUtils.isEquals(classRelatedSpecs, other.classRelatedSpecs)
&& CompareUtils.isEquals(sort, other.sort);
}
&& CompareUtils.isEquals(sort, other.sort);
}

public Long getLimit() {
public Long getLimit() {
OffsetLimitPagingSpec offsetLimitPagingSpec = getPaging(OffsetLimitPagingSpec.class);
return offsetLimitPagingSpec.getLimit();
}
Expand Down Expand Up @@ -278,7 +280,7 @@ public void setNestedSpecs(Collection<QuerySpec> specs) {
for (QuerySpec spec : specs) {
if (spec.getResourceType() != null) {
typeRelatedSpecs.put(spec.getResourceType(), spec);
}
}
if (spec.getResourceClass() != null) {
classRelatedSpecs.put(spec.getResourceClass(), spec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void testFindAllOrderByAsc() {
@Test
public void testFollowNestedObjectWithinResource() {
// follow ProjectData.data
QuerySpec expectedSpec = new QuerySpec(Task.class);
QuerySpec expectedSpec = new QuerySpec(Project.class);
expectedSpec.addSort(new SortSpec(Arrays.asList("data", "data"), Direction.ASC));

ResourceInformation projectInformation = resourceRegistry.getEntry(Project.class).getResourceInformation();
Expand Down Expand Up @@ -731,7 +731,7 @@ public void testIncludeAttributesOnRoot() {
@Test
public void testHyphenIsAllowedInResourceName() {

QuerySpec expectedSpec = new QuerySpec(Task.class);
QuerySpec expectedSpec = new QuerySpec(TaskWithLookup.class);
expectedSpec.addSort(new SortSpec(Arrays.asList("id"), Direction.ASC));

Map<String, Set<String>> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testReadAndUpdateFromEntity() {
Assert.assertEquals(2L, dto.getId().longValue());
Assert.assertEquals("test", dto.getStringValue());
Assert.assertEquals("TEST", dto.getComputedUpperStringValue());
Mockito.verify(dtoMapper, Mockito.times(1)).unmapQuerySpec(Mockito.eq(querySpec));
Mockito.verify(dtoMapper, Mockito.times(1)).unmapQuerySpec(Mockito.refEq(querySpec, "resourceClass", "resourceType"));

// update the mapped dto
dto.setStringValue("newValue");
Expand Down