diff --git a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java index a05ce82f3..f85d9d8ae 100644 --- a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java +++ b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java @@ -1,20 +1,40 @@ package org.alfresco.rest.actions; +import static junit.framework.Assert.fail; +import static org.testng.Assert.assertFalse; + +import org.alfresco.dataprep.CMISUtil; import org.alfresco.rest.RestTest; import org.alfresco.rest.exception.EmptyJsonResponseException; +import org.alfresco.rest.model.RestActionDefinitionModel; import org.alfresco.rest.model.RestActionDefinitionModelsCollection; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +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.json.JSONObject; import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import static junit.framework.TestCase.fail; -import static org.testng.Assert.assertFalse; - public class ActionsTests extends RestTest { + private UserModel adminUser; + private FileModel document; + private SiteModel publicSite; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + publicSite = dataSite.createPublicRandomSite(); + document = dataContent.usingSite(publicSite).usingUser(adminUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, description = "Verify actions") @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY}) @@ -57,17 +77,50 @@ public class ActionsTests extends RestTest { UserModel userUnauthorized = new UserModel("invalid-user", "invalid-pasword"); - try - { - restClient.authenticateUser(userUnauthorized).withCoreAPI().usingActions().listActionDefinitions(); - fail("Expected an empty JSON response exception"); - } - catch (EmptyJsonResponseException e) - { - // Since there is no JSON for a 401, the processModels directive - // will throw the EmptyJsonResponseException - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); - } + restClient.authenticateUser(userUnauthorized).withCoreAPI().usingActions().listActionDefinitions(); + + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); } } + + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, + description = "Sanity test for POST /action-executions") + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY}) + public void executeAction() throws Exception + { + JSONObject response = restClient.authenticateUser(adminUser).withCoreAPI().usingActions().executeAction("add-features", document, "aspect-name", "cm:versionable"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + assertFalse(response.getString("id").isEmpty()); + + /* + * Get all node properties and check that action was executed and + * cm:versionable aspect was added + */ + Utility.sleep(500, 20000, () -> { + RestNodeModel fileModel = restClient.authenticateUser(adminUser).withCoreAPI().usingNode(document).getNode(); + + restClient.assertStatusCodeIs(HttpStatus.OK); + fileModel.assertThat().field("aspectNames").contains("cm:versionable"); + }); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, + description = "Sanity test for ACTIONS endpoint GET action-definitions/{actionDefinitionId}") + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY}) + public void testGetActionDefinitionById() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()); + + RestActionDefinitionModel restActionDefinition = restClient. + withCoreAPI(). + usingActions(). + getActionDefinitionById("add-features"); + + restClient.assertStatusCodeIs(HttpStatus.OK); + assertFalse(restActionDefinition.getId().isEmpty()); + restActionDefinition.getId().equals("add-features"); + restActionDefinition.getDescription().equals("This will add an aspect to the matched item."); + restActionDefinition.getTitle().equals("Add aspect"); + } } diff --git a/e2e-test/java/org/alfresco/rest/discovery/DiscoveryTests.java b/e2e-test/java/org/alfresco/rest/discovery/DiscoveryTests.java new file mode 100644 index 000000000..ae6271040 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/discovery/DiscoveryTests.java @@ -0,0 +1,48 @@ +package org.alfresco.rest.discovery; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.model.RestDiscoveryModel; +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.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DiscoveryTests extends RestTest +{ + private UserModel adminModel, userModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminModel = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.DISCOVERY, TestGroup.SANITY }) + @TestRail(section = { TestGroup.REST_API, TestGroup.DISCOVERY }, executionType = ExecutionType.SANITY, + description = "Sanity tests for GET /discovery endpoint") + public void getRepositoryInformation() throws Exception + { + // Get repository info from admin console + RestResponse adminConsoleRepoInfo = restClient.authenticateUser(adminModel).withAdminConsole().getAdminConsoleRepoInfo(); + String edition = adminConsoleRepoInfo.getResponse().getBody().path("data.edition"); + String schema = adminConsoleRepoInfo.getResponse().getBody().path("data.schema"); + String version = adminConsoleRepoInfo.getResponse().getBody().path("data.version"); + + // Get repository info using Discovery API + RestDiscoveryModel response = restClient.authenticateUser(userModel).withDiscoveryAPI().getRepositoryInfo(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + // Compare information + response.getRepository().getVersion().assertThat().field("major").is(version.charAt(0)); + response.getRepository().getVersion().assertThat().field("minor").is(version.charAt(2)); + response.getRepository().getVersion().assertThat().field("patch").is(version.charAt(4)); + response.getRepository().getVersion().assertThat().field("schema").is(schema); + response.getRepository().getEdition().equals(edition); + response.getRepository().getStatus().assertThat().field("isReadOnly").is(false); + } +} diff --git a/e2e-test/java/org/alfresco/rest/syncService/SyncServiceAPITests.java b/e2e-test/java/org/alfresco/rest/syncService/SyncServiceAPITests.java index 2bad98400..58dacb907 100644 --- a/e2e-test/java/org/alfresco/rest/syncService/SyncServiceAPITests.java +++ b/e2e-test/java/org/alfresco/rest/syncService/SyncServiceAPITests.java @@ -30,7 +30,7 @@ import org.testng.annotations.Test; * * @author mbhave */ -@Test(groups = {TestGroup.SYNC_API, TestGroup.REQUIRES_AMP}) +@Test(groups = { TestGroup.SYNC_API, TestGroup.REQUIRES_AMP }) public class SyncServiceAPITests extends RestTest { private static Logger LOG = LogFactory.getLogger(); @@ -41,7 +41,7 @@ public class SyncServiceAPITests extends RestTest private FolderModel targetFolder2; private RestSyncNodeSubscriptionModelCollection nodeSubscriptions; - + private String clientVersion; @BeforeClass(alwaysRun = true) @@ -51,25 +51,24 @@ public class SyncServiceAPITests extends RestTest restClient.authenticateUser(adminUserModel); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - + targetFolder1 = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); targetFolder2 = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); siteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(siteModel).getSite().getGuidWithoutVersion()); - + clientVersion = "1.1"; } @Test(priority = 1) public void testSyncServiceHealthCheck() throws Exception { - // Register Device + // Perform HealthCheck Healthcheck healthCheck = restClient.authenticateUser(adminUserModel).withPrivateAPI().doHealthCheck(); - restClient.assertStatusCodeIs(HttpStatus.OK); - + RestSyncServiceHealthCheckModel syncServiceHealthCheck = healthCheck.getHealthcheck(); - + Assert.assertTrue(syncServiceHealthCheck.getActiveMQConnection().getHealthy()); Assert.assertTrue(syncServiceHealthCheck.getDatabaseConnection().getHealthy()); Assert.assertTrue(syncServiceHealthCheck.getRepositoryConnection().getHealthy()); @@ -78,39 +77,40 @@ public class SyncServiceAPITests extends RestTest Assert.assertTrue(syncServiceHealthCheck.getSyncServiceIdCheck().getHealthy()); Assert.assertTrue(syncServiceHealthCheck.getVersionCheck().getHealthy()); } - + @Test(priority = 2) public void testNewDeviceSubscription() throws Exception { // Register Device - RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscribers().registerDevice("windows", clientVersion); + RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscribers() + .registerDevice("windows", clientVersion); restClient.assertStatusCodeIs(HttpStatus.CREATED); restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.notNullValue()); restClient.onResponse().assertThat().body("entry.id", org.hamcrest.Matchers.equalTo(deviceSubscription.getId())); // Get Registered Devices - RestSubscriberModelCollection deviceSubscriptions = restClient.authenticateUser(adminUserModel).withParams("maxItems=500").withPrivateAPI().withSubscribers().getSubscribers(); + RestSubscriberModelCollection deviceSubscriptions = restClient.authenticateUser(adminUserModel).withParams("maxItems=500").withPrivateAPI() + .withSubscribers().getSubscribers(); restClient.onResponse().assertThat().body("list.entries.entry", org.hamcrest.Matchers.notNullValue()); int noOfSubscriptions = deviceSubscriptions.getEntries().size(); Assert.assertTrue(noOfSubscriptions > 0, "No Device subscriptions found when expected"); - Assert.assertTrue(deviceSubscriptions.getEntries().get(noOfSubscriptions - 1).onModel().getId().equals(deviceSubscription.getId()),"Not found: " + deviceSubscription.getId()); + Assert.assertTrue(deviceSubscriptions.getEntries().get(noOfSubscriptions - 1).onModel().getId().equals(deviceSubscription.getId()), "Not found: " + + deviceSubscription.getId()); } - + @Test(priority = 3) public void testDeviceSubcriptionToNode() throws Exception { // Register Device - RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscribers().registerDevice("windows", - clientVersion); + RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscribers() + .registerDevice("windows", clientVersion); // Subscribe to a node - RestSyncNodeSubscriptionModel nodeSubscription = restClient - .withPrivateAPI() - .withSubscriber(deviceSubscription) - .subscribeToNode(targetFolder1.getNodeRefWithoutVersion(), TYPE.BOTH); + RestSyncNodeSubscriptionModel nodeSubscription = restClient.withPrivateAPI().withSubscriber(deviceSubscription) + .subscribeToNode(targetFolder1.getNodeRefWithoutVersion(), TYPE.BOTH); restClient.assertStatusCodeIs(HttpStatus.CREATED); restClient.onResponse().assertThat().body("entry.deviceSubscriptionId", org.hamcrest.Matchers.notNullValue()); @@ -142,17 +142,17 @@ public class SyncServiceAPITests extends RestTest subscription.assertThat().field("id").isNotNull().assertThat().field("id").is(nodeSubscription.getId()).assertThat().field("deviceSubscriptionId") .isNotNull().assertThat().field("deviceSubscriptionId").is(nodeSubscription.getDeviceSubscriptionId()); } - + @Test(priority = 4) public void testDeviceSubcriptionToMultipleNodes() throws Exception { // Register Device - RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscribers().registerDevice("windows", - "1.2"); + RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscribers() + .registerDevice("windows", "1.2"); // Subscribe to a node - restClient.withPrivateAPI().withSubscriber(deviceSubscription).subscribeToNodes(siteModel.getGuid(), targetFolder1.getNodeRefWithoutVersion(), - targetFolder2.getNodeRefWithoutVersion()); + restClient.withPrivateAPI().withSubscriber(deviceSubscription) + .subscribeToNodes(siteModel.getGuid(), targetFolder1.getNodeRefWithoutVersion(), targetFolder2.getNodeRefWithoutVersion()); restClient.assertStatusCodeIs(HttpStatus.CREATED); // Get Sync Node Subscriptions @@ -167,23 +167,18 @@ public class SyncServiceAPITests extends RestTest { // Register Device List clientChanges = new LinkedList<>(); - RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel) - .withPrivateAPI() - .withSubscribers() - .registerDevice("windows","1.2"); + RestSubscriberModel deviceSubscription = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscribers() + .registerDevice("windows", "1.2"); // Subscribe to a node - RestSyncNodeSubscriptionModel nodeSubscription = restClient.withPrivateAPI() - .withSubscriber(deviceSubscription) - .subscribeToNode(targetFolder1.getNodeRefWithoutVersion(), TYPE.BOTH); + RestSyncNodeSubscriptionModel nodeSubscription = restClient.withPrivateAPI().withSubscriber(deviceSubscription) + .subscribeToNode(targetFolder1.getNodeRefWithoutVersion(), TYPE.BOTH); restClient.assertStatusCodeIs(HttpStatus.CREATED); // Start Sync - RestSyncSetRequestModel syncRequest = restClient.authenticateUser(adminUserModel) - .withPrivateAPI() - .withSubscription(nodeSubscription) - .startSync(nodeSubscription, clientChanges, clientVersion); - + RestSyncSetRequestModel syncRequest = restClient.authenticateUser(adminUserModel).withPrivateAPI().withSubscription(nodeSubscription) + .startSync(nodeSubscription, clientChanges, clientVersion); + restClient.assertStatusCodeIs(HttpStatus.CREATED); Assert.assertNotNull(syncRequest.getSyncId(), "Sync Id not expected to be null"); @@ -196,14 +191,14 @@ public class SyncServiceAPITests extends RestTest // Get Sync Changes RestSyncSetGetModel changeSet = restClient.withPrivateAPI().withSubscription(nodeSubscription).getSync(nodeSubscription, syncRequest); - + restClient.assertStatusCodeIs(HttpStatus.OK); Assert.assertNotNull(changeSet.getSyncId(), "Sync Id not expected to be null"); Assert.assertTrue(changeSet.getSyncId().equals(syncId), "Incorrect SyncId in the response"); Assert.assertNotNull(changeSet.getMoreChanges(), "MoreChanges expected to be true or false. It's null"); // End Sync - restClient.withPrivateAPI().withSubscription(nodeSubscription).endSync(nodeSubscription,syncRequest); + restClient.withPrivateAPI().withSubscription(nodeSubscription).endSync(nodeSubscription, syncRequest); restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); } }