Search in sources :

Example 1 with ApplicationContextFactory

use of org.alfresco.repo.management.subsystems.ApplicationContextFactory in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method setUp.

@Override
protected void setUp() throws Exception {
    applicationContext = ApplicationContextHelper.getApplicationContext();
    repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    ApplicationContextFactory fileServers = (ApplicationContextFactory) this.applicationContext.getBean("fileServers");
    cifsHelper = (CifsHelper) fileServers.getApplicationContext().getBean("cifsHelper");
    driver = (ExtendedDiskInterface) this.applicationContext.getBean("contentDiskDriver");
    mlAwareNodeService = (NodeService) this.applicationContext.getBean("mlAwareNodeService");
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    transactionService = (TransactionService) applicationContext.getBean("transactionService");
    contentService = (ContentService) applicationContext.getBean("contentService");
    ruleService = (RuleService) applicationContext.getBean("ruleService");
    actionService = (ActionService) this.applicationContext.getBean("actionService");
    personService = (PersonService) this.applicationContext.getBean("personService");
    authenticationService = (MutableAuthenticationService) this.applicationContext.getBean("authenticationService");
    permissionService = (PermissionService) this.applicationContext.getBean("permissionService");
    ownableService = (OwnableService) this.applicationContext.getBean("ownableService");
    fileFolderService = (FileFolderService) this.applicationContext.getBean("fileFolderService");
    checkOutCheckInService = (CheckOutCheckInService) this.applicationContext.getBean("checkOutCheckInService");
    assertNotNull("content disk driver is null", driver);
    assertNotNull("repositoryHelper is null", repositoryHelper);
    assertNotNull("mlAwareNodeService is null", mlAwareNodeService);
    assertNotNull("nodeService is null", nodeService);
    assertNotNull("transactionService is null", transactionService);
    assertNotNull("contentService is null", contentService);
    assertNotNull("ruleService is null", ruleService);
    assertNotNull("actionService is null", actionService);
    assertNotNull("cifsHelper", cifsHelper);
    assertNotNull("checkOutCheckInService", checkOutCheckInService);
    AuthenticationUtil.setRunAsUserSystem();
    // remove our test root
    RetryingTransactionCallback<Void> removeRootCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef rootNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, TEST_ROOT_PATH);
            if (rootNode != null) {
                logger.debug("Clean up test root node");
                nodeService.deleteNode(rootNode);
            }
            return null;
        }
    };
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    tran.doInTransaction(removeRootCB, false, true);
}
Also used : ApplicationContextFactory(org.alfresco.repo.management.subsystems.ApplicationContextFactory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper)

Example 2 with ApplicationContextFactory

use of org.alfresco.repo.management.subsystems.ApplicationContextFactory in project alfresco-repository by Alfresco.

the class SubsystemsTest method testSubsystems.

/**
 * Test subsystems.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void testSubsystems() throws Exception {
    ApplicationContextFactory subsystem = (ApplicationContextFactory) applicationContext.getBean("testsubsystem");
    ConfigurableApplicationContext childContext = (ConfigurableApplicationContext) subsystem.getApplicationContext();
    assertTrue("Subsystem not started", childContext.isActive());
    TestService testService = (TestService) childContext.getBean("testService");
    // Make sure subsystem defaults work
    assertEquals("Subsystem Default1", testService.getSimpleProp1());
    // Make sure global property overrides work
    assertEquals(true, testService.getSimpleProp2().booleanValue());
    // Make sure extension classpath property overrides work
    assertEquals("Instance Override3", testService.getSimpleProp3());
    // Make sure extension classpath Spring overrides work
    assertEquals("An extra bean I changed", childContext.getBean("anotherBean"));
    // Make sure composite properties and their defaults work
    TestBean[] testBeans = testService.getTestBeans();
    assertNotNull("Composite property not set", testBeans);
    assertEquals(3, testBeans.length);
    assertEquals("inst1", testBeans[0].getId());
    assertEquals(false, testBeans[0].isBoolProperty());
    assertEquals(123456789123456789L, testBeans[0].getLongProperty());
    assertEquals("Global Default", testBeans[0].getAnotherStringProperty());
    assertEquals("inst2", testBeans[1].getId());
    assertEquals(true, testBeans[1].isBoolProperty());
    assertEquals(123456789123456789L, testBeans[1].getLongProperty());
    assertEquals("Global Default", testBeans[1].getAnotherStringProperty());
    assertEquals("inst3", testBeans[2].getId());
    assertEquals(false, testBeans[2].isBoolProperty());
    assertEquals(123456789123456789L, testBeans[2].getLongProperty());
    assertEquals("Global Instance Default", testBeans[2].getAnotherStringProperty());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory) ApplicationContextFactory(org.alfresco.repo.management.subsystems.ApplicationContextFactory) TestService(org.alfresco.repo.management.subsystems.test.TestService) TestBean(org.alfresco.repo.management.subsystems.test.TestBean) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 3 with ApplicationContextFactory

use of org.alfresco.repo.management.subsystems.ApplicationContextFactory in project alfresco-repository by Alfresco.

the class RuleServiceCoverageTest method testMailAction.

/**
 * Test:
 *          rule type:  inbound
 *          condition:  no-condition
 *          action:     mail
 * @throws MessagingException
 * @throws IOException
 */
public void testMailAction() throws MessagingException, IOException {
    this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null);
    Map<String, Serializable> params = new HashMap<String, Serializable>(1);
    params.put(MailActionExecuter.PARAM_TO, "alfresco.test@gmail.com");
    params.put(MailActionExecuter.PARAM_SUBJECT, "Unit test");
    params.put(MailActionExecuter.PARAM_TEXT, "This is a test to check that the mail action is working.");
    Rule rule = createRule(RuleType.INBOUND, MailActionExecuter.NAME, params, NoConditionEvaluator.NAME, null);
    this.ruleService.saveRule(this.nodeRef, rule);
    MailActionExecuter mailService = (MailActionExecuter) ((ApplicationContextFactory) applicationContext.getBean("OutboundSMTP")).getApplicationContext().getBean("mail");
    mailService.setTestMode(true);
    mailService.clearLastTestMessage();
    this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, getContentProperties()).getChildRef();
    // An email should appear in the recipients email
    // System.out.println(NodeStoreInspector.dumpNodeStore(this.nodeService, this.testStoreRef));
    MimeMessage lastMessage = mailService.retrieveLastTestMessage();
    assertNotNull("Message should have been sent", lastMessage);
    System.out.println("Sent email with subject: " + lastMessage.getSubject());
    System.out.println("Sent email with content: " + lastMessage.getContent());
}
Also used : MailActionExecuter(org.alfresco.repo.action.executer.MailActionExecuter) ApplicationContextFactory(org.alfresco.repo.management.subsystems.ApplicationContextFactory) Serializable(java.io.Serializable) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) Rule(org.alfresco.service.cmr.rule.Rule)

Example 4 with ApplicationContextFactory

use of org.alfresco.repo.management.subsystems.ApplicationContextFactory in project alfresco-repository by Alfresco.

the class RuleServiceCoverageTest method testMailNotSentIfRollback.

public void testMailNotSentIfRollback() {
    this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null);
    Map<String, Serializable> params = new HashMap<String, Serializable>(1);
    params.put(MailActionExecuter.PARAM_TO, "alfresco.test@gmail.com");
    params.put(MailActionExecuter.PARAM_SUBJECT, "testMailNotSentIfRollback()");
    params.put(MailActionExecuter.PARAM_TEXT, "This email should NOT have been sent.");
    Rule rule = createRule(RuleType.INBOUND, MailActionExecuter.NAME, params, NoConditionEvaluator.NAME, null);
    this.ruleService.saveRule(this.nodeRef, rule);
    // space at end
    String illegalName = "MyName.txt ";
    MailActionExecuter mailService = (MailActionExecuter) ((ApplicationContextFactory) applicationContext.getBean("OutboundSMTP")).getApplicationContext().getBean("mail");
    mailService.setTestMode(true);
    mailService.clearLastTestMessage();
    try {
        this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, makeNameProperty(illegalName)).getChildRef();
        fail("createNode() should have failed.");
    } catch (IntegrityException e) {
    // Expected exception.
    // An email should NOT appear in the recipients email
    }
    MimeMessage lastMessage = mailService.retrieveLastTestMessage();
    assertNull("Message should NOT have been sent", lastMessage);
}
Also used : MailActionExecuter(org.alfresco.repo.action.executer.MailActionExecuter) ApplicationContextFactory(org.alfresco.repo.management.subsystems.ApplicationContextFactory) Serializable(java.io.Serializable) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) Rule(org.alfresco.service.cmr.rule.Rule)

Aggregations

ApplicationContextFactory (org.alfresco.repo.management.subsystems.ApplicationContextFactory)4 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 MimeMessage (javax.mail.internet.MimeMessage)2 MailActionExecuter (org.alfresco.repo.action.executer.MailActionExecuter)2 Rule (org.alfresco.service.cmr.rule.Rule)2 ChildApplicationContextFactory (org.alfresco.repo.management.subsystems.ChildApplicationContextFactory)1 TestBean (org.alfresco.repo.management.subsystems.test.TestBean)1 TestService (org.alfresco.repo.management.subsystems.test.TestService)1 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 BaseSpringTest (org.alfresco.util.BaseSpringTest)1 Test (org.junit.Test)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1