mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
REPO-3690: Add integration tests
* Prepare for addition of new tests specific to the transformation switches
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
package org.alfresco.rest.renditions;
|
||||
|
||||
import org.alfresco.rest.model.RestNodeModel;
|
||||
import org.alfresco.rest.model.RestRenditionInfoModel;
|
||||
import org.alfresco.rest.model.RestRenditionInfoModelCollection;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.testrail.ExecutionType;
|
||||
import org.alfresco.utility.testrail.annotation.TestRail;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Sanity check for renditions through REST API.<br>
|
||||
* Tests upload files and then request renditions for those files. <br>
|
||||
* Renditions are requested based on supported renditions according to GET '/nodes/{nodeId}/renditions'. <br>
|
||||
*/
|
||||
@Test(groups = {TestGroup.REQUIRE_TRANSFORMATION, TestGroup.RENDITIONS_REGRESSION})
|
||||
public class AvailableRenditionTests extends RenditionIntegrationTests
|
||||
{
|
||||
|
||||
/**
|
||||
* Check that a particular rendition can be created for the file and that it has the expected Mime type
|
||||
*/
|
||||
@Test(dataProvider = "RenditionTestDataProvider", groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY})
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify renditions created for a selection of test files via POST nodes/{nodeId}/renditions")
|
||||
public void supportedRenditionTest(String fileName, String renditionId, String expectedMimeType, String nodeId) throws Exception
|
||||
{
|
||||
checkRendition(fileName, nodeId, renditionId, expectedMimeType);
|
||||
}
|
||||
|
||||
@DataProvider(name = "RenditionTestDataProvider")
|
||||
protected Iterator<Object[]> renditionTestDataProvider() throws Exception
|
||||
{
|
||||
List<String> toTest = Arrays.asList("doc", "xls", "ppt", "docx", "xlsx", "pptx", "msg", "pdf", "png", "gif", "jpg");
|
||||
|
||||
List<Object[]> renditionsForFiles = new LinkedList<>();
|
||||
|
||||
for (String extensions : toTest)
|
||||
{
|
||||
String sourceFile = "quick/quick." + extensions;
|
||||
renditionsForFiles.addAll(uploadFileAndGetAvailableRenditions(sourceFile));
|
||||
}
|
||||
|
||||
return renditionsForFiles.iterator();
|
||||
}
|
||||
/**
|
||||
* Upload a source file, get all supported renditions for it.
|
||||
*/
|
||||
private List<Object[]> uploadFileAndGetAvailableRenditions(String sourceFile) throws Exception
|
||||
{
|
||||
|
||||
// Create folder & upload file
|
||||
RestNodeModel fileNode = uploadFile(sourceFile);
|
||||
FileModel file = new FileModel();
|
||||
file.setNodeRef(fileNode.getId());
|
||||
|
||||
List<Object[]> renditionsForFile = new LinkedList<>();
|
||||
|
||||
// Get supported renditions
|
||||
RestRenditionInfoModelCollection renditionsInfo = restClient.withCoreAPI().usingNode(file).getNodeRenditionsInfo();
|
||||
for (RestRenditionInfoModel m : renditionsInfo.getEntries())
|
||||
{
|
||||
RestRenditionInfoModel renditionInfo = m.onModel();
|
||||
String renditionId = renditionInfo.getId();
|
||||
String targetMimeType = renditionInfo.getContent().getMimeType();
|
||||
|
||||
renditionsForFile.add(new Object[]{sourceFile, renditionId, targetMimeType, fileNode.getId()});
|
||||
|
||||
}
|
||||
|
||||
return renditionsForFile;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "UnsupportedRenditionTestDataProvider",groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY})
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify that requests for unsupported renditions return 400 ")
|
||||
public void unsupportedRenditionTest(String sourceFile, String renditionId) throws Exception
|
||||
{
|
||||
RestNodeModel fileNode = uploadFile(sourceFile);
|
||||
|
||||
// 2. Request rendition of the file using RESTAPI
|
||||
FileModel file = new FileModel(sourceFile);
|
||||
file.setNodeRef(fileNode.getId());
|
||||
restClient.withCoreAPI().usingNode(file).createNodeRendition(renditionId);
|
||||
|
||||
Assert.assertEquals(restClient.getStatusCode(), HttpStatus.BAD_REQUEST.toString(),
|
||||
"Expected to see the rendition rejected. [" + sourceFile + ", " + renditionId + "] [source file, rendition ID] ");
|
||||
}
|
||||
|
||||
@DataProvider(name = "UnsupportedRenditionTestDataProvider")
|
||||
protected Iterator<Object[]> unsupportedRenditionTestDataProvider() throws Exception
|
||||
{
|
||||
String renditionId = "pdf";
|
||||
|
||||
List<Object[]> toTest = new LinkedList<>();
|
||||
toTest.add(new Object[]{"quick/quick.png", renditionId});
|
||||
toTest.add(new Object[]{"quick/quick.gif", renditionId});
|
||||
toTest.add(new Object[]{"quick/quick.jpg", renditionId});
|
||||
toTest.add(new Object[]{"quick/quick.pdf", renditionId});
|
||||
|
||||
return toTest.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,38 +3,22 @@ package org.alfresco.rest.renditions;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.core.RestResponse;
|
||||
import org.alfresco.rest.model.RestNodeModel;
|
||||
import org.alfresco.rest.model.RestRenditionInfoModel;
|
||||
import org.alfresco.rest.model.RestRenditionInfoModelCollection;
|
||||
import org.alfresco.utility.Utility;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.alfresco.utility.testrail.ExecutionType;
|
||||
import org.alfresco.utility.testrail.annotation.TestRail;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Sanity check for renditions through REST API.<br>
|
||||
* Tests upload files and then request renditions for those files. <br>
|
||||
* Renditions are requested based on supported renditions according to GET '/nodes/{nodeId}/renditions'. <br>
|
||||
*/
|
||||
@Test(groups = {TestGroup.REQUIRE_TRANSFORMATION, TestGroup.RENDITIONS_REGRESSION})
|
||||
public class RenditionIntegrationTests extends RestTest
|
||||
public abstract class RenditionIntegrationTests extends RestTest
|
||||
{
|
||||
|
||||
private UserModel user;
|
||||
private SiteModel site;
|
||||
protected UserModel user;
|
||||
protected SiteModel site;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void dataPreparation() throws Exception
|
||||
@@ -44,14 +28,16 @@ public class RenditionIntegrationTests extends RestTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a particular rendition can be created for the file and that it has the expected Mime type
|
||||
* Check that a rendition can be created for the specified node id
|
||||
* @param fileName
|
||||
* @param nodeId
|
||||
* @param renditionId
|
||||
* @param expectedMimeType
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test(dataProvider = "RenditionTestDataProvider", groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY})
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify renditions created for a selection of test files via POST nodes/{nodeId}/renditions")
|
||||
public void supportedRenditionTest(String fileName, String renditionId, String expectedMimeType, String nodeId) throws Exception
|
||||
protected void checkRendition(String fileName, String nodeId, String renditionId, String expectedMimeType) throws Exception
|
||||
{
|
||||
FileModel file = new FileModel(fileName);
|
||||
FileModel file = new FileModel();
|
||||
file.setNodeRef(nodeId);
|
||||
|
||||
// 1. Create a rendition of the file using RESTAPI
|
||||
@@ -73,29 +59,14 @@ public class RenditionIntegrationTests extends RestTest
|
||||
"Rendition was created but its content is empty. [" + fileName+ ", " + renditionId+"] [source file, rendition ID] ");
|
||||
}
|
||||
|
||||
@DataProvider(name = "RenditionTestDataProvider")
|
||||
protected Iterator<Object[]> renditionTestDataProvider() throws Exception
|
||||
{
|
||||
List<String> toTest = Arrays.asList("doc", "xls", "ppt", "docx", "xlsx", "pptx", "msg", "png", "gif", "jpg", "pdf", "txt"); // "tiff"
|
||||
|
||||
List<Object[]> renditionsForFiles = new LinkedList<>();
|
||||
|
||||
for (String extensions : toTest)
|
||||
{
|
||||
String sourceFile = "quick/quick." + extensions;
|
||||
renditionsForFiles.addAll(uploadFileAndGetAvailableRenditions(sourceFile));
|
||||
}
|
||||
|
||||
return renditionsForFiles.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a source file, get all supported renditions for it.
|
||||
* Upload a file and return its node id
|
||||
* @param sourceFile
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<Object[]> uploadFileAndGetAvailableRenditions(String sourceFile) throws Exception
|
||||
protected RestNodeModel uploadFile(String sourceFile) throws Exception
|
||||
{
|
||||
|
||||
// Create folder & upload file
|
||||
FolderModel folder = FolderModel.getRandomFolderModel();
|
||||
folder = dataContent.usingUser(user).usingSite(site).createFolder(folder);
|
||||
restClient.authenticateUser(user).configureRequestSpec()
|
||||
@@ -105,61 +76,6 @@ public class RenditionIntegrationTests extends RestTest
|
||||
Assert.assertEquals(restClient.getStatusCode(), HttpStatus.CREATED.toString(),
|
||||
"Failed to created a node for rendition tests using file " + sourceFile);
|
||||
|
||||
FileModel file = new FileModel(sourceFile);
|
||||
file.setNodeRef(fileNode.getId());
|
||||
|
||||
List<Object[]> renditionsForFile = new LinkedList<>();
|
||||
|
||||
// Get supported renditions
|
||||
RestRenditionInfoModelCollection renditionsInfo = restClient.withCoreAPI().usingNode(file).getNodeRenditionsInfo();
|
||||
for (RestRenditionInfoModel m : renditionsInfo.getEntries())
|
||||
{
|
||||
RestRenditionInfoModel renditionInfo = m.onModel();
|
||||
String renditionId = renditionInfo.getId();
|
||||
String targetMimeType = renditionInfo.getContent().getMimeType();
|
||||
|
||||
renditionsForFile.add(new Object[]{sourceFile, renditionId, targetMimeType, fileNode.getId()});
|
||||
|
||||
}
|
||||
|
||||
return renditionsForFile;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "UnsupportedRenditionTestDataProvider",groups = {TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY})
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify that requests for unsupported renditions return 400 ")
|
||||
public void unsupportedRenditionTest(String sourceFile, String renditionId) throws Exception
|
||||
{
|
||||
// 1. Create a folder in existing site"
|
||||
FolderModel folder = FolderModel.getRandomFolderModel();
|
||||
folder = dataContent.usingUser(user).usingSite(site).createFolder(folder);
|
||||
|
||||
// 2. Upload a local file using RESTAPI
|
||||
restClient.authenticateUser(user).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile(sourceFile));
|
||||
RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).createNode();
|
||||
Assert.assertEquals(restClient.getStatusCode(), HttpStatus.CREATED.toString(),
|
||||
"Failed to created a node for rendition tests using file " + sourceFile);
|
||||
|
||||
// 3. Request rendition of the file using RESTAPI
|
||||
FileModel file = new FileModel(sourceFile);
|
||||
file.setNodeRef(fileNode.getId());
|
||||
restClient.withCoreAPI().usingNode(file).createNodeRendition(renditionId);
|
||||
|
||||
Assert.assertEquals(restClient.getStatusCode(), HttpStatus.BAD_REQUEST.toString(),
|
||||
"Expected to see the rendition rejected. [" + sourceFile + ", " + renditionId + "] [source file, rendition ID] ");
|
||||
}
|
||||
|
||||
@DataProvider(name = "UnsupportedRenditionTestDataProvider")
|
||||
protected Iterator<Object[]> unsupportedRenditionTestDataProvider() throws Exception
|
||||
{
|
||||
String renditionId = "pdf";
|
||||
|
||||
List<Object[]> toTest = new LinkedList<>();
|
||||
toTest.add(new Object[]{"quick/quick.png", renditionId});
|
||||
toTest.add(new Object[]{"quick/quick.gif", renditionId});
|
||||
toTest.add(new Object[]{"quick/quick.jpg", renditionId});
|
||||
toTest.add(new Object[]{"quick/quick.pdf", renditionId});
|
||||
|
||||
return toTest.iterator();
|
||||
return fileNode;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user