-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from croz-ltd/feature_upgradeSpringBootToLate…
…stVersion Feature upgrade spring boot to latest version
- Loading branch information
Showing
7 changed files
with
122 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ gradleJgitverPluginVersion=0.10.0-rc03 | |
gradlePublishPluginVersion=1.1.0 | ||
modelMapperVersion=3.1.1 | ||
reflectionsVersion=0.10.2 | ||
springBootVersion=3.1.5 | ||
springBootVersion=3.2.5 | ||
|
||
# POM metadata | ||
developerEmail=[email protected] | ||
|
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
31 changes: 31 additions & 0 deletions
31
nrich-search/src/main/java/net/croz/nrich/search/util/AttributeResolvingUtil.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,31 @@ | ||
package net.croz.nrich.search.util; | ||
|
||
import jakarta.persistence.metamodel.Attribute; | ||
import jakarta.persistence.metamodel.ManagedType; | ||
|
||
import org.hibernate.metamodel.model.domain.AbstractManagedType; | ||
|
||
public final class AttributeResolvingUtil { | ||
|
||
private AttributeResolvingUtil() { | ||
} | ||
|
||
public static Attribute<?, ?> resolveAttributeByName(ManagedType<?> managedType, String attributeName) { | ||
if (managedType instanceof AbstractManagedType<?> abstractManagedType) { | ||
Attribute<?, ?> attribute = abstractManagedType.findAttribute(attributeName); | ||
if (attribute == null) { | ||
return abstractManagedType.findSubTypesAttribute(attributeName); | ||
} | ||
|
||
return attribute; | ||
} | ||
else { | ||
try { | ||
return managedType.getAttribute(attributeName); | ||
} | ||
catch (Exception ignored) { | ||
return null; | ||
} | ||
} | ||
} | ||
} |
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
74 changes: 74 additions & 0 deletions
74
nrich-search/src/test/java/net/croz/nrich/search/util/AttributeResolvingUtilTest.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,74 @@ | ||
package net.croz.nrich.search.util; | ||
|
||
import jakarta.persistence.metamodel.Attribute; | ||
import jakarta.persistence.metamodel.ManagedType; | ||
|
||
import org.hibernate.metamodel.model.domain.AbstractManagedType; | ||
import org.hibernate.metamodel.model.domain.PersistentAttribute; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class AttributeResolvingUtilTest { | ||
|
||
private static final String ATTRIBUTE_NAME = "attributeName"; | ||
|
||
private static final Attribute<?, ?> ATTRIBUTE_VALUE = mock(Attribute.class); | ||
|
||
private static final PersistentAttribute<?, ?> PERSISTENT_ATTRIBUTE_VALUE = mock(PersistentAttribute.class); | ||
|
||
@Test | ||
void shouldResolveAttributeFromManagedType() { | ||
// given | ||
ManagedType<?> managedType = mock(ManagedType.class); | ||
doReturn(ATTRIBUTE_VALUE).when(managedType).getAttribute(ATTRIBUTE_NAME); | ||
|
||
// when | ||
Attribute<?, ?> result = AttributeResolvingUtil.resolveAttributeByName(managedType, ATTRIBUTE_NAME); | ||
|
||
// then | ||
assertThat(result).isEqualTo(ATTRIBUTE_VALUE); | ||
} | ||
|
||
@Test | ||
void shouldReturnNullIfAttributeDoesNotExist() { | ||
// given | ||
ManagedType<?> managedType = mock(ManagedType.class); | ||
doThrow(IllegalArgumentException.class).when(managedType).getAttribute(ATTRIBUTE_NAME); | ||
|
||
// when | ||
Attribute<?, ?> result = AttributeResolvingUtil.resolveAttributeByName(managedType, ATTRIBUTE_NAME); | ||
|
||
// then | ||
assertThat(result).isNull(); | ||
} | ||
|
||
@Test | ||
void shouldResolveAttributeFromAbstractManagedType() { | ||
// given | ||
AbstractManagedType<?> managedType = mock(AbstractManagedType.class); | ||
doReturn(PERSISTENT_ATTRIBUTE_VALUE).when(managedType).findAttribute(ATTRIBUTE_NAME); | ||
|
||
// when | ||
Attribute<?, ?> result = AttributeResolvingUtil.resolveAttributeByName(managedType, ATTRIBUTE_NAME); | ||
|
||
// then | ||
assertThat(result).isEqualTo(PERSISTENT_ATTRIBUTE_VALUE); | ||
} | ||
|
||
@Test | ||
void shouldResolveSubclassAttributeFromAbstractManagedType() { | ||
// given | ||
AbstractManagedType<?> managedType = mock(AbstractManagedType.class); | ||
doReturn(PERSISTENT_ATTRIBUTE_VALUE).when(managedType).findSubTypesAttribute(ATTRIBUTE_NAME); | ||
|
||
// when | ||
Attribute<?, ?> result = AttributeResolvingUtil.resolveAttributeByName(managedType, ATTRIBUTE_NAME); | ||
|
||
// then | ||
assertThat(result).isEqualTo(PERSISTENT_ATTRIBUTE_VALUE); | ||
} | ||
} |
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