use of org.alfresco.repo.management.subsystems.ChildApplicationContextFactory in project alfresco-remote-api by Alfresco.
the class InviteServiceTest method configureMailExecutorForTestMode.
/**
* This method turns off email-sending within the MailActionExecuter bean.
*/
public static void configureMailExecutorForTestMode(TestWebScriptServer server) {
// This test class depends on a MailActionExecuter bean which sends out emails
// in a live system. We want to prevent these emails from being sent during
// test execution.
// To do that, we need to get at the outboundSMTP-context.xml and change its
// "mail" MailActionExecuter bean to test mode. setTestMode(true) on that object
// will turn off email sending.
// But that bean is defined within a subsystem i.e. a child application context.
// There are a number of ways we could do this, none of them perfect.
//
// 1. Expose the setTestMode(boolean) method in the subsystem API.
// We could have the "mail" bean implement a "TestModeable" interface and
// expose that through the proxy.
// But that would mean that the setTestMode method would be available in the
// live system too, which is not ideal.
// 2. Replace the "mail" bean in outboundSMTP-context.xml with an alternative in a
// different subsystem context file as described in
// http://wiki.alfresco.com/wiki/Alfresco_Subsystems#Debugging_Alfresco_Subsystems
// But to do that, we'd have to reproduce all the spring config for that bean
// and add a testMode property. Again not ideal.
// 3. Hack into the "mail" bean by programmatically going through the known applicationContext
// and bean structure. This is not ideal either, but it has no effect on product code
// and isolates all the hacking into this test class.
//
// Therefore we've decided to do [3].
ChildApplicationContextFactory outboundSmptSubsystem = (ChildApplicationContextFactory) server.getApplicationContext().getBean("OutboundSMTP");
ApplicationContext childAppCtxt = outboundSmptSubsystem.getApplicationContext();
MailActionExecuter mailActionExecutor = (MailActionExecuter) childAppCtxt.getBean("mail");
mailActionExecutor.setTestMode(true);
}
use of org.alfresco.repo.management.subsystems.ChildApplicationContextFactory in project alfresco-remote-api by Alfresco.
the class LinksRestApiTest method setUp.
// General methods
@Override
protected void setUp() throws Exception {
super.setUp();
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
this.policyBehaviourFilter = (BehaviourFilter) getServer().getApplicationContext().getBean("policyBehaviourFilter");
this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("transactionService");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
this.internalNodeService = (NodeService) getServer().getApplicationContext().getBean("nodeService");
this.nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService");
this.activityService = (ActivityService) getServer().getApplicationContext().getBean("activityService");
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) getServer().getApplicationContext().getBean("ActivitiesFeed");
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
this.feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
this.postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
// Authenticate as user
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
// Create test site
// - only create the site if it doesn't already exist
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_LINKS);
if (siteInfo == null) {
this.siteService.createSite("CalendarSitePreset", SITE_SHORT_NAME_LINKS, "LinksSiteTitle", "TestDescription", SiteVisibility.PUBLIC);
}
// Ensure the links container is there
if (!siteService.hasContainer(SITE_SHORT_NAME_LINKS, "links")) {
siteService.createContainer(SITE_SHORT_NAME_LINKS, "links", null, null);
}
// Create users
createUser(USER_ONE, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_LINKS);
createUser(USER_TWO, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_LINKS);
// Do tests as inviter user
this.authenticationComponent.setCurrentUser(USER_ONE);
}
use of org.alfresco.repo.management.subsystems.ChildApplicationContextFactory in project alfresco-remote-api by Alfresco.
the class BlogServiceTest method setUp.
// General methods
@Override
protected void setUp() throws Exception {
super.setUp();
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
this.nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService");
this.activityService = (ActivityService) getServer().getApplicationContext().getBean("activityService");
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) getServer().getApplicationContext().getBean("ActivitiesFeed");
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
this.feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
this.postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
// Authenticate as user
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
// Create test site
// - only create the site if it doesn't already exist
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_BLOG);
if (siteInfo == null) {
this.siteService.createSite("BlogSitePreset", SITE_SHORT_NAME_BLOG, "BlogSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
}
// Create users
createUser(USER_ONE, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_BLOG);
createUser(USER_TWO, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_BLOG);
// Blank our lists used to track things the test creates
posts = new ArrayList<String>(5);
drafts = new ArrayList<String>(5);
// Do tests as inviter user
this.authenticationComponent.setCurrentUser(USER_ONE);
}
use of org.alfresco.repo.management.subsystems.ChildApplicationContextFactory in project alfresco-remote-api by Alfresco.
the class CommentsApiTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
ApplicationContext appContext = getServer().getApplicationContext();
fileFolderService = (FileFolderService) appContext.getBean("fileFolderService");
transactionService = (TransactionService) appContext.getBean("transactionService");
searchService = (SearchService) appContext.getBean("SearchService");
nodeService = (NodeService) appContext.getBean("nodeService");
namespaceService = (NamespaceService) appContext.getBean("namespaceService");
versionService = (VersionService) appContext.getBean("versionService");
personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
permissionService = (PermissionServiceSPI) getServer().getApplicationContext().getBean("permissionService");
permissionModelDAO = (ModelDAO) getServer().getApplicationContext().getBean("permissionsModelDAO");
siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService");
activityService = (ActivityService) getServer().getApplicationContext().getBean("activityService");
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) getServer().getApplicationContext().getBean("ActivitiesFeed");
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
txn = transactionService.getUserTransaction();
txn.begin();
// Get Company Home
rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
List<NodeRef> results = searchService.selectNodes(rootNodeRef, "/app:company_home", null, namespaceService, false);
if (results.size() == 0) {
throw new AlfrescoRuntimeException("Can't find /app:company_home");
}
companyHomeNodeRef = results.get(0);
// Get Shared
results = searchService.selectNodes(rootNodeRef, "/app:company_home/app:shared", null, namespaceService, false);
if (results.size() == 0) {
throw new AlfrescoRuntimeException("Can't find /app:company_home/app:shared");
}
sharedHomeNodeRef = results.get(0);
results = searchService.selectNodes(rootNodeRef, "/app:company_home/cm:Commenty", null, namespaceService, false);
if (results.size() > 0) {
fileFolderService.delete(results.get(0));
}
nodeRef = fileFolderService.create(companyHomeNodeRef, "Commenty", ContentModel.TYPE_CONTENT).getNodeRef();
versionService.ensureVersioningEnabled(nodeRef, null);
nodeService.setProperty(nodeRef, ContentModel.PROP_AUTO_VERSION_PROPS, true);
createUser(USER2);
createUser(USER_TEST);
txn.commit();
AuthenticationUtil.clearCurrentSecurityContext();
// MNT-12082
// Authenticate as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// Create test site
// - only create the site if it doesn't already exist
SiteInfo siteInfo = siteService.getSite(SITE_SHORT_NAME);
if (siteInfo == null) {
siteInfo = siteService.createSite("SomeTestSite", SITE_SHORT_NAME, "SiteTitle", "SiteDescription", SiteVisibility.PUBLIC);
}
NodeRef docLibContainer = siteService.getContainer(SITE_SHORT_NAME, DOCLIB_CONTAINER);
if (docLibContainer == null) {
siteService.createContainer(SITE_SHORT_NAME, DOCLIB_CONTAINER, ContentModel.TYPE_FOLDER, null);
}
txn = transactionService.getUserTransaction();
txn.begin();
// Create users
createUser(USER_ONE, SiteModel.SITE_CONSUMER);
createUser(USER_TWO, SiteModel.SITE_CONTRIBUTOR);
createUser(USER_THREE, SiteModel.SITE_COLLABORATOR);
createUser(USER_FOUR, SiteModel.SITE_COLLABORATOR);
// Create site page
sitePage = nodeService.createNode(siteInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "test"), ContentModel.TYPE_CONTENT).getChildRef();
txn.commit();
}
use of org.alfresco.repo.management.subsystems.ChildApplicationContextFactory in project alfresco-remote-api by Alfresco.
the class ServerStatusWebScript method execute.
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
ChildApplicationContextFactory subsystem = (ChildApplicationContextFactory) applicationContext.getBean("imap");
// note: getting property (rather than getting imapService bean to check isEnabled) does not cause subsystem startup (if stopped)
// hence providing ability for subsystem to be disabled (whilst still supporting ability to check status and/or dynamically start via JMX)
String isEnabled = (String) subsystem.getProperty("imap.server.enabled");
if (new Boolean(isEnabled).booleanValue()) {
res.getWriter().write("enabled");
} else {
res.getWriter().write("disabled");
}
res.getWriter().flush();
res.getWriter().close();
}
Aggregations