cancel
Showing results for 
Search instead for 
Did you mean: 

Webscript testing

sanketgosavi
Champ in-the-making
Champ in-the-making

Hi,

how can I perform unit testing of Junit on alfresco webscripts,

I have found a solution on forum; but cant find jar of following :
org.springframework.extensions.webscripts.TestWebScriptServer
1 ACCEPTED ANSWER

Solved problem. Now I can use all the stuff from BaseWebScriptTest in my tests.
This configuration in my pom file solved my problem.



         <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-remote-api</artifactId>
            <version>4.1.5</version>
        </dependency>

        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-remote-api</artifactId>
            <scope>provided</scope>
            <classifier>config</classifier>
            <version>4.1.5</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.extensions.surf</groupId>
            <artifactId>spring-webscripts</artifactId>
            <version>1.2.0-M14</version>
            <classifier>tests</classifier>
        </dependency>


View answer in original post

6 REPLIES 6

abarisone
Star Contributor
Star Contributor

Hi Andrea,

I am still not be able to get this working although you last commit help me to understand it.
I am just trying with this example (https://wiki.alfresco.com/wiki/3.0_Web_Scripts_Testing)
How ever when I run mvn clean package I am getting the error below. My guess is that I am missing some dependencies in my pom which you can see below as well. Could you help me, thanks?

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [alfresco/web-scripts-application-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [alfresco/web-scripts-application-context.xml] cannot be opened because it does not exist
   at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
   at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
   at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
   at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
   at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
   at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
   at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
   at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
   at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
   at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
   at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
   at org.alfresco.repo.web.scripts.TestWebScriptRepoServer.getTestServer(TestWebScriptRepoServer.java:164)
   at org.alfresco.repo.web.scripts.TestWebScriptRepoServer.getTestServer(TestWebScriptRepoServer.java:111)
   at org.alfresco.repo.web.scripts.BaseWebScriptTest.getServer(BaseWebScriptTest.java:262)
   at com.netaporter.api.publish.PublishContentTest.setUp(PublishContentTest.java:29)



It seems it can't load the context or something like that. This my pom file:

// this is pointing at alfresco-sdk-parent artifactId
<parent>
        <groupId>com.company.cms.content-alfresco</groupId>
        <artifactId>cms-content-parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

 

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-remote-api</artifactId>
            <version>4.1.5</version>
        </dependency>

        <dependency>
          <groupId>org.springframework.extensions.surf</groupId>
          <artifactId>spring-surf</artifactId>
          <version>1.2.0-M9</version>
        </dependency>

        <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-test</artifactId>
           <version>3.0.0.RELEASE</version>
        </dependency>

        <dependency>
          <groupId>org.springframework.extensions.surf</groupId>
          <artifactId>spring-surf-core-configservice</artifactId>
          <version>1.2.0-M14</version>
        </dependency>

        <dependency>
          <groupId>org.springframework.extensions.surf</groupId>
          <artifactId>spring-webscripts</artifactId>
          <version>1.2.0-M14</version>
          <classifier>tests</classifier>
        </dependency>

        <dependency>
          <groupId>org.springframework.extensions.surf</groupId>
          <artifactId>spring-surf-core</artifactId>
          <version>1.2.0-M14</version>
        </dependency>

        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>4.0.0.M3</version>
        </dependency>

abarisone
Star Contributor
Star Contributor
Hi,
reading the content of the site it states:
<cite>NOTE: This document describes features found in Alfresco v3 onwards (Older versions: v2)
NOTE: This document does not cover 3.4 changes. 3.4 introduces considerable changes with regard to packages, in particular the use of Spring Surf</cite>
So depending on the version you're using this information could not be up-to-date.
Try to search the forum for other resources about testing:
http://docs.alfresco.com/4.2/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Ftasks%2Fws-register.ht...

Regards,
Andrea

Hi,

I am using enterprise 4.1.5. However if you have a look at the alfresco source they are using that way to test the api everywhere in the source. Have a look at the project alfresco-remote-api you will see how they extend from BaseWebScriptTest. For instance the class NodeLocatorWebScriptTest. Which is something new in Alfresco4 and they are using this way to test it.
I would like to know how to test my api in the same way. Unfortunately because of the problem I mentioned above it does not work. And there is a lack of documentations about it.

David.

Solved problem. Now I can use all the stuff from BaseWebScriptTest in my tests.
This configuration in my pom file solved my problem.



         <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-remote-api</artifactId>
            <version>4.1.5</version>
        </dependency>

        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-remote-api</artifactId>
            <scope>provided</scope>
            <classifier>config</classifier>
            <version>4.1.5</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.extensions.surf</groupId>
            <artifactId>spring-webscripts</artifactId>
            <version>1.2.0-M14</version>
            <classifier>tests</classifier>
        </dependency>


i used the same config as iguannago  mentioned but i am getting an error like 

[ERROR] Failed to execute goal on project repo: Could not resolve dependencies for project versions-diff:repo:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.alfresco:alfresco-remote-api:jar:4.1.5: Failed to read artifact descriptor for org.alfresco:alfresco-remote-api:jar:4.1.5: Could not transfer artifact org.alfresco:alfresco-remote-apiSmiley Tongueom:4.1.5 from/to alfresco-private-repository (https://artifacts.alfresco.com/nexus/content/groups/private): Not authorized , ReasonPhrase:Unauthorized. -> [Help 1]
[ERROR]

please help!