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

JNG-5883 Add testCases for new Query Customizer functions #320

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
*/

import com.google.inject.Inject;
import hu.blackbelt.judo.dao.api.DAO;
import hu.blackbelt.judo.dispatcher.api.FileType;
import hu.blackbelt.judo.meta.asm.runtime.AsmUtils;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.primitives.primitives.myentitywithoptionalfields.*;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.primitives.primitives.myenum.MyEnum;
import hu.blackbelt.judo.psm.generator.sdk.core.test.guice.PrimitivesDaoModules;
import hu.blackbelt.judo.requirement.report.annotation.Requirement;
import hu.blackbelt.judo.runtime.core.jsl.fixture.JudoRuntimeExtension;
import hu.blackbelt.judo.runtime.core.jsl.fixture.JudoRuntimeFixture;
import hu.blackbelt.judo.sdk.query.StringFilter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -36,8 +39,11 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

@Slf4j
public class QueryCustomizerFunctionsTest {
Expand Down Expand Up @@ -421,11 +427,185 @@ public void testMask() {

assertEquals(entity1.identifier().getIdentifier(), maskedResult.identifier().getIdentifier());
assertEquals(entity1.getIntegerAttr(), maskedResult.getIntegerAttr());
assertEquals(null, maskedResult.getScaledAttr());
assertNull(maskedResult.getScaledAttr());
assertEquals(entity1.getStringAttr(), maskedResult.getStringAttr());
assertEquals(null, maskedResult.getRegexAttr());
assertNull(maskedResult.getRegexAttr());
}

@Test
public void testQueryCustomizerClearMask() {
MyEntityWithOptionalFieldsQueryCustomizer queryCustomizer = myEntityWithOptionalFieldsDao
.query()
.maskedBy(MyEntityWithOptionalFieldsMask.myEntityWithOptionalFieldsMask()
.withStringAttr()
.withIntegerAttr())
.filterByStringAttr(StringFilter.equalTo("test"));

MyEntityWithOptionalFields maskedResult = queryCustomizer
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), maskedResult.identifier().getIdentifier());
assertEquals(entity1.getIntegerAttr(), maskedResult.getIntegerAttr());
assertNull(maskedResult.getScaledAttr());
assertEquals(entity1.getStringAttr(), maskedResult.getStringAttr());
assertNull(maskedResult.getRegexAttr());

MyEntityWithOptionalFields nonMaskedResult = queryCustomizer
.clearMask()
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), nonMaskedResult.identifier().getIdentifier());
assertEquals(entity1.getIntegerAttr(), nonMaskedResult.getIntegerAttr());
assertEquals(entity1.getScaledAttr(), nonMaskedResult.getScaledAttr());
assertEquals(entity1.getStringAttr(), nonMaskedResult.getStringAttr());
assertEquals(entity1.getRegexAttr(), nonMaskedResult.getRegexAttr());
}

@Test
public void testQueryCustomizerClearFilter() {
MyEntityWithOptionalFieldsQueryCustomizer queryCustomizer = myEntityWithOptionalFieldsDao
.query()
.filterByStringAttr(StringFilter.equalTo("test"));

List<MyEntityWithOptionalFields> filteredResult = queryCustomizer
.selectList();

assertEquals(1, filteredResult.size());
assertEquals(entity1.identifier().getIdentifier(), filteredResult.get(0).identifier().getIdentifier());
assertEquals(entity1.getIntegerAttr(), filteredResult.get(0).getIntegerAttr());
assertEquals(entity1.getStringAttr(), filteredResult.get(0).getStringAttr());


List<MyEntityWithOptionalFields> nonFilteredResult = queryCustomizer
.clearFilter()
.selectList();

assertEquals(2, nonFilteredResult.size());

}

@Test
public void testQueryCustomizerClearOrderBy() {
MyEntityWithOptionalFieldsQueryCustomizer queryCustomizer = myEntityWithOptionalFieldsDao
.query()
.orderBy(MyEntityWithOptionalFieldsAttribute.STRING_ATTR);

MyEntityWithOptionalFields orderByResult = queryCustomizer
.selectOne()
.orElseThrow();

assertEquals(entity2.identifier().getIdentifier(), orderByResult.identifier().getIdentifier());

orderByResult = queryCustomizer
.orderBy(MyEntityWithOptionalFieldsAttribute.DERIVED_SCALED_ATTR)
.selectOne()
.orElseThrow();

assertEquals(entity2.identifier().getIdentifier(), orderByResult.identifier().getIdentifier());

orderByResult = queryCustomizer
.clearOrder()
.orderByDescending(MyEntityWithOptionalFieldsAttribute.STRING_ATTR)
.orderByDescending(MyEntityWithOptionalFieldsAttribute.DERIVED_SCALED_ATTR)
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), orderByResult.identifier().getIdentifier());

}

@Test
public void testQueryCustomizerCopy() {
MyEntityWithOptionalFieldsQueryCustomizer queryCustomizer = myEntityWithOptionalFieldsDao
.query()
.orderBy(MyEntityWithOptionalFieldsAttribute.STRING_ATTR)
.filterByStringAttr(StringFilter.equalTo("test"))
.maskedBy(MyEntityWithOptionalFieldsMask.myEntityWithOptionalFieldsMask()
.withStringAttr())
;

MyEntityWithOptionalFields orderByResult = queryCustomizer
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), orderByResult.identifier().getIdentifier());
assertEquals(entity1.getStringAttr(), orderByResult.getStringAttr());
assertNull(orderByResult.getScaledAttr());

orderByResult = queryCustomizer
.copy()
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), orderByResult.identifier().getIdentifier());
assertEquals(entity1.getStringAttr(), orderByResult.getStringAttr());
assertNull(orderByResult.getScaledAttr());

queryCustomizer.copy().clearOrder().clearMask().clearFilter();

orderByResult = queryCustomizer
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), orderByResult.identifier().getIdentifier());
assertEquals(entity1.getStringAttr(), orderByResult.getStringAttr());
assertNull(orderByResult.getScaledAttr());

}

@Test
public void testQueryCustomizerAppend(JudoRuntimeFixture runtimeFixture) {
AsmUtils asmUtils = new AsmUtils(runtimeFixture.modelHolder.getAsmModel().getResourceSet());

DAO.QueryCustomizer<java.util.UUID> queryCustomizer = DAO.QueryCustomizer.<java.util.UUID>builder()
.orderBy(DAO.OrderBy.builder().descending(false).attribute(asmUtils.resolveAttribute("Primitives.Primitives.MyEntityWithOptionalFields#stringAttr").orElseThrow()).build())
.filter("this.stringAttr!like('tes%') and this.stringAttr!like('%t')")
.mask(Map.of("stringAttr", true))
.build();

MyEntityWithOptionalFields result = myEntityWithOptionalFieldsDao
.query()
.appendBy(queryCustomizer)
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), result.identifier().getIdentifier());
assertEquals(entity1.getStringAttr(), result.getStringAttr());
assertNull(result.getScaledAttr());

queryCustomizer = DAO.QueryCustomizer.<java.util.UUID>builder()
.orderBy(DAO.OrderBy.builder().descending(false).attribute(asmUtils.resolveAttribute("Primitives.Primitives.MyEntityWithOptionalFields#stringAttr").orElseThrow()).build())
.filter("this.stringAttr!like('tes%') and this.stringAttr!like('%t')")
.build();

result = myEntityWithOptionalFieldsDao
.query()
.appendBy(queryCustomizer)
.selectOne()
.orElseThrow();

assertEquals(entity1.identifier().getIdentifier(), result.identifier().getIdentifier());
assertEquals(entity1.getStringAttr(), result.getStringAttr());
assertNotNull(result.getScaledAttr());

queryCustomizer = DAO.QueryCustomizer.<java.util.UUID>builder()
.orderBy(DAO.OrderBy.builder().descending(false).attribute(asmUtils.resolveAttribute("Primitives.Primitives.MyEntityWithOptionalFields#stringAttr").orElseThrow()).build())
.build();

result = myEntityWithOptionalFieldsDao
.query()
.appendBy(queryCustomizer)
.selectOne()
.orElseThrow();

assertEquals(entity2.identifier().getIdentifier(), result.identifier().getIdentifier());
assertEquals(entity2.getStringAttr(), result.getStringAttr());
assertNotNull(result.getScaledAttr());

}

private void assertOrderBy(MyEntityWithOptionalFieldsAttribute attribute, MyEntityWithOptionalFields firstEntity) {
MyEntityWithOptionalFields orderBy = myEntityWithOptionalFieldsDao
.query()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<judo-tatami-jsl-version>1.1.4.20240808_113814_898e9db7_develop</judo-tatami-jsl-version>
<judo-runtime-core-version>1.0.6.20240807_160904_472d7c55_develop</judo-runtime-core-version>
<judo-psm-generator-sdk-core-version>1.0.0.20240809_162212_865aea2f_develop</judo-psm-generator-sdk-core-version>
<judo-psm-generator-sdk-core-version>1.0.0.20240813_092457_7179908f_feature_JNG_5883_QueryCustomizer_should_have_append_clearFilter_clearOrder_function</judo-psm-generator-sdk-core-version>

<judo-meta-psm-version>1.3.0.20240713_040609_6f9ce2de_develop</judo-meta-psm-version>

Expand Down
Loading