-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 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
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
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
89 changes: 89 additions & 0 deletions
89
...boleth/admin/ui/repository/envers/MetadataResolverEntityBasicEnversVersioningTests.groovy
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,89 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.repository.envers | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.configuration.CoreShibUiConfiguration | ||
| import edu.internet2.tier.shibboleth.admin.ui.configuration.InternationalizationConfiguration | ||
| import edu.internet2.tier.shibboleth.admin.ui.configuration.SearchConfiguration | ||
| import edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration | ||
| import edu.internet2.tier.shibboleth.admin.ui.domain.filters.EntityAttributesFilter | ||
| import edu.internet2.tier.shibboleth.admin.ui.domain.filters.EntityAttributesFilterTarget | ||
| import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolver | ||
| import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository | ||
| import org.hibernate.envers.AuditReaderFactory | ||
| import org.hibernate.envers.query.AuditQuery | ||
| import org.springframework.beans.factory.annotation.Autowired | ||
| import org.springframework.boot.autoconfigure.domain.EntityScan | ||
| import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest | ||
| import org.springframework.data.jpa.repository.config.EnableJpaRepositories | ||
| import org.springframework.test.context.ContextConfiguration | ||
| import org.springframework.transaction.PlatformTransactionManager | ||
| import org.springframework.transaction.support.DefaultTransactionDefinition | ||
| import spock.lang.Specification | ||
|
|
||
| import javax.persistence.EntityManager | ||
|
|
||
| import static org.springframework.transaction.TransactionDefinition.PROPAGATION_REQUIRES_NEW | ||
|
|
||
| /** | ||
| * Testing metadata resolvers basic versioning by envers is functioning. | ||
| */ | ||
| @DataJpaTest | ||
| @ContextConfiguration(classes = [CoreShibUiConfiguration, InternationalizationConfiguration, TestConfiguration, SearchConfiguration]) | ||
| @EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"]) | ||
| @EntityScan("edu.internet2.tier.shibboleth.admin.ui") | ||
| class MetadataResolverEntityBasicEnversVersioningTests extends Specification { | ||
|
|
||
| @Autowired | ||
| MetadataResolverRepository metadataResolverRepository | ||
|
|
||
| @Autowired | ||
| EntityManager entityManager | ||
|
|
||
| @Autowired | ||
| PlatformTransactionManager txMgr | ||
|
|
||
| def "test basic audit and version data is created when persisting base metadata resolver with envers enabled"() { | ||
| when: | ||
| doInExplicitTransaction { | ||
| metadataResolverRepository.save(create {new MetadataResolver()}) | ||
| } | ||
| def metadataResolverHistory = metadataResolverHistory() | ||
|
|
||
| then: | ||
| metadataResolverHistory | ||
| } | ||
|
|
||
| private metadataResolverHistory() { | ||
| def auditReader = AuditReaderFactory.get(entityManager) | ||
| AuditQuery auditQuery = auditReader | ||
| .createQuery() | ||
| .forRevisionsOfEntity(MetadataResolver, false, true) | ||
| auditQuery.resultList | ||
|
|
||
| } | ||
|
|
||
| private static create(Closure concreteResolverSupplier) { | ||
| MetadataResolver resolver = concreteResolverSupplier() | ||
| resolver.with { | ||
| it.name = "testme" | ||
| it.metadataFilters.add(new EntityAttributesFilter().with { | ||
| it.entityAttributesFilterTarget = new EntityAttributesFilterTarget().with { | ||
| it.entityAttributesFilterTargetType = EntityAttributesFilterTarget.EntityAttributesFilterTargetType.ENTITY | ||
| it.value = ["hola"] | ||
| return it | ||
| } | ||
| return it | ||
| }) | ||
| } | ||
| resolver | ||
| } | ||
|
|
||
| //This explicit low level transaction dance is required in order to verify history/version data that envers | ||
| //writes out only after the explicit transaction is committed, therefore making it impossible to verify within the main tx | ||
| //boundary of the test method which commits tx only after an execution of the test method. This let's us explicitly | ||
| //start/commit transaction making envers data written out and verifiable | ||
| private doInExplicitTransaction(Closure uow) { | ||
| def txStatus = txMgr.getTransaction(new DefaultTransactionDefinition(PROPAGATION_REQUIRES_NEW)) | ||
| uow() | ||
| txMgr.commit(txStatus) | ||
| } | ||
| } |