mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3227 Simple rules tests. (#1236) [tas]
* ACS-3227 Initial tests for POST rules API. * ACS-3227 Add sanity tests for getting created rules. * Update license header year.
This commit is contained in:
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.rules;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.springframework.http.HttpStatus.CREATED;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
import org.alfresco.rest.RestTest;
|
||||||
|
import org.alfresco.rest.model.RestRuleModel;
|
||||||
|
import org.alfresco.rest.model.RestRuleModelsCollection;
|
||||||
|
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.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for POST /nodes/{nodeId}/rule-sets/{ruleSetId}/rules.
|
||||||
|
*/
|
||||||
|
@Test(groups = {TestGroup.RULES})
|
||||||
|
public class CreateRulesTests extends RestTest
|
||||||
|
{
|
||||||
|
private UserModel user;
|
||||||
|
private SiteModel site;
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true)
|
||||||
|
public void dataPreparation()
|
||||||
|
{
|
||||||
|
user = dataUser.createRandomTestUser();
|
||||||
|
site = dataSite.usingUser(user).createPublicRandomSite();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check we can create a rule. */
|
||||||
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||||
|
public void createRule()
|
||||||
|
{
|
||||||
|
STEP("Create a folder in existing site");
|
||||||
|
FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||||
|
|
||||||
|
RestRuleModel ruleModel = new RestRuleModel();
|
||||||
|
ruleModel.setName("ruleName");
|
||||||
|
|
||||||
|
RestRuleModel rule = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet()
|
||||||
|
.createSingleRule(ruleModel);
|
||||||
|
|
||||||
|
restClient.assertStatusCodeIs(CREATED);
|
||||||
|
|
||||||
|
rule.assertThat().field("id").isNotNull()
|
||||||
|
.assertThat().field("name").is("ruleName");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check we can create several rules. */
|
||||||
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
|
public void createRules()
|
||||||
|
{
|
||||||
|
STEP("Create a folder in existing site");
|
||||||
|
FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||||
|
|
||||||
|
STEP("Create a list of rules in one POST request");
|
||||||
|
List<String> ruleNames = List.of("ruleA", "ruleB", "ruleC");
|
||||||
|
List<RestRuleModel> ruleModels = ruleNames.stream().map(ruleName ->
|
||||||
|
{
|
||||||
|
RestRuleModel ruleModel = new RestRuleModel();
|
||||||
|
ruleModel.setName(ruleName);
|
||||||
|
return ruleModel;
|
||||||
|
}).collect(toList());
|
||||||
|
|
||||||
|
RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet()
|
||||||
|
.createListOfRules(ruleModels);
|
||||||
|
|
||||||
|
restClient.assertStatusCodeIs(CREATED);
|
||||||
|
|
||||||
|
assertEquals("Unexpected number of rules received in response.", ruleNames.size(), rules.getEntries().size());
|
||||||
|
IntStream.range(0, ruleModels.size()).forEach(i ->
|
||||||
|
rules.getEntries().get(i).onModel()
|
||||||
|
.assertThat().field("id").isNotNull()
|
||||||
|
.assertThat().field("name").is(ruleNames.get(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -25,12 +25,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.rules;
|
package org.alfresco.rest.rules;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import static org.alfresco.utility.report.log.Step.STEP;
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.alfresco.rest.RestTest;
|
import org.alfresco.rest.RestTest;
|
||||||
|
import org.alfresco.rest.model.RestRuleModel;
|
||||||
import org.alfresco.rest.model.RestRuleModelsCollection;
|
import org.alfresco.rest.model.RestRuleModelsCollection;
|
||||||
import org.alfresco.utility.model.FolderModel;
|
import org.alfresco.utility.model.FolderModel;
|
||||||
import org.alfresco.utility.model.SiteModel;
|
import org.alfresco.utility.model.SiteModel;
|
||||||
@@ -47,16 +54,29 @@ public class GetRulesTests extends RestTest
|
|||||||
{
|
{
|
||||||
private UserModel user;
|
private UserModel user;
|
||||||
private SiteModel site;
|
private SiteModel site;
|
||||||
|
private FolderModel ruleFolder;
|
||||||
|
private List<RestRuleModel> createdRules;
|
||||||
|
private RestRuleModel createdRuleA;
|
||||||
|
|
||||||
@BeforeClass(alwaysRun = true)
|
@BeforeClass(alwaysRun = true)
|
||||||
public void dataPreparation()
|
public void dataPreparation()
|
||||||
{
|
{
|
||||||
|
STEP("Create a user, site and folder");
|
||||||
user = dataUser.createRandomTestUser();
|
user = dataUser.createRandomTestUser();
|
||||||
site = dataSite.usingUser(user).createPublicRandomSite();
|
site = dataSite.usingUser(user).createPublicRandomSite();
|
||||||
|
ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||||
|
|
||||||
|
STEP("Create rules in the folder");
|
||||||
|
createdRules = Stream.of("ruleA", "ruleB").map(ruleName -> {
|
||||||
|
RestRuleModel ruleModel = new RestRuleModel();
|
||||||
|
ruleModel.setName(ruleName);
|
||||||
|
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||||
|
}).collect(toList());
|
||||||
|
createdRuleA = createdRules.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check we can get an empty list of rules. */
|
/** Check we can get an empty list of rules. */
|
||||||
@Test(groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
@Test(groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void getEmptyRulesList()
|
public void getEmptyRulesList()
|
||||||
{
|
{
|
||||||
STEP("Create a folder in existing site");
|
STEP("Create a folder in existing site");
|
||||||
@@ -69,6 +89,21 @@ public class GetRulesTests extends RestTest
|
|||||||
assertTrue("Expected no rules to be present.", rules.isEmpty());
|
assertTrue("Expected no rules to be present.", rules.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check we can get all the rules for a folder. */
|
||||||
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||||
|
public void getRulesList()
|
||||||
|
{
|
||||||
|
STEP("Get the rules that apply to the folder");
|
||||||
|
RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().getListOfRules();
|
||||||
|
|
||||||
|
restClient.assertStatusCodeIs(OK);
|
||||||
|
rules.assertThat().entriesListCountIs(createdRules.size());
|
||||||
|
IntStream.range(0, createdRules.size()).forEach(i ->
|
||||||
|
rules.getEntries().get(i).onModel()
|
||||||
|
.assertThat().field("id").is(createdRules.get(i).getId())
|
||||||
|
.assertThat().field("name").is(createdRules.get(i).getName()));
|
||||||
|
}
|
||||||
|
|
||||||
/** Check we get a 404 if trying to load rules for a folder that doesn't exist. */
|
/** Check we get a 404 if trying to load rules for a folder that doesn't exist. */
|
||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void getRulesForNonExistentFolder()
|
public void getRulesForNonExistentFolder()
|
||||||
@@ -91,6 +126,19 @@ public class GetRulesTests extends RestTest
|
|||||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check we can get a rule by its id. */
|
||||||
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||||
|
public void getSingleRule()
|
||||||
|
{
|
||||||
|
STEP("Load a particular rule");
|
||||||
|
RestRuleModel rule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().getSingleRule(createdRuleA.getId());
|
||||||
|
|
||||||
|
restClient.assertStatusCodeIs(OK);
|
||||||
|
|
||||||
|
rule.assertThat().field("id").is(createdRuleA.getId())
|
||||||
|
.assertThat().field("name").is(createdRuleA.getName());
|
||||||
|
}
|
||||||
|
|
||||||
/** Check we get a 404 if trying to load a rule from a folder that doesn't exist. */
|
/** Check we get a 404 if trying to load a rule from a folder that doesn't exist. */
|
||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void getSingleRuleFromNonExistentFolder()
|
public void getSingleRuleFromNonExistentFolder()
|
||||||
|
2
pom.xml
2
pom.xml
@@ -120,7 +120,7 @@
|
|||||||
<dependency.mariadb.version>2.7.4</dependency.mariadb.version>
|
<dependency.mariadb.version>2.7.4</dependency.mariadb.version>
|
||||||
<dependency.tas-utility.version>3.0.49</dependency.tas-utility.version>
|
<dependency.tas-utility.version>3.0.49</dependency.tas-utility.version>
|
||||||
<dependency.rest-assured.version>3.3.0</dependency.rest-assured.version>
|
<dependency.rest-assured.version>3.3.0</dependency.rest-assured.version>
|
||||||
<dependency.tas-restapi.version>1.93</dependency.tas-restapi.version>
|
<dependency.tas-restapi.version>1.94</dependency.tas-restapi.version>
|
||||||
<dependency.tas-cmis.version>1.31</dependency.tas-cmis.version>
|
<dependency.tas-cmis.version>1.31</dependency.tas-cmis.version>
|
||||||
<dependency.tas-email.version>1.8</dependency.tas-email.version>
|
<dependency.tas-email.version>1.8</dependency.tas-email.version>
|
||||||
<dependency.tas-webdav.version>1.6</dependency.tas-webdav.version>
|
<dependency.tas-webdav.version>1.6</dependency.tas-webdav.version>
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
package org.alfresco.rest.api.model.rules;
|
package org.alfresco.rest.api.model.rules;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -104,6 +106,12 @@ public class Rule
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Added stub for actions as it's a required field. Replace this implementation when we implement support for actions.
|
||||||
|
public List<Void> getActions()
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user