Skip to content

Commit

Permalink
SHIBUI-1788
Browse files Browse the repository at this point in the history
Updated test configurations to fix autowired dependencies
  • Loading branch information
chasegawa committed Jun 8, 2021
1 parent d650f34 commit 2b4c374
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.persistence.EntityManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import edu.internet2.tier.shibboleth.admin.ui.domain.CustomEntityAttributeDefinition;
Expand All @@ -13,6 +14,7 @@
import edu.internet2.tier.shibboleth.admin.ui.repository.CustomEntityAttributeFilterValueRepository;

@Service
@Primary
public class CustomEntityAttributesDefinitionServiceImpl implements CustomEntityAttributesDefinitionService {
@Autowired
private CustomEntityAttributeDefinitionRepository repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ package edu.internet2.tier.shibboleth.admin.ui.configuration

import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.opensaml.OpenSamlChainingMetadataResolver
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import edu.internet2.tier.shibboleth.admin.ui.repository.CustomEntityAttributeDefinitionRepository
import edu.internet2.tier.shibboleth.admin.ui.repository.CustomEntityAttributeFilterValueRepository
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository
import edu.internet2.tier.shibboleth.admin.ui.security.DefaultAuditorAware
import edu.internet2.tier.shibboleth.admin.ui.service.CustomEntityAttributesDefinitionServiceImpl
import edu.internet2.tier.shibboleth.admin.ui.service.IndexWriterService
import net.shibboleth.ext.spring.resource.ResourceHelper
import net.shibboleth.utilities.java.support.component.ComponentInitializationException

import javax.persistence.EntityManager

import org.apache.lucene.document.Document
import org.apache.lucene.document.Field
import org.apache.lucene.document.StringField
Expand Down Expand Up @@ -35,11 +41,30 @@ class TestConfiguration {
final MetadataResolverRepository metadataResolverRepository
final Logger logger = LoggerFactory.getLogger(TestConfiguration.class);

@Autowired
private CustomEntityAttributeDefinitionRepository repository;

@Autowired
CustomEntityAttributeFilterValueRepository customEntityAttributeFilterValueRepository;

@Autowired
EntityManager entityManager

TestConfiguration(final OpenSamlObjects openSamlObjects, final MetadataResolverRepository metadataResolverRepository) {
this.openSamlObjects =openSamlObjects
this.metadataResolverRepository = metadataResolverRepository
}

@Bean
CustomEntityAttributesDefinitionServiceImpl ceadService() {
new CustomEntityAttributesDefinitionServiceImpl().with {
it.entityManager = entityManager
it.repository = repository
it.customEntityAttributeFilterValueRepository = customEntityAttributeFilterValueRepository
return it
}
}

@Bean
JavaMailSender javaMailSender() {
return new JavaMailSenderImpl().with {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.nio.file.Files
* @author Bill Smith (wsmith@unicon.net)
*/
@DataJpaTest
@ContextConfiguration(classes=[CoreShibUiConfiguration, SearchConfiguration, InternationalizationConfiguration, MyConfig, PlaceholderResolverComponentsConfiguration])
@ContextConfiguration(classes=[CoreShibUiConfiguration, SearchConfiguration, InternationalizationConfiguration, MyConfig, PlaceholderResolverComponentsConfiguration, edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration])
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"])
@EntityScan("edu.internet2.tier.shibboleth.admin.ui")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import edu.internet2.tier.shibboleth.admin.ui.security.repository.RoleRepository
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository
import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService
import edu.internet2.tier.shibboleth.admin.ui.service.CustomEntityAttributesDefinitionServiceImpl
import edu.internet2.tier.shibboleth.admin.ui.service.JPAEntityDescriptorServiceImpl
import edu.internet2.tier.shibboleth.admin.ui.service.JPAEntityServiceImpl
import org.apache.lucene.analysis.Analyzer
Expand All @@ -29,14 +30,20 @@ import javax.persistence.EntityManager
* A highly unnecessary test so that I can check to make sure that persistence is correct for the model
*/
@DataJpaTest
@ContextConfiguration(classes=[CoreShibUiConfiguration, InternationalizationConfiguration, Config])
@ContextConfiguration(classes=[CoreShibUiConfiguration, InternationalizationConfiguration, LocalConfig])
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"])
@EntityScan("edu.internet2.tier.shibboleth.admin.ui")
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
class EntityDescriptorRepositoryTest extends Specification {
@Autowired
EntityDescriptorRepository entityDescriptorRepository

@Autowired
private CustomEntityAttributeDefinitionRepository repository;

@Autowired
CustomEntityAttributeFilterValueRepository customEntityAttributeFilterValueRepository;

@Autowired
EntityManager entityManager

Expand Down Expand Up @@ -86,7 +93,7 @@ class EntityDescriptorRepositoryTest extends Specification {
}

@TestConfiguration
static class Config {
static class LocalConfig {
@Bean
MetadataResolver metadataResolver() {
new OpenSamlChainingMetadataResolver().with {
Expand All @@ -100,5 +107,15 @@ class EntityDescriptorRepositoryTest extends Specification {
Analyzer analyzer() {
return new EnglishAnalyzer()
}

@Bean
CustomEntityAttributesDefinitionServiceImpl ceadService() {
new CustomEntityAttributesDefinitionServiceImpl().with {
it.entityManager = entityManager
it.repository = repository
it.customEntityAttributeFilterValueRepository = customEntityAttributeFilterValueRepository
return it
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import spock.lang.Specification
import static edu.internet2.tier.shibboleth.admin.ui.util.TestHelpers.*

@DataJpaTest
@ContextConfiguration(classes = [CoreShibUiConfiguration, SearchConfiguration, InternationalizationConfiguration, TestConfig])
@ContextConfiguration(classes = [CoreShibUiConfiguration, SearchConfiguration, InternationalizationConfiguration, edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration ,LocalConfig])
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"])
@EntityScan("edu.internet2.tier.shibboleth.admin.ui")
class IncommonJPAMetadataResolverServiceImplTests extends Specification {
Expand Down Expand Up @@ -106,7 +106,7 @@ class IncommonJPAMetadataResolverServiceImplTests extends Specification {

//TODO: check that this configuration is sufficient
@TestConfiguration
static class TestConfig {
static class LocalConfig {
@Autowired
OpenSamlObjects openSamlObjects

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import spock.lang.Unroll
import static edu.internet2.tier.shibboleth.admin.ui.util.TestHelpers.generatedXmlIsTheSameAsExpectedXml

@DataJpaTest
@ContextConfiguration(classes=[CoreShibUiConfiguration, MetadataResolverConverterConfiguration, SearchConfiguration, InternationalizationConfiguration, PlaceholderResolverComponentsConfiguration, Config])
@ContextConfiguration(classes=[CoreShibUiConfiguration, MetadataResolverConverterConfiguration, SearchConfiguration, InternationalizationConfiguration, PlaceholderResolverComponentsConfiguration, edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration ,Config])
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"])
@EntityScan("edu.internet2.tier.shibboleth.admin.ui")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
Expand Down

0 comments on commit 2b4c374

Please sign in to comment.