Search in sources :

Example 11 with TransactionService

use of org.alfresco.service.transaction.TransactionService in project alfresco-remote-api by Alfresco.

the class AbstractContextTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    Map<String, Object> entityResourceBeans = applicationContext.getBeansWithAnnotation(EntityResource.class);
    Map<String, Object> relationResourceBeans = applicationContext.getBeansWithAnnotation(RelationshipResource.class);
    locator.setDictionary(ResourceDictionaryBuilder.build(entityResourceBeans.values(), relationResourceBeans.values()));
    AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
    AbstractResourceWebScript postExecutor = (AbstractResourceWebScript) applicationContext.getBean("executorOfPost");
    AbstractResourceWebScript putExecutor = (AbstractResourceWebScript) applicationContext.getBean("executorOfPut");
    AbstractResourceWebScript deleteExecutor = (AbstractResourceWebScript) applicationContext.getBean("executorOfDelete");
    // Mock transaction service
    TransactionService transerv = mock(TransactionService.class);
    RetryingTransactionHelper tHelper = mock(RetryingTransactionHelper.class);
    when(transerv.getRetryingTransactionHelper()).thenReturn(tHelper);
    when(tHelper.doInTransaction(any(RetryingTransactionHelper.RetryingTransactionCallback.class), anyBoolean(), anyBoolean())).thenAnswer(new Answer<Object>() {

        @SuppressWarnings("rawtypes")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            RetryingTransactionHelper.RetryingTransactionCallback cb = (RetryingTransactionHelper.RetryingTransactionCallback) args[0];
            return cb.execute();
        }
    });
    executor.setTransactionService(transerv);
    postExecutor.setTransactionService(transerv);
    putExecutor.setTransactionService(transerv);
    deleteExecutor.setTransactionService(transerv);
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 12 with TransactionService

use of org.alfresco.service.transaction.TransactionService in project alfresco-remote-api by Alfresco.

the class TestEnterpriseAtomPubTCK method setup.

@Before
public void setup() throws Exception {
    JettyComponent jetty = getTestFixture().getJettyComponent();
    final SearchService searchService = (SearchService) jetty.getApplicationContext().getBean("searchService");
    ;
    final NodeService nodeService = (NodeService) jetty.getApplicationContext().getBean("nodeService");
    final FileFolderService fileFolderService = (FileFolderService) jetty.getApplicationContext().getBean("fileFolderService");
    final NamespaceService namespaceService = (NamespaceService) jetty.getApplicationContext().getBean("namespaceService");
    final TransactionService transactionService = (TransactionService) jetty.getApplicationContext().getBean("transactionService");
    final String name = "abc" + System.currentTimeMillis();
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
            Repository repositoryHelper = (Repository) jetty.getApplicationContext().getBean("repositoryHelper");
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            fileFolderService.create(companyHome, name, ContentModel.TYPE_FOLDER).getNodeRef();
            return null;
        }
    }, false, true);
    int port = jetty.getPort();
    Map<String, String> cmisParameters = new HashMap<String, String>();
    cmisParameters.put(TestParameters.DEFAULT_RELATIONSHIP_TYPE, "R:cm:replaces");
    cmisParameters.put(TestParameters.DEFAULT_TEST_FOLDER_PARENT, "/" + name);
    clientContext = new OpenCMISClientContext(BindingType.ATOMPUB, MessageFormat.format(CMIS_URL, "localhost", String.valueOf(port), "alfresco"), "admin", "admin", cmisParameters, jetty.getApplicationContext());
    overrideVersionableAspectProperties(jetty.getApplicationContext());
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) HashMap(java.util.HashMap) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) JettyComponent(org.alfresco.repo.web.util.JettyComponent) OpenCMISClientContext(org.alfresco.opencmis.OpenCMISClientContext) Before(org.junit.Before)

Aggregations

TransactionService (org.alfresco.service.transaction.TransactionService)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 NodeService (org.alfresco.service.cmr.repository.NodeService)6 SearchService (org.alfresco.service.cmr.search.SearchService)6 NamespaceService (org.alfresco.service.namespace.NamespaceService)5 Before (org.junit.Before)5 ServiceRegistry (org.alfresco.service.ServiceRegistry)4 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)4 HashMap (java.util.HashMap)3 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)3 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 QName (org.alfresco.service.namespace.QName)3 InputStream (java.io.InputStream)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UserTransaction (javax.transaction.UserTransaction)2 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 LockService (org.alfresco.service.cmr.lock.LockService)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2