diff --git a/packaging/tests/tas-restapi/.gitignore b/packaging/tests/tas-restapi/.gitignore index a1c2a238a9..ff04b28cf1 100644 --- a/packaging/tests/tas-restapi/.gitignore +++ b/packaging/tests/tas-restapi/.gitignore @@ -1,23 +1,37 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* +*.class + +# Eclipse +.classpath +.settings +.project + +# Intellij +.idea/ +*.iml +*.iws + +# Mac +.DS_Store + +# Maven +target +*.log +*.log.* + +# Mobile Tools for Java (J2ME) + +.mtj +.tmp/ + +# Package Files # + +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml + +hs_err_pid* +alf_data +/src/main/resources/alfresco-global.properties +/src/main/resources/alfresco/extension/custom-log4j.properties diff --git a/packaging/tests/tas-restapi/CODE_OF_CONDUCT.md b/packaging/tests/tas-restapi/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..2ff9dbad09 --- /dev/null +++ b/packaging/tests/tas-restapi/CODE_OF_CONDUCT.md @@ -0,0 +1,13 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. + +Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) \ No newline at end of file diff --git a/packaging/tests/tas-restapi/README.md b/packaging/tests/tas-restapi/README.md index 22e6f186f1..2926638e74 100644 --- a/packaging/tests/tas-restapi/README.md +++ b/packaging/tests/tas-restapi/README.md @@ -1,2 +1,564 @@ -# alfresco-tas-restapi -Common classes for REST APIs TAS tests for ACS projects +![in progress](https://img.shields.io/badge/Document_Level-In_Progress-yellow.svg?style=flat-square) + +Back to [TAS Master Documentation](https://git.alfresco.com/tas/alfresco-tas-utility/wikis/home) + +--- +## Table of Contents +* [Synopsis](#synopsis) +* [Prerequisite](#prerequisite) +* [Installation](#installation-if-you-want-to-contribute) +* [Package Presentation](#package-presentation) +* [Sample Usage](#sample-usage) + * [How to write a test](#how-to-write-a-test) + * [How to generate models or check coverage](#how-to-generate-models-or-check-coverage) + * [How to run tests?](#how-to-run-tests) + * [from IDE](#from-ide) + * [from command line](#from-command-line) +* [Listeners](#listeners) +* [Test Results](#test-results) +* [Test Rail Integration](#test-rail-integration) + * [Configuration](#configuration) + * [How to enable Test Rail Integration?](#how-to-enable-test-rail-integration) +* [Reference](#reference) +* [Change Log](docs/CHANGELOG.md) :glowing_star: +* [Contributors](#contributors) +* [Releasing](#releasing) +* [License](#license) + +## Synopsis + +**TAS**( **T**est **A**utomation **S**ystem)- **RESTAPI** is the project that handles the automated tests related only to [Alfresco REST API](http://docs.alfresco.com/5.1/pra/1/topics/pra-welcome.html). + +It is based on Apache Maven, compatible with major IDEs and is using also Spring capabilities for dependency injection. + +As a high level overview, this project makes use of the following functionality useful in automation testing as: +* reading/defining test environment settings (e.g. alfresco server details, authentication, etc.) +* managing resource (i.e. creating files and folders) +* test data generators (for site, users, content, etc) +* helpers (i.e. randomizers, test environment information) +* test logging generated on runtime and test reporting capabilities +* test management tool integration (at this point we support integration with [Test Rail](https://alfresco.testrail.net) (v5.2.1) +* health checks (verify if server is reachable, if server is online) +* generic Internal-DSL (Domain Specific Language) + +Using Nexus -Release Repository, everyone will be able to use individual interfaces in their projects by extending the automation core functionalities. + +**[Back to Top ^](#table-of-contents)** + +## Prerequisite +(tested on unix/non-unix destribution) +* [Java SE 1.8](http://www.oracle.com/technetwork/java/javase/downloads/index.html). +* [Maven 3.3](https://maven.apache.org/download.cgi) installed and configure according to [Windows OS](https://maven.apache.org/guides/getting-started/windows-prerequisites.html) or [Mac OS](https://maven.apache.org/install.html). +* Configure Maven to use Alfresco alfresco-internal repository following this [Guide](https://ts.alfresco.com/share/page/site/eng/wiki-page?title=Maven_Setup). +* Your favorite IDE as [Eclipse](https://eclipse.org/downloads/) or [InteliJ](https://www.jetbrains.com/idea). +* Access to [Nexus](https://nexus.alfresco.com/nexus/) repository. +* Access to Gitlab [TAS](https://gitlab.alfresco.com/tas/) repository. +* GitLab client for your operating system. (we recommend [SourceTree](https://www.sourcetreeapp.com) - use your google account for initial setup). +* Getting familiar with [Basic Git Commands](http://docs.gitlab.com/ee/gitlab-basics/basic-git-commands.html). +* Getting familiar with [Maven](https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html). +* Getting familiar with [Spring](http://docs.spring.io). +* Getting familiar with [TestNG](http://testng.org/doc/index.html) + +**[Back to Top ^](#table-of-contents)** + +## Installation (if you want to contribute) + +* Open your Gitlab client and clone the repository of this project. +* You can do this also from command line (or in your terminal) adding: + +```bash +$ git clone https://git.alfresco.com/tas/alfresco-tas-restapi-test.git +# this clone will have the latest changes from repository. If you want to checkout a specific version released, take a look at the [Change Log](docs/CHANGELOG.md) page +$ cd alfresco-tas-tester +# this command will checkout the remove v2.0.0 tagged repository and create locally a new branch v2.0.0 +$ git checkout tags/v2.0.0 -b v2.0.0 + +``` + +* Install and check if all dependencies are downloaded + +```bash +> cd alfresco-tas-restapi-test +> mvn clean install -DskipTests +# you should see one [INFO] BUILD SUCCESS message displayed +``` +**[Back to Top ^](#table-of-contents)** + +## Package Presentation + +The project uses a maven layout [archetype](https://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/simple.html): +```ruby +├── pom.xml +├── report.html +├── src +│   ├── main +│   │   └── java +│   │   └── org +│   │   └── alfresco +│   │   └── rest +│   │   ├── core +│   │   │   ├── assertion +│ │ │ │  ├── IModelAssertion.java +│   │   │ │  ├── IModelsCollectionAssertion.java +│   │   │ │  ├── (...) +│   │   │ │  └── PaginationAssertionVerbs.java +│   │   │   ├── swagger +│ │  │  │  ├── Generator.java +│ │  │  │  ├── RestModelProperty.java +│ │  │  │  ├── (...) +│ │  │  │  └── SwaggerYamlParser.java +│   │   │   ├── IRestModel.java +│   │   │   ├── IRestModelsCollection.java +│   │   │   ├── (...) +│   │   │   ├── RestResponse.java +│   │   │   └── RestWrapper.java +│   │   ├── exception +│   │   │   ├── EmptyJsonResponseException.java +│   │   │ ├── EmptyRestModelCollectionException.java +│   │   │ └── JsonToModelConversionException.java +│   │   ├── model +│  │ │ ├── builder   +│   │   │ │  └── NodesBuilder.java +│   │   │ ├── RestActivityModel.java +│   │   │ ├── RestActivityModelsCollection.java +│   │   │ ├── (...) +│   │   │ └── RestVariableModelsCollection.java +│ │ ├── requests +│ │ │ ├── authAPI   +│   │   │ │  └── RestAuthAPI.java +│   │   │ ├── coreAPI +│ │ │ │ └── RestCoreAPI.java +│   │   │ ├── workflowAPI +│ │ │ │ └── RestWorkflowAPI.java +│ │ │ ├── Deployments.java +│   │   │ ├── (...) +│   │   │ └── Tenant.java +│ │ +│   ├── test +│   │   ├── java +│   │   │   └── org +│   │   │   └── alfresco +│   │   │   └── rest +│   │   │   ├── auth +│ │ │ │ └── AuthTests.java +│ │ │ ├── comments +│ │ │ │ ├── AddCommentCoreTests.java +│ │ │ │ ├── (...) +│   │   │   ├── (...) +│ │ │ ├── workflow +│ │ │ │ ├── deployments +│ │ │ │ │ ├── DeleteDeploymentCoreFullTests.java +│ │ │ │ │ ├── (...) +│ │ │ │ ├── processDefinitions +│ │ │ │ │ ├── GetProcessDefinitionCoreTests.java +│ │ │ │ │ ├── (...) +│ │ │ │ ├── (...) +│   │   │   ├── FunctionalCasesTests.java +│   │   │   └── RestTest.java +│   │   └── resources +│   │   ├── alfresco-restapi-context.xml +│   │   ├── default.properties +│   │   └── log4j.properties +``` + +**[Back to Top ^](#table-of-contents)** + +## Sample Usage + +Following the standard layout for Maven projects, the application sources locate in src/main/java and test sources locate in src/test/java. +Application sources consist in defining the REST API object that simulates the calls: get, post, put, delete. +The tests are based on an abstract object: Rest.java that handles the common behavior: checking the health status of the test server, configuration settings, getting the general properties, etc. + +Please take a look at [RestDemoTests.java](src/test/java/org/alfresco/rest/demo/RestDemoTests.java) class for an example. + +Common configuration settings required for this project are stored in properties file, see [default.properties](src/test/resources/default.properties). +Please analyze and update it accordingly with Alfresco test server IP, port, credentials, etc. + +Example: +```java +# Alfresco HTTP Server Settings +alfresco.scheme=http +alfresco.server= +alfresco.port= +``` + +* optional update the logging level in [log4j](src/test/resources/log4j.properties) file (you can increase/decrease the deails of the [logging file](https://logging.apache.org/log4j/1.2/manual.html), setting the ```log4j.rootLogger=DEBUG``` if you want.) +* go to [running](#how-to-run-tests) section for more information on how to run this tests. + +**[Back to Top ^](#table-of-contents)** + +### How to write a test + +* Please also take a look at the [Rest-API desing and implementation](https://ts.alfresco.com/share/page/site/eng/document-details?nodeRef=workspace://SpacesStore/9f7823e7-0597-4435-9fd1-6ec8a4791259) guidelines. +* Tests are organized in java classes and located on src/test/java as per maven layout. +* One test class should contain the tests that cover one functionality as we want to have a clear separation of test scope: tests for sanity/core/full, tests that verify manage of folder/files etc. +* These are the conventions that need to follow when you write a test: + * The test class has @Test annotation with the group defined: rest-api. You can add more groups like sanity, regression + + ```java + @Test(groups={ TestGroup.COMMENTS} + ``` + + * The test has @TestRail annotation in order to assure that the details and results will be submitted on TestRail. The fields for TestRail annotation will be explained on next chapter. + + + ```java + @TestRail(section={TestGroup.REST_API, TestGroup.PEOPLE}, executionType= ExecutionType.SANITY, + description = "Verify admin user gets person with Rest API and response is not empty") + public void adminShouldRetrievePerson() throws Exception + { + peopleAPI.getPerson(userModel.getUsername()) + .assertResponseIsNotEmpty(); + + restClient.assertStatusCodeIs(HttpStatus.OK.toString()); + } + + ``` + + * Use Spring capabilities to initialize the objects(Models, Wrappers) with @Autowired + + * To view a simple class that is using this utility, just browse on [RestDemoTests.java]((src/test/java/org/alfresco/rest/demo/RestDemoTests.java) + Notice the class definition and inheritance value: + + ```java + public class RestDemoTest extends RestTest + ``` + + * as a convention, before running your test, check if the test environment is reachable and your alfresco test server is online. + (this will stop the test if the server defined in your property file is not healthy - method available in parent class) + + ```java + @BeforeClass(alwaysRun = true) + public void setupRestTest() throws Exception{ + serverHealth.assertServerIsOnline(); + } + ``` + * the test name are self explanatory: + + ```java + @TestRail(section={TestGroup.REST_API, TestGroup.SITES}, executionType= ExecutionType.SANITY, + description = "Verify admin user gets sites with Rest API and status code is 200") + public void adminShouldRetrieveSites() throws JsonToModelConversionException, Exception + { + siteAPI.getSites(); + restClient() + .assertStatusCodeIs(HttpStatus.OK.toString()); + } + ``` +* Asserting on imbricated keys: + +Let's say your response is something like: + +```json +{"entry": { + "createdAt": "2017-08-01T12:01:24.979+0000", + "edited": false, + "modifiedBy": { + "firstName": "Administrator" + } +}} +``` + +if you want to assert that firstName is "Administrator" you can do that using the following DSL: + +```java +restClient.onResponse().assertThat().body("entry.modifiedBy.firstName", org.hamcrest.Matchers.is("Administrator")); +``` + +(notice that i'm using Hamcrest Matcher to finalize this assertion) + +**[Back to Top ^](#table-of-contents)** + +### How to generate models or check coverage + +There are some simple generators that could parse [Swagger YAML](http://docs.alfresco.com/community/concepts/alfresco-sdk-tutorials-using-rest-api-explorer.html) files and provide some usefull information to you like: + +a) Show on screen the actual coverage of TAS vs requests that exists in each YAML file - defined in pom.xml) + +```bash +mvn exec:java -Dcoverage +``` +Any missing request are saved under "missing-requests``````.txt" file for further analysis +All current implementation are saved under "implemented-requests``````.txt" +![](docs/pics/coverage.png) + +b) Generate all missing models + +```bash +mvn exec:java -Dmodels +``` + +This command will read all definitions of models from swagger YAML file predefined in pom.xml file. +It will compare with this file pattern: 'Rest``````Model.java', file created under ```/src/main/java/org/alfresco/rest/model``` ignoring the ones that are specified in [ignore-models](src/main/java/org/alfresco/rest/model/ignore-models) file. + +![](docs/pics/models-all.png) + +At this time you you will be prompted to select (based on displayed ID) what models you want to generate (separate each one by comma). +(you can also skip the generation of models from select yaml file or generate all missing models) + + +c) Generate specific models +Maybe you want to generate/regenerate just one model or multiple ones. + +```bash +mvn exec:java -Dmodels=Error,SiteModel +``` + +This command will parse the Swagger YAML file, and will generate the definition of only those specified models, even if those models exist locally (in this case you will be prompted to override that file or not) + +_NOTE_: there are some fields that are marked as ```required``` in swagger file. We also generate those fields with annotation ```@JsonProperty(required = true)``` + +All models are generated based on a [freemarker](http://freemarker.org) template found [here](src/main/resources/rest-model.ftl). + +### How to run tests + +#### from IDE + +* The project can be imported into a development environment tool (Eclipse or IntelliJ). You have the possibility to execute tests or suite of tests using [TestNG plugin](http://testng.org/doc/eclipse.html) previously installed in IDE. + +* In case you are using the default settings that points to localhost (127.0.0.1) and you don't have Alfresco installed on your machine, you will see one exception thrown (as expected): + ```java + org.alfresco.utility.exception.ServerUnreachableException: Server {127.0.0.1} is unreachable. + ``` + +#### from command line + +* In terminal or CMD, navigate (with CD) to root folder of your project (you can use the sample project): + + + + The tests can be executed on command line/terminal using Maven command + + ```bash + mvn test + ``` + + This command with trigger the tests specified in the default testng suite from POM file: src/main/resources/shared-resources/restapi-acs-community-suite.xml + + You can use -Dtest parameter to run the test/suites through command line (http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html). + + You can also specify a different suiteXMLFile like: + + ```bash + mvn test -DsuiteXmlFile=src/resources/your-custom-suite.xml + ``` + + Or even a single test: + + ```bash + mvn test -Dtest=org.alfresco.rest.RestDemoTest + ``` + But pay attention that you will not have enabled all the [listeners](#listeners) in this case (the Reporting listener or TestRail integration one) + +**[Back to Top ^](#table-of-contents)** + +## Listeners + + With the help of Listeners we can modify the behavior of TestNG framework. There are a lot of testNG listener interfaces that we can override in order to provide new functionalities. + The TAS framework provides out of the box a couple of listeners that you could use. These could be enabled and added at the class level or suite level. + +### a) org.alfresco.utility.report.ReportListenerAdapter + + * if added at the class level: + + ```java + @Listeners(value=ReportListenerAdapter.class) + public class MyTestClass extends RestTest + { + (...) + } + ``` + + * or suite xml level + + ```java + + + + + (...) + + ``` + It will automatically generate one html named "report.html" in ./target/report folder. + Please also take a look at [Test Results](#test-results) section. + +### b) org.alfresco.utility.testrail.TestRailExecutorListener + It will automatically update Test Rail application with the test cases that you've automated. + Please take a look at [Test Rail Integration](#test-rail-integration) section for more details. + +### c) org.alfresco.utility.report.log.LogsListener +This is a new listener that will generate further details in one XML format of the automated test steps that you will write. + +Example: + +```java +public void myDSLMethod1() +{ + STEP("Lorem ipsum dolor sit amet"); + //code for first step + + STEP("consectetur adipiscing elit"); + //code for the next description +} + +public void myDSLMethod2() +{ + STEP("sed do eiusmod tempor incididunt ut labore"); + //code for first step + + STEP("et dolore magna aliqua"); + //code for the next description +} +``` + +If these methods will be executed insite a test method, all those steps will be automatically logged in the XML report generated. +Example: + +```java +@Test +public void adminShouldCreateFileInSite() +{ + myDSLMethod1(); + myDSLMethod2() +} +``` + +So if "testingSomething" will be executed this is what you will see on the XML file generated. (please take a look at [Test Results](#test-results) section for defining the defaul location) + +Here is one example of XML file generated with these steps: + +![](docs/pics/xml-steps-report.JPG) + +**[Back to Top ^](#table-of-contents)** + +## Test Results + We already executed a couple of tests using command line as indicated above. Sweet! Please take a look at [rest-suites.xml](src/main/resources/shared-resources/restapi-acs-community-suite.xml) one more time. + You will see there that we have one listener added: + + ```java + + ``` + This will tell our framework, after we run all tests, to generate one HTML report file with graphs and metrics. + + Take a look at the target/reports folder (created after running the tests) and open the report.html file. + + ![](docs/pics/html-report-sample.JPG) + + Playing with this report, you will notice that you will be able to: + * search tests cases by name + * filter test cases by errors, labels, groups, test types, date when it was executed, protocol used, etc. + * view overall pass/fail metrics of current test suite, history of tests execution, etc. + + The report path can be configured in default.properties): + + ``` + # The location of the reports path + reports.path=your-new-location-of-reports + ``` + +**[Back to Top ^](#table-of-contents)** + +## Test Rail Integration + +Alfresco is using now https://alfresco.testrail.net (v5.3.0.3601). + +We aim to accelerate the delivery of automated test by minimizing the interaction with the test management tool - TestRail. In this scope we developed the following capabilities: +* creating automatically the manual tests in TestRail +* submitting the test results (with stack trace) after each execution into TestRail Test Runs +* adding the test steps for each test. + +### Configuration +In order to use Test Rail Integration you will need to add a couple of information in [default.properties](src/test/resources/default.properties) file: +(the document is pretty self explanatory) + +```java +# Example of configuration: +# ------------------------------------------------------ +# testManagement.enabled= +# testManagement.endPoint=https://alfresco.testrail.com/ +# testManagement.username= +# testManagement.apiKey= +# testManagement.project= +# testManagement.rateLimitInSeconds= 1 +# testManagement.testRun= +# testManagement.suiteId= +``` +!This settings are already defined in default.properties for you. + + +For generating a new API Key take a look at the official documentation, TestRail [APIv2](http://docs.gurock.com/testrail-api2) +* _testManagement.project= **_" this represents the name of the Test Run from your project. +* In Test Rail, navigating to Test Runs & Results, create a new Test Run and include all/particular test cases. If this test run name is "Automation", update _testManagement.testRun= **Automation**_. + All test results will be updated only on this test run at runtime as each test is executed by TAS framework. + +### How to enable Test Rail Integration? + +We wanted to simplify the Test Rail integration, so we used listeners in order to enable/disable the integration of Test Rail. +* first configure your default.properties as indicated above + +* now on your TestNG test, add the @TestRail annotation, so let's say you will have this test: + + ```java + @Test(groups="sample-tests") + public void thisAutomatedTestWillBePublishedInTestRail() + { + } + ``` + add now @TestRail integration with mandatory field ```section```. This means that this tests annotated, will be uploaded in TestRail: + + ```java + @Test(groups= TestGroup.REST_API, TestGroup.FULL,) + @TestRail(section = {TestGroup.REST_API, TestGroup.PROCESSES }) + public void thisAutomatedTestWillBePublishedInTestRail() + { + } + ``` + The section field, represents an array of strings, the hierarchy of sections that SHOULD be found on TestRail under the project you've selected in default.properties. Follow the TestRail [user-guide](http://docs.gurock.com/testrail-userguide/start) for more information regarding sections. + In our example we created in Test Rail one root section "restAPI" with a child section: "processes" (you can go further and add multiple section as you wish) + +* now, lets add the listener, the TestRailExecutorListener that will handle this TC Management interaction. + This listener can be added at the class level or suite level (approach that we embrace) + Take a look at [restapi-acs-community-suite.xml](src/main/resources/shared-resources/restapi-acs-community-suite.xml) for further example. + + ```xml + + + (...) + + ``` + + Right click on sanity-suite.xml file and run it, or just "mvn test" from root if this sample project. + After everything passes, go in Test Rail, open your project and navigate to "Test Cases" section. Notice that under restApi/processes section, you will see your test case published. + + If you defined also the "testManagement.testRun" correctly, you will see under Test Runs, the status of this case marked as passed. + + The @TestRail annotation offers also other options like: + - "description" this is the description that will be updated in Test Rail for your test case + - "testType", the default value is set to Functional test + - "executionType", default value is set to ExecutionType.REGRESSION, but you can also use ExecutionType.SMOKE, ExecutionType.SANITY, etc + + Take a look at the demo scenarios in this project for further examples. + +**[Back to Top ^](#table-of-contents)** + +## Reference + +* For any improvements, bugs, please use Jira - [TAS](https://issues.alfresco.com/jira/browse/TAS) project. +* Setup the environment using [docker](https://gitlab.alfresco.com/tas/alfresco-docker-provisioning/blob/master/Readme.md). +* [Bamboo Test Plan](https://bamboo.alfresco.com/bamboo/browse/TAS-RESTAPI) + +## Contributors + +As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other... [more](CODE_OF_CONDUCT.md) + +## Releasing + +Any commit done on this project should be automatically executed by [TAS Build Plan](https://bamboo.alfresco.com/bamboo/browse/TAS-TAS) +If the build passes, then you didn't broke anything. + +If you want to perform a release, open [TAS-RestAPI](https://bamboo.alfresco.com/bamboo/browse/TAS-RESTAPI) Bamboo Build. +Run the Default stage and if it passes, then manually perform the Release stage (this will auto-increment the version in pom.xml) diff --git a/packaging/tests/tas-restapi/TASRegression.cvs b/packaging/tests/tas-restapi/TASRegression.cvs new file mode 100644 index 0000000000..420c9dd84c --- /dev/null +++ b/packaging/tests/tas-restapi/TASRegression.cvs @@ -0,0 +1 @@ +TASRegression,total,totalbugs,sanity,sanitybugs,core,curebugs,full,fullbugs diff --git a/packaging/tests/tas-restapi/docs/pics/coverage.png b/packaging/tests/tas-restapi/docs/pics/coverage.png new file mode 100644 index 0000000000..d611959317 Binary files /dev/null and b/packaging/tests/tas-restapi/docs/pics/coverage.png differ diff --git a/packaging/tests/tas-restapi/docs/pics/html-report-sample.png b/packaging/tests/tas-restapi/docs/pics/html-report-sample.png new file mode 100644 index 0000000000..576422e34f Binary files /dev/null and b/packaging/tests/tas-restapi/docs/pics/html-report-sample.png differ diff --git a/packaging/tests/tas-restapi/docs/pics/models-all.png b/packaging/tests/tas-restapi/docs/pics/models-all.png new file mode 100644 index 0000000000..05e2031d52 Binary files /dev/null and b/packaging/tests/tas-restapi/docs/pics/models-all.png differ diff --git a/packaging/tests/tas-restapi/pom.xml b/packaging/tests/tas-restapi/pom.xml new file mode 100644 index 0000000000..56452ff122 --- /dev/null +++ b/packaging/tests/tas-restapi/pom.xml @@ -0,0 +1,374 @@ + + + 4.0.0 + org.alfresco.tas + restapi + alfresco-tas-restapi + 1.0-SNAPSHOT + + Alfresco Software + http://www.alfresco.com/ + + + + Paul Brodner + + Test Automation Architect + + + + + + src/main/resources/shared-resources/testCount.xml + UTF-8 + 2.0.12 + 3.8.0 + 3.3.0 + 4.5.2 + 3.3.0 + 3.3.0 + 3.3.0 + 2.9.8 + 3.1.1 + 2.5.3 + 1.0.4 + 1.6.0 + 3.8 + 6.5.1 + + + 11 + + + + scm:git:git@github.com:Alfresco/alfresco-tas-restapi.git + scm:git:git@github.com:Alfresco/alfresco-tas-restapi.git + https://github.com/Alfresco/alfresco-tas-restapi + HEAD + + + + JIRA + https://issues.alfresco.com/jira/browse/ + + + + + + alfresco-public-snapshots + https://nexus.alfresco.com/nexus/content/repositories/snapshots/ + + + alfresco-public-releases + https://nexus.alfresco.com/nexus/content/repositories/releases/ + + + + + + + + org.apache.maven.plugins + maven-remote-resources-plugin + ${maven-remote-resources.version} + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + true + true + + + + maven-release-plugin + ${maven-release.version} + + v@{project.version} + + + + org.apache.maven.plugins + maven-jar-plugin + + + package + + test-jar + + + + + + org.apache.maven.plugins + maven-remote-resources-plugin + + + shared-resources/**/* + + + org.alfresco.tas:utility:${tas.utility.version} + + + + + + process + bundle + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + java + + + + + + https://raw.githubusercontent.com/Alfresco/rest-api-explorer/5.2.N/src/main/webapp/definitions/alfresco-auth.yaml + https://raw.githubusercontent.com/Alfresco/rest-api-explorer/5.2.N/src/main/webapp/definitions/alfresco-core.yaml + https://raw.githubusercontent.com/Alfresco/rest-api-explorer/5.2.N/src/main/webapp/definitions/alfresco-discovery.yaml + https://raw.githubusercontent.com/Alfresco/rest-api-explorer/5.2.N/src/main/webapp/definitions/alfresco-search.yaml + https://raw.githubusercontent.com/Alfresco/rest-api-explorer/5.2.N/src/main/webapp/definitions/alfresco-workflow.yaml + + org.alfresco.rest.core.swagger.Generator + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M2 + + + enforce-maven + + enforce + + + + + 3.3 + + + + + + + + + + src/main/resources + + shared-resources/**/* + + + + + + + + + javax.servlet + servlet-api + 2.4 + provided + + + + + org.alfresco.tas + utility + ${tas.utility.version} + + + slf4j-api + org.slf4j + + + commons-lang3 + org.apache.commons + + + commons-lang + commons-lang + + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + + org.apache.httpcomponents + httpclient-osgi + ${httpclient-osgi-version} + + + + io.rest-assured + rest-assured + ${rest-assured.version} + + + + io.rest-assured + json-path + ${json-path.version} + + + commons-lang3 + org.apache.commons + + + + + + io.rest-assured + xml-path + ${xml-path.version} + + + commons-lang3 + org.apache.commons + + + + + + io.rest-assured + json-schema-validator + ${json-schema-validator.version} + + + + com.github.scribejava + scribejava-apis + ${scribejava-apis.version} + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + + + + + org.glassfish + javax.json + ${org.glassfish.version} + + + + + org.slf4j + slf4j-api + 1.7.2 + + + + + io.swagger + swagger-parser + 1.0.23 + + + commons-lang3 + org.apache.commons + + + + + + + org.alfresco + alfresco-insight-jdbc + 1.0.0 + + + org.apache.tika + tika-parsers + + + + + + xerces + xercesImpl + 2.11.0-alfresco-patched-20180402 + + + + + + org.codehaus.groovy + groovy + 2.5.5 + + + + + org.codehaus.groovy + groovy-json + 2.5.5 + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + + dependencies + issue-tracking + scm + + + + + + + + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/NetworkDataPrep.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/NetworkDataPrep.java new file mode 100644 index 0000000000..dfee1c0d5f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/NetworkDataPrep.java @@ -0,0 +1,45 @@ +package org.alfresco.rest; + +import org.alfresco.rest.model.RestNetworkModel; +import org.alfresco.utility.model.UserModel; + +public abstract class NetworkDataPrep extends RestTest +{ + protected static UserModel adminUserModel; + protected static UserModel adminTenantUser, secondAdminTenantUser; + protected static UserModel tenantUser, secondTenantUser, differentNetworkTenantUser; + protected static UserModel tenantUserWithBad; + protected static UserModel userModel; + protected static RestNetworkModel restNetworkModel; + protected static String tenantDomain; + private static boolean isInitialized = false; + + public void init() throws Exception + { + if(!isInitialized) + { + isInitialized = true; + initialization(); + } + } + + public void initialization() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + //create first tenant Admin User. + adminTenantUser = UserModel.getAdminTenantUser(); + restClient.authenticateUser(adminUserModel); + restClient.usingTenant().createTenant(adminTenantUser); + + tenantUser = dataUser.usingUser(adminTenantUser).createUserWithTenant("uTenant"); + secondTenantUser = dataUser.usingUser(adminTenantUser).createUserWithTenant("sTenant"); + //create second tenant Admin User. + secondAdminTenantUser = UserModel.getAdminTenantUser(); + restClient.usingTenant().createTenant(secondAdminTenantUser); + + tenantDomain = tenantUser.getDomain(); + differentNetworkTenantUser = dataUser.usingUser(secondAdminTenantUser).createUserWithTenant("dTenant"); + + userModel = dataUser.createRandomTestUser(); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/RestTest.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/RestTest.java new file mode 100644 index 0000000000..f4104eda88 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/RestTest.java @@ -0,0 +1,85 @@ +package org.alfresco.rest; + +import java.lang.reflect.Method; + +import org.alfresco.dataprep.WorkflowService; +import org.alfresco.rest.core.RestProperties; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.utility.LogFactory; +import org.alfresco.utility.TasProperties; +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataGroup; +import org.alfresco.utility.data.DataLink; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.data.DataUserAIS; +import org.alfresco.utility.data.DataWorkflow; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.network.ServerHealth; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; + +@ContextConfiguration("classpath:alfresco-restapi-context.xml") +public abstract class RestTest extends AbstractTestNGSpringContextTests +{ + private static Logger LOG = LogFactory.getLogger(); + + @Autowired + protected RestProperties restProperties; + + @Autowired + protected TasProperties properties; + + @Autowired + protected ServerHealth serverHealth; + + @Autowired + protected RestWrapper restClient; + + @Autowired + protected DataUserAIS dataUser; + + @Autowired + protected DataSite dataSite; + + @Autowired + protected DataContent dataContent; + + @Autowired + protected DataGroup dataGroup; + + @Autowired + protected DataWorkflow dataWorkflow; + + @Autowired + protected DataLink dataLink; + + @Autowired + protected WorkflowService workflow; + + protected SiteModel testSite; + + @BeforeSuite(alwaysRun = true) + public void checkServerHealth() throws Exception + { + super.springTestContextPrepareTestInstance(); + serverHealth.assertServerIsOnline(); + testSite = dataSite.createPublicRandomSite(); + } + + @BeforeMethod(alwaysRun=true) + public void showStartTestInfo(Method method) + { + LOG.info(String.format("*** STARTING Test: [%s] ***",method.getName())); + } + + @AfterMethod(alwaysRun=true) + public void showEndTestInfo(Method method) + { + LOG.info(String.format("*** ENDING Test: [%s] ***", method.getName())); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/IRestModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/IRestModel.java new file mode 100644 index 0000000000..1e995dc624 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/IRestModel.java @@ -0,0 +1,9 @@ +package org.alfresco.rest.core; + +import org.alfresco.rest.core.assertion.IModelAssertion; + +public interface IRestModel extends IModelAssertion { + + public Model onModel(); + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/IRestModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/IRestModelsCollection.java new file mode 100644 index 0000000000..db507d9327 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/IRestModelsCollection.java @@ -0,0 +1,21 @@ +package org.alfresco.rest.core; + +import java.util.List; + +import org.alfresco.rest.exception.EmptyRestModelCollectionException; +import org.alfresco.rest.model.RestPaginationModel; + +public interface IRestModelsCollection { + + public List getEntries(); + + public Model getOneRandomEntry() throws EmptyRestModelCollectionException; + + /** + * @return boolean value if entry is empty + */ + public boolean isEmpty(); + + public RestPaginationModel getPagination(); + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/JsonBodyGenerator.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/JsonBodyGenerator.java new file mode 100644 index 0000000000..4a7123d571 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/JsonBodyGenerator.java @@ -0,0 +1,268 @@ +package org.alfresco.rest.core; + +import java.util.HashMap; +import java.util.Map; + +import javax.json.Json; +import javax.json.JsonArrayBuilder; +import javax.json.JsonBuilderFactory; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.RepoTestModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; + +/** + * Json builder for small post calls + */ +public class JsonBodyGenerator +{ + private static JsonBuilderFactory jsonBuilder; + + /** + * @return {@link JsonObjectBuilder} + */ + public static JsonObjectBuilder defineJSON() + { + return jsonBuilder().createObjectBuilder(); + } + + /** + * @return {@link JsonArrayBuilder} + */ + public static JsonArrayBuilder defineJSONArray() + { + return jsonBuilder().createArrayBuilder(); + } + /** + * { + * "tag":"test-tag-1" + * } + * + * @param key + * @param value + * @return + */ + public static String keyValueJson(String key, String value) + { + return defineJSON().add(key, value).build().toString(); + } + + /** + * { + * "target": { + * "site": { + * "guid": "abcde-01234" + * } + * } + * } + * + * @param siteModel + * @return + */ + public static String targetSiteWithGuid(SiteModel siteModel) + { + JsonObject value = defineJSON() + .add("target", defineJSON() + .add("site", defineJSON() + .add("guid", siteModel.getGuid()))).build(); + + return value.toString(); + } + + /** + * { + * "target": { + * "file": { + * "guid": "abcde-01234" + * } + * } + * } + * + * @param siteModel + * @return + */ + public static String targetFileWithGuid(FileModel fileModel) + { + JsonObject value = defineJSON() + .add("target", defineJSON() + .add("file", defineJSON() + .add("guid", fileModel.getNodeRef().replace(";1.0", "")))).build(); + return value.toString(); + } + + /** + * { + * "target": { + * "folder": { + * "guid": "abcde-01234" + * } + * } + * } + * + * @param siteModel + * @return + */ + public static String targetFolderWithGuid(FolderModel folderModel) + { + JsonObject value = defineJSON() + .add("target", defineJSON() + .add("folder", defineJSON() + .add("guid", folderModel.getNodeRef()))).build(); + return value.toString(); + } + + /** + * @return the initialized JSON builder + */ + private static JsonBuilderFactory jsonBuilder() + { + if (jsonBuilder == null) + return Json.createBuilderFactory(null); + else + { + return jsonBuilder; + } + } + + public static String likeRating(boolean likeOrNot) + { + JsonObject value = defineJSON() + .add("id", "likes") + .add("myRating", likeOrNot).build(); + return value.toString(); + } + + public static String fiveStarRating(int stars) + { + JsonObject value = defineJSON() + .add("id", "fiveStar") + .add("myRating", stars).build(); + return value.toString(); + } + + + public static String siteMember(UserModel userModel) throws Exception + { + Utility.checkObjectIsInitialized(userModel.getUserRole(), "userModel.getUserRole()"); + JsonObject value = defineJSON() + .add("role", userModel.getUserRole().name()) + .add("id", userModel.getUsername()).build(); + return value.toString(); + } + + public static String siteMemberhipRequest(String message, SiteModel siteModel, String title) + { + JsonObject value = defineJSON() + .add("message", message) + .add("id", siteModel.getId()) + .add("title", title).build(); + return value.toString(); + } + + public static String process(String processDefinitionKey, UserModel assignee, boolean sendEmailNotifications, Priority priority) + { + JsonObject value = defineJSON() + .add("processDefinitionKey", processDefinitionKey) + .add("variables", jsonBuilder().createObjectBuilder() + .add("bpm_assignee", assignee.getUsername()) + .add("bpm_sendEMailNotifications", sendEmailNotifications) + .add("bpm_workflowPriority", priority.getLevel())).build(); + return value.toString(); + } + + public static String processVariable(RestProcessVariableModel variableModel) + { + JsonObject value = defineJSON() + .add("name", variableModel.getName()) + .add("value", variableModel.getValue()) + .add("type", variableModel.getType()).build(); + return value.toString(); + } + + public static String taskVariable(RestVariableModel taskVariableModel) + { + JsonObject value = defineJSON() + .add("scope", taskVariableModel.getScope()) + .add("name", taskVariableModel.getName()) + .add("type", taskVariableModel.getType()) + .add("value", taskVariableModel.getValue().toString()).build(); + return value.toString(); + } + + /** + * { + * "actionDefinitionId": "copy", + * "targetId": "4c4b3c43-f18b-43ff-af84-751f16f1ddfd", + * "params": { + "destination-folder": "34219f79-66fa-4ebf-b371-118598af898c" + * } + * } + * + * @param actionDefinitionId + * @param targetNode + * @param params + * @return + */ + public static String executeActionPostBody(String actionDefinitionId, RepoTestModel targetNode, Map params) + { + JsonObjectBuilder objectBuilder = jsonBuilder().createObjectBuilder(); + for(Map.Entry param : params.entrySet()) + { + objectBuilder.add(param.getKey(), param.getValue()); + } + JsonObject value = defineJSON() + .add("actionDefinitionId", actionDefinitionId) + .add("targetId", targetNode.getNodeRefWithoutVersion()) + .add("params", objectBuilder).build(); + return value.toString(); + } + + /** + * { + * "actionDefinitionId": "check-out", + * "targetId": "4c4b3c43-f18b-43ff-af84-751f16f1ddfd", + * } + * + * @param actionDefinitionId + * @param targetNode + * @return + */ + public static String executeActionPostBody(String actionDefinitionId, RepoTestModel targetNode) + { + JsonObject value = defineJSON() + .add("actionDefinitionId", actionDefinitionId) + .add("targetId", targetNode.getNodeRefWithoutVersion()) + .build(); + return value.toString(); + } + + /** + * { + * "key1":"key1", + * "key2":"key2", + * "key3":"key3" + * } + * + * @param key + * @param value + * @return + */ + public static String keyValueJson(HashMap mapJson) + { + JsonObjectBuilder builder= defineJSON(); + + for (Map.Entry entry : mapJson.entrySet()) + { + builder.add(entry.getKey().toString(), entry.getValue().toString()); + } + return builder.build().toString(); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestAisAuthentication.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestAisAuthentication.java new file mode 100644 index 0000000000..7014c5719d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestAisAuthentication.java @@ -0,0 +1,83 @@ +package org.alfresco.rest.core; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.utility.data.AisToken; +import org.alfresco.utility.data.auth.DataAIS; +import org.alfresco.utility.model.UserModel; +import org.keycloak.authorization.client.util.HttpResponseException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class RestAisAuthentication +{ + public static String STEP_PREFIX = "RestAisAuthProvider:"; + public static String USER_DISABLED_MSG = "Account disabled"; + + @Autowired + private DataAIS dataAIS; + + /** + * + * Get the AIS access token for the specified user model. + * + * @param userModel + * @return + */ + public String getAisAuthenticationToken(UserModel userModel) + { + STEP(String.format("%s Retrieving AIS authentication.", STEP_PREFIX)); + AisToken aisToken = getAisAccessToken(userModel); + + return aisToken.getToken(); + } + + /** + * Check if the Alfresco Identity Service is enabled + * @return True if Alfresco Identity Service is enabled (the identity service URL is not null or empty) + */ + public Boolean isAisAuthenticationEnabled() + { + return dataAIS.isEnabled() ? true : false; + } + + /** + * Returns a valid access token for valid user credentials in userModel. An + * invalid access token is returned for invalid user credentials, which can + * be used for tests involving non existing or unauthorized users. + * + * @param userModel + * @return + */ + private AisToken getAisAccessToken(UserModel userModel) + { + String badToken = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJUazFPZ2JqVlo1UEw2bmtsNWFvTUlacTZ4cW9PZzc5WGtzdnJTTUcxLUFZIn0.eyJqdGkiOiI3NTVkMGZiOS03NzI5LTQ1NzYtYWM4Ny1hZWZjZWNiZDE0ZGEiLCJleHAiOjE1NTM2MjQ1NDgsIm5iZiI6MCwiaWF0IjoxNTUzNjI0MjQ4LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0L2F1dGgvcmVhbG1zL2FsZnJlc2NvIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6Ijk4NDE0Njg4LTUwMDUtNDVmOS05YTVjLTlkMDRlODMyYTNkMiIsInR5cCI6IkJlYXJlciIsImF6cCI6ImFsZnJlc2NvIiwiYXV0aF90aW1lIjowLCJzZXNzaW9uX3N0YXRlIjoiNjJlN2U5YzktZmFlNS00N2RhLTk5MDItMTZjYTJhZWUwMWMwIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwOi8vbG9jYWxob3N0KiIsImh0dHBzOi8vbG9jYWxob3N0KiJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoicHJvZmlsZSBlbWFpbCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoidXNlci12eGlrcXd3cG5jYmpzeHgifQ.PeLGCNCzj-P2m0knwUU9Vfx4dzLLQER9IdV7GyLel9LRN-3J9nh7GBDRQsyDJ0pqhObQyMg4V3wSsrsXRQ6gKhmUyDemmD-w1YMC2a2HKX6GlxsTEF_f1K_R15lIQOawNVErlWjZWORJGCvCYZOJ99SOmeOC6PGY79zLL94MMnf6dXcegePPMOKG-59eNjBkOylTipYebvM40nbbKrS5vzNHQlvUh4ALFeBoMSKGnLSjQd06Dj4SWojG0p1BrxurqDjW0zz6pQlEAm4vcWApRZ6qBLZcMH8adYix07zCDb87GOn1pmfEBWpwd3BEgC_LLu06guaCPHC9tpeIaDTHLg"; + String badRefreshToken = "eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJmM2YyMjhjYS1jMzg5LTQ5MGUtOGU1Zi02YWI1MmJhZDVjZGEifQ.eyJqdGkiOiIyNmExZWNhYy00Zjk0LTQwYzctYjJjNS04NTlhZmQ3NjBiYWMiLCJleHAiOjE1NTM2MjYwNDgsIm5iZiI6MCwiaWF0IjoxNTUzNjI0MjQ4LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0L2F1dGgvcmVhbG1zL2FsZnJlc2NvIiwiYXVkIjoiaHR0cDovL2xvY2FsaG9zdC9hdXRoL3JlYWxtcy9hbGZyZXNjbyIsInN1YiI6Ijk4NDE0Njg4LTUwMDUtNDVmOS05YTVjLTlkMDRlODMyYTNkMiIsInR5cCI6IlJlZnJlc2giLCJhenAiOiJhbGZyZXNjbyIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjYyZTdlOWM5LWZhZTUtNDdkYS05OTAyLTE2Y2EyYWVlMDFjMCIsInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJwcm9maWxlIGVtYWlsIn0.lRBJQc7tj0rk7JBC0zpM0dDdZgDKjm9wcxP8nzLnXe4"; + + AisToken aisToken; + try + { + // Attempt to get an access token for userModel from AIS + aisToken = dataAIS.perform().getAccessToken(userModel); + } + catch (HttpResponseException e) + { + // Trying to authenticate with invalid user credentials or disabled + // user so return an invalid access token + String httpResponse = new String(e.getBytes()); + if (e.getStatusCode() == 401 || httpResponse.contains(USER_DISABLED_MSG)) + { + STEP(String.format("%s User disabled or invalid user credentials were provided %s:%s. Using invalid token for request.", STEP_PREFIX, + userModel.getUsername(), userModel.getPassword())); + aisToken = new AisToken(badToken, badRefreshToken, System.currentTimeMillis(), 300000); + } + else + { + throw e; + } + } + return aisToken; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestModels.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestModels.java new file mode 100644 index 0000000000..0df16ed1ed --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestModels.java @@ -0,0 +1,137 @@ +package org.alfresco.rest.core; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; +import java.util.Random; + +import org.alfresco.rest.core.assertion.IModelsCollectionAssertion; +import org.alfresco.rest.core.assertion.ModelsCollectionAssertion; +import org.alfresco.rest.exception.EmptyRestModelCollectionException; +import org.alfresco.rest.model.RestPaginationModel; +import org.alfresco.rest.model.RestSiteModelsCollection; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Map multiple entries of JSON response to a class + * + * Example: + * + * "entries": [ + { + "entry": { + "visibility": "PUBLIC", + "guid": "79e140e1-5039-4efa-acaf-c22b5ba7c947", + "description": "Description1470255221170", + "id": "0-C2291-1470255221170", + "title": "0-C2291-1470255221170" + } + }, + * + * Having this JSON Entry, we can auto-map this to {@link RestSiteModelsCollection} class having a List of based on this example + * + * @author Paul Brodner + */ +public abstract class RestModels implements IRestModelsCollection, IModelsCollectionAssertion +{ + @JsonProperty(value = "entries") + private List modelEntries; + + private RestPaginationModel pagination; + + @Override + public List getEntries() + { + return modelEntries; + } + + /** + * @return a random entry from entries list + * @throws EmptyRestModelCollectionException + */ + @Override + public Model getOneRandomEntry() throws EmptyRestModelCollectionException + { + STEP("REST API: Get random one entry from response"); + Random random = new Random(); + List models = getEntries(); + if(models.isEmpty()) + throw new EmptyRestModelCollectionException(models); + + int index = random.nextInt(models.size()); + return models.get(index); + } + + /** + * Example + * + * siteMembershipRequests.getEntryByIndex(0) + .assertThat().field("site.visibility").is(moderatedSite.getVisibility()) + .assertThat().field("site.description").is(moderatedSite.getDescription()) + .assertThat().field("site.id").is(moderatedSite.getId()) + .assertThat().field("site.title").is(moderatedSite.getTitle()); + * + * @param index + * @return + * @throws EmptyRestModelCollectionException + */ + @SuppressWarnings("unchecked") + public Model getEntryByIndex(int index) throws EmptyRestModelCollectionException{ + STEP("REST API: Get index entry from response"); + + List models = getEntries(); + if(models.isEmpty()) + throw new EmptyRestModelCollectionException(models); + + if(models.size() > index){ + return (Model) ((IRestModel)models.get(index)).onModel(); + } + + return null; + } + + @Override + public ModelsCollectionAssertion> assertThat() + { + return new ModelsCollectionAssertion>(this); + } + + @Override + public ModelsCollectionAssertion> and() + { + return assertThat(); + } + + @SuppressWarnings("unchecked") + @Override + public ModelCollection when() + { + return (ModelCollection)this; + } + + /** + * @return boolean value if entry is empty + */ + @Override + public boolean isEmpty() + { + if (getEntries() != null) + return getEntries().isEmpty(); + else + return true; + } + + @Override + public RestPaginationModel getPagination() + { + return pagination; + } + + public void setPagination(RestPaginationModel pagination) + { + this.pagination = pagination; + } + + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestProperties.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestProperties.java new file mode 100644 index 0000000000..af5b31bc55 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestProperties.java @@ -0,0 +1,20 @@ +package org.alfresco.rest.core; + +import org.alfresco.utility.TasProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@PropertySource("classpath:default.properties") +@PropertySource(value = "classpath:${environment}.properties", ignoreResourceNotFound = true) +public class RestProperties +{ + @Autowired + private TasProperties properties; + + public TasProperties envProperty() + { + return properties; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestRequest.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestRequest.java new file mode 100644 index 0000000000..664b155ac9 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestRequest.java @@ -0,0 +1,146 @@ +package org.alfresco.rest.core; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.springframework.http.HttpMethod; + +import io.restassured.RestAssured; + +/** + * @author Paul Brodner + */ +public class RestRequest +{ + private String body = ""; + private HttpMethod httpMethod; + private String path; + private Object[] pathParams; + private String contentType = "UTF-8"; + + private RestRequest(HttpMethod httpMethod, String path, String... pathParams) + { + setHttpMethod(httpMethod); + setPath(path); + setPathParams(pathParams); + STEP(toString()); + } + + private RestRequest(HttpMethod httpMethod, String body, String path, String... pathParams) + { + setHttpMethod(httpMethod); + setPath(path); + setPathParams(pathParams); + setBody(body); + STEP(toString()); + } + + /** + * Use this request when no body is needed + * + * @param httpMethod + * @param path + * @param pathParams + * @return + */ + public static RestRequest simpleRequest(HttpMethod httpMethod, String path, String... pathParams) + { + return new RestRequest(httpMethod, path, pathParams); + } + + /** + * Use this request when a body has to be provided + * + * @param httpMethod + * @param body + * @param path + * @param pathParams + * @return + */ + public static RestRequest requestWithBody(HttpMethod httpMethod, String body, String path, String... pathParams) + { + return new RestRequest(httpMethod, body, path, pathParams); + } + + public String getBody() + { + return body; + } + + public void setBody(String body) + { + this.body = body; + } + + public HttpMethod getHttpMethod() + { + return httpMethod; + } + + public void setHttpMethod(HttpMethod httpMethod) + { + this.httpMethod = httpMethod; + } + + public String getPath() + { + return path; + } + + public void setPath(String path) + { + this.path = path; + } + + public Object[] getPathParams() + { + return pathParams; + } + + public void setPathParams(Object[] pathParams) + { + this.pathParams = pathParams; + } + + public String getContentType() + { + return contentType; + } + + public void setContentType(String contentType) + { + this.contentType = contentType; + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder() + .append("Request: ") + .append(getHttpMethod()) + .append(" ") + .append(RestAssured.baseURI) + .append(":") + .append(RestAssured.port) + .append("/") + .append(RestAssured.basePath) + .append("/"); + + String getPathFormatted = getPath(); + if(getPath().contains("{")) + { + getPathFormatted = getPath().replaceAll("\\{.*?}", "%s"); + getPathFormatted = String.format(getPathFormatted, getPathParams()); + } + sb.append(getPathFormatted); + + if(!getBody().isEmpty()) + { + sb.append("\nbody:") + .append(getBody()); + } + sb.append("\n"); + + + return sb.toString(); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestResponse.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestResponse.java new file mode 100644 index 0000000000..be97586380 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestResponse.java @@ -0,0 +1,46 @@ +package org.alfresco.rest.core; + +import io.restassured.response.Response; +import io.restassured.response.ValidatableResponse; + +/** + * Defines a Rest Response + * + * @author Paul Brodner + */ +public class RestResponse +{ + private Response response; + + public RestResponse(Response response) + { + this.setResponse(response); + } + + public String getStatusCode() + { + return String.valueOf(response.getStatusCode()); + } + + public Response getResponse() + { + return response; + } + + public void setResponse(Response response) + { + this.response = response; + } + + public T toModel(Class classz) + { + return response.as(classz); + + } + + public ValidatableResponse assertThat() + { + return response.then(); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestWrapper.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestWrapper.java new file mode 100644 index 0000000000..a92edb9cdb --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/RestWrapper.java @@ -0,0 +1,1112 @@ +package org.alfresco.rest.core; + +import static io.restassured.RestAssured.basic; +import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.oauth2; +import static org.alfresco.utility.report.log.Step.STEP; + +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.alfresco.rest.exception.EmptyJsonResponseException; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestHtmlResponse; +import org.alfresco.rest.model.RestSiteContainerModelsCollection; +import org.alfresco.rest.model.RestSiteMemberModelsCollection; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.alfresco.rest.model.RestSyncSetRequestModel; +import org.alfresco.rest.model.RestTextResponse; +import org.alfresco.rest.requests.AdminConsole; +import org.alfresco.rest.requests.Tenant; +import org.alfresco.rest.requests.aosAPI.RestAosAPI; +import org.alfresco.rest.requests.authAPI.RestAuthAPI; +import org.alfresco.rest.requests.cmisAPI.RestCmisAPI; +import org.alfresco.rest.requests.coreAPI.RestCoreAPI; +import org.alfresco.rest.requests.discoveryAPI.RestDiscoveryAPI; +import org.alfresco.rest.requests.privateAPI.RestPrivateAPI; +import org.alfresco.rest.requests.search.SearchAPI; +import org.alfresco.rest.requests.search.SearchSQLAPI; +import org.alfresco.rest.requests.search.SearchSQLJDBC; +import org.alfresco.rest.requests.search.ShardInfoAPI; +import org.alfresco.rest.requests.search.SolrAPI; +import org.alfresco.rest.requests.workflowAPI.RestWorkflowAPI; +import org.alfresco.utility.LogFactory; +import org.alfresco.utility.Utility; +import org.alfresco.utility.dsl.DSLWrapper; +import org.alfresco.utility.model.StatusModel; +import org.alfresco.utility.model.TestModel; +import org.alfresco.utility.model.UserModel; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.XMLSerializer; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.testng.Assert; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.restassured.RestAssured; +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.http.ContentType; +import io.restassured.parsing.Parser; +import io.restassured.http.Headers; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; + +@SuppressWarnings("deprecation") +@Service +@Scope(value = "prototype") +public class RestWrapper extends DSLWrapper +{ + private static final Integer IGNORE_CONTENT_LIMIT_BYTES = 4 * 1024 * 1024; + + @Autowired + protected RestProperties restProperties; + + private Logger LOG = LogFactory.getLogger(); + + private RequestSpecification request; + private RestErrorModel lastError; + private StatusModel lastStatusModel; + private Object lastException = ""; // handle values of last exception thrown + private UserModel currentUser; + private String statusCode; + private String parameters = ""; + private ContentType defaultContentType = ContentType.JSON; + private RequestSpecBuilder requestSpecBuilder = new RequestSpecBuilder(); + private Headers responseHeaders; + private RestResponse response; + + @Autowired + private RestAisAuthentication aisAuthentication; + + public void setResponseHeaders(Headers responseHeaders) + { + this.responseHeaders = responseHeaders; + } + + public Headers getResponseHeaders() + { + return responseHeaders; + } + + /** + * Verify response header contains a specific value + * Example: + * assertHeaderValueContains("Content-Disposition", "filename=\"myfile.txt\""); + * + * @param headerName the header name from response + * @param expectedHeaderValue the header property value to be checked + * @return + */ + public RestWrapper assertHeaderValueContains(String headerName, String expectedHeaderValue) + { + STEP(String.format("REST API: Assert that header value contains %s", expectedHeaderValue)); + String actualHeaderValue = getResponseHeaders().getValue(headerName); + Assert.assertTrue(getResponseHeaders().getValue(headerName).contains(expectedHeaderValue), + String.format("Header %s is %s", headerName, actualHeaderValue)); + return this; + } + + @PostConstruct + public void initializeRequestSpecBuilder() + { + requestSpecBuilder = new RequestSpecBuilder(); + RestAssured.baseURI = restProperties.envProperty().getTestServerUrl(); + RestAssured.port = restProperties.envProperty().getPort(); + configureRequestSpec().setBaseUri(restProperties.envProperty().getTestServerUrl()); + configureRequestSpec().setPort(restProperties.envProperty().getPort()); + } + + /** + * Authenticate specific user to Alfresco REST API + * + * @param userModel + * @return + */ + public RestWrapper authenticateUser(UserModel userModel) + { + STEP(String.format("REST API: Basic Authentication using user {%s}", userModel.toString())); + currentUser = userModel; + setTestUser(userModel); + return this; + } + + public RestWrapper noAuthentication() + { + STEP("REST API: No Authentication"); + currentUser = null; + setTestUser(null); + return this; + } + + /** + * Request sent to server + */ + protected RequestSpecification onRequest() + { + if (currentUser != null) + { + if(aisAuthentication.isAisAuthenticationEnabled()) + { + configureRequestSpec().setAuth(oauth2(aisAuthentication.getAisAuthenticationToken(currentUser))); + } + else + { + configureRequestSpec().setAuth(basic(currentUser.getUsername(), currentUser.getPassword())); + } + } + + request = given().spec(configureRequestSpec().build()); + + // reset to default as JSON + usingContentType(ContentType.JSON); + return request; + } + + /** + * @return the last error model thrown if any + */ + private RestErrorModel getLastError() + { + if (lastError == null) + return new RestErrorModel(); + else + return lastError; + } + + public void setLastError(RestErrorModel errorModel) + { + lastError = errorModel; + } + + public RestErrorModel assertLastError() + { + + return getLastError(); + } + + public StatusModel assertLastStatus() + { + return getLastStatus(); + } + + public RestWrapper assertLastExceptionContains(String exception) + { + if (!lastException.toString().contains(exception)) + Assert.fail(String.format("Expected exception {%s} but found {%s}", exception, lastException)); + + return this; + } + + /** + * Process responses for a collection of models as {@link RestSiteModelsCollection} + * + * @throws JsonToModelConversionException If the response cannot be converted to the given model. + * @throws EmptyJsonResponseException If there is no response from the server. + */ + + public T processModels(Class classz, RestRequest restRequest) + throws EmptyJsonResponseException, JsonToModelConversionException + { + Response returnedResponse = sendRequest(restRequest); + + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + boolean responseHasErrors = checkForJsonError(returnedResponse); + boolean responseHasExceptions = checkForJsonStatusException(returnedResponse); + + T models = null; + + if (!responseHasExceptions && !responseHasErrors) + { + try + { + models = returnedResponse.jsonPath().getObject("list", classz); + validateJsonModelSchema(classz, models); + } + catch (Exception processError) + { + processError.printStackTrace(); + throw new JsonToModelConversionException(classz, processError); + } + } + + if (models == null) + { + try + { + return classz.getDeclaredConstructor().newInstance(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + return models; + } + + /** + * Process responses for a single model as {@link RestSiteModel} + * + * @throws JsonToModelConversionException If the response cannot be converted to the given model. + * @throws EmptyJsonResponseException If there is no response from the server. + */ + public T processModel(Class classz, RestRequest restRequest) + throws EmptyJsonResponseException, JsonToModelConversionException + { + Response returnedResponse = sendRequest(restRequest); + + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + boolean responseHasErrors = checkForJsonError(returnedResponse); + boolean responseHasExceptions = checkForJsonStatusException(returnedResponse); + + T model = null; + + try + { + if (!responseHasExceptions && !responseHasErrors) + { + model = returnedResponse.jsonPath().getObject("entry", classz); + validateJsonModelSchema(classz, model); + } + } + catch (Exception processError) + { + throw new JsonToModelConversionException(classz, processError); + } + if (model == null) + { + try + { + return classz.newInstance(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + return model; + } + + /** + * Process responses for a single model as {@link RestSiteModel} + * + * @throws JsonToModelConversionException If the response cannot be converted to the given model. + * @throws EmptyJsonResponseException If there is no response from the server. + */ + public JSONObject processJson(RestRequest restRequest) + throws EmptyJsonResponseException, JsonToModelConversionException + { + Response returnedResponse = sendRequest(restRequest); + + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + boolean responseHasErrors = checkForJsonError(returnedResponse); + boolean responseHasExceptions = checkForJsonStatusException(returnedResponse); + + JSONObject response = null; + + try + { + if (!responseHasExceptions && !responseHasErrors) + { + JSONObject jsonObject = new JSONObject(returnedResponse.getBody().asString()); + response = jsonObject.getJSONObject("entry"); + } + } + catch (Exception processError) + { + throw new EmptyJsonResponseException(processError.getMessage()); + } + + return response; + } + + /** + * Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection} + * + * @throws Exception + */ + public List processRelationsJson(RestRequest restRequest) throws Exception + { + List jsonObjects = new ArrayList(); + Response returnedResponse = sendRequest(restRequest); + + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + boolean responseHasErrors = checkForJsonError(returnedResponse); + boolean responseHasExceptions = checkForJsonStatusException(returnedResponse); + + ObjectMapper mapper = new ObjectMapper(); + JSONObject response = null; + + try + { + if (!responseHasExceptions && !responseHasErrors) + { + JSONObject jsonObject = new JSONObject(returnedResponse.getBody().asString()); + + response = jsonObject.getJSONObject("entry"); + RestSiteModel site = mapper.readValue(response.toString(), RestSiteModel.class); + jsonObjects.add(site); + + if (!jsonObject.getJSONObject("relations").isNull("containers")) + { + response = jsonObject.getJSONObject("relations").getJSONObject("containers").getJSONObject("list"); + RestSiteContainerModelsCollection containers = mapper.readValue(response.toString(), + RestSiteContainerModelsCollection.class); + jsonObjects.add(containers); + } + + if (!jsonObject.getJSONObject("relations").isNull("members")) + { + response = jsonObject.getJSONObject("relations").getJSONObject("members").getJSONObject("list"); + RestSiteMemberModelsCollection members = mapper.readValue(response.toString(), + RestSiteMemberModelsCollection.class); + jsonObjects.add(members); + } + } + } + catch (Exception processError) + { + throw new EmptyJsonResponseException(processError.getMessage()); + } + + return jsonObjects; + } + + /** + * Process responses for site relations models, such as {@link RestSiteModel, RestSiteContainerModelsCollection, RestSiteMemberModelsCollection} + * + * @throws Exception + */ + public List> processSitesRelationsJson(RestRequest restRequest) throws Exception + { + List> allObjects = new ArrayList>(); + List sitesList = new ArrayList(); + List containersList = new ArrayList(); + List membersList = new ArrayList(); + + Response returnedResponse = sendRequest(restRequest); + + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + boolean responseHasErrors = checkForJsonError(returnedResponse); + boolean responseHasExceptions = checkForJsonStatusException(returnedResponse); + + ObjectMapper mapper = new ObjectMapper(); + JSONObject response = null; + + try + { + if (!responseHasExceptions && !responseHasErrors) + { + JSONObject jsonObject = new JSONObject(returnedResponse.getBody().asString()); + + if (jsonObject.getJSONObject("list").getJSONArray("entries").length() != 0) + { + { + for (int i = 0; i < jsonObject.getJSONObject("list").getJSONArray("entries").length(); i++) + { + response = jsonObject.getJSONObject("list").getJSONArray("entries").getJSONObject(i) + .getJSONObject("entry"); + RestSiteModel site = mapper.readValue(response.toString(), RestSiteModel.class); + sitesList.add(site); + } + + allObjects.add(sitesList); + } + + if (jsonObject.toString().contains("containers")) + { + for (int i = 0; i < jsonObject.getJSONObject("list").getJSONArray("entries").length(); i++) + { + response = jsonObject.getJSONObject("list").getJSONArray("entries").getJSONObject(i) + .getJSONObject("relations").getJSONObject("containers").getJSONObject("list"); + RestSiteContainerModelsCollection containers = mapper.readValue(response.toString(), + RestSiteContainerModelsCollection.class); + containersList.add(containers); + } + + allObjects.add(containersList); + } + + if (jsonObject.toString().contains("members")) + { + for (int i = 0; i < jsonObject.getJSONObject("list").getJSONArray("entries").length(); i++) + { + response = jsonObject.getJSONObject("list").getJSONArray("entries").getJSONObject(i) + .getJSONObject("relations").getJSONObject("members").getJSONObject("list"); + RestSiteMemberModelsCollection members = mapper.readValue(response.toString(), + RestSiteMemberModelsCollection.class); + membersList.add(members); + } + + allObjects.add(membersList); + } + } + } + } + catch (Exception processError) + { + throw new EmptyJsonResponseException(processError.getMessage()); + } + + return allObjects; + } + + /** + * Process a response that returns a html + * + * @param restRequest + * @return + * @throws EmptyJsonResponseException If there is no response from the server. + */ + public RestHtmlResponse processHtmlResponse(RestRequest restRequest) throws EmptyJsonResponseException + { + Response returnedResponse = sendRequest(restRequest); + + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + if (returnedResponse.contentType().contains("json")) + { + checkForJsonError(returnedResponse); + checkForJsonStatusException(returnedResponse); + } + + return new RestHtmlResponse(returnedResponse.getHeaders(), returnedResponse.getBody()); + } + + /** + * Generic REST API call on a {@link RestRequest} + * + * @param restRequest + * @return + */ + public RestResponse process(RestRequest restRequest) + { + Response returnedResponse = sendRequest(restRequest); + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + RestResponse response = new RestResponse(returnedResponse); + setResponseHeaders(response.getResponse().getHeaders()); + return response; + } + + public RestTextResponse processTextResponse(RestRequest restRequest) + { + Response returnedResponse = sendRequest(restRequest); + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + if (returnedResponse.contentType().contains("text/plain")) + { + RestAssured.registerParser("text/plain", Parser.TEXT); + + RestTextResponse testResponse = new RestTextResponse(returnedResponse); + return testResponse; + } + + RestResponse response = new RestResponse(returnedResponse); + setResponseHeaders(response.getResponse().getHeaders()); + RestTextResponse testResponse = new RestTextResponse(returnedResponse); + return testResponse; + } + + /** + * Process a response that has no body - basically will need only the status code from it + * + * @param restRequest + * @throws EmptyJsonResponseException + */ + public void processEmptyModel(RestRequest restRequest) throws EmptyJsonResponseException + { + Response returnedResponse = sendRequest(restRequest); + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + if (!returnedResponse.asString().isEmpty()) + { + checkForJsonError(returnedResponse); + checkForJsonStatusException(returnedResponse); + } + + } + + public StatusModel getLastStatus() + { + return lastStatusModel; + } + + /** + * Set the status code for the latest REST call + * + * @param lastStatusModel + */ + public void setLastStatus(StatusModel lastStatusModel) + { + this.lastStatusModel = lastStatusModel; + } + + public String getStatusCode() + { + return statusCode; + } + + public void setStatusCode(String statusCode) + { + this.statusCode = statusCode; + } + + /** + * Send REST request based on HTTP method + * + * @param restRequest + * @return + */ + protected Response sendRequest(RestRequest restRequest) + { + Response returnedResponse = null; + switch (restRequest.getHttpMethod()) + { + case GET: + returnedResponse = onRequest().get(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + case DELETE: + returnedResponse = onRequest().delete(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + + case HEAD: + returnedResponse = onRequest().head(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + case OPTIONS: + returnedResponse = onRequest().options(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + case POST: + returnedResponse = onRequest().body(restRequest.getBody()) + .post(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + case PUT: + returnedResponse = onRequest().body(restRequest.getBody()) + .contentType(ContentType.JSON.withCharset(restRequest.getContentType())) + .put(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + case TRACE: + returnedResponse = onRequest().get(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + default: + returnedResponse = onRequest().get(restRequest.getPath(), restRequest.getPathParams()).andReturn(); + break; + } + + logResponseInformation(restRequest, returnedResponse); + + initializeRequestSpecBuilder(); + response = new RestResponse(returnedResponse); + return returnedResponse; + } + + private void logResponseInformation(RestRequest restRequest, Response returnedResponse) + { + String responseSizeString = returnedResponse.getHeader("Content-Length"); + if (responseSizeString != null && Integer.valueOf(responseSizeString) > IGNORE_CONTENT_LIMIT_BYTES) + { + LOG.info("On {} {}, received a response size that was {} bytes.\n" + + "This is bigger than the limit of {} bytes so its content will not be displayed: \n", restRequest.getHttpMethod(), + restRequest.getPath(), Integer.valueOf(responseSizeString), IGNORE_CONTENT_LIMIT_BYTES); + } + else + { + if (returnedResponse.getContentType().contains("image/png")) + { + LOG.info("On {} {}, received the response with an image and headers: \n{}", restRequest.getHttpMethod(), restRequest.getPath(), + returnedResponse.getHeaders().toString()); + } + else if (returnedResponse.getContentType().contains("application/json") && !returnedResponse.asString().isEmpty()) + { + LOG.info("On {} {}, received the following response \n{}", restRequest.getHttpMethod(), restRequest.getPath(), + Utility.prettyPrintJsonString(returnedResponse.asString())); + } + else if (returnedResponse.getContentType().contains("application/xml") && !returnedResponse.asString().isEmpty()) + { + String response = parseXML(returnedResponse); + LOG.info("On {} {}, received the following response \n{}", restRequest.getHttpMethod(), restRequest.getPath(), response); + } + else + { + LOG.info("On {} {}, received the following response \n{}", restRequest.getHttpMethod(), restRequest.getPath(), + ToStringBuilder.reflectionToString(returnedResponse.asString(), ToStringStyle.MULTI_LINE_STYLE)); + } + } + } + + private String parseXML(Response returnedResponse) + { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + String result = ""; + try + { + DocumentBuilder db = dbf.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(returnedResponse.asString())); + Document document = db.parse(is); + + OutputFormat format = new OutputFormat(document); + format.setLineWidth(65); + format.setIndenting(true); + format.setIndent(2); + Writer out = new StringWriter(); + XMLSerializer serializer = new XMLSerializer(out, format); + serializer.serialize(document); + + result = out.toString(); + } + catch (Exception e) + { + result = "Error Parsing XML file returned: "+ e.getMessage(); + setStatusCode(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value())); + } + + return result; + } + + /** + * Check if returned response contains an error (error node) + * + * @param returnedResponse + * @throws EmptyJsonResponseException + */ + private boolean checkForJsonError(Response returnedResponse) throws EmptyJsonResponseException + { + setLastError(null); + + try + { + // check for empty json response + returnedResponse.jsonPath().get(); + } + catch (Exception e) + { + throw new EmptyJsonResponseException(e.getMessage()); + } + Object error = returnedResponse.jsonPath().get("error"); + if (error != null) + { + setLastError(returnedResponse.jsonPath().getObject("error", RestErrorModel.class)); + return true; + } + + return false; + } + + /** + * Check if returned response contains an exception (status node) + * + * @param returnedResponse + * @throws EmptyJsonResponseException + */ + private boolean checkForJsonStatusException(Response returnedResponse) throws EmptyJsonResponseException + { + try + { + // check for empty json response + lastException = returnedResponse.jsonPath().get("exception"); + } + catch (Exception e) + { + throw new EmptyJsonResponseException(e.getMessage()); + } + if (lastException == null) + lastException = ""; + + Object error = returnedResponse.jsonPath().get("status"); + if (error != null) + { + setLastStatus(returnedResponse.jsonPath().getObject("status", StatusModel.class)); + LOG.error("Exception thrown on response: {}", getLastStatus().toInfo()); + return true; + } + + return false; + } + + /** + * Assert that a specific status code is returned + * + * @param statusCode + * @return; + */ + public RestWrapper assertStatusCodeIs(HttpStatus statusCode) + { + STEP(String.format("REST API: Assert that status code is %s", statusCode.toString())); + Assert.assertEquals(getStatusCode(), String.valueOf(statusCode.value()), "Status code is not as expected."); + + return this; + } + + /** + * Backtrack algorithm to gather all declared fields within SuperClasses + * but stopping on TestModel.class + * + * @param fields + * @param classz + * @return + */ + private List getAllDeclaredFields(List fields, Class classz) + { + if (classz.isAssignableFrom(TestModel.class)) + { + return fields; + } + + fields.addAll(Arrays.asList(classz.getDeclaredFields())); + + if (classz.getSuperclass() != null) + { + fields = getAllDeclaredFields(fields, classz.getSuperclass()); + } + + return fields; + } + + /** + * Check that REST response has returned all required fields + * + * @param classz + * @param classzInstance + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws InvocationTargetException + * @throws InstantiationException + */ + public void validateJsonModelSchema(Class classz, Object classzInstance) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException + { + List allFields = getAllDeclaredFields(new LinkedList(), classz); + + for (Field field : allFields) + { + /* + * check for required fields + */ + if (field.isAnnotationPresent(JsonProperty.class)) + { + if (field.getAnnotation(JsonProperty.class).required()) + { + // we make it accessible to get the value + field.setAccessible(true); + + // now obtaining the field value from instance + Object fieldValue = field.get(classzInstance); + String info = String.format("Checking required field [%s] from class %s - value: %s", + field.getName(), classzInstance.getClass().getName(), fieldValue); + LOG.info(info); + Assert.assertNotNull(fieldValue, info); + + // continue for non-primitive objects + if (!field.getType().isPrimitive()) + { + validateJsonModelSchema(fieldValue.getClass(), fieldValue); + } + } + } + } + } + + /** + * @return parameters that you could pass on the request ?param=value + */ + public String getParameters() + { + String localParam = parameters; + clearParameters(); + return localParam; + } + + /** + * Define the entire string of parameters that will be send to request + * Don't forget to call {@link #getParameters()} in the request to enable this. + * + * @param parameters + */ + public void setParameters(String parameters) + { + this.parameters = parameters; + } + + /** + * Just clear the parameters sent + */ + public void clearParameters() + { + setParameters(""); + } + + /** + * just clear the base path + * + * @return + */ + public RestWrapper clearBasePath() + { + this.configureRequestSpec().setBasePath(""); + return this; + } + + /** + * Send key=value parameters + * All of them will be automatically passed to url. + * Example: "maxItems=10000" + * + * @param parameters + * @return + */ + 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()); + return this; + } + + /** + * @return {@link RestCoreAPI} using the rest Core API as prefix: {@link /alfresco/api/-default-/public/alfresco/versions/1} + */ + public RestCoreAPI withCoreAPI() + { + return new RestCoreAPI(this); + } + + /** + * @return {@link RestWorkflowAPI} using the rest Workflow API with prefix: {@link /alfresco/api/-default-/public/workflow/versions/1 } + */ + public RestWorkflowAPI withWorkflowAPI() + { + return new RestWorkflowAPI(this); + } + + /** + * @return {@link RestAuthAPI} using the rest Auth API with prefix: {@link /alfresco/api/-default-/public/authentication/versions/1 } + */ + public RestAuthAPI withAuthAPI() + { + return new RestAuthAPI(this); + } + + public SearchAPI withSearchAPI() + { + return new SearchAPI(this); + } + + public SearchSQLAPI withSearchSqlAPI() + { + return new SearchSQLAPI(this); + } + + public SearchSQLJDBC withSearchSqlViaJDBC() + { + return new SearchSQLJDBC(this); + } + + public ShardInfoAPI withShardInfoAPI() + { + return new ShardInfoAPI(this); + } + + public SolrAPI withSolrAPI() + { + return new SolrAPI(this); + } + + /** + * @return {@link RestDiscoveryAPI} using the rest Discovery API as prefix: {@link /alfresco/api/discovery} + */ + public RestDiscoveryAPI withDiscoveryAPI() + { + return new RestDiscoveryAPI(this); + } + + /** + * @return {@link AdminConsole} using the Admin Console API as prefix: {@link /alfresco/service/api/server} + */ + public AdminConsole withAdminConsole() + { + return new AdminConsole(this); + } + + /** + * Provides DSL on creating Tenant users + * + * @return {@link Tenant} + */ + public Tenant usingTenant() + { + return new Tenant(this, restProperties); + } + + /** + * Construct the Where clause of any REST API call + * You can use the where parameter to restrict the list in the response to entries of a specific kind. + * The where parameter takes a value. + */ + public RestWrapper where(String whereExpression) + { + String whereClause = "where=(%s)"; + + return withParams(String.format(whereClause, whereExpression)); + } + + public ContentType getDefaultContentType() + { + return defaultContentType; + } + + public RestWrapper usingContentType(ContentType defaultContentType) + { + this.defaultContentType = defaultContentType; + return this; + } + + /** + * You can handle the request sent to server by calling this method. + * If for example you want to sent multipart form data you can use: + * restClient.configureRequestSpec() + .addMultiPart("filedata", Utility.getResourceTestDataFile("restapi-resource")) + .addFormParam("renditions", "doclib") + .addFormParam("autoRename", true); + + restClient.withCoreAPI().usingNode(ContentModel.my()).createNode(); + * This will create the node using the multipart data defined. + * + * @return + */ + public RequestSpecBuilder configureRequestSpec() + { + return this.requestSpecBuilder; + } + + /** + * Perform CMIS browser binding calls ("alfresco/api/-default-/public/cmis/versions/1.1/browser") with Rest API + * + * @return {@link RestCmisAPI} + */ + public RestCmisAPI withCMISApi() + { + return new RestCmisAPI(this); + } + + /** + * Perform AOS browser binding calls ("alfresco/aos") with Rest API + * + * @return {@link RestAosAPI} + */ + public RestAosAPI withAosAPI() + { + return new RestAosAPI(this); + } + + /** + * @return {@link RestPrivateAPI} using the rest Private API as prefix: {@link /alfresco/api/-default-/private/alfresco/versions/1} + */ + public RestPrivateAPI withPrivateAPI() + { + return new RestPrivateAPI(this); + } + + public RestResponse onResponse() + { + if (response == null) + throw new UnsupportedOperationException("Cannot perform on a Response that wasn't yet received!"); + return response; + } + + /** + * Process responses for a single model as {@link RestSyncSetRequestModel} + * Notice that {@link RestSyncSetRequestModel} doesn't have one "entry" field as any other rest request model + * + * @throws JsonToModelConversionException If the response cannot be converted to the given model. + * @throws EmptyJsonResponseException If there is no response from the server. + */ + public T processModelWithoutEntryObject(Class classz, RestRequest restRequest) + throws EmptyJsonResponseException, JsonToModelConversionException + { + Response returnedResponse = sendRequest(restRequest); + + setStatusCode(String.valueOf(returnedResponse.getStatusCode())); + + boolean responseHasErrors = checkForJsonError(returnedResponse); + // Do not check checkForJsonStatusException as status object in the API response is not a standard statusModel + // boolean responseHasExceptions = checkForJsonStatusException(returnedResponse); + + T model = null; + + try + { + if (!responseHasErrors) + { + model = returnedResponse.jsonPath().getObject("$", classz); + validateJsonModelSchema(classz, model); + } + } + catch (Exception processError) + { + throw new JsonToModelConversionException(classz, processError); + } + if (model == null) + { + try + { + return classz.newInstance(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + return model; + } + + public void configureSyncServiceEndPoint() + { + RestAssured.baseURI = restProperties.envProperty().getSyncServerUrl(); + RestAssured.port = restProperties.envProperty().getSyncPort(); + configureRequestSpec().setBaseUri(restProperties.envProperty().getSyncServerUrl()); + configureRequestSpec().setPort(restProperties.envProperty().getSyncPort()); + } + + public void configureSolrEndPoint() + { + RestAssured.baseURI = restProperties.envProperty().getSolrServerUrl(); + RestAssured.port = restProperties.envProperty().getSolrPort(); + configureRequestSpec().setBaseUri(restProperties.envProperty().getSolrServerUrl()); + configureRequestSpec().setPort(restProperties.envProperty().getSolrPort()); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/IModelAssertion.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/IModelAssertion.java new file mode 100644 index 0000000000..e91faa3450 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/IModelAssertion.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.core.assertion; + +public interface IModelAssertion +{ + public ModelAssertion and(); + + public ModelAssertion assertThat(); +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/IModelsCollectionAssertion.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/IModelsCollectionAssertion.java new file mode 100644 index 0000000000..8e692eb896 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/IModelsCollectionAssertion.java @@ -0,0 +1,10 @@ +package org.alfresco.rest.core.assertion; + +@SuppressWarnings("rawtypes") +public interface IModelsCollectionAssertion { + public ModelsCollectionAssertion and(); + + public ModelsCollectionAssertion assertThat(); + + public ModelCollection when(); +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/ModelAssertion.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/ModelAssertion.java new file mode 100644 index 0000000000..3be0c3ac3e --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/ModelAssertion.java @@ -0,0 +1,336 @@ +package org.alfresco.rest.core.assertion; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.alfresco.utility.exception.TestConfigurationException; +import org.alfresco.utility.model.TestModel; +import org.testng.Assert; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.restassured.path.json.JsonPath; + +/** + * Assertion on Rest Model + * Just pass your rest model as constructor + * + * @author Paul Brodner + */ + +public class ModelAssertion +{ + protected static void checkFieldIsPresent(Object fieldNameToBeRetuned, Object fieldValueToBeRetuned) + { + if (fieldValueToBeRetuned == null) + { + Assert.fail(String.format("Field {%s} was not found in returned response.",fieldNameToBeRetuned)); + } + } + private Object model; + + public ModelAssertion(Object model) + { + this.model = model; + } + + /** + * Use this DSL for asserting particular fields of your model if your model + * is like this (basic POJO) public class Person extends + * ModelAssertion { private String id = "1234"; you can use assert + * the id of this person as: + * Person p = new Person(); p.assertField("id").is("1234") + * + * @param fieldName + * @return + * @throws IllegalStateException If the field cannot be converted to JSON. + */ + public AssertionVerbs field(String fieldName) + { + + ObjectMapper mapper = new ObjectMapper(); + + String jsonInString = null; + try + { + jsonInString = mapper.writeValueAsString(model); + } + catch (JsonProcessingException e) + { + throw new IllegalStateException(e); + } + + Object fieldValue = JsonPath.with(jsonInString).get(fieldName); + + return new AssertionVerbs(model, fieldValue, fieldName); + } + + public AssertionItemVerbs fieldsCount() throws Exception + { + + int actualSize = 0; + List allFields = getAllDeclaredFields(new LinkedList(), model.getClass()); + + for (Field field : allFields) + { + + field.setAccessible(true); + Object fieldValue = field.get(model); + if (fieldValue != null) + actualSize++; + } + return new AssertionItemVerbs(model, actualSize); + } + + /** + * Get all fields declared from all classes hierarchy + * + * @param fields + * @param classz + * @return + */ + private List getAllDeclaredFields(List fields, Class classz) + { + if (classz.isAssignableFrom(TestModel.class)) + { + return fields; + } + + fields.addAll(Arrays.asList(classz.getDeclaredFields())); + + if (classz.getSuperclass() != null) + { + fields = getAllDeclaredFields(fields, classz.getSuperclass()); + } + + return fields; + } + + /** + * DSL assertion on Rest Model fields + * + * @author Paul Brodner + */ + @SuppressWarnings("unchecked") + public class AssertionVerbs + { + private String fieldName; + private Object model; + private Object fieldValue; + + public AssertionVerbs(Object model, Object fieldValue, String fieldName) + { + this.model = model; + this.fieldValue = fieldValue; + this.fieldName = fieldName; + } + + private String errorMessage(String info) + { + return String.format("The value of field [%s -> from %s] %s", fieldName, model.getClass().getCanonicalName(), info); + } + + public T isNot(Object expected) + { + checkFieldIsPresent(fieldName, fieldValue); + Assert.assertNotEquals(fieldValue, expected, errorMessage("is correct,")); + return (T) model; + } + + @Override + public boolean equals(Object o) + { + throw new UnsupportedOperationException("You probably want to use is() rather than equals()"); + } + + public T is(Object expected) + { + checkFieldIsPresent(fieldName, fieldValue); + Assert.assertEquals(fieldValue.toString(), expected.toString(), errorMessage("is NOT correct,")); + return (T) model; + } + + /** + * Check if the supplied field is a non-empty String, Collection or Map. + * + * @throws AssertionError if the field is empty. + * @throws UnsupportedOperationException if the field cannot be checked for emptiness. + */ + public T isNotEmpty() + { + checkFieldIsPresent(fieldName, fieldValue); + if (fieldValue instanceof Collection) + { + Assert.assertNotEquals(fieldValue, Collections.emptyList(), errorMessage("is empty,")); + } + else if (fieldValue instanceof String) + { + Assert.assertNotEquals(fieldValue, "", errorMessage("is empty,")); + } + else if (fieldValue instanceof Map) + { + Assert.assertNotEquals(fieldValue, Collections.emptyMap(), errorMessage("is empty,")); + } + else if (fieldValue instanceof Integer) + { + Assert.assertNotEquals(fieldValue.toString(), "", errorMessage("is empty,")); + } + else if (fieldValue instanceof Long) + { + Assert.assertNotEquals(fieldValue.toString(), "", errorMessage("is empty,")); + } + else if (fieldValue instanceof Boolean) + { + Assert.assertNotEquals(String.valueOf(fieldValue), "", errorMessage("is empty,")); + } + else + { + throw new UnsupportedOperationException("Cannot check for emptiness of " + fieldValue.getClass()); + } + return (T) model; + } + + public T isNotNull() + { + checkFieldIsPresent(fieldName, fieldValue); + Assert.assertNotNull(fieldValue, errorMessage("is null,")); + return (T) model; + } + + public T isNull() + { + Assert.assertNull(fieldValue, errorMessage("is not null,")); + return (T) model; + } + + /** + * Check if the supplied field is an empty String, Collection or Map. + * + * @throws AssertionError if the field is not empty. + * @throws UnsupportedOperationException if the field cannot be checked for emptiness. + */ + public T isEmpty() + { + checkFieldIsPresent(fieldName, fieldValue); + if (fieldValue instanceof Collection) + { + Assert.assertEquals((Collection) fieldValue, Collections.emptyList(), errorMessage("is NOT empty,")); + } + else if (fieldValue instanceof String) + { + Assert.assertEquals(fieldValue, "", errorMessage("is NOT empty,")); + } + else if (fieldValue instanceof Map) + { + Assert.assertEquals(fieldValue, Collections.emptyMap(), errorMessage("is NOT empty,")); + } + else + { + throw new UnsupportedOperationException("Cannot check for emptiness of " + fieldValue.getClass()); + } + return (T) model; + } + + public T contains(String value) + { + if (!fieldValue.toString().contains(value)) + Assert.fail(errorMessage("does NOT contain expected value: " + value + ", Current Value: " + fieldValue.toString())); + + return (T) model; + } + /** + * Assert if predicate value is greater than the field value + * @author Michael Suzuki + * @param value the predicate + * @return + * @throws TestConfigurationException + * + */ + public T isGreaterThan(Integer value) throws TestConfigurationException + { + return validateSize(value, Operation.Greater); + } + + private T validateSize(Integer value, Operation operation) throws TestConfigurationException + { + try + { + if(value == null) + { + throw new TestConfigurationException("Input must be valid"); + } + Integer b = Integer.valueOf(fieldValue.toString()); + switch (operation) + { + case Greater: + if(value > b) + { + Assert.fail(errorMessage(String.format("The expected value %s is not greater than the actual value %s ", + value, fieldValue.toString()))); + } + break; + case Less: + if(value < b) + { + Assert.fail(errorMessage(String.format("The expected value %s is not less than the actual value %s ", + value, fieldValue.toString()))); + } + break; + + default: + Assert.fail(errorMessage("No operation type provided")); + break; + } + } + catch(NumberFormatException e) + { + Assert.fail(errorMessage("The field is not numeric " + fieldValue.toString())); + } + catch (NullPointerException ne) + { + Assert.fail(errorMessage("The input value must be numeric " + value)); + } + return (T) model; + } + /** + * Assert if predicate value is less than the field value + * @author Michael Suzuki + * @param value the predicate + * @return + * @throws TestConfigurationException + * + */ + public T isLessThan(Integer value) throws TestConfigurationException + { + return validateSize(value, Operation.Less); + } + } + + @SuppressWarnings("unchecked") + public class AssertionItemVerbs + { + private Object model; + private Object actual; + + public AssertionItemVerbs(Object model, Object actual) throws Exception + { + this.model = model; + this.actual = actual; + } + + public T is(Object expected) { + Assert.assertEquals(actual, expected, String.format("For model [%s], the expected value is not correct ", + model.getClass().getSimpleName(), expected.toString(), actual.toString())); + return (T) model; + } + } + public static enum Operation + { + Less,Greater + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/ModelsCollectionAssertion.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/ModelsCollectionAssertion.java new file mode 100644 index 0000000000..141d2cbb14 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/ModelsCollectionAssertion.java @@ -0,0 +1,246 @@ +package org.alfresco.rest.core.assertion; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.rest.core.IRestModelsCollection; +import org.alfresco.utility.exception.TestConfigurationException; +import org.alfresco.utility.model.Model; +import org.apache.commons.beanutils.BeanUtils; +import org.testng.Assert; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Ordering; +import io.restassured.path.json.JsonPath; + +/** + * Assertion on Rest Model Collection + * Just pass your rest model collection as constructor + * + * @author Paul Brodner + */ +public class ModelsCollectionAssertion +{ + @SuppressWarnings("rawtypes") + private IRestModelsCollection modelCollection; + + @SuppressWarnings("rawtypes") + public ModelsCollectionAssertion(IRestModelsCollection modelCollection) + { + this.modelCollection = modelCollection; + } + + /** + * check if "entries" list from JSON is not empty + */ + @SuppressWarnings("unchecked") + public C entriesListIsNotEmpty() + { + STEP("REST API: Assert that entries list from response is not empty"); + Assert.assertFalse(modelCollection.isEmpty(), "Entries list from response is empty.Check the logs for more details!"); + return (C) modelCollection; + } + + /** + * check if "entries" list from JSON is empty + */ + @SuppressWarnings("unchecked") + public C entriesListIsEmpty() + { + STEP("REST API: Assert that entries list from response is empty"); + Assert.assertTrue(modelCollection.isEmpty(), "Entries list from response is not empty.Check the logs for more details!"); + return (C) modelCollection; + } + + @SuppressWarnings("unchecked") + public C entriesListCountIs(int expectedCount) + { + STEP(String.format("REST API: Assert that entries list count is %d", expectedCount)); + int actualSize = modelCollection.getEntries().size(); + Assert.assertEquals(actualSize, expectedCount); + return (C) modelCollection; + } + + @SuppressWarnings("unchecked") + public C entriesListContains(String key, String value) throws Exception + { + List modelEntries = modelCollection.getEntries(); + String fieldValue = ""; + for (Model m : modelEntries) { + Method method = m.getClass().getMethod("onModel", new Class[] {}); + Object model = method.invoke(m, new Object[] {}); + try { + ObjectMapper mapper = new ObjectMapper(); + String jsonInString = mapper.writeValueAsString(model); + fieldValue = JsonPath.with(jsonInString).get(key); + if (fieldValue != null && fieldValue.equals(value)) { + break; + } + } catch (Exception e) { + throw new TestConfigurationException(String.format( + "You try to assert field [%s] that doesn't exist in class: [%s]. Exception: %s, Please check your code!", + key, getClass().getCanonicalName(), e.getMessage())); + } + } + Assert.assertEquals(fieldValue, value, String.format("Entry with key: [%s] with value [%s] not found in list", key, value)); + + + return (C) modelCollection; + } + + @SuppressWarnings("unchecked") + public C entriesListDoesNotContain(String key, String value) throws Exception + { + boolean exist = false; + List modelEntries = modelCollection.getEntries(); + for (Model m : modelEntries) { + Method method = m.getClass().getMethod("onModel", new Class[] {}); + Object model = method.invoke(m, new Object[] {}); + String fieldValue = ""; + try { + ObjectMapper mapper = new ObjectMapper(); + String jsonInString = mapper.writeValueAsString(model); + fieldValue = JsonPath.with(jsonInString).get(key); + if (fieldValue != null && fieldValue.equals(value)) { + exist = true; + break; + } + } catch (Exception e) { + // nothing to do + } + } + Assert.assertFalse(exist, + String.format("Entry with key: %s and value %s was found in list", key, value)); + + return (C) modelCollection; + } + + @SuppressWarnings("unchecked") + public C entriesListDoesNotContain(String key) throws Exception + { + boolean exist = false; + List modelEntries = modelCollection.getEntries(); + for (Model m : modelEntries) { + Method method = m.getClass().getMethod("onModel", new Class[] {}); + Object model = method.invoke(m, new Object[] {}); + String fieldValue = ""; + ObjectMapper mapper = new ObjectMapper(); + String jsonInString = mapper.writeValueAsString(model); + fieldValue = JsonPath.with(jsonInString).get(key); + if (fieldValue != null) { + exist = true; + break; + } + } + Assert.assertFalse(exist, + String.format("Entry list contains key: %s", key)); + + return (C) modelCollection; + } + + @SuppressWarnings("unchecked") + public C entriesListContains(String key) throws Exception + { + boolean exist = false; + List modelEntries = modelCollection.getEntries(); + for (Model m : modelEntries) { + Method method = m.getClass().getMethod("onModel", new Class[] {}); + Object model = method.invoke(m, new Object[] {}); + Object fieldValue = null; + ObjectMapper mapper = new ObjectMapper(); + String jsonInString = mapper.writeValueAsString(model); + fieldValue = JsonPath.with(jsonInString).get(key); + if (fieldValue != null) { + exist = true; + break; + } + } + Assert.assertTrue(exist, + String.format("Entry list doesn't contain key: %s", key)); + + return (C) modelCollection; + } + + @SuppressWarnings("unchecked") + public C paginationExist() + { + STEP("REST API: Assert that response has pagination"); + Assert.assertNotNull(modelCollection.getPagination(), "Pagination is was not found in the response"); + return (C) modelCollection; + } + + /** + * Check one field from pagination json body + * + * @param field + * @return + */ + @SuppressWarnings("rawtypes") + public PaginationAssertionVerbs paginationField(String field) + { + return new PaginationAssertionVerbs(modelCollection, field, modelCollection.getPagination()); + } + + /** + * check is the entries are ordered ASC by a specific field + * + * @param field from json response + * @return + * @throws Exception + */ + @SuppressWarnings("unchecked") + public C entriesListIsSortedAscBy(String field) throws Exception + { + List modelEntries = modelCollection.getEntries(); + List fieldValues = new ArrayList(); + for(Model m: modelEntries) + { + Method method = m.getClass().getMethod("onModel", new Class[] {}); + Object model = method.invoke(m, new Object[] {}); + String fieldValue = ""; + try { + fieldValue = BeanUtils.getProperty(model, field); + fieldValues.add(fieldValue); + } + catch (Exception e) + { + // nothing to do + } + } + Assert.assertTrue(Ordering.natural().isOrdered(fieldValues), String.format("Entries are not ordered ASC by %s", field)); + return (C) modelCollection; + } + + /** + * check is the entries are ordered DESC by a specific field + * + * @param field from json response + * @return + * @throws Exception + */ + @SuppressWarnings("unchecked") + public C entriesListIsSortedDescBy(String field) throws Exception + { + List modelEntries = modelCollection.getEntries(); + List fieldValues = new ArrayList(); + for(Model m: modelEntries) + { + Method method = m.getClass().getMethod("onModel", new Class[] {}); + Object model = method.invoke(m, new Object[] {}); + String fieldValue = ""; + try { + fieldValue = BeanUtils.getProperty(model, field); + fieldValues.add(fieldValue); + } + catch (Exception e) + { + // nothing to do + } + } + Assert.assertTrue(Ordering.natural().reverse().isOrdered(fieldValues), String.format("Entries are not ordered DESC by %s", field)); + return (C) modelCollection; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/PaginationAssertionVerbs.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/PaginationAssertionVerbs.java new file mode 100644 index 0000000000..497dd57378 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/assertion/PaginationAssertionVerbs.java @@ -0,0 +1,80 @@ +package org.alfresco.rest.core.assertion; + +import org.alfresco.rest.core.IRestModelsCollection; +import org.alfresco.rest.model.RestPaginationModel; +import org.alfresco.utility.exception.TestConfigurationException; +import org.apache.commons.beanutils.BeanUtils; +import org.testng.Assert; + +/** + * Pagination related assertions + * + * @author Paul Brodner + */ +public class PaginationAssertionVerbs { + private RestPaginationModel pagination; + private C modelCollection; + private String fieldName; + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public PaginationAssertionVerbs(IRestModelsCollection modelCollection, String fieldName, RestPaginationModel pagination) { + this.modelCollection = (C)modelCollection; + this.fieldName = fieldName; + this.pagination = pagination; + } + + /** + * @return the value of the field + * @throws Exception + */ + private String getFieldValue() throws Exception { + String value = ""; + try { + value = BeanUtils.getProperty(pagination, fieldName); + + } catch (Exception e) { + throw new TestConfigurationException(String.format( + "You try to assert field [%s] that doesn't exist in class: [%s]. Exception: %s, Please check your code!", + fieldName, modelCollection.getClass().getCanonicalName(), e.getMessage())); + } + + return value; + } + + private String errorMessage(String info) { + return String.format("The value of field [%s -> from %s] %s", fieldName, + modelCollection.getClass().getCanonicalName(), info); + } + + public C is(String expected) throws Exception { + + Assert.assertEquals(getFieldValue(), expected, errorMessage("is NOT correct,")); + return modelCollection; + } + + public C isNot(Object expected) throws Exception { + + Assert.assertNotEquals(getFieldValue(), expected, errorMessage("is correct,")); + return modelCollection; + } + + public C isNotEmpty() throws Exception { + Assert.assertNotEquals(getFieldValue(), "", errorMessage("is empty,")); + return modelCollection; + } + + public C isNotNull() throws Exception { + Assert.assertNotNull(getFieldValue(), errorMessage("is null,")); + return modelCollection; + } + + public C isNotPresent() throws Exception { + Assert.assertNull(getFieldValue(), errorMessage("is present,")); + return modelCollection; + } + + public C isEmpty() throws Exception { + Assert.assertEquals(getFieldValue(), "", errorMessage("is NOT empty,")); + return modelCollection; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/Generator.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/Generator.java new file mode 100644 index 0000000000..9bf7c8d1f9 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/Generator.java @@ -0,0 +1,51 @@ +package org.alfresco.rest.core.swagger; + +/** + * Executed via command line/terminal from root of this project + * Just execute mvn exec:java passing as arguments: + * -Dcoverage => this will show on screen the actual coverage of TAS (vs requests that exists in each YAML file - defined in pom.xml) + * -Dmodels => this will show all MISSING models that are NOT already implemented in TAS. + * -Dmodels=a,b,d => this will generate ONLY the models 'a', 'b' and 'd' passed as parameter + * -Dhelp => show help + * + * @author Paul Brodner + */ +public class Generator +{ + public static String line = "********\n------------------------------------------------------------------------"; + + public static void main(String[] args) throws Exception + { + + if (!System.getProperties().containsKey("coverage") && !System.getProperties().containsKey("models") || System.getProperties().containsKey("help") ) + { + System.out.println(line); + System.out.println("No parameters provided, please use the following values:\n"); + System.out.println( + "mvn exec:java -Dcoverage => this will show on screen the actual coverage of TAS (vs requests that exists in each YAML file - defined in pom.xml)."); + System.out.println("mvn exec:java -Dmodels => this will show all MISSING models that are NOT already implemented in TAS."); + System.out.println("mvn exec:java -Dmodels=a,b,d => this will generate ONLY the models 'a', 'b' and 'd' passed as parameter."); + System.out.println(line); + + } + + for (String url : args) + { + if (System.getProperty("coverage") != null) + { + /* + * mvn exec:java -Dcoverage + */ + new SwaggerYamlParser(url).computeCoverage(); + } + else if (System.getProperty("models") != null) + { + /* + * mvn exec:java -Dmodels + * mvn exec:java -Dmodels=a,c,e + */ + new SwaggerYamlParser(url).generateMissingModules(); + } + } + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/RestModelProperty.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/RestModelProperty.java new file mode 100644 index 0000000000..e69e67f7e7 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/RestModelProperty.java @@ -0,0 +1,125 @@ +package org.alfresco.rest.core.swagger; + +import java.util.AbstractMap; +import java.util.Map.Entry; + +import io.swagger.models.properties.ArrayProperty; +import io.swagger.models.properties.RefProperty; + +/** + * Model property used by freemarker template in {@link SwaggerModel} + * + */ +public class RestModelProperty +{ + private String name; + private String type; + private String description; + private Boolean isRequired = false; + /** If the property is a ref then this is the type referenced. */ + private String simpleRef; + /** If the property is an array then this is the type of the items in it. */ + private RestModelProperty itemsType; + + public static RestModelProperty build(Entry property) + { + RestModelProperty model = new RestModelProperty(); + model.setName(property.getKey()); + model.setType(property.getValue().getType()); + model.setDescription(property.getValue().getDescription()); + model.setIsRequired(property.getValue().getRequired()); + if (property.getValue() instanceof RefProperty) + { + RefProperty refProperty = (RefProperty) property.getValue(); + model.setSimpleRef(refProperty.getSimpleRef()); + } + if (property.getValue() instanceof ArrayProperty) + { + ArrayProperty arrayProperty = (ArrayProperty) property.getValue(); + Entry itemsEntry = new AbstractMap.SimpleEntry( + arrayProperty.getName(), arrayProperty.getItems()); + model.setItemsType(RestModelProperty.build(itemsEntry)); + } + + return model; + } + + public String getName() + { + return name; + } + + public String getNameCapitalized() + { + return org.apache.commons.lang3.StringUtils.capitalize(name); + } + + public void setName(String name) + { + this.name = name; + } + + public String getType() + { + switch (this.type) + { + case "string": + return "String"; + case "integer": + return "int"; + case "object": + return "Object"; + case "ref": + return "Rest" + getSimpleRef() + "Model"; + case "array": + return "List<" + getItemsType().getType() + ">"; + default: + return type; + } + } + + public void setType(String type) + { + this.type = type; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public Boolean isRequired() + { + return isRequired; + } + + public void setIsRequired(Boolean isRequired) + { + this.isRequired = isRequired; + } + + protected void setSimpleRef(String simpleRef) + { + this.simpleRef = simpleRef; + } + + public String getSimpleRef() + { + return simpleRef; + } + + protected void setItemsType(RestModelProperty itemsType) + { + this.itemsType = itemsType; + } + + public RestModelProperty getItemsType() + { + return itemsType; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerDefinitions.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerDefinitions.java new file mode 100644 index 0000000000..1e8feba864 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerDefinitions.java @@ -0,0 +1,178 @@ +package org.alfresco.rest.core.swagger; + +import java.io.BufferedReader; +import java.io.Console; +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import org.alfresco.utility.exception.TestConfigurationException; + +import freemarker.template.TemplateException; +import io.swagger.models.Model; +import io.swagger.models.Swagger; + +/** + * Handles all + * Entry model : swagger.getDefinitions().entrySet() + * + * @author Paul Brodner + */ +public class SwaggerDefinitions +{ + private Swagger swagger; + List missingSwaggerModels = new ArrayList(); + Path modelsPath; + + public SwaggerDefinitions(Swagger swagger) + { + this.swagger = swagger; + modelsPath = Paths.get(Paths.get(".").toAbsolutePath().normalize().toFile().getPath(), "src/main/java/org/alfresco/rest/model"); + } + + public void generateMissingDefinitions() throws Exception + { + /* + * read the content of ignore-moldels file + */ + List ignoreModel = new ArrayList(); + try (BufferedReader br = new BufferedReader(new FileReader(Paths.get(modelsPath.toFile().getPath(), "ignore-models").toFile()))) + { + String line; + while ((line = br.readLine()) != null) + { + if (!line.startsWith("#") && !line.equals("")) + ignoreModel.add(line); + } + } + + /* + * filter all models, ignoring the ones from ignore-model or the ones that are already created locally + */ + for (Entry model : swagger.getDefinitions().entrySet()) + { + SwaggerModel swaggerModel = new SwaggerModel(model, swagger); + + //regexp + if(swaggerModel.getName().matches(".*Paging|.*Entry")) + { + System.out.printf("Ignoring Model: [%s] (based on regular expression: '.*Paging|.*Entry')\n", swaggerModel.getName()); + continue; + } + + if (ignoreModel.contains(swaggerModel.getName())) + { + System.out.printf("Ignoring Model: [%s] (based on 'ignore-models' file)\n", swaggerModel.getName()); + continue; + } + + + + if (!swaggerModel.exist()) + missingSwaggerModels.add(swaggerModel); + } + + System.out.println(Generator.line); + int count = 0; + /* + * iterate on all missing models + */ + for (SwaggerModel swaggerModel : missingSwaggerModels) + { + if (count == 0) // table heather + { + System.out.printf("MISSING MODEL ~ THE NEW FILE THAT WILL BE GENERATED\n"); + System.out.println(" 0 -[Skip all]"); + } + + count += 1; + StringBuilder info = new StringBuilder(); + info.append(" ") + .append(count) + .append(" -") + .append("[") + .append(swaggerModel.getName()) + .append("] ~ [") + .append(swaggerModel.getPath()) + .append("]"); + + System.out.println(info.toString()); + } + System.out.println("ENTER -[All Models]"); + + /* + * wait for input + */ + Console c = System.console(); + if (c != null && missingSwaggerModels.size() > 0) + { + c.format("%s\n", Generator.line); + c.format("\nPlease select what Models you want to generate (ex: 1,3,4) or press <>to generating all missing models:"); + String prompt = c.readLine(); + + if(prompt.equals("0")) + return; + + if (prompt.length() == 0) + { + System.out.println("\nStart generating all models..."); + for (SwaggerModel swaggerModel : missingSwaggerModels) + { + swaggerModel.generate(); + } + } + else + { + if (prompt.contains(",")) + { + String[] modelsIDToGen = prompt.split(","); + for (int i = 0; i < modelsIDToGen.length; i++) + { + generateSelectedSwaggerModel(modelsIDToGen[i]); + } + } + else + { + generateSelectedSwaggerModel(prompt); + } + } + } + } + + /** + * Generate the model based on the ID provided + * + * @param id + * @throws Exception + */ + private void generateSelectedSwaggerModel(String id) throws Exception + { + int choise = Integer.parseInt(id); + if ((choise - 1) >= missingSwaggerModels.size()) + { + throw new TestConfigurationException( + "You specified a wrong ID: [" + id + "] please select one value from the list displayed above. Run the command again!"); + } + missingSwaggerModels.get(choise - 1).generate(); + } + + public boolean generateDefinition(String modelParamValue) throws IOException, TemplateException + { + for (Entry model : swagger.getDefinitions().entrySet()) + { + SwaggerModel swaggerModel = new SwaggerModel(model, swagger); + if (swaggerModel.getName().equals(modelParamValue)) + { + swaggerModel.generate(); + return true; + } + } + System.err.println("Model that you provided was NOT found!"); + System.err.printf("Model [%s] not found in Swagger file: %s\n", modelParamValue, swagger.getBasePath()); + return false; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerModel.java new file mode 100644 index 0000000000..7fe8463dd2 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerModel.java @@ -0,0 +1,161 @@ +package org.alfresco.rest.core.swagger; + +import java.io.Console; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import io.swagger.models.Model; +import io.swagger.models.Swagger; + +/** + * Handles swagger definitions Entry model : swagger.getDefinitions().entrySet() + * + * @author Paul Brodner + */ +public class SwaggerModel +{ + private Swagger swagger; + private Entry model; + private Path modelsPath = Paths.get(Paths.get(".").toAbsolutePath().normalize().toFile().getPath(), "src/main/java/org/alfresco/rest/model"); + private List properties = new ArrayList(); + private Configuration cfg; + + private Configuration getConfig() throws IOException + { + if (cfg == null) + { + cfg = new Configuration(Configuration.VERSION_2_3_23); + cfg.setDirectoryForTemplateLoading(new File("src/main/resources")); + } + return cfg; + } + + public SwaggerModel(Entry model, Swagger swagger) + { + this.model = model; + this.swagger = swagger; + + + if(model.getValue().getProperties()!=null) + { + /* + * compute the properties of this model + */ + for (Entry property : model.getValue().getProperties().entrySet()) + { + if (property.getKey().equals("entry")) + continue; + + properties.add(RestModelProperty.build(property)); + } + } + + } + + /** + * @return boolean value if file is already generated in TAS, under 'models' package + */ + public boolean exist() + { + return getPath().exists(); + } + + /** + * @return the location of the model in TAS + */ + public File getPath() + { + return Paths.get(modelsPath.toFile().getPath(), getNameInTAS() + ".java").toFile(); + } + + /** + * @return original model name as defined in Swagger YAML + */ + public String getName() + { + return model.getKey(); + } + + /** + * @return the name as it will be used in TAS + */ + public String getNameInTAS() + { + return String.format("Rest%sModel", getName()); + } + + public List getProperties() + { + return properties; + } + + public void setProperties(List properties) + { + this.properties = properties; + } + + public void generate() throws IOException, TemplateException + { + Template template = getConfig().getTemplate("rest-model.ftl"); + + // here we will store all data passed to template + Map data = new HashMap(); + data.put("date", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date())); + data.put("author", System.getProperty("user.name")); + data.put("yamlTitle", swagger.getInfo().getTitle()); + data.put("yamlBasePath", swagger.getBasePath()); + data.put("name", getNameInTAS()); + + if (!getProperties().isEmpty()) + data.put("properties", getProperties()); + + Writer append = new StringWriter(); + template.process(data, append); + + append.close(); + + System.out.println("----- " + getPath().getName() + " -----\n"); + System.out.println(Generator.line); + System.out.println(append.toString()); + System.out.printf("\nGenerating Model: %-10s to ->'%-60s'", getName(), getPath()); + if (exist()) + { + Console c = System.console(); + if (c != null) + { + System.out.printf("There is already one model created locally: \n%s\nDo you want to override it ?(ENTER=yes, any other key=no):", getPath()); + if (c.readLine().length() == 0) + { + writeContent(append.toString()); + } + } + } + else + { + writeContent(append.toString()); + + } + } + + private void writeContent(String content) throws IOException + { + FileWriter fw = new FileWriter(getPath()); + fw.write(content); + fw.close(); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerPaths.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerPaths.java new file mode 100644 index 0000000000..62e9461585 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerPaths.java @@ -0,0 +1,191 @@ +package org.alfresco.rest.core.swagger; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; +import java.util.Map.Entry; + +import org.alfresco.utility.exception.TestConfigurationException; +import org.apache.commons.io.FilenameUtils; + +import io.swagger.models.HttpMethod; +import io.swagger.models.Operation; +import io.swagger.models.Swagger; + +/** + * Handles all + * Entry path : swagger.getPaths().entrySet() + * + * @author Paul Brodner + */ +public class SwaggerPaths +{ + private Swagger swagger; + private BufferedWriter fileWithMissingRequests; + private BufferedWriter fileWithImplementedRequests; + private String swaggerFilePath; + private int implementedRequestCount = 0; + private int missingRequestCount = 0; + + public SwaggerPaths(Swagger swagger, String swaggerFilePath) + { + this.swagger = swagger; + this.swaggerFilePath = swaggerFilePath; + } + + /** + * Compare requests that exist in swagger yaml file vs request implemented in your code + * any findings are saved to a missing-request txt file. + * @throws Exception + * + * @throws TestConfigurationException + */ + public void computeCoverage() throws Exception + { + System.out.println("Start computing the coverage of TAS vs Swagger file. Stand by..."); + File missingReq = new File(String.format("missing-requests-%s.txt", FilenameUtils.getBaseName(swaggerFilePath))); + missingReq.delete(); + fileWithMissingRequests = new BufferedWriter(new FileWriter(missingReq)); + fileWithMissingRequests.write(String.format("BasePath: {%s}", swagger.getBasePath())); + fileWithMissingRequests.newLine(); + fileWithMissingRequests.write("These requests generated should be analyzed and modified according to your needs."); + fileWithMissingRequests.newLine(); + fileWithMissingRequests.write("PLEASE UPDATE your 'RestReturnedModel' name with the appropiate returned model by your request."); + fileWithMissingRequests.newLine(); + fileWithMissingRequests.newLine(); + + File implReq = new File(String.format("implemented-requests-%s.txt", FilenameUtils.getBaseName(swaggerFilePath))); + implReq.delete(); + fileWithImplementedRequests = new BufferedWriter(new FileWriter(implReq)); + + for (Entry path : swagger.getPaths().entrySet()) + { + for (Map.Entry operation : path.getValue().getOperationMap().entrySet()) + { + searchPattern(path.getKey(),operation); + } + } + + System.out.println(toString()); + + fileWithImplementedRequests.close(); + fileWithMissingRequests.close(); + + if (missingRequestCount > 0) + { + System.out.println("[ERROR] PLEASE ANALYSE THE GENERATED file(s), it seems some request were NOT implemented!"); + } + else + missingReq.delete(); + + System.out.println("ALSO ANALYZE for current implementation, take a look at duplicated requests if any!"); + + + } + + /** + * Use RegExp to check for requests in code, line by line: no further algorithm performance analysis required at this time + * + * @param httpMethod + * @param pathUrl + * @param methodName + * @throws Exception + */ + private void searchPattern(String pathUrl, Entry operation) throws Exception + { + String originalPathUrl = pathUrl; + String httpMethod = operation.getKey().name(); + + /* update path url, removing first "/" as implemented in TAS requests. */ + if (pathUrl.startsWith("/")) + pathUrl = pathUrl.substring(1, pathUrl.length()); + + if (pathUrl.contains("{")) + pathUrl = pathUrl.replace("{", "\\{"); + + /* + * if in code we have something like: "(HttpMethod.GET, "process-definitions?{parameters}" + * our regular expression will search for text insider the 'HttpMethod.GET' concatenated with found 'pathUrl" until the optional double brackets + * RegExp: .*HttpMethod.%s.*\\\"%s\\\"?.* + * Result: .*HttpMethod.GET."process-definition".* - if this line is found we have a match + */ + String patternRegEx = String.format(".*HttpMethod.%s.*\\\"%s\\\"?.*", httpMethod, pathUrl); + + // all request are saved under this directory, but limited to the rest/request folder + File project = Paths.get(".").toAbsolutePath().normalize().toFile(); + Path requestsPath = Paths.get(project.getPath(), "src/main/java/org/alfresco/rest/requests"); + + BufferedReader br; + try (DirectoryStream directoryStream = Files.newDirectoryStream(requestsPath)) + { + boolean found = false; + + for (Path path : directoryStream) + { + if (Files.isRegularFile(path) && Files.isReadable(path)) + { + String line; + InputStream fis = new FileInputStream(path.toFile()); + InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8")); + br = new BufferedReader(isr); + + while ((line = br.readLine()) != null) + { + + if (line.matches(patternRegEx)) + { + // log("OK - Pattern %-60s found in: {%s} file." , originalPathUrl, path.getFileName()); + fileWithImplementedRequests.write(String.format("%-10s %-60s %s", httpMethod, pathUrl, path.getFileName())); + fileWithImplementedRequests.newLine(); + fileWithImplementedRequests.flush(); + implementedRequestCount += 1; + found = true; + } + } + br.close(); + } + } + + if (!found) + { + fileWithMissingRequests.write(String.format("%-10s %-60s %s", httpMethod, originalPathUrl, patternRegEx)); + fileWithMissingRequests.newLine(); + + SwaggerRequest swaggerReqModel = new SwaggerRequest(httpMethod, pathUrl, operation.getValue()); + fileWithMissingRequests.write(swaggerReqModel.getRequestSample()); + fileWithMissingRequests.flush(); + missingRequestCount += 1; + } + } + catch (IOException ex) + { + ex.printStackTrace(); + } + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append("|\n").append("|------------------------------------------------------------------------\n").append("COVERAGE: ") + .append(swaggerFilePath).append("\n"); + + int percentage = (implementedRequestCount * 100) / (implementedRequestCount + missingRequestCount); + sb.append("\t\tImplemented:\t").append(String.valueOf(percentage)).append("% [# ").append(implementedRequestCount).append("]\t Missing: "); + + percentage = (missingRequestCount * 100) / (implementedRequestCount + missingRequestCount); + sb.append(String.valueOf(percentage)).append("% [# ").append(missingRequestCount).append("]"); + return sb.toString(); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerRequest.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerRequest.java new file mode 100644 index 0000000000..fd93839520 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerRequest.java @@ -0,0 +1,52 @@ +package org.alfresco.rest.core.swagger; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import io.swagger.models.Operation; + +public class SwaggerRequest +{ + private Configuration cfg; + private Operation swaggerRequest; + private String httpMethod; + private String pathUrl; + + private Configuration getConfig() throws IOException + { + if (cfg == null) + { + cfg = new Configuration(Configuration.VERSION_2_3_23); + cfg.setDirectoryForTemplateLoading(new File("src/main/resources")); + } + return cfg; + } + + public SwaggerRequest(String httpMethod, String pathUrl, Operation swaggerRequest) + { + this.swaggerRequest = swaggerRequest; + this.httpMethod = httpMethod; + this.pathUrl = pathUrl; + } + + public String getRequestSample() throws Exception + { + Template template = getConfig().getTemplate("rest-request.ftl"); + Map data = new HashMap(); + data.put("operationId", swaggerRequest.getOperationId()); + data.put("httpMethod", httpMethod); + data.put("pathUrl", pathUrl); + + Writer append = new StringWriter(); + template.process(data, append); + + append.close(); + return append.toString(); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerYamlParser.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerYamlParser.java new file mode 100644 index 0000000000..5c8ddcb19f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/core/swagger/SwaggerYamlParser.java @@ -0,0 +1,79 @@ +package org.alfresco.rest.core.swagger; + +import org.alfresco.utility.exception.TestConfigurationException; + +import io.swagger.models.Swagger; +import io.swagger.parser.SwaggerParser; + +/** + * This will handle the Swagger YAML file + * It will contain all the models, request or any other properties needed for out generator + * + * @author Paul Brodner + */ +public class SwaggerYamlParser +{ + private Swagger swagger; + private String swaggerFilePath; + + public SwaggerYamlParser(String swaggerFilePath) throws TestConfigurationException + { + if (swaggerFilePath == null) + throw new TestConfigurationException("'swaggerFilePath' not defined. Please update your pom.xml file with all ''"); + + this.swaggerFilePath = swaggerFilePath; + this.swagger = new SwaggerParser().read(this.swaggerFilePath); + + } + + public void computeCoverage() throws Exception + { + new SwaggerPaths(swagger, this.swaggerFilePath).computeCoverage(); + } + + public void generateMissingModules() throws Exception + { + String modelParamValue = System.getProperty("models"); + + SwaggerDefinitions swaggerDefinitions = new SwaggerDefinitions(swagger); + + System.out.println(Generator.line); + System.out.println("Using SWAGGER FILE: " + this.swaggerFilePath); + System.out.println(Generator.line); + /* + * multiple models, separated by comma: 'mvn exec:java -Dmodels=a,b,d' + */ + if (modelParamValue.contains(",")) + { + String[] models = {}; + models = modelParamValue.split(","); + + for (int i = 0; i < models.length; i++) + { + // generate model + swaggerDefinitions.generateDefinition(models[i]); + } + } + else + { + /* + * if no value is added after models "mvn exec:java -Dmodels" + * then we assume that we want to generate all models + */ + if (modelParamValue.equals("true")) + { + swaggerDefinitions.generateMissingDefinitions(); + } + /* + * there is just one model passed as value "mvn exec:java -Dmodels=a" + * so only model "a" is generated locally + */ + else + { + swaggerDefinitions.generateDefinition(modelParamValue); + } + } + + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/RestDemoTests.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/RestDemoTests.java new file mode 100644 index 0000000000..80ba29199a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/RestDemoTests.java @@ -0,0 +1,104 @@ +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
+ * Perform GET sites call using admin user
+ * Check that created site is included in response
+ * Perform GET site call, validate that site title, description and visibility are correct
+ * + * @throws JsonToModelConversionException + * @throws Exception + */ + @Test(groups = { "demo" }) + public void adminRetrievesCorrectSiteDetails() throws JsonToModelConversionException, Exception + { + 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
+ * POST one comment to file using admin user
+ * Perform GET comments, check the new one is listed
+ * Update existing comment using PUT call, check that comment content is updated
+ * @throws Exception + */ + @Test(groups = { "demo" }) + public void adminCanPostAndUpdateComments() throws Exception + { + 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
+ * As admin, add user as Consumer to site as a new site member using POST call
+ * Update site member role to Manager using PUT call
+ * Delete site member using DELETE call
+ * + * @throws DataPreparationException + * @throws JsonToModelConversionException + */ + @Test(groups = { "demo" }) + public void adminCanAddAndUpdateSiteMemberDetails() throws Exception + { + 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); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SampleCommentsTests.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SampleCommentsTests.java new file mode 100644 index 0000000000..1151d4c2e9 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SampleCommentsTests.java @@ -0,0 +1,56 @@ +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() throws Exception + { + 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, Exception + { + restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + } + + @Test(groups = { "demo" }) + public void admiShouldRetrieveComments() throws Exception + { + restClient.withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @Test(groups = { "demo" }) + public void adminShouldUpdateComment() throws JsonToModelConversionException, Exception + { + 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"); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SamplePeopleTests.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SamplePeopleTests.java new file mode 100644 index 0000000000..6c0a2ff18f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SamplePeopleTests.java @@ -0,0 +1,32 @@ +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() throws Exception + { + restClient.withCoreAPI().usingUser(userModel).getPerson().assertThat().field("id").isNotEmpty(); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SampleSitesTests.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SampleSitesTests.java new file mode 100644 index 0000000000..f5c59e8a86 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/SampleSitesTests.java @@ -0,0 +1,79 @@ +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()); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/workshop/RestApiDemoTests.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/workshop/RestApiDemoTests.java new file mode 100644 index 0000000000..7492d80239 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/workshop/RestApiDemoTests.java @@ -0,0 +1,52 @@ +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() throws Exception + { + 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() throws Exception + { + 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 + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/workshop/RestApiWorkshopTests.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/workshop/RestApiWorkshopTests.java new file mode 100644 index 0000000000..88484bf665 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/demo/workshop/RestApiWorkshopTests.java @@ -0,0 +1,38 @@ +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() throws Exception + { + // 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() throws Exception + { + // 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 + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/EmptyJsonResponseException.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/EmptyJsonResponseException.java new file mode 100644 index 0000000000..885b9ccd84 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/EmptyJsonResponseException.java @@ -0,0 +1,11 @@ +package org.alfresco.rest.exception; + +public class EmptyJsonResponseException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public EmptyJsonResponseException(String message) + { + super(String.format("Empty JSON Response returned. Possible API bug, please investigate this further. Message: %s", message)); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/EmptyRestModelCollectionException.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/EmptyRestModelCollectionException.java new file mode 100644 index 0000000000..9afc19053f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/EmptyRestModelCollectionException.java @@ -0,0 +1,13 @@ +package org.alfresco.rest.exception; + +import java.util.Collection; + +public class EmptyRestModelCollectionException extends Exception +{ + private static final long serialVersionUID = 1L; + + public EmptyRestModelCollectionException(Collection models) + { + super(String.format("Empty Rest Model Collection of type: %s -> %s", models.getClass(), models.toString())); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/JsonToModelConversionException.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/JsonToModelConversionException.java new file mode 100644 index 0000000000..67d9e0650d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/exception/JsonToModelConversionException.java @@ -0,0 +1,13 @@ +package org.alfresco.rest.exception; + +public class JsonToModelConversionException extends RuntimeException +{ + + private static final long serialVersionUID = 1L; + + public JsonToModelConversionException(Class classz, Exception e) + { + super(String.format("Could not parse Json Response to model [%s] error: %s", classz.getName(), e.getMessage())); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActionDefinitionModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActionDefinitionModel.java new file mode 100644 index 0000000000..e6c6727e88 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActionDefinitionModel.java @@ -0,0 +1,121 @@ +package org.alfresco.rest.model; + +import java.util.List; +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; + +public class RestActionDefinitionModel extends TestModel implements IRestModel +{ + + @JsonProperty(value = "entry") + RestActionDefinitionModel actionDefinitionModel; + private String id; + private String name; + private String title; + private String description; + private List applicableTypes; + private boolean adhocPropertiesAllowed; + private boolean trackStatus; + private List parameterDefinitions; + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public List getApplicableTypes() + { + return applicableTypes; + } + + public void setApplicableTypes(List applicableTypes) + { + this.applicableTypes = applicableTypes; + } + + public boolean isAdhocPropertiesAllowed() + { + return adhocPropertiesAllowed; + } + + public void setAdhocPropertiesAllowed(boolean adhocPropertiesAllowed) + { + this.adhocPropertiesAllowed = adhocPropertiesAllowed; + } + + public boolean isTrackStatus() + { + return trackStatus; + } + + public void setTrackStatus(boolean trackStatus) + { + this.trackStatus = trackStatus; + } + + public List getParameterDefinitions() + { + return parameterDefinitions; + } + + public void setParameterDefinitions(List parameterDefinitions) + { + this.parameterDefinitions = parameterDefinitions; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public RestActionDefinitionModel onModel() + { + return actionDefinitionModel; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActionDefinitionModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActionDefinitionModelsCollection.java new file mode 100644 index 0000000000..d490db6df6 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActionDefinitionModelsCollection.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestActionDefinitionModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivityModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivityModel.java new file mode 100644 index 0000000000..1dce4252ff --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivityModel.java @@ -0,0 +1,150 @@ +package org.alfresco.rest.model; + +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; + +/** + * + * @author Cristina Axinte + * + * Handles single Activity JSON responses + * Example: + { + "postedAt": "2016-09-30T12:31:54.088+0000", + "feedPersonId": "user-vtcaquckbq", + "postPersonId": "user-vtcaquckbq", + "siteId": "site-mNygPRuKka", + "activitySummary": { + "firstName": "User-vtCaqUCKBq FirstName", + "lastName": "LN-User-vtCaqUCKBq", + "memberFirstName": "User-vtCaqUCKBq FirstName", + "role": "SiteManager", + "memberLastName": "LN-User-vtCaqUCKBq", + "title": "User-vtCaqUCKBq FirstName LN-User-vtCaqUCKBq (User-vtCaqUCKBq)", + "memberPersonId": "User-vtCaqUCKBq" + }, + "id": 14689, + "activityType": "org.alfresco.site.user-joined" + } + * + */ +public class RestActivityModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestActivityModel activityModel; + + @Override + public RestActivityModel onModel() + { + return activityModel; + } + + @JsonProperty(required = true) + String id; + + /** + * The id of the person who performed the activity + */ + @JsonProperty(required = true) + String postPersonId; + + String siteId; + String postedAt; + + /** + * The feed on which this activity was posted + */ + @JsonProperty(required = true) + String feedPersonId; + + RestActivitySummaryModel activitySummary; + + @JsonProperty(required = true) + String activityType; + + public String getActivityType() + { + return activityType; + } + + public void setActivityType(String activityType) + { + this.activityType = activityType; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getPostPersonId() + { + return postPersonId; + } + + public void setPostPersonId(String postPersonId) + { + this.postPersonId = postPersonId; + } + + public String getSiteId() + { + return siteId; + } + + public void setSiteID(String siteId) + { + this.siteId = siteId; + } + + public String getPostedAt() + { + return postedAt; + } + + public void setPostedAt(String postedAt) + { + this.postedAt = postedAt; + } + + public String getFeedPersonId() + { + return feedPersonId; + } + + public void setFeedPersonId(String feedPersonId) + { + this.feedPersonId = feedPersonId; + } + + public RestActivitySummaryModel getActivitySummary() + { + return activitySummary; + } + + public void setActivitySummary(RestActivitySummaryModel activitySummary) + { + this.activitySummary = activitySummary; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivityModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivityModelsCollection.java new file mode 100644 index 0000000000..10cdfc223e --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivityModelsCollection.java @@ -0,0 +1,44 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; +/** + * + * @author Cristina Axinte + * + * /** + * Handle collection of + * Example: +{ + "list": { + "pagination": { + "count": 3, + "hasMoreItems": false, + "skipCount": 0, + "maxItems": 100 + }, + "entries": [ + { + "entry": { + "postedAt": "2016-09-30T12:31:55.923+0000", + "feedPersonId": "user-vtcaquckbq", + "postPersonId": "user-vtcaquckbq", + "siteId": "site-mNygPRuKka", + "activitySummary": { + "firstName": "User-vtCaqUCKBq FirstName", + "lastName": "LN-User-vtCaqUCKBq", + "parentObjectId": "e982c6b7-e16e-4a25-ae77-5ed96614e871", + "title": "file-bWbaaGycDm.txt", + "objectId": "3a647ca9-cef9-45d0-ae4a-49cffa131154" + }, + "id": 14692, + "activityType": "org.alfresco.documentlibrary.file-added" + } + } + ] + } +} + * + */ +public class RestActivityModelsCollection extends RestModels +{ +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivitySummaryModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivitySummaryModel.java new file mode 100644 index 0000000000..a1c4eaad67 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestActivitySummaryModel.java @@ -0,0 +1,130 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * + * "activitySummary": { + "firstName": "string", + "lastName": "string", + "parentObjectId": "string", + "title": "string", + "objectId": "string" + } + * + * @author Cristina Axinte + * + */ +public class RestActivitySummaryModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestActivitySummaryModel activitySummaryModel; + + + @Override + public RestActivitySummaryModel onModel() + { + return activitySummaryModel; + } + + String firstName; + String lastName; + String parentObjectId; + String title; + String objectId; + String memberFirstName; + UserRole role; + String memberLastName; + String memberPersonId; + + public String getMemberFirstName() + { + return memberFirstName; + } + public void setMemberFirstName(String memberFirstName) + { + this.memberFirstName = memberFirstName; + } + public UserRole getRole() + { + return role; + } + public void setRole(UserRole role) + { + this.role = role; + } + public String getMemberLastName() + { + return memberLastName; + } + public void setMemberLastName(String memberLastName) + { + this.memberLastName = memberLastName; + } + public String getMemberPersonId() + { + return memberPersonId; + } + public void setMemberPersonId(String memberPersonId) + { + this.memberPersonId = memberPersonId; + } + + public String getFirstName() + { + return firstName; + } + public void setFirstName(String firstName) + { + this.firstName = firstName; + } + + public String getLastName() + { + return lastName; + } + public void setLastName(String lastName) + { + this.lastName = lastName; + } + + public String getParentObjectId() + { + return parentObjectId; + } + public void setParentObjectId(String parentObjectId) + { + this.parentObjectId = parentObjectId; + } + public String getTitle() + { + return title; + } + public void setTitle(String title) + { + this.title = title; + } + public String getObjectId() + { + return objectId; + } + public void setObjectId(String objectId) + { + this.objectId = objectId; + } + + @Override + public ModelAssertion and() { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() { + return new ModelAssertion(this); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAggregateModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAggregateModel.java new file mode 100644 index 0000000000..fdd1f472ac --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAggregateModel.java @@ -0,0 +1,55 @@ +package org.alfresco.rest.model; + +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; + +public class RestAggregateModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "aggregate") + RestAggregateModel model; + + @JsonProperty(required = true) + private int numberOfRatings; + private String average; + + @Override + public RestAggregateModel onModel() + { + return model; + } + + public int getNumberOfRatings() + { + return numberOfRatings; + } + + public void setNumberOfRatings(int numberOfRatings) + { + this.numberOfRatings = numberOfRatings; + } + + public String getAverage() + { + return average; + } + + public void setAverage(String average) + { + this.average = average; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditAppModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditAppModel.java new file mode 100644 index 0000000000..226d1bd0f0 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditAppModel.java @@ -0,0 +1,74 @@ +package org.alfresco.rest.model; + +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 'aepure' on '2017-06-29 15:31' 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} + */ +public class RestAuditAppModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestAuditAppModel model; + + @Override + public RestAuditAppModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String id; + + private String name; + + private boolean isEnabled; + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public boolean getIsEnabled() + { + return this.isEnabled; + } + + public void setIsEnabled(boolean isEnabled) + { + this.isEnabled = isEnabled; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditAppModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditAppModelsCollection.java new file mode 100644 index 0000000000..7e056d8a92 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditAppModelsCollection.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestAuditAppModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditEntryModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditEntryModel.java new file mode 100644 index 0000000000..b9d4ed0d9a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditEntryModel.java @@ -0,0 +1,94 @@ +package org.alfresco.rest.model; + +import java.util.Map; + +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; + +public class RestAuditEntryModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestAuditEntryModel model; + + @Override + public RestAuditEntryModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String id; + private String auditApplicationId ; + private String createdAt; + @JsonProperty("createdByUser") + private RestByUserModel createdByUser; + + @JsonProperty("values") + Map values; + +public Map getValues() + { + return values; + } + + public void setValues(Map values) + { + this.values = values; + } + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getAuditApplicationId() + { + return this.auditApplicationId; + } + + public void setAuditApplicationId(String auditApplicationId) + { + this.auditApplicationId = auditApplicationId; + } + + public RestByUserModel getCreatedByUser() + { + return this.createdByUser; + } + + public void setCreatedByUser(RestByUserModel createdByUser) + { + this.createdByUser = createdByUser; + } + + public String getCreatedAt() + { + return this.createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditEntryModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditEntryModelsCollection.java new file mode 100644 index 0000000000..a17a0d2ea8 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditEntryModelsCollection.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestAuditEntryModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditValuesModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditValuesModel.java new file mode 100644 index 0000000000..2b38dd5e31 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestAuditValuesModel.java @@ -0,0 +1,27 @@ +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +public class RestAuditValuesModel extends TestModel +{ + + public String getDisplayName() + { + return displayName; + } + public void setDisplayName(String displayName) + { + this.displayName = displayName; + } + public String getId() + { + return id; + } + public void setId(String id) + { + this.id = id; + } + private String displayName; + private String id; + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestByUserModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestByUserModel.java new file mode 100644 index 0000000000..76a673f9bf --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestByUserModel.java @@ -0,0 +1,32 @@ +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +/** + * Created by Claudia Agache on 11/11/2016. + */ +public class RestByUserModel extends TestModel +{ + private String displayName; + private String id; + + public String getDisplayName() + { + return displayName; + } + + public void setDisplayName(String displayName) + { + this.displayName = displayName; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCandidateModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCandidateModel.java new file mode 100644 index 0000000000..4fff805963 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCandidateModel.java @@ -0,0 +1,59 @@ +package org.alfresco.rest.model; + +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; + +public class RestCandidateModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestCandidateModel model; + + public enum CandidateType + { + USER, GROUP + } + + private String candidateType; + private String candidateId; + + @Override + public RestCandidateModel onModel() + { + return model; + } + + public String getCandidateType() + { + return candidateType; + } + + public void setCandidateType(String candidateType) + { + this.candidateType = candidateType; + } + + public String getCandidateId() + { + return candidateId; + } + + public void setCandidateId(String candidateId) + { + this.candidateId = candidateId; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCandidateModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCandidateModelsCollection.java new file mode 100644 index 0000000000..b3086b2d50 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCandidateModelsCollection.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestCandidateModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCommentModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCommentModel.java new file mode 100644 index 0000000000..8fd6b2c665 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCommentModel.java @@ -0,0 +1,132 @@ +package org.alfresco.rest.model; + +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; + +public class RestCommentModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestCommentModel model; + + @Override + public RestCommentModel onModel() + { + return model; + } + + private String createdAt; + private RestPersonModel createdBy; + private String edited; + private String modifiedAt; + private boolean canEdit; + private RestPersonModel modifiedBy; + private boolean canDelete; + private String id; + private String content; + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public String getEdited() + { + return edited; + } + + public void setEdited(String edited) + { + this.edited = edited; + } + + public String getContent() + { + return content; + } + + public void setContent(String content) + { + this.content = content; + } + + public RestPersonModel getCreatedBy() + { + return createdBy; + } + + public void RestPersonModel(RestPersonModel createdBy) + { + this.createdBy = createdBy; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public boolean isCanEdit() + { + return canEdit; + } + + public void setCanEdit(boolean canEdit) + { + this.canEdit = canEdit; + } + + public RestPersonModel getModifiedBy() + { + return modifiedBy; + } + + public void setModifiedBy(RestPersonModel modifiedBy) + { + this.modifiedBy = modifiedBy; + } + + public boolean isCanDelete() + { + return canDelete; + } + + public void setCanDelete(boolean canDelete) + { + this.canDelete = canDelete; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCommentModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCommentModelsCollection.java new file mode 100644 index 0000000000..cbe82ddb76 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCommentModelsCollection.java @@ -0,0 +1,7 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestCommentModelsCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCompanyModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCompanyModel.java new file mode 100644 index 0000000000..4405624305 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCompanyModel.java @@ -0,0 +1,119 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; + +/** + "company": { + "organization": "myCompany", + "address1": "Iasi", + "address2": "City", + "address3": "trei", + "postcode": "1234556", + "telephone": "564510213453", + "fax": "541", + "email": "qLZ41D2QnXQcqySNK09J@yahoo.com" + } + */ +public class RestCompanyModel extends TestModel +{ + private String organization; + private String address1; + private String address2; + private String address3; + private String postcode; + private String telephone; + private String fax; + private String email; + + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + public ModelAssertion and() + { + return assertThat(); + } + + public String getOrganization() + { + return organization; + } + + public void setOrganization(String organization) + { + this.organization = organization; + } + + public String getAddress1() + { + return address1; + } + + public void setAddress1(String address1) + { + this.address1 = address1; + } + + public String getAddress2() + { + return address2; + } + + public void setAddress2(String address2) + { + this.address2 = address2; + } + + public String getAddress3() + { + return address3; + } + + public void setAddress3(String address3) + { + this.address3 = address3; + } + + public String getPostcode() + { + return postcode; + } + + public void setPostcode(String postcode) + { + this.postcode = postcode; + } + + public String getTelephone() + { + return telephone; + } + + public void setTelephone(String telephone) + { + this.telephone = telephone; + } + + public String getFax() + { + return fax; + } + + public void setFax(String fax) + { + this.fax = fax; + } + + public String getEmail() + { + return email; + } + + public void setEmail(String email) + { + this.email = email; + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestContentModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestContentModel.java new file mode 100644 index 0000000000..e58e6c02a8 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestContentModel.java @@ -0,0 +1,54 @@ +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +/** + * Created by Claudia Agache on 11/11/2016. + */ +public class RestContentModel extends TestModel +{ + private int sizeInBytes; + private String mimeTypeName; + private String mimeType; + private String encoding; + + public int getSizeInBytes() + { + return sizeInBytes; + } + + public void setSizeInBytes(int sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } + + public String getMimeTypeName() + { + return mimeTypeName; + } + + public void setMimeTypeName(String mimeTypeName) + { + this.mimeTypeName = mimeTypeName; + } + + public String getMimeType() + { + return mimeType; + } + + public void setMimeType(String mimeType) + { + this.mimeType = mimeType; + } + + public String getEncoding() + { + return encoding; + } + + public void setEncoding(String encoding) + { + this.encoding = encoding; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCustomAspectModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCustomAspectModel.java new file mode 100644 index 0000000000..40cc4450ab --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCustomAspectModel.java @@ -0,0 +1,54 @@ +package org.alfresco.rest.model; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.CustomAspectModel; +import org.alfresco.utility.model.CustomAspectPropertiesModel; +import org.testng.Assert; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Bogdan Bocancea + */ +public class RestCustomAspectModel extends CustomAspectModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestCustomAspectModel model; + + @Override + public RestCustomAspectModel onModel() + { + return model; + } + + public RestCustomAspectModel assertHasProperties(CustomAspectPropertiesModel... propertiesName) + { + List propertiesModelName = new ArrayList(); + List properiesModel = getProperties(); + for (CustomAspectPropertiesModel model : properiesModel) + { + propertiesModelName.add(model.getName()); + } + for (CustomAspectPropertiesModel property : propertiesName) + { + Assert.assertTrue(propertiesModelName.contains(property.getName()), String.format("Property %s was found.", property.getName())); + } + return this; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCustomModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCustomModel.java new file mode 100644 index 0000000000..7e415c6306 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestCustomModel.java @@ -0,0 +1,34 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.CustomContentModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Bogdan Bocancea + */ +public class RestCustomModel extends CustomContentModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestCustomModel model; + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion<>(this); + } + + @Override + public RestCustomModel onModel() + { + return model; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDeploymentModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDeploymentModel.java new file mode 100644 index 0000000000..869d126fad --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDeploymentModel.java @@ -0,0 +1,98 @@ +package org.alfresco.rest.model; + +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; + +/** + * Handles single Deployment Entry JSON response + * "entry": { + * "id": "string", + * "name": "string", + * "category": "string", + * "deployedAt": "2016-10-04T13:15:36.222Z" + * } + * + * Created by Claudia Agache on 10/4/2016. + */ +public class RestDeploymentModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestDeploymentModel model; + + @Override + public RestDeploymentModel onModel() + { + return model; + } + + public RestDeploymentModel() + { + } + + public RestDeploymentModel(String id) + { + setId(id); + } + + + @JsonProperty(required = true) + private String id; + private String name; + private String category; + private String deployedAt; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getCategory() + { + return category; + } + + public void setCategory(String category) + { + this.category = category; + } + + public String getDeployedAt() + { + return deployedAt; + } + + public void setDeployedAt(String deployedAt) + { + this.deployedAt = deployedAt; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion<>(this); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDeploymentModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDeploymentModelsCollection.java new file mode 100644 index 0000000000..4382187084 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDeploymentModelsCollection.java @@ -0,0 +1,46 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; + +/** + * "entries": [ + * { + * "entry": { + * "name": "parallel-review-group.bpmn20.xml", + * "id": "17", + * "deployedAt": "2016-03-04T11:28:02.000+0000" + * } + * }, + * { + * "entry": { + * "name": "review.bpmn20.xml", + * "id": "5", + * "deployedAt": "2016-03-04T11:28:01.000+0000" + * } + * } + * ] + * Created by Claudia Agache on 10/4/2016. + */ +public class RestDeploymentModelsCollection extends RestModels +{ + + public RestDeploymentModel getDeploymentByName(String deploymentName) + { + STEP(String.format("REST API: Get deployment with name '%s'", deploymentName)); + List deploymentsList = getEntries(); + + for (RestDeploymentModel deploymentEntry: deploymentsList) + { + if (deploymentEntry.onModel().getName().equals(deploymentName)) + { + return deploymentEntry.onModel(); + } + } + + return null; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDiscoveryModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDiscoveryModel.java new file mode 100644 index 0000000000..453b44cf9f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDiscoveryModel.java @@ -0,0 +1,44 @@ +package org.alfresco.rest.model; + +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; + +public class RestDiscoveryModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestDiscoveryModel model; + + @Override + public RestDiscoveryModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private RestRepositoryInfoModel repository; + + public RestRepositoryInfoModel getRepository() + { + return repository; + } + + public void setRepository(RestRepositoryInfoModel repository) + { + this.repository = repository; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDownloadsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDownloadsModel.java new file mode 100644 index 0000000000..96fc222d65 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestDownloadsModel.java @@ -0,0 +1,135 @@ +package org.alfresco.rest.model; + +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; + +/* + * Handles responses for GET /downloads/{downloadId} and POST /downloads rest calls + * E.g + * { + * "entry": { + * "filesAdded": 1, + * "bytesAdded": 4, + * "totalBytes": 4, + * "id": "6ab1357c-bf13-4ecc-9c6e-3af0b6a7bb34", + * "totalFiles": 1, + * "status": "DONE" + * } + * } +*/ + +public class RestDownloadsModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestDownloadsModel model; + + @Override + public RestDownloadsModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String filesAdded; + + @JsonProperty(required = true) + private String bytesAdded; + + @JsonProperty(required = true) + private String totalBytes; + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = true) + private String totalFiles; + + @JsonProperty(required = true) + private String status; + + public RestDownloadsModel getModel() + { + return model; + } + + public void setModel(RestDownloadsModel model) + { + this.model = model; + } + + public String getFilesAdded() + { + return filesAdded; + } + + public void setFilesAdded(String filesAdded) + { + this.filesAdded = filesAdded; + } + + public String getBytesAdded() + { + return bytesAdded; + } + + public void setBytesAdded(String bytesAdded) + { + this.bytesAdded = bytesAdded; + } + + public String getTotalBytes() + { + return totalBytes; + } + + public void setTotalBytes(String totalBytes) + { + this.totalBytes = totalBytes; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getTotalFiles() + { + return totalFiles; + } + + public void setTotalFiles(String totalFiles) + { + this.totalFiles = totalFiles; + } + + public String getStatus() + { + return status; + } + + public void setStatus(String status) + { + this.status = status; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestElementModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestElementModel.java new file mode 100644 index 0000000000..233873fb16 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestElementModel.java @@ -0,0 +1,66 @@ +package org.alfresco.rest.model; + +import java.util.List; + +import org.alfresco.utility.model.TestModel; + +/** + * Created by Meenal Bhave + * "elements": [ + * { + * "aspectNames": ["cm:titled", "cm:auditable", "app:uifacets"], + * "id": "7f0c47ae-d334-4b66-a86b-1a60d2518ad1", + * "name": "Folder-oawzdncUXFLgnFe", + * "nodeType": "cm:folder" + * } + * ] + */ + +public class RestElementModel extends TestModel +{ + private String name; + private String id; + private List aspectNames; + private String nodeType; + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public List getAspectNames() + { + return aspectNames; + } + + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + public String getNodeType() + { + return nodeType; + } + + public void setNodeType(String nodeType) + { + this.nodeType = nodeType; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestEntitlementsInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestEntitlementsInfoModel.java new file mode 100644 index 0000000000..90cb32fc31 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestEntitlementsInfoModel.java @@ -0,0 +1,86 @@ +package org.alfresco.rest.model; + +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 'aforascu' on '2018-01-10 16:02' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api} + */ +public class RestEntitlementsInfoModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestEntitlementsInfoModel model; + + @Override + public RestEntitlementsInfoModel onModel() + { + return model; + } + + + private int maxUsers; + + private int maxDocs; + + private boolean isClusterEnabled; + + private boolean isCryptodocEnabled; + + public int getMaxUsers() + { + return this.maxUsers; + } + + public void setMaxUsers(int maxUsers) + { + this.maxUsers = maxUsers; + } + + public int getMaxDocs() + { + return this.maxDocs; + } + + public void setMaxDocs(int maxDocs) + { + this.maxDocs = maxDocs; + } + + public boolean getIsClusterEnabled() + { + return this.isClusterEnabled; + } + + public void setIsClusterEnabled(boolean isClusterEnabled) + { + this.isClusterEnabled = isClusterEnabled; + } + + public boolean getIsCryptodocEnabled() + { + return this.isCryptodocEnabled; + } + + public void setIsCryptodocEnabled(boolean isCryptodocEnabled) + { + this.isCryptodocEnabled = isCryptodocEnabled; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestErrorModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestErrorModel.java new file mode 100644 index 0000000000..f7b0f71923 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestErrorModel.java @@ -0,0 +1,187 @@ +package org.alfresco.rest.model; + +import org.springframework.http.HttpStatus; +import org.testng.Assert; + +public class RestErrorModel +{ + private String errorKey = ""; + private String logId = ""; + private int statusCode = 0; + + private String briefSummary = ""; + private String stackTrace = ""; + private String descriptionURL = ""; + public static String PERMISSION_WAS_DENIED = "Permission was denied"; + public static String ENTITY_NOT_FOUND = "%s was not found"; + public static String ENTITY_WAS_NOT_FOUND = "The entity with id: %s was not found"; + public static String RELATIONSHIP_NOT_FOUND = "The relationship resource was not found for the entity with id: %s and a relationship id of %s"; + public static String AUTHENTICATION_FAILED = "Authentication failed"; + public static String INVALID_ARGUMENT = "An invalid %s was received"; + public static String UNABLE_TO_LOCATE = "Unable to locate resource"; + public static String NULL_ARGUMENT = "Must provide a non-null %s"; + public static String CANNOT_COMMENT = "Cannot comment on this node"; + public static String NON_NULL_COMMENT = "Must provide a non-null comment"; + public static String INVALID_RATING = "Invalid ratingSchemeId %s"; + public static String NO_CONTENT = "Could not read content from HTTP request body: %s"; + public static String NULL_LIKE_RATING = "Rating should be non-null and a boolean for 'likes' rating scheme"; + public static String NULL_FIVESTAR_RATING = "Rating should be non-null and an integer for 'fiveStar' rating scheme"; + public static String CANNOT_RATE = "Cannot rate this node"; + public static String CANNOT_TAG = "Cannot tag this node"; + public static String NOT_SUFFICIENT_PERMISSIONS = "The current user does not have sufficient permissions to delete membership details of the site %s"; + public static String DELETE_EMPTY_ARGUMENT = "DELETE not supported for Actions"; + public static String PUT_EMPTY_ARGUMENT = "PUT is executed against the instance URL"; + public static String TASK_INVALID_STATE = "The task state property has an invalid value: %s"; + public static String INVALID_MAXITEMS = "Invalid paging parameter maxItems:%s"; + public static String INVALID_SKIPCOUNT = "Invalid paging parameter skipCount:%s"; + public static String INVALID_TAG = "Tag name must not contain %s char sequence"; + public static String EMPTY_TAG = "New tag cannot be null"; + public static String UNKNOWN_ROLE = "Unknown role '%s'"; + public static String ALREADY_Site_MEMBER = "%s is already a member of site %s"; + public static String ALREADY_INVITED = "%s is already invited to site %s"; + public static String NOT_A_MEMBER = "User is not a member of the site"; + public static String ONLY_POSITIVE_VALUES_MAXITEMS = "Only positive values supported for maxItems"; + public static String NEGATIVE_VALUES_SKIPCOUNT = "Negative values not supported for skipCount"; + public static String PROCESS_ENTITY_NOT_FOUND = "The entity with id: Item %s not found in the process package variable was not found"; + public static String MUST_PROVIDE_ROLE = "Must provide a role"; + public static String INVALID_ORDERBY = "OrderBy %s is not supported, supported items are [%s]"; + public static String ONLY_ONE_ORDERBY = "Only one orderBy parameter is supported"; + public static String INVALID_WHERE_QUERY = "An invalid WHERE query was received. %s"; + public static String PROCESS_RUNNING_IN_ANOTHER_TENANT = "Process is running in another tenant"; + public static String ILLEGAL_SCOPE = "Illegal value for variable scope: '%s'."; + public static String UNSUPPORTED_TYPE = "Unsupported type of variable: '%s'."; + public static String PROPERTY_DOES_NOT_EXIST = "The property selected for update does not exist for this resource: %s"; + public static String PROPERTY_IS_NOT_SUPPORTED_EQUALS = "The property '%s' with value '%s' isn't supported for EQUALS comparison"; + public static String INVALID_VALUE = "The %s property has an invalid value: %s"; + public static String REQUIRED_TO_ADD = "%s is required to add an attached item"; + public static String ACCESS_INFORMATION_NOT_ALLOWED = "user is not allowed to access information about process %s"; + public static String TASK_ALREADY_COMPLETED = "Task with id: %s cannot be updated, it's completed"; + public static String DELEGATED_TASK_CAN_NOT_BE_COMPLETED = "A delegated task cannot be completed, but should be resolved instead."; + public static String UNEXPECTED_TENANT = "Unexpected tenant: %s (contains %s)"; + public static String DELETE_LAST_MANAGER = "Can't remove last manager of site %s"; + public static String RATING_OUT_OF_BOUNDS = "Rating is out of bounds."; + public static String ACCEPT_ME= "Please accept me"; + public static String NO_WORKFLOW_DEFINITION_FOUND = "No workflow definition could be found with key '%s'."; + public static String INVALID_USER_ID = "%s is not a valid person user id"; + public static String TASK_ALREADY_CLAIMED = "The task is already claimed by another user."; + public static String INVALID_SELECT = "An invalid SELECT query was received"; + public static String DELEGATING_ASSIGNEE_PROVIDED = "When delegating a task, assignee should be selected and provided in the request."; + public static String INVALID_NAMEPACE_PREFIX="Namespace prefix %s is not mapped to a namespace URI"; + public static String FOR_INPUT_STRING ="For input string: \"%s\""; + public static String UNRECOGNIZED_FIELD ="Unrecognized field \"%s\""; + + public static String LOCAL_NAME_CONSISTANCE = "A QName must consist of a local name"; + public static String INVALID_PARAMETER_WHO = "Parameter who should be one of [me, others]"; + public static String NOT_FAVOURITE_SITE = "Site %s is not a favourite site"; + + public static String RESTAPIEXPLORER = "https://api-explorer.alfresco.com"; + public static String STACKTRACE = "For security reasons the stack trace is no longer displayed, but the property is kept for previous versions"; + public static String RELATIONSHIP_NOT_FOUND_ERRORKEY = "framework.exception.RelationshipNotFound"; + public static String ENTITY_NOT_FOUND_ERRORKEY = "framework.exception.EntityNotFound"; + public static String PERMISSION_DENIED_ERRORKEY = "framework.exception.PermissionDenied"; + public static String API_DEFAULT_ERRORKEY = "framework.exception.ApiDefault"; + public static String INVALID_QUERY_ERRORKEY = "framework.exception.InvalidQuery"; + public static String INVALID_PROPERTY_ERRORKEY = "framework.exception.InvalidProperty"; + public static String NOT_FOUND_ERRORKEY = "framework.exception.NotFound"; + public static String VARIABLE_NAME_REQUIRED = "Variable name is required."; + public static String MANDATORY_PARAM = "%s is a mandatory parameter"; + public static String MANDATORY_COLLECTION = "%s collection must contain at least one item"; + public static String INVALID_SELECT_ERRORKEY = "framework.exception.InvalidSelect"; + public static String LOCKED_NODE_OPERATION = "Cannot perform operation since the node (id:%s) is locked."; + public static String LOCKED_NODE_SUMMARY = "The node (id: %s) could not be locked since it is already locked by another user."; + + public String getErrorKey() + { + return errorKey; + } + + public void setErrorKey(String errorKey) + { + this.errorKey = errorKey; + } + + public int getStatusCode() + { + return statusCode; + } + + public void setStatusCode(int statusCode) + { + this.statusCode = statusCode; + } + + public String getBriefSummary() + { + return briefSummary; + } + + public void setBriefSummary(String briefSummary) + { + this.briefSummary = briefSummary; + } + + public String getStackTrace() + { + return stackTrace; + } + + public void setStackTrace(String stackTrace) + { + this.stackTrace = stackTrace; + } + + public String getDescriptionURL() + { + return descriptionURL; + } + + public void setDescriptionURL(String descriptionURL) + { + this.descriptionURL = descriptionURL; + } + + public String getLogId() + { + return logId; + } + + public void setLogId(String logId) + { + this.logId = logId; + } + + public RestErrorModel containsSummary(String summary) + { + if (!getBriefSummary().contains(summary)) + Assert.fail(String.format("Expected [%s] error to be found in actual briefSummary returned by server: %s", summary, getBriefSummary())); + return this; + } + + public RestErrorModel containsErrorKey(String expected) + { + if (!getErrorKey().contains(expected)) + Assert.fail(String.format("Expected [%s] error to be found in actual errorKey returned by server: %s", expected, getErrorKey())); + return this; + } + + public RestErrorModel statusCodeIs(HttpStatus statusCode) + { + if (getStatusCode() != statusCode.value()) + Assert.fail(String.format("Expected [%s] to be found. Actual statusCode returned by server is [%s]", statusCode, getStatusCode())); + return this; + } + + public RestErrorModel descriptionURLIs(String expected) + { + if (!getDescriptionURL().equals(expected)) + Assert.fail(String.format("Expected [%s] to be found. Actual descriptionURL returned by server is [%s]", expected, getDescriptionURL())); + return this; + } + + public RestErrorModel stackTraceIs(String expected) + { + if (!getStackTrace().equals(expected)) + Assert.fail(String.format("Expected [%s] to be found. Actual stackTrace returned by server is [%s]", expected, getStackTrace())); + return this; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFavoriteSiteModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFavoriteSiteModel.java new file mode 100644 index 0000000000..765510ba3f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFavoriteSiteModel.java @@ -0,0 +1,42 @@ +package org.alfresco.rest.model; + +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; + +public class RestFavoriteSiteModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestFavoriteSiteModel model; + + @JsonProperty(required = true) + String id; + + @Override + public RestFavoriteSiteModel onModel() + { + return model; + } + public String getId() + { + return id; + } + public void setId(String id) + { + this.id = id; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFileModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFileModel.java new file mode 100644 index 0000000000..beba040e2c --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFileModel.java @@ -0,0 +1,260 @@ +package org.alfresco.rest.model; + +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; + +/** + * Handles single Folder JSON responses + * Example: + "createdAt": "2016-10-03T09:48:52.385+0000", + "sizeInBytes": 19, + "versionLabel": "1.0", + "createdBy": "admin", + "modifiedAt": "2016-10-03T09:48:52.385+0000", + "name": "file-OUQAyqdsNi.txt", + "guid": "00f6b250-a841-4ff6-b660-5b45cee30497", + "modifiedBy": "admin", + "mimeType": "text/plain", + "id": "00f6b250-a841-4ff6-b660-5b45cee30497" + */ + +public class RestFileModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestFileModel model; + + @Override + public RestFileModel onModel() + { + return model; + } + + @JsonProperty(required = true) + protected String createdAt; + + @JsonProperty(required = true) + protected String sizeInBytes; + + @JsonProperty(required = true) + protected String versionLabel; + + @JsonProperty(required = true) + protected String createdBy; + + @JsonProperty(required = true) + protected String modifiedAt; + + @JsonProperty(required = true) + protected String name; + + @JsonProperty(required = true) + protected String guid; + + @JsonProperty(required = true) + protected String modifiedBy; + + @JsonProperty(required = true) + protected String mimeType; + + @JsonProperty(required = true) + protected String id; + + @JsonProperty(required = false) + RestPathModel path; + + private boolean isFile; + private boolean isFolder; + private RestByUserModel createdByUser; + private RestByUserModel modifiedByUser; + private RestContentModel content; + private String parentId; + + public RestFileModel() + { + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public String getSizeInBytes() + { + return sizeInBytes; + } + + public void setSizeInBytes(String sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } + + public String getVersionLabel() + { + return versionLabel; + } + + public void setVersionLabel(String versionLabel) + { + this.versionLabel = versionLabel; + } + + public String getCreatedBy() + { + return createdBy; + } + + public void setCreatedBy(String createdBy) + { + this.createdBy = createdBy; + } + + public String getModifiedBy() + { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) + { + this.modifiedBy = modifiedBy; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public String getGuid() + { + return guid; + } + + public void setGuid(String guid) + { + this.guid = guid; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getMimeType() + { + return mimeType; + } + + public void setMimeType(String mimeType) + { + this.mimeType = mimeType; + } + + public boolean getIsFile() + { + return isFile; + } + + public void setIsFile(boolean isFile) + { + this.isFile = isFile; + } + + public RestByUserModel getCreatedByUser() + { + return createdByUser; + } + + public void setCreatedByUser(RestByUserModel createdByUser) + { + this.createdByUser = createdByUser; + } + + public RestByUserModel getModifiedByUser() + { + return modifiedByUser; + } + + public void setModifiedByUser(RestByUserModel modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public RestContentModel getContent() + { + return content; + } + + public void setContent(RestContentModel content) + { + this.content = content; + } + + public String getParentId() + { + return parentId; + } + + public void setParentId(String parentId) + { + this.parentId = parentId; + } + + public boolean getIsFolder() + { + return isFolder; + } + + public void setIsFolder(boolean isFolder) + { + this.isFolder = isFolder; + } + + public RestPathModel getPath() + { + return path; + } + + public void setPath(RestPathModel path) + { + this.path = path; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFolderModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFolderModel.java new file mode 100644 index 0000000000..66ba7183c4 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFolderModel.java @@ -0,0 +1,207 @@ +package org.alfresco.rest.model; + +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; + +/** + * Handles single Folder JSON responses + * Example: + "createdAt": "2016-10-03T08:15:08.722+0000", + "createdBy": "admin", + "modifiedAt": "2016-10-03T08:15:08.722+0000", + "name": "Folder-EJJXzPAauf", + "guid": "fd84a762-7fea-4ed8-b9cd-7622ab966ac4", + "modifiedBy": "admin", + "id": "fd84a762-7fea-4ed8-b9cd-7622ab966ac4" + */ + +public class RestFolderModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestFolderModel model; + + @Override + public RestFolderModel onModel() + { + return model; + } + + @JsonProperty(required = true) + protected String createdAt; + + @JsonProperty(required = true) + protected String createdBy; + + @JsonProperty(required = true) + protected String modifiedAt; + + @JsonProperty(required = true) + protected String name; + + @JsonProperty(required = true) + protected String guid; + + @JsonProperty(required = true) + protected String modifiedBy; + + @JsonProperty(required = true) + protected String id; + + @JsonProperty(required = false) + RestPathModel path; + + private boolean isFolder; + private boolean isFile; + private RestByUserModel createdByUser; + private RestByUserModel modifiedByUser; + private String parentId; + + public RestFolderModel() + { + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public String getCreatedBy() + { + return createdBy; + } + + public void setCreatedBy(String createdBy) + { + this.createdBy = createdBy; + } + + public String getModifiedBy() + { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) + { + this.modifiedBy = modifiedBy; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public String getGuid() + { + return guid; + } + + public void setGuid(String guid) + { + this.guid = guid; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public boolean getIsFolder() + { + return isFolder; + } + + public void setIsFolder(boolean isFolder) + { + this.isFolder = isFolder; + } + + public boolean getIsFile() + { + return isFile; + } + + public void setIsFile(boolean isFile) + { + this.isFile = isFile; + } + + public RestByUserModel getCreatedByUser() + { + return createdByUser; + } + + public void setCreatedByUser(RestByUserModel createdByUser) + { + this.createdByUser = createdByUser; + } + + public RestByUserModel getModifiedByUser() + { + return modifiedByUser; + } + + public void setModifiedByUser(RestByUserModel modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public String getParentId() + { + return parentId; + } + + public void setParentId(String parentId) + { + this.parentId = parentId; + } + + public RestPathModel getPath() + { + return path; + } + + public void setPath(RestPathModel path) + { + this.path = path; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFormModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFormModel.java new file mode 100644 index 0000000000..171241c664 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFormModel.java @@ -0,0 +1,127 @@ +package org.alfresco.rest.model; + +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; + +/** + * Handles single representation of a Start Form Model + * * "entry": { + * "allowedValues": [ + * "1", + * "2", + * "3" + * ], + * "qualifiedName": "{http://www.alfresco.org/model/bpm/1.0}workflowPriority", + * "defaultValue": "2", + * "dataType": "d:int", + * "name": "bpm_workflowPriority", + * "title": "Workflow Priority", + * "required": false + * } + * Created by Claudia Agache on 10/18/2016. + */ +public class RestFormModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") RestFormModel model; + private String qualifiedName; + private String defaultValue; + private String dataType; + private String name; + private String title; + private String required; + private String[] allowedValues; + + public RestFormModel onModel() + { + return model; + } + + public String[] getAllowedValues() + { + return allowedValues; + } + + public void setAllowedValues(String[] allowedValues) + { + this.allowedValues = allowedValues; + } + + public String getQualifiedName() + { + return qualifiedName; + } + + public void setQualifiedName(String qualifiedName) + { + this.qualifiedName = qualifiedName; + } + + public String getDefaultValue() + { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) + { + this.defaultValue = defaultValue; + } + + public String getDataType() + { + return dataType; + } + + public void setDataType(String dataType) + { + this.dataType = dataType; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getRequired() + { + return required; + } + + public void setRequired(String required) + { + this.required = required; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFormModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFormModelsCollection.java new file mode 100644 index 0000000000..9e0c2b1ea1 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestFormModelsCollection.java @@ -0,0 +1,54 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * "entries": [ + * "entry": { + * "qualifiedName": "{http://www.alfresco.org/model/bpm/1.0}reassignable", + * "defaultValue": "true", + * "dataType": "d:boolean", + * "name": "bpm_reassignable", + * "required": false + * } + * }, + * { + * "entry": { + * "allowedValues": [ + * "1", + * "2", + * "3" + * ], + * "qualifiedName": "{http://www.alfresco.org/model/bpm/1.0}workflowPriority", + * "defaultValue": "2", + * "dataType": "d:int", + * "name": "bpm_workflowPriority", + * "title": "Workflow Priority", + * "required": false + * } + * }, + * ] + * Created by Claudia Agache on 10/18/2016. + */ +public class RestFormModelsCollection extends RestModels +{ + public RestFormModel getStartFormModelByQualifiedName(String qualifiedName) + { + STEP(String.format("REST API: Get start form model by qualified name '%s'", qualifiedName)); + List startFormModels = getEntries(); + + for (RestFormModel startFormModel: startFormModels) + { + if (startFormModel.onModel().getQualifiedName().equals(qualifiedName)) + { + return startFormModel.onModel(); + } + } + return null; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGenericBucketModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGenericBucketModel.java new file mode 100644 index 0000000000..cd1a81e7ef --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGenericBucketModel.java @@ -0,0 +1,131 @@ +package org.alfresco.rest.model; + +import java.util.List; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.rest.search.RestGenericMetricModel; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Generated by 'msuzuki' on '2017-05-15 13:08' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestGenericBucketModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestGenericBucketModel model; + + @Override + public RestGenericBucketModel onModel() + { + return model; + } + + /** + The bucket label + */ + + private String label; + /** + The filter query you can use to apply this facet + */ + + private String filterQuery; + /** + An optional field for additional display information + */ + + private Object display; + /** + An array of buckets and values + */ + + private List metrics; + /** + Additional list of nested facets + */ + + private List facets; + /** + Additional information of nested facet + */ + + private Object facetInfo; + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getFilterQuery() + { + return this.filterQuery; + } + + public void setFilterQuery(String filterQuery) + { + this.filterQuery = filterQuery; + } + + public Object getDisplay() + { + return this.display; + } + + public void setDisplay(Object display) + { + this.display = display; + } + + public List getMetrics() + { + return this.metrics; + } + + public void setMetrics(List metrics) + { + this.metrics = metrics; + } + + public List getFacets() + { + return this.facets; + } + + public void setFacets(List facets) + { + this.facets = facets; + } + + public Object getFacetInfo() + { + return this.facetInfo; + } + + public void setFacetInfo(Object facetInfo) + { + this.facetInfo = facetInfo; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupMember.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupMember.java new file mode 100644 index 0000000000..340c8d1c16 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupMember.java @@ -0,0 +1,69 @@ +package org.alfresco.rest.model; + +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; + +public class RestGroupMember extends TestModel implements IRestModel +{ + @JsonProperty(required = true) + private String id; + @JsonProperty(required = true) + private String displayName; + @JsonProperty(required = true) + private String memberType; + + @JsonProperty(value = "entry") + RestGroupMember model; + + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public RestGroupMember onModel() + { + return model; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getDisplayName() + { + return displayName; + } + + public void setDisplayName(String displayName) + { + this.displayName = displayName; + } + + public String getMemberType() + { + return memberType; + } + + public void setMemberType(String memberType) + { + this.memberType = memberType; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupMemberModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupMemberModelsCollection.java new file mode 100644 index 0000000000..720774d17b --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupMemberModelsCollection.java @@ -0,0 +1,7 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestGroupMemberModelsCollection extends RestModels +{ +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java new file mode 100644 index 0000000000..92fd3cc7ac --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java @@ -0,0 +1,96 @@ +package org.alfresco.rest.model; + +import java.util.ArrayList; + +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; + +public class RestGroupsModel extends TestModel implements IRestModel +{ + @JsonProperty(required = true) + private String id; + @JsonProperty(required = true) + private String displayName; + @JsonProperty(required = true) + private Boolean isRoot; + + @JsonProperty("parentIds") + private ArrayList parentIds; + @JsonProperty("zones") + private ArrayList zones; + + @JsonProperty(value = "entry") + RestGroupsModel model; + + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public RestGroupsModel onModel() + { + return model; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getDisplayName() + { + return displayName; + } + + public void setDisplayName(String displayName) + { + this.displayName = displayName; + } + + public Boolean getIsRoot() + { + return isRoot; + } + + public void setIsRoot(Boolean isRoot) + { + this.isRoot = isRoot; + } + + public ArrayList getParentIds() + { + return parentIds; + } + + public void setParentIds(ArrayList parentIds) + { + this.parentIds = parentIds; + } + + public ArrayList getZones() + { + return zones; + } + + public void setZones(ArrayList zones) + { + this.zones = zones; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModelsCollection.java new file mode 100644 index 0000000000..04088ca0fa --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModelsCollection.java @@ -0,0 +1,7 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestGroupsModelsCollection extends RestModels +{ +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestHtmlResponse.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestHtmlResponse.java new file mode 100644 index 0000000000..4fb41369f7 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestHtmlResponse.java @@ -0,0 +1,71 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.Utility; +import org.testng.Assert; + +import io.restassured.http.Headers; +import io.restassured.response.ResponseBody; + +/** + * Created by Claudia Agache on 10/13/2016. + */ +@SuppressWarnings("rawtypes") +public class RestHtmlResponse +{ + private Headers headers; + private ResponseBody body; + + /** + * @return the {@link ResponseBody} + */ + public ResponseBody getBody() + { + return body; + } + + public RestHtmlResponse(Headers headers, ResponseBody body) + { + this.headers = headers; + this.body = body; + } + + public void assertResponseContainsImage() throws Exception + { + STEP("REST API: Assert that response has an image."); + Utility.checkObjectIsInitialized(headers, "Headers"); + Utility.checkObjectIsInitialized(body, "Body"); + Assert.assertTrue(headers.getValue("content-type").contains("image/png"), + String.format("Content type is not an image. Actual content type is %s", headers.getValue("content-type"))); + Assert.assertNotEquals(headers.getValue("content-length"), "0", "Content length should be greater than 0 bytes."); + Assert.assertFalse(body.toString().isEmpty(), "Body should not be empty."); + } + + /** + * DSL for assertion on this rest model + * + * @return + */ + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + public ModelAssertion and() + { + return assertThat(); + } + + /** + * Assetion that a html element with specific html path has the specified value + * + * @param elementHtmlPath the HTML path of the HTML element + * @param value value of the field + */ + public void assertPathInHtmlBodyEquals(String elementHtmlPath, String value) + { + Assert.assertEquals(body.htmlPath().get(elementHtmlPath), value); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestItemModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestItemModel.java new file mode 100644 index 0000000000..c6846a2771 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestItemModel.java @@ -0,0 +1,120 @@ +package org.alfresco.rest.model; + +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; + +/** + * + "entry": { + "createdAt": "2016-10-13T11:21:34.621+0000", + "size": 19, + "createdBy": "admin", + "modifiedAt": "2016-10-13T11:21:38.338+0000", + "name": "file-yCQFYpLniWAzkcR.txt", + "modifiedBy": "User-cchKFZoNIAfZXXn", + "id": "ffb7178f-fc11-41c9-8c40-df6523ad917f", + "mimeType": "text/plain" + } + * + */ +public class RestItemModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestItemModel model; + + @JsonProperty(required = true) + private String createdAt; + private int size; + private String createdBy; + private String modifiedAt; + private String name; + private String modifiedBy; + private String id; + private String mimeType; + + @Override + public RestItemModel onModel() + { + return model; + } + + public String getCreatedAt() + { + return createdAt; + } + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + public int getSize() + { + return size; + } + public void setSize(int size) + { + this.size = size; + } + public String getCreatedBy() + { + return createdBy; + } + public void setCreatedBy(String createdBy) + { + this.createdBy = createdBy; + } + public String getName() + { + return name; + } + public void setName(String name) + { + this.name = name; + } + public String getModifiedBy() + { + return modifiedBy; + } + public void setModifiedBy(String modifiedBy) + { + this.modifiedBy = modifiedBy; + } + public String getId() + { + return id; + } + public void setId(String id) + { + this.id = id; + } + public String getMimeType() + { + return mimeType; + } + public void setMimeType(String mimeType) + { + this.mimeType = mimeType; + } + public String getModifiedAt() + { + return modifiedAt; + } + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestItemModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestItemModelsCollection.java new file mode 100644 index 0000000000..4d71ad9048 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestItemModelsCollection.java @@ -0,0 +1,44 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +import java.util.List; + +import static org.alfresco.utility.report.log.Step.STEP; + +/** + * Handles collection of Processes + * + * Example: + * "entries": [ + { + "entry": { + "createdAt": "2016-10-13T11:21:34.621+0000", + "size": 19, + "createdBy": "admin", + "modifiedAt": "2016-10-13T11:21:38.338+0000", + "name": "file-yCQFYpLniWAzkcR.txt", + "modifiedBy": "User-cchKFZoNIAfZXXn", + "id": "ffb7178f-fc11-41c9-8c40-df6523ad917f", + "mimeType": "text/plain" + } + } + ] + */ +public class RestItemModelsCollection extends RestModels +{ + public RestItemModel getProcessItemByName(String name) + { + STEP(String.format("REST API: Get process item entry with name '%s'", name)); + List processItemsList = getEntries(); + + for (RestItemModel item: processItemsList) + { + if (item.onModel().getName().equals(name)) + { + return item.onModel(); + } + } + return null; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestLicenseInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestLicenseInfoModel.java new file mode 100644 index 0000000000..3b1f4dcc1e --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestLicenseInfoModel.java @@ -0,0 +1,115 @@ +package org.alfresco.rest.model; + +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 'aforascu' on '2018-01-10 16:02' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api} + */ +public class RestLicenseInfoModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestLicenseInfoModel model; + + @Override + public RestLicenseInfoModel onModel() + { + return model; + } + + + @JsonProperty(required = true) + private String issuedAt; + + @JsonProperty(required = true) + private String expiresAt; + + @JsonProperty(required = true) + private int remainingDays; + + @JsonProperty(required = true) + private String holder; + + @JsonProperty(required = true) + private String mode; + + private RestEntitlementsInfoModel entitlements; + + public String getIssuedAt() + { + return this.issuedAt; + } + + public void setIssuedAt(String issuedAt) + { + this.issuedAt = issuedAt; + } + + public String getExpiresAt() + { + return this.expiresAt; + } + + public void setExpiresAt(String expiresAt) + { + this.expiresAt = expiresAt; + } + + public int getRemainingDays() + { + return this.remainingDays; + } + + public void setRemainingDays(int remainingDays) + { + this.remainingDays = remainingDays; + } + + public String getHolder() + { + return this.holder; + } + + public void setHolder(String holder) + { + this.holder = holder; + } + + public String getMode() + { + return this.mode; + } + + public void setMode(String mode) + { + this.mode = mode; + } + + public RestEntitlementsInfoModel getEntitlements() + { + return this.entitlements; + } + + public void setEntitlements(RestEntitlementsInfoModel entitlements) + { + this.entitlements = entitlements; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestModuleInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestModuleInfoModel.java new file mode 100644 index 0000000000..1a6ff1f065 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestModuleInfoModel.java @@ -0,0 +1,134 @@ +package org.alfresco.rest.model; + +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 'aforascu' on '2018-01-10 16:02' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api} + */ +public class RestModuleInfoModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestModuleInfoModel model; + + @Override + public RestModuleInfoModel onModel() + { + return model; + } + + + private String id; + + private String title; + + private String description; + + private String version; + + private String installDate; + + private String installState; + + private String versionMin; + + private String versionMax; + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getTitle() + { + return this.title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getDescription() + { + return this.description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getVersion() + { + return this.version; + } + + public void setVersion(String version) + { + this.version = version; + } + + public String getInstallDate() + { + return this.installDate; + } + + public void setInstallDate(String installDate) + { + this.installDate = installDate; + } + + public String getInstallState() + { + return this.installState; + } + + public void setInstallState(String installState) + { + this.installState = installState; + } + + public String getVersionMin() + { + return this.versionMin; + } + + public void setVersionMin(String versionMin) + { + this.versionMin = versionMin; + } + + public String getVersionMax() + { + return this.versionMax; + } + + public void setVersionMax(String versionMax) + { + this.versionMax = versionMax; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkModel.java new file mode 100644 index 0000000000..eb0390c3be --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkModel.java @@ -0,0 +1,83 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.UserModel; +import org.testng.Assert; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Created by Cristina Axinte on 9/26/2016. + * + * { + "entry": { + "id": "string", + "homeNetwork": true, + "isEnabled": true, + "createdAt": "2016-09-26T11:33:36.343Z", + "paidNetwork": true, + "subscriptionLevel": "Free", + "quotas": [ + { + "id": "string", + "limit": 0, + "usage": 0 + } + ] + } +} + * + */ +public class RestNetworkModel extends RestPersonNetworkModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestNetworkModel model; + + @Override + public RestNetworkModel onModel() + { + return model; + } + + public RestNetworkModel assertNetworkHasName(UserModel user) + { + STEP(String.format("REST API: Assert that network has name '%s'", user.getDomain())); + Assert.assertTrue(getId().equalsIgnoreCase(user.getDomain()), "Network doesn't have the expected name."); + + return this; + } + + public RestNetworkModel assertNetworkIsEnabled() + { + STEP(String.format("REST API: Assert network is enabled")); + Assert.assertEquals(isEnabled(), true, "Network should be enabled."); + + return this; + } + public RestNetworkModel assertNetworkIsNotEnabled() + { + STEP(String.format("REST API: Assert that network is disable")); + Assert.assertEquals(isEnabled(), false, "Network should be disabled."); + + return this; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkModelsCollection.java new file mode 100644 index 0000000000..b3751f92dc --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkModelsCollection.java @@ -0,0 +1,7 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestNetworkModelsCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkQuotaModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkQuotaModel.java new file mode 100644 index 0000000000..5d5afb6c11 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNetworkQuotaModel.java @@ -0,0 +1,74 @@ +package org.alfresco.rest.model; + +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 'pbrodner' on '2016-12-19 14:12' from 'Alfresco Core REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/alfresco/versions/1} + */ +public class RestNetworkQuotaModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestNetworkQuotaModel model; + + @Override + public RestNetworkQuotaModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = true) + private int limit; + + @JsonProperty(required = true) + private int usage; + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public int getLimit() + { + return this.limit; + } + + public void setLimit(int limit) + { + this.limit = limit; + } + + public int getUsage() + { + return this.usage; + } + + public void setUsage(int usage) + { + this.usage = usage; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssocTargetModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssocTargetModel.java new file mode 100644 index 0000000000..e21dcb1ca2 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssocTargetModel.java @@ -0,0 +1,68 @@ +package org.alfresco.rest.model; + +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; + +public class RestNodeAssocTargetModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "aggregate") + RestNodeAssocTargetModel model; + + @JsonProperty(required = true) + private String targetId; + @JsonProperty(required = true) + private String assocType; + + public RestNodeAssocTargetModel() + { + + } + + public RestNodeAssocTargetModel(String targetId, String assocType) + { + this.targetId = targetId; + this.assocType = assocType; + } + + @Override + public RestNodeAssocTargetModel onModel() + { + return model; + } + + public String getTargetId() + { + return targetId; + } + + public void setTargetId(String targetId) + { + this.targetId = targetId; + } + + public String getAssocType() + { + return assocType; + } + + public void setAssocType(String assocType) + { + this.assocType = assocType; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationModel.java new file mode 100644 index 0000000000..4c49931a39 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationModel.java @@ -0,0 +1,314 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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; + +/** + * Created by Andrei Forascu on 30/08/2017. + */ +public class RestNodeAssociationModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestNodeAssociationModel model; + + @Override + public RestNodeAssociationModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String id; + + /** + * The name must not contain spaces or the following special characters: * " < > \ / ? : and |. + * The character . must not be used at the end of the name. + */ + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + private String nodeType; + + @JsonProperty(required = true) + private boolean isFolder; + + @JsonProperty(required = true) + private boolean isFile; + + private boolean isLocked; + + @JsonProperty(required = true) + private String modifiedAt; + + @JsonProperty(required = true) + private RestByUserModel modifiedByUser; + + @JsonProperty(required = true) + private String createdAt; + + @JsonProperty + private String archivedAt; + + @JsonProperty + private RestByUserModel archivedByUser; + + @JsonProperty(required = true) + private RestByUserModel createdByUser; + + private String parentId; + + private boolean isLink; + + private RestContentModel content; + + private List aspectNames; + + private Object properties; + + private List allowableOperations; + + private Object path; + + private Object permissions; + + private RestNodeAssociationTypeModel association; + + public RestNodeAssociationTypeModel getAssociation() + { + return association; + } + + public void setAssociation(RestNodeAssociationTypeModel association) + { + this.association = association; + } + + public RestNodeAssociationModel getModel() + { + return model; + } + + public void setModel(RestNodeAssociationModel model) + { + this.model = model; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getNodeType() + { + return nodeType; + } + + public void setNodeType(String nodeType) + { + this.nodeType = nodeType; + } + + public boolean isFolder() + { + return isFolder; + } + + public void setFolder(boolean isFolder) + { + this.isFolder = isFolder; + } + + public boolean isFile() + { + return isFile; + } + + public void setFile(boolean isFile) + { + this.isFile = isFile; + } + + public boolean isLocked() + { + return isLocked; + } + + public void setLocked(boolean isLocked) + { + this.isLocked = isLocked; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public RestByUserModel getModifiedByUser() + { + return modifiedByUser; + } + + public void setModifiedByUser(RestByUserModel modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public String getArchivedAt() + { + return archivedAt; + } + + public void setArchivedAt(String archivedAt) + { + this.archivedAt = archivedAt; + } + + public RestByUserModel getArchivedByUser() + { + return archivedByUser; + } + + public void setArchivedByUser(RestByUserModel archivedByUser) + { + this.archivedByUser = archivedByUser; + } + + public RestByUserModel getCreatedByUser() + { + return createdByUser; + } + + public void setCreatedByUser(RestByUserModel createdByUser) + { + this.createdByUser = createdByUser; + } + + public String getParentId() + { + return parentId; + } + + public void setParentId(String parentId) + { + this.parentId = parentId; + } + + public boolean isLink() + { + return isLink; + } + + public void setLink(boolean isLink) + { + this.isLink = isLink; + } + + public RestContentModel getContent() + { + return content; + } + + public void setContent(RestContentModel content) + { + this.content = content; + } + + public List getAspectNames() + { + return aspectNames; + } + + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + public Object getProperties() + { + return properties; + } + + public void setProperties(Object properties) + { + this.properties = properties; + } + + public List getAllowableOperations() + { + return allowableOperations; + } + + public void setAllowableOperations(List allowableOperations) + { + this.allowableOperations = allowableOperations; + } + + public Object getPath() + { + return path; + } + + public void setPath(Object path) + { + this.path = path; + } + + public Object getPermissions() + { + return permissions; + } + + public void setPermissions(Object permissions) + { + this.permissions = permissions; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationModelCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationModelCollection.java new file mode 100644 index 0000000000..1933744830 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationModelCollection.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestNodeAssociationModelCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationTypeModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationTypeModel.java new file mode 100644 index 0000000000..1e825261ef --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeAssociationTypeModel.java @@ -0,0 +1,61 @@ +package org.alfresco.rest.model; + +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; + +/** + * Represents an association between two nodes + */ +public class RestNodeAssociationTypeModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestNodeAssociationTypeModel model; + + @Override + public RestNodeAssociationTypeModel onModel() + { + return model; + } + + @JsonProperty + private String assocType; + + @JsonProperty + private boolean isPrimary; + + public String getAssocType() + { + return assocType; + } + + public void setAssocType(String assocType) + { + this.assocType = assocType; + } + + public boolean isPrimary() + { + return isPrimary; + } + + public void setPrimary(boolean isPrimary) + { + this.isPrimary = isPrimary; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeBodyModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeBodyModel.java new file mode 100644 index 0000000000..699423f39b --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeBodyModel.java @@ -0,0 +1,142 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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 from 'Alfresco Core REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/alfresco/versions/1} + */ +public class RestNodeBodyModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestNodeBodyModel model; + + @Override + public RestNodeBodyModel onModel() + { + return model; + } + + /** + * The name must not contain spaces or the following special characters: * " < > \ / ? : and |. + * The character . must not be used at the end of the name. + */ + + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + private String nodeType; + + private List aspectNames; + + private Object properties; + + private String relativePath; + + private Object association; + + private List secondaryChildren; + + private List targets; + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getNodeType() + { + return this.nodeType; + } + + public void setNodeType(String nodeType) + { + this.nodeType = nodeType; + } + + + + public Object getProperties() + { + return this.properties; + } + + public void setProperties(Object properties) + { + this.properties = properties; + } + + public String getRelativePath() + { + return this.relativePath; + } + + public void setRelativePath(String relativePath) + { + this.relativePath = relativePath; + } + + public Object getAssociation() + { + return this.association; + } + + public void setAssociation(Object association) + { + this.association = association; + } + + public List getAspectNames() + { + return aspectNames; + } + + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + public List getSecondaryChildren() + { + return secondaryChildren; + } + + public void setSecondaryChildren(List secondaryChildren) + { + this.secondaryChildren = secondaryChildren; + } + + public List getTargets() + { + return targets; + } + + public void setTargets(List targets) + { + this.targets = targets; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeBodyMoveCopyModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeBodyMoveCopyModel.java new file mode 100644 index 0000000000..8114493c84 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeBodyMoveCopyModel.java @@ -0,0 +1,39 @@ +package org.alfresco.rest.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.alfresco.utility.model.TestModel; + +/** + * Destination Model used for passing the body parameters in the move node request + * + * @author Ana Bozianu + */ +public class RestNodeBodyMoveCopyModel extends TestModel +{ + @JsonProperty(required = true) + private String targetParentId; + + @JsonProperty + private String name; + + public String getTargetParentId() + { + return targetParentId; + } + + public void setTargetParentId(String targetParentId) + { + this.targetParentId = targetParentId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeChildAssocModelCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeChildAssocModelCollection.java new file mode 100644 index 0000000000..7c76e484fe --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeChildAssocModelCollection.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestNodeChildAssocModelCollection extends RestModels +{ + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeChildAssociationModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeChildAssociationModel.java new file mode 100644 index 0000000000..cfa692aac0 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeChildAssociationModel.java @@ -0,0 +1,69 @@ +package org.alfresco.rest.model; + +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; + +public class RestNodeChildAssociationModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public RestNodeChildAssociationModel onModel() + { + return model; + } + + @JsonProperty(value = "entry") + RestNodeChildAssociationModel model; + + @JsonProperty(required = true) + private String childId; + + @JsonProperty(required = true) + private String assocType; + + public RestNodeChildAssociationModel(String childId, String assocType) + { + this.childId = childId; + this.assocType = assocType; + } + + public RestNodeChildAssociationModel() + { + + } + + public String getChildId() + { + return childId; + } + + public void setChildId(String childId) + { + this.childId = childId; + } + + public String getAssocType() + { + return assocType; + } + + public void setAssocType(String assocType) + { + this.assocType = assocType; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeModel.java new file mode 100644 index 0000000000..7062d41b5c --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeModel.java @@ -0,0 +1,313 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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 from 'Alfresco Core REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/alfresco/versions/1} + */ +public class RestNodeModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestNodeModel model; + + @Override + public RestNodeModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String id; + + /** + * The name must not contain spaces or the following special characters: * " < > \ / ? : and |. + * The character . must not be used at the end of the name. + */ + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + private String nodeType; + + @JsonProperty(required = true) + private boolean isFolder; + + @JsonProperty(required = true) + private boolean isFile; + + private boolean isLocked; + + @JsonProperty(required = true) + private String modifiedAt; + + @JsonProperty(required = true) + private RestByUserModel modifiedByUser; + + @JsonProperty(required = true) + private String createdAt; + + @JsonProperty + private String archivedAt; + + @JsonProperty + private RestByUserModel archivedByUser; + + @JsonProperty(required = true) + private RestByUserModel createdByUser; + + private String parentId; + + private boolean isLink; + + private RestContentModel content; + + private List aspectNames; + + private Object properties; + + private List allowableOperations; + + private Object path; + + private Object permissions; + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getNodeType() + { + return this.nodeType; + } + + public void setNodeType(String nodeType) + { + this.nodeType = nodeType; + } + + public boolean getIsFolder() + { + return this.isFolder; + } + + public void setIsFolder(boolean isFolder) + { + this.isFolder = isFolder; + } + + public boolean getIsFile() + { + return this.isFile; + } + + public void setIsFile(boolean isFile) + { + this.isFile = isFile; + } + + public boolean getIsLocked() + { + return this.isLocked; + } + + public void setIsLocked(boolean isLocked) + { + this.isLocked = isLocked; + } + + public String getModifiedAt() + { + return this.modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public String getCreatedAt() + { + return this.createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public String getArchivedAt() + { + return this.archivedAt; + } + + public void setArchivedAt(String archivedAt) + { + this.archivedAt = archivedAt; + } + + public RestByUserModel getArchivedByUser() + { + return this.archivedByUser; + } + + public void setArchivedByUser(RestByUserModel archivedByUser) + { + this.archivedByUser = archivedByUser; + } + + public String getParentId() + { + return this.parentId; + } + + public void setParentId(String parentId) + { + this.parentId = parentId; + } + + public boolean getIsLink() + { + return this.isLink; + } + + public void setIsLink(boolean isLink) + { + this.isLink = isLink; + } + + public Object getProperties() + { + return this.properties; + } + + public void setProperties(Object properties) + { + this.properties = properties; + } + + public RestByUserModel getModifiedByUser() + { + return modifiedByUser; + } + + public void setModifiedByUser(RestByUserModel modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public RestByUserModel getCreatedByUser() + { + return createdByUser; + } + + public void setCreatedByUser(RestByUserModel createdByUser) + { + this.createdByUser = createdByUser; + } + + public RestContentModel getContent() + { + return content; + } + + public void setContent(RestContentModel content) + { + this.content = content; + } + + public List getAspectNames() + { + return aspectNames; + } + + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + public List getAllowableOperations() + { + return allowableOperations; + } + + public void setAllowableOperations(List allowableOperations) + { + this.allowableOperations = allowableOperations; + } + + public Object getPath() + { + return path; + } + + public void setPath(Object path) + { + this.path = path; + } + + public Object getPermissions() + { + return permissions; + } + + public void setPermissions(Object permissions) + { + this.permissions = permissions; + } + + public void setFolder(boolean isFolder) + { + this.isFolder = isFolder; + } + + public void setFile(boolean isFile) + { + this.isFile = isFile; + } + + public void setLocked(boolean isLocked) + { + this.isLocked = isLocked; + } + + public void setLink(boolean isLink) + { + this.isLink = isLink; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeModelsCollection.java new file mode 100644 index 0000000000..dd2b87cbb7 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestNodeModelsCollection.java @@ -0,0 +1,71 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handles collection of nodes. + * Example: + * { + "list": { + "pagination": { + "count": 2, + "hasMoreItems": false, + "totalItems": 2, + "skipCount": 0, + "maxItems": 100 + }, + "entries": [ + { + "entry": { + "createdAt": "2017-01-26T14:34:13.781+0000", + "isFolder": true, + "isFile": false, + "createdByUser": { + "id": "admin", + "displayName": "Administrator" + }, + "modifiedAt": "2017-01-26T14:34:13.781+0000", + "modifiedByUser": { + "id": "admin", + "displayName": "Administrator" + }, + "name": "my folder", + "id": "ad79ba3f-daf2-4446-be9b-9686a020a94a", + "nodeType": "cm:folder", + "parentId": "ab7eb66a-cfc4-4325-b0a5-a43a0a6ffecd" + } + }, + { + "entry": { + "createdAt": "2017-01-26T14:31:59.821+0000", + "isFolder": false, + "isFile": true, + "createdByUser": { + "id": "admin", + "displayName": "Administrator" + }, + "modifiedAt": "2017-01-26T14:31:59.821+0000", + "modifiedByUser": { + "id": "admin", + "displayName": "Administrator" + }, + "name": "my file", + "id": "6c93bff3-2174-4737-9c02-162df70a8549", + "nodeType": "cm:content", + "content": { + "mimeType": "text/plain", + "mimeTypeName": "Plain Text", + "sizeInBytes": 17, + "encoding": "UTF-8" + }, + "parentId": "ab7eb66a-cfc4-4325-b0a5-a43a0a6ffecd" + } + } + ] + } + } + */ +public class RestNodeModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPaginationModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPaginationModel.java new file mode 100644 index 0000000000..5b35f8f79e --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPaginationModel.java @@ -0,0 +1,88 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.assertion.IModelAssertion; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; + +/** + * Handles Pagination JSON + * + * Example: + * "pagination": { + "count": 100, + "hasMoreItems": true, + "totalItems": 269, + "skipCount": 0, + "maxItems": 100 + }, + */ +public class RestPaginationModel extends TestModel implements IModelAssertion +{ + private int count; + private boolean hasMoreItems; + private Integer totalItems; + private int skipCount; + private int maxItems; + + public int getCount() + { + return count; + } + + public void setCount(int count) + { + this.count = count; + } + + public boolean isHasMoreItems() + { + return hasMoreItems; + } + + public void setHasMoreItems(boolean hasMoreItems) + { + this.hasMoreItems = hasMoreItems; + } + + public Integer getTotalItems() + { + return totalItems; + } + + public void setTotalItems(Integer totalItems) + { + this.totalItems = totalItems; + } + + public int getSkipCount() + { + return skipCount; + } + + public void setSkipCount(int skipCount) + { + this.skipCount = skipCount; + } + + public int getMaxItems() + { + return maxItems; + } + + public void setMaxItems(int maxItems) + { + this.maxItems = maxItems; + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestParameterDefinitionModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestParameterDefinitionModel.java new file mode 100644 index 0000000000..564834d741 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestParameterDefinitionModel.java @@ -0,0 +1,109 @@ +package org.alfresco.rest.model; + +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; + +public class RestParameterDefinitionModel extends TestModel implements IRestModel +{ + private String name; + private String type; + private boolean multiValued; + private boolean mandatory; + private String displayLabel; + private String parameterConstraintName; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + public boolean isMultiValued() + { + return multiValued; + } + + public void setMultiValued(boolean multiValued) + { + this.multiValued = multiValued; + } + + public boolean isMandatory() + { + return mandatory; + } + + public void setMandatory(boolean mandatory) + { + this.mandatory = mandatory; + } + + public String getDisplayLabel() + { + return displayLabel; + } + + public void setDisplayLabel(String displayLabel) + { + this.displayLabel = displayLabel; + } + + public String getParameterConstraintName() + { + return parameterConstraintName; + } + + public void setParameterConstraintName(String parameterConstraintName) + { + this.parameterConstraintName = parameterConstraintName; + } + + public RestParameterDefinitionModel getParameterDefinitionModel() + { + return parameterDefinitionModel; + } + + public void setParameterDefinitionModel(RestParameterDefinitionModel parameterDefinitionModel) + { + this.parameterDefinitionModel = parameterDefinitionModel; + } + + @JsonProperty(value = "entry") + RestParameterDefinitionModel parameterDefinitionModel; + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public RestParameterDefinitionModel onModel() + { + return parameterDefinitionModel; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPathModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPathModel.java new file mode 100644 index 0000000000..7343f021a4 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPathModel.java @@ -0,0 +1,60 @@ +package org.alfresco.rest.model; + +import java.util.List; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Created by Meenal Bhave + * "path": { + * "name": "/Folder-oawzdncUXFLgnFe", + * "isComplete": false, + * "elements": [ + * { + * "aspectNames": ["cm:titled", "cm:auditable", "app:uifacets"], + * "id": "7f0c47ae-d334-4b66-a86b-1a60d2518ad1", + * "name": "Folder-oawzdncUXFLgnFe", + * "nodeType": "cm:folder" + * } + * ] + * } + */ +public class RestPathModel extends TestModel +{ + private String name; + @JsonProperty(value = "isComplete") + private boolean isComplete; + private List elements; + + public List getElements() + { + return elements; + } + + public void setElements(List elements) + { + this.elements = elements; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public boolean isComplete() + { + return isComplete; + } + + public void setComplete(boolean isComplete) + { + this.isComplete = isComplete; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonFavoritesModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonFavoritesModel.java new file mode 100644 index 0000000000..615af85b8b --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonFavoritesModel.java @@ -0,0 +1,78 @@ +package org.alfresco.rest.model; + +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; + +public class RestPersonFavoritesModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestPersonFavoritesModel model; + + @Override + public RestPersonFavoritesModel onModel() + { + return model; + } + + private String targetGuid; + private String createdAt; + + private RestTargetModel target; + + public RestPersonFavoritesModel() + { + } + + public RestPersonFavoritesModel(String targetGuid, String createdAt) + { + super(); + this.targetGuid = targetGuid; + this.createdAt = createdAt; + } + + public String getTargetGuid() + { + return targetGuid; + } + + public void setTargetGuid(String targetGuid) + { + this.targetGuid = targetGuid; + } + + public RestTargetModel getTarget() + { + return target; + } + + public void setTarget(RestTargetModel target) + { + this.target = target; + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion<>(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonFavoritesModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonFavoritesModelsCollection.java new file mode 100644 index 0000000000..f477f71b56 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonFavoritesModelsCollection.java @@ -0,0 +1,38 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * Example: +{ + "list": { + "pagination": { + "count": 1, + "hasMoreItems": false, + "totalItems": 1, + "skipCount": 0, + "maxItems": 100 + }, + "entries": [ + { + "entry": { + "targetGuid": "096babce-9f28-40d2-a38b-84b2ae41d71f", + "createdAt": "2016-09-26T13:04:42.066+0000", + "target": { + "site": { + "id": "site", + "guid": "096babce-9f28-40d2-a38b-84b2ae41d71f", + "title": "site", + "visibility": "PUBLIC", + "role": "SiteManager" + } + } + ] + } +} + */ + +public class RestPersonFavoritesModelsCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonModel.java new file mode 100644 index 0000000000..99c0a65a92 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonModel.java @@ -0,0 +1,335 @@ +package org.alfresco.rest.model; + +import java.util.List; +import java.util.Map; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.IModelAssertion; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Person Model implementation + */ +public class RestPersonModel extends TestModel implements IModelAssertion, IRestModel +{ + /** + * DSL for assertion on this rest model + * + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestPersonModel personModel; + + @Override + public RestPersonModel onModel() + { + return personModel; + } + + private List aspectNames; + + @JsonProperty(required = true) + private String firstName; + @JsonProperty(required = true) + private String id; + @JsonProperty(required = true) + private boolean enabled; + @JsonProperty(required = true) + private String email; + private String lastName; + private String displayName; + private boolean emailNotificationsEnabled; + + private RestCompanyModel company; + + private String avatarId; + private String location; + private String instantMessageId; + private String googleId; + private String skypeId; + private String description; + private String telephone; + private String jobTitle; + private String mobile; + private String statusUpdatedAt; + private String userStatus; + private String password; + private Object properties; + private Map capabilities; + + public RestPersonModel() + { + } + + public RestPersonModel(String firstName, boolean emailNotificationsEnabled, RestCompanyModel company, String id, boolean enabled, String email) + { + super(); + this.firstName = firstName; + this.emailNotificationsEnabled = emailNotificationsEnabled; + this.company = company; + this.id = id; + this.enabled = enabled; + this.email = email; + } + + public String getFirstName() + { + return firstName; + } + + public void setFirstName(String firstName) + { + this.firstName = firstName; + } + + public String getLastName() + { + return lastName; + } + + public void setLastName(String lastName) + { + this.lastName = lastName; + } + + public boolean getEmailNotificationsEnabled() + { + return emailNotificationsEnabled; + } + + public void setEmailNotificationsEnabled(boolean emailNotificationsEnabled) + { + this.emailNotificationsEnabled = emailNotificationsEnabled; + } + + public RestCompanyModel getCompany() + { + return company; + } + + public void setCompany(RestCompanyModel company) + { + this.company = company; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public boolean getEnabled() + { + return enabled; + } + + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + } + + public String getEmail() + { + return email; + } + + public void setEmail(String email) + { + this.email = email; + } + + public String getAvatarId() + { + return avatarId; + } + + public void setAvatarId(String avatarId) + { + this.avatarId = avatarId; + } + + public String getLocation() + { + return location; + } + + public void setLocation(String location) + { + this.location = location; + } + + public String getInstantMessageId() + { + return instantMessageId; + } + + public void setInstantMessageId(String instantMessageId) + { + this.instantMessageId = instantMessageId; + } + + public String getGoogleId() + { + return googleId; + } + + public void setGoogleId(String googleId) + { + this.googleId = googleId; + } + + public String getSkypeId() + { + return skypeId; + } + + public void setSkypeId(String skypeId) + { + this.skypeId = skypeId; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getTelephone() + { + return telephone; + } + + public void setTelephone(String telephone) + { + this.telephone = telephone; + } + + public String getJobTitle() + { + return jobTitle; + } + + public void setJobTitle(String jobTitle) + { + this.jobTitle = jobTitle; + } + + public String getMobile() + { + return mobile; + } + + public void setMobile(String mobile) + { + this.mobile = mobile; + } + + public String getStatusUpdatedAt() + { + return statusUpdatedAt; + } + + public void setStatusUpdatedAt(String statusUpdatedAt) + { + this.statusUpdatedAt = statusUpdatedAt; + } + + public String getUserStatus() + { + return userStatus; + } + + public void setUserStatus(String userStatus) + { + this.userStatus = userStatus; + } + + public List getAspectNames() + { + return aspectNames; + } + + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + public Object getProperties() + { + return properties; + } + + public void setProperties(Object properties) + { + this.properties = properties; + } + + public Map getCapabilities() + { + return capabilities; + } + + public void setCapabilities(Map capabilities) + { + this.capabilities = capabilities; + } + + public String getPassword() + { + return password; + } + + + public void setPassword(String password) + { + this.password = password; + } + + public String getDisplayName() + { + return displayName; + } + + public void setDisplayName(String displayName) + { + this.displayName = displayName; + } + + /** + * Generate a PersonModel with random values for all existing fields excluding fields specified as ingnoredFields + * + * @param ignoredFields field to be excluded when generating a random model + * @return + * @throws Exception + */ + public static RestPersonModel getRandomPersonModel(String... ignoredFields) throws Exception + { + RestPersonModel personModel = new RestPersonModel(); + setRandomValuesForAllFields(personModel, ignoredFields); + return personModel; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonModelsCollection.java new file mode 100644 index 0000000000..655a1cd3f3 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonModelsCollection.java @@ -0,0 +1,13 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; +/** + * Handle collection of + * + * @author Cristina Axinte + * + */ +public class RestPersonModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonNetworkModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonNetworkModel.java new file mode 100644 index 0000000000..ff872b5340 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPersonNetworkModel.java @@ -0,0 +1,109 @@ +package org.alfresco.rest.model; + +import java.util.List; + +import org.alfresco.utility.constants.NetworkSubscriptionLevel; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Created by Cristina Axinte on 9/26/2016. + */ +public class RestPersonNetworkModel extends TestModel +{ + @JsonProperty(required = true) + private String id; + + private boolean homeNetwork; + + @JsonProperty(required = true) + private boolean isEnabled; + + private String createdAt; + private boolean paidNetwork; + private NetworkSubscriptionLevel subscriptionLevel; + + private List quotas; + + public RestPersonNetworkModel() + { + } + + public RestPersonNetworkModel(String id, boolean isEnabled) + { + this.id = id; + this.isEnabled = isEnabled; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public boolean isHomeNetwork() + { + return homeNetwork; + } + + public void setHomeNetwork(boolean homeNetwork) + { + this.homeNetwork = homeNetwork; + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public boolean isPaidNetwork() + { + return paidNetwork; + } + + public void setPaidNetwork(boolean paidNetwork) + { + this.paidNetwork = paidNetwork; + } + + public NetworkSubscriptionLevel getSubscriptionLevel() + { + return subscriptionLevel; + } + + public void setSubscriptionLevel(NetworkSubscriptionLevel subscriptionLevel) + { + this.subscriptionLevel = subscriptionLevel; + } + + public List getQuotas() + { + return quotas; + } + + public void setQuotas(List quotas) + { + this.quotas = quotas; + } + + public boolean isEnabled() + { + return isEnabled; + } + + public void setEnabled(boolean isEnabled) + { + this.isEnabled = isEnabled; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPreferenceModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPreferenceModel.java new file mode 100644 index 0000000000..987bd0c1a1 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPreferenceModel.java @@ -0,0 +1,64 @@ +package org.alfresco.rest.model; + +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; + +/** + * Handles Pagination JSON + * + * Example: + * { + "entry": { + "id": "org.alfresco.share.sites.favourites.site-lwdxYDQFIi", + "value": true + } + * + * @author Cristina Axinte + */ +public class RestPreferenceModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestPreferenceModel model; + + @Override + public RestPreferenceModel onModel() + { + return model; + } + + @JsonProperty(required = true) + String id; + String value; + + public String getValue() + { + return value; + } + public void setValue(String value) + { + this.value = value; + } + public String getId() + { + return id; + } + public void setId(String id) + { + this.id = id; + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPreferenceModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPreferenceModelsCollection.java new file mode 100644 index 0000000000..cf5623000f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestPreferenceModelsCollection.java @@ -0,0 +1,37 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * { + * "list": { + * "pagination": { + * "count": 2, + * "hasMoreItems": false, + * "totalItems": 2, + * "skipCount": 0, + * "maxItems": 100 + * }, + * "entries": [ + * { + * "entry": { + * "id": "org.alfresco.ext.sites.favourites.site-lwdxYDQFIi.createdAt", + * "value": "2016-09-30T16:31:05.085Z" + * } + * }, + * { + * "entry": { + * "id": "org.alfresco.share.sites.favourites.site-lwdxYDQFIi", + * "value": true + * } + * } + * ] + * } + * } + * + * @author Cristina Axinte + */ +public class RestPreferenceModelsCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessDefinitionModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessDefinitionModel.java new file mode 100644 index 0000000000..aa377f1800 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessDefinitionModel.java @@ -0,0 +1,161 @@ +package org.alfresco.rest.model; + +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; + +/** + * Handles single Process Definition Entry JSON response + * "entry": { + * "deploymentId": "1", + * "name": "Adhoc Activiti Process", + * "description": "Assign a new task to yourself or a colleague", + * "id": "activitiAdhoc:1:4", + * "startFormResourceKey": "wf:submitAdhocTask", + * "category": "http://alfresco.org", + * "title": "New Task", + * "version": 1, + * "graphicNotationDefined": true, + * "key": "activitiAdhoc" + * } + * Created by Claudia Agache on 10/13/2016. + */ +public class RestProcessDefinitionModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestProcessDefinitionModel model; + + @JsonProperty(required = true) + private String id; + private String deploymentId; + private String name; + private String description; + private String startFormResourceKey; + private String category; + private String title; + private int version; + private boolean graphicNotationDefined; + private String key; + + @Override + public RestProcessDefinitionModel onModel() + { + return model; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getKey() + { + return key; + } + + public void setKey(String key) + { + this.key = key; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getCategory() + { + return category; + } + + public void setCategory(String category) + { + this.category = category; + } + + public String getDeploymentId() + { + return deploymentId; + } + + public void setDeploymentId(String deploymentId) + { + this.deploymentId = deploymentId; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getStartFormResourceKey() + { + return startFormResourceKey; + } + + public void setStartFormResourceKey(String startFormResourceKey) + { + this.startFormResourceKey = startFormResourceKey; + } + + public boolean getGraphicNotationDefined() + { + return graphicNotationDefined; + } + + public void setGraphicNotationDefined(boolean graphicNotationDefined) + { + this.graphicNotationDefined = graphicNotationDefined; + } + + public int getVersion() + { + return version; + } + + public void setVersion(int version) + { + this.version = version; + } + + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessDefinitionModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessDefinitionModelsCollection.java new file mode 100644 index 0000000000..4fda495a23 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessDefinitionModelsCollection.java @@ -0,0 +1,75 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * "entries": [ + * { + * "entry": { + * "deploymentId": "1", + * "name": "Adhoc Activiti Process", + * "description": "Assign a new task to yourself or a colleague", + * "id": "activitiAdhoc:1:4", + * "startFormResourceKey": "wf:submitAdhocTask", + * "category": "http://alfresco.org", + * "title": "New Task", + * "version": 1, + * "graphicNotationDefined": true, + * "key": "activitiAdhoc" + * } + * }, + * ] + * Created by Claudia Agache on 10/13/2016. + */ +public class RestProcessDefinitionModelsCollection extends RestModels +{ + public RestProcessDefinitionModel getProcessDefinitionByDeploymentId(String deploymentId) + { + STEP(String.format("REST API: Get process definition with deploymentId '%s'", deploymentId)); + List processDefinitionsList = getEntries(); + + for (RestProcessDefinitionModel processDefinitionEntry: processDefinitionsList) + { + if (processDefinitionEntry.onModel().getDeploymentId().equals(deploymentId)) + { + return processDefinitionEntry.onModel(); + } + } + return null; + } + + public RestProcessDefinitionModel getProcessDefinitionById(String id) + { + STEP(String.format("REST API: Get process definition with id '%s'", id)); + List processDefinitionsList = getEntries(); + + for (RestProcessDefinitionModel processDefinitionEntry: processDefinitionsList) + { + if (processDefinitionEntry.onModel().getId().equals(id)) + { + return processDefinitionEntry.onModel(); + } + } + return null; + } + + public RestProcessDefinitionModel getProcessDefinitionByKey(String key) + { + STEP(String.format("REST API: Get process definition with key '%s'", key)); + List processDefinitionsList = getEntries(); + + for (RestProcessDefinitionModel processDefinitionEntry: processDefinitionsList) + { + if (processDefinitionEntry.onModel().getKey().equals(key)) + { + return processDefinitionEntry.onModel(); + } + } + return null; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessModel.java new file mode 100644 index 0000000000..cca9ff4486 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessModel.java @@ -0,0 +1,149 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.IModelAssertion; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.ProcessModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Handles single Process Entry JSON response + * "entry": { + * "processDefinitionId": "activitiAdhoc:1:4", + * "startUserId": "admin", + * "startActivityId": "start", + * "startedAt": "2016-05-24T09:43:17.000+0000", + * "id": "55069", + * "completed": false, + * "processDefinitionKey": "activitiAdhoc" + * } + * Created by Claudia Agache on 10/11/2016. + */ +public class RestProcessModel extends ProcessModel implements IRestModel,IModelAssertion +{ + @JsonProperty(value = "entry") + RestProcessModel model; + + @Override + public RestProcessModel onModel() + { + return model; + } + + private String processDefinitionId; + private String startedAt; + private String startUserId; + private String startActivityId; + private String completed; + private String processDefinitionKey; + private String durationInMs; + private String endedAt; + private String deleteReason; + + public String getProcessDefinitionId() + { + return processDefinitionId; + } + + public void setProcessDefinitionId(String processDefinitionId) + { + this.processDefinitionId = processDefinitionId; + } + + public String getStartUserId() + { + return startUserId; + } + + public void setStartUserId(String startUserId) + { + this.startUserId = startUserId; + } + + public String getStartActivityId() + { + return startActivityId; + } + + public void setStartActivityId(String startActivityId) + { + this.startActivityId = startActivityId; + } + + public String getCompleted() + { + return completed; + } + + public void setCompleted(String completed) + { + this.completed = completed; + } + + public String getProcessDefinitionKey() + { + return processDefinitionKey; + } + + public void setProcessDefinitionKey(String processDefinitionKey) + { + this.processDefinitionKey = processDefinitionKey; + } + + public String getStartedAt() + { + return startedAt; + } + + public void setStartedAt(String startedAt) + { + this.startedAt = startedAt; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + public String getDurationInMs() + { + return durationInMs; + } + + public void setDurationInMs(String durationInMs) + { + this.durationInMs = durationInMs; + } + + public String getEndedAt() + { + return endedAt; + } + + public void setEndedAt(String endedAt) + { + this.endedAt = endedAt; + } + + public String getDeleteReason() + { + return deleteReason; + } + + public void setDeleteReason(String deleteReason) + { + this.deleteReason = deleteReason; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessModelsCollection.java new file mode 100644 index 0000000000..535c2d6d17 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessModelsCollection.java @@ -0,0 +1,51 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; + +/** + * Handles collection of Processes + * Example + * { + * "list": { + * "pagination": { + * "count": 100, + * "hasMoreItems": true, + * "totalItems": 849, + * "skipCount": 0, + * "maxItems": 100 + * , + * "entries": [ + * { + * "entry": { + * "processDefinitionId": "activitiAdhoc:1:4", + * "startUserId": "admin", + * "startActivityId": "start", + * "startedAt": "2016-05-24T09:43:17.000+0000", + * "id": "55069", + * "completed": false, + * "processDefinitionKey": "activitiAdhoc" + * } + * }, + * ] + * Created by Claudia Agache on 10/11/2016. + */ +public class RestProcessModelsCollection extends RestModels +{ + public RestProcessModel getProcessModelByProcessDefId(String processDefinitionId) + { + List processesList = getEntries(); + for (RestProcessModel processModel : processesList) + { + if (processModel.onModel().getId().equals(processDefinitionId)) + { + STEP(String.format("REST API: Get process with process definition '%s'", processDefinitionId)); + return processModel.onModel(); + } + } + return null; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessVariableCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessVariableCollection.java new file mode 100644 index 0000000000..f2ad1d30f2 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessVariableCollection.java @@ -0,0 +1,35 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +import java.util.List; + +import static org.alfresco.utility.report.log.Step.STEP; + +/** + * + "entries": [ + {"entry": { + "name": "bpm_package", + "type": "bpm:workflowPackage", + "value": "workspace://SpacesStore/ab728441-84f4-4d61-bb04-c51822b114fe" + }}, + * + */ +public class RestProcessVariableCollection extends RestModels +{ + public RestProcessVariableModel getProcessVariableByName(String name) + { + STEP(String.format("REST API: Get process variable entry with name '%s'", name)); + List processVariablesList = getEntries(); + + for (RestProcessVariableModel variable: processVariablesList) + { + if (variable.onModel().getName().equals(name)) + { + return variable.onModel(); + } + } + return null; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessVariableModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessVariableModel.java new file mode 100644 index 0000000000..68ffbacdf5 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestProcessVariableModel.java @@ -0,0 +1,85 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class RestProcessVariableModel extends TestModel implements IRestModel +{ + private String name; + + private String value; + + private String type; + + @JsonProperty(value = "entry") + RestProcessVariableModel model; + + public RestProcessVariableModel() + { + } + + public RestProcessVariableModel(String name, String value, String type) + { + this.name = name; + this.value = value; + this.type = type; + } + + @Override + public RestProcessVariableModel onModel() + { + return model; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + public static RestProcessVariableModel getRandomProcessVariableModel(String variableType){ + return new RestProcessVariableModel(RandomData.getRandomName("name"), RandomData.getRandomName("value"), variableType); + } + + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRatingModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRatingModel.java new file mode 100644 index 0000000000..12c00733b9 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRatingModel.java @@ -0,0 +1,78 @@ +package org.alfresco.rest.model; + +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; + +public class RestRatingModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestRatingModel model; + + @JsonProperty(required = true) + private String id; + + private String ratedAt; + private String myRating; + private RestAggregateModel aggregate; + + @Override + public RestRatingModel onModel() + { + return model; + } + + public RestAggregateModel getAggregate() + { + return aggregate; + } + + public void setAggregate(RestAggregateModel aggregate) + { + this.aggregate = aggregate; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getRatedAt() + { + return ratedAt; + } + + public void setRatedAt(String ratedAt) + { + this.ratedAt = ratedAt; + } + + public String getMyRating() + { + return myRating; + } + + public void setMyRating(String myRating) + { + this.myRating = myRating; + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion<>(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRatingModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRatingModelsCollection.java new file mode 100644 index 0000000000..5a7de7e484 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRatingModelsCollection.java @@ -0,0 +1,90 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; +import org.testng.Assert; + +/** + * Handle collection of +{ + "list": { + "pagination": { + "count": 0, + "hasMoreItems": true, + "totalItems": 0, + "skipCount": 0, + "maxItems": 0 + }, + "entries": [ + { + "entry": { + "id": "string", + "aggregate": { + "numberOfRatings": 0, + "average": 0 + }, + "ratedAt": "2016-09-28T13:56:58.931Z", + "myRating": "string" + } + } + ] + } +} + */ +public class RestRatingModelsCollection extends RestModels +{ + public RestRatingModelsCollection assertNodeIsLiked() + { + STEP("REST API: Assert that document is liked"); + Assert.assertTrue(getNumberOfRatingsFor("likes") > 0, "Node should have like ratings"); + + return this; + } + + public RestRatingModelsCollection assertNodeIsNotLiked() + { + STEP("REST API: Assert that document is not liked"); + Assert.assertTrue(getNumberOfRatingsFor("likes") == 0, "Node should have no like ratings"); + + return this; + } + + public RestRatingModelsCollection assertNodeHasFiveStarRating() + { + STEP("REST API: Assert that document has five star rating"); + Assert.assertTrue(getNumberOfRatingsFor("fiveStar") > 0, "Node should have five star ratings"); + + return this; + } + + public RestRatingModelsCollection assertNodeHasNoFiveStarRating() + { + STEP("REST API: Assert that document has no five star rating"); + Assert.assertTrue(getNumberOfRatingsFor("fiveStar") == 0, "Node should have no five star ratings"); + + return this; + } + + /** + * Default, the rating value can be: "likes" or "fiveStar" + * @param ratingValue + * @return + */ + public int getNumberOfRatingsFor(String ratingValue) + { + List ratings = getEntries(); + int noOfRatings = 0; + for (int i = 0; i < ratings.size(); i++) + { + if (ratings.get(i).onModel().getId().equals(ratingValue)) + { + noOfRatings = ratings.get(i).onModel().getAggregate().getNumberOfRatings(); + } + } + + return noOfRatings; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRenditionInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRenditionInfoModel.java new file mode 100644 index 0000000000..fc7f9d2517 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRenditionInfoModel.java @@ -0,0 +1,62 @@ +package org.alfresco.rest.model; + +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; + +/** + * @author cmocanu + * Base Path + * {@linkplain /alfresco/api/-default-/public/alfresco/versions/1} + */ + +public class RestRenditionInfoModel extends TestModel implements IRestModel { + + @Override + public ModelAssertion and() { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() { + return new ModelAssertion(this); + } + + @JsonProperty(value = "entry") + RestRenditionInfoModel model; + + @Override + public RestRenditionInfoModel onModel() { + return model; + } + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public RestContentModel getContent() { + return content; + } + + public void setContent(RestContentModel content) { + this.content = content; + } + + private String id; + private RestContentModel content; + private String status; + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRenditionInfoModelCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRenditionInfoModelCollection.java new file mode 100644 index 0000000000..dae53065bd --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRenditionInfoModelCollection.java @@ -0,0 +1,56 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * + * @author meenal bhave + * Example: + * { + * "list": + * { + * "pagination": + * { + * "count": 2, + * "hasMoreItems": false, + * "totalItems": 2, + * "skipCount": 0, + * "maxItems": 100 + * }, + * "entries": [ + * { + * "entry": + * { + * "id": "doclib", + * "content": + * { + * "mimeType": "image/png", + * "mimeTypeName": "PNG Image", + * "sizeInBytes": 414, + * "encoding": "UTF-8" + * }, + * "status": "CREATED" + * } + * }, + * { + * "entry": + * { + * "id": "pdf", + * "content": + * { + * "mimeType": "application/pdf", + * "mimeTypeName": "Adobe PDF Document", + * "sizeInBytes": 10144, + * "encoding": "UTF-8" + * }, + * "status": "CREATED" + * } + * } + * ] + * } + * } + */ +public class RestRenditionInfoModelCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRepositoryInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRepositoryInfoModel.java new file mode 100644 index 0000000000..4201d3a6ee --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRepositoryInfoModel.java @@ -0,0 +1,115 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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 'aforascu' on '2018-01-10 16:02' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api} + */ +public class RestRepositoryInfoModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRepositoryInfoModel model; + + @Override + public RestRepositoryInfoModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = true) + private String edition; + + @JsonProperty(required = true) + private RestVersionInfoModel version; + + @JsonProperty(required = true) + private RestStatusInfoModel status; + + private RestLicenseInfoModel license; + + private List modules; + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getEdition() + { + return this.edition; + } + + public void setEdition(String edition) + { + this.edition = edition; + } + + public RestVersionInfoModel getVersion() + { + return this.version; + } + + public void setVersion(RestVersionInfoModel version) + { + this.version = version; + } + + public RestStatusInfoModel getStatus() + { + return this.status; + } + + public void setStatus(RestStatusInfoModel status) + { + this.status = status; + } + + public RestLicenseInfoModel getLicense() + { + return this.license; + } + + public void setLicense(RestLicenseInfoModel license) + { + this.license = license; + } + + public List getModules() + { + return this.modules; + } + + public void setModules(List modules) + { + this.modules = modules; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRequestRangesModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRequestRangesModel.java new file mode 100644 index 0000000000..e3376bc037 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRequestRangesModel.java @@ -0,0 +1,175 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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 'msuzuki' on '2017-05-15 10:58' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestRangesModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestRangesModel model; + + @Override + public RestRequestRangesModel onModel() + { + return model; + } + + /** + The name of the field to perform range + */ + + private String field; + /** + The start of the range + */ + + private String start; + /** + The end of the range + */ + + private String end; + /** + Bucket size + */ + + private String gap; + /** + If true means that the last bucket will end at “end” even if it is less than “gap” wide. + */ + + private boolean hardend; + /** + before, after, between, non, all + */ + + private List other; + /** + lower, upper, edge, outer, all + */ + + private List include; + /** + Tags used exclude the filters from facet evaluation for multi-select facet support + */ + + private String label; + /** + Filter queries to exclude when calculating statistics + */ + + private List excludeFilters; + + public String getField() + { + return this.field; + } + + public void setField(String field) + { + this.field = field; + } + + public String getStart() + { + return this.start; + } + + public void setStart(String start) + { + this.start = start; + } + + public String getEnd() + { + return this.end; + } + + public void setEnd(String end) + { + this.end = end; + } + + public String getGap() + { + return this.gap; + } + + public void setGap(String gap) + { + this.gap = gap; + } + + public boolean getHardend() + { + return this.hardend; + } + + public void setHardend(boolean hardend) + { + this.hardend = hardend; + } + + public List getOther() + { + return this.other; + } + + public void setOther(List other) + { + this.other = other; + } + + public List getInclude() + { + return this.include; + } + + public void setInclude(List include) + { + this.include = include; + } + + public String getLabel() + { + return label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public List getExcludeFilters() + { + return this.excludeFilters; + } + + public void setExcludeFilters(List excludeFilters) + { + this.excludeFilters = excludeFilters; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRequestSpellcheckModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRequestSpellcheckModel.java new file mode 100644 index 0000000000..5e19ee16aa --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestRequestSpellcheckModel.java @@ -0,0 +1,50 @@ +package org.alfresco.rest.model; + +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 'msuzuki' on '2017-02-28 16:04' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestSpellcheckModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestSpellcheckModel model; + + @Override + public RestRequestSpellcheckModel onModel() + { + return model; + } + + + private String query; + + public String getQuery() + { + return this.query; + } + + public void setQuery(String query) + { + this.query = query; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSharedLinksModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSharedLinksModel.java new file mode 100644 index 0000000000..c84b405eab --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSharedLinksModel.java @@ -0,0 +1,190 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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 from 'Alfresco Core REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/alfresco/versions/1} + * + * @author Meenal Bhave + */ +public class RestSharedLinksModel extends TestModel implements IRestModel +{ + + public RestSharedLinksModel() + { + } + + public RestSharedLinksModel(String fileGuid) + { + super(); + this.nodeId = fileGuid; + } + + @JsonProperty(value = "entry") + RestSharedLinksModel model; + + @Override + public RestSharedLinksModel onModel() + { + return model; + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(required = true) + private String modifiedAt; + + @JsonProperty(required = true) + private RestByUserModel modifiedByUser; + + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = true) + private String nodeId; + + @JsonProperty(required = true) + private RestByUserModel sharedByUser; + + private RestContentModel content; + + @JsonProperty(required = false) + RestPathModel path; + + @JsonProperty(required = false) + private String expiresAt; + + @JsonProperty(required = false) + private List allowableOperations; + + public List getAllowableOperations() + { + return allowableOperations; + } + + public void setAllowableOperations(List allowableOperations) + { + this.allowableOperations = allowableOperations; + } + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getNodeType() + { + return this.nodeId; + } + + public void setNodeType(String nodeType) + { + this.nodeId = nodeType; + } + + public String getModifiedAt() + { + return this.modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public String getNodeId() + { + return nodeId; + } + + public void setNodeId(String nodeId) + { + this.nodeId = nodeId; + } + + public RestByUserModel getModifiedByUser() + { + return modifiedByUser; + } + + public void setModifiedByUser(RestByUserModel modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public RestByUserModel getSharedByUser() + { + return sharedByUser; + } + + public void setSharedByUser(RestByUserModel SharedByUser) + { + this.sharedByUser = SharedByUser; + } + + public RestContentModel getContent() + { + return content; + } + + public void setContent(RestContentModel content) + { + this.content = content; + } + + public RestPathModel getPath() + { + return path; + } + + public void setPath(RestPathModel path) + { + this.path = path; + } + + public String getExpiresAt() + { + return expiresAt; + } + + public void setExpiresAt(String expiresAt) + { + this.expiresAt = expiresAt; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSharedLinksModelCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSharedLinksModelCollection.java new file mode 100644 index 0000000000..d8e5774e3b --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSharedLinksModelCollection.java @@ -0,0 +1,78 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * + * @author meenal bhave + * Example: + * { + * "list": { + * "pagination": { + * "count": 1, + * "hasMoreItems": false, + * "totalItems": 1, + * "skipCount": 0, + * "maxItems": 100 + * }, + * "entries": [ + * { + * "entry": { + * "path": { + * "name": "/Company Home/Sites/sitePublic-LACmuuuWwbeBYeG/documentLibrary/Folder-uxxKzDflwxOuetG/Folder-oawzdncUXFLgnFe", + * "isComplete": true, + * "elements": [ + * { + * "id": "50e1fe3c-d60f-4088-8f79-c6c10031a379", + * "name": "Company Home" + * }, + * { + * "id": "ad7887fe-ac12-464e-ab26-486b0574959c", + * "name": "Sites" + * }, + * { + * "id": "98db769c-9fa1-47ed-b66c-37a59f2c7a3c", + * "name": "sitePublic-LACmuuuWwbeBYeG" + * }, + * { + * "id": "155ffb4f-0d81-4548-bde1-44c41f10b34d", + * "name": "documentLibrary" + * }, + * { + * "id": "bd1bb93b-bcc3-40d9-857b-5222880d1e4d", + * "name": "Folder-uxxKzDflwxOuetG" + * }, + * { + * "id": "7f0c47ae-d334-4b66-a86b-1a60d2518ad1", + * "name": "Folder-oawzdncUXFLgnFe" + * } + * ] + * }, + * "modifiedAt": "2017-08-01T09:53:20.784+0000", + * "modifiedByUser": { + * "id": "User-hleADFGrDvxsonw", + * "displayName": "User-hleADFGrDvxsonw FirstName LN-User-hleADFGrDvxsonw" + * }, + * "name": "file-CUNTdqhjLRaMPuQ.txt", + * "id": "UztDeg4hSju1DSVZHA3Zmg", + * "nodeId": "fe065c44-4be2-4231-affa-fee8617eb4e6", + * "sharedByUser": { + * "id": "user2", + * "displayName": "user2" + * }, + * "content": { + * "mimeType": "text/plain", + * "mimeTypeName": "Plain Text", + * "sizeInBytes": 19, + * "encoding": "ISO-8859-2" + * } + * } + * } + * ] + * } + * } + */ +public class RestSharedLinksModelCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteContainerModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteContainerModel.java new file mode 100644 index 0000000000..080673fbda --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteContainerModel.java @@ -0,0 +1,59 @@ +package org.alfresco.rest.model; + +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; + +public class RestSiteContainerModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestSiteContainerModel model; + + @Override + public RestSiteContainerModel onModel() + { + return model; + } + + private String id; + private String folderId; + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getFolderId() + { + return folderId; + } + + public void setFolderId(String folderId) + { + this.folderId = folderId; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteContainerModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteContainerModelsCollection.java new file mode 100644 index 0000000000..6128167361 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteContainerModelsCollection.java @@ -0,0 +1,30 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * Example: + * { + * "list": { + * "pagination": { + * "count": 1, + * "hasMoreItems": false, + * "totalItems": 1, + * "skipCount": 0, + * "maxItems": 100 + * }, + * "entries": [ + * { + * "entry": { + * "id": "d79666e2-3d77-4cbd-aa15-a1e0dcc4da1e", + * "folderId": "documentLibrary" + * } + * } + * ] + * } + * } + */ +public class RestSiteContainerModelsCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteEntry.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteEntry.java new file mode 100644 index 0000000000..9d61ff8862 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteEntry.java @@ -0,0 +1,93 @@ +package org.alfresco.rest.model; + +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; + +/** + * + * Handles Site Entry in Site Membership Information response + * + * "entry": /{ + "site": { + "id": "string", + "guid": "string", + "title": "string", + "description": "string", + "visibility": "PRIVATE", + "role": "SiteConsumer" + }, + "id": "string", + "guid": "string", + "role": "SiteConsumer" + } + * + */ +public class RestSiteEntry extends TestModel implements IRestModel +{ + private String role; + private String guid; + private String id; + + @JsonProperty(value = "site", required = true) + RestSiteModel site; + + @JsonProperty(value= "entry") + RestSiteEntry model; + + public RestSiteModel onSite() + { + return site; + } + + public String getRole() + { + return role; + } + + public void setRole(String role) + { + this.role = role; + } + + public String getGuid() { + return guid; + } + + public void setGuid(String guid) { + this.guid = guid; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public RestSiteEntry onModel() + { + return model; + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMemberModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMemberModel.java new file mode 100644 index 0000000000..29f25f2792 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMemberModel.java @@ -0,0 +1,81 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.TestModel; +import org.testng.Assert; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class RestSiteMemberModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestSiteMemberModel model; + + @Override + public RestSiteMemberModel onModel() + { + return model; + } + + private UserRole role; + private String id = "no-id"; + + private RestPersonModel person; + + public UserRole getRole() + { + return role; + } + + public void setRole(UserRole role) + { + this.role = role; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public RestPersonModel getPerson() + { + return person; + } + + public void setPerson(RestPersonModel person) + { + this.person = person; + } + + public RestSiteMemberModel assertSiteMemberHasRole(UserRole role) { + STEP(String.format("REST API: Assert that site member role is '%s'", role)); + Assert.assertEquals(getRole(), role, "Site member role is not as expected."); + + return this; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMemberModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMemberModelsCollection.java new file mode 100644 index 0000000000..7f1f9d529a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMemberModelsCollection.java @@ -0,0 +1,81 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * Example: + * { + * { + * "list": { + * "pagination": { + * "count": 2, + * "hasMoreItems": false, + * "skipCount": 0, + * "maxItems": 100 + * }, + * "entries": [ + * { + * "entry": { + * "role": "SiteManager", + * "person": { + * "firstName": "Administrator", + * "emailNotificationsEnabled": true, + * "company": {}, + * "id": "admin", + * "enabled": true, + * "email": "admin@alfresco.com" + * }, + * "id": "admin" + * } + * }, + * { + * "entry": { + * "role": "SiteConsumer", + * "person": { + * "firstName": "CqeKxvPHBd FirstName", + * "lastName": "LN-CqeKxvPHBd", + * "emailNotificationsEnabled": true, + * "company": {}, + * "id": "CqeKxvPHBd", + * "enabled": true, + * "email": "CqeKxvPHBd" + * }, + * "id": "CqeKxvPHBd" + * } + * } + * ] + * } + * } + */ +public class RestSiteMemberModelsCollection extends RestModels +{ + + /** + * Get member from site members list + * + * @param memberId + * @return + */ + public RestSiteMemberModel getSiteMember(String memberId) + { + STEP(String.format("REST API: Get site member with id '%s'", memberId)); + RestSiteMemberModel siteMemberEntry = null; + List siteMembers = getEntries(); + + for (int i = 1; i < siteMembers.size(); i++) + { + if (siteMembers.get(i).onModel().getId().equals(memberId)) + { + siteMemberEntry = siteMembers.get(i).onModel(); + } + } + + return siteMemberEntry; + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipModelsCollection.java new file mode 100644 index 0000000000..7f4ae66534 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipModelsCollection.java @@ -0,0 +1,41 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * + * Handle collection of + * + * { + "list": { + "pagination": { + "count": 0, + "hasMoreItems": true, + "totalItems": 0, + "skipCount": 0, + "maxItems": 0 + }, + "entries": [ + { + "entry": { + "site": { + "id": "string", + "guid": "string", + "title": "string", + "description": "string", + "visibility": "PRIVATE", + "role": "SiteConsumer" + }, + "id": "string", + "guid": "string", + "role": "SiteConsumer" + } + } + ] + } +} + * + */ +public class RestSiteMembershipModelsCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipRequestModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipRequestModel.java new file mode 100644 index 0000000000..246b3fbafc --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipRequestModel.java @@ -0,0 +1,99 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; +import org.testng.Assert; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class RestSiteMembershipRequestModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestSiteMembershipRequestModel model; + + @Override + public RestSiteMembershipRequestModel onModel() + { + return model; + } + + private String id; + private String createdAt; + private String modifiedAt; + private String message; + private RestSiteModel site; + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public String getMessage() + { + return message; + } + + public void setMessage(String message) + { + this.message = message; + } + + public RestSiteModel getSite() + { + return site; + } + + public void setSite(RestSiteModel site) + { + this.site = site; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public RestSiteMembershipRequestModel assertMembershipRequestMessageIs(String message) + { + Assert.assertEquals(getMessage(), message, "Site membership request message is not correct"); + return this; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipRequestModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipRequestModelsCollection.java new file mode 100644 index 0000000000..cf4c3b4335 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteMembershipRequestModelsCollection.java @@ -0,0 +1,42 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * + * { + "list": { + "pagination": { + "count": 0, + "hasMoreItems": true, + "totalItems": 0, + "skipCount": 0, + "maxItems": 0 + }, + "entries": [ + { + "entry": { + "id": "string", + "createdAt": "2016-10-06T08:24:04.910Z", + "site": { + "id": "string", + "guid": "string", + "title": "string", + "description": "string", + "visibility": "PRIVATE", + "role": "SiteConsumer" + }, + "message": "string" + } + } + ] + } +} + * + * @author Cristina Axinte + * + */ +public class RestSiteMembershipRequestModelsCollection extends RestModels +{ +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteModel.java new file mode 100644 index 0000000000..c40733b7b0 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteModel.java @@ -0,0 +1,68 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.SiteModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Handles single Site JSON responses + * Example: + * "visibility": "PUBLIC", + * "guid": "79e140e1-5039-4efa-acaf-c22b5ba7c947", + * "description": "Description1470255221170", + * "id": "0-C2291-1470255221170", + * "title": "0-C2291-1470255221170" + */ +public class RestSiteModel extends SiteModel implements IRestModel +{ + private String role; + + public String getPreset() + { + return preset; + } + + public void setPreset(String preset) + { + this.preset = preset; + } + + private String preset; + + @JsonProperty(value = "entry") + RestSiteModel model; + + @Override + public RestSiteModel onModel() + { + return model; + } + + public String getRole() + { + return role; + } + + public void setRole(String role) + { + this.role = role; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteModelsCollection.java new file mode 100644 index 0000000000..7dbdd7f53a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSiteModelsCollection.java @@ -0,0 +1,70 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; +import org.alfresco.utility.model.SiteModel; + +/** + * Handle collection of + * Example: +{ + "list": { + "pagination": { + "count": 100, + "hasMoreItems": true, + "totalItems": 269, + "skipCount": 0, + "maxItems": 100 + }, + "entries": [{ + "entry": { + "visibility": "PUBLIC", + "guid": "79e140e1-5039-4efa-acaf-c22b5ba7c947", + "description": "Description1470255221170", + "id": "0-C2291-1470255221170", + "title": "0-C2291-1470255221170" + } + }, + ] +} + * + */ +public class RestSiteModelsCollection extends RestModels +{ + + /** + * Get site from sites list + * + * @param siteId + * @return the site model or null if a site with this id wasn't found + */ + public RestSiteModel getSite(String siteId) + { + STEP(String.format("REST API: Get site with '%s' id", siteId)); + List sites = getEntries(); + + for (RestSiteModel site : sites) + { + if (site.onModel().getId().equals(siteId)) + { + return site.onModel(); + } + } + + return null; + } + + /** + * Get site from sites list + * + * @param siteId + * @return + */ + public RestSiteModel getSite(SiteModel siteModel) + { + return getSite(siteModel.getId()); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSitePersonMembershipRequestModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSitePersonMembershipRequestModel.java new file mode 100644 index 0000000000..673f256fc0 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSitePersonMembershipRequestModel.java @@ -0,0 +1,104 @@ +package org.alfresco.rest.model; + +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; + +public class RestSitePersonMembershipRequestModel extends TestModel implements IRestModel +{ + private String id; + private String createdAt; + private String modifiedAt; + private String message; + private RestSiteModel site; + + @JsonProperty(value = "person") + private RestPersonModel person; + + @JsonProperty(value = "entry") + RestSitePersonMembershipRequestModel model; + + public RestPersonModel getPersonModel() + { + return person; + } + + public void setPersonModel(RestPersonModel person) + { + this.person = person; + } + + @Override + public RestSitePersonMembershipRequestModel onModel() + { + return model; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public String getMessage() + { + return message; + } + + public void setMessage(String message) + { + this.message = message; + } + + public RestSiteModel getSite() + { + return site; + } + + public void setSite(RestSiteModel site) + { + this.site = site; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSitePersonMembershipRequestModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSitePersonMembershipRequestModelsCollection.java new file mode 100644 index 0000000000..69194b8427 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSitePersonMembershipRequestModelsCollection.java @@ -0,0 +1,48 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * + *{"list": { + "entries": [{"entry": { + "createdAt": "2018-03-08T07:51:54.948+0000", + "site": { + "visibility": "MODERATED", + "guid": "9d633bed-de72-414e-b188-c8e0ca42235a", + "description": "siteModerated-sHrfyEhnJcBqElEMODERATED", + "id": "siteModerated-sHrfyEhnJcBqElE", + "preset": "site-dashboard", + "title": "siteModerated-sHrfyEhnJcBqElE" + }, + "person": { + "firstName": "testUser-jvagwleqUCYSLeG FirstName", + "lastName": "LN-testUser-jvagwleqUCYSLeG", + "capabilities": { + "isMutable": true, + "isGuest": false, + "isAdmin": false + }, + "emailNotificationsEnabled": true, + "company": {}, + "id": "testUser-jvagwleqUCYSLeG", + "enabled": true, + "email": "testUser-jvagwleqUCYSLeG@tas-automation.org" + }, + "id": "siteModerated-sHrfyEhnJcBqElE", + "message": "Please accept me" + }}], + "pagination": { + "maxItems": 100, + "hasMoreItems": false, + "totalItems": 1, + "count": 1, + "skipCount": 0 + } + }} + */ +public class RestSitePersonMembershipRequestModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestStatusInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestStatusInfoModel.java new file mode 100644 index 0000000000..28b0b3ec54 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestStatusInfoModel.java @@ -0,0 +1,90 @@ +package org.alfresco.rest.model; + +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 'aforascu' on '2018-01-10 16:02' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api} + */ +public class RestStatusInfoModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestStatusInfoModel model; + + @Override + public RestStatusInfoModel onModel() + { + return model; + } + + + @JsonProperty(required = true) + private boolean isReadOnly; + + @JsonProperty(required = true) + private boolean isAuditEnabled; + + @JsonProperty(required = true) + private boolean isQuickShareEnabled; + + @JsonProperty(required = true) + private boolean isThumbnailGenerationEnabled; + + public boolean getIsReadOnly() + { + return this.isReadOnly; + } + + public void setIsReadOnly(boolean isReadOnly) + { + this.isReadOnly = isReadOnly; + } + + public boolean getIsAuditEnabled() + { + return this.isAuditEnabled; + } + + public void setIsAuditEnabled(boolean isAuditEnabled) + { + this.isAuditEnabled = isAuditEnabled; + } + + public boolean getIsQuickShareEnabled() + { + return this.isQuickShareEnabled; + } + + public void setIsQuickShareEnabled(boolean isQuickShareEnabled) + { + this.isQuickShareEnabled = isQuickShareEnabled; + } + + public boolean getIsThumbnailGenerationEnabled() + { + return this.isThumbnailGenerationEnabled; + } + + public void setIsThumbnailGenerationEnabled(boolean isThumbnailGenerationEnabled) + { + this.isThumbnailGenerationEnabled = isThumbnailGenerationEnabled; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSubscriberModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSubscriberModel.java new file mode 100644 index 0000000000..08d13dd827 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSubscriberModel.java @@ -0,0 +1,170 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +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; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * { + * "entry": { + * "createdAt": "2017-08-11T14:18:22.765+0000", + * "syncService": { + * "id": "0", + * "uri": "https://localhost:9090/alfresco", + * "config": { + * "filters": { + * "nodeAspects": [ + * "rma:filePlanComponent", + * "sf:*", + * "smf:*", + * "cm:workingcopy" + * ], + * "smartFolderNodeAspects": [ + * "sf:*", + * "smf:*" + * ], + * "nodeTypesWhitelist": [ + * "dod:filePlan", + * "hwf:rejectedCloudTask", + * "imap:imapBody", + * "st:site" + * ], + * "nodeTypes": [ + * "bpm:package", + * "cm:systemfolder", + * "cm:failedThumbnail" + * ] + * }, + * "dsyncClientVersionMin": "1.0.1", + * "repoInfo": { + * "versionLabel": "5.2.2", + * "edition": "Enterprise" + * } + * } + * }, + * "deviceOS": "windows", + * "syncServiceId": "0", + * "id": "089e45bd-a059-41f2-885e-c51f487956d6" + * } + * } + */ +public class RestSubscriberModel extends TestModel implements IRestModel +{ + + public RestSubscriberModel() + { + } + + public RestSubscriberModel(String deviceOS, String clientVersion) + { + super(); + this.deviceOS = deviceOS; + this.clientVersion = clientVersion; + } + + @JsonProperty(value = "entry") + RestSubscriberModel model; + + @Override + public RestSubscriberModel onModel() + { + return model; + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(required = true) + private String createdAt; + + @JsonProperty(required = true) + private RestSyncServiceModel syncService; + + @JsonProperty(required = true) + private String deviceOS; + + @JsonProperty(required = true) + private String syncServiceId; + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = false) + private String clientVersion; + + public String getClientVersion() + { + return clientVersion; + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public RestSyncServiceModel getSyncService() + { + return syncService; + } + + public void setSyncService(RestSyncServiceModel syncService) + { + this.syncService = syncService; + } + + public String getDeviceOS() + { + return deviceOS; + } + + public void setDeviceOS(String deviceOS) + { + this.deviceOS = deviceOS; + } + + public String getSyncServiceId() + { + return syncServiceId; + } + + public void setSyncServiceId(String syncServiceId) + { + this.syncServiceId = syncServiceId; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSubscriberModelCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSubscriberModelCollection.java new file mode 100644 index 0000000000..b93ad5d42d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSubscriberModelCollection.java @@ -0,0 +1,159 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * + * @author meenal bhave + * Example: + * { + "list": { + "pagination": { + "count": 20, + "hasMoreItems": false, + "totalItems": 20, + "skipCount": 0, + "maxItems": 100 + }, + "entries": [ + { + "entry": { + "createdAt": "2017-07-14T13:52:47.319+0000", + "syncService": { + "id": "0", + "uri": "https://localhost:9090/alfresco", + "config": { + "filters": { + "nodeAspects": [ + "rma:filePlanComponent", + "sf:*", + "smf:*", + "cm:workingcopy" + ], + "smartFolderNodeAspects": [ + "sf:*", + "smf:*" + ], + "nodeTypesWhitelist": [ + + ], + "nodeTypes": [ + "bpm:package", + "cm:systemfolder", + "cm:failedThumbnail" + ] + }, + "dsyncClientVersionMin": "1.0.1", + "repoInfo": { + "versionLabel": "5.2.2", + "edition": "Enterprise" + } + } + }, + "deviceOS": "windows", + "syncServiceId": "0", + "id": "da34e9e5-57c8-4275-b24a-373b9f56e6da" + } + }, + { + "entry": { + "createdAt": "2017-07-14T16:14:29.851+0000", + "syncService": { + "id": "0", + "uri": "https://localhost:9090/alfresco", + "config": { + "filters": { + "nodeAspects": [ + "rma:filePlanComponent", + "sf:*", + "smf:*", + "cm:workingcopy" + ], + "smartFolderNodeAspects": [ + "sf:*", + "smf:*" + ], + "nodeTypesWhitelist": [ + "dod:filePlan", + "hwf:rejectedCloudTask", + "imap:imapBody", + "st:site" + ], + "nodeTypes": [ + "bpm:package", + "cm:systemfolder", + "cm:failedThumbnail", + "rma:rmsite" + ] + }, + "dsyncClientVersionMin": "1.0.1", + "repoInfo": { + "versionLabel": "5.2.2", + "edition": "Enterprise" + } + } + }, + "deviceOS": "windows", + "syncServiceId": "0", + "id": "7c53fef9-d6fd-4657-830a-475850d6f04e" + } + }, + { + "entry": { + "createdAt": "2017-07-21T13:19:11.792+0000", + "syncService": { + "id": "0", + "uri": "https://localhost:9090/alfresco", + "config": { + "filters": { + "nodeAspects": [ + "rma:filePlanComponent", + "sf:*", + "smf:*", + "cm:workingcopy" + ], + "smartFolderNodeAspects": [ + "sf:*", + "smf:*" + ], + "nodeTypesWhitelist": [ + "dod:filePlan", + "hwf:rejectedCloudTask", + "imap:imapBody", + "st:site", + "resetpasswordwf:requestPasswordResetTask", + "rma:hold", + "rma:recordCategory", + "hwf:approvedCloudTask" + ], + "nodeTypes": [ + "bpm:package", + "cm:systemfolder", + "cm:failedThumbnail" + ] + }, + "dsyncClientVersionMin": "1.0.1", + "repoInfo": { + "versionLabel": "5.2.2", + "edition": "Enterprise" + } + } + }, + "deviceOS": "windows", + "syncServiceId": "0", + "id": "d9141278-8105-4986-a3f6-c003fdb3925e" + } + } + */ +public class RestSubscriberModelCollection extends RestModels +{ +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncNodeSubscriptionModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncNodeSubscriptionModel.java new file mode 100644 index 0000000000..faea143811 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncNodeSubscriptionModel.java @@ -0,0 +1,119 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +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; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * { + "entry": { + "deviceSubscriptionId": "012d6bf6-8b11-4dc3-bd45-6e4f77b48f67", + "createdAt": "2017-08-11T15:54:41.444+0000", + "targetPath": "/Company Home/Data Dictionary", + "state": "VALID", + "id": "5d120857-e155-44bc-9d1f-97ead5631090", + "targetNodeId": "20ad767c-4d86-4d9f-91a6-2e82fffa4e87" + } +} + */ +public class RestSyncNodeSubscriptionModel extends TestModel implements IRestModel +{ + + public RestSyncNodeSubscriptionModel() + { + } + + public RestSyncNodeSubscriptionModel(String targetNodeId, String subscriptionType) + { + super(); + this.createdAt = targetNodeId; + this.targetNodeId = subscriptionType; + } + + @JsonProperty(value = "entry") + RestSyncNodeSubscriptionModel model; + + @Override + public RestSyncNodeSubscriptionModel onModel() + { + return model; + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(required = true) + private String deviceSubscriptionId; + + @JsonProperty(required = true) + private String createdAt; + + @JsonProperty(required = true) + private String targetPath; + + @JsonProperty(required = true) + private String state; + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = true) + private String targetNodeId; + + public RestSyncNodeSubscriptionModel getModel() + { + return model; + } + + public String getDeviceSubscriptionId() + { + return deviceSubscriptionId; + } + + public String getCreatedAt() + { + return createdAt; + } + + public String getTargetPath() + { + return targetPath; + } + + public String getState() + { + return state; + } + + public String getId() + { + return id; + } + + public String getTargetNodeId() + { + return targetNodeId; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncNodeSubscriptionModelCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncNodeSubscriptionModelCollection.java new file mode 100644 index 0000000000..dcd1627a7a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncNodeSubscriptionModelCollection.java @@ -0,0 +1,54 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of + * + * @author meenal bhave + * Example: + * { + "list": { + "pagination": { + "count": 2, + "hasMoreItems": false, + "totalItems": 2, + "skipCount": 0, + "maxItems": 100 + }, + "entries": [ + { + "entry": { + "deviceSubscriptionId": "012d6bf6-8b11-4dc3-bd45-6e4f77b48f67", + "createdAt": "2017-07-28T10:15:35.461+0000", + "targetPath": "/Company Home/Data Dictionary", + "state": "VALID", + "id": "f1c346a9-4ba1-4357-bced-f9ad2164db43", + "targetNodeId": "20ad767c-4d86-4d9f-91a6-2e82fffa4e87" + } + }, + { + "entry": { + "deviceSubscriptionId": "012d6bf6-8b11-4dc3-bd45-6e4f77b48f67", + "createdAt": "2017-08-11T15:54:41.444+0000", + "targetPath": "/Company Home/Data Dictionary", + "state": "VALID", + "id": "5d120857-e155-44bc-9d1f-97ead5631090", + "targetNodeId": "20ad767c-4d86-4d9f-91a6-2e82fffa4e87" + } + } + ] + } +} + */ +public class RestSyncNodeSubscriptionModelCollection extends RestModels +{ +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceComponentModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceComponentModel.java new file mode 100644 index 0000000000..180212bf5a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceComponentModel.java @@ -0,0 +1,49 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/healthcheck} + * + * @author Meenal Bhave + * Example: + * + "healthCheckComponent": { + "healthy": true, + "message": "ActiveMQ connection Ok" + } +} + */ +public class RestSyncServiceComponentModel extends TestModel +{ + + public RestSyncServiceComponentModel() + { + } + + @JsonProperty(required = true) + private Boolean healthy; + + @JsonProperty + private String message; + + public Boolean getHealthy() + { + return healthy; + } + + public String getMessage() + { + return message; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceConfigFiltersModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceConfigFiltersModel.java new file mode 100644 index 0000000000..0821c56c74 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceConfigFiltersModel.java @@ -0,0 +1,107 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * "filters": { + * "nodeAspects": [ + * "rma:filePlanComponent", + * "sf:*", + * "smf:*", + * "cm:workingcopy" + * ], + * "smartFolderNodeAspects": [ + * "sf:*", + * "smf:*" + * ], + * "nodeTypesWhitelist": [ + * "dod:filePlan", + * "hwf:rejectedCloudTask", + * "imap:imapBody", + * "st:site" + * ], + * "nodeTypes": [ + * "bpm:package", + * "cm:systemfolder", + * "cm:failedThumbnail" + * ] + * }, + * "dsyncClientVersionMin": "1.0.1", + * "repoInfo": { + * "versionLabel": "5.2.2", + * "edition": "Enterprise" + * } + */ +public class RestSyncServiceConfigFiltersModel extends TestModel +{ + + public RestSyncServiceConfigFiltersModel() + { + } + + @JsonProperty(required = true) + private String[] nodeAspects; + + @JsonProperty + private String[] smartFolderNodeAspects; + + @JsonProperty(required = true) + private String[] nodeTypesWhitelist; + + @JsonProperty(required = true) + private String[] nodeTypes; + + public String[] getNodeAspects() + { + return nodeAspects; + } + + public void setNodeAspects(String[] nodeAspects) + { + this.nodeAspects = nodeAspects; + } + + public String[] getSmartFolderNodeAspects() + { + return smartFolderNodeAspects; + } + + public void setSmartFolderNodeAspects(String[] smartFolderNodeAspects) + { + this.smartFolderNodeAspects = smartFolderNodeAspects; + } + + public String[] getNodeTypesWhitelist() + { + return nodeTypesWhitelist; + } + + public void setNodeTypesWhitelist(String[] nodeTypesWhitelist) + { + this.nodeTypesWhitelist = nodeTypesWhitelist; + } + + public String[] getNodeTypes() + { + return nodeTypes; + } + + public void setNodeTypes(String[] nodeTypes) + { + this.nodeTypes = nodeTypes; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceConfigModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceConfigModel.java new file mode 100644 index 0000000000..5384a0cdc8 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceConfigModel.java @@ -0,0 +1,81 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * "config": { + "filters": { + "nodeAspects": [ + "rma:filePlanComponent", + "sf:*", + "smf:*", + "cm:workingcopy" + ], + "smartFolderNodeAspects": [ + "sf:*", + "smf:*" + ], + "nodeTypesWhitelist": [ + "dod:filePlan", + "hwf:rejectedCloudTask", + "imap:imapBody", + "st:site" + ], + "nodeTypes": [ + "bpm:package", + "cm:systemfolder", + "cm:failedThumbnail" + ] + }, + "dsyncClientVersionMin": "1.0.1", + "repoInfo": { + "versionLabel": "5.2.2", + "edition": "Enterprise" + } + } + */ +public class RestSyncServiceConfigModel extends TestModel +{ + + public RestSyncServiceConfigModel() + { + } + + @JsonProperty(required = true) + private String dsyncClientVersionMin; + + @JsonProperty(required = true) + private RestSyncServiceConfigFiltersModel filters; + + @JsonProperty(required = true) + private RestSyncServiceRepoInfoModel repoInfo; + + public String getDsyncClientVersionMin() + { + return dsyncClientVersionMin; + } + + public RestSyncServiceConfigFiltersModel getFilters() + { + return filters; + } + + public RestSyncServiceRepoInfoModel getRepoInfo() + { + return repoInfo; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceHealthCheckModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceHealthCheckModel.java new file mode 100644 index 0000000000..1f02ca55df --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceHealthCheckModel.java @@ -0,0 +1,124 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/healthcheck} + * + * @author Meenal Bhave + * Example: + * { + "activeMQConnection": { + "healthy": true, + "message": "ActiveMQ connection Ok" + }, + "databaseConnection": { + "healthy": true, + "message": "Database connection Ok" + }, + "deadlocks": { + "healthy": true + }, + "eventsHealthCheck": { + "healthy": true, + "message": "Ok" + }, + "minimumClientVersion": { + "healthy": true, + "message": "1.0.1" + }, + "repositoryConnection": { + "healthy": true, + "message": "Repository connection Ok" + }, + "syncServiceIdCheck": { + "healthy": true, + "message": "41ca6903-3b40-3154-b9ae-a406d83e02c9" + }, + "versionCheck": { + "healthy": true, + "message": "2.2-SNAPSHOT (2017-10-04T08:41:58Z)" + } +} + */ +public class RestSyncServiceHealthCheckModel extends TestModel +{ + + public RestSyncServiceHealthCheckModel() + { + } + + @JsonProperty(required = true) + private RestSyncServiceComponentModel activeMQConnection; + + @JsonProperty(required = true) + private RestSyncServiceComponentModel databaseConnection; + + @JsonProperty(required = true) + private RestSyncServiceComponentModel deadlocks; + + @JsonProperty(required = true) + private RestSyncServiceComponentModel eventsHealthCheck; + + @JsonProperty(required = true) + private RestSyncServiceComponentModel minimumClientVersion; + + @JsonProperty(required = true) + private RestSyncServiceComponentModel repositoryConnection; + + @JsonProperty(required = true) + private RestSyncServiceComponentModel syncServiceIdCheck; + + @JsonProperty(required = true) + private RestSyncServiceComponentModel versionCheck; + + public RestSyncServiceComponentModel getActiveMQConnection() + { + return activeMQConnection; + } + + public RestSyncServiceComponentModel getDatabaseConnection() + { + return databaseConnection; + } + + public RestSyncServiceComponentModel getDeadlocks() + { + return deadlocks; + } + + public RestSyncServiceComponentModel getEventsHealthCheck() + { + return eventsHealthCheck; + } + + public RestSyncServiceComponentModel getMinimumClientVersion() + { + return minimumClientVersion; + } + + public RestSyncServiceComponentModel getRepositoryConnection() + { + return repositoryConnection; + } + + public RestSyncServiceComponentModel getSyncServiceIdCheck() + { + return syncServiceIdCheck; + } + + public RestSyncServiceComponentModel getVersionCheck() + { + return versionCheck; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceModel.java new file mode 100644 index 0000000000..ceda3bda37 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceModel.java @@ -0,0 +1,85 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * "syncService": { + * "id": "0", + * "uri": "https://localhost:9090/alfresco", + * "config": { + * "filters": { + * "nodeAspects": [ + * "rma:filePlanComponent", + * "sf:*", + * "smf:*", + * "cm:workingcopy" + * ], + * "smartFolderNodeAspects": [ + * "sf:*", + * "smf:*" + * ], + * "nodeTypesWhitelist": [ + * "dod:filePlan", + * "hwf:rejectedCloudTask", + * "imap:imapBody", + * "st:site" + * ], + * "nodeTypes": [ + * "bpm:package", + * "cm:systemfolder", + * "cm:failedThumbnail" + * ] + * }, + * "dsyncClientVersionMin": "1.0.1", + * "repoInfo": { + * "versionLabel": "5.2.2", + * "edition": "Enterprise" + * } + * } + * } + */ +public class RestSyncServiceModel extends TestModel +{ + + public RestSyncServiceModel() + { + } + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = true) + private String uri; + + @JsonProperty(required = true) + private RestSyncServiceConfigModel config; + + public String getId() + { + return id; + } + + public String getUri() + { + return uri; + } + + public RestSyncServiceConfigModel getConfig() + { + return config; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceRepoInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceRepoInfoModel.java new file mode 100644 index 0000000000..109a818f3e --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncServiceRepoInfoModel.java @@ -0,0 +1,60 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * "repoInfo": { + * "versionLabel": "5.2.2", + * "edition": "Enterprise" + * } + */ +public class RestSyncServiceRepoInfoModel extends TestModel +{ + + public RestSyncServiceRepoInfoModel() + { + } + + @JsonProperty(required = true) + private String versionLabel; + + @JsonProperty(required = true) + private String edition; + + @JsonProperty(required = true) + private boolean clusterEnabled; + + public boolean isClusterEnabled() + { + return clusterEnabled; + } + + public String getVersionLabel() + { + return versionLabel; + } + + public void setVersionLabel(String versionLabel) + { + this.versionLabel = versionLabel; + } + + public String getEdition() + { + return edition; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetChangesModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetChangesModel.java new file mode 100644 index 0000000000..b1b07fcefe --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetChangesModel.java @@ -0,0 +1,297 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * "changes": [ + { + "conflict": false, + "skip": false, + "id": "1", + "username": "admin", + "type": "DELETE_REPOS", + "name": "2", + "toName": null, + "parentNodeIds": [ + "1007f928-3d95-402f-a9ac-35300c66f3fa", + "02a172dd-3156-4443-a216-d11bcd082ccc", + "e1f3777a-4eb3-4e49-9e65-ec52dbf21032", + "859d721e-07b4-4b8f-8a9e-122d45a1f9bb", + "5c9b0f55-eb3a-48ba-8532-c2877548291e", + "c0a5ad7b-cf36-47f1-85a6-6c0aafe242df" + ], + "toParentNodeIds": [], + "path": "/Company Home/Sites/primary/documentLibrary/5/2", + "toPath": null, + "nodeId": "aa667a0c-03bb-44b8-a65c-bdc95a90a6ac", + "eventTimestamp": 1505838692779, + "checksum": "dummyChecksum", + "size": -1, + "nodeType": "cm:folder", + "nodeTimestamp": 1505838597992, + "error": false, + "aspects": [ + "cm:titled", + "cm:auditable", + "sys:referenceable", + "sys:pendingDelete", + "sys:localized" + ], + "seqNo": 0, + "parentGroup": null, + "permission": null, + "async": false, + "authority": null, + "cascade": false + } + ] + */ + +public class RestSyncSetChangesModel extends TestModel +{ + + public RestSyncSetChangesModel() + { + } + + @JsonProperty(required = true) + private Boolean conflict; + + @JsonProperty(required = true) + private Boolean skip; + + @JsonProperty(required = true) + private String id; + + @JsonProperty(required = true) + private String username; + + @JsonProperty(required = true) + private String type; + + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + private String toName; + + @JsonProperty(required = true) + private String[] parentNodeIds; + + @JsonProperty(required = true) + private String[] toParentNodeIds; + + @JsonProperty(required = true) + private String path; + + @JsonProperty(required = true) + private String toPath; + + @JsonProperty(required = true) + private String nodeId; + + @JsonProperty(required = true) + private String eventTimestamp; + + @JsonProperty(required = true) + private String checksum; + + @JsonProperty(required = true) + private Integer size; + + @JsonProperty(required = true) + private String nodeType; + + @JsonProperty(required = true) + private String nodeTimestamp; + + @JsonProperty(required = true) + private Boolean error; + + @JsonProperty(required = true) + private String[] aspects; + + @JsonProperty(required = true) + private Integer seqNo; + + @JsonProperty(required = true) + private String parentGroup; + + @JsonProperty(required = true) + private String permission; + + @JsonProperty(required = true) + private Boolean async; + + @JsonProperty(required = true) + private String authority; + + @JsonProperty(required = true) + private Boolean cascade; + + @JsonProperty(required = true) + private boolean recordFromCollabSite; + + @JsonProperty(required = true) + private int numberOfSecondaryAssocs; + + + + public Boolean getConflict() + { + return conflict; + } + + public Boolean getSkip() + { + return skip; + } + + public String getId() + { + return id; + } + + public String getUsername() + { + return username; + } + + public String getType() + { + return type; + } + + public String getName() + { + return name; + } + + public String getToName() + { + return toName; + } + + public String[] getParentNodeIds() + { + return parentNodeIds; + } + + public String[] getToParentNodeIds() + { + return toParentNodeIds; + } + + public String getPath() + { + return path; + } + + public String getToPath() + { + return toPath; + } + + public String getNodeId() + { + return nodeId; + } + + public String getEventTimestamp() + { + return eventTimestamp; + } + + public String getCheckSum() + { + return checksum; + } + + public Integer getSize() + { + return size; + } + + public String getNodeType() + { + return nodeType; + } + + public String getNodeTimeStamp() + { + return nodeTimestamp; + } + + public Boolean getError() + { + return error; + } + + public String[] getAspects() + { + return aspects; + } + + public Integer getSeqNo() + { + return seqNo; + } + + public String getParentGroup() + { + return parentGroup; + } + + public String getPermissions() + { + return permission; + } + + public Boolean getAsync() + { + return async; + } + + public String getAuthority() + { + return authority; + } + + public Boolean getCascade() + { + return cascade; + } + + public boolean getRecordFromCollabSite() + { + return recordFromCollabSite; + } + + public void setRecordFromCollabSite(boolean recordFromCollabSite) + { + this.recordFromCollabSite = recordFromCollabSite; + } + + public int getNumberOfSecondaryAssocs() + { + return numberOfSecondaryAssocs; + } + + public void setNumberOfSecondaryAssocs(int numberOfSecondaryAssocs) + { + this.numberOfSecondaryAssocs = numberOfSecondaryAssocs; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetGetModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetGetModel.java new file mode 100644 index 0000000000..2d96102e39 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetGetModel.java @@ -0,0 +1,85 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * { + * "syncId": "8151", + * "status": "ready", + * "changes": [], + * "resets": [], + * "moreChanges": false, + * "message": "optional" + * } + */ + +public class RestSyncSetGetModel extends TestModel +{ + + public RestSyncSetGetModel() + { + } + + @JsonProperty + private String syncId; + + @JsonProperty(required = true) + private String status; + + // This field is only displayed when there is an error and syncID can not be returned e.g. sync db is down etc + @JsonProperty(required = false) + private String message; + + @JsonProperty(required = true) + private Boolean moreChanges; + + @JsonProperty(required = false) + private RestSyncSetChangesModel[] changes; + + @JsonProperty(required = false) + private RestSyncSetResetsModel[] resets; + + public String getSyncId() + { + return syncId; + } + + public String getStatus() + { + return status; + } + + public boolean getMoreChanges() + { + return moreChanges; + } + + public RestSyncSetChangesModel[] getChanges() + { + return changes; + } + + public RestSyncSetResetsModel[] getResets() + { + return resets; + } + + public String getMessage() + { + return message; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetRequestModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetRequestModel.java new file mode 100644 index 0000000000..972e46794c --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetRequestModel.java @@ -0,0 +1,72 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * { + * "syncId": "8096", + * "url": "/api/-default-/private/alfresco/versions/1/subscribers/925a2663-bc86-466d-9a49-95e9e8df7cde/subscriptions/7cfbd62d-2f9d-4c4e-bc3d-14234ae53d9e/sync/8096", + * "status": "ok", + * "message": null, + * "error": null + * } + */ + +public class RestSyncSetRequestModel extends TestModel +{ + + public RestSyncSetRequestModel() + { + } + + @JsonProperty(required = false) + private String message; + + @JsonProperty(required = false) + private String error; + + private String syncId; + + private String status; + + private String url; + + public String getSyncId() + { + return syncId; + } + + public String getUrl() + { + return url; + } + + public String getStatus() + { + return status; + } + + public String getMessage() + { + return message; + } + + public String getError() + { + return error; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetResetsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetResetsModel.java new file mode 100644 index 0000000000..aecb6f4831 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestSyncSetResetsModel.java @@ -0,0 +1,68 @@ +/* + * Copyright 2017 Alfresco Software, Ltd. All rights reserved. + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +package org.alfresco.rest.model; + +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Base Path {@linkplain /alfresco/api/-default-/private/alfresco/versions/1} + * + * @author Meenal Bhave + * Example: + * "resets": [ + * { + * "subscriptionId": "7787ac59-ec71-43c0-b97a-ebdba0254759", + * "resetAll": false, + * "resetReason": "Stale", + * "timestamp": 1502811227880 + * } + * ] + */ + +public class RestSyncSetResetsModel extends TestModel +{ + + public RestSyncSetResetsModel() + { + } + + @JsonProperty(required = true) + private String subscriptionId; + + @JsonProperty(required = true) + private String resetReason; + + @JsonProperty(required = true) + private Boolean resetAll; + + @JsonProperty(required = true) + private String timeStamp; + + public String getSubscriptionId() + { + return subscriptionId; + } + + public String getResetReason() + { + return resetReason; + } + + public Boolean getIsResetAll() + { + return resetAll; + } + + public String getTimeStamp() + { + return timeStamp; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTagModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTagModel.java new file mode 100644 index 0000000000..c615136fac --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTagModel.java @@ -0,0 +1,70 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TagModel; +import org.testng.Assert; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Handles single Tag Entry JSON response + * "entry": + * { + * "tag":"addedtag-c7444-1474370805346" + * "id":"f45c4d06-f4df-42d7-a118-29121557d284" + * } + * + * @author Corina Nechifor + */ +public class RestTagModel extends TagModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestTagModel model; + + protected Integer count; + + public RestTagModel onModel() + { + return model; + } + + public RestTagModel assertResponseIsNotEmpty() + { + STEP(String.format("REST API: Assert get tags response is not empty")); + Assert.assertFalse(getId().isEmpty(), "Get tags response is empty."); + + return this; + } + + /** + * DSL for assertion on this rest model + * @return + */ + public ModelAssertion and() + { + return new ModelAssertion(this); + } + + /** + * DSL for assertion on this rest model + * @return + */ + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + public Integer getCount() + { + return count; + } + + public void setCount(Integer count) + { + this.count = count; + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTagModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTagModelsCollection.java new file mode 100644 index 0000000000..6738c124b0 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTagModelsCollection.java @@ -0,0 +1,26 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + + +/** + * Handles collection of Tags + * + * "entries": + * [ + * {"entry": + * { "tag":"addedtag-c7444-1474370805346", + * "id":"f45c4d06-f4df-42d7-a118-29121557d284"} + * }, + * {"entry": + * {"tag":"addedtag-c7444-1474370863151", + * "id":"c05bdec5-1051-4413-9db6-0d3797f1cce5"} + * } + * + * @author Corina Nechifor + * + */ +public class RestTagModelsCollection extends RestModels +{ + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTargetModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTargetModel.java new file mode 100644 index 0000000000..3590e114ba --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTargetModel.java @@ -0,0 +1,100 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class RestTargetModel extends TestModel implements IRestModel +{ + @Override + public RestTargetModel onModel() + { + return model; + } + + @JsonProperty(value = "target") + RestTargetModel model; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private RestSiteModel site; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private RestFolderModel folder; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private RestFileModel file; + + public RestTargetModel() + { + } + + public RestTargetModel(RestSiteModel site) + { + super(); + this.site = site; + } + + public RestTargetModel(RestSiteModel site, RestFolderModel folder, RestFileModel file) + { + super(); + this.site = site; + this.folder = folder; + this.file = file; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public RestSiteModel getSite() + { + return site; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public void setSite(RestSiteModel site) + { + this.site = site; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public RestFolderModel getFolder() + { + return folder; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public void setFolder(RestFolderModel folder) + { + this.folder = folder; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public RestFileModel getFile() + { + return file; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public void setFile(RestFileModel file) + { + this.file = file; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTaskModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTaskModel.java new file mode 100644 index 0000000000..3cee8c647d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTaskModel.java @@ -0,0 +1,199 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TaskModel; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Handles single Task JSON response + * Example: + * "entry": { + "id": "string", + "processId": "string", + "processDefinitionId": "string", + "activityDefinitionId": "string", + "name": "string", + "description": "string", + "dueAt": "2016-10-11T09:53:02.549Z", + "startedAt": "2016-10-11T09:53:02.549Z", + "endedAt": "2016-10-11T09:53:02.549Z", + "durationInMs": 0, + "priority": 0, + "owner": "string", + "assignee": "string", + "formResourceKey": "string", + "state": "unclaimed", + "variables": [ + { + "scope": "string", + "name": "string", + "value": 0, + "type": "string" + } + ] + } + * + * @author Cristina Axinte + * + */ +public class RestTaskModel extends TaskModel implements IRestModel +{ + @JsonProperty(value = "entry") + RestTaskModel model; + + @Override + public RestTaskModel onModel() + { + return model; + } + + private String processDefinitionId; + private String activityDefinitionId; + private String name; + private String startedAt; + private String endedAt; + private Integer durationInMs; + private String owner; + private String formResourceKey; + private String state; + private String description; + @JsonProperty(value = "priority") + private Integer priorityTask; + @JsonInclude(JsonInclude.Include.NON_NULL) + private RestVariableModelsCollection variables; + + public RestVariableModelsCollection getVariables() + { + return variables; + } + + public void setVariables(RestVariableModelsCollection variables) + { + this.variables = variables; + } + + public String getProcessDefinitionId() + { + return processDefinitionId; + } + + public void setProcessDefinitionId(String processDefinitionId) + { + this.processDefinitionId = processDefinitionId; + } + + public String getActivityDefinitionId() + { + return activityDefinitionId; + } + + public void setActivityDefinitionId(String activityDefinitionId) + { + this.activityDefinitionId = activityDefinitionId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getStartedAt() + { + return startedAt; + } + + public void setStartedAt(String startedAt) + { + this.startedAt = startedAt; + } + + public String getEndedAt() + { + return endedAt; + } + + public void setEndedAt(String endedAt) + { + this.endedAt = endedAt; + } + + public Integer getDurationInMs() + { + return durationInMs; + } + + public void setDurationInMs(Integer durationInMs) + { + this.durationInMs = durationInMs; + } + + public String getOwner() + { + return owner; + } + + public String getFormResourceKey() + { + return formResourceKey; + } + + public void setFormResourceKey(String formResourceKey) + { + this.formResourceKey = formResourceKey; + } + + public String getState() + { + return state; + } + + public void setState(String state) + { + this.state = state; + } + + /** + * DSL for assertion on this rest model + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + public Integer getPriorityTask() + { + return priorityTask; + } + + public void setPriorityTask(Integer priorityTask) + { + this.priorityTask = priorityTask; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTaskModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTaskModelsCollection.java new file mode 100644 index 0000000000..bd73c9e613 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTaskModelsCollection.java @@ -0,0 +1,66 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; + +/** + * Handle collection of + * + * @author Critina Axinte + */ +public class RestTaskModelsCollection extends RestModels +{ + public RestTaskModel getTaskModelByAssignee(UserModel assigneeName) + { + List tasksList = getEntries(); + + for (RestTaskModel taskModel: tasksList) + { + if (taskModel.onModel().getAssignee().equals(assigneeName.getUsername())) + { + STEP(String.format("REST API: Get task with assignee '%s'", assigneeName.getUsername())); + return taskModel.onModel(); + } + } + + return null; + } + + public RestTaskModel getTaskModelByDescription(SiteModel siteModel) + { + List tasksList = getEntries(); + + for (RestTaskModel taskModel: tasksList) + { + if (taskModel.onModel().getDescription().equals(String.format("Request to join %s site", siteModel.getId()))) + { + STEP(String.format("REST API: Get task with site name '%s'", siteModel.getId())); + return taskModel.onModel(); + } + } + + return null; + } + + public RestTaskModel getTaskModelByProcess(ProcessModel process) + { + List tasksList = getEntries(); + + for (RestTaskModel taskModel: tasksList) + { + if (taskModel.onModel().getProcessId().equals(process.getId())) + { + STEP(String.format("REST API: Get task with processId '%s'", process.getId())); + return taskModel.onModel(); + } + } + + return null; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTextResponse.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTextResponse.java new file mode 100644 index 0000000000..20566cc955 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTextResponse.java @@ -0,0 +1,35 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestResponse; +import org.json.simple.JSONObject; + +import com.google.gson.JsonObject; +import io.restassured.response.Response; + +/** + * Process RestReponse of type application/text + * @author Meenal Bhave + */ +public class RestTextResponse extends RestResponse +{ + + public RestTextResponse(Response response) + { + super(response); + } + + public JsonObject getJsonObject() + { + return this.getResponse().jsonPath().get(); + } + + public String getJsonValueByPath(String path) + { + return this.getResponse().jsonPath().get(path).toString(); + } + + public JSONObject getJsonObjectByPath(String path) + { + return new JSONObject(this.getResponse().jsonPath().get(path)); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTicketBodyModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTicketBodyModel.java new file mode 100644 index 0000000000..d911d8d4e1 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTicketBodyModel.java @@ -0,0 +1,59 @@ +package org.alfresco.rest.model; + +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 from 'Alfresco Authentication REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/authentication/versions/1} + */ +public class RestTicketBodyModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestTicketBodyModel model; + + @Override + public RestTicketBodyModel onModel() + { + return model; + } + + private String userId; + private String password; + + public String getUserId() + { + return this.userId; + } + + public void setUserId(String userId) + { + this.userId = userId; + } + + public String getPassword() + { + return this.password; + } + + public void setPassword(String password) + { + this.password = password; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTicketModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTicketModel.java new file mode 100644 index 0000000000..ed66a12d37 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestTicketModel.java @@ -0,0 +1,59 @@ +package org.alfresco.rest.model; + +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 from 'Alfresco Authentication REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/authentication/versions/1} + */ +public class RestTicketModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestTicketModel model; + + @Override + public RestTicketModel onModel() + { + return model; + } + + private String id; + private String userId; + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getUserId() + { + return this.userId; + } + + public void setUserId(String userId) + { + this.userId = userId; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVariableModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVariableModel.java new file mode 100644 index 0000000000..7e8fed71cd --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVariableModel.java @@ -0,0 +1,112 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Handles a single Variable JSON response + * Example: + * { + * "scope": "string", + * "name": "string", + * "value": 0, + * "type": "string" + * } + * + * @author Cristina Axinte + */ +public class RestVariableModel extends TestModel implements IRestModel +{ + private String scope; + private String name; + private Object value; + private String type; + + @JsonProperty(value = "entry") + RestVariableModel model; + + public RestVariableModel() + { + } + + public RestVariableModel(String scope, String name, String type, Object value) + { + this.scope = scope; + this.name = name; + this.type = type; + this.value = value; + } + + public String getScope() + { + return scope; + } + + public void setScope(String scope) + { + this.scope = scope; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Object getValue() + { + return value; + } + + public void setValue(Object value) + { + this.value = value; + } + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + public static RestVariableModel getRandomTaskVariableModel(String scope, String type) + { + return new RestVariableModel(scope, RandomData.getRandomName("name"), type, RandomData.getRandomName("value")); + } + + /** + * DSL for assertion on this rest model + * + * @return + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public RestVariableModel onModel() + { + return model; + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVariableModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVariableModelsCollection.java new file mode 100644 index 0000000000..ca04c3ca1d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVariableModelsCollection.java @@ -0,0 +1,41 @@ +package org.alfresco.rest.model; + +import static org.alfresco.utility.report.log.Step.STEP; + +import java.util.List; + +import org.alfresco.rest.core.RestModels; + +/** + * Handles a collection of JSON response + * Example: + * "variables": [ + { + "scope": "string", + "name": "string", + "value": 0, + "type": "string" + } + ] + + * @author Cristina Axinte + * + */ +public class RestVariableModelsCollection extends RestModels +{ + public RestVariableModel getVariableByName(String variableName) + { + STEP(String.format("REST API: Get variable with name '%s'", variableName)); + List variableList = getEntries(); + + for (RestVariableModel variableEntry: variableList) + { + if (variableEntry.onModel().getName().equals(variableName)) + { + return variableEntry.onModel(); + } + } + + return null; + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionInfoModel.java new file mode 100644 index 0000000000..16d94e86bd --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionInfoModel.java @@ -0,0 +1,129 @@ +package org.alfresco.rest.model; + +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 'aforascu' on '2018-01-10 16:02' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api} + */ +public class RestVersionInfoModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestVersionInfoModel model; + + @Override + public RestVersionInfoModel onModel() + { + return model; + } + + + @JsonProperty(required = true) + private String major; + + @JsonProperty(required = true) + private String minor; + + @JsonProperty(required = true) + private String patch; + + @JsonProperty(required = true) + private String hotfix; + + @JsonProperty(required = true) + private int schema; + + @JsonProperty(required = true) + private String label; + + @JsonProperty(required = true) + private String display; + + public String getMajor() + { + return this.major; + } + + public void setMajor(String major) + { + this.major = major; + } + + public String getMinor() + { + return this.minor; + } + + public void setMinor(String minor) + { + this.minor = minor; + } + + public String getPatch() + { + return this.patch; + } + + public void setPatch(String patch) + { + this.patch = patch; + } + + public String getHotfix() + { + return this.hotfix; + } + + public void setHotfix(String hotfix) + { + this.hotfix = hotfix; + } + + public int getSchema() + { + return this.schema; + } + + public void setSchema(int schema) + { + this.schema = schema; + } + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getDisplay() + { + return this.display; + } + + public void setDisplay(String display) + { + this.display = display; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionModel.java new file mode 100644 index 0000000000..fb1bc86968 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionModel.java @@ -0,0 +1,173 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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; + +public class RestVersionModel extends TestModel implements IRestModel +{ + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @JsonProperty(value = "entry") + RestVersionModel model; + + @Override + public RestVersionModel onModel() + { + return model; + } + + @JsonProperty(required = true) + private String id; + + private String versionComment; + + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + private String nodeType; + + @JsonProperty(required = true) + private boolean isFolder; + + @JsonProperty(required = true) + private boolean isFile; + + @JsonProperty(required = true) + private String modifiedAt; + + @JsonProperty(required = true) + private RestByUserModel modifiedByUser; + + private RestContentModel content; + + private List aspectNames; + + private Object properties; + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getVersionComment() + { + return versionComment; + } + + public void setVersionComment(String versionComment) + { + this.versionComment = versionComment; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getNodeType() + { + return nodeType; + } + + public void setNodeType(String nodeType) + { + this.nodeType = nodeType; + } + + public boolean isFolder() + { + return isFolder; + } + + public void setFolder(boolean isFolder) + { + this.isFolder = isFolder; + } + + public boolean isFile() + { + return isFile; + } + + public void setFile(boolean isFile) + { + this.isFile = isFile; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public RestByUserModel getModifiedByUser() + { + return modifiedByUser; + } + + public void setModifiedByUser(RestByUserModel modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public RestContentModel getContent() + { + return content; + } + + public void setContent(RestContentModel content) + { + this.content = content; + } + + public List getAspectNames() + { + return aspectNames; + } + + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + public Object getProperties() + { + return properties; + } + + public void setProperties(Object properties) + { + this.properties = properties; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionModelsCollection.java new file mode 100644 index 0000000000..c94d580233 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestVersionModelsCollection.java @@ -0,0 +1,8 @@ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +public class RestVersionModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/body/RestNodeLockBodyModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/body/RestNodeLockBodyModel.java new file mode 100644 index 0000000000..9859ae4f5d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/body/RestNodeLockBodyModel.java @@ -0,0 +1,78 @@ +package org.alfresco.rest.model.body; + +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; + +public class RestNodeLockBodyModel extends TestModel implements IRestModel +{ + + @JsonProperty(value = "entry") + RestNodeLockBodyModel model; + + @Override + public ModelAssertion and() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion assertThat() + { + return assertThat(); + } + + @Override + public RestNodeLockBodyModel onModel() + { + return model; + } + + @JsonProperty + private int timeToExpire; + + @JsonProperty + private String type; + + @JsonProperty + private String lifetime; + + public String getLifetime() + { + return lifetime; + } + + public void setLifetime(String lifetime) + { + this.lifetime = lifetime; + } + + public int getTimeToExpire() + { + return timeToExpire; + } + + /* + * Set in seconds lock time + * if lock time = 0 or not set, the lock never expires + */ + public void setTimeToExpire(int timeToExpire) + { + this.timeToExpire = timeToExpire; + } + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/builder/NodesBuilder.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/builder/NodesBuilder.java new file mode 100644 index 0000000000..63a1eadd50 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/builder/NodesBuilder.java @@ -0,0 +1,140 @@ +package org.alfresco.rest.model.builder; + +import java.util.LinkedList; +import java.util.List; + +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestNodeBodyModel; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.RepoTestModel; + +/** + * Builder for creating nested nodes using REST v1 + * No assertion is made in order to use this builder also for negative testing + * + * @author Paul Brodner + */ +public class NodesBuilder +{ + private List nodes = new LinkedList<>(); + private RestWrapper restWrapper; + private RepoTestModel lastNode; + + public NodeDetail getNode(String prefix) + { + for(NodeDetail node : nodes) + { + if(node.getPrefix().equals(prefix)) + return node; + } + return null; + } + /** + * How you can use to create nested nodes: + * will create in Admin's Repository: + * - F1-P-randomname> + * - F1-P-randomname + * - F3-P-randomname + * ------file1-randomname + * ------file2-randomname + * ------F3-randomname + * + * restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI() + .usingNode(ContentModel.my()) + .createHierarcy() + .folder("F1-P") + .folder("F2-P") + .folder("F3-P") + .file("file1") + .file("file2") + .folder("F4") + * + * + * @param restWrapper + * @param repoModel + */ + public NodesBuilder(RestWrapper restWrapper, RepoTestModel repoModel) + { + this.restWrapper = restWrapper; + this.lastNode = repoModel; + } + + public NodeDetail folder(String prefix) throws Exception + { + NodeDetail n = new NodeDetail(prefix, lastNode.getNodeRef(), "cm:folder"); + nodes.add(n); + return n; + } + + public class NodeDetail + { + private RestNodeModel parentNodeModel; + private String id; + private String prefix; + private String name; + + public ContentModel toContentModel() + { + ContentModel cm = new ContentModel(); + cm.setNodeRef(getId()); + return cm; + } + public NodeDetail(String prefix, String parentId, String nodeType) throws Exception + { + this.prefix = prefix; + this.name = RandomData.getRandomName(prefix); + + RestNodeBodyModel model = new RestNodeBodyModel(); + model.setName(name); + model.setNodeType(nodeType); + + // define the parent + ContentModel parent = new ContentModel(); + parent.setNodeRef(parentId); + + RestNodeModel newModel = restWrapper.withCoreAPI().usingNode(parent).createNode(model); + this.id = newModel.getId(); + + if (nodeType.equals("cm:content")) + { + RestNodeModel tmp = new RestNodeModel(); + tmp.setId(parentId); + parentNodeModel = tmp; + } + else + parentNodeModel = newModel; + + } + + public NodeDetail folder(String prefix) throws Exception + { + NodeDetail n = new NodeDetail(prefix, parentNodeModel.getId(), "cm:folder"); + nodes.add(n); + return n; + } + + public NodeDetail file(String prefix) throws Exception + { + NodeDetail n = new NodeDetail(prefix, parentNodeModel.getId(), "cm:content"); + nodes.add(n); + return n; + } + + public String getId() + { + return id; + } + + public String getName() + { + return name; + } + + public String getPrefix() + { + return prefix; + } + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/ignore-models b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/ignore-models new file mode 100644 index 0000000000..bae3a13e50 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/ignore-models @@ -0,0 +1,12 @@ +# Any line that will start with # will be considered one comment +# Empty lines are also ignored +# Use this file if you want to ignore models from YAML file +#---------------------------------------------------------- +SiteBodyCreate +Error +# this is SiteModel (exist in Utility project) +SiteModel +#NodeBodyCreate/NodeBodyUpdate are created as NodeBody +NodeBodyCreate +NodeBodyUpdate +Node \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Actions.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Actions.java new file mode 100644 index 0000000000..94149e09a1 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Actions.java @@ -0,0 +1,58 @@ +package org.alfresco.rest.requests; + +import java.util.Map; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestActionDefinitionModel; +import org.alfresco.rest.model.RestActionDefinitionModelsCollection; +import org.alfresco.utility.model.RepoTestModel; +import org.json.JSONObject; +import org.springframework.http.HttpMethod; + +public class Actions extends ModelRequest +{ + public Actions(RestWrapper restWrapper) + { + super(restWrapper); + } + + /** + * List available actions using GET on '/action-definitions' + */ + public RestActionDefinitionModelsCollection listActionDefinitions() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "action-definitions?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestActionDefinitionModelsCollection.class, request); + } + + /** + * Execute action with parameters using POST on '/action-executions' + */ + public JSONObject executeAction(String actionDefinitionId, RepoTestModel targetNode, Map params) throws Exception + { + String postBody = JsonBodyGenerator.executeActionPostBody(actionDefinitionId, targetNode, params); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "action-executions"); + return restWrapper.processJson(request); + } + + /** + * Execute action without parameters using POST on '/action-executions' + */ + public JSONObject executeAction(String actionDefinitionId, RepoTestModel targetNode) throws Exception + { + String postBody = JsonBodyGenerator.executeActionPostBody(actionDefinitionId, targetNode); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "action-executions"); + return restWrapper.processJson(request); + } + + /** + * Get specific action definition using GET on '/action-definitions/{actionDefinitionId}' + */ + public RestActionDefinitionModel getActionDefinitionById(String actionDefinitionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "action-definitions/".concat(actionDefinitionId)); + return restWrapper.processModel(RestActionDefinitionModel.class, request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/AdminConsole.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/AdminConsole.java new file mode 100644 index 0000000000..7e916fd4c6 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/AdminConsole.java @@ -0,0 +1,25 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.core.RestWrapper; +import org.springframework.http.HttpMethod; + +import io.restassured.RestAssured; + +public class AdminConsole extends ModelRequest { + + public AdminConsole(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/service/api/server"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + // Method for getting repository info from Admin Console + public RestResponse getAdminConsoleRepoInfo() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, ""); + return restWrapper.process(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Audit.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Audit.java new file mode 100644 index 0000000000..ee406ee943 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Audit.java @@ -0,0 +1,136 @@ + +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestAuditAppModelsCollection; +import org.alfresco.rest.model.RestAuditEntryModel; +import org.alfresco.rest.model.RestAuditAppModel; +import org.alfresco.rest.model.RestAuditEntryModelsCollection; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /audit-applications path + * + */ +public class Audit extends ModelRequest +{ + + public Audit(RestWrapper restWrapper) throws Exception + { + super(restWrapper); + } + + + /** + * Gets a list of audit applications in this repository using GET call on "/audit-applications" + * + * @return + * @throws JsonToModelConversionException + */ + public RestAuditAppModelsCollection getAuditApplications() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "audit-applications?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestAuditAppModelsCollection.class, request); + } + + /** + * Retrieves an audit application info with ID using GET call on "/audit-applications/{auditApplicationId}" + * + * @param auditApplicationId + * @return + * @throws Exception + */ + public RestAuditAppModel getAuditApp(RestAuditAppModel restAuditAppModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "audit-applications/{auditApplicationId}?{parameters}", restAuditAppModel.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestAuditAppModel.class, request); + } + + /** + * Retrieves a list of audit entries for audit application auditApplicationId using GET call on "/audit-applications/{auditApplicationId}/audit-entries" + * + * @param auditApplicationId + * @return + * @throws Exception + */ + public RestAuditEntryModelsCollection listAuditEntriesForAnAuditApplication(String auditApplicationId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "audit-applications/{auditApplicationId}/audit-entries?{parameters}", auditApplicationId, restWrapper.getParameters()); + return restWrapper.processModels(RestAuditEntryModelsCollection.class, request); + } + + /** + * Disable or re-enable the audit application auditApplicationId using PUT call on "/audit-applications/{auditApplicationId}" + * + * @param restAuditAppModel + * @param key + * @param value + * @return + * @throws Exception + */ + public RestAuditAppModel updateAuditApp(RestAuditAppModel restAuditAppModel, String key, String value) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson(key, value); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "audit-applications/{auditApplicationId}",restAuditAppModel.getId()); + return restWrapper.processModel(RestAuditAppModel.class, request); + } + + /** + * Retrieves an audit entry auditEntryId for audit application auditApplicationId using GET call on "/audit-applications/{auditApplicationId}/audit-entries/{auditEntryId}" + * + * @param auditApplicationId + * @param auditEntryId + * @return + * @throws Exception + */ + public RestAuditEntryModel getAuditEntryForAnAuditApplication(String auditApplicationId, String auditEntryId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "audit-applications/{auditApplicationId}/audit-entries/{auditEntryId}?{parameters}", auditApplicationId, auditEntryId, restWrapper.getParameters()); + return restWrapper.processModel(RestAuditEntryModel.class, request); + } + + /** + * Deletes an audit entry auditEntryId for audit application auditApplicationId using DELETE call on "/audit-applications/{auditApplicationId}/audit-entries/{auditEntryId}" + * + * @param auditApplicationId + * @param auditEntryId + * @return + * @throws Exception + */ + public void deleteAuditEntryForAnAuditApplication(String auditApplicationId, String auditEntryId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "audit-applications/{auditApplicationId}/audit-entries/{auditEntryId}", auditApplicationId, auditEntryId); + restWrapper.processEmptyModel(request); + } + + /** + * Deletes audit entries for audit application auditApplicationId using DELETE call on "/audit-applications/{auditApplicationId}/audit-entries" + * + * @param auditApplicationId + * @return + * @throws Exception + */ + public void deleteAuditEntriesForAnAuditApplication(String auditApplicationId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "audit-applications/{auditApplicationId}/audit-entries?{parameters}", auditApplicationId, restWrapper.getParameters()); + restWrapper.processEmptyModel(request); + } + + /** + * Retrieves a list of audit entries for a node nodeId using GET call on "/nodes/{nodeId}/audit-entries" + * + * @param nodeId + * @return + * @throws Exception + */ + public RestAuditEntryModelsCollection listAuditEntriesForNode(String nodeId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/audit-entries?{parameters}", nodeId, restWrapper.getParameters()); + return restWrapper.processModels(RestAuditEntryModelsCollection.class, request); + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/CustomAspectModelManager.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/CustomAspectModelManager.java new file mode 100644 index 0000000000..d9bd7e19d2 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/CustomAspectModelManager.java @@ -0,0 +1,69 @@ +package org.alfresco.rest.requests; + +import javax.json.JsonArrayBuilder; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestCustomAspectModel; +import org.alfresco.utility.model.CustomAspectModel; +import org.alfresco.utility.model.CustomAspectPropertiesModel; +import org.alfresco.utility.model.CustomContentModel; +import org.springframework.http.HttpMethod; + +/** + * @author Bogdan Bocancea + */ +public class CustomAspectModelManager extends ModelRequest +{ + private CustomContentModel customContentModel; + private CustomAspectModel customAspectModel; + + public CustomAspectModelManager(CustomContentModel customContentModel, CustomAspectModel aspectModel, RestWrapper restWrapper) + { + super(restWrapper); + this.customContentModel = customContentModel; + this.customAspectModel = aspectModel; + } + + public RestCustomAspectModel getAspect() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "cmm/{modelName}/aspects/{aspectName}?{parameters}", + this.customContentModel.getName(), this.customAspectModel.getName(), restWrapper.getParameters()); + return restWrapper.processModel(RestCustomAspectModel.class, request); + } + + public void addProperty(CustomAspectPropertiesModel propertyModel) + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + array.add(JsonBodyGenerator.defineJSON() + .add("name", propertyModel.getName()) + .add("title", propertyModel.getTitle()) + .add("description", propertyModel.getDescription()) + .add("dataType", propertyModel.getDataType()) + .add("multiValued", propertyModel.isMultiValued()) + .add("mandatory", propertyModel.isMandatory()) + .add("mandatoryEnforced", propertyModel.isMandatoryEnforced())); + + String body = JsonBodyGenerator.defineJSON().add("name", this.customAspectModel.getName()).add("properties", array).build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, body, "cmm/{modelName}/aspects/{aspectName}?select=props", + this.customContentModel.getName(), this.customAspectModel.getName()); + restWrapper.processEmptyModel(request); + } + + public void deleteAspectProperty(CustomAspectPropertiesModel propertyModel) + { + String body = JsonBodyGenerator.defineJSON() + .add("name", this.customAspectModel.getName()).build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, body, "cmm/{modelName}/aspects/{aspectName}?select=props&delete={propertyName}", + this.customContentModel.getName(), this.customAspectModel.getName(), propertyModel.getName()); + restWrapper.processEmptyModel(request); + } + + public void deleteAspect() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "cmm/{modelName}/aspects/{aspectName}", + this.customContentModel.getName(), this.customAspectModel.getName()); + restWrapper.processEmptyModel(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/CustomModelManager.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/CustomModelManager.java new file mode 100644 index 0000000000..ab521ab298 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/CustomModelManager.java @@ -0,0 +1,54 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestCustomModel; +import org.alfresco.utility.model.CustomContentModel; +import org.springframework.http.HttpMethod; + +/** + * @author Bogdan Bocancea + */ +public class CustomModelManager extends ModelRequest +{ + private CustomContentModel customContentModel; + + public CustomModelManager(CustomContentModel customContentModel, RestWrapper restWrapper) + { + super(restWrapper); + this.customContentModel = customContentModel; + } + + /** + * Retrieve one model using GET call on "cmm/{modelName}" + * + * @return {@link RestCustomModel} + */ + public RestCustomModel getModel() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "cmm/{modelName}?{parameters}", this.customContentModel.getName(), + restWrapper.getParameters()); + return restWrapper.processModel(RestCustomModel.class, request); + } + + public void activateModel() + { + String json = JsonBodyGenerator.keyValueJson("status", "ACTIVE"); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, json, "cmm/{modelName}?select=status", this.customContentModel.getName()); + restWrapper.processEmptyModel(request); + } + + public void deactivateModel() + { + String json = JsonBodyGenerator.keyValueJson("status", "DRAFT"); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, json, "cmm/{modelName}?select=status", this.customContentModel.getName()); + restWrapper.processEmptyModel(request); + } + + public void deleteModel() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "cmm/{modelName}", this.customContentModel.getName()); + restWrapper.processEmptyModel(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Deployments.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Deployments.java new file mode 100644 index 0000000000..5358563e41 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Deployments.java @@ -0,0 +1,65 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestDeploymentModelsCollection; +import org.springframework.http.HttpMethod; + +/** + * Created by Claudia Agache on 10/4/2016. + */ +public class Deployments extends ModelRequest +{ + RestDeploymentModel deployment; + + public Deployments(RestWrapper restWrapper) + { + super(restWrapper); + } + + public Deployments(RestDeploymentModel deployment, RestWrapper restWrapper) + { + super(restWrapper); + this.deployment = deployment; + } + + /** + * Retrieve 100 deployments (this is the default size when maxItems is not specified) from Alfresco using GET call on "/deployments" + * + * @return + * @throws JsonToModelConversionException + */ + public RestDeploymentModelsCollection getDeployments() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deployments?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestDeploymentModelsCollection.class, request); + } + + /** + * Delete the specified deployment from Alfresco using DELETE call on "/deployments/{deploymentId}" + * + * @return + * @throws JsonToModelConversionException + */ + public void deleteDeployment() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "deployments/{deploymentId}", deployment.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Retrieve the specified deployment from Alfresco using GET call on "/deployments/{deploymentId}" + * + * @return + * @throws JsonToModelConversionException + */ + public RestDeploymentModel getDeployment() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deployments/{deploymentId}?{parameters}", + deployment.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestDeploymentModel.class, request); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Downloads.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Downloads.java new file mode 100644 index 0000000000..74ad844d30 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Downloads.java @@ -0,0 +1,54 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestDownloadsModel; +import org.springframework.http.HttpMethod; + + +/** + * Methods for Rest API under the /downloads path + */ + +public class Downloads extends ModelRequest { + + RestDownloadsModel downloadsModel; + + public Downloads(RestWrapper restWrapper) + { + super(restWrapper); + } + + public Downloads(RestDownloadsModel downloadsModel, RestWrapper restWrapper) throws Exception + { + super(restWrapper); + this.downloadsModel = downloadsModel; + } + + /** + * Get download details using POST call on "downloads" + */ + public RestDownloadsModel createDownload(String postBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "downloads"); + return restWrapper.processModel(RestDownloadsModel.class, request); + } + + /** + * Get download details using GET call on "downloads/{downloadId}" + */ + public RestDownloadsModel getDownload() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "downloads/{downloadId}", downloadsModel.getId()); + return restWrapper.processModel(RestDownloadsModel.class, request); + } + + /** + * Cancel download using DELETE call on "downloads/{downloadId}" + */ + public void cancelDownload() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "downloads/{downloadId}", downloadsModel.getId()); + restWrapper.processEmptyModel(request);; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Groups.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Groups.java new file mode 100644 index 0000000000..7aba5a746e --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Groups.java @@ -0,0 +1,91 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestGroupMember; +import org.alfresco.rest.model.RestGroupMemberModelsCollection; +import org.alfresco.rest.model.RestGroupsModel; +import org.alfresco.rest.model.RestGroupsModelsCollection; +import org.springframework.http.HttpMethod; + +public class Groups extends ModelRequest +{ + + public Groups(RestWrapper restWrapper) + { + super(restWrapper); + } + + /** + * List existing groups using GET on '/groups + */ + public RestGroupsModelsCollection listGroups() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "groups?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestGroupsModelsCollection.class, request); + } + + /** + * Create a group using POST on '/groups + */ + public RestGroupsModel createGroup(String groupBodyCreate) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, groupBodyCreate, "groups?{parameters}", restWrapper.getParameters()); + return restWrapper.processModel(RestGroupsModel.class, request); + } + + /** + * Retrieve group details using GET on '/groups/{groupId} + */ + public RestGroupsModel getGroupDetail(String groupId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "groups/{groupId}?{parameters}", groupId, restWrapper.getParameters()); + return restWrapper.processModel(RestGroupsModel.class, request); + } + + /** + * Delete a group using DELETE on '/groups/{groupId} + */ + public void deleteGroup(String groupId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "groups/{groupId}?{parameters}", groupId, restWrapper.getParameters()); + restWrapper.processEmptyModel(request); + } + + /** + * Update group details using PUT on '/groups/{groupId} + */ + public RestGroupsModel updateGroupDetails(String groupId, String groupBodyUpdate) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, groupBodyUpdate, "groups/{groupId}?{parameters}", groupId, restWrapper.getParameters()); + return restWrapper.processModel(RestGroupsModel.class, request); + } + + /** + * List memberships of a group using GET on '/groups/{groupId}/members + */ + public RestGroupMemberModelsCollection listGroupMemberships(String groupId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "groups/{groupId}/members?{parameters}", groupId, restWrapper.getParameters()); + return restWrapper.processModels(RestGroupMemberModelsCollection.class, request); + } + + /** + * Create a group membership using POST on '/groups/{groupId}/members + */ + public RestGroupMember createGroupMembership (String groupId, String groupMembershipBodyCreate) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, groupMembershipBodyCreate, "groups/{groupId}/members?{parameters}", groupId, + restWrapper.getParameters()); + return restWrapper.processModel(RestGroupMember.class, request); + } + + /** + * Delete a group membership using DELETE on '/groups/{groupId}/members/{groupMemberId} + */ + public void deleteGroupMembership(String groupId, String groupMemberId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "groups/{groupId}/members/{groupMemberId}", groupId, groupMemberId); + restWrapper.processEmptyModel(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/ModelRequest.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/ModelRequest.java new file mode 100644 index 0000000000..9c8dfce52d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/ModelRequest.java @@ -0,0 +1,27 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestWrapper; + +public abstract class ModelRequest +{ + protected RestWrapper restWrapper; + + public ModelRequest(RestWrapper restWrapper) + { + this.restWrapper = restWrapper; + } + + @SuppressWarnings("unchecked") + public Request usingParams(String... parameters) + { + restWrapper.withParams(parameters); + return (Request) this; + } + + @SuppressWarnings("unchecked") + public Request includePath() + { + restWrapper.withParams("include=path"); + return (Request) this; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Networks.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Networks.java new file mode 100644 index 0000000000..55eecb8d3c --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Networks.java @@ -0,0 +1,58 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestNetworkModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.UserModel; +import org.json.JSONObject; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /networks path + * + */ +public class Networks extends ModelRequest +{ + public Networks(RestWrapper restWrapper) + { + super(restWrapper); + } + + /** + * Retrieve details for the current user network using GET call on "networks/{networkId}" + * + * @return + * @throws Exception + */ + public RestNetworkModel getNetwork() throws Exception + { + return getNetwork(restWrapper.getTestUser()); + } + + /** + * Retrieve details of a specific network using GET call on "networks/{networkId}" + * + * @return + * @throws Exception + */ + public RestNetworkModel getNetwork(UserModel tenant) throws Exception + { + Utility.checkObjectIsInitialized(tenant.getDomain(), "tenant.getDomain()"); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "networks/{networkId}", tenant.getDomain()); + return restWrapper.processModel(RestNetworkModel.class, request); + } + + /** + * Retrieve details of a specific network using GET call with parameters on "networks/{networkId}?{parameters}" + * + * @return JSONObject + * @throws Exception + */ + public JSONObject getNetworkWithParams(UserModel tenant) throws Exception + { + Utility.checkObjectIsInitialized(tenant.getDomain(), "tenant.getDomain()"); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "networks/{networkId}?{parameters}", tenant.getDomain(), restWrapper.getParameters()); + return restWrapper.processJson(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Node.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Node.java new file mode 100644 index 0000000000..437bf79728 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Node.java @@ -0,0 +1,794 @@ + +package org.alfresco.rest.requests; + +import java.io.File; + +import javax.json.JsonArrayBuilder; + +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.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.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; +import org.alfresco.utility.model.RepoTestModel; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.reporters.Files; + +import io.restassured.http.ContentType; + +/** + * Declares all Rest API under the /nodes path + * + */ +public class Node extends ModelRequest +{ + private RepoTestModel repoModel; + + public Node(RestWrapper restWrapper) throws Exception + { + super(restWrapper); + } + + public Node(RepoTestModel repoModel, RestWrapper restWrapper) throws Exception + { + super(restWrapper); + this.repoModel = repoModel; + Utility.checkObjectIsInitialized(this.repoModel.getNodeRef(), "repoModel.getNodeRef()"); + } + + /** + * Retrieve details for a specific node using GET call on "nodes/{nodeId}" + * + * @param nodeId + * @return + * @throws JsonToModelConversionException + */ + public RestNodeModel getNode() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Retrieve comments for a specific node using GET call on "nodes/{nodeId}/comments" + * + * @param nodeId + * @return + * @throws JsonToModelConversionException + */ + public RestCommentModelsCollection getNodeComments() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/comments?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestCommentModelsCollection.class, request); + } + + /** + * Publish one new comment on a specific node using POST call on "nodes/{nodeId}/comments" + * + * @param node + * @param commentContent + * @return + * @throws Exception + */ + public RestCommentModel addComment(String commentContent) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("content", commentContent); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/comments", repoModel.getNodeRef()); + return restWrapper.processModel(RestCommentModel.class, request); + } + + /** + * Publish multiple comments on a specific node using POST call on "nodes/{nodeId}/comments" + * + * @param contentModel + * @param comments + * @return + * @throws Exception + */ + public RestCommentModelsCollection addComments(String... comments) throws Exception + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for(String comment: comments) + { + array.add(JsonBodyGenerator.defineJSON().add("content", comment)); + } + String postBody = array.build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/comments", repoModel.getNodeRef()); + return restWrapper.processModels(RestCommentModelsCollection.class, request); + } + + /** + * Update a comment for a specific node using PUT call on nodes/{nodeId}/comments/{commentId} + * + * @param nodeId + * @param commentId + * @param commentContent + * @return + * @throws JsonToModelConversionException + */ + public RestCommentModel updateComment(RestCommentModel commentModel, String commentContent) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("content", commentContent); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "nodes/{nodeId}/comments/{commentId}?{parameters}", repoModel.getNodeRef(), commentModel.getId(), restWrapper.getParameters()); + request.setContentType("UTF-8"); + RestCommentModel response = restWrapper.processModel(RestCommentModel.class, request); + return response; + } + + /** + * Delete a comment for a specific node using DELETE call on nodes/{nodeId}/comments/{commentId} + * + * @param nodeId + * @param commentId + * @return + * @throws JsonToModelConversionException + */ + public void deleteComment(RestCommentModel comment) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/comments/{commentId}", repoModel.getNodeRef(), comment.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Like a document using POST call on "nodes/{nodeId}/ratings" + * + * @return + * @throws Exception + */ + public RestRatingModel likeDocument() throws Exception { + String postBody = JsonBodyGenerator.likeRating(true); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/ratings", repoModel.getNodeRef()); + return restWrapper.processModel(RestRatingModel.class, request); + } + + public RestRatingModel dislikeDocument() throws Exception { + String postBody = JsonBodyGenerator.likeRating(false); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/ratings", repoModel.getNodeRef()); + return restWrapper.processModel(RestRatingModel.class, request); + } + + /** + * POST call on "nodes/{nodeId}/ratings" using an invalid rating body + * + * @return + * @throws Exception + */ + public RestRatingModel addInvalidRating(String jsonBody) throws Exception { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, jsonBody, "nodes/{nodeId}/ratings", repoModel.getNodeRef()); + return restWrapper.processModel(RestRatingModel.class, request); + } + + + + /** + * Add five star rate to a document using POST call on "nodes/{nodeId}/ratings" + * + * @param stars + * @return + * @throws Exception + */ + public RestRatingModel rateStarsToDocument(int stars) throws Exception { + String postBody = JsonBodyGenerator.fiveStarRating(stars); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/ratings", repoModel.getNodeRef()); + return restWrapper.processModel(RestRatingModel.class, request); + } + + /** + * Retrieve node ratings using GET call on "nodes/{nodeId}/ratings" + * + * @return + * @throws Exception + */ + public RestRatingModelsCollection getRatings() throws Exception { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestRatingModelsCollection.class, request); + } + + /** + * Delete like rating using DELETE call on "nodes/{nodeId}/ratings/{ratingId}" + * + * @return + * @throws Exception + */ + public void deleteLikeRating() throws Exception { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/ratings/{ratingId}", repoModel.getNodeRef(), "likes"); + restWrapper.processEmptyModel(request); + } + + /** + * Try to delete invalid rating using DELETE call on "nodes/{nodeId}/ratings/{ratingId}" + * + * @return + * @throws Exception + */ + public void deleteInvalidRating(String rating) throws Exception { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/ratings/{ratingId}", repoModel.getNodeRef(), rating); + restWrapper.processEmptyModel(request); + } + + /** + * + * Get like rating of a document using GET call on "nodes/{nodeId}/ratings/{ratingId}" + */ + public RestRatingModel getLikeRating() throws Exception { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings/{ratingId}?{parameters}", repoModel.getNodeRef(), "likes", restWrapper.getParameters()); + return restWrapper.processModel(RestRatingModel.class, request); + } + + /** + * Delete fivestar rating using DELETE call on "nodes/{nodeId}/ratings/{ratingId}" + * + * @return + * @throws Exception + */ + public void deleteFiveStarRating() throws Exception { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/ratings/{ratingId}", repoModel.getNodeRef(), "fiveStar"); + restWrapper.processEmptyModel(request); + } + + /** + * + * Get fivestar rating of a document using GET call on "nodes/{nodeId}/ratings/{ratingId}" + * @return + * @throws Exception + */ + public RestRatingModel getFiveStarRating() throws Exception { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings/{ratingId}?{parameters}", repoModel.getNodeRef(), "fiveStar", restWrapper.getParameters()); + return restWrapper.processModel(RestRatingModel.class, request); + } + + /** + * Adds a tag to the given content node + * + * @param contentModel + * @param tag + * @return + * @throws Exception + */ + public RestTagModel addTag(String tag) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("tag", tag); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/tags", repoModel.getNodeRef()); + return restWrapper.processModel(RestTagModel.class, request); + } + + /** + * Adds multiple tags to the given content node + * + * @param contentModel + * @param tags + * @return + * @throws Exception + */ + public RestTagModelsCollection addTags(String... tags) throws Exception + { + String postBody = "["; + for(String tag: tags) + { + postBody += JsonBodyGenerator.keyValueJson("tag", tag) + ","; + } + postBody = postBody.substring(0, postBody.length()-1) + "]"; + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/tags", repoModel.getNodeRef()); + return restWrapper.processModels(RestTagModelsCollection.class, request); + } + + + /** + * Deletes a tag for a specific content node using DELETE call on nodes/{nodeId}/tags/{tagId} + * + * @param content + * @param tag + * @return + * @throws JsonToModelConversionException + */ + public void deleteTag(RestTagModel tag) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/tags/{tagId}", repoModel.getNodeRef(), tag.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Get node tags using GET call on 'nodes/{nodeId}/tags' + * + * @param tag + * @return + * @throws Exception + */ + public RestTagModelsCollection getNodeTags() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/tags?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestTagModelsCollection.class, request); + } + + /** + * Create new nodes using POST call on 'nodes/{nodeId}/children + * + * @param node + * @return + * @throws Exception + */ + public RestNodeModel createNode(RestNodeBodyModel node) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, node.toJson(), "nodes/{nodeId}/children?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Create new nodes using POST call on 'nodes/{nodeId}/children + * + * You need to specify first the multipart call {@link RestWrapper#usingMultipartFile(java.io.File)} + * + * usingMultipartFile(new File("your-local-file.txt")).withCoreAPI().usingNode(ContentModel.my()).createNode(); + * @return + * @throws Exception + */ + public RestNodeModel createNode() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.POST, "nodes/{nodeId}/children", repoModel.getNodeRef()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Retrieve content for a specific node using GET call on "nodes/{nodeId}/content" + * + * @return + * @throws Exception + */ + public RestResponse getNodeContent() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/content?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Retrieve content for a specific node using GET call on "nodes/{nodeId}/content" + * + * @return + * @param nodeId + * @throws Exception + */ + public RestResponse getNodeContent(String nodeId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/content?{parameters}", nodeId, restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Create node rendition using POST call on '/nodes/{nodeId}/renditions' + * + * @param renditionId id of rendition to be created + * @return + * @throws Exception + */ + public void createNodeRendition(String renditionId) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("id", renditionId); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/renditions", repoModel.getNodeRef()); + restWrapper.processEmptyModel(request); + } + + /** + * Get node rendition using GET call on '/nodes/{nodeId}/renditions/{renditionId} + * + * @param renditionId id of rendition to be retrieved + * @return + * @throws Exception + */ + public RestRenditionInfoModel getNodeRendition(String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/renditions/{renditionId}", repoModel.getNodeRef(), renditionId); + return restWrapper.processModel(RestRenditionInfoModel.class, request); + } + + /** + * Get node rendition using GET call on 'nodes/{nodeId}/renditions/{renditionId} Please note that it retries to get + * the renditions response several times because on the alfresco server the rendition can take a while to be created. + * + * @return + * @throws Exception + */ + public RestRenditionInfoModel getNodeRenditionUntilIsCreated(String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/renditions/{renditionId}",repoModel.getNodeRef(), renditionId); + RestRenditionInfoModel renditions = restWrapper.processModel(RestRenditionInfoModel.class, request); + int retry = 0; + if (restWrapper.getStatusCode().equals(HttpStatus.OK.toString())) + { + while (renditions.getStatus().equals("NOT_CREATED") && retry < Utility.retryCountSeconds - 8) + { + Utility.waitToLoopTime(1); + renditions = restWrapper.processModel(RestRenditionInfoModel.class, request); + retry++; + } + } + return renditions; + } + + /** + * Get node rendition content using GET call on + * 'nodes/{nodeId}/renditions/{renditionId}/content Please note that it + * retries to get the renditions response several times because on the + * alfresco server the rendition can take a while to be created. + * + * @return + * @throws Exception + */ + public RestResponse getNodeRenditionContentUntilIsCreated(String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/renditions/{renditionId}/content", repoModel.getNodeRef(), + renditionId); + RestResponse response = restWrapper.process(request); + int retry = 0; + while (response.getStatusCode().equals(HttpStatus.NOT_FOUND.toString()) && retry < Utility.retryCountSeconds) + { + Utility.waitToLoopTime(1); + response = restWrapper.process(request); + retry++; + } + + return response; + } + + /** + * Get node rendition content using GET call on + * 'nodes/{nodeId}/renditions/{renditionId}/content + * + * @return + * @throws Exception + */ + public RestResponse getNodeRenditionContent(String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/renditions/{renditionId}/content", repoModel.getNodeRef(), + renditionId); + return restWrapper.process(request); + } + + /** + * Get rendition information for available renditions for the node using GET call on + * 'nodes/{nodeId}/renditions' + * @return + * @throws Exception + */ + public RestRenditionInfoModelCollection getNodeRenditionsInfo() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/renditions?{parameters}", repoModel.getNodeRef(), + restWrapper.getParameters()); + return restWrapper.processModels(RestRenditionInfoModelCollection.class, request); + } + + /** + * Get a node's children using GET call 'nodes/{nodeId}/children + * + * @return a collection of nodes + * @throws Exception + */ + public RestNodeModelsCollection listChildren() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/children?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestNodeModelsCollection.class, request); + } + + /** + * Move a node to a target folder + * + * @param moveBody a {@link RestNodeBodyMoveCopyModel} containing at least the target parent id + * @return the moved node's new information + * @throws Exception + */ + public RestNodeModel move(RestNodeBodyMoveCopyModel moveBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, moveBody.toJson(), "nodes/{nodeId}/move?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Copy a node to a target folder + * + * @param copyBody a {@link RestNodeBodyMoveCopyModel} containing at least the target parent id + * @return the moved node's new information + * @throws Exception + */ + public RestNodeModel copy(RestNodeBodyMoveCopyModel copyBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, copyBody.toJson(), + "nodes/{nodeId}/copy?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + + /** + * Lock a specific node using POST call on "nodes/{nodeId}/lock" + * + * @return + * @throws Exception + */ + public RestNodeModel lockNode(RestNodeLockBodyModel lockBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, lockBody.toJson(), "nodes/{nodeId}/lock?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Unlock a specific node using POST call on "nodes/{nodeId}/unlock" + * + * @return + * @throws Exception + */ + public RestNodeModel unlockNode() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.POST, "nodes/{nodeId}/unlock?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * @return {@link NodesBuilder} - help you define new nodes using rest API calls + */ + public NodesBuilder defineNodes() + { + return new NodesBuilder(restWrapper, this.repoModel); + } + + /** + * Update a specific node using PUT call on "nodes/{nodeId}" + * + * @param putBody + * @return + * @throws Exception + */ + public RestNodeModel updateNode(String putBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, putBody, "nodes/{nodeId}?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + request.setContentType("UTF-8"); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Retrieve targets for a specific node using GET call on "nodes/{nodeId}/targets + * + * @return + * @throws Exception + */ + public RestNodeAssociationModelCollection getNodeTargets() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/targets?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestNodeAssociationModelCollection.class, request); + } + + /** + * Create new target nodes using POST call on '/nodes/{nodeId}/targets' + * + * @param target + * @return + * @throws Exception + */ + public RestNodeAssocTargetModel createTargetForNode(RestNodeAssocTargetModel target) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, target.toJson(), "nodes/{nodeId}/targets?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeAssocTargetModel.class, request); + } + + /** + * Delete a target for a specific node using DELETE call on + * nodes/{nodeId}/targets/{targetId} + * + * @param target + * @throws Exception + */ + public void deleteTarget(RestNodeAssocTargetModel target) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/targets/{targetId}", repoModel.getNodeRef(), + target.getTargetId()); + restWrapper.processEmptyModel(request); + } + + /** + * Get sources for a specific node using GET call on GET /nodes/{nodeId}/sources + * + * @return + * @throws Exception + */ + public RestNodeAssociationModelCollection getNodeSources() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "/nodes/{nodeId}/sources?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestNodeAssociationModelCollection.class, request); + } + + /** + * Updates the content of the node with identifier nodeId using PUT call "/nodes/{nodeId}/content" + * + * @param nodeContent + * @return + * @throws Exception + */ + public RestNodeModel updateNodeContent(File nodeContent) throws Exception + { + restWrapper.usingContentType(ContentType.BINARY); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, Files.readFile(nodeContent), "nodes/{nodeId}/content?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + request.setContentType("UTF-8"); + restWrapper.usingContentType(ContentType.JSON); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Copies the node nodeId to the parent folder node targetParentId using POST call "nodes/{nodeId}/copy" + * + * @param postBody + * @return + */ + public RestNodeModel copyNode(String postBody) + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/copy?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Get a node's parents using GET call 'nodes/{nodeId}/parents + * + * @return a collection of nodes + * @throws Exception + */ + public RestNodeAssociationModelCollection getParents() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/parents?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestNodeAssociationModelCollection.class, request); + } + + /** + * Get a node's secondary children using GET call 'nodes/{nodeId}/secondary-children + * + * @return a collection of nodes + * @throws Exception + */ + public RestNodeAssociationModelCollection getSecondaryChildren() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/secondary-children?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestNodeAssociationModelCollection.class, request); + } + + /** + * Create secondary children association using POST call 'nodes/{nodeId}/secondary-children + * Use a list of secondary children nodes + * + * @return a collection of nodes + * @throws Exception + */ + public RestNodeChildAssocModelCollection createSecondaryChildren(String secondaryChildren) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, secondaryChildren, "nodes/{nodeId}/secondary-children?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestNodeChildAssocModelCollection.class, request); + } + + /** + * Delete secondary children using DELETE call 'nodes/{nodeId}/secondary-children/{childId} + * + * @return a collection of nodes + * @throws Exception + */ + public void deleteSecondaryChild(RestNodeAssociationModel child) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/secondary-children/{childId}?{parameters}", repoModel.getNodeRef(), child.getId(), restWrapper.getParameters()); + restWrapper.processEmptyModel(request); + } + + /** + * Gets the version history as an ordered list for the specified nodeId using GET call 'nodes/{nodeId}/versions + * + * @return + */ + public RestVersionModelsCollection listVersionHistory() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/versions?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestVersionModelsCollection.class, request); + } + + /** + * Delete the version identified by versionId for nodeId using DELETE call 'nodes/{nodeId}versions/{versionId} + * + * @param versionId + */ + public void deleteNodeVersion(String versionId) + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}/versions/{versionId}", repoModel.getNodeRef(), versionId); + restWrapper.processEmptyModel(request); + } + + /** + * Gets the version information versionId for node nodeId using GET call 'nodes/{nodeId}/versions/{versionId} + * + * @param versionId + * @return + */ + public RestVersionModel getVersionInformation(String versionId) + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/versions/{versionId}", repoModel.getNodeRef(), versionId); + return restWrapper.processModel(RestVersionModel.class, request); + } + + /** + * Gets the content for versionId of node nodeId using GET call 'nodes/{nodeId}/versions/{versionId}/content + * + * @param versionId + * @return + */ + public RestResponse getVersionContent(String versionId) + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/versions/{versionId}/content?{parameters}", repoModel.getNodeRef(), versionId, restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Revert the version identified by versionId and nodeId to the node using POST call 'nodes/{nodeId}/versions/{versionId}/revert + * + * @param versionId + * @param postBody + * @return + */ + public RestVersionModel revertVersion(String versionId, String postBody) + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/versions/{versionId}/revert?{parameters}", repoModel.getNodeRef(), versionId, restWrapper.getParameters()); + return restWrapper.processModel(RestVersionModel.class, request); + } + + /** + * Delete a specific node using DELETE call on nodes/{nodeId} + * + * @param nodeModel + * @return + * @throws Exception + */ + public void deleteNode(RestNodeModel nodeModel) throws Exception + { + deleteNode(nodeModel.getId()); + } + + + /** + * Delete a specific node using DELETE call on nodes/{nodeId} + * + * @param nodeId + * @return + * @throws Exception + */ + public void deleteNode(String nodeId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "nodes/{nodeId}", nodeId); + restWrapper.processEmptyModel(request); + } + + /** + * + *@param nodeId + *@return + */ + public RestActionDefinitionModelsCollection getActionDefinitions() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/action-definitions?{parameters}", repoModel.getNodeRef(), restWrapper.getParameters()); + return restWrapper.processModels(RestActionDefinitionModelsCollection.class, request); + + } + +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/People.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/People.java new file mode 100644 index 0000000000..39f612d553 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/People.java @@ -0,0 +1,495 @@ +package org.alfresco.rest.requests; + +import static io.restassured.RestAssured.given; + +import java.io.File; + +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.EmptyJsonResponseException; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestActivityModelsCollection; +import org.alfresco.rest.model.RestFavoriteSiteModel; +import org.alfresco.rest.model.RestGroupsModelsCollection; +import org.alfresco.rest.model.RestNetworkModel; +import org.alfresco.rest.model.RestNetworkModelsCollection; +import org.alfresco.rest.model.RestPersonFavoritesModel; +import org.alfresco.rest.model.RestPersonFavoritesModelsCollection; +import org.alfresco.rest.model.RestPersonModel; +import org.alfresco.rest.model.RestPreferenceModel; +import org.alfresco.rest.model.RestPreferenceModelsCollection; +import org.alfresco.rest.model.RestSiteEntry; +import org.alfresco.rest.model.RestSiteMembershipModelsCollection; +import org.alfresco.rest.model.RestSiteMembershipRequestModel; +import org.alfresco.rest.model.RestSiteMembershipRequestModelsCollection; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +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.UserModel; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; + +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import io.restassured.response.ValidatableResponse; + +/** + * Declares all Rest API under the /people path + */ + +public class People extends ModelRequest +{ + UserModel person; + + public People(UserModel person, RestWrapper restWrapper) throws Exception + { + super(restWrapper); + this.person = person; + Utility.checkObjectIsInitialized(this.person, "person"); + } + + /** + * Retrieve details of a specific person using GET call on "people/{personId}" + */ + public RestPersonModel getPerson() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModel(RestPersonModel.class, request); + } + + /** + * Update a person properties using PUT call on "people/{personId}" + */ + public RestPersonModel updatePerson(String putBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, putBody, "people/{personId}", this.person.getUsername()); + return restWrapper.processModel(RestPersonModel.class, request); + } + + /** + * Retrieve list of activities for a specific person using GET call on "people/{personId}/activities" + * Please note that it retries to get the list of activities several times before returning the empty list. The list of activities are not displayed as + * they are created. + */ + public RestActivityModelsCollection getPersonActivitiesUntilEntriesCountIs(int expectedNoOfEntries) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/activities?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + RestActivityModelsCollection activityCollection = restWrapper.processModels(RestActivityModelsCollection.class, request); + int retry = 0; + if (restWrapper.getStatusCode().equals(HttpStatus.OK.toString())) + { + while ((activityCollection.isEmpty() || activityCollection.getPagination().getCount() != expectedNoOfEntries) && retry < Utility.retryCountSeconds + 20) + { + Utility.waitToLoopTime(2); + activityCollection = restWrapper.processModels(RestActivityModelsCollection.class, request); + retry++; + } + } + return activityCollection; + } + + /** + * Retrieve list of activities for a specific person using GET call on "people/{personId}/activities" without retry + */ + public RestActivityModelsCollection getPersonActivities() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/activities?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModels(RestActivityModelsCollection.class, request); + } + + /** + * Retrieve preferences of a specific person using GET call on "people/{personId}/preferences" + */ + public RestPreferenceModelsCollection getPersonPreferences() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/preferences?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModels(RestPreferenceModelsCollection.class, request); + } + + /** + * Retrieve the current site membership requests for a specific person using GET call on "/people/{personId}/site-membership-requests" + */ + public RestSiteMembershipRequestModelsCollection getSiteMembershipRequests() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/site-membership-requests?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModels(RestSiteMembershipRequestModelsCollection.class, request); + } + + /** + * Retrieve a specific person's favorite sites using GET call on "people/{personId}/favorite-sites" + */ + public RestSiteModelsCollection getFavoriteSites() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/favorite-sites?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModels(RestSiteModelsCollection.class, request); + } + + /** + * Add a favorite site for a specific person using POST call on "people/{personId}/favorite-sites" + */ + public RestFavoriteSiteModel addFavoriteSite(SiteModel site) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("id", site.getId()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "people/{personId}/favorite-sites", this.person.getUsername()); + return restWrapper.processModel(RestFavoriteSiteModel.class, request); + } + + /** + * Retrieve a specific preference of a specific person using GET call on "people/{personId}/preferences/{preferenceName}" + */ + public RestPreferenceModel getPersonPreferenceInformation(String preferenceName) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/preferences/{preferenceName}?{parameters}", this.person.getUsername(), preferenceName, restWrapper.getParameters()); + return restWrapper.processModel(RestPreferenceModel.class, request); + } + + /** + * Remove a specific site from favorite sites list of a person using DELETE call on "people/{personId}/favorite-sites/{siteId}" + */ + public void removeFavoriteSite(SiteModel site) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "people/{personId}/favorite-sites/{siteId}", this.person.getUsername(), site.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Returns information on favorite site siteId of person personId. GET call on "people/{personId}/favorite-sites/{siteId}" + */ + public RestSiteModel getFavoriteSite(SiteModel site) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/favorite-sites/{siteId}?{parameters}", this.person.getUsername(), site.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestSiteModel.class, request); + } + + /** + * Delete site member with DELETE call on "people/{personId}/sites/{siteId}" + */ + public void deleteSiteMember(SiteModel site) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "people/{personId}/sites/{siteId}", person.getUsername(), site.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Add new site membership request using POST call on "people/{personId}/site-membership-requests" + */ + public RestSiteMembershipRequestModel addSiteMembershipRequest(String siteMembershipRequest) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, siteMembershipRequest, "people/{personId}/site-membership-requests", this.person.getUsername()); + return restWrapper.processModel(RestSiteMembershipRequestModel.class, request); + } + + /** + * Add new site membership request using POST call on "people/{personId}/site-membership-requests" + */ + public RestSiteMembershipRequestModel addSiteMembershipRequest(SiteModel siteModel) throws Exception + { + String json = JsonBodyGenerator.siteMemberhipRequest("Please accept me", siteModel, "New request"); + return addSiteMembershipRequest(json); + } + + /** + * Add new site membership request using POST call on "people/{personId}/site-membership-requests" + */ + public RestSiteMembershipRequestModel addSiteMembershipRequest(String message, SiteModel siteModel, String title) throws Exception + { + String json = JsonBodyGenerator.siteMemberhipRequest(message, siteModel, title); + return addSiteMembershipRequest(json); + } + + /** + * Get site membership information using GET call on "/people/{personId}/sites" + */ + + public RestSiteMembershipModelsCollection getSitesMembershipInformation() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/sites?{parameters}", person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModels(RestSiteMembershipModelsCollection.class, request); + } + + /** + * Retrieve site membership information for a person using GET call on "people/{personId}/sites/{siteId}" + */ + public RestSiteEntry getSiteMembership(SiteModel site) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/sites/{siteId}?{parameters}", person.getUsername(), site.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestSiteEntry.class, request); + } + + /** + * Retrieve site membership request details for a person/site using GET call on "people/{personId}/site-membership-requests/{siteId}" + */ + public RestSiteMembershipRequestModel getSiteMembershipRequest(SiteModel site) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/site-membership-requests/{siteId}?{parameters}", person.getUsername(), + site.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestSiteMembershipRequestModel.class, request); + } + + /** + * Delete site membership request with DELETE call on "/people/{personId}/site-membership-requests/{siteId}" + */ + public void deleteSiteMembershipRequest(SiteModel site) throws JsonToModelConversionException, EmptyJsonResponseException + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "people/{personId}/site-membership-requests/{siteId}", person.getUsername(), + site.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Update site membership request using PUT call on "people/{personId}/site-membership-requests/{siteId}" + */ + public RestSiteMembershipRequestModel updateSiteMembershipRequest(SiteModel siteModel, String message) throws Exception + { + String json = JsonBodyGenerator.siteMemberhipRequest(message, siteModel, "New request"); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, json, "people/{personId}/site-membership-requests/{siteId}", person.getUsername(), + siteModel.getId()); + return restWrapper.processModel(RestSiteMembershipRequestModel.class, request); + } + + /** + * Retrieve favorite site for a specific user using GET call on "people/{personId}/favorites/{favoriteId}" + */ + public RestPersonFavoritesModel getFavorite(String favoriteId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/favorites/{favoriteId}?{parameters}", this.person.getUsername(), favoriteId, restWrapper.getParameters()); + return restWrapper.processModel(RestPersonFavoritesModel.class, request); + } + + /** + * Retrieve specific favorites for a specific user using GET call on "people/{personId}/favorites" + */ + public RestPersonFavoritesModelsCollection getFavorites() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/favorites?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModels(RestPersonFavoritesModelsCollection.class, request); + } + + /** + * Add a folder to favorites for a specific user using POST call on "people/{personId}/favorites" + */ + public RestPersonFavoritesModel addFolderToFavorites(FolderModel folderModel) throws Exception + { + String jsonPost = JsonBodyGenerator.targetFolderWithGuid(folderModel); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, jsonPost, "people/{personId}/favorites?{parameters}", this.person.getUsername(), + restWrapper.getParameters()); + return restWrapper.processModel(RestPersonFavoritesModel.class, request); + } + + /** + * Add a folder to favorites for a specific user using POST call on "people/{personId}/favorites" + */ + public RestPersonFavoritesModel addFileToFavorites(FileModel fileModel) throws Exception + { + String jsonPost = JsonBodyGenerator.targetFileWithGuid(fileModel); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, jsonPost, "people/{personId}/favorites?{parameters}", this.person.getUsername(), + restWrapper.getParameters()); + return restWrapper.processModel(RestPersonFavoritesModel.class, request); + } + + /** + * Add a site to favorites for a specific user using POST call on "people/{personId}/favorites" + */ + public RestPersonFavoritesModel addSiteToFavorites(SiteModel siteModel) throws Exception + { + String jsonPost = JsonBodyGenerator.targetSiteWithGuid(siteModel); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, jsonPost, "people/{personId}/favorites?{parameters}", this.person.getUsername(), + restWrapper.getParameters()); + return restWrapper.processModel(RestPersonFavoritesModel.class, request); + } + + /** + * Delete site from favorites for a specific user using DELETE call on "people/{personId}/favorites/{favoriteId}" + */ + public RestWrapper deleteSiteFromFavorites(SiteModel site) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "people/{personId}/favorites/{favoriteId}", this.person.getUsername(), site.getGuid()); + restWrapper.processEmptyModel(request); + return restWrapper; + } + + /** + * Delete a folder from favorites for a specific user using DELETE call on "people/{personId}/favorites/{favoriteId}" + */ + public RestWrapper deleteFolderFromFavorites(FolderModel folderModel) throws Exception + { + String jsonPost = JsonBodyGenerator.targetFolderWithGuid(folderModel); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.DELETE, jsonPost, "people/{personId}/favorites/{favoriteId}", this.person.getUsername(), + folderModel.getNodeRef()); + restWrapper.processEmptyModel(request); + return restWrapper; + } + + /** + * Delete a file from favorites for a specific user using DELETE call on "people/{personId}/favorites/{favoriteId}" + */ + public RestWrapper deleteFileFromFavorites(FileModel fileModel) throws Exception + { + String jsonPost = JsonBodyGenerator.targetFileWithGuid(fileModel); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.DELETE, jsonPost, "people/{personId}/favorites/{favoriteId}", this.person.getUsername(), + fileModel.getNodeRef()); + restWrapper.processEmptyModel(request); + return restWrapper; + } + + /** + * Retrieve details of the current user network using GET call on "people/{personId}/networks/{networkId}" + */ + public RestNetworkModel getNetwork() throws Exception + { + return getNetwork(person); + } + + /** + * Retrieve details of a specific network using GET call on "people/{personId}/networks/{networkId}" + */ + public RestNetworkModel getNetwork(UserModel tenant) throws Exception + { + Utility.checkObjectIsInitialized(tenant.getDomain(), "tenant.getDomain()"); + String personId = tenant.getUsername().contains("-me-@")? "-me-" : tenant.getUsername(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/networks/{networkId}?{parameters}", personId, tenant.getDomain(), restWrapper.getParameters()); + return restWrapper.processModel(RestNetworkModel.class, request); + } + + /** + * Retrieve details of all networks related to the current person using GET call on "people/{personId}/networks" + */ + public RestNetworkModelsCollection getNetworks() throws Exception + { + return getNetworks(person); + } + + /** + * Retrieve details of all networks related to a specific person using GET call on "people/{personId}/networks" + */ + public RestNetworkModelsCollection getNetworks(UserModel tenant) throws Exception + { + String personId = tenant.getUsername().contains("-me-@") ? "-me-" : tenant.getUsername(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/networks?{parameters}", personId, restWrapper.getParameters()); + return restWrapper.processModels(RestNetworkModelsCollection.class, request); + } + + /** + * Create new person with given newPerson details using POST call on "people" + */ + public RestPersonModel createPerson(RestPersonModel newPerson) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, newPerson.toJson(), "people"); + return restWrapper.processModel(RestPersonModel.class, request); + } + + /** + * Get people avatar image using GET call on '/people/{personId}/avatar Please note that it retries to get the + * renditions response several times because on the alfresco server the rendition can take a while to be created. + */ + public RestResponse downloadAvatarContent() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/avatar?{parameters}", + this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Delete avatar image with DELETE call on "/people/{personId}/avatar}" + */ + public void resetAvatarImageRequest() throws JsonToModelConversionException, EmptyJsonResponseException + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "people/{personId}/avatar", this.person.getUsername()); + restWrapper.processEmptyModel(request); + } + + /** + * Update avatar image PUT call on 'people/{nodeId}/children + */ + public ValidatableResponse uploadAvatarContent(String fullServerUrL, File avatarFile) throws Exception + { + return given().auth().preemptive().basic(person.getUsername(), person.getPassword()).contentType(ContentType.BINARY) + .body(avatarFile).when() + .put(String.format("%s/%s/people/%s/avatar", fullServerUrL, RestAssured.basePath, person.getUsername())) + .then(); + } + + /** + * List group memberships for a person using GET on '/people/{personId}/groups + */ + public RestGroupsModelsCollection listGroupMemberships() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/groups?{parameters}", this.person.getUsername(), restWrapper.getParameters()); + return restWrapper.processModels(RestGroupsModelsCollection.class, request); + } + + public WhereClause where() + { + return new WhereClause(this); + } + +/** + * Construct the Where clause of getFavorites + * You can use the where parameter to restrict the list in the response to entries of a specific kind. The where parameter takes a value. The value is a + * single predicate that can include one or more EXISTS conditions. The EXISTS condition uses a single operand to limit the list to include entries that + * include that one property. The property values are:- + * target/file + * target/folder + * target/site + * Usage: + * where.. targetFileExist().or().targetSiteExist().filterAnd().getFavorites(...) + * At this point this method is working only with @link {@link RestFavoritesApi#getFavorites(UserModel) method. + * + * @author paul.brodner + */ + public class WhereClause + { + String whereClause = "where=(%s))"; + StringBuilder expression = new StringBuilder(); + private People people; + + public WhereClause(People people) + { + this.people = people; + } + + public WhereClause targetFileExist() + { + expression.append("EXISTS(target/file)").append(" "); + return this; + } + + public WhereClause targetFolderExist() + { + expression.append("EXISTS(target/folder)").append(" "); + return this; + } + + public WhereClause targetSiteExist() + { + expression.append(" EXISTS(target/site)").append(" "); + return this; + } + + public WhereClause invalidWhereParameter(String invalidParameter) + { + expression.append(invalidParameter).append(" "); + return this; + } + + public WhereClause or() + { + expression.append("OR").append(" "); + return this; + } + + public RestPersonFavoritesModelsCollection getFavorites() throws Exception + { + restWrapper.withParams(String.format(whereClause, expression)); + return people.getFavorites(); + } + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/ProcessDefinitions.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/ProcessDefinitions.java new file mode 100644 index 0000000000..6349ed2f54 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/ProcessDefinitions.java @@ -0,0 +1,84 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestFormModelsCollection; +import org.alfresco.rest.model.RestHtmlResponse; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.utility.Utility; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /process-definitions path + * + */ +public class ProcessDefinitions extends ModelRequest +{ + RestProcessDefinitionModel processDefinition; + + public ProcessDefinitions(RestWrapper restWrapper) + { + super(restWrapper); + } + + public ProcessDefinitions(RestProcessDefinitionModel processDefinition, RestWrapper restWrapper) + { + super(restWrapper); + this.processDefinition = processDefinition; + } + + /** + * Retrieve 100 process definitions (this is the default size when maxItems is not specified) from Alfresco using GET call on "/process-definitions" + * + * @return + * @throws JsonToModelConversionException + */ + public RestProcessDefinitionModelsCollection getAllProcessDefinitions() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "process-definitions?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestProcessDefinitionModelsCollection.class, request); + } + + /** + * Retrieves a process definition using GET call on "/process-definitions/{processDefinitionId}" + * + * @return + * @throws Exception + */ + public RestProcessDefinitionModel getProcessDefinition() throws Exception + { + Utility.checkObjectIsInitialized(processDefinition, "processDefinition"); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "process-definitions/{processDefinitionId}?{parameters}", + processDefinition.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestProcessDefinitionModel.class, request); + } + + /** + * Retrieves an image that represents a single process definition using GET call on "/process-definitions/{processDefinitionId}/image" + * + * @return + * @throws Exception + */ + public RestHtmlResponse getProcessDefinitionImage() throws Exception + { + Utility.checkObjectIsInitialized(processDefinition, "processDefinition"); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "process-definitions/{processDefinitionId}/image", processDefinition.getId()); + return restWrapper.processHtmlResponse(request); + } + + /** + * Retrieves start form type definitions using GET call on "/process-definitions/{processDefinitionId}/start-form-model" + * + * @return + * @throws Exception + */ + public RestFormModelsCollection getProcessDefinitionStartFormModel() throws Exception + { + Utility.checkObjectIsInitialized(processDefinition, "processDefinition.onModel()"); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "process-definitions/{processDefinitionId}/start-form-model?{parameters}", + processDefinition.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestFormModelsCollection.class, request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Processes.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Processes.java new file mode 100644 index 0000000000..a857789328 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Processes.java @@ -0,0 +1,249 @@ +package org.alfresco.rest.requests; + +import javax.json.JsonArrayBuilder; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.rest.model.RestProcessVariableCollection; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.UserModel; +import org.springframework.http.HttpMethod; + +/** + * Created by Claudia Agache on 10/11/2016. + */ + +public class Processes extends ModelRequest +{ + private ProcessModel processModel; + public Processes(RestWrapper restWrapper) + { + super(restWrapper); + } + + public Processes(ProcessModel processModel, RestWrapper restWrapper) { + this(restWrapper); + this.processModel = processModel; + } + + /** + * Retrieve 100 processes (this is the default size when maxItems is not specified) from Alfresco using GET call on "/processes" + * + * @return + * @throws JsonToModelConversionException + */ + public RestProcessModelsCollection getProcesses() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "processes?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestProcessModelsCollection.class, request); + } + + /** + * Retrieve all process variables from Alfresco using GET /processes/{processId}/variables + * + * @return + * @throws JsonToModelConversionException + */ + public RestProcessVariableCollection getProcessVariables() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "processes/{processId}/variables?{parameters}", processModel.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestProcessVariableCollection.class, request); + } + + /** + * Retrieves the process identified by processId using GET /processes/{processId} + * @return + * @throws Exception + */ + public RestProcessModel getProcess() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "processes/{processId}?{parameters}", processModel.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestProcessModel.class, request); + } + + /** + * Delete a process using DELETE call on processes/{processId} + * + * @throws Exception + */ + public void deleteProcess() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "processes/{processId}", processModel.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Starts new process using POST /processes + * + * @param processDefinitionKey + * @param assignee + * @param sendEmailNotifications + * @param priority + * @return + * @throws Exception + */ + public RestProcessModel addProcess(String processDefinitionKey, UserModel assignee, boolean sendEmailNotifications, Priority priority) throws Exception + { + String postBody = JsonBodyGenerator.process(processDefinitionKey, assignee, sendEmailNotifications, priority); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "processes"); + return restWrapper.processModel(RestProcessModel.class, request); + } + + /** + * Starts new process with given input body using POST /processes + * + * @param postBody + * @return + * @throws Exception + */ + public RestProcessModel addProcessWithBody(String postBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "processes"); + return restWrapper.processModel(RestProcessModel.class, request); + } + + /** + * Add process variable using POST /processes/{processId}/variables + * + * @param variableModel + * @return + * @throws JsonToModelConversionException + */ + public RestProcessVariableModel addProcessVariable(RestProcessVariableModel variableModel) throws Exception + { + String postBody = JsonBodyGenerator.processVariable(variableModel); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "processes/{processId}/variables", processModel.getId()); + return restWrapper.processModel(RestProcessVariableModel.class, request); + } + + /** + * Add process variables using POST /processes/{processId}/variables + * + * @param processVariablesModel + * @return + * @throws JsonToModelConversionException + */ + public RestProcessVariableCollection addProcessVariables(RestProcessVariableModel... processVariablesModel) throws Exception + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for(RestProcessVariableModel processVariableModel: processVariablesModel) + { + array.add(JsonBodyGenerator.defineJSON().add("name", processVariableModel.getName()) + .add("value", processVariableModel.getValue()) + .add("type", processVariableModel.getType())).toString(); + } + + String postBody = array.build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "processes/{processId}/variables", processModel.getId()); + return restWrapper.processModels(RestProcessVariableCollection.class, request); + } + + + /** + * Retrieve all process items from Alfresco using GET /processes/{processId}/items + * + * @return + * @throws JsonToModelConversionException + */ + public RestItemModelsCollection getProcessItems() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "processes/{processId}/items?{parameters}", processModel.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestItemModelsCollection.class, request); + } + + /** + * Delete a process variable using DELETE call on processes/{processId}/variables/{variableName} + * + * @param variableModel + * @throws Exception + */ + public void deleteProcessVariable(RestProcessVariableModel variableModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "processes/{processId}/variables/{variableName}", processModel.getId(), + variableModel.getName()); + restWrapper.processEmptyModel(request); + } + + /** + * Update/Add process variable using PUT /processes/{processId}/variables/{variableName} + * + * @param variableModel + * @return + * @throws JsonToModelConversionException + */ + public RestProcessVariableModel updateProcessVariable(RestProcessVariableModel variableModel) throws Exception + { + String postBody = JsonBodyGenerator.processVariable(variableModel); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "processes/{processId}/variables/{variableName}", processModel.getId(), + variableModel.getName()); + return restWrapper.processModel(RestProcessVariableModel.class, request); + } + + /** + * Retrieve all tasks of a specified process from Alfresco using GET /processes/{processId}/tasks + * + * @return + * @throws JsonToModelConversionException + */ + public RestTaskModelsCollection getProcessTasks() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "processes/{processId}/tasks?{parameters}", processModel.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestTaskModelsCollection.class, request); + } + + /** + * Add process item using POST /processes/{processId}/items + * + * @param fileModel + * @return + * @throws JsonToModelConversionException + */ + public RestItemModel addProcessItem(FileModel fileModel) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("id", fileModel.getNodeRefWithoutVersion()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "processes/{processId}/items", processModel.getId()); + return restWrapper.processModel(RestItemModel.class, request); + } + + /** + * Add process items using POST /processes/{processId}/items + * + * @param fileModels + * @return + * @throws JsonToModelConversionException + */ + public RestItemModelsCollection addProcessItems(FileModel... fileModels) throws Exception + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for(FileModel fileModel: fileModels) + { + array.add(JsonBodyGenerator.defineJSON().add("id", fileModel.getNodeRefWithoutVersion())); + } + + String postBody = array.build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "processes/{processId}/items", processModel.getId()); + return restWrapper.processModels(RestItemModelsCollection.class, request); + } + + /** + * Delete a process item using DELETE call on processes/{processId}/items/{itemId} + * + * @param itemModel + * @throws Exception + */ + public void deleteProcessItem(RestItemModel itemModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "processes/{processId}/items/{itemId}", processModel.getId(), itemModel.getId()); + restWrapper.processEmptyModel(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Queries.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Queries.java new file mode 100644 index 0000000000..99780b53b4 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Queries.java @@ -0,0 +1,57 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestNodeModelsCollection; +import org.alfresco.rest.model.RestPersonModelsCollection; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.springframework.http.HttpMethod; + +public class Queries extends ModelRequest +{ + + public Queries(RestWrapper restWrapper) + { + super(restWrapper); + } + + /** + * GET on queries/nodes + * + * @return + * @throws Exception + */ + public RestNodeModelsCollection findNodes() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "queries/nodes?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestNodeModelsCollection.class, request); + } + + /** + * GET on queries/people + * + * @return + * @throws Exception + */ + public RestPersonModelsCollection findPeople() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "queries/people?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestPersonModelsCollection.class, request); + } + + /** + * GET on queries/people + * + * @return + * @throws Exception + */ + public RestSiteModelsCollection findSites() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "queries/sites?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestSiteModelsCollection.class, request); + } + + + + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/SharedLinks.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/SharedLinks.java new file mode 100644 index 0000000000..44887ae68c --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/SharedLinks.java @@ -0,0 +1,194 @@ +package org.alfresco.rest.requests; + +import java.util.HashMap; + +import javax.json.JsonArrayBuilder; + +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.RestRenditionInfoModel; +import org.alfresco.rest.model.RestRenditionInfoModelCollection; +import org.alfresco.rest.model.RestSharedLinksModel; +import org.alfresco.rest.model.RestSharedLinksModelCollection; +import org.alfresco.utility.model.FileModel; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /shared-links path + * + * @author Meenal Bhave + */ +public class SharedLinks extends ModelRequest +{ + public SharedLinks(RestWrapper restWrapper) + { + super(restWrapper); + } + + /** + * Retrieve sharedLinks using GET call on /shared-links + * + * @return RestSharedLinksModelCollection + * @throws JsonToModelConversionException + */ + public RestSharedLinksModelCollection getSharedLinks() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "shared-links?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestSharedLinksModelCollection.class, request); + } + + /** + * Retrieve details for a specific sharedLink using GET call on "shared-links/{sharedLinkId}" + * + * @param sharedLinksModel + * @return RestSharedLinkModel + * @throws JsonToModelConversionException + */ + public RestSharedLinksModel getSharedLink(RestSharedLinksModel sharedLinksModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "shared-links/{sharedLinkId}?{parameters}", sharedLinksModel.getId(), + restWrapper.getParameters()); + return restWrapper.processModel(RestSharedLinksModel.class, request); + } + + /** + * Retrieve content for a specific sharedLink using GET call on "shared-links/{sharedLinkId}/content" + * + * @param sharedLinksModel + * @return RestResponse + * @throws Exception + */ + public RestResponse getSharedLinkContent(RestSharedLinksModel sharedLinksModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "shared-links/{sharedLinkId}/content?{parameters}", sharedLinksModel.getId(), + restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Send email with a specific sharedLink using POST call on "shared-links/{sharedLinkId}/email" + * + * @param sharedLinksModel + * @param postBody + * @return RestResponse + * @throws Exception + */ + public RestResponse sendSharedLinkEmail(RestSharedLinksModel sharedLinksModel, String postBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "shared-links/{sharedLinkId}/email?{parameters}", sharedLinksModel.getId(), + restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Retrieves Renditions for the specified sharedLink + * + * @return RestRenditionInfoModelCollection + * @throws JsonToModelConversionException + */ + public RestRenditionInfoModelCollection getSharedLinkRenditions(RestSharedLinksModel sharedLinksModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "shared-links/{sharedLinkId}/renditions?{parameters}", sharedLinksModel.getId(), + restWrapper.getParameters()); + return restWrapper.processModels(RestRenditionInfoModelCollection.class, request); + } + + /** + * Retrieves specific Rendition for the specified sharedLink + * + * @param sharedLinksModel + * @param renditionId + * @return RestRenditionInfoModel + * @throws JsonToModelConversionException + */ + public RestRenditionInfoModel getSharedLinkRendition(RestSharedLinksModel sharedLinksModel, String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "shared-links/{sharedLinkId}/renditions/{renditionId}?{parameters}", + sharedLinksModel.getId(), renditionId, restWrapper.getParameters()); + return restWrapper.processModel(RestRenditionInfoModel.class, request); + } + + /** + * Retrieve rendition content for the specified sharedLink using GET call on "shared-links/{sharedLinkId}/renditions/{renditionId}/content" + * + * @param sharedLinksModel + * @param renditionId + * @return RestRenditionInfoModel + * @throws Exception + */ + public RestResponse getSharedLinkRenditionContent(RestSharedLinksModel sharedLinksModel, String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "shared-links/{sharedLinkId}/renditions/{renditionId}/content?{parameters}", + sharedLinksModel.getId(), renditionId, restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Removes SharedLink for the specified file, the sharedlink is deleted, file is unshared as a result + * + * @param RestSharedLinksModel + * @return void + * @throws Exception + */ + public void deleteSharedLink(RestSharedLinksModel sharedLinksModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "shared-links/{sharedLinkId}", sharedLinksModel.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Creates SharedLink for the specified file + * + * @param file + * @return RestSharedLinksModel + * @throws Exception + */ + public RestSharedLinksModel createSharedLink(FileModel file) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("nodeId", file.getNodeRefWithoutVersion()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "shared-links?{parameters}", restWrapper.getParameters()); + return restWrapper.processModel(RestSharedLinksModel.class, request); + } + + /** + * Creates SharedLink for all the specified files + * + * @param file list + * @return RestSharedLinksModelCollection + * @throws Exception + */ + public RestSharedLinksModelCollection createSharedLinks(FileModel... files) throws Exception + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for (FileModel file : files) + { + array.add(JsonBodyGenerator.defineJSON().add("nodeId", file.getNodeRefWithoutVersion())); + } + String postBody = array.build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "shared-links?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestSharedLinksModelCollection.class, request); + + } + + /** + * Creates SharedLink for the specified file, with the given expiry date + * + * @param file + * @param expiryDate: format: "2027-03-23T23:00:00.000+0000"; + * @return RestSharedLinksModel + * @throws Exception + */ + public RestSharedLinksModel createSharedLinkWithExpiryDate(FileModel file, String expiryDate) throws Exception + { + HashMap body = new HashMap(); + body.put("nodeId", file.getNodeRefWithoutVersion()); + body.put("expiresAt", expiryDate); + String postBody = JsonBodyGenerator.keyValueJson(body); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "shared-links?{parameters}", restWrapper.getParameters()); + return restWrapper.processModel(RestSharedLinksModel.class, request); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Site.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Site.java new file mode 100644 index 0000000000..23873146cc --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Site.java @@ -0,0 +1,239 @@ +package org.alfresco.rest.requests; + +import java.util.List; + +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.RestSiteContainerModel; +import org.alfresco.rest.model.RestSiteContainerModelsCollection; +import org.alfresco.rest.model.RestSiteMemberModel; +import org.alfresco.rest.model.RestSiteMemberModelsCollection; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.alfresco.rest.model.RestSitePersonMembershipRequestModelsCollection; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /sites path + * + */ +public class Site extends ModelRequest +{ + private SiteModel site; + + public Site(SiteModel site, RestWrapper restWrapper) + { + super(restWrapper); + this.site = site; + } + + /** + * Retrieve one site using GET call on "sites/{siteId}" + * + * @param siteId + * @return + * @throws JsonToModelConversionException + */ + public RestSiteModel getSite() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}?{parameters}", this.site.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestSiteModel.class, request); + } + + /** + * Retrieve one site using GET call on "sites/{siteId}" along with relations parameter + * + * @param siteId + * @return + * @throws JsonToModelConversionException + */ + public List getSiteWithRelations() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}?{parameters}", this.site.getId(), restWrapper.getParameters()); + return restWrapper.processRelationsJson(request); + } + + /** + * Retrieve 100 sites (this is the default size when maxItems is not specified) from Alfresco using GET call on TestGroup.SITES + * + * @return + * @throws JsonToModelConversionException + */ + public RestSiteModelsCollection getSites() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestSiteModelsCollection.class, request); + } + + /** + * Retrieve sites using GET call on "sites/{siteId}" along with relations parameter + * + * @return + * @throws JsonToModelConversionException + */ + public List> getSitesWithRelations() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites?{parameters}", restWrapper.getParameters()); + return restWrapper.processSitesRelationsJson(request); + } + + /** + * Add new site member using POST call on "/sites/{siteId}/members" + * + * @param person {@link UserModel} + * @return + * @throws Exception + * @throws JsonToModelConversionException + */ + public RestSiteMemberModel addPerson(UserModel person) throws Exception + { + String siteMemberBody = JsonBodyGenerator.siteMember(person); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, siteMemberBody, "sites/{siteId}/members?{parameters}", site.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestSiteMemberModel.class, request); + } + + /** + * Retrieve all members of a site using GET call on "sites/{siteId}/members" + * + * @return + * @throws JsonToModelConversionException + */ + public RestSiteMemberModelsCollection getSiteMembers() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}/members?{parameters}", site.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestSiteMemberModelsCollection.class, request); + } + + /** + * Retrieve specific member of a site using GET call on "sites/{siteId}/members/{personId}" + * + * @param siteId + * @param personid + * @return + * @throws JsonToModelConversionException + */ + public RestSiteMemberModel getSiteMember(UserModel user) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}/members/{personId}?{parameters}", site.getId(), user.getUsername(), restWrapper.getParameters()); + return restWrapper.processModel(RestSiteMemberModel.class, request); + } + + /** + * Update site member role with PUT call on "sites/{siteId}/members/{personId}" + * @param siteMember + * @return + * @throws JsonToModelConversionException + */ + public RestSiteMemberModel updateSiteMember(UserModel siteMember) throws Exception + { + String json = JsonBodyGenerator.keyValueJson("role", siteMember.getUserRole().toString()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, json, "sites/{siteId}/members/{personId}", site.getId(), siteMember.getUsername()); + return restWrapper.processModel(RestSiteMemberModel.class, request); + } + + /** + * Delete site member with DELETE call on "sites/{siteId}/members/{personId}" + * @param person + * @throws Exception + */ + public void deleteSiteMember(UserModel person) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "sites/{siteId}/members/{personId}", site.getId(), person.getUsername()); + restWrapper.processEmptyModel(request); + } + + /** + * Retrieve all containers of a site using GET call on "sites/{siteId}/containers" + * + * @return + * @throws JsonToModelConversionException + */ + public RestSiteContainerModelsCollection getSiteContainers() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}/containers?{parameters}", site.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestSiteContainerModelsCollection.class, request); + } + + /** + * Retrieve specific container of a site using GET call on "sites/{siteId}/containers/{containerId}" + * + * @param siteId + * @param folderId + * @return + * @throws JsonToModelConversionException + */ + public RestSiteContainerModel getSiteContainer(RestSiteContainerModel container) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}/containers/{containerId}?{parameters}", site.getId(), container.getFolderId(), restWrapper.getParameters()); + return restWrapper.processModel(RestSiteContainerModel.class, request); + } + + /** + * Retrieve specific container of a site using GET call on "sites/{siteId}/containers/{containerId}" + * + * @param siteId + * @param folderId + * @return + * @throws JsonToModelConversionException + */ + public RestSiteContainerModel getSiteContainer(String containerFolder) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "sites/{siteId}/containers/{containerId}?{parameters}", site.getId(), containerFolder, restWrapper.getParameters()); + return restWrapper.processModel(RestSiteContainerModel.class, request); + } + + /** + * Create a collaboration site + * + * @param site information on the site to create + * @return the properties of the created site + * @throws Exception + */ + public RestSiteModel createSite() throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, site.toJson(), "sites?{parameters}", restWrapper.getParameters()); + return restWrapper.processModel(RestSiteModel.class, request); + } + + /** + * Get site membership requests by using GET /site-membership-requests + * + * @return site memberships + * @throws Exception + */ + public RestSitePersonMembershipRequestModelsCollection getSiteMemberships() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "site-membership-requests?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestSitePersonMembershipRequestModelsCollection.class, request); + } + + /** + * Approve a site membership request by using POST call on /sites/{siteId}/site-membership-requests/{inviteeId}/approve + * + * @param siteMember + * @throws Exception + */ + public RestResponse approveSiteMembership(UserModel siteMember) throws Exception + { + String json = JsonBodyGenerator.keyValueJson("role", siteMember.getUserRole().toString()); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/site-membership-requests/{inviteeId}/approve", site.getId(), siteMember.getUsername()); + return restWrapper.process(request); + } + + /** + * Reject a site membership request by using POST call /sites/{siteId}/site-membership-requests/{inviteeId}/reject + * + * @param siteMember + * @throws Exception + */ + public RestResponse rejectSiteMembership(UserModel siteMember) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.POST, "sites/{siteId}/site-membership-requests/{inviteeId}/reject", site.getId(), siteMember.getUsername()); + return restWrapper.process(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Tags.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Tags.java new file mode 100644 index 0000000000..e0da603fda --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Tags.java @@ -0,0 +1,61 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTagModelsCollection; +import org.springframework.http.HttpMethod; + +public class Tags extends ModelRequest +{ + RestTagModel tag; + + public Tags(RestTagModel tag, RestWrapper restWrapper) + { + super(restWrapper); + this.tag = tag; + } + + /** + * Retrieves 100 tags (this is the default size when maxItems is not specified) from Alfresco using GET call on "/tags" + * + * @return + * @throws JsonToModelConversionException + */ + public RestTagModelsCollection getTags() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tags?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestTagModelsCollection.class, request); + } + + /** + * Retrieves a tag with ID using GET call on using GET call on "/tags/{tagId}" + * + * @param tag + * @return + * @throws Exception + */ + public RestTagModel getTag() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tags/{tagId}?{parameters}", tag.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestTagModel.class, request); + } + + /** + * Update a tag using PUT call on tags/{tagId} + * + * @param tag + * @param newTag + * @return + * @throws JsonToModelConversionException + */ + public RestTagModel update(String newTag) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("tag", newTag); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tags/{tagId}", tag.getId()); + + return restWrapper.processModel(RestTagModel.class, request); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Task.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Task.java new file mode 100644 index 0000000000..cc1b11766a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Task.java @@ -0,0 +1,253 @@ +package org.alfresco.rest.requests; + +import javax.json.JsonArrayBuilder; +import javax.json.JsonObject; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestCandidateModelsCollection; +import org.alfresco.rest.model.RestFormModelsCollection; +import org.alfresco.rest.model.RestItemModel; +import org.alfresco.rest.model.RestItemModelsCollection; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.rest.model.RestVariableModelsCollection; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.TaskModel; +import org.springframework.http.HttpMethod; + +public class Task extends ModelRequest +{ + private TaskModel task; + + public Task(RestWrapper restWrapper) + { + super(restWrapper); + } + + public Task(RestWrapper restWrapper, TaskModel task) + { + super(restWrapper); + this.task = task; + } + + /** + * Retrieve a list of tasks visible for the authenticated user using GET call on "/tasks" + * + * @return + * @throws Exception + */ + public RestTaskModelsCollection getTasks() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestTaskModelsCollection.class, request); + } + + /** + * Retrieve the tasks identified by taskId using GET call on "/tasks/{taskId}" + * + * @param taskId + * @return + * @throws Exception + */ + public RestTaskModel getTask() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks/{taskId}?{parameters}", task.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestTaskModel.class, request); + } + + /** + * Update task using PUT put /tasks/{taskId} call + * + * @param newStateValue + * @return + * @throws JsonToModelConversionException + */ + public RestTaskModel updateTask(String newStateValue) throws Exception + { + return updateTask(JsonBodyGenerator.defineJSON().add("state", newStateValue).build()); + } + + /** + * Update task using PUT put /tasks/{taskId} cal + * + * @param inputJson the json used as input for PUT call + * @return + * @throws Exception + */ + public RestTaskModel updateTask(JsonObject inputJson) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, inputJson.toString(), "tasks/{taskId}?{parameters}", task.getId(), restWrapper.getParameters()); + return restWrapper.processModel(RestTaskModel.class, request); + } + + /** + * Retrieve the task variables using GET call on "/tasks/{taskId}/variables" + * + * @param taskId + * @return + * @throws Exception + */ + public RestVariableModelsCollection getTaskVariables() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks/{taskId}/variables?{parameters}", task.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestVariableModelsCollection.class, request); + } + + /** + * Update/Add task variable using PUT put /tasks/{taskId}/variables/{variableName} call + * + * @param taskId + * @param variableName + * @return + * @throws JsonToModelConversionException + */ + public RestVariableModel updateTaskVariable(RestVariableModel variableModel) throws Exception + { + String postBody = JsonBodyGenerator.taskVariable(variableModel); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}/variables/{variableName}", task.getId(), + variableModel.getName()); + return restWrapper.processModel(RestVariableModel.class, request); + } + + /** + * Add task variable using POST /tasks/{taskId}/variables call + * + * @param taskId + * @return + * @throws JsonToModelConversionException + */ + public RestVariableModel addTaskVariable(RestVariableModel variableModel) throws Exception + { + String postBody = JsonBodyGenerator.taskVariable(variableModel); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "tasks/{taskId}/variables", task.getId()); + return restWrapper.processModel(RestVariableModel.class, request); + } + + /** + * Add task variables using POST /tasks/{taskId}/variables call + * + * @param taskId + * @return + * @throws JsonToModelConversionException + */ + public RestVariableModelsCollection addTaskVariables(RestVariableModel... taskVariablesModel) throws Exception + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for(RestVariableModel taskVariableModel: taskVariablesModel) + { + array.add(JsonBodyGenerator.defineJSON().add("scope", taskVariableModel.getScope()).add("name", taskVariableModel.getName()) + .add("type", taskVariableModel.getType()).add("value", taskVariableModel.getValue().toString())); + } + + String postBody = array.build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "tasks/{taskId}/variables", task.getId()); + return restWrapper.processModels(RestVariableModelsCollection.class, request); + } + + /** + * Delete task variable using DELETE /tasks/{taskId}/variables/{variableName} call + * + * @param taskId + * @param variableName + * @return + * @throws JsonToModelConversionException + */ + public void deleteTaskVariable(RestVariableModel variableModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "tasks/{taskId}/variables/{variableName} ", task.getId(), + variableModel.getName()); + restWrapper.processEmptyModel(request); + } + + /** + * Add task item using POST /tasks/{taskId}/items + * + * @param processId + * @return + * @throws JsonToModelConversionException + */ + public RestItemModel addTaskItem(FileModel fileModel) throws Exception + { + String postBody = JsonBodyGenerator.keyValueJson("id", fileModel.getNodeRef().split(";")[0]); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "tasks/{taskId}/items", task.getId()); + return restWrapper.processModel(RestItemModel.class, request); + } + + /** + * Add task items using POST /tasks/{taskId}/items + * + * @param fileModels + * @return + * @throws JsonToModelConversionException + */ + public RestItemModelsCollection addTaskItems(FileModel... fileModels) throws Exception + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for(FileModel fileModel: fileModels) + { + array.add(JsonBodyGenerator.defineJSON().add("id", fileModel.getNodeRef().split(";")[0])); + } + + String postBody = array.build().toString(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "tasks/{taskId}/items", task.getId()); + return restWrapper.processModels(RestItemModelsCollection.class, request); + } + + + /** + * Retrieve the task items using GET call on "/tasks/{taskId}/items" + * + * @param taskId + * @return + * @throws Exception + */ + public RestItemModelsCollection getTaskItems() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks/{taskId}/items?{parameters}", task.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestItemModelsCollection.class, request); + } + + /** + * Retrieves models of the task form type definition + * @param taskModel + * @return + * @throws Exception + */ + public RestFormModelsCollection getTaskFormModel() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks/{taskId}/task-form-model?{parameters}", task.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestFormModelsCollection.class, request); + } + + /** + * Delete a task item using DELETE call on tasks/{taskId}/items/{itemId} + * + * @param taskId + * @param itemId + * + * @throws Exception + */ + public void deleteTaskItem(RestItemModel itemModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "tasks/{taskId}/items/{itemId}", task.getId(), + itemModel.getId()); + restWrapper.processEmptyModel(request); + } + + /** + * Retrieve the task candidates (users and groups) using GET call on "/tasks/{taskId}/candidates" + * + * @param taskId + * @return + * @throws Exception + */ + public RestCandidateModelsCollection getTaskCandidates() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tasks/{taskId}/candidates?{parameters}", task.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestCandidateModelsCollection.class, request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Tenant.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Tenant.java new file mode 100644 index 0000000000..1c553d3431 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Tenant.java @@ -0,0 +1,51 @@ +package org.alfresco.rest.requests; + +import static io.restassured.RestAssured.given; +import static org.alfresco.utility.report.log.Step.STEP; + +import org.alfresco.rest.core.RestProperties; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.UserModel; +import org.springframework.http.HttpStatus; + +import io.restassured.http.ContentType; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; + +/** + * Declares all Rest API under the /alfresco/service/api/tenants path + * + */ +public class Tenant extends ModelRequest +{ + private RestProperties restProperties; + + public Tenant(RestWrapper restWrapper, RestProperties restProperties) + { + super(restWrapper); + this.restProperties = restProperties; + } + /** + * Create tenant using POST call on "http://{server}:{port}/alfresco/service/api/tenants" + * + * @param userModel + * @return + * @throws Exception + * @throws JsonToModelConversionException + */ + public void createTenant(UserModel userModel) throws Exception + { + STEP(String.format("DATAPREP: Create new tenant %s", userModel.getDomain())); + String json = String.format("{\"tenantDomain\": \"%s\", \"tenantAdminPassword\": \"%s\"}", userModel.getDomain(), DataUser.PASSWORD); + RequestSpecification request = given().auth().basic(restWrapper.getTestUser().getUsername(), restWrapper.getTestUser().getPassword()) + .contentType(ContentType.JSON); + Response returnedResponse = request.contentType(ContentType.JSON).body(json) + .post(String.format("%s/%s", restProperties.envProperty().getFullServerUrl(), "alfresco/service/api/tenants")).andReturn(); + if (!String.valueOf(returnedResponse.getStatusCode()).equals(HttpStatus.OK.toString())) + { + throw new Exception(String.format("Tenant is not created: %s", returnedResponse.asString())); + } + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Trashcan.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Trashcan.java new file mode 100644 index 0000000000..16097a122f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/Trashcan.java @@ -0,0 +1,124 @@ +package org.alfresco.rest.requests; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.model.RestNodeModelsCollection; +import org.alfresco.rest.model.RestRenditionInfoModel; +import org.alfresco.rest.model.RestRenditionInfoModelCollection; +import org.alfresco.utility.model.RepoTestModel; +import org.springframework.http.HttpMethod; + +public class Trashcan extends ModelRequest +{ + public Trashcan(RestWrapper restWrapper) + { + super(restWrapper); + } + + /** + * GET on deleted-nodes + * + * @return RestNodeModelsCollection + * @throws Exception + */ + public RestNodeModelsCollection findDeletedNodes() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deleted-nodes?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestNodeModelsCollection.class, request); + } + + /** + * Gets a node from trashcan using GET call on "deleted-nodes/{nodeId}" + * + * @param repoModel + * @return RestNodeModel + * @throws Exception + */ + public RestNodeModel findDeletedNode(RepoTestModel repoModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deleted-nodes/{nodeId}?{parameters}", repoModel.getNodeRefWithoutVersion(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Delete node from trashcan using DELETE call on "deleted-nodes/{nodeId}" + * + * @param repoModel + * @return + * @throws Exception + */ + public void deleteNodeFromTrashcan(RepoTestModel repoModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "deleted-nodes/{nodeId}", repoModel.getNodeRefWithoutVersion()); + restWrapper.processEmptyModel(request); + } + + /** + * Restore node from trashcan using POST call on "deleted-nodes/{nodeId}/restore" + * + * @param repoModel + * @return RestNodeModel + * @throws Exception + */ + public RestNodeModel restoreNodeFromTrashcan(RepoTestModel repoModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.POST, "deleted-nodes/{nodeId}/restore?{parameters}", repoModel.getNodeRefWithoutVersion(), restWrapper.getParameters()); + return restWrapper.processModel(RestNodeModel.class, request); + } + + /** + * Gets a trashcan node content using GET call on "deleted-nodes/{nodeId}/content" + * + * @param repoModel + * @return RestResponse + * @throws Exception + */ + public RestResponse getDeletedNodeContent(RepoTestModel repoModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deleted-nodes/{nodeId}/content?{parameters}", repoModel.getNodeRefWithoutVersion(), restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * Gets all trashcan node renditions using GET call on "/deleted-nodes/{nodeId}/renditions" + * + * @param repoModel + * @return RestRenditionInfoModelCollection + * @throws Exception + */ + public RestRenditionInfoModelCollection getDeletedNodeRenditions(RepoTestModel repoModel) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deleted-nodes/{nodeId}/renditions?{parameters}", repoModel.getNodeRefWithoutVersion(), restWrapper.getParameters()); + return restWrapper.processModels(RestRenditionInfoModelCollection.class, request); + } + + /** + * Gets a single trashcan node rendition using GET call on "/deleted-nodes/{nodeId}/renditions/{renditionId}" + * + * @param repoModel + * @param renditionId + * @return RestRenditionInfoModel + * @throws Exception + */ + public RestRenditionInfoModel getDeletedNodeRendition(RepoTestModel repoModel, String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deleted-nodes/{nodeId}/renditions/{renditionId}?{parameters}", repoModel.getNodeRefWithoutVersion(), renditionId, restWrapper.getParameters()); + return restWrapper.processModel(RestRenditionInfoModel.class, request); + } + + /** + * Gets a single trashcan node rendition content using GET call on "/deleted-nodes/{nodeId}/renditions/{renditionId}/content" + * + * @param repoModel + * @param renditionId + * @return RestResponse + * @throws Exception + */ + public RestResponse getDeletedNodeRenditionContent(RepoTestModel repoModel, String renditionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "deleted-nodes/{nodeId}/renditions/{renditionId}/content?{parameters}", repoModel.getNodeRefWithoutVersion(), renditionId, restWrapper.getParameters()); + return restWrapper.process(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/aosAPI/RestAosAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/aosAPI/RestAosAPI.java new file mode 100644 index 0000000000..f2c1a7cc5c --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/aosAPI/RestAosAPI.java @@ -0,0 +1,27 @@ +package org.alfresco.rest.requests.aosAPI; + +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.cmisAPI.RestCmisAPI; + +import io.restassured.RestAssured; + +/** + * @author Catalin Gornea + * + * Perform AOS rest API calls "alfresco/aos" + * + * Take a look at {@link org.alfresco.rest.aos.AosApiTest} + * @since 5.2.0-8 + */ + +public class RestAosAPI extends ModelRequest +{ + + public RestAosAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/aos"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/authAPI/RestAuthAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/authAPI/RestAuthAPI.java new file mode 100644 index 0000000000..0dfd295385 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/authAPI/RestAuthAPI.java @@ -0,0 +1,39 @@ +package org.alfresco.rest.requests.authAPI; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestTicketBodyModel; +import org.alfresco.rest.model.RestTicketModel; +import org.alfresco.rest.requests.ModelRequest; +import org.springframework.http.HttpMethod; + +import io.restassured.RestAssured; + +public class RestAuthAPI extends ModelRequest +{ + public RestAuthAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/public/authentication/versions/1"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + public RestTicketModel createTicket(RestTicketBodyModel ticketBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, ticketBody.toJson(), "tickets"); + return restWrapper.processModel(RestTicketModel.class, request); + } + + public RestTicketModel getTicket() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "tickets/-me-"); + return restWrapper.processModel(RestTicketModel.class, request); + } + + public void removeTicket() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "tickets/-me-"); + restWrapper.processEmptyModel(request); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/cmisAPI/RestCmisAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/cmisAPI/RestCmisAPI.java new file mode 100644 index 0000000000..7972d4e042 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/cmisAPI/RestCmisAPI.java @@ -0,0 +1,67 @@ +package org.alfresco.rest.requests.cmisAPI; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.utility.model.ContentModel; +import org.springframework.http.HttpMethod; + +import io.restassured.RestAssured; + +/** + * @author Paul Brodner + * + * Perform CMIS rest API calls "alfresco/api/-default-/public/cmis/versions/1.1/browser" + * + * Take a look at {@link org.alfresco.rest.cmis.CmisBrowserTest} + * @since 5.2.0-8 + */ +public class RestCmisAPI extends ModelRequest { + + public RestCmisAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/public/cmis/versions/1.1/browser"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + /** + * @param objectCmisLocation + * @return object + */ + public RestResponse getRootObjectByLocation(ContentModel contentModel) + { + return getRootObjectByLocation(contentModel.getName()); + } + + /** + * @param objectCmisLocation + * @return object + */ + public RestResponse getRootObjectByLocation(String objectName) + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "root/Shared/{objectName}?{parameters}", objectName, restWrapper.getParameters()); + return restWrapper.process(request); + } + + /** + * @param objectId + * @return object + */ + public RestResponse getRootObjectByID(ContentModel contentModel) + { + return getRootObjectByID(contentModel.getNodeRef()); + } + + /** + * @param objectId + * @return object + */ + public RestResponse getRootObjectByID(String objectID) + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "root?objectid={objectId}?{parameters}", objectID, restWrapper.getParameters()); + return restWrapper.process(request); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/coreAPI/RestCoreAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/coreAPI/RestCoreAPI.java new file mode 100644 index 0000000000..783d1b685d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/coreAPI/RestCoreAPI.java @@ -0,0 +1,210 @@ +package org.alfresco.rest.requests.coreAPI; + +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestDownloadsModel; +import org.alfresco.rest.model.RestSiteModelsCollection; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.rest.model.RestTagModelsCollection; +import org.alfresco.rest.requests.Actions; +import org.alfresco.rest.requests.Audit; +import org.alfresco.rest.requests.Downloads; +import org.alfresco.rest.requests.Groups; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.Networks; +import org.alfresco.rest.requests.Node; +import org.alfresco.rest.requests.People; +import org.alfresco.rest.requests.Queries; +import org.alfresco.rest.requests.SharedLinks; +import org.alfresco.rest.requests.Site; +import org.alfresco.rest.requests.Tags; +import org.alfresco.rest.requests.Trashcan; +import org.alfresco.utility.model.RepoTestModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; + +import io.restassured.RestAssured; + +/** + * Defines the entire Rest Core API + * {@link https://api-explorer.alfresco.com/api-explorer/} select "Core API" + */ +public class RestCoreAPI extends ModelRequest +{ + public RestCoreAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/public/alfresco/versions/1"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + /** + * Provides DSL on all REST calls under sites/{siteId}/... API path + * + * @param siteId + * @return {@link Site} + */ + public Site usingSite(String siteId) + { + return new Site(new SiteModel(siteId), restWrapper); + } + + /** + * Provides DSL on all REST calls under sites/{siteId}/... API path + * + * @param SiteModel + * @return {@link Site} + */ + public Site usingSite(SiteModel siteModel) + { + return new Site(siteModel, restWrapper); + } + + /** + * Provides DSL on all REST calls under /sites API path + * + * @return {@link Site} + * @throws Exception + */ + public RestSiteModelsCollection getSites() throws Exception + { + return new Site(null, restWrapper).getSites(); + } + + /** + * Provides DSL on all REST calls under /nodes API path + * + * @return {@link Node} + * @throws Exception + */ + public Node usingResource(RepoTestModel node) throws Exception + { + return new Node(node, restWrapper); + } + + /** + * synonym for {@link #usingResource(RepoTestModel)} + * + * @param node + * @return + * @throws Exception + */ + public Node usingNode(RepoTestModel node) throws Exception + { + return new Node(node, restWrapper); + } + + public Node usingNode() throws Exception + { + return new Node(restWrapper); + } + + /** + * Provides DSL of all REST calls under /people API path + * + * @return {@link People} + * @throws Exception + */ + public People usingUser(UserModel person) throws Exception + { + return new People(person, restWrapper); + } + + /** + * Make REST calls using current authenticated user, but using -me- instead of username + * + * @return {@link People} + * @throws Exception + */ + public People usingMe() throws Exception + { + UserModel userModel = new UserModel("-me-", restWrapper.getTestUser().getPassword()); + userModel.setDomain(restWrapper.getTestUser().getDomain()); + userModel.setUserRole(restWrapper.getTestUser().getUserRole()); + return new People(userModel, restWrapper); + } + + /** + * Make REST calls using current authenticated user. + * This is set on the {@link #authenticateUser(UserModel)} call + * + * @return {@link People} + * @throws Exception + */ + public People usingAuthUser() throws Exception + { + return new People(restWrapper.getTestUser(), restWrapper); + } + + /** + * Provides DSL on all REST calls under /network API path + * + * @return {@link Networks} + */ + public Networks usingNetworks() + { + return new Networks(restWrapper); + } + + public Tags usingTag(RestTagModel tag) + { + return new Tags(tag, restWrapper); + } + + public RestTagModelsCollection getTags() throws Exception + { + return new Tags(null, restWrapper).getTags(); + } + + public RestTagModel getTag(RestTagModel tag) throws Exception + { + return new Tags(tag, restWrapper).getTag(); + } + + public Queries usingQueries() + { + return new Queries(restWrapper); + } + + public Audit usingAudit() throws Exception + { + return new Audit(restWrapper); + } + + public Trashcan usingTrashcan() + { + return new Trashcan(restWrapper); + } + + /** + * SharedLinks api endpoint + * + * @author meenal bhave + * @return SharedLinks api endpoint + */ + + public SharedLinks usingSharedLinks() + { + return new SharedLinks(restWrapper); + } + + public Groups usingGroups() + { + return new Groups(restWrapper); + } + + + public Actions usingActions() + { + return new Actions(restWrapper); + } + + public Downloads usingDownloads() + { + return new Downloads(restWrapper); + } + + public Downloads usingDownloads(RestDownloadsModel downloadsModel) throws Exception + { + return new Downloads(downloadsModel, restWrapper); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/discoveryAPI/RestDiscoveryAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/discoveryAPI/RestDiscoveryAPI.java new file mode 100644 index 0000000000..7bbcf5bffa --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/discoveryAPI/RestDiscoveryAPI.java @@ -0,0 +1,28 @@ +package org.alfresco.rest.requests.discoveryAPI; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestDiscoveryModel; +import org.alfresco.rest.requests.ModelRequest; +import org.springframework.http.HttpMethod; + +import io.restassured.RestAssured; + +public class RestDiscoveryAPI extends ModelRequest { + + public RestDiscoveryAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/discovery"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + // Method for getting repository info. The call is executed on root api path + public RestDiscoveryModel getRepositoryInfo() + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, ""); + return restWrapper.processModel(RestDiscoveryModel.class, request); + } + +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/privateAPI/RestPrivateAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/privateAPI/RestPrivateAPI.java new file mode 100644 index 0000000000..57e7e15858 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/privateAPI/RestPrivateAPI.java @@ -0,0 +1,106 @@ +package org.alfresco.rest.requests.privateAPI; + +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestSubscriberModel; +import org.alfresco.rest.model.RestSyncNodeSubscriptionModel; +import org.alfresco.rest.requests.CustomAspectModelManager; +import org.alfresco.rest.requests.CustomModelManager; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.syncServiceAPI.Healthcheck; +import org.alfresco.rest.requests.syncServiceAPI.Subscribers; +import org.alfresco.rest.requests.syncServiceAPI.Subscriptions; +import org.alfresco.rest.requests.syncServiceAPI.Sync; +import org.alfresco.utility.model.CustomAspectModel; +import org.alfresco.utility.model.CustomContentModel; + +import io.restassured.RestAssured; + +/** + * @author Bogdan Bocancea + */ +public class RestPrivateAPI extends ModelRequest +{ + public RestPrivateAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/private/alfresco/versions/1"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + /** + * Provides DSL on all REST calls under cmm/{modelName}/... API path + * + * @param customContentModel {@link CustomContentModel} + * @return {@link CustomModelManager} + */ + public CustomModelManager usingCustomModel(CustomContentModel customContentModel) + { + return new CustomModelManager(customContentModel, restWrapper); + } + + /** + * Provides DSL on all REST calls under cmm/{modelName}/aspects/{aspectName}... API path + * + * @param customContentModel {@link CustomContentModel} + * @param aspectModel {@link CustomAspectModel} + * @return {@link CustomAspectModelManager} + */ + public CustomAspectModelManager usingAspect(CustomContentModel customContentModel, CustomAspectModel aspectModel) + { + return new CustomAspectModelManager(customContentModel, aspectModel, restWrapper); + } + + /** + * Provides DSL on all REST calls under subscribers/ API path + * + * @return {@link Subscribers} + */ + public Subscribers withSubscribers() + { + return new Subscribers(restWrapper); + } + + /** + * Provides DSL on all REST calls under subscribers/{subscriberId}/ API path + * + * @return {@link Subscribers} + */ + public Subscriptions withSubscriber(RestSubscriberModel subscriber) throws Exception + { + return new Subscriptions(subscriber, restWrapper); + } + + /** + * Provides DSL on all REST calls under subscribers/{subscriberId}/ API path + * + * @return {@link Subscribers} + */ + public Subscriptions withSubscriber(String subscriberID) throws Exception + { + RestSubscriberModel s = new RestSubscriberModel(); + s.setId(subscriberID); + return new Subscriptions(s, restWrapper); + } + + /** + * Provides DSL on all REST calls under subscribers/{subscriberId}/subscriptions/ API path + * + * @return {@link Subscribers} + */ + public Sync withSubscription(RestSyncNodeSubscriptionModel nodeSubscription) throws Exception + { + RestSubscriberModel s = new RestSubscriberModel(); + s.setId(nodeSubscription.getDeviceSubscriptionId()); + return new Sync(nodeSubscription, restWrapper); + } + /** + * Provides DSL on all REST calls under subscribers/ API path + * + * @return {@link Subscribers} + */ + public Healthcheck doHealthCheck() + { + return new Healthcheck(restWrapper); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchAPI.java new file mode 100644 index 0000000000..7491894952 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchAPI.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.requests.search; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.search.SearchRequest; +import org.alfresco.rest.search.SearchResponse; +import org.springframework.http.HttpMethod; + +import io.restassured.RestAssured; +/** + * Wrapper for Search API. + * @author Michael Suzuki + * + */ +public class SearchAPI extends ModelRequest +{ + public SearchAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/public/search/versions/1"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + public SearchResponse search(SearchRequest queryBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, queryBody.toJson(), "search"); + return restWrapper.processModels(SearchResponse.class, request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchSQLAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchSQLAPI.java new file mode 100644 index 0000000000..bba6a2bf62 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchSQLAPI.java @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * This file is part of Alfresco + * 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 . + */ +package org.alfresco.rest.requests.search; + +import javax.json.JsonArrayBuilder; +import javax.json.JsonObjectBuilder; + +import io.restassured.RestAssured; + +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.requests.ModelRequest; +import org.alfresco.rest.search.SearchSqlRequest; +import org.springframework.http.HttpMethod; + + +/** + * Wrapper for Search SQL API. + * + * @author Meenal Bhave + * + * Request POST + * End point: /sql + * PostBody: + * { + * "stmt":"Select SITE from alfresco where SITE = 'swsdp' limit 2", + * "locales":["ja"], + * "timezone":"Israel", + * "includeMetadata":true, + * "format":"", + * "limit": 100 + * } + * Response in json format: + * { + * "list": { + * "pagination": { + * "count": 3, + * "hasMoreItems": false, + * "totalItems": 3, + * "skipCount": 0, + * "maxItems": 100 + * }, + * "entries": [ + * { + * "entry": [ + * { + * "label": "aliases", + * "value": "{\"SITE\":\"SITE\"}" + * }, + * { + * "label": "isMetadata", + * "value": "true" + * }, + * { + * "label": "fields", + * "value": "[\"SITE\"]" + * } + * ] + * }, + * { + * "entry": [ + * { + * "label": "SITE", + * "value": "[\"swsdp\"]" + * } + * ] + * }, + * { + * "entry": [ + * { + * "label": "SITE", + * "value": "[\"swsdp\"]" + * } + * ] + * } + * ] + * } + * } + * + * Response in solr format + * { + * "result-set": { + * "docs": [ + * { + * "aliases": { + * "SITE": "SITE" + * }, + * "isMetadata": true, + * "fields": [ + * "SITE" + * ] + * }, + * { + * "SITE": [ + * "swsdp" + * ] + * }, + * { + * "SITE": [ + * "swsdp" + * ] + * }, + * { + * "RESPONSE_TIME": 79, + * "EOF": true + * } + * ] + * } + * } + */ +public class SearchSQLAPI extends ModelRequest +{ + public SearchSQLAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/public/search/versions/1"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + public RestResponse searchSql(SearchSqlRequest query) throws Exception + { + String stmt = (null == query.getSql() || query.getSql().isEmpty()) ? "" : query.getSql(); + + String format = (null == query.getFormat() || query.getFormat().isEmpty()) ? "" : query.getFormat(); + + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + if (query.getLocales() != null) + { + for (String locale : query.getLocales()) + { + array.add(locale); + } + } + + String timezone = (null == query.getTimezone() || query.getTimezone().isEmpty()) ? "" : query.getTimezone(); + + Boolean includeMetadata = (query.getIncludeMetadata() != null && query.getIncludeMetadata()); + + Integer limit = null == query.getLimit() ? 0 : query.getLimit(); + + JsonArrayBuilder filterQueries = null; + if (query.getFilterQueries() != null) + { + filterQueries = JsonBodyGenerator.defineJSONArray(); + for (String filterQuery : query.getFilterQueries()) + { + filterQueries.add(filterQuery); + } + } + + JsonObjectBuilder builder = JsonBodyGenerator.defineJSON() + .add("stmt", stmt) + .add("format", format) + .add("locales", array) + .add("timezone", timezone) + .add("includeMetadata", includeMetadata) + .add("limit", limit); + if (filterQueries != null) + { + builder.add("filterQueries", filterQueries); + } + String postBody = builder.build().toString(); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "sql"); + return restWrapper.process(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchSQLJDBC.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchSQLJDBC.java new file mode 100644 index 0000000000..3a56724fa4 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SearchSQLJDBC.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2018 Alfresco Software Limited. + * This file is part of Alfresco + * 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 . + */ +package org.alfresco.rest.requests.search; + +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; + +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.search.SearchSqlJDBCRequest; +import io.restassured.RestAssured; + + +/** + * Wrapper for Search SQL using JDBC connection. + * + * @author Meenal Bhave + * + * Request POST JDBC + * End point: /sql + */ +public class SearchSQLJDBC extends ModelRequest +{ + public SearchSQLJDBC(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/public/search/versions/1/sql"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + public ResultSet executeQueryViaJDBC(SearchSqlJDBCRequest query) throws SQLException + { + + StringBuilder connectionString = new StringBuilder() + .append(RestAssured.baseURI + .replaceAll("http", "jdbc:alfresco") + .replaceAll("https", "jdbc:alfresco")) + .append(":") + .append(RestAssured.port) + .append("/") + .append(RestAssured.basePath) + .append("/"); + + String sql = (null == query.getSql() || query.getSql().isEmpty()) ? "" : query.getSql(); + + Properties auth = new Properties(); + auth.put("user", query.getAuthUser().getUsername()); + auth.put("password", query.getAuthUser().getPassword()); + + try + { + query.setConnection(DriverManager.getConnection(connectionString.toString(), auth)); + query.setStmt(query.getConnection().createStatement()); + query.setResultSet(query.getStmt().executeQuery(sql)); + } + catch (SQLException eSql) + { + query.setErrorDetails(eSql.getMessage()); + } + + return query.getResultSet(); + } + + public void clearSearchQuery(SearchSqlJDBCRequest query) throws SQLException + { + if (query.getResultSet() != null) + { + query.getResultSet().close(); + } + + if (query.getStmt() != null) + { + query.getStmt().close(); + } + + if (query.getConnection() != null) + { + query.getConnection().close(); + } + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/ShardInfoAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/ShardInfoAPI.java new file mode 100644 index 0000000000..a32f247dcc --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/ShardInfoAPI.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2005-2018 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.requests.search; + +import com.fasterxml.jackson.core.JsonProcessingException; +import io.restassured.RestAssured; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.search.RestShardInfoModelCollection; +import org.springframework.http.HttpMethod; + +/** + * Wrapper for Shard Info API. + * + * @author Tuna Aksoy + */ +public class ShardInfoAPI extends ModelRequest +{ + /** + * Constructor + * + * @param restWrapper Rest Wrapper + */ + public ShardInfoAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/private/search/versions/1"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + /** + * Get Info about the shard groups + * + * @return {@link RestShardInfoModelCollection} Information about shard groups + * @throws JsonProcessingException + */ + public RestShardInfoModelCollection getInfo() throws JsonProcessingException + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "info"); + return restWrapper.processModels(RestShardInfoModelCollection.class, request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SolrAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SolrAPI.java new file mode 100644 index 0000000000..2367cc2409 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/search/SolrAPI.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2018 Alfresco Software Limited. + * This file is part of Alfresco + * 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 . + */ +package org.alfresco.rest.requests.search; + +import java.util.ArrayList; +import java.util.List; + +import io.restassured.RestAssured; +import io.restassured.http.Header; +import io.restassured.http.Headers; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestTextResponse; +import org.alfresco.rest.requests.ModelRequest; +import org.springframework.http.HttpMethod; + +/** + * Wrapper for solr API. + * + * @author Meenal Bhave + */ +public class SolrAPI extends ModelRequest +{ + public SolrAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "solr/alfresco"; + + restWrapper.configureSolrEndPoint(); + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + public RestTextResponse getConfig() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "config?{parameters}", restWrapper.getParameters()); + return restWrapper.processTextResponse(request); + } + + public RestTextResponse getConfigOverlay() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "config/overlay?{parameters}", restWrapper.getParameters()); + return restWrapper.processTextResponse(request); + } + + public RestTextResponse getConfigParams() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "config/params?{parameters}", restWrapper.getParameters()); + return restWrapper.processTextResponse(request); + } + + public RestTextResponse postConfig(String queryBody) throws Exception + { + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, queryBody, "config"); + return restWrapper.processTextResponse(request); + } + + public RestTextResponse getSelectQuery() throws Exception + { + List
headers = new ArrayList
(); + headers.add(new Header("Content-Type", "application/xml")); + Headers header = new Headers(headers); + restWrapper.setResponseHeaders(header); + restWrapper.configureRequestSpec().setUrlEncodingEnabled(false); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "select?q={parameters}", restWrapper.getParameters()); + return restWrapper.processTextResponse(request); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Healthcheck.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Healthcheck.java new file mode 100644 index 0000000000..afe6b1b548 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Healthcheck.java @@ -0,0 +1,35 @@ +package org.alfresco.rest.requests.syncServiceAPI; + +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestSyncServiceHealthCheckModel; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.privateAPI.RestPrivateAPI; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /healthcheck path + * + * @author Meenal Bhave + */ +public class Healthcheck extends ModelRequest +{ + public Healthcheck(RestWrapper restWrapper) + { + super(restWrapper); + restWrapper.configureSyncServiceEndPoint(); + restWrapper.configureRequestSpec().setBasePath("alfresco/"); + } + + /** + * Get Healthcheck using GET call on alfresco/healthcheck + * @return {@link RestSyncServiceHealthCheckModel} + * @throws Exception + */ + public RestSyncServiceHealthCheckModel getHealthcheck() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "healthcheck?{parameters}", restWrapper.getParameters()); + return restWrapper.processModelWithoutEntryObject(RestSyncServiceHealthCheckModel.class, request); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Subscribers.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Subscribers.java new file mode 100644 index 0000000000..9f72a23d8f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Subscribers.java @@ -0,0 +1,56 @@ +package org.alfresco.rest.requests.syncServiceAPI; + +import java.util.HashMap; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestSubscriberModel; +import org.alfresco.rest.model.RestSubscriberModelCollection; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.privateAPI.RestPrivateAPI; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /subscribers path + * + * @author Meenal Bhave + */ +public class Subscribers extends ModelRequest +{ + public Subscribers(RestWrapper restWrapper) + { + super(restWrapper); + } + + /** + * Get Subscription(s) using GET call on /subscribers + * @return {@link RestSubscriberModelCollection} + * @throws Exception + */ + public RestSubscriberModelCollection getSubscribers() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "subscribers?{parameters}", restWrapper.getParameters()); + return restWrapper.processModels(RestSubscriberModelCollection.class, request); + } + + /** + * POST Create Device Subscription using POST call on /subscribers + * + * @param deviceOS + * @param clientVersion + * @return {@link RestSubscriberModel} + * @throws Exception + */ + public RestSubscriberModel registerDevice(String deviceOS, String clientVersion) throws Exception + { + HashMap body = new HashMap(); + body.put("deviceOS", deviceOS); + body.put("clientVersion", clientVersion); + String postBody = JsonBodyGenerator.keyValueJson(body); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "subscribers?{parameters}", restWrapper.getParameters()); + return restWrapper.processModel(RestSubscriberModel.class, request); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Subscriptions.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Subscriptions.java new file mode 100644 index 0000000000..09db1c0510 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Subscriptions.java @@ -0,0 +1,110 @@ +package org.alfresco.rest.requests.syncServiceAPI; + +import java.util.HashMap; + +import javax.json.JsonArrayBuilder; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestSubscriberModel; +import org.alfresco.rest.model.RestSyncNodeSubscriptionModel; +import org.alfresco.rest.model.RestSyncNodeSubscriptionModelCollection; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.privateAPI.RestPrivateAPI; +import org.alfresco.utility.Utility; +import org.springframework.http.HttpMethod; + +/** + * Declares all Rest API under the /subscribers//subscriptions/ path + * + * @author Meenal Bhave + */ +public class Subscriptions extends ModelRequest +{ + public enum TYPE + { + BOTH, CONTENT, METADATA + } + + private RestSubscriberModel subscriber; + private String subscriptionsURL = "subscribers/{deviceSubscriptionId}/subscriptions"; + String nodeSubscriptionURL = subscriptionsURL + "/{nodeSubscriptionId}"; + String params = "?{parameters}"; + + public Subscriptions(RestSubscriberModel subscriber, RestWrapper restWrapper) throws Exception + { + super(restWrapper); + this.subscriber = subscriber; + Utility.checkObjectIsInitialized(this.subscriber, "Subscriber Device"); + } + + /** + * Create Node Subscriptions for multiple targets using POST call on /subscribers/{deviceSubscriptionId}/subscriptions + * + * @param targetNodeIds: one or more + * @return RestSyncNodeSubscriptionModel + * @throws Exception: EmptyJsonResponseException, JsonToModelConversionException + */ + public RestSyncNodeSubscriptionModelCollection subscribeToNodes(String... targetNodeIds) throws Exception + { + + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for (String targetNodeId : targetNodeIds) + { + array.add(JsonBodyGenerator.defineJSON().add("targetNodeId", targetNodeId).add("subscriptionType", TYPE.BOTH.toString())); + } + + String postBody = array.build().toString(); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, subscriptionsURL + params, this.subscriber.getId(), + restWrapper.getParameters()); + + return restWrapper.processModels(RestSyncNodeSubscriptionModelCollection.class, request); + } + + /** + * Create Node Subscription for the specified target node using POST call on /subscribers/{deviceSubscriptionId}/subscriptions + * + * @param targetNodeId + * @param subscriberType + * @return + */ + public RestSyncNodeSubscriptionModel subscribeToNode(String targetNodeId, TYPE subscriberType) + { + HashMap body = new HashMap(); + body.put("targetNodeId", targetNodeId); + body.put("subscriptionType", subscriberType.toString()); + String postBody = JsonBodyGenerator.keyValueJson(body); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, subscriptionsURL + params, this.subscriber.getId(), + restWrapper.getParameters()); + return restWrapper.processModel(RestSyncNodeSubscriptionModel.class, request); + } + + /** + * Get NODE Subscription(s) using GET call on /subscribers/{deviceSubscriptionId}/subscriptions + * + * @return {@link RestSyncNodeSubscriptionModelCollection} + * @throws Exception + */ + public RestSyncNodeSubscriptionModelCollection getSubscriptions() throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, subscriptionsURL + params, this.subscriber.getId(), restWrapper.getParameters()); + return restWrapper.processModels(RestSyncNodeSubscriptionModelCollection.class, request); + } + + /** + * Get NODE Subscription using GET call on /subscribers/{deviceSubscriptionId}/subscriptions/{nodeSubscriptionId} + * + * @return RestSyncNodeSubscriptionModelCollection + * @throws Exception: EmptyJsonResponseException, JsonToModelConversionException + */ + public RestSyncNodeSubscriptionModel getSubscription(String nodeSubscriptionId) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, nodeSubscriptionURL + params, this.subscriber.getId(), nodeSubscriptionId, + restWrapper.getParameters()); + return restWrapper.processModel(RestSyncNodeSubscriptionModel.class, request); + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Sync.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Sync.java new file mode 100644 index 0000000000..1601f0c7b5 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/syncServiceAPI/Sync.java @@ -0,0 +1,100 @@ +package org.alfresco.rest.requests.syncServiceAPI; + +import java.util.List; + +import javax.json.JsonArrayBuilder; + +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestSyncNodeSubscriptionModel; +import org.alfresco.rest.model.RestSyncSetChangesModel; +import org.alfresco.rest.model.RestSyncSetGetModel; +import org.alfresco.rest.model.RestSyncSetRequestModel; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.privateAPI.RestPrivateAPI; +import org.alfresco.utility.Utility; +import org.springframework.http.HttpMethod; + +import io.restassured.http.ContentType; + +/** + * Declares all Rest API under the /subscribers//subscriptions//sync path + * + * @author Meenal Bhave + */ +public class Sync extends ModelRequest +{ + String subscriber; + RestSyncNodeSubscriptionModel subscription; + String requestSyncURL = "subscribers/{deviceSubscriptionId}/subscriptions/{nodeSubscriptionId}/sync"; + String syncSetURL = requestSyncURL + "/{syncId}"; + String params = "?{parameters}"; + + public Sync(RestSyncNodeSubscriptionModel subscription, RestWrapper restWrapper) throws Exception + { + super(restWrapper); + restWrapper.configureSyncServiceEndPoint(); + this.subscription = subscription; + this.subscriber = subscription.getDeviceSubscriptionId(); + Utility.checkObjectIsInitialized(this.subscription, "Node Subscription"); + } + + /** + * Request sync for the specified subscriber/subscription using POST call on /subscribers/{deviceSubscriptionId}/subscriptions/{nodeSubscriptionId}/sync + * + * @param nodeSubscriptionId + * @param clientChanges + * @return + * @throws Exception + */ + public RestSyncSetRequestModel startSync(RestSyncNodeSubscriptionModel nodeSubscriptionModel, List clientChanges, String clientVersion) + throws Exception + { + JsonArrayBuilder array = JsonBodyGenerator.defineJSONArray(); + for (RestSyncSetChangesModel change : clientChanges) + { + array.add(JsonBodyGenerator.defineJSON().add("changes", change.toJson())); + } + + String postBody = JsonBodyGenerator.defineJSON().add("changes", array.build()).add("clientVersion", clientVersion).build().toString(); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, requestSyncURL + params, this.subscriber, nodeSubscriptionModel.getId(), + restWrapper.getParameters()); + + // This step is necessary for this request. Without it, empty json response is returned + restWrapper.configureRequestSpec().setContentType(ContentType.JSON.withCharset(request.getContentType())); + RestSyncSetRequestModel model = restWrapper.processModelWithoutEntryObject(RestSyncSetRequestModel.class, request); + restWrapper.initializeRequestSpecBuilder(); + return model; + } + + public RestWrapper endSync(RestSyncNodeSubscriptionModel nodeSubscriptionModel, RestSyncSetRequestModel sync) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, syncSetURL + params, this.subscriber, nodeSubscriptionModel.getId(), + sync.getSyncId(), restWrapper.getParameters()); + + restWrapper.processEmptyModel(request); + restWrapper.initializeRequestSpecBuilder(); + return restWrapper; + } + + /** + * Gets the Change Set for the specified subscriber/subscription and SyncId using GET call on + * /subscribers/{deviceSubscriptionId}/subscriptions/{nodeSubscriptionId}/sync + * + * @param syncRequest + * @return + * @throws Exception + */ + public RestSyncSetGetModel getSync(RestSyncNodeSubscriptionModel nodeSubscriptionModel, RestSyncSetRequestModel sync) throws Exception + { + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, syncSetURL + params, this.subscriber, nodeSubscriptionModel.getId(), sync.getSyncId(), + restWrapper.getParameters()); + + RestSyncSetGetModel model = restWrapper.processModelWithoutEntryObject(RestSyncSetGetModel.class, request); + restWrapper.initializeRequestSpecBuilder(); + return model; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/workflowAPI/RestWorkflowAPI.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/workflowAPI/RestWorkflowAPI.java new file mode 100644 index 0000000000..5594e02d57 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/requests/workflowAPI/RestWorkflowAPI.java @@ -0,0 +1,137 @@ +package org.alfresco.rest.requests.workflowAPI; + +import javax.json.JsonObject; + +import org.alfresco.dataprep.CMISUtil.Priority; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestDeploymentModel; +import org.alfresco.rest.model.RestDeploymentModelsCollection; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestProcessDefinitionModelsCollection; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessModelsCollection; +import org.alfresco.rest.model.RestTaskModelsCollection; +import org.alfresco.rest.requests.Deployments; +import org.alfresco.rest.requests.ModelRequest; +import org.alfresco.rest.requests.ProcessDefinitions; +import org.alfresco.rest.requests.Processes; +import org.alfresco.rest.requests.Task; +import org.alfresco.utility.model.ProcessModel; +import org.alfresco.utility.model.TaskModel; +import org.alfresco.utility.model.UserModel; + +import io.restassured.RestAssured; + +/** + * Defines the entire Rest Workflow API + * {@link https://api-explorer.alfresco.com/api-explorer/} select "Workflow API" + */ +public class RestWorkflowAPI extends ModelRequest +{ + public RestWorkflowAPI(RestWrapper restWrapper) + { + super(restWrapper); + RestAssured.basePath = "alfresco/api/-default-/public/workflow/versions/1"; + restWrapper.configureRequestSpec().setBasePath(RestAssured.basePath); + } + + /** + * Provides DSL on all REST calls under /processes/{processId}/... API path + * + * @return {@link RestProcessModel} + */ + public RestProcessModel addProcess(String processDefinitionKey, UserModel assignee, boolean sendEmailNotifications, Priority priority) throws Exception + { + return new Processes(restWrapper).addProcess(processDefinitionKey, assignee, sendEmailNotifications, priority); + } + + /** + * Provides DSL on all REST calls under /processes/{processId}/... API path + * + * @return {@link RestProcessModel} + */ + public RestProcessModel addProcessWithBody(JsonObject postBody) throws Exception + { + return new Processes(restWrapper).addProcessWithBody(postBody.toString()); + } + + /** + * Provides DSL on all REST calls under /tasks/{taskId}/... API path + * + * @return {@link Task} + */ + public Task usingTask(TaskModel task) + { + return new Task(restWrapper, task); + } + + /** + * Provides get all process /processesof current user logged in + * + * @return {@link RestProcessModelsCollection} + */ + public RestProcessModelsCollection getProcesses() throws Exception + { + return new Processes(restWrapper).getProcesses(); + } + + /** + * Provides all deployments of current user logged in + * + * @return {@link RestDeploymentModelsCollection} + */ + public RestDeploymentModelsCollection getDeployments() throws Exception + { + return new Deployments(restWrapper).getDeployments(); + } + + /** + * Provides DSL on all REST calls under /deployments/{deploymentID} API path + * + * @return {@link Deployments} + */ + public Deployments usingDeployment(RestDeploymentModel deployment) + { + return new Deployments(deployment, restWrapper); + } + + /** + * Provides all ProcessDefinitions of current user logged in + * + * @return {@link RestProcessDefinitionModelsCollection} + */ + public RestProcessDefinitionModelsCollection getAllProcessDefinitions() throws Exception + { + return new ProcessDefinitions(restWrapper).getAllProcessDefinitions(); + } + + /** + * Provides DSL on all REST calls under /process-definition/{processDefinitionID} API path + * + * @return {@link ProcessDefinitions} + */ + public ProcessDefinitions usingProcessDefinitions(RestProcessDefinitionModel processDefinition) + { + return new ProcessDefinitions(processDefinition, restWrapper); + } + + /** + * Provides DSL on all REST calls under /process-definition/{processDefinitionID} API path + * + * @return {@link Processes} + */ + public Processes usingProcess(ProcessModel processModel) throws Exception + { + return new Processes(processModel, restWrapper); + } + + /** + * Provides all tasks of the current user + * + * @return {@link RestTaskModelsCollection} + */ + public RestTaskModelsCollection getTasks() throws Exception + { + return new Task(restWrapper, null).getTasks(); + } +} \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/Context.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/Context.java new file mode 100644 index 0000000000..e347cae0f4 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/Context.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.utility.model.TestModel; + +/** + * Search response sample. + * { + * "context": {"consistency": {"lastTxId": 1123}} + * } + **/ +public class Context extends TestModel +{ + + private Integer lastTxId; + + public Integer getLastTxId() + { + return lastTxId; + } + + public void setLastTxId(Integer lastTxId) + { + this.lastTxId = lastTxId; + } + + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetFieldBucket.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetFieldBucket.java new file mode 100644 index 0000000000..1f1b3cbda9 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetFieldBucket.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; + +/** + * Pojo to represent facet field bucket response. + * {"count":1,"label":"small"}, + **/ +public class FacetFieldBucket extends TestModel implements IRestModel +{ + + private String label; + private String display; + private String filterQuery; + private int count; + + + public FacetFieldBucket() {} + + public String getLabel() + { + return label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getDisplay() + { + return display; + } + + public void setDisplay(String display) + { + this.display = display; + } + + public int getCount() + { + return count; + } + + public void setCount(int count) + { + this.count = count; + } + + public String getFilterQuery() + { + return filterQuery; + } + + public void setFilterQuery(String filterQuery) + { + this.filterQuery = filterQuery; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public FacetFieldBucket onModel() + { + // TODO Auto-generated method stub + return null; + } + + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetFieldQuery.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetFieldQuery.java new file mode 100644 index 0000000000..2fa8771a89 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetFieldQuery.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.utility.model.TestModel; + +/** + * Pojo to represent facet field query. + * {"",""}, + **/ +public class FacetFieldQuery extends TestModel +{ + + private String field; + private String prefix; + + public FacetFieldQuery() {} + public FacetFieldQuery(String field) + { + this.field = field; + } + public FacetFieldQuery(String field, String prefix) + { + this.field = field; + this.prefix = prefix; + } + public String getField() + { + return field; + } + public void setField(String field) + { + this.field = field; + } + public String getPrefix() + { + return prefix; + } + public void setPrefix(String prefix) + { + this.prefix = prefix; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetInterval.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetInterval.java new file mode 100644 index 0000000000..eadcfef209 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetInterval.java @@ -0,0 +1,77 @@ +package org.alfresco.rest.search; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; + +import java.util.List; + +/** + * Represents a facet interval. + */ + +public class FacetInterval extends TestModel implements IRestModel +{ + private String field; + private String label; + private List sets; + + public FacetInterval() + { + } + + public FacetInterval(String field, String label, List sets) + { + this.field = field; + this.label = label; + this.sets = sets; + } + + public String getField() + { + return field; + } + + public String getLabel() + { + return label; + } + + public List getSets() + { + return sets; + } + + public void setField(String field) + { + this.field = field; + } + + public void setLabel(String label) + { + this.label = label; + } + + public void setSets(List sets) + { + this.sets = sets; + } + + @Override + public FacetInterval onModel() + { + return null; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetQuery.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetQuery.java new file mode 100644 index 0000000000..18a52734e3 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/FacetQuery.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.utility.model.TestModel; + +/** + * Pojo to represent facet query. + * {"query": "content.size:[o TO 102400]", "label": "small"}, + **/ +public class FacetQuery extends TestModel //implements IRestModel +{ + + private String query; + private String label; + private String group; + + public FacetQuery() {} + public FacetQuery(String query,String label) + { + this.query = query; + this.label = label; + } + public FacetQuery(String query,String label, String group) + { + this.query = query; + this.label = label; + this.group = group; + } + + public String getQuery() + { + return query; + } + public void setQuery(String query) + { + this.query = query; + } + public String getLabel() + { + return label; + } + public void setLabel(String label) + { + this.label = label; + } + public String getGroup() + { + return group; + } + public void setGroup(String group) + { + this.group = group; + } + + /* @Override + public ModelAssertion and() + { + return assertThat(); + } + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + @Override + public FacetQuery onModel() + { + return null; + }*/ + + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/Pagination.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/Pagination.java new file mode 100644 index 0000000000..f0ad17fc86 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/Pagination.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.utility.model.TestModel; + +/** + * Search response sample. + * "pagination": { + * "maxItems": 100, + * "hasMoreItems": false, + * "totalItems": 0, + * "count": 0, + * "skipCount": 0 + * }, + **/ +public class Pagination extends TestModel +{ + + private Integer maxItems; + private Integer totalItems; + private Integer count; + private Integer skipCount; + private boolean hasMoreItems; + public Integer getMaxItems() + { + return maxItems; + } + public void setMaxItems(Integer maxItems) + { + this.maxItems = maxItems; + } + public Integer getTotalItems() + { + return totalItems; + } + public void setTotalItems(Integer totalItems) + { + this.totalItems = totalItems; + } + public Integer getCount() + { + return count; + } + public void setCount(Integer count) + { + this.count = count; + } + public Integer getSkipCount() + { + return skipCount; + } + public void setSkipCount(Integer skipCount) + { + this.skipCount = skipCount; + } + public boolean isHasMoreItems() + { + return hasMoreItems; + } + public void setHasMoreItems(boolean hasMoreItems) + { + this.hasMoreItems = hasMoreItems; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/ResponseHighLightModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/ResponseHighLightModel.java new file mode 100644 index 0000000000..4174644b06 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/ResponseHighLightModel.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import java.util.List; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; +/** + * Pojo which represents the search response that includes the highlighting info. + * @author Michael Suzuki + * + */ +public class ResponseHighLightModel extends TestModel implements IRestModel +{ + private ResponseHighLightModel model; + private String field; + private List snippets; + + public String getField() + { + return field; + } + public void setField(String field) + { + this.field = field; + } + public List getSnippets() + { + return snippets; + } + public void setSnippets(List snippets) + { + this.snippets = snippets; + } + @Override + public ModelAssertion and() + { + return assertThat(); + } + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + @Override + public ResponseHighLightModel onModel() + { + return model; + } + + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericBucketModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericBucketModel.java new file mode 100644 index 0000000000..a4672a4104 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericBucketModel.java @@ -0,0 +1,127 @@ +package org.alfresco.rest.search; + +import java.util.List; + +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 'gethin' on '2017-03-17 13:23' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestGenericBucketModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestGenericBucketModel model; + + @Override + public RestGenericBucketModel onModel() + { + return model; + } + + /** + The bucket label + */ + + private String label; + /** + The filter query you can use to apply this facet + */ + + private String filterQuery; + /** + An optional field for additional display information + */ + + private Object display; + /** + An array of buckets and values + */ + + private List metrics; + private Object bucketInfo; + /** + Additional list of embedded GenericFacetResponse + */ + + private List facets; + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getFilterQuery() + { + return this.filterQuery; + } + + public void setFilterQuery(String filterQuery) + { + this.filterQuery = filterQuery; + } + + public Object getDisplay() + { + return this.display; + } + + public void setDisplay(Object display) + { + this.display = display; + } + + public List getMetrics() + { + return this.metrics; + } + + public void setMetrics(List metrics) + { + this.metrics = metrics; + } + + public List getFacets() + { + return this.facets; + } + + public void setFacets(List facets) + { + this.facets = facets; + } + + public Object getBucketInfo() + { + return bucketInfo; + } + + public void setFacetInfo(Object bucketInfo) + { + this.bucketInfo = bucketInfo; + } + +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericFacetResponseModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericFacetResponseModel.java new file mode 100644 index 0000000000..d844c97902 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericFacetResponseModel.java @@ -0,0 +1,85 @@ +package org.alfresco.rest.search; + +import java.util.List; + +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 'gethin' on '2017-03-17 12:44' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestGenericFacetResponseModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestGenericFacetResponseModel model; + + @Override + public RestGenericFacetResponseModel onModel() + { + return model; + } + + /** + The facet type, eg. interval, range, field, query1 + */ + + private String type; + /** + The field name or its explicit label, if provided on the request + */ + + private String label; + /** + An array of buckets and values + */ + + private List buckets; + + public String getType() + { + return this.type; + } + + public void setType(String type) + { + this.type = type; + } + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public List getBuckets() + { + return this.buckets; + } + + public void setBuckets(List buckets) + { + this.buckets = buckets; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericMetricModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericMetricModel.java new file mode 100644 index 0000000000..c993a1c0fa --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestGenericMetricModel.java @@ -0,0 +1,68 @@ +package org.alfresco.rest.search; + +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 'gethin' on '2017-03-17 13:23' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestGenericMetricModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestGenericMetricModel model; + + @Override + public RestGenericMetricModel onModel() + { + return model; + } + + /** + The type of metric, e.g. count + */ + + private String type; + /** + The metric value, e.g. + */ + + private Object value; + + public String getType() + { + return this.type; + } + + public void setType(String type) + { + this.type = type; + } + + public Object getValue() + { + return this.value; + } + + public void setValue(Object value) + { + this.value = value; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestInstanceModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestInstanceModel.java new file mode 100644 index 0000000000..81c405ba9f --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestInstanceModel.java @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2005-2018 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +/** + * Representation of a shard instance + * + * @author Tuna Aksoy + */ +public class RestInstanceModel +{ + /** Base Url */ + private String baseUrl; + + /** Host */ + private String host; + + /** Last indexed change set date */ + private String lastIndexedChangesetDate; + + /** Last indexed change set Id */ + private Long lastIndexedChangesetId; + + /** Last indexed transaction date */ + private String lastIndexedTransactionDate; + + /** Last indexed transaction Id */ + private Long lastIndexedTransactionId; + + /** Last update date */ + private String lastUpdateDate; + + /** Port */ + private Integer port; + + /** State */ + private String state; + + /** Mode */ + private String mode; + + /** Transactions remaining */ + private Long transactionsRemaining; + + /** + * @return the baseUrl + */ + public String getBaseUrl() + { + return this.baseUrl; + } + + /** + * @param baseUrl the baseUrl to set + */ + public void setBaseUrl(String baseUrl) + { + this.baseUrl = baseUrl; + } + + /** + * @return the host + */ + public String getHost() + { + return this.host; + } + + /** + * @param host the host to set + */ + public void setHost(String host) + { + this.host = host; + } + + /** + * @return the lastIndexedChangesetDate + */ + public String getLastIndexedChangesetDate() + { + return this.lastIndexedChangesetDate; + } + + /** + * @param lastIndexedChangesetDate the lastIndexedChangesetDate to set + */ + public void setLastIndexedChangesetDate(String lastIndexedChangesetDate) + { + this.lastIndexedChangesetDate = lastIndexedChangesetDate; + } + + /** + * @return the lastIndexedChangesetId + */ + public Long getLastIndexedChangesetId() + { + return this.lastIndexedChangesetId; + } + + /** + * @param lastIndexedChangesetId the lastIndexedChangesetId to set + */ + public void setLastIndexedChangesetId(Long lastIndexedChangesetId) + { + this.lastIndexedChangesetId = lastIndexedChangesetId; + } + + /** + * @return the lastIndexedTransactionDate + */ + public String getLastIndexedTransactionDate() + { + return this.lastIndexedTransactionDate; + } + + /** + * @param lastIndexedTransactionDate the lastIndexedTransactionDate to set + */ + public void setLastIndexedTransactionDate(String lastIndexedTransactionDate) + { + this.lastIndexedTransactionDate = lastIndexedTransactionDate; + } + + /** + * @return the lastIndexedTransactionId + */ + public Long getLastIndexedTransactionId() + { + return this.lastIndexedTransactionId; + } + + /** + * @param lastIndexedTransactionId the lastIndexedTransactionId to set + */ + public void setLastIndexedTransactionId(Long lastIndexedTransactionId) + { + this.lastIndexedTransactionId = lastIndexedTransactionId; + } + + /** + * @return the lastUpdateDate + */ + public String getLastUpdateDate() + { + return this.lastUpdateDate; + } + + /** + * @param lastUpdateDate the lastUpdateDate to set + */ + public void setLastUpdateDate(String lastUpdateDate) + { + this.lastUpdateDate = lastUpdateDate; + } + + /** + * @return the port + */ + public Integer getPort() + { + return this.port; + } + + /** + * @param port the port to set + */ + public void setPort(Integer port) + { + this.port = port; + } + + /** + * @return the state + */ + public String getState() + { + return this.state; + } + + /** + * @param state the state to set + */ + public void setState(String state) + { + this.state = state; + } + + /** + * @return the mode + */ + public String getMode() + { + return this.mode; + } + + /** + * @param mode the mode to set + */ + public void setMode(String mode) + { + this.mode = mode; + } + + /** + * @return the transactionsRemaining + */ + public Long getTransactionsRemaining() + { + return this.transactionsRemaining; + } + + /** + * @param transactionsRemaining the transactionsRemaining to set + */ + public void setTransactionsRemaining(Long transactionsRemaining) + { + this.transactionsRemaining = transactionsRemaining; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetFieldModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetFieldModel.java new file mode 100644 index 0000000000..ba4bf73cac --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetFieldModel.java @@ -0,0 +1,222 @@ +package org.alfresco.rest.search; + +import java.util.List; + +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 'gethin' on '2017-03-23 10:59' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestFacetFieldModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestFacetFieldModel model; + + @Override + public RestRequestFacetFieldModel onModel() + { + return model; + } + + public RestRequestFacetFieldModel() + { + super(); + } + + public RestRequestFacetFieldModel(String field) + { + super(); + this.field = field; + } + + public RestRequestFacetFieldModel(String field, String prefix) + { + super(); + this.field = field; + this.prefix = prefix; + } + + public RestRequestFacetFieldModel(String field, String label, Integer minCount) + { + super(); + this.setField(field); + this.setLabel(label); + + if (minCount != null) + { + this.setMincount(minCount); + } + } + + /** + The facet field + */ + + private String field; + /** + A label to include in place of the facet field + */ + + private String label; + /** + Restricts the possible constraints to only indexed values with a specified prefix. + */ + + private String prefix; + + private String sort; + + private String method; + /** + When true, count results that match the query but which have no facet value for the field (in addition to the Term-based constraints). + */ + + private boolean missing; + + private int limit; + + private int offset; + /** + The minimum count required for a facet field to be included in the response. + */ + + private int mincount; + + private int facetEnumCacheMinDf; + /** + Filter Queries with tags listed here will not be included in facet counts. +This is used for multi-select facetting. + + */ + + private List excludeFilters; + + public String getField() + { + return this.field; + } + + public void setField(String field) + { + this.field = field; + } + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getPrefix() + { + return this.prefix; + } + + public void setPrefix(String prefix) + { + this.prefix = prefix; + } + + public String getSort() + { + return this.sort; + } + + public void setSort(String sort) + { + this.sort = sort; + } + + public String getMethod() + { + return this.method; + } + + public void setMethod(String method) + { + this.method = method; + } + + public boolean getMissing() + { + return this.missing; + } + + public void setMissing(boolean missing) + { + this.missing = missing; + } + + public int getLimit() + { + return this.limit; + } + + public void setLimit(int limit) + { + this.limit = limit; + } + + public int getOffset() + { + return this.offset; + } + + public void setOffset(int offset) + { + this.offset = offset; + } + + public int getMincount() + { + return this.mincount; + } + + public void setMincount(int mincount) + { + this.mincount = mincount; + } + + public int getFacetEnumCacheMinDf() + { + return this.facetEnumCacheMinDf; + } + + public void setFacetEnumCacheMinDf(int facetEnumCacheMinDf) + { + this.facetEnumCacheMinDf = facetEnumCacheMinDf; + } + + public List getExcludeFilters() + { + return this.excludeFilters; + } + + public void setExcludeFilters(List excludeFilters) + { + this.excludeFilters = excludeFilters; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetFieldsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetFieldsModel.java new file mode 100644 index 0000000000..1d90bd1902 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetFieldsModel.java @@ -0,0 +1,56 @@ +package org.alfresco.rest.search; + +import java.util.List; + +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 'gethin' on '2017-03-23 10:41' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestFacetFieldsModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestFacetFieldsModel model; + + @Override + public RestRequestFacetFieldsModel onModel() + { + return model; + } + + /** + Define specific fields on which to facet (adds SOLR facet.field and f..facet.* options) + + */ + + private List facets; + + public List getFacets() + { + return this.facets; + } + + public void setFacets(List facets) + { + this.facets = facets; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetIntervalsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetIntervalsModel.java new file mode 100644 index 0000000000..5978bb0621 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetIntervalsModel.java @@ -0,0 +1,70 @@ +package org.alfresco.rest.search; + +import java.util.List; + +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 'gethin' on '2017-03-01 12:12' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestFacetIntervalsModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestFacetIntervalsModel model; + + @Override + public RestRequestFacetIntervalsModel onModel() + { + return model; + } + + /** + Sets the intervals for all fields. + */ + + private List sets; + /** + Specifies the fields to facet by interval. + */ + + private List intervals; + + public List getSets() + { + return this.sets; + } + + public void setSets(List sets) + { + this.sets = sets; + } + + public List getIntervals() + { + return this.intervals; + } + + public void setIntervals(List intervals) + { + this.intervals = intervals; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetSetModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetSetModel.java new file mode 100644 index 0000000000..1ee19eb7ab --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFacetSetModel.java @@ -0,0 +1,113 @@ +package org.alfresco.rest.search; + +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 'gethin' on '2017-03-01 12:12' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestFacetSetModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestFacetSetModel model; + + @Override + public RestRequestFacetSetModel onModel() + { + return model; + } + + /** + A label to use to identify the set + */ + + private String label; + /** + The start of the range + */ + + private String start; + /** + The end of the range + */ + + private String end; + /** + When true, the set will include values greater or equal to "start" + */ + + private boolean startInclusive = true; + /** + When true, the set will include values less than or equal to "end" + */ + + private boolean endInclusive = true; + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getStart() + { + return this.start; + } + + public void setStart(String start) + { + this.start = start; + } + + public String getEnd() + { + return this.end; + } + + public void setEnd(String end) + { + this.end = end; + } + + public boolean isStartInclusive() + { + return this.startInclusive; + } + + public void setStartInclusive(boolean startInclusive) + { + this.startInclusive = startInclusive; + } + + public boolean isEndInclusive() + { + return this.endInclusive; + } + + public void setEndInclusive(boolean endInclusive) + { + this.endInclusive = endInclusive; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFieldsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFieldsModel.java new file mode 100644 index 0000000000..f4eef3eb76 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFieldsModel.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +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 'msuzuki' on '2017-02-24 09:26' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestFieldsModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + public RestRequestFieldsModel(){} + + public RestRequestFieldsModel(String fieldValue) + { + this.field = fieldValue; + } + + @JsonProperty(value = "entry") + RestRequestFieldsModel model; + + @Override + public RestRequestFieldsModel onModel() + { + return model; + } + @JsonProperty(required = true) + private String field; + + public String getField() + { + return field; + } + + public void setField(String field) + { + this.field = field; + } + + + +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFilterQueryModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFilterQueryModel.java new file mode 100644 index 0000000000..96cab717d4 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestFilterQueryModel.java @@ -0,0 +1,82 @@ +package org.alfresco.rest.search; + +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 java.util.List; + +/** + * Hacked together by 'gethin' on '2017-03-23 10:59' from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestFilterQueryModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestFilterQueryModel model; + + @Override + public RestRequestFilterQueryModel onModel() + { + return model; + } + + public RestRequestFilterQueryModel() + { + super(); + } + + public RestRequestFilterQueryModel(String query) + { + super(); + this.query = query; + } + + public RestRequestFilterQueryModel(String query, List tags) + { + super(); + this.query = query; + this.tags = tags; + } + + /** + The filter query + */ + + private String query; + private List tags; + + public String getQuery() + { + return this.query; + } + + public void setQuery(String query) + { + this.query = query; + } + + public List getTags() + { + return this.tags; + } + + public void setTags(List tags) + { + this.tags = tags; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestHighlightModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestHighlightModel.java new file mode 100644 index 0000000000..9de70f1d7a --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestHighlightModel.java @@ -0,0 +1,160 @@ +package org.alfresco.rest.search; + +import java.util.List; + +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 'msuzuki' on '2017-02-23 13:41' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestHighlightModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestHighlightModel model; + + @Override + public RestRequestHighlightModel onModel() + { + return model; + } + + /** + The string used to mark the start of a highlight in a fragment. + */ + + private String prefix; + /** + The string used to mark the end of a highlight in a fragment. + */ + + private String postfix; + /** + The maximum number of distinct highlight snippets to return for each highlight field. + */ + + private int snippetCount; + /** + The character length of each snippet. + */ + + private int fragmentSize; + /** + The number of characters to be considered for highlighting. Matches after this count will not be shown. + */ + + private int maxAnalyzedChars; + /** + If fragments over lap they can be merged into one larger fragment + */ + + private boolean mergeContiguous; + /** + Should phrases be identified. + */ + + private boolean usePhraseHighlighter; + /** + The fields to highlight and field specific configuration properties for each field + */ + + private List fields; + + public String getPrefix() + { + return this.prefix; + } + + public void setPrefix(String prefix) + { + this.prefix = prefix; + } + + public String getPostfix() + { + return this.postfix; + } + + public void setPostfix(String postfix) + { + this.postfix = postfix; + } + + public int getSnippetCount() + { + return this.snippetCount; + } + + public void setSnippetCount(int snippetCount) + { + this.snippetCount = snippetCount; + } + + public int getFragmentSize() + { + return this.fragmentSize; + } + + public void setFragmentSize(int fragmentSize) + { + this.fragmentSize = fragmentSize; + } + + public int getMaxAnalyzedChars() + { + return this.maxAnalyzedChars; + } + + public void setMaxAnalyzedChars(int maxAnalyzedChars) + { + this.maxAnalyzedChars = maxAnalyzedChars; + } + + public boolean getMergeContiguous() + { + return this.mergeContiguous; + } + + public void setMergeContiguous(boolean mergeContiguous) + { + this.mergeContiguous = mergeContiguous; + } + + public boolean getUsePhraseHighlighter() + { + return this.usePhraseHighlighter; + } + + public void setUsePhraseHighlighter(boolean usePhraseHighlighter) + { + this.usePhraseHighlighter = usePhraseHighlighter; + } + + public List getFields() + { + return this.fields; + } + + public void setFields(List fields) + { + this.fields = fields; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestPivotModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestPivotModel.java new file mode 100644 index 0000000000..4e60096446 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestPivotModel.java @@ -0,0 +1,67 @@ +package org.alfresco.rest.search; + +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; + +import java.util.List; + +/** + * Generated by 'gethin' on '2017-03-23 10:07' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestPivotModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestPivotModel model; + + @Override + public RestRequestPivotModel onModel() + { + return model; + } + + /** + A key corresponding to a matching field facet label. + */ + + private String key; + + private List pivots; + + public String getKey() + { + return this.key; + } + + public void setKey(String key) + { + this.key = key; + } + + public List getPivots() + { + return this.pivots; + } + + public void setPivots(List pivots) + { + this.pivots = pivots; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestQueryModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestQueryModel.java new file mode 100644 index 0000000000..6f833b31dd --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestQueryModel.java @@ -0,0 +1,86 @@ +package org.alfresco.rest.search; + +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 'msuzuki' on '2017-02-21 15:39' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestQueryModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestQueryModel model; + + @Override + public RestRequestQueryModel onModel() + { + return model; + } + + /** + The query language in which the query is written. + */ + + private String language; + /** + The exact search request typed in by the user + */ + + private String userQuery; + /** + The query which may have been generated in some way from the userQuery + */ + + + @JsonProperty(required = true) + private String query; + + public String getLanguage() + { + return this.language; + } + + public void setLanguage(String language) + { + this.language = language; + } + + public String getUserQuery() + { + return this.userQuery; + } + + public void setUserQuery(String userQuery) + { + this.userQuery = userQuery; + } + + public String getQuery() + { + return this.query; + } + + public void setQuery(String query) + { + this.query = query; + } + +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestStatsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestStatsModel.java new file mode 100644 index 0000000000..edb3a91acb --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestRequestStatsModel.java @@ -0,0 +1,279 @@ +package org.alfresco.rest.search; + +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 java.util.List; + +/** + * Generated by 'gethin' on '2017-05-05 09:54' from 'Alfresco Content Services REST API' swagger file + * Generated from 'Alfresco Content Services REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestRequestStatsModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestRequestStatsModel model; + + @Override + public RestRequestStatsModel onModel() + { + return model; + } + + /** + The stats field + */ + + private String field; + /** + A label to include for reference the stats field + */ + + private String label; + /** + The minimum value of the field + */ + + private boolean min = true; + /** + The maximum value of the field + */ + + private boolean max = true; + /** + The sum of all values of the field + */ + + private boolean sum = true; + /** + The Number of values found + */ + + private boolean countValues = true; + /** + The Number which do not have a value for this field + */ + + private boolean missing = true; + /** + The average + */ + + private boolean mean = true; + /** + Standard deviation + */ + + private boolean stddev = true; + /** + Sum of all values squared + */ + + private boolean sumOfSquares = true; + /** + The set of all distinct values for the field (This can be very expensive to calculate) + */ + + private boolean distinctValues; + /** + The Number of distinct values (This can be very expensive to calculate) + */ + + private boolean countDistinct; + /** + A statistical approximation of the Number of distinct values + */ + + private boolean cardinality; + /** + Number between 0.0 and 1.0 indicating how aggressively the algorithm should try to be accurate. Used with boolean cardinality flag. + */ + + private Number cardinalityAccuracy; + /** + A list of filters to exclude + */ + + private List excludeFilters; + /** + A list of percentile values, e.g. "1,99,99.9" + */ + + private List percentiles; + + public String getField() + { + return this.field; + } + + public void setField(String field) + { + this.field = field; + } + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public boolean getMin() + { + return this.min; + } + + public void setMin(boolean min) + { + this.min = min; + } + + public boolean getMax() + { + return this.max; + } + + public void setMax(boolean max) + { + this.max = max; + } + + public boolean getSum() + { + return this.sum; + } + + public void setSum(boolean sum) + { + this.sum = sum; + } + + public boolean getCountValues() + { + return this.countValues; + } + + public void setCountValues(boolean countValues) + { + this.countValues = countValues; + } + + public boolean getMissing() + { + return this.missing; + } + + public void setMissing(boolean missing) + { + this.missing = missing; + } + + public boolean getMean() + { + return this.mean; + } + + public void setMean(boolean mean) + { + this.mean = mean; + } + + public boolean getStddev() + { + return this.stddev; + } + + public void setStddev(boolean stddev) + { + this.stddev = stddev; + } + + public boolean getSumOfSquares() + { + return this.sumOfSquares; + } + + public void setSumOfSquares(boolean sumOfSquares) + { + this.sumOfSquares = sumOfSquares; + } + + public boolean getDistinctValues() + { + return this.distinctValues; + } + + public void setDistinctValues(boolean distinctValues) + { + this.distinctValues = distinctValues; + } + + public boolean getCountDistinct() + { + return this.countDistinct; + } + + public void setCountDistinct(boolean countDistinct) + { + this.countDistinct = countDistinct; + } + + public boolean getCardinality() + { + return this.cardinality; + } + + public void setCardinality(boolean cardinality) + { + this.cardinality = cardinality; + } + + public Number getCardinalityAccuracy() + { + return this.cardinalityAccuracy; + } + + public void setCardinalityAccuracy(Number cardinalityAccuracy) + { + this.cardinalityAccuracy = cardinalityAccuracy; + } + + public List getExcludeFilters() + { + return this.excludeFilters; + } + + public void setExcludeFilters(List excludeFilters) + { + this.excludeFilters = excludeFilters; + } + + public List getPercentiles() + { + return this.percentiles; + } + + public void setPercentiles(List percentiles) + { + this.percentiles = percentiles; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResponseConsistencyModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResponseConsistencyModel.java new file mode 100644 index 0000000000..75c5edb536 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResponseConsistencyModel.java @@ -0,0 +1,53 @@ +package org.alfresco.rest.search; + +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 'msuzuki' on '2017-02-23 11:20' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestResponseConsistencyModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestResponseConsistencyModel model; + + @Override + public RestResponseConsistencyModel onModel() + { + return model; + } + + /** + The id of the last indexed transaction + */ + + private int lastTxId; + + public int getLastTxId() + { + return this.lastTxId; + } + + public void setLastTxId(int lastTxId) + { + this.lastTxId = lastTxId; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResultBucketsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResultBucketsModel.java new file mode 100644 index 0000000000..f27d3eee4d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResultBucketsModel.java @@ -0,0 +1,70 @@ +package org.alfresco.rest.search; + +import java.util.List; + +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 'gethin' on '2017-03-01 12:12' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestResultBucketsModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestResultBucketsModel model; + + @Override + public RestResultBucketsModel onModel() + { + return model; + } + + /** + The field name or its explicit label, if provided on the request + */ + + private String label; + /** + An array of buckets and values + */ + + private List buckets; + + public String getLabel() + { + return this.label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public List getBuckets() + { + return this.buckets; + } + + public void setBuckets(List buckets) + { + this.buckets = buckets; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResultSetContextModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResultSetContextModel.java new file mode 100644 index 0000000000..187537fe15 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestResultSetContextModel.java @@ -0,0 +1,128 @@ +package org.alfresco.rest.search; + +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 java.util.List; + +/** + * Generated by 'gethin' on '2017-03-01 14:46' from 'Alfresco Search REST API' swagger file + * Generated from 'Alfresco Search REST API' swagger file + * Base Path {@linkplain /alfresco/api/-default-/public/search/versions/1} + */ +public class RestResultSetContextModel extends TestModel implements IRestModel +{ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + RestResultSetContextModel model; + + @Override + public RestResultSetContextModel onModel() + { + return model; + } + + + private RestResponseConsistencyModel consistency; + /** + The counts from facet queries + */ + + private List facetQueries; + /** + The counts from field facets + */ + + private List facetsFields; + /** + The counts from facet intervals + */ + + private List facets; + /** + Suggested corrections + +If zero results were found for the original query then a single entry of type "searchInsteadFor" will be returned. +If alternatives were found that return more results than the original query they are returned as "didYouMean" options. +The highest quality suggestion is first. + + */ + + private SpellCheckModel spellCheck; + + private SearchRequest request; + + public RestResponseConsistencyModel getConsistency() + { + return this.consistency; + } + + public void setConsistency(RestResponseConsistencyModel consistency) + { + this.consistency = consistency; + } + + public List getFacetQueries() + { + return this.facetQueries; + } + + public void setFacetQueries(List facetQueries) + { + this.facetQueries = facetQueries; + } + + public List getFacetsFields() + { + return this.facetsFields; + } + + public void setFacetsFields(List facetsFields) + { + this.facetsFields = facetsFields; + } + + public List getFacets() + { + return this.facets; + } + + public void setFacets(List facets) + { + this.facets = facets; + } + + public SpellCheckModel getSpellCheck() + { + return this.spellCheck; + } + + public void setSpellCheck(SpellCheckModel spellCheck) + { + this.spellCheck = spellCheck; + } + + public SearchRequest getRequest() + { + return request; + } + + public void setRequest(SearchRequest request) + { + this.request = request; + } +} + diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardInfoModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardInfoModel.java new file mode 100644 index 0000000000..0936281f38 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardInfoModel.java @@ -0,0 +1,348 @@ +/* + * Copyright (C) 2005-2018 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +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; + +/** + * POJO representing shard info model + * + * @author Tuna Aksoy + */ +public class RestShardInfoModel extends TestModel implements IRestModel +{ + /** Model */ + @JsonProperty(value = "entry") + RestShardInfoModel model; + + /** + * @see org.alfresco.rest.core.assertion.IModelAssertion#and() + */ + @Override + public ModelAssertion and() + { + return assertThat(); + } + + /** + * @see org.alfresco.rest.core.assertion.IModelAssertion#assertThat() + */ + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + /** + * @see org.alfresco.rest.core.IRestModel#onModel() + */ + @Override + public RestShardInfoModel onModel() + { + return model; + } + + /** + * @return the model + */ + public RestShardInfoModel getModel() + { + return this.model; + } + + /** + * @param model the model to set + */ + public void setModel(RestShardInfoModel model) + { + this.model = model; + } + + /** Template */ + private String template; + + /** Low instance shards */ + private String lowInstanceShards; + + /** Missing shards */ + private String missingShards; + + /** Max repository transaction Id */ + private Long maxRepositoryTransactionId; + + /** Max live instances */ + private Integer maxLiveInstances; + + /** Remaining Transactions */ + private Long remainingTransactions; + + /** Number of shards */ + private Integer numberOfShards; + + /** Min active instances */ + private Integer minActiveInstances; + + /** Max change set Id */ + private Long maxChangesetId; + + /** Mode */ + private String mode; + + /** Stores */ + private String stores; + + /** Has content */ + private Boolean hasContent; + + /** Shard method */ + private String shardMethod; + + /** Shards */ + private List shards; + + /** + * @return the template + */ + public String getTemplate() + { + return this.template; + } + + /** + * @param template the template to set + */ + public void setTemplate(String template) + { + this.template = template; + } + + /** + * @return the lowInstanceShards + */ + public String getLowInstanceShards() + { + return this.lowInstanceShards; + } + + /** + * @param lowInstanceShards the lowInstanceShards to set + */ + public void setLowInstanceShards(String lowInstanceShards) + { + this.lowInstanceShards = lowInstanceShards; + } + + /** + * @return the missingShards + */ + public String getMissingShards() + { + return this.missingShards; + } + + /** + * @param missingShards the missingShards to set + */ + public void setMissingShards(String missingShards) + { + this.missingShards = missingShards; + } + + /** + * @return the maxRepositoryTransactionId + */ + public Long getMaxRepositoryTransactionId() + { + return this.maxRepositoryTransactionId; + } + + /** + * @param maxRepositoryTransactionId the maxRepositoryTransactionId to set + */ + public void setMaxRepositoryTransactionId(Long maxRepositoryTransactionId) + { + this.maxRepositoryTransactionId = maxRepositoryTransactionId; + } + + /** + * @return the maxLiveInstances + */ + public Integer getMaxLiveInstances() + { + return this.maxLiveInstances; + } + + /** + * @param maxLiveInstances the maxLiveInstances to set + */ + public void setMaxLiveInstances(Integer maxLiveInstances) + { + this.maxLiveInstances = maxLiveInstances; + } + + /** + * @return the remainingTransactions + */ + public Long getRemainingTransactions() + { + return this.remainingTransactions; + } + + /** + * @param remainingTransactions the remainingTransactions to set + */ + public void setRemainingTransactions(Long remainingTransactions) + { + this.remainingTransactions = remainingTransactions; + } + + /** + * @return the numberOfShards + */ + public Integer getNumberOfShards() + { + return this.numberOfShards; + } + + /** + * @param numberOfShards the numberOfShards to set + */ + public void setNumberOfShards(Integer numberOfShards) + { + this.numberOfShards = numberOfShards; + } + + /** + * @return the minActiveInstances + */ + public Integer getMinActiveInstances() + { + return this.minActiveInstances; + } + + /** + * @param minActiveInstances the minActiveInstances to set + */ + public void setMinActiveInstances(Integer minActiveInstances) + { + this.minActiveInstances = minActiveInstances; + } + + /** + * @return the maxChangesetId + */ + public Long getMaxChangesetId() + { + return this.maxChangesetId; + } + + /** + * @param maxChangesetId the maxChangesetId to set + */ + public void setMaxChangesetId(Long maxChangesetId) + { + this.maxChangesetId = maxChangesetId; + } + + /** + * @return the mode + */ + public String getMode() + { + return this.mode; + } + + /** + * @param mode the mode to set + */ + public void setMode(String mode) + { + this.mode = mode; + } + + /** + * @return the stores + */ + public String getStores() + { + return this.stores; + } + + /** + * @param stores the stores to set + */ + public void setStores(String stores) + { + this.stores = stores; + } + + /** + * @return the hasContent + */ + public Boolean getHasContent() + { + return this.hasContent; + } + + /** + * @param hasContent the hasContent to set + */ + public void setHasContent(Boolean hasContent) + { + this.hasContent = hasContent; + } + + /** + * @return the shardMethod + */ + public String getShardMethod() + { + return this.shardMethod; + } + + /** + * @param shardMethod the shardMethod to set + */ + public void setShardMethod(String shardMethod) + { + this.shardMethod = shardMethod; + } + + /** + * @return the shards + */ + public List getShards() + { + return this.shards; + } + + /** + * @param shards the shards to set + */ + public void setShards(List shards) + { + this.shards = shards; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardInfoModelCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardInfoModelCollection.java new file mode 100644 index 0000000000..4054df5651 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardInfoModelCollection.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2005-2018 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.rest.core.RestModels; + +/** + * Object that represent shard info response collection. + * + * @author Tuna Aksoy + */ +public class RestShardInfoModelCollection extends RestModels +{ +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardModel.java new file mode 100644 index 0000000000..f9ca505ef3 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/RestShardModel.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2005-2018 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import java.util.List; + +/** + * Representation of a shard + * + * @author Tuna Aksoy + */ +public class RestShardModel +{ + /** Shard instances */ + private List instances; + + /** + * @return the instances + */ + public List getInstances() + { + return this.instances; + } + + /** + * @param instances the instances to set + */ + public void setInstances(List instances) + { + this.instances = instances; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchNodeModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchNodeModel.java new file mode 100644 index 0000000000..e61a1ad106 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchNodeModel.java @@ -0,0 +1,304 @@ +package org.alfresco.rest.search; + +import java.util.List; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.rest.model.RestByUserModel; +import org.alfresco.rest.model.RestContentModel; +import org.alfresco.utility.model.TestModel; + +import com.fasterxml.jackson.annotation.JsonProperty; +/** + * Object that represent search response entry. + * @author Michael Suzuki + * + */ +public class SearchNodeModel extends TestModel implements IRestModel +{ + @JsonProperty(value = "entry") + SearchNodeModel model; + @JsonProperty(required = true) + private SearchScoreModel search; + @JsonProperty(required = true) + private String id; + + /** + * The name must not contain spaces or the following special characters: * " < > \ / ? : and |. + * The character . must not be used at the end of the name. + */ + @JsonProperty(required = true) + private String name; + + @JsonProperty(required = true) + private String nodeType; + + @JsonProperty(required = true) + private boolean isFolder; + + @JsonProperty(required = true) + private boolean isFile; + + @JsonProperty + private boolean isLocked; + + @JsonProperty(required = true) + private String modifiedAt; + + @JsonProperty(required = true) + private RestByUserModel modifiedByUser; + + @JsonProperty(required = true) + private String createdAt; + + @JsonProperty(required = true) + private RestByUserModel createdByUser; + + private String parentId; + + private boolean isLink; + + private RestContentModel content; + + private List aspectNames; + + private Object properties; + + private List allowableOperations; + + private Object path; + + @JsonProperty + private Object permissions; + + private String location; + + public SearchScoreModel getSearch() + { + return search; + } + + public void setSearch(SearchScoreModel search) + { + this.search = search; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public SearchNodeModel onModel() + { + return model; + } + + public SearchNodeModel getModel() + { + return model; + } + + public void setModel(SearchNodeModel model) + { + this.model = model; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getNodeType() + { + return nodeType; + } + + public void setNodeType(String nodeType) + { + this.nodeType = nodeType; + } + + public boolean isFolder() + { + return isFolder; + } + + public void setFolder(boolean isFolder) + { + this.isFolder = isFolder; + } + + public boolean isFile() + { + return isFile; + } + + public void setFile(boolean isFile) + { + this.isFile = isFile; + } + + public boolean isLocked() + { + return isLocked; + } + + public void setLocked(boolean isLocked) + { + this.isLocked = isLocked; + } + + public String getModifiedAt() + { + return modifiedAt; + } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public RestByUserModel getModifiedByUser() + { + return modifiedByUser; + } + + public void setModifiedByUser(RestByUserModel modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public String getCreatedAt() + { + return createdAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public RestByUserModel getCreatedByUser() + { + return createdByUser; + } + + public void setCreatedByUser(RestByUserModel createdByUser) + { + this.createdByUser = createdByUser; + } + + public String getParentId() + { + return parentId; + } + + public void setParentId(String parentId) + { + this.parentId = parentId; + } + + public boolean isLink() + { + return isLink; + } + + public void setLink(boolean isLink) + { + this.isLink = isLink; + } + + public RestContentModel getContent() + { + return content; + } + + public void setContent(RestContentModel content) + { + this.content = content; + } + + public List getAspectNames() + { + return aspectNames; + } + + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + public Object getProperties() + { + return properties; + } + + public void setProperties(Object properties) + { + this.properties = properties; + } + + public List getAllowableOperations() + { + return allowableOperations; + } + + public void setAllowableOperations(List allowableOperations) + { + this.allowableOperations = allowableOperations; + } + + public Object getPath() + { + return path; + } + + public void setPath(Object path) + { + this.path = path; + } + + public Object getPermissions() + { + return permissions; + } + + public void setPermissions(Object permissions) + { + this.permissions = permissions; + } + + public String getLocation() + { + return location; + } + + public void setLocation(String location) + { + this.location = location; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchNodeModelsCollection.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchNodeModelsCollection.java new file mode 100644 index 0000000000..5ba061d3b3 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchNodeModelsCollection.java @@ -0,0 +1,12 @@ +package org.alfresco.rest.search; + +import org.alfresco.rest.core.RestModels; +/** + * Object that represent search response collection. + * @author Michael Suzuki + * + */ +public class SearchNodeModelsCollection extends RestModels +{ + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchRequest.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchRequest.java new file mode 100644 index 0000000000..13e24de4fe --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchRequest.java @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.alfresco.rest.model.RestRequestRangesModel; +import org.alfresco.rest.model.RestRequestSpellcheckModel; +import org.alfresco.utility.model.TestModel; + +import java.util.ArrayList; +import java.util.List; + +/** + * Search Query object. + * @author msuzuki + * + */ +public class SearchRequest extends TestModel +{ + @JsonProperty(value = "query") + RestRequestQueryModel query; + String language; + Pagination paging; + List fields; + RestRequestHighlightModel highlight; + RestRequestFilterQueryModel filterQueries; + RestRequestFacetFieldsModel facetFields; + RestRequestFacetIntervalsModel facetIntervals; + List facetQueries; + RestRequestSpellcheckModel spellcheck; + Boolean includeRequest = false; + List pivots; + List stats; + List ranges; + String facetFormat; + List include; + List sort; + + public SearchRequest() + { + } + + public SearchRequest(RestRequestQueryModel query) + { + this.query = query; + } + public SearchRequest(RestRequestQueryModel query,RestRequestHighlightModel highlight) + { + this.query = query; + this.highlight = highlight; + } + + public RestRequestQueryModel getQuery() + { + return query; + } + + public void setQuery(RestRequestQueryModel query) + { + this.query = query; + } + + public String getLanguage() + { + return language; + } + + public void setLanguage(String language) + { + this.language = language; + } + + /** + * Returns the include options in this request. + * + * @return the include options in this request. + */ + public List getInclude() + { + return include; + } + + /** + * Sets the include options within this request. + * + * @param options the include options. + */ + public void setInclude(final List options) + { + this.include = options; + } + + public RestRequestHighlightModel getHighlight() + { + return highlight; + } + public void setHighlight(RestRequestHighlightModel highlight) + { + this.highlight = highlight; + } + + public RestRequestFacetFieldsModel getFacetFields() + { + return facetFields; + } + public void setFacetFields(RestRequestFacetFieldsModel facetFields) + { + this.facetFields = facetFields; + } + public List getFacetQueries() + { + return facetQueries; + } + public void setFacetQueries(List facetQueries) + { + this.facetQueries = facetQueries; + } + + public RestRequestFacetIntervalsModel getFacetIntervals() + { + return facetIntervals; + } + + public void setFacetIntervals(RestRequestFacetIntervalsModel facetIntervals) + { + this.facetIntervals = facetIntervals; + } + + public RestRequestSpellcheckModel getSpellcheck() + { + return spellcheck; + } + public void setSpellcheck(RestRequestSpellcheckModel spellcheck) + { + this.spellcheck = spellcheck; + } + + public Boolean getIncludeRequest() + { + return includeRequest; + } + + public void setIncludeRequest(Boolean includeRequest) + { + this.includeRequest = includeRequest; + } + + public List getPivots() + { + return pivots; + } + + public void setPivots(List pivots) + { + this.pivots = pivots; + } + + public List getStats() + { + return stats; + } + + public void setStats(List stats) + { + this.stats = stats; + } + + public Pagination getPaging() + { + return paging; + } + + public void setPaging(Pagination paging) + { + this.paging = paging; + } + + public RestRequestFilterQueryModel getFilterQueries() + { + return filterQueries; + } + + public void setFilterQueries(RestRequestFilterQueryModel filterQueries) + { + this.filterQueries = filterQueries; + } + public List getRanges() + { + return ranges; + } + + public void setRanges(List ranges) + { + this.ranges = ranges; + } + + public String getFacetFormat() + { + return facetFormat; + } + + public void setFacetFormat(String facetFormat) + { + this.facetFormat = facetFormat; + } + + public List getFields() + { + return fields; + } + + public void setFields(List fields) + { + this.fields = fields; + } + + public List getSort() + { + if (sort == null) + { + sort = new ArrayList<>(); + } + return sort; + } + + /** + * Adds a new sort clause to this request. + * The method uses a fluent approach and it returns the same {@link SearchRequest} instance. + * + * @param type the sort clause type (e.g. FIELD) + * @param fieldname the field name. + * @param ascending the sort criterion. + * @return this {@link SearchRequest} instance. + */ + public SearchRequest addSortClause(String type, String fieldname, boolean ascending) + { + getSort().add(SortClause.from(type, fieldname, ascending)); + + return this; + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchResponse.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchResponse.java new file mode 100644 index 0000000000..86eb1d9cc8 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchResponse.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import org.alfresco.rest.core.RestModels; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Search response sample. + * {"list": { + * "entries": [], + * "pagination": { + * "maxItems": 100, + * "hasMoreItems": false, + * "totalItems": 0, + * "count": 0, + * "skipCount": 0 + * }, + * "context": {"consistency": {"lastTxId": 1123}} + * }} + **/ +public class SearchResponse extends RestModels +{ + @JsonProperty(value = "entry") + SearchResponse model; + private RestResultSetContextModel context; + public RestResultSetContextModel getContext() + { + return context; + } + public void setContext(RestResultSetContextModel context) + { + this.context = context; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchScoreModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchScoreModel.java new file mode 100644 index 0000000000..e224800d08 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchScoreModel.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import java.util.List; + +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; +/** + * Object that represents the search score. + * @author Michael Suzuki + * + */ +public class SearchScoreModel extends TestModel implements IRestModel +{ + + @JsonProperty(required = true) + private int score; + + private List highlight; + + public int getScore() + { + return score; + } + + public void setScore(int score) + { + this.score = score; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public SearchScoreModel onModel() + { + return this; + } + + public List getHighlight() + { + return highlight; + } + + public void setHighlight(List highlight) + { + this.highlight = highlight; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchSqlJDBCRequest.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchSqlJDBCRequest.java new file mode 100644 index 0000000000..3da624bfd9 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchSqlJDBCRequest.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2018 Alfresco Software Limited. + * This file is part of Alfresco + * 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 . + */ +package org.alfresco.rest.search; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import org.alfresco.utility.model.TestModel; +import org.alfresco.utility.model.UserModel; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Search SQL Query object for JDBC connection. + * + * @author Meenal Bhave + * + * Request POST + * End point: /sql + * PostBody: + * { + * "stmt":"Select SITE from alfresco where SITE = 'swsdp' limit 2" + * } + */ +public class SearchSqlJDBCRequest extends TestModel +{ + @JsonProperty(required = true) + + String sql; + Connection connection; + Statement stmt; + ResultSet resultSet; + UserModel authUser; + String errorDetails; + + public String getSql() + { + return sql; + } + + public void setSql(String sql) + { + this.sql = sql; + } + + public Statement getStmt() + { + return stmt; + } + + public void setStmt(Statement stmt) + { + this.stmt = stmt; + } + + public Connection getConnection() + { + return connection; + } + + public void setConnection(Connection con) + { + this.connection = con; + } + + public ResultSet getResultSet() + { + return resultSet; + } + + public void setResultSet(ResultSet rs) + { + this.resultSet = rs; + } + + public UserModel getAuthUser() + { + return authUser; + } + + public void setAuthUser(UserModel usermodel) + { + this.authUser = usermodel; + } + + public String getErrorDetails() + { + return errorDetails; + } + + public void setErrorDetails(String errorDetails) + { + this.errorDetails = errorDetails; + } + + public SearchSqlJDBCRequest() + { + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchSqlRequest.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchSqlRequest.java new file mode 100644 index 0000000000..c86a98b36c --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SearchSqlRequest.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2018 Alfresco Software Limited. + * This file is part of Alfresco + * 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 . + */ +package org.alfresco.rest.search; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.alfresco.utility.model.TestModel; + +/** + * Search SQL Query object. + * + * @author Meenal Bhave + * + * Request POST + * End point: /sql + * PostBody: + * { + * "stmt":"Select SITE from alfresco where SITE = 'swsdp' limit 2", + * "locales":["en-Uk"], + * "timezone":"Israel", + * "includeMetadata":true, + * "format":"solr", + * "limit":100, + * "filterQueries":["-ASPECT:ASPECT_CLASSIFIED"] + * } + */ +public class SearchSqlRequest extends TestModel +{ + @JsonProperty(required = true) + String stmt; + + String[] locales; + String timezone; + Boolean includeMetadata; + String format; + Integer limit; + String[] filterQueries; + + public String getSql() + { + return stmt; + } + + public void setSql(String sql) + { + this.stmt = sql; + } + + public String[] getLocales() + { + return locales; + } + + public void setLocales(String[] locales) + { + this.locales = locales; + } + + public String getTimezone() + { + return timezone; + } + + public void setTimezone(String timezone) + { + this.timezone = timezone; + } + + public Boolean getIncludeMetadata() + { + return includeMetadata; + } + + public void setIncludeMetadata(Boolean includeMetadata) + { + this.includeMetadata = includeMetadata; + } + + public String getFormat() + { + return format; + } + + public void setFormat(String format) + { + this.format = format; + } + + public Integer getLimit() + { + return limit; + } + + public void setLimit(Integer limit) + { + this.limit = limit; + } + + public String[] getFilterQueries() + { + return filterQueries; + } + + public void setFilterQuery(String[] filterQueries) + { + this.filterQueries = filterQueries; + } + + public SearchSqlRequest() + { + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SortClause.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SortClause.java new file mode 100644 index 0000000000..8cdcb79ece --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SortClause.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Object representation of a single sort clause. + * + *
+ *  "sort": [
+ *     {
+ *       "type": "FIELD",
+ *       "field": "string",
+ *       "ascending": false
+ *     }
+ *   ]
+ * 
+ */ +public class SortClause +{ + + private String type; + private String field; + private boolean ascending; + + public SortClause() + { + } + + @JsonCreator + public SortClause(@JsonProperty("type") String type, + @JsonProperty("field") String field, + @JsonProperty("ascending") boolean ascending) + { + this.type = type; + this.field = field; + this.ascending = ascending; + } + + public String getType() + { + return type; + } + + public String getField() + { + return field; + } + + public boolean isAscending() + { + return ascending; + } + + public void setType(String type) { + this.type = type; + } + + public void setField(String field) { + this.field = field; + } + + public void setAscending(boolean ascending) { + this.ascending = ascending; + } + + /** + * Shortcut method for creating a sort clause. + * + * @param type the sort type (e.g. FIELD) + * @param fieldname the field name. + * @param ascending ascending (true) or descending (false). + * @return a new {@link SortClause} instance. + */ + public static SortClause from(String type, String fieldname, boolean ascending) + { + return new SortClause(type, fieldname, ascending); + } +} diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SpellCheckModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SpellCheckModel.java new file mode 100644 index 0000000000..18c5a566c0 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/search/SpellCheckModel.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.rest.search; + +import java.util.List; + +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.utility.model.TestModel; +/** + * Object that represents the spell check model response. + * @author Michael Suzuki + * + */ +public class SpellCheckModel extends TestModel implements IRestModel +{ + + private String type; + + private List suggestions; + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + public List getSuggestions() + { + return suggestions; + } + + public void setSuggestions(List suggestions) + { + this.suggestions = suggestions; + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public SpellCheckModel onModel() + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/packaging/tests/tas-restapi/src/main/resources/alfresco-restapi-context.xml b/packaging/tests/tas-restapi/src/main/resources/alfresco-restapi-context.xml new file mode 100644 index 0000000000..7d492e69f2 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/alfresco-restapi-context.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/packaging/tests/tas-restapi/src/main/resources/default.properties b/packaging/tests/tas-restapi/src/main/resources/default.properties new file mode 100644 index 0000000000..268003078d --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/default.properties @@ -0,0 +1,88 @@ +# dataprep related +alfresco.scheme=http +alfresco.server=localhost +alfresco.port=8081 + +# sync service related +sync.scheme=http +sync.server=localhost +sync.port=9090 + +# Solr Server Settings +solr.scheme=http +solr.server=localhost +solr.port=8083 + +#Solr Indexing Time +solrWaitTimeInSeconds=20 + +# credentials +admin.user=admin +admin.password=admin + +# Identity Service configuration +# set this property to run tests using AIS +# identity-service.auth-server-url=http://localhost:8999/auth + +# in containers we cannot access directly JMX, so we will use http://jolokia.org agent +# disabling this we will use direct JMX calls to server +jmx.useJolokiaAgent=false + +# Server Health section +# in ServerHealth#isServerReachable() - could also be shown. +# enable this option to view if on server there are tenants or not +serverHealth.showTenants=false + +# TEST MANAGEMENT SECTION - Test Rail +# +# (currently supporting Test Rail v5.2.1.3472 integration) +# +# Example of configuration: +# ------------------------------------------------------ +# if testManagement.enabled=true we enabled TestRailExecutorListener (if used in your suite xml file) +# testManagement.updateTestExecutionResultsOnly=true (this will just update the results of a test: no step will be updated - good for performance) +# testManagement.endPoint=https://alfresco.testrail.com/ +# testManagement.username= +# testManagement.apiKey= +# testManagement.project= +# testManagement.includeOnlyTestCasesExecuted=true #if you want to include in your run ONLY the test cases that you run, then set this value to false +# testManagement.rateLimitInSeconds=1 #is the default rate limit after what minimum time, should we upload the next request. http://docs.gurock.com/testrail-api2/introduction #Rate Limit +# testManagement.suiteId=23 (the id of the Master suite) +# ------------------------------------------------------ +testManagement.enabled=false +testManagement.endPoint=https://alfresco.testrail.com/ +testManagement.username= +testManagement.apiKey= +testManagement.project= +testManagement.includeOnlyTestCasesExecuted=true +testManagement.rateLimitInSeconds=1 +testManagement.testRun=MyTestRunInTestRail +testManagement.suiteId=12 + +# The location of the reports path +reports.path=./target/reports + +# +# Database Section +# You should provide here the database URL, that can be a differed server as alfresco. +# https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html +# +# Current supported db.url: +# +# MySQL: +# db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +# +# PostgreSQL: +# db.url = jdbc:postgresql://:3306/alfresco +# +# Oracle: +# db.url = jdbc:oracle://:3306/alfresco +# +# MariaDB: +# db.url = jdbc:mariadb://:3306/alfresco +# +db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +db.username = alfresco +db.password = alfresco + diff --git a/packaging/tests/tas-restapi/src/main/resources/log4j.properties b/packaging/tests/tas-restapi/src/main/resources/log4j.properties new file mode 100644 index 0000000000..00e9b5a114 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/log4j.properties @@ -0,0 +1,26 @@ +# Root logger option +log4j.rootLogger=INFO, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=./target/reports/alfresco-tas.log +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +# TestRail particular log file +# Direct log messages to a log file +log4j.appender.testrailLog=org.apache.log4j.RollingFileAppender +log4j.appender.testrailLog.File=./target/reports/alfresco-testrail.log +log4j.appender.testrailLog.MaxBackupIndex=10 +log4j.appender.testrailLog.layout=org.apache.log4j.PatternLayout +log4j.appender.testrailLog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n + +log4j.category.testrail=INFO, testrailLog +log4j.additivity.testrail=false \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/resources/rest-model.ftl b/packaging/tests/tas-restapi/src/main/resources/rest-model.ftl new file mode 100644 index 0000000000..21b3082503 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/rest-model.ftl @@ -0,0 +1,68 @@ +package org.alfresco.rest.model; + +import java.util.List; + +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 '${author}' on '${date}' from '${yamlTitle}' swagger file + * Generated from '${yamlTitle}' swagger file + * Base Path {@linkplain ${yamlBasePath}} + */ +public class ${name} extends TestModel implements IRestModel<${name}> +{ + @Override + public ModelAssertion<${name}> assertThat() + { + return new ModelAssertion<${name}>(this); + } + + @Override + public ModelAssertion<${name}> and() + { + return assertThat(); + } + + @JsonProperty(value = "entry") + ${name} model; + + @Override + public ${name} onModel() + { + return model; + } + +<#if properties??> +<#list properties as p> + <#if p.getDescription()??> + /** + ${p.getDescription()} + */ + + + <#if p.isRequired()==true> + @JsonProperty(required = true) + + private ${p.getType()} ${p.getName()}; + + +<#if properties??> +<#list properties as p> + + public ${p.getType()} get${p.getNameCapitalized()}() + { + return this.${p.getName()}; + } + + public void set${p.getNameCapitalized()}(${p.getType()} ${p.getName()}) + { + this.${p.getName()} = ${p.getName()}; + } + + +} + diff --git a/packaging/tests/tas-restapi/src/main/resources/rest-request.ftl b/packaging/tests/tas-restapi/src/main/resources/rest-request.ftl new file mode 100644 index 0000000000..d964ff7852 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/rest-request.ftl @@ -0,0 +1,12 @@ + public RestReturnedModel ${operationId}() throws Exception + { +<#if httpMethod == "POST"> + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "add-here-json-post-body-u-can-use-JsonBodyGenerator-or-generate-the-model-for-further-use", "${pathUrl}"); +<#elseif httpMethod == "DELETE"> + RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "${pathUrl}"); +<#else> + RestRequest request = RestRequest.simpleRequest(HttpMethod.${httpMethod}, "${pathUrl}?{parameters}", "add-1st-argument-here-or-remove-this", restWrapper.getParameters()); + + return restWrapper.processModel(RestReturnedModel.class, request); + } +------------------------------------------------------------ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/rest-runner-suite.xml b/packaging/tests/tas-restapi/src/main/resources/shared-resources/rest-runner-suite.xml new file mode 100644 index 0000000000..8704fb27d4 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/shared-resources/rest-runner-suite.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testCount.xml b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testCount.xml new file mode 100644 index 0000000000..a79dc36948 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testCount.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/UTF-8File.txt b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/UTF-8File.txt new file mode 100644 index 0000000000..2f273e7986 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/UTF-8File.txt @@ -0,0 +1 @@ + ∮ E⋅da = Q \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/avatar.jpg b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/avatar.jpg new file mode 100644 index 0000000000..30db230dbd Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/avatar.jpg differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/content-zip-test.zip b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/content-zip-test.zip new file mode 100644 index 0000000000..61785e62e5 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/content-zip-test.zip differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/iso8859File.txt b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/iso8859File.txt new file mode 100644 index 0000000000..05665b37d5 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/iso8859File.txt @@ -0,0 +1 @@ +aegif Mind Share Leader Generating New Paradigms by aegif corporation

Test html

\ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/larger.pdf b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/larger.pdf new file mode 100644 index 0000000000..306c8dfc73 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/larger.pdf differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/my-file.tif b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/my-file.tif new file mode 100644 index 0000000000..612bfa9c0b Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/my-file.tif differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.doc b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.doc new file mode 100644 index 0000000000..eb307fb218 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.doc differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.docx b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.docx new file mode 100644 index 0000000000..64832464bb Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.docx differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.gif b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.gif new file mode 100644 index 0000000000..5e4e40e091 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.gif differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.jpg b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.jpg new file mode 100644 index 0000000000..08473b8e8b Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.jpg differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.msg b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.msg new file mode 100644 index 0000000000..6ee3750070 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.msg differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.pdf b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.pdf new file mode 100644 index 0000000000..a1779afd8b Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.pdf differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.png b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.png new file mode 100644 index 0000000000..8f1f89b8fc Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.png differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.ppt b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.ppt new file mode 100644 index 0000000000..5e3f1ef58b Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.ppt differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.pptx b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.pptx new file mode 100644 index 0000000000..666b5d7ea1 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.pptx differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.tiff b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.tiff new file mode 100644 index 0000000000..e8069e0925 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.tiff differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.txt b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.txt new file mode 100644 index 0000000000..f89201fc87 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.txt @@ -0,0 +1,7 @@ +The quick brown fox jumps over the lazy dog + +Le renard brun rapide saute par-dessus le chien paresseux + +Der schnelle braune Fuchs springt über den faulen Hund + +براون وكس السريع يقفز فوق الكلب كسالي \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.xls b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.xls new file mode 100644 index 0000000000..e6ec64cb4d Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.xls differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.xlsx b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.xlsx new file mode 100644 index 0000000000..2e1f271ed8 Binary files /dev/null and b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/quick/quick.xlsx differ diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/restapi-resource b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/restapi-resource new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/sampleContent.txt b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/sampleContent.txt new file mode 100644 index 0000000000..1519fdbdbe --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/shared-resources/testdata/sampleContent.txt @@ -0,0 +1 @@ +Sample text. \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/main/resources/tas-demo-suite.xml b/packaging/tests/tas-restapi/src/main/resources/tas-demo-suite.xml new file mode 100644 index 0000000000..a49a428347 --- /dev/null +++ b/packaging/tests/tas-restapi/src/main/resources/tas-demo-suite.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/.keepme b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/.keepme new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/model/ModelAssertionTest.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/model/ModelAssertionTest.java new file mode 100644 index 0000000000..1ca7d32724 --- /dev/null +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/model/ModelAssertionTest.java @@ -0,0 +1,188 @@ +package org.alfresco.rest.model; + +import com.google.common.collect.ImmutableMap; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; +import org.alfresco.rest.model.RestPersonModel; +import org.junit.Ignore; +import org.testng.annotations.Test; + +import static com.google.common.collect.Sets.newHashSet; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +public class ModelAssertionTest { + + @Test(groups = "unit") + public void iCanAssertExistingProperty() throws Exception { + Person p = new Person(); + p.assertThat().field("id").is("1234"); + } + + @Test(groups = "unit") + public void iCanAssertExistingPropertyNegative() throws Exception { + Person p = new Person(); + p.assertThat().field("id").isNot("12342"); + RestPersonModel rp = new RestPersonModel(); + + rp.getFirstName(); + } + + @Test(groups = "unit", expectedExceptions = AssertionError.class) + public void iHaveOneExceptionThrownWithSelfExplanatoryMessageOnMissingField() throws Exception { + Person p = new Person(); + p.assertThat().field("id2").is("12342"); + + } + + @Test(groups = "unit") + public void iCanTakeTheValueOfFieldsThatDoesntHaveGetters() throws Exception { + Person p = new Person(); + + p.assertThat().field("name").is("test"); + + } + + @Test(groups = "unit") + public void iCanAssertStringIsEmpty() { + Person p = new Person(); + + // Check no exception when field is empty. + p.assertThat().field("nickname").isEmpty(); + + try { + p.assertThat().field("id").isEmpty(); + fail("Expected exception to be raised."); + } catch (AssertionError e) { + assertTrue(e.getMessage().contains("is NOT empty"), "Expected exception to be about a field not being empty."); + } + } + + @Test(groups = "unit") + public void iCanAssertStringIsNotEmpty() { + Person p = new Person(); + + // Check no exception when field is not empty. + p.assertThat().field("id").isNotEmpty(); + + try { + p.assertThat().field("nickname").isNotEmpty(); + fail("Expected exception to be raised."); + } catch (AssertionError e) { + assertTrue(e.getMessage().contains("is empty"), "Expected exception to be about a field being empty."); + } + } + + @Test(groups = "unit") + public void iCanAssertCollectionIsEmpty() { + Person p = new Person(); + + // Check no exception when field is empty. + p.assertThat().field("previousNames").isEmpty(); + + try { + p.assertThat().field("legs").isEmpty(); + fail("Expected exception to be raised."); + } catch (AssertionError e) { + assertTrue(e.getMessage().contains("is NOT empty"), "Expected exception to be about a field not being empty."); + } + } + + @Test(groups = "unit") + public void iCanAssertCollectionIsNotEmpty() { + Person p = new Person(); + + // Check no exception when field is not empty. + p.assertThat().field("legs").isNotEmpty(); + + try { + p.assertThat().field("previousNames").isNotEmpty(); + fail("Expected exception to be raised."); + } catch (AssertionError e) { + assertTrue(e.getMessage().contains("is empty"), "Expected exception to be about a field being empty."); + } + } + + @Test(groups = "unit") + public void iCanAssertMapIsEmpty() { + Person p = new Person(); + + // Check no exception when field is empty. + p.assertThat().field("carrying").isEmpty(); + + try { + p.assertThat().field("clothing").isEmpty(); + fail("Expected exception to be raised."); + } catch (AssertionError e) { + assertTrue(e.getMessage().contains("is NOT empty"), "Expected exception to be about a field not being empty."); + } + } + + @Test(groups = "unit") + public void iCanAssertMapIsNotEmpty() { + Person p = new Person(); + + // Check no exception when field is not empty. + p.assertThat().field("clothing").isNotEmpty(); + + try { + p.assertThat().field("carrying").isNotEmpty(); + fail("Expected exception to be raised."); + } catch (AssertionError e) { + assertTrue(e.getMessage().contains("is empty"), "Expected exception to be about a field being empty."); + } + } + + @Test(groups = "unit") + public void iCanAssertIntIsNotEmpty() { + Person p = new Person(); + + p.assertThat().field("age").isNotEmpty(); + } + + public class Person implements IRestModel { + private String id = "1234"; + private String name = "test"; + public String getName() { return name;} + private String nickname = ""; + private int age = 42; + private Set legs = newHashSet("left", "right"); + private List previousNames = Collections.emptyList(); + private Map clothing = ImmutableMap.of("head", "hat"); + private Map carrying = Collections.emptyMap(); + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getNickname() { return nickname; } + public int getAge() { return age; } + public Set getLegs() { return legs; } + public List getPreviousNames() { return previousNames; } + public Map getClothing() { return clothing; } + public Map getCarrying() { return carrying; } + + @Override + public ModelAssertion and() { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion assertThat() { + return new ModelAssertion(this); + } + + @Override + public Person onModel() { + // TODO Auto-generated method stub + return null; + } + } + +}