Documentation to write test cases for the functionalities in alfresco community edition

cancel
Showing results for 
Search instead for 
Did you mean: 
arjunm1989
Active Member

Documentation to write test cases for the functionalities in alfresco community edition

Is there a documentation to write test cases for the functionalities which are supported by alfresco.

3 Replies
abhinavmishra14
Advanced

Re: Documentation to write test cases for the functionalities in alfresco community edition

I am not sure if there is any specific documentation available in docs.alfresco.com for writing test cases. You should take reference from alfresco sdk sample and follow the same approach while writing test cases. You can write simple junit test cases as well as Integration test cases. 

Refer this sdk doc for details on integration test:

https://github.com/Alfresco/alfresco-sdk/blob/master/docs/advanced-topics/integration-testing/it-wor...

Sample webscript test case, you can find this in sample artifacts generated via sdk:

import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.extensions.webscripts.*;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class HelloWorldWebScriptControllerTest {
    @Test
    public void testController() {
        WebScriptRequest req = Mockito.mock(WebScriptRequest.class);
        Status status = Mockito.mock(Status.class);
        Cache cache = Mockito.mock(Cache.class);
        String helloPropName = "fromJava";
        String helloPropExpectedValue = "HelloFromJava";
        HelloWorldWebScript ws = new HelloWorldWebScript();
        Map<String, Object> model = ws.executeImpl(req, status, cache);
        assertNotNull("Response from Web Script Java Controller is null", model);
        assertEquals("Incorrect Web Script Java Controller Response",
                helloPropExpectedValue, model.get(helloPropName));
    }
}

Sample of IT:

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class HelloWorldWebScriptIT {
    private static final String ACS_ENDPOINT_PROP = "acs.endpoint.path";
    private static final String ACS_DEFAULT_ENDPOINT = "http://localhost:8080/alfresco";
    @Test
    public void testWebScriptCall() throws Exception {
        String webscriptURL = getPlatformEndpoint() + "/service/sample/helloworld";
        String expectedResponse = "Message: 'Hello from JS!' 'HelloFromJava'";
        // Login credentials for Alfresco Repo
        CredentialsProvider provider = new BasicCredentialsProvider();
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
        provider.setCredentials(AuthScope.ANY, credentials);

        // Create HTTP Client with credentials
        CloseableHttpClient httpclient = HttpClientBuilder.create()
                .setDefaultCredentialsProvider(provider)
                .build();
        // Execute Web Script call
        try {
            HttpGet httpget = new HttpGet(webscriptURL);
            HttpResponse httpResponse = httpclient.execute(httpget);
            assertEquals("Incorrect HTTP Response Status",
                    HttpStatus.SC_OK, httpResponse.getStatusLine().getStatusCode());
            HttpEntity entity = httpResponse.getEntity();
            assertNotNull("Response from Web Script is null", entity);
            assertEquals("Incorrect Web Script Response", expectedResponse, EntityUtils.toString(entity));
        } finally {
            httpclient.close();
        }
    }
    private String getPlatformEndpoint() {
        final String platformEndpoint = System.getProperty(ACS_ENDPOINT_PROP);
        return StringUtils.isNotBlank(platformEndpoint) ? platformEndpoint : ACS_DEFAULT_ENDPOINT;
    }
}
~Abhinav
(ACSCE, AWS SAA, Azure Admin)
arjunm1989
Active Member

Re: Documentation to write test cases for the functionalities in alfresco community edition

Thank you Abhinav. Also is there any doc that covering all the tasks or actions list in alfresco share kind of default alfresco scenarios or functionalities.

abhinavmishra14
Advanced

Re: Documentation to write test cases for the functionalities in alfresco community edition

No, or i am not aware of any such specific doc. However, you can go through this video tutorials to learn more:

https://docs.alfresco.com/6.2/topics/alfresco-video-tutorials.html

~Abhinav
(ACSCE, AWS SAA, Azure Admin)