本文整理汇总了Java中org.ligoj.bootstrap.core.SpringUtils.setSharedApplicationContext方法的典型用法代码示例。如果您正苦于以下问题:Java SpringUtils.setSharedApplicationContext方法的具体用法?Java SpringUtils.setSharedApplicationContext怎么用?Java SpringUtils.setSharedApplicationContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ligoj.bootstrap.core.SpringUtils
的用法示例。
在下文中一共展示了SpringUtils.setSharedApplicationContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mockApplicationContext
import org.ligoj.bootstrap.core.SpringUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void mockApplicationContext() {
final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
SpringUtils.setSharedApplicationContext(applicationContext);
mockLdapResource = Mockito.mock(GroupResource.class);
final GroupFullLdapTask mockTask = new GroupFullLdapTask();
mockTask.resource = mockLdapResource;
mockTask.securityHelper = securityHelper;
mockTask.containerScopeResource = Mockito.mock(ContainerScopeResource.class);
Mockito.when(applicationContext.getBean(SessionSettings.class)).thenReturn(new SessionSettings());
Mockito.when(applicationContext.getBean((Class<?>) ArgumentMatchers.any(Class.class))).thenAnswer((Answer<Object>) invocation -> {
final Class<?> requiredType = (Class<Object>) invocation.getArguments()[0];
if (requiredType == GroupFullLdapTask.class) {
return mockTask;
}
return GroupBatchLdapResourceTest.super.applicationContext.getBean(requiredType);
});
final ContainerScope container = new ContainerScope();
container.setId(1);
container.setName("Fonction");
container.setType(ContainerType.GROUP);
Mockito.when(mockTask.containerScopeResource.findByName("Fonction")).thenReturn(container);
}
示例2: mockApplicationContext
import org.ligoj.bootstrap.core.SpringUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void mockApplicationContext() {
final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
SpringUtils.setSharedApplicationContext(applicationContext);
mockLdapResource = Mockito.mock(UserOrgResource.class);
final UserFullLdapTask mockTask = new UserFullLdapTask();
mockTask.resource = mockLdapResource;
mockTask.securityHelper = securityHelper;
final UserAtomicLdapTask mockTaskUpdate = new UserAtomicLdapTask();
mockTaskUpdate.resource = mockLdapResource;
mockTaskUpdate.securityHelper = securityHelper;
Mockito.when(applicationContext.getBean(SessionSettings.class)).thenReturn(new SessionSettings());
Mockito.when(applicationContext.getBean((Class<?>) ArgumentMatchers.any(Class.class))).thenAnswer((Answer<Object>) invocation -> {
final Class<?> requiredType = (Class<Object>) invocation.getArguments()[0];
if (requiredType == UserFullLdapTask.class) {
return mockTask;
}
if (requiredType == UserAtomicLdapTask.class) {
return mockTaskUpdate;
}
return UserBatchLdapResourceTest.super.applicationContext.getBean(requiredType);
});
mockTaskUpdate.jaxrsFactory = ServerProviderFactory.createInstance(null);
}
示例3: restoreApplicationContext
import org.ligoj.bootstrap.core.SpringUtils; //导入方法依赖的package包/类
/**
* Restore original Spring application context
*/
@After
@Before
public void restoreApplicationContext() {
if (applicationContext != null) {
// This test was running in a Spring context, restore the shared context
SpringUtils.setSharedApplicationContext(applicationContext);
}
}
示例4: init
import org.ligoj.bootstrap.core.SpringUtils; //导入方法依赖的package包/类
@Before
public void init() {
companyRepository = Mockito.mock(CompanyLdapRepository.class);
groupRepository = Mockito.mock(GroupLdapRepository.class);
userRepository = Mockito.mock(UserLdapRepository.class);
iamProvider = Mockito.mock(IamProvider.class);
final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
SpringUtils.setSharedApplicationContext(applicationContext);
final IamConfiguration iamConfiguration = new IamConfiguration();
iamConfiguration.setCompanyRepository(companyRepository);
iamConfiguration.setGroupRepository(groupRepository);
iamConfiguration.setUserRepository(userRepository);
Mockito.when(iamProvider.getConfiguration()).thenReturn(iamConfiguration);
companies = new HashMap<>();
companies.put("company", new CompanyOrg("dnc", "Company"));
groups = new HashMap<>();
final Set<String> members = new HashSet<>();
members.add("u");
groupLdap = new GroupOrg("dn", "Group", members);
groups.put("group", groupLdap);
groupLdap2 = new GroupOrg("dn2", "Group2", new HashSet<>());
groups.put("group2", groupLdap2);
user = new UserOrg();
user.setId("u");
user.setFirstName("f");
user.setLastName("l");
user.setCompany("company");
final List<String> userGroups = new ArrayList<>();
userGroups.add("group");
user.setGroups(userGroups);
user.setMails(Collections.singletonList("mail"));
user2 = new UserOrg();
user2.setId("u2");
user2.setFirstName("f");
user2.setLastName("l");
user2.setCompany("company");
user2.setGroups(new ArrayList<>());
users = new HashMap<>();
users.put("u", user);
users.put("u2", user2);
Mockito.when(companyRepository.findAllNoCache()).thenReturn(companies);
Mockito.when(groupRepository.findAllNoCache()).thenReturn(groups);
Mockito.when(userRepository.findAllNoCache(groups)).thenReturn(users);
Mockito.when(companyRepository.findAll()).thenReturn(companies);
Mockito.when(groupRepository.findAll()).thenReturn(groups);
Mockito.when(userRepository.findAll()).thenReturn(users);
CacheManager.getInstance().getCache("ldap").removeAll();
repository = new LdapCacheRepository();
repository.iamProvider = new IamProvider[] { iamProvider };
repository.ldapCacheDao = Mockito.mock(LdapCacheDao.class);
}
示例5: unmockApplicationContext
import org.ligoj.bootstrap.core.SpringUtils; //导入方法依赖的package包/类
@After
public void unmockApplicationContext() {
SpringUtils.setSharedApplicationContext(super.applicationContext);
}