AnsweredAssumed Answered

Webscript unit-test in alfresco 5.0.1 / 5.0.2 are not working

Question asked by ryanj on Dec 17, 2015
Hi All,

I checked out a fresh alfresco project and changed it version to 5.0.1. And when I wanted to test a fresh repo side webscript, then it shows a list of errors as given below. Hence test fails. Im struck in this point. Please help me out.


Error creating bean with name 'authorityBridgeTableCache'
   defined in class path resource
      [alfresco/cache-context.xml]:
   Cannot resolve reference to bean 'tenantAdminService'
   while setting bean property 'tenantAdminService';
   nested exception is org.springframework.beans.factory.BeanCreationException:
   
Error creating bean with name 'tenantAdminService'
   defined in URL
      [jar:file:/Users/ssiddique/.m2/repository/org/alfresco/alfresco-repository/5.0.1/alfresco-repository-5.0.1.jar!/alfresco/mt/mt-admin-context.xml]:
   Cannot resolve reference to bean 'dbNodeServiceImpl'
   while setting bean property 'nodeService';
   nested exception is org.springframework.beans.factory.BeanCreationException:
   
Error creating bean with name 'dbNodeService'
   defined in class path resource
      [alfresco/node-services-context.xml]:
   Cannot resolve reference to bean 'permissionServiceImpl'
   while setting bean property 'permissionService';
   nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'permissionServiceImpl'
   defined in class path resource
      [alfresco/public-services-security-context.xml]:
   Cannot resolve reference to bean 'authorityService'
   while setting bean property 'authorityService';
   nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'authorityService'
   defined in class path resource
      [alfresco/authority-services-context.xml]:
   Cannot resolve reference to bean 'personService'
   while setting bean property 'personService';
   nested exception is org.springframework.beans.factory.BeanCreationException:
   
Error creating bean with name 'personService'
   defined in class path resource
      [alfresco/authentication-services-context.xml]:
   Cannot resolve reference to bean 'eventPublisher'
   while setting bean property 'eventPublisher';
   nested exception is org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class [org.alfresco.repo.events.EventPublisherForTestingOnly] for bean with name 'eventPublisher' defined in class path resource [alfresco/web-scripts-application-context-test.xml]; nested exception is java.lang.ClassNotFoundException: org.alfresco.repo.events.EventPublisherForTestingOnly


Following is my test class:-

package com.zaizi.alfresco.trinity.demoamp.test;

import org.activiti.engine.impl.util.json.JSONObject;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.extensions.webscripts.TestWebScriptServer.Request;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
import org.alfresco.httpclient.GetRequest;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.site.SiteService;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.util.HttpURLConnection;
import org.apache.http.client.methods.RequestBuilder;
import org.junit.Test;
import org.alfresco.util.GUID;

public class testWebscript extends BaseWebScriptTest
{
    private ServiceRegistry serviceRegistry;
    private SiteService siteService;
    public testWebscript(final ServiceRegistry serviceRegistry){
        this.serviceRegistry = serviceRegistry;
        this.siteService = serviceRegistry.getSiteService();
    }
    //the following method will be called on test runtime.
    public void testSample()
    {
       executeTest();
    }
    public void executeTest(){
        AuthenticationUtil.setRunAsUser("admin");
       
        Request req = new Request("get", "/alfresco/service/getWebscript");
        try{
            Response res = sendRequest(req, HttpStatus.SC_OK, "admin");
            String ax = res.getContentAsString();
            JSONObject jj = new JSONObject(ax);
            JSONObject j2 = jj.getJSONObject("result");
            System.out.println(j2.toString());
        }
        catch(Exception e){
            System.out.println("exception occured: "+ e.getMessage());
        }
    }

Regrds,
Shamran.

Outcomes