-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`IS TRUE` predicate does not seem to be valid in Hiberate 6. RHINENG-1631
- Loading branch information
Showing
2 changed files
with
66 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
src/test/java/com/redhat/cloud/policies/engine/db/repositories/PoliciesRepositoryTest.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,65 @@ | ||
package com.redhat.cloud.policies.engine.db.repositories; | ||
|
||
import com.redhat.cloud.policies.engine.TestLifecycleManager; | ||
import com.redhat.cloud.policies.engine.db.StatelessSessionFactory; | ||
import com.redhat.cloud.policies.engine.db.entities.Policy; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectSpy; | ||
|
||
import org.hibernate.Session; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(TestLifecycleManager.class) | ||
class PoliciesRepositoryTest { | ||
|
||
@InjectSpy | ||
StatelessSessionFactory statelessSessionFactory; | ||
|
||
@Inject | ||
Session session; | ||
|
||
@Inject | ||
PoliciesRepository repository; | ||
|
||
@Test | ||
public void testGetEnabledPolicies() { | ||
String orgId = UUID.randomUUID().toString(); | ||
|
||
Policy policyFixture = createEnabledPolicy(orgId); | ||
|
||
statelessSessionFactory.withSession(session -> { | ||
List<Policy> enabledPolicies = repository.getEnabledPolicies(orgId); | ||
assertEquals(1, enabledPolicies.size()); | ||
assertEquals(orgId, enabledPolicies.get(0).orgId); | ||
assertEquals(policyFixture.id, enabledPolicies.get(0).id); | ||
}); | ||
} | ||
|
||
@Transactional | ||
Policy createEnabledPolicy(String orgId) { | ||
Policy policy = new Policy(); | ||
policy.id = UUID.randomUUID(); | ||
policy.accountId = "123"; | ||
policy.orgId = orgId; | ||
policy.name = "Test"; | ||
policy.description = "desc"; | ||
policy.condition = "true"; | ||
policy.enabled = true; | ||
policy.actions = "none"; | ||
session.persist(policy); | ||
|
||
return policy; | ||
} | ||
} |