mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-10 14:11:58 +00:00
Compare commits
24 Commits
tas-restap
...
tas-restap
Author | SHA1 | Date | |
---|---|---|---|
|
10f32aa74c | ||
|
bea386ddc8 | ||
|
2449d1d8f3 | ||
|
3883fd22e3 | ||
|
183ac4c7cd | ||
|
fa1b8d46dd | ||
|
df35137d12 | ||
|
1d1b454978 | ||
|
deaee78d09 | ||
|
9e3c144a7d | ||
|
d0b100a88b | ||
|
9d807242ee | ||
|
5f2b5fe9af | ||
|
7edee67997 | ||
|
5f151aaa96 | ||
|
dcf25d89d0 | ||
|
7d5aafecb5 | ||
|
1d8f1bd8a2 | ||
|
fe04e621e1 | ||
|
ee03296733 | ||
|
c5e89242ba | ||
|
0fbeffe80a | ||
|
d1e9cf0144 | ||
|
b51146c868 |
@@ -2,18 +2,12 @@ dist: focal
|
||||
sudo: required
|
||||
language: java
|
||||
jdk:
|
||||
- openjdk11
|
||||
- openjdk17
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.m2/repository
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
install: travis_retry mvn install -DskipTests=true -B -V
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
@@ -22,7 +16,7 @@ jobs:
|
||||
include:
|
||||
- stage: test
|
||||
name: "Build and test"
|
||||
script: travis_retry mvn test -Dtest=ModelAssertionTest
|
||||
script: travis_retry mvn -B -V -ntp test
|
||||
- stage: release
|
||||
name: "Push to Nexus"
|
||||
if: fork = false AND branch = master AND type != pull_request AND commit_message !~ /\[no-release\]/
|
||||
@@ -33,5 +27,5 @@ jobs:
|
||||
- git checkout -B "${TRAVIS_BRANCH}"
|
||||
# Add email to link commits to user
|
||||
- git config user.email "${GIT_EMAIL}"
|
||||
# Skip building of release commits
|
||||
- mvn --batch-mode -DscmCommentPrefix="[maven-release-plugin][skip ci] " -Dusername="${GIT_USERNAME}" -Dpassword="${GIT_PASSWORD}" -DskipTests -Darguments=-DskipTests release:clean release:prepare release:perform
|
||||
# Make release
|
||||
- mvn --batch-mode -ntp -DscmCommentPrefix="[maven-release-plugin][skip ci] " -Dusername="${GIT_USERNAME}" -Dpassword="${GIT_PASSWORD}" -Darguments=-DskipTests release:clean release:prepare release:perform
|
||||
|
@@ -4,7 +4,7 @@
|
||||
<groupId>org.alfresco.tas</groupId>
|
||||
<artifactId>restapi</artifactId>
|
||||
<name>alfresco-tas-restapi</name>
|
||||
<version>1.99</version>
|
||||
<version>1.107</version>
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-super-pom</artifactId>
|
||||
@@ -29,11 +29,8 @@
|
||||
<maven.build.sourceVersion>11</maven.build.sourceVersion>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<tas.utility.version>3.0.49</tas.utility.version>
|
||||
<rest-assured.version>3.3.0</rest-assured.version>
|
||||
<rest-assured.version>5.1.1</rest-assured.version>
|
||||
<httpclient-osgi-version>4.5.6</httpclient-osgi-version>
|
||||
<json-path.version>3.3.0</json-path.version>
|
||||
<xml-path.version>3.3.0</xml-path.version>
|
||||
<json-schema-validator.version>3.3.0</json-schema-validator.version>
|
||||
<jackson-databind.version>2.13.3</jackson-databind.version>
|
||||
<maven-release.version>2.5.3</maven-release.version>
|
||||
<org.glassfish.version>1.1.4</org.glassfish.version>
|
||||
@@ -70,7 +67,7 @@
|
||||
<connection>scm:git:https://github.com/Alfresco/alfresco-tas-restapi.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/Alfresco/alfresco-tas-restapi.git</developerConnection>
|
||||
<url>https://github.com/Alfresco/alfresco-tas-restapi</url>
|
||||
<tag>v1.99</tag>
|
||||
<tag>v1.107</tag>
|
||||
</scm>
|
||||
|
||||
<issueManagement>
|
||||
@@ -264,7 +261,7 @@
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<version>${json-path.version}</version>
|
||||
<version>${rest-assured.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@@ -276,7 +273,7 @@
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>xml-path</artifactId>
|
||||
<version>${xml-path.version}</version>
|
||||
<version>${rest-assured.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@@ -288,7 +285,7 @@
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>json-schema-validator</artifactId>
|
||||
<version>${json-schema-validator.version}</version>
|
||||
<version>${rest-assured.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -350,8 +347,14 @@
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-json</artifactId>
|
||||
<version>3.0.12</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
|
@@ -39,6 +39,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@@ -906,26 +907,17 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
|
||||
}
|
||||
|
||||
/**
|
||||
* Send key=value parameters
|
||||
* All of them will be automatically passed to url.
|
||||
* Example: "maxItems=10000"
|
||||
*
|
||||
* @param parameters
|
||||
* @return
|
||||
* Send key=value parameters.
|
||||
* <p>
|
||||
* Note that this will replace any existing parameters.
|
||||
*
|
||||
* @param parameters A list of URL query parameters - e.g. "maxItems=10000"
|
||||
* @return The RestWrapper
|
||||
*/
|
||||
public RestWrapper withParams(String... parameters)
|
||||
{
|
||||
StringBuilder paramsUrl = new StringBuilder();
|
||||
String delimiter = (parameters.length > 1 ? "&" : "");
|
||||
|
||||
for (int i = 0; i < parameters.length; i++)
|
||||
{
|
||||
paramsUrl.append(parameters[i]);
|
||||
if (i < parameters.length - 1)
|
||||
paramsUrl.append(delimiter);
|
||||
}
|
||||
|
||||
setParameters(paramsUrl.toString());
|
||||
String paramsStr = Arrays.stream(parameters).collect(Collectors.joining("&"));
|
||||
setParameters(paramsStr);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -4,37 +4,35 @@
|
||||
* %%
|
||||
* 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
|
||||
* 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.model;
|
||||
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.rest.core.assertion.ModelAssertion;
|
||||
import org.alfresco.utility.model.TestModel;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Generated by 'Kristian.Dimitrov@hyland.com' on '2022-07-13 15:53' from 'Alfresco Content Services REST API' swagger file
|
||||
* Generated by 'Kristian.Dimitrov@hyland.com' on '2022-07-13 15:53' from 'Alfresco Content Services REST API' swagger file
|
||||
* Generated from 'Alfresco Content Services REST API' swagger file
|
||||
* Base Path {@linkplain /alfresco/api/-default-/public/alfresco/versions/1}
|
||||
*/
|
||||
@@ -43,7 +41,7 @@ public class RestRuleSetModel extends TestModel implements IRestModel<RestRuleSe
|
||||
@Override
|
||||
public ModelAssertion<RestRuleSetModel> assertThat()
|
||||
{
|
||||
return new ModelAssertion<RestRuleSetModel>(this);
|
||||
return new ModelAssertion<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,7 +50,7 @@ public class RestRuleSetModel extends TestModel implements IRestModel<RestRuleSe
|
||||
return assertThat();
|
||||
}
|
||||
|
||||
@JsonProperty(value = "entry")
|
||||
@JsonProperty (value = "entry")
|
||||
RestRuleSetModel model;
|
||||
|
||||
@Override
|
||||
@@ -62,30 +60,14 @@ public class RestRuleSetModel extends TestModel implements IRestModel<RestRuleSe
|
||||
}
|
||||
|
||||
/**
|
||||
Identifier for the rule set
|
||||
*/
|
||||
|
||||
@JsonProperty(required = true)
|
||||
private String id;
|
||||
/**
|
||||
True if the rule set is shared to at least one folder
|
||||
*/
|
||||
|
||||
@JsonProperty(required = true)
|
||||
private boolean shared;
|
||||
/**
|
||||
List of folder identifiers which use the rule set.
|
||||
|
||||
Note that any folders the user does not have access to will not appear in this list. Use **shared** instead to check existence of any link.
|
||||
|
||||
*/
|
||||
|
||||
private List<String> usedBy;
|
||||
/**
|
||||
An ordered list of the rule ids within the rule set
|
||||
*/
|
||||
|
||||
private List<String> ruleIds;
|
||||
* Identifier for the rule set
|
||||
*/
|
||||
@JsonProperty (required = true)
|
||||
private String id;
|
||||
/** The node id of the folder that owns this rule set */
|
||||
private String owningFolder;
|
||||
/** The reason why the rule set is included for the folder. */
|
||||
private String inclusionType;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
@@ -95,36 +77,25 @@ Note that any folders the user does not have access to will not appear in this l
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean getShared()
|
||||
{
|
||||
return this.shared;
|
||||
}
|
||||
|
||||
public void setShared(boolean shared)
|
||||
public String getOwningFolder()
|
||||
{
|
||||
this.shared = shared;
|
||||
}
|
||||
|
||||
public List<String> getUsedBy()
|
||||
{
|
||||
return this.usedBy;
|
||||
return owningFolder;
|
||||
}
|
||||
|
||||
public void setUsedBy(List<String> usedBy)
|
||||
public void setOwningFolder(String owningFolder)
|
||||
{
|
||||
this.usedBy = usedBy;
|
||||
}
|
||||
|
||||
public List<String> getRuleIds()
|
||||
{
|
||||
return this.ruleIds;
|
||||
this.owningFolder = owningFolder;
|
||||
}
|
||||
|
||||
public void setRuleIds(List<String> ruleIds)
|
||||
public String getInclusionType()
|
||||
{
|
||||
this.ruleIds = ruleIds;
|
||||
}
|
||||
return inclusionType;
|
||||
}
|
||||
|
||||
public void setInclusionType(String inclusionType)
|
||||
{
|
||||
this.inclusionType = inclusionType;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,9 @@
|
||||
*/
|
||||
package org.alfresco.rest.requests;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.rest.core.RestWrapper;
|
||||
|
||||
public abstract class ModelRequest<Request>
|
||||
@@ -43,10 +46,26 @@ public abstract class ModelRequest<Request>
|
||||
return (Request) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
/**
|
||||
* Use "include=path" in the URL query.
|
||||
* <p>
|
||||
* Nb. Replaces any existing parameters.
|
||||
*/
|
||||
public Request includePath()
|
||||
{
|
||||
restWrapper.withParams("include=path");
|
||||
return include("path");
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify fields to include in the response.
|
||||
* <p>
|
||||
* Nb. Replaces any existing parameters.
|
||||
*/
|
||||
@SuppressWarnings ("unchecked")
|
||||
public Request include(String... includes)
|
||||
{
|
||||
String includeString = Arrays.stream(includes).collect(Collectors.joining(","));
|
||||
restWrapper.withParams("include=" + includeString);
|
||||
return (Request) this;
|
||||
}
|
||||
}
|
||||
|
@@ -26,13 +26,37 @@
|
||||
|
||||
package org.alfresco.rest.requests;
|
||||
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import io.restassured.http.ContentType;
|
||||
import org.alfresco.rest.core.JsonBodyGenerator;
|
||||
import org.alfresco.rest.core.RestRequest;
|
||||
import org.alfresco.rest.core.RestResponse;
|
||||
import org.alfresco.rest.core.RestWrapper;
|
||||
import org.alfresco.rest.exception.JsonToModelConversionException;
|
||||
import org.alfresco.rest.model.*;
|
||||
import org.alfresco.rest.model.RestActionDefinitionModelsCollection;
|
||||
import org.alfresco.rest.model.RestCommentModel;
|
||||
import org.alfresco.rest.model.RestCommentModelsCollection;
|
||||
import org.alfresco.rest.model.RestNodeAssocTargetModel;
|
||||
import org.alfresco.rest.model.RestNodeAssociationModel;
|
||||
import org.alfresco.rest.model.RestNodeAssociationModelCollection;
|
||||
import org.alfresco.rest.model.RestNodeBodyModel;
|
||||
import org.alfresco.rest.model.RestNodeBodyMoveCopyModel;
|
||||
import org.alfresco.rest.model.RestNodeChildAssocModelCollection;
|
||||
import org.alfresco.rest.model.RestNodeModel;
|
||||
import org.alfresco.rest.model.RestNodeModelsCollection;
|
||||
import org.alfresco.rest.model.RestRatingModel;
|
||||
import org.alfresco.rest.model.RestRatingModelsCollection;
|
||||
import org.alfresco.rest.model.RestRenditionInfoModel;
|
||||
import org.alfresco.rest.model.RestRenditionInfoModelCollection;
|
||||
import org.alfresco.rest.model.RestRuleSetModel;
|
||||
import org.alfresco.rest.model.RestRuleSetModelsCollection;
|
||||
import org.alfresco.rest.model.RestTagModel;
|
||||
import org.alfresco.rest.model.RestTagModelsCollection;
|
||||
import org.alfresco.rest.model.RestVersionModel;
|
||||
import org.alfresco.rest.model.RestVersionModelsCollection;
|
||||
import org.alfresco.rest.model.body.RestNodeLockBodyModel;
|
||||
import org.alfresco.rest.model.builder.NodesBuilder;
|
||||
import org.alfresco.utility.Utility;
|
||||
@@ -41,16 +65,15 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.reporters.Files;
|
||||
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Declares all Rest API under the /nodes path
|
||||
*
|
||||
*/
|
||||
public class Node extends ModelRequest<Node>
|
||||
{
|
||||
private static final String RULE_SETS_URI = "nodes/{nodeId}/rule-sets";
|
||||
private static final String RULE_SET_BY_ID = RULE_SETS_URI + "/{ruleSetId}";
|
||||
|
||||
private RepoTestModel repoModel;
|
||||
|
||||
public Node(RestWrapper restWrapper)
|
||||
@@ -987,4 +1010,41 @@ public class Node extends ModelRequest<Node>
|
||||
.withNodeId(repoModel.getNodeRef())
|
||||
.withRuleSetId(ruleSetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rule sets defined on a folder.
|
||||
*
|
||||
* @return The list of rule sets.
|
||||
*/
|
||||
public RestRuleSetModelsCollection getListOfRuleSets()
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SETS_URI + "?{parameters}",
|
||||
repoModel.getNodeRef(), restWrapper.getParameters());
|
||||
return restWrapper.processModels(RestRuleSetModelsCollection.class, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified rule set from a folder.
|
||||
*
|
||||
* @param ruleSetId The id of the rule set.
|
||||
* @return The specified rule set.
|
||||
*/
|
||||
public RestRuleSetModel getRuleSet(String ruleSetId)
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SET_BY_ID + "?{parameters}",
|
||||
repoModel.getNodeRef(), ruleSetId, restWrapper.getParameters());
|
||||
return restWrapper.processModel(RestRuleSetModel.class, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default rule set from a folder.
|
||||
*
|
||||
* @return The specified rule set.
|
||||
*/
|
||||
public RestRuleSetModel getDefaultRuleSet()
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, RULE_SET_BY_ID + "?{parameters}",
|
||||
repoModel.getNodeRef(), "-default-", restWrapper.getParameters());
|
||||
return restWrapper.processModel(RestRuleSetModel.class, request);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,77 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.core;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/** Unit tests for {@link RestWrapper}. */
|
||||
public class RestWrapperTest
|
||||
{
|
||||
private RestWrapper restWrapper;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp()
|
||||
{
|
||||
restWrapper = new RestWrapper();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithParams_noParams()
|
||||
{
|
||||
restWrapper.withParams();
|
||||
|
||||
assertEquals(restWrapper.getParameters(), "", "Expected empty parameters");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithParams_singleParam()
|
||||
{
|
||||
restWrapper.withParams("param=value");
|
||||
|
||||
assertEquals(restWrapper.getParameters(), "param=value", "Unexpected parameter string");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithParams_multipleParams()
|
||||
{
|
||||
restWrapper.withParams("param1=value1", "param2=value2");
|
||||
|
||||
assertEquals(restWrapper.getParameters(), "param1=value1¶m2=value2", "Unexpected parameter string");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithParams_lastValueWins()
|
||||
{
|
||||
// The first call should be overwritten by the second.
|
||||
restWrapper.withParams("param1=value1");
|
||||
restWrapper.withParams("param2=value2");
|
||||
|
||||
assertEquals(restWrapper.getParameters(), "param2=value2", "Unexpected parameter string");
|
||||
}
|
||||
}
|
@@ -1,128 +0,0 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.demo;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil.DocumentType;
|
||||
import org.alfresco.dataprep.SiteService.Visibility;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.exception.JsonToModelConversionException;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.exception.DataPreparationException;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class RestDemoTests extends RestTest
|
||||
{
|
||||
private UserModel userModel;
|
||||
private SiteModel siteModel;
|
||||
|
||||
@BeforeClass(alwaysRun=true)
|
||||
public void dataPreparation() throws DataPreparationException
|
||||
{
|
||||
userModel = dataUser.getAdminUser();
|
||||
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
|
||||
restClient.authenticateUser(userModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data preparation – create site with custom details <br/>
|
||||
* Perform GET sites call using admin user<br/>
|
||||
* Check that created site is included in response <br/>
|
||||
* Perform GET site call, validate that site title, description and visibility are correct <br/>
|
||||
*
|
||||
* @throws JsonToModelConversionException
|
||||
*/
|
||||
@Test(groups = { "demo" })
|
||||
public void adminRetrievesCorrectSiteDetails() throws JsonToModelConversionException
|
||||
{
|
||||
restClient.withCoreAPI().getSites().assertThat()
|
||||
.entriesListContains("id", siteModel.getId());
|
||||
|
||||
restClient.withCoreAPI().usingSite(siteModel).getSite()
|
||||
.assertThat().field("id").isNotNull()
|
||||
.assertThat().field("description").is(siteModel.getDescription())
|
||||
.assertThat().field("title").is(siteModel.getTitle())
|
||||
.assertThat().field("visibility").is(Visibility.PUBLIC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data preparation – create site and document on server <br/>
|
||||
* POST one comment to file using admin user <br/>
|
||||
* Perform GET comments, check the new one is listed <br/>
|
||||
* Update existing comment using PUT call, check that comment content is updated <br/>
|
||||
*/
|
||||
//Opened DESKTOPAPP-475 for fixing the failing test
|
||||
// @Test(groups = { "demo" })
|
||||
public void adminCanPostAndUpdateComments()
|
||||
{
|
||||
FileModel fileModel = dataContent.usingUser(userModel)
|
||||
.usingResource(FolderModel.getSharedFolderModel())
|
||||
.createContent(DocumentType.TEXT_PLAIN);
|
||||
// add new comment
|
||||
restClient.withCoreAPI().usingResource(fileModel).addComment("This is a new comment");
|
||||
restClient.withCoreAPI().usingResource(fileModel).getNodeComments()
|
||||
.assertThat().entriesListIsNotEmpty().and()
|
||||
.entriesListContains("content", "This is a new comment");
|
||||
}
|
||||
|
||||
/**
|
||||
* Data preparation – create site and a new user <br/>
|
||||
* As admin, add user as Consumer to site as a new site member using POST call <br/>
|
||||
* Update site member role to Manager using PUT call <br/>
|
||||
* Delete site member using DELETE call <br/>
|
||||
*
|
||||
* @throws DataPreparationException
|
||||
* @throws JsonToModelConversionException
|
||||
*/
|
||||
@Test(groups = { "demo" })
|
||||
public void adminCanAddAndUpdateSiteMemberDetails()
|
||||
{
|
||||
UserModel testUser = dataUser.createRandomTestUser("testUser");
|
||||
testUser.setUserRole(UserRole.SiteConsumer);
|
||||
|
||||
// add user as Consumer to site
|
||||
restClient.withCoreAPI().usingSite(siteModel).addPerson(testUser);
|
||||
restClient.withCoreAPI().usingSite(siteModel).getSiteMembers().assertThat().entriesListContains("id", testUser.getUsername())
|
||||
.when().getSiteMember(testUser.getUsername())
|
||||
.assertSiteMemberHasRole(UserRole.SiteConsumer);
|
||||
|
||||
// update site member to Manager
|
||||
testUser.setUserRole(UserRole.SiteCollaborator);
|
||||
restClient.withCoreAPI().usingSite(siteModel).updateSiteMember(testUser);
|
||||
restClient.withCoreAPI().usingSite(siteModel).getSiteMembers().and()
|
||||
.entriesListContains("id", testUser.getUsername())
|
||||
.when().getSiteMember(testUser.getUsername())
|
||||
.assertSiteMemberHasRole(UserRole.SiteCollaborator);
|
||||
|
||||
restClient.withCoreAPI().usingSite(siteModel).deleteSiteMember(testUser);
|
||||
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.demo;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil.DocumentType;
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.exception.JsonToModelConversionException;
|
||||
import org.alfresco.rest.model.RestCommentModel;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
public class SampleCommentsTests extends RestTest
|
||||
{
|
||||
private UserModel userModel;
|
||||
private FolderModel folderModel;
|
||||
private SiteModel siteModel;
|
||||
private FileModel document;
|
||||
|
||||
@BeforeClass(alwaysRun=true)
|
||||
public void dataPreparation()
|
||||
{
|
||||
userModel = dataUser.getAdminUser();
|
||||
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
|
||||
folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
|
||||
restClient.authenticateUser(userModel);
|
||||
document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void admiShouldAddComment() throws JsonToModelConversionException
|
||||
{
|
||||
restClient.withCoreAPI().usingResource(document).addComment("This is a new comment");
|
||||
restClient.assertStatusCodeIs(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void admiShouldRetrieveComments()
|
||||
{
|
||||
restClient.withCoreAPI().usingResource(document).getNodeComments();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldUpdateComment() throws JsonToModelConversionException
|
||||
{
|
||||
RestCommentModel commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment");
|
||||
|
||||
restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Collaborator user")
|
||||
.assertThat().field("content").is("This is the updated comment with Collaborator user");
|
||||
}
|
||||
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.demo;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.utility.exception.DataPreparationException;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
public class SamplePeopleTests extends RestTest
|
||||
{
|
||||
private UserModel userModel;
|
||||
private UserModel adminUser;
|
||||
|
||||
@BeforeClass(alwaysRun=true)
|
||||
public void dataPreparation() throws DataPreparationException
|
||||
{
|
||||
userModel = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20));
|
||||
adminUser = dataUser.getAdminUser();
|
||||
restClient.authenticateUser(adminUser);
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldRetrievePerson()
|
||||
{
|
||||
restClient.withCoreAPI().usingUser(userModel).getPerson().assertThat().field("id").isNotEmpty();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.demo;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.exception.JsonToModelConversionException;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.exception.DataPreparationException;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
public class SampleSitesTests extends RestTest
|
||||
{
|
||||
private UserModel userModel;
|
||||
private SiteModel siteModel;
|
||||
|
||||
@BeforeClass(alwaysRun=true)
|
||||
public void dataPreparation() throws DataPreparationException
|
||||
{
|
||||
userModel = dataUser.getAdminUser();
|
||||
restClient.authenticateUser(userModel);
|
||||
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldGetSiteDetails() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.withCoreAPI().usingSite(siteModel).getSite()
|
||||
.assertThat().field("id").isNotNull();
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldGetSites() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.withCoreAPI().usingSite(siteModel).getSite();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldAccessSites() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.withCoreAPI().getSites().assertThat().entriesListIsNotEmpty();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldAccessResponsePagination() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.withCoreAPI().getSites().assertThat().paginationExist();
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldAddNewSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception
|
||||
{
|
||||
UserModel testUser = dataUser.createRandomTestUser("testUser");
|
||||
testUser.setUserRole(UserRole.SiteConsumer);
|
||||
restClient.withCoreAPI().usingSite(siteModel).addPerson(testUser);
|
||||
restClient.assertStatusCodeIs(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldGetSiteFromSitesList() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.withCoreAPI().getSites().assertThat().entriesListContains("id", siteModel.getId());
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void adminShouldAccessSiteDetails() throws JsonToModelConversionException, Exception
|
||||
{
|
||||
restClient.withCoreAPI().usingSite(siteModel).getSite()
|
||||
.assertThat().field("id").isNotNull()
|
||||
.and().field("description").is(siteModel.getDescription())
|
||||
.and().field("title").is(siteModel.getTitle())
|
||||
.and().field("visibility").is(siteModel.getVisibility());
|
||||
}
|
||||
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.demo.workshop;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class RestApiDemoTests extends RestTest
|
||||
{
|
||||
/*
|
||||
* Test steps:
|
||||
* 1. create a user
|
||||
* 2. create a site
|
||||
* 3. create a second user
|
||||
* 4. add the second user to site with a user role
|
||||
* 5. call rest api call " GET sites/{siteId}/members" with first user authenticated
|
||||
* Expected: the response contains the user added as a member to the site
|
||||
*/
|
||||
@Test(groups = { "demo" })
|
||||
public void verifyGetSiteMembersRestApiCall()
|
||||
{
|
||||
UserModel user = dataUser.createRandomTestUser();
|
||||
SiteModel site = dataSite.usingUser(user).createPublicRandomSite();
|
||||
UserModel member = dataUser.createRandomTestUser();
|
||||
dataUser.usingUser(user).addUserToSite(member, site, UserRole.SiteCollaborator);
|
||||
|
||||
//add here code for step 5
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Test steps:
|
||||
* 1. create a user
|
||||
* 2. create a site
|
||||
* 3. create a second user
|
||||
* 4. add the second user to site with a user role
|
||||
* 5. call rest api call " GET sites/{siteId}/members/{personId}" with first user authenticated
|
||||
* Expected: the response contains the user added as a member to the site
|
||||
*/
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void verifyGetASiteMemberApiCall()
|
||||
{
|
||||
UserModel user = dataUser.createRandomTestUser();
|
||||
SiteModel site = dataSite.usingUser(user).createPublicRandomSite();
|
||||
UserModel member = dataUser.createRandomTestUser();
|
||||
dataUser.usingUser(user).addUserToSite(member, site, UserRole.SiteCollaborator);
|
||||
|
||||
//add here code for step 5
|
||||
}
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.demo.workshop;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* Demo workshop for RestAPI test
|
||||
*
|
||||
*/
|
||||
public class RestApiWorkshopTests extends RestTest
|
||||
{
|
||||
@Test(groups = { "demo" })
|
||||
public void verifyGetSitesRestApiCall()
|
||||
{
|
||||
// creating a random user in repository
|
||||
|
||||
// create a new random site using your UserModel from above
|
||||
|
||||
// using "siteApi", call get "/sites" Rest API and verify created site is present
|
||||
|
||||
// verify status is OK
|
||||
|
||||
}
|
||||
|
||||
@Test(groups = { "demo" })
|
||||
public void verifyGetASiteRestApiCall()
|
||||
{
|
||||
// creating a random user in repository
|
||||
|
||||
// create a new random site using your UserModel from above
|
||||
|
||||
// using "siteApi", call get "/sites/{siteId}" Rest API
|
||||
// using "siteApi", verify created site is present
|
||||
|
||||
// verify status is OK
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* 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.requests;
|
||||
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.MockitoAnnotations.openMocks;
|
||||
|
||||
import org.alfresco.rest.core.RestWrapper;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/** Unit tests for {@link ModelRequest}. */
|
||||
public class ModelRequestTest
|
||||
{
|
||||
/** Abstract class, so test with mock passing through to real methods. */
|
||||
@InjectMocks
|
||||
private ModelRequest<Object> modelRequest = mock(ModelRequest.class, CALLS_REAL_METHODS);
|
||||
@Mock
|
||||
private RestWrapper restWrapperMock;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp()
|
||||
{
|
||||
openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclude_empty()
|
||||
{
|
||||
modelRequest.include();
|
||||
|
||||
then(restWrapperMock).should().withParams("include=");
|
||||
then(restWrapperMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclude_singleInclude()
|
||||
{
|
||||
modelRequest.include("field1");
|
||||
|
||||
then(restWrapperMock).should().withParams("include=field1");
|
||||
then(restWrapperMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInclude_multipleIncludes()
|
||||
{
|
||||
modelRequest.include("field1", "field2", "field3");
|
||||
|
||||
then(restWrapperMock).should().withParams("include=field1,field2,field3");
|
||||
then(restWrapperMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludePath()
|
||||
{
|
||||
modelRequest.includePath();
|
||||
|
||||
then(restWrapperMock).should().withParams("include=path");
|
||||
then(restWrapperMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsingParams()
|
||||
{
|
||||
modelRequest.usingParams("param1=value1", "param2=value2");
|
||||
|
||||
then(restWrapperMock).should().withParams("param1=value1", "param2=value2");
|
||||
then(restWrapperMock).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user