-
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.
test updates
- Loading branch information
Showing
9 changed files
with
325 additions
and
241 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
82 changes: 82 additions & 0 deletions
82
backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/BaseDataJpaTestSetup.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,82 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui | ||
|
||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.model.Role | ||
import edu.internet2.tier.shibboleth.admin.ui.security.model.User | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.OwnershipRepository | ||
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.GroupServiceForTesting | ||
import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService | ||
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.annotation.Transactional | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
@DataJpaTest | ||
@ContextConfiguration(classes = [BaseDataJpaTestSetupConfiguration]) | ||
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"]) | ||
@EntityScan("edu.internet2.tier.shibboleth.admin.ui") | ||
abstract class BaseDataJpaTestSetup extends Specification { | ||
static boolean setupRun = false | ||
|
||
@Autowired | ||
GroupServiceForTesting groupService | ||
|
||
@Autowired | ||
OwnershipRepository ownershipRepository | ||
|
||
@Autowired | ||
RoleRepository roleRepository | ||
|
||
@Autowired | ||
UserRepository userRepository | ||
|
||
@Autowired | ||
UserService userService | ||
|
||
def setup() { | ||
runOnce() | ||
} | ||
|
||
// One time setup to ensure roles are in a known good state and that we have an admin user and group | ||
@Transactional | ||
runOnce() { | ||
if (setupRun) return | ||
|
||
groupService.clearAllForTesting() | ||
userRepository.deleteAll() | ||
ownershipRepository.deleteAll() | ||
roleRepository.deleteAll() | ||
|
||
def roles = [new Role().with { | ||
name = 'ROLE_ADMIN' | ||
it | ||
}, new Role().with { | ||
name = 'ROLE_USER' | ||
it | ||
}, new Role().with { | ||
name = 'ROLE_ENABLE' | ||
it | ||
}, new Role().with { | ||
name = 'ROLE_NONE' | ||
it | ||
}] | ||
roles.each { | ||
if (roleRepository.findByName(it.name).isEmpty()) { | ||
roleRepository.save(it) | ||
} | ||
} | ||
|
||
if (userRepository.findByUsername("admin").isEmpty()) { | ||
Optional<Role> adminRole = roleRepository.findByName("ROLE_ADMIN") | ||
User adminUser = new User(username: "admin", roles: [adminRole.get()], password: "foo") | ||
userService.save(adminUser) | ||
} | ||
setupRun = true | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...st/groovy/edu/internet2/tier/shibboleth/admin/ui/BaseDataJpaTestSetupConfiguration.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,51 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.configuration.ShibUIConfiguration | ||
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects | ||
import edu.internet2.tier.shibboleth.admin.ui.security.model.listener.GroupUpdatedEntityListener | ||
import edu.internet2.tier.shibboleth.admin.ui.security.model.listener.UserUpdatedEntityListener | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.GroupsRepository | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.OwnershipRepository | ||
import edu.internet2.tier.shibboleth.admin.ui.security.service.GroupServiceForTesting | ||
import edu.internet2.tier.shibboleth.admin.ui.security.service.GroupServiceImpl | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Import | ||
import org.springframework.context.annotation.Primary | ||
|
||
@Configuration | ||
@Import(ShibUIConfiguration.class) | ||
@ComponentScan(basePackages=[ "edu.internet2.tier.shibboleth.admin.ui.service", "edu.internet2.tier.shibboleth.admin.ui.security.service" ]) | ||
class BaseDataJpaTestSetupConfiguration { | ||
@Bean | ||
@Primary | ||
GroupServiceForTesting groupServiceForTesting(GroupsRepository groupRepo, OwnershipRepository ownershipRepository) { | ||
GroupServiceForTesting result = new GroupServiceForTesting(new GroupServiceImpl().with { | ||
it.groupRepository = groupRepo | ||
it.ownershipRepository = ownershipRepository | ||
return it | ||
}) | ||
result.ensureAdminGroupExists() | ||
return result | ||
} | ||
|
||
@Bean | ||
GroupUpdatedEntityListener groupUpdatedEntityListener(OwnershipRepository ownershipRepository) { | ||
GroupUpdatedEntityListener listener = new GroupUpdatedEntityListener() | ||
listener.init(ownershipRepository) | ||
return listener | ||
} | ||
|
||
@Bean | ||
OpenSamlObjects openSamlObjects() { | ||
return new OpenSamlObjects() | ||
} | ||
|
||
@Bean | ||
UserUpdatedEntityListener userUpdatedEntityListener(OwnershipRepository ownershipRepository, GroupsRepository groupRepo) { | ||
UserUpdatedEntityListener listener = new UserUpdatedEntityListener() | ||
listener.init(ownershipRepository, groupRepo) | ||
return listener | ||
} | ||
} |
Oops, something went wrong.