当前位置: 首页>>代码示例>>Java>>正文


Java SpringUtils.setSharedApplicationContext方法代码示例

本文整理汇总了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);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:26,代码来源:GroupBatchLdapResourceTest.java

示例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);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:27,代码来源:UserBatchLdapResourceTest.java

示例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);
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:12,代码来源:AbstractDataGeneratorTest.java

示例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);
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:54,代码来源:LdapCacheRepositoryTest.java

示例5: unmockApplicationContext

import org.ligoj.bootstrap.core.SpringUtils; //导入方法依赖的package包/类
@After
public void unmockApplicationContext() {
	SpringUtils.setSharedApplicationContext(super.applicationContext);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:5,代码来源:GroupBatchLdapResourceTest.java


注:本文中的org.ligoj.bootstrap.core.SpringUtils.setSharedApplicationContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。