Skip to content

Commit

Permalink
Add resourceType to QuerySpec.equals (and hashcode)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Fernandez committed Oct 6, 2022
1 parent 4e4dd89 commit 3f1e101
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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

0 comments on commit 3f1e101

Please sign in to comment.