From 3f1e10170d2d9d2076e51562eca79fa9e5968105 Mon Sep 17 00:00:00 2001 From: Gregory Fernandez Date: Wed, 14 Sep 2022 13:24:01 +0200 Subject: [PATCH] Add resourceType to QuerySpec.equals (and hashcode) --- .../main/java/io/crnk/core/queryspec/QuerySpec.java | 12 +++++++----- ...efaultQuerySpecUrlMapperDeserializerTestBase.java | 4 ++-- .../io/crnk/data/jpa/mapping/DtoMappingTest.java | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crnk-core/src/main/java/io/crnk/core/queryspec/QuerySpec.java b/crnk-core/src/main/java/io/crnk/core/queryspec/QuerySpec.java index 497323962..ff9df762e 100644 --- a/crnk-core/src/main/java/io/crnk/core/queryspec/QuerySpec.java +++ b/crnk-core/src/main/java/io/crnk/core/queryspec/QuerySpec.java @@ -148,6 +148,7 @@ public void apply(Iterable resources, ResourceList 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()); @@ -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(); } @@ -278,7 +280,7 @@ public void setNestedSpecs(Collection specs) { for (QuerySpec spec : specs) { if (spec.getResourceType() != null) { typeRelatedSpecs.put(spec.getResourceType(), spec); - } + } if (spec.getResourceClass() != null) { classRelatedSpecs.put(spec.getResourceClass(), spec); } diff --git a/crnk-core/src/test/java/io/crnk/core/queryspec/mapper/DefaultQuerySpecUrlMapperDeserializerTestBase.java b/crnk-core/src/test/java/io/crnk/core/queryspec/mapper/DefaultQuerySpecUrlMapperDeserializerTestBase.java index b88300578..6d4804fbf 100644 --- a/crnk-core/src/test/java/io/crnk/core/queryspec/mapper/DefaultQuerySpecUrlMapperDeserializerTestBase.java +++ b/crnk-core/src/test/java/io/crnk/core/queryspec/mapper/DefaultQuerySpecUrlMapperDeserializerTestBase.java @@ -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(); @@ -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> params = new HashMap<>(); diff --git a/crnk-data/crnk-data-jpa/src/test/java/io/crnk/data/jpa/mapping/DtoMappingTest.java b/crnk-data/crnk-data-jpa/src/test/java/io/crnk/data/jpa/mapping/DtoMappingTest.java index affc57044..1d9507609 100644 --- a/crnk-data/crnk-data-jpa/src/test/java/io/crnk/data/jpa/mapping/DtoMappingTest.java +++ b/crnk-data/crnk-data-jpa/src/test/java/io/crnk/data/jpa/mapping/DtoMappingTest.java @@ -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");