コード例 #1
0
ファイル: FormsTest.java プロジェクト: negabaro/alfresco
  protected void onSetUpInTransaction() throws Exception {
    System.err.println("onSetUpInTransaction");
    super.onSetUpInTransaction();
    this.nodeService = (NodeService) super.applicationContext.getBean("dbNodeService");
    assertNotNull(this.nodeService);
    final FileFolderService fileFolderService =
        (FileFolderService) super.applicationContext.getBean("fileFolderService");
    assertNotNull(fileFolderService);
    this.formsService = (FormsService) super.applicationContext.getBean("FormsService");
    assertNotNull(this.formsService);
    final MutableAuthenticationService authenticationService =
        (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    authenticationService.clearCurrentSecurityContext();
    final MutableAuthenticationDao authenticationDAO =
        (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");

    // Create a workspace that contains the 'live' nodes
    final StoreRef testStoreRef =
        this.nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());

    // Get a reference to the root node
    final NodeRef rootNodeRef = this.nodeService.getRootNode(testStoreRef);

    // Create an authenticate the user
    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) {
      authenticationService.createAuthentication(
          AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }

    TestWithUserUtils.authenticateUser(
        AuthenticationUtil.getAdminUserName(), "admin", rootNodeRef, authenticationService);

    // set up a faces context
    final MockExternalContext ec =
        new MockExternalContext(
            new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
    final StaticWebApplicationContext ac = new StaticWebApplicationContext();
    ac.setParent(this.applicationContext);
    this.applicationContext = ac;
    ec.getApplicationMap()
        .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext);
    new MockFacesContext(ec);

    final FileInfo folderInfo =
        fileFolderService.create(rootNodeRef, "test_form", WCMAppModel.TYPE_FORMFOLDER);
    final HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
    this.nodeService.addAspect(folderInfo.getNodeRef(), WCMAppModel.ASPECT_FORM, props);
    this.mockForm = new MockForm(folderInfo.getNodeRef(), this.formsService);
  }
コード例 #2
0
  public void setUp() throws Exception {
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) {
      throw new AlfrescoRuntimeException(
          "A previous tests did not clean up transaction: "
              + AlfrescoTransactionSupport.getTransactionId());
    }

    nodeService = (NodeService) applicationContext.getBean("nodeService");
    dictionaryService =
        (DictionaryService)
            applicationContext.getBean(ServiceRegistry.DICTIONARY_SERVICE.getLocalName());
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");
    permissionServiceImpl =
        (PermissionServiceImpl) applicationContext.getBean("permissionServiceImpl");
    namespacePrefixResolver =
        (NamespacePrefixResolver)
            applicationContext.getBean(ServiceRegistry.NAMESPACE_SERVICE.getLocalName());
    authenticationService =
        (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    authenticationComponent =
        (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    serviceRegistry =
        (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    permissionModelDAO = (ModelDAO) applicationContext.getBean("permissionsModelDAO");
    personService = (PersonService) applicationContext.getBean("personService");
    authorityService = (AuthorityService) applicationContext.getBean("authorityService");
    authorityDAO = (AuthorityDAO) applicationContext.getBean("authorityDAO");

    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
    nodeDAO = (NodeDAO) applicationContext.getBean("nodeDAO");
    aclDaoComponent = (AclDAO) applicationContext.getBean("aclDAO");

    publicServiceAccessService =
        (PublicServiceAccessService) applicationContext.getBean("publicServiceAccessService");

    retryingTransactionHelper =
        (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper");

    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");

    testTX = transactionService.getUserTransaction();
    testTX.begin();

    testStoreRef =
        nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime());
    rootNodeRef = nodeService.getRootNode(testStoreRef);

    QName children = ContentModel.ASSOC_CHILDREN;
    QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system");
    QName container = ContentModel.TYPE_CONTAINER;
    QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people");

    systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef();
    NodeRef typesNodeRef =
        nodeService.createNode(systemNodeRef, children, types, container).getChildRef();
    Map<QName, Serializable> props = createPersonProperties("andy");
    nodeService
        .createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props)
        .getChildRef();
    props = createPersonProperties("lemur");
    nodeService
        .createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props)
        .getChildRef();

    // create an authentication object e.g. the user
    if (authenticationDAO.userExists("andy")) {
      authenticationService.deleteAuthentication("andy");
    }
    authenticationService.createAuthentication("andy", "andy".toCharArray());

    if (authenticationDAO.userExists("lemur")) {
      authenticationService.deleteAuthentication("lemur");
    }
    authenticationService.createAuthentication("lemur", "lemur".toCharArray());

    if (authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) {
      authenticationService.deleteAuthentication(AuthenticationUtil.getAdminUserName());
    }
    authenticationService.createAuthentication(
        AuthenticationUtil.getAdminUserName(), "admin".toCharArray());

    authenticationComponent.clearCurrentSecurityContext();

    assertTrue(permissionServiceImpl.getAnyDenyDenies());
  }