From b10c6747a0e5ed1142b8e495e49e27d30a9d6bdf Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Wed, 30 Nov 2016 14:59:51 +0000 Subject: [PATCH 01/12] RM-4391: Test tidied up. --- .../fileplancomponents/UnfiledRecordsFolderTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java index d074f1c8e8..74e669d8ce 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java @@ -100,7 +100,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest public void createRootUnfiledRecordsFolder() throws Exception { // Authenticate with admin user - RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); String folderName = "Folder " + getRandomAlphanumeric(); String folderTitle = folderName + " Title"; @@ -142,7 +142,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest ) public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(FilePlanComponentType componentType) { - RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); String folderName = "Folder " + getRandomAlphanumeric(); String folderTitle = folderName + " Title"; From e411c10ec650863d9f90de8cba007dd1ca63a0b2 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 10:14:07 +0000 Subject: [PATCH 02/12] RM-4391: added parameters in POST and PUT --- .../rm/community/requests/FilePlanComponentAPI.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java index 0ba49263ab..f90d9e767c 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java @@ -123,8 +123,9 @@ public class FilePlanComponentAPI extends RestAPI return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody( POST, toJson(filePlanComponentModel), - "fileplan-components/{fileplanComponentId}/children", - parentId + "fileplan-components/{fileplanComponentId}/children?{parameters}", + parentId, + getParameters() )); } @@ -152,8 +153,9 @@ public class FilePlanComponentAPI extends RestAPI return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody( PUT, toJson(filePlanComponent), - "fileplan-components/{fileplanComponentId}", - filePlanComponentId + "fileplan-components/{fileplanComponentId}?{parameters}", + filePlanComponentId, + getParameters() )); } From 218412357da25c172b63667e739b19e50ee3d45f Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 10:39:06 +0000 Subject: [PATCH 03/12] RM-4391: Support for non-electronic records. --- .../fileplancomponents/FilePlanComponent.java | 3 + .../FilePlanComponentContent.java | 98 +++++++++++++++++ .../FilePlanComponentFields.java | 15 ++- .../FilePlanComponentProperties.java | 100 ++++++++++++++++++ .../FilePlanComponentType.java | 3 +- 5 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java index 8342ce9661..c74034ed5a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java @@ -85,6 +85,9 @@ public class FilePlanComponent @JsonProperty (value = ALLOWABLE_OPERATIONS) private List allowableOperations; + @JsonProperty (required = false) + private FilePlanComponentContent content; + private FilePlanComponentPath path; @JsonProperty (required = true) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java new file mode 100644 index 0000000000..9c90c35156 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java @@ -0,0 +1,98 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * 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. + * #L% + */ +package org.alfresco.rest.rm.community.model.fileplancomponents; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * POJO for FilePlanComponent content field + * @author Kristijan Conkas + * @since 2.6 + */ +public class FilePlanComponentContent +{ + @JsonProperty (required = true) + private String encoding; + + @JsonProperty (required = true) + private String mimeType; + + @JsonProperty (required = true) + private String mimeTypeName; + + @JsonProperty (required = true) + private Integer sizeInBytes; + + /** + * @return the encoding + */ + public String getEncoding() + { + return this.encoding; + } + + /** + * @param encoding the encoding to set + */ + public void setEncoding(String encoding) + { + this.encoding = encoding; + } + + /** + * @return the mimeType + */ + public String getMimeType() + { + return this.mimeType; + } + + /** + * @param mimeType the mimeType to set + */ + public void setMimeType(String mimeType) + { + this.mimeType = mimeType; + } + + /** + * @return the mimeTypeName + */ + public String getMimeTypeName() + { + return this.mimeTypeName; + } + + /** + * @param mimeTypeName the mimeTypeName to set + */ + public void setMimeTypeName(String mimeTypeName) + { + this.mimeTypeName = mimeTypeName; + } + + /** + * @return the sizeInBytes + */ + public Integer getSizeInBytes() + { + return this.sizeInBytes; + } + + /** + * @param sizeInBytes the sizeInBytes to set + */ + public void setSizeInBytes(Integer sizeInBytes) + { + this.sizeInBytes = sizeInBytes; + } +} diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java index 98f38afd36..f839ffda9a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java @@ -45,7 +45,16 @@ public class FilePlanComponentFields public static final String PROPERTIES_DESCRIPTION = "cm:description"; public static final String PROPERTIES_SUPPLEMENTAL_MARKING_LIST = "rmc:supplementalMarkingList"; public static final String ALLOWABLE_OPERATIONS = "allowableOperations"; - public static final String IS_CLOSED="isClosed"; - public static final String PROPERTIES_REVIEW_PERIOD="rma:reviewPeriod"; - public static final String PROPERTIES_LOCATION="rma:location"; + public static final String IS_CLOSED = "isClosed"; + public static final String PROPERTIES_REVIEW_PERIOD = "rma:reviewPeriod"; + public static final String PROPERTIES_LOCATION = "rma:location"; + + // for non-electronic records + public static final String PROPERTIES_BOX = "rma:box"; + public static final String PROPERTIES_FILE = "rma:file"; + public static final String PROPERTIES_NUMBER_OF_COPIES = "rma:numberOfCopies"; + public static final String PROPERTIES_PHYSICAL_SIZE = "rma:physicalSize"; + public static final String PROPERTIES_SHELF = "rma:shelf"; + public static final String PROPERTIES_STORAGE_LOCATION = "rma:storageLocation"; + } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java index ab8fbcd253..261bf546e0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java @@ -26,10 +26,15 @@ */ package org.alfresco.rest.rm.community.model.fileplancomponents; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_BOX; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_FILE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_NUMBER_OF_COPIES; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PHYSICAL_SIZE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_PERIOD; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SHELF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SUPPLEMENTAL_MARKING_LIST; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; @@ -74,6 +79,22 @@ public class FilePlanComponentProperties @JsonProperty(PROPERTIES_LOCATION) private String location; + + @JsonProperty(value = PROPERTIES_BOX, required = false) + private String box; + + @JsonProperty(value = PROPERTIES_FILE, required = false) + private String file; + + @JsonProperty(value = PROPERTIES_SHELF, required = false) + private String shelf; + + @JsonProperty(value = PROPERTIES_NUMBER_OF_COPIES, required = false) + private Integer numberOfCopies; + + @JsonProperty(value = PROPERTIES_PHYSICAL_SIZE, required = false) + private Integer physicalSize; + public FilePlanComponentProperties(String title, String description) { @@ -203,4 +224,83 @@ public class FilePlanComponentProperties this.location = location; } + /** + * @return the box + */ + public String getBox() + { + return this.box; + } + + /** + * @param box the box to set + */ + public void setBox(String box) + { + this.box = box; + } + + /** + * @return the file + */ + public String getFile() + { + return this.file; + } + + /** + * @param file the file to set + */ + public void setFile(String file) + { + this.file = file; + } + + /** + * @return the shelf + */ + public String getShelf() + { + return this.shelf; + } + + /** + * @param shelf the shelf to set + */ + public void setShelf(String shelf) + { + this.shelf = shelf; + } + + /** + * @return the numberOfCopies + */ + public Integer getNumberOfCopies() + { + return this.numberOfCopies; + } + + /** + * @param numberOfCopies the numberOfCopies to set + */ + public void setNumberOfCopies(Integer numberOfCopies) + { + this.numberOfCopies = numberOfCopies; + } + + /** + * @return the physicalSize + */ + public Integer getPhysicalSize() + { + return this.physicalSize; + } + + /** + * @param physicalSize the physicalSize to set + */ + public void setPhysicalSize(Integer physicalSize) + { + this.physicalSize = physicalSize; + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentType.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentType.java index 1308a68295..4398087e56 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentType.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentType.java @@ -46,7 +46,8 @@ public enum FilePlanComponentType TRANSFER_CONTAINER_TYPE("rma:transferContainer"), UNFILED_CONTAINER_TYPE("rma:unfiledRecordContainer"), FOLDER_TYPE("cm:folder"), - CONTENT_TYPE("cm:content"); + CONTENT_TYPE("cm:content"), + NON_ELECTRONIC_RECORD_TYPE("rma:nonElectronicDocument"); private String type; From 5defa54e0d8ab7faebe1b601dabed0059bbf14e5 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 10:39:33 +0000 Subject: [PATCH 04/12] RM-4391: Added tests --- .../NonElectronicRecordTests.java | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java new file mode 100644 index 0000000000..1528f02404 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -0,0 +1,184 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.fileplancomponents; + +import static java.util.Arrays.asList; + +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +import java.util.Random; + +import org.alfresco.rest.rm.community.base.BaseRestTest; +import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; +import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +/** + * Create/File Non-Electronic Record into Unfiled Record Container/Record Folder ReST API tests + * + * @author Kristijan Conkas + * @since 2.6 + */ +public class NonElectronicRecordTests extends BaseRestTest +{ + @Autowired + private FilePlanComponentAPI filePlanComponentAPI; + + @Autowired + private DataUser dataUser; + + + /** + * Given a parent container that is NOT a record folder or an unfiled record folder + * When I try to create a non-electronic record within the parent container + * Then nothing happens + * And an error is reported + * @throws Exception + */ + @Test(description = "Non-electronic record can't be created as a child of invalid parent Id") + public void noCreateForInvalidParentIds() throws Exception + { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // non-electronic record object to be used for create tests + FilePlanComponent nonElectronicRecord = new FilePlanComponent( + "Record " + getRandomAlphanumeric(), + NON_ELECTRONIC_RECORD_TYPE.toString(), + new FilePlanComponentProperties()); + + // create record category, non-electronic records can't be its children + FilePlanComponent recordCategory = filePlanComponentAPI.createFilePlanComponent( + new FilePlanComponent("Category " + getRandomAlphanumeric(), + RECORD_CATEGORY_TYPE.toString(), + new FilePlanComponentProperties()), + FILE_PLAN_ALIAS.toString()); + + // iterate through all invalid parent containers and try to create/file an electronic record + asList(FILE_PLAN_ALIAS.toString(), TRANSFERS_ALIAS.toString(), HOLDS_ALIAS.toString(), recordCategory.getId()) + .stream() + .forEach(id -> + { + try + { + filePlanComponentAPI.createFilePlanComponent(nonElectronicRecord, id); + } + catch (Exception error) + { + } + + // Verify the status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); + }); + } + + /** + * Given a parent container that is a record folder + * And the record folder is open + * When I try to create a non-electronic record within the parent container + * Then the non-electronic record is created + * And the details of the new record are returned + * @throws Exception if record can't be created + */ + @Test(description = "Non-electronic record can be created in open record folder") + public void canCreateInOpenFolder() throws Exception + { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // create root category + FilePlanComponent recordCategory = filePlanComponentAPI.createFilePlanComponent( + new FilePlanComponent("Category " + getRandomAlphanumeric(), + RECORD_CATEGORY_TYPE.toString(), + new FilePlanComponentProperties()), + FILE_PLAN_ALIAS.toString()); + + // create record folder as a child of recordCategory + FilePlanComponent recordFolder = filePlanComponentAPI.withParams("include=" + IS_CLOSED) + .createFilePlanComponent(new FilePlanComponent("Folder " + getRandomAlphanumeric(), + RECORD_FOLDER_TYPE.toString(), + new FilePlanComponentProperties()), + recordCategory.getId()); + + // the folder should be open + assertFalse(recordFolder.isClosed()); + + String title = "Title " + getRandomAlphanumeric(); + String description = "Description " + getRandomAlphanumeric(); + String box = "Box "+ getRandomAlphanumeric(); + String file = "File " + getRandomAlphanumeric(); + String shelf = "Shelf " + getRandomAlphanumeric(); + String location = "Location " + getRandomAlphanumeric(); + + Random random = new Random(); + Integer copies = random.nextInt(Integer.MAX_VALUE); + Integer size = random.nextInt(Integer.MAX_VALUE); + + // set values of all available properties + FilePlanComponentProperties properties = new FilePlanComponentProperties(title, description); + properties.setBox(box); + properties.setFile(file); + properties.setShelf(shelf); + properties.setLocation(location); + properties.setNumberOfCopies(copies); + properties.setPhysicalSize(size); + + // create non-electronic record + String nonElectronicId = filePlanComponentAPI.createFilePlanComponent( + new FilePlanComponent("Record " + getRandomAlphanumeric(), + NON_ELECTRONIC_RECORD_TYPE.toString(), + properties), + recordFolder.getId()).getId(); + + // verify the create request status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); + + // get newly created non-electonic record and verify its properties + FilePlanComponent nonElectronicRecord = filePlanComponentAPI.getFilePlanComponent(nonElectronicId); + + assertEquals(title, nonElectronicRecord.getProperties().getTitle()); + assertEquals(description, nonElectronicRecord.getProperties().getDescription()); + assertEquals(box, nonElectronicRecord.getProperties().getBox()); + assertEquals(file, nonElectronicRecord.getProperties().getFile()); + assertEquals(shelf, nonElectronicRecord.getProperties().getShelf()); + assertEquals(location, nonElectronicRecord.getProperties().getLocation()); + assertEquals(copies, nonElectronicRecord.getProperties().getNumberOfCopies()); + assertEquals(size, nonElectronicRecord.getProperties().getPhysicalSize()); + } +} From a0ca1d8de87759a3d16d1c59fb867a84c7ec3e3a Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 11:29:47 +0000 Subject: [PATCH 05/12] RM-4391: Closed folder creation test. --- .../FilePlanComponentFields.java | 1 + .../FilePlanComponentProperties.java | 20 ++++++ .../rest/rm/community/base/BaseRestTest.java | 21 ++++++ .../NonElectronicRecordTests.java | 70 ++++++++++++++----- 4 files changed, 96 insertions(+), 16 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java index f839ffda9a..11b14c1906 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java @@ -48,6 +48,7 @@ public class FilePlanComponentFields public static final String IS_CLOSED = "isClosed"; public static final String PROPERTIES_REVIEW_PERIOD = "rma:reviewPeriod"; public static final String PROPERTIES_LOCATION = "rma:location"; + public static final String PROPERTIES_IS_CLOSED = "rma:isClosed"; // not to be confused with IS_CLOSED! // for non-electronic records public static final String PROPERTIES_BOX = "rma:box"; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java index 261bf546e0..9c17419680 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java @@ -30,6 +30,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_FILE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_IS_CLOSED; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_NUMBER_OF_COPIES; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PHYSICAL_SIZE; @@ -80,6 +81,9 @@ public class FilePlanComponentProperties @JsonProperty(PROPERTIES_LOCATION) private String location; + @JsonProperty(value = PROPERTIES_IS_CLOSED, required = false) + private Boolean isClosed; + @JsonProperty(value = PROPERTIES_BOX, required = false) private String box; @@ -303,4 +307,20 @@ public class FilePlanComponentProperties { this.physicalSize = physicalSize; } + + /** + * @return the isClosed + */ + public Boolean getIsClosed() + { + return this.isClosed; + } + + /** + * @param isClosed the isClosed to set + */ + public void setIsClosed(Boolean isClosed) + { + this.isClosed = isClosed; + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java index 7eade80baa..601d1437e2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java @@ -35,6 +35,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.STANDARD; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; import com.jayway.restassured.RestAssured; @@ -190,4 +191,24 @@ public class BaseRestTest extends RestTest return fpc; } + /** + * Helper method to close folder + * @param folderToClose + * @return + * @throws Exception + */ + public FilePlanComponent closeFolder(String folderId) throws Exception + { + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // build fileplan component + properties for update request + FilePlanComponentProperties properties = new FilePlanComponentProperties(); + properties.setIsClosed(true); + FilePlanComponent filePlanComponent = new FilePlanComponent(); + filePlanComponent.setProperties(properties); + + FilePlanComponent updatedComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanComponent, folderId); + restWrapper.assertStatusCodeIs(OK); + return updatedComponent; + } } \ No newline at end of file diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java index 1528f02404..257548c797 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -121,24 +121,12 @@ public class NonElectronicRecordTests extends BaseRestTest public void canCreateInOpenFolder() throws Exception { filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - - // create root category - FilePlanComponent recordCategory = filePlanComponentAPI.createFilePlanComponent( - new FilePlanComponent("Category " + getRandomAlphanumeric(), - RECORD_CATEGORY_TYPE.toString(), - new FilePlanComponentProperties()), - FILE_PLAN_ALIAS.toString()); - - // create record folder as a child of recordCategory - FilePlanComponent recordFolder = filePlanComponentAPI.withParams("include=" + IS_CLOSED) - .createFilePlanComponent(new FilePlanComponent("Folder " + getRandomAlphanumeric(), - RECORD_FOLDER_TYPE.toString(), - new FilePlanComponentProperties()), - recordCategory.getId()); + FilePlanComponent recordFolder = createFolderInFilePlan(); // the folder should be open - assertFalse(recordFolder.isClosed()); + assertFalse(recordFolder.getProperties().getIsClosed()); + // use these properties for non-electronic record to be created String title = "Title " + getRandomAlphanumeric(); String description = "Description " + getRandomAlphanumeric(); String box = "Box "+ getRandomAlphanumeric(); @@ -180,5 +168,55 @@ public class NonElectronicRecordTests extends BaseRestTest assertEquals(location, nonElectronicRecord.getProperties().getLocation()); assertEquals(copies, nonElectronicRecord.getProperties().getNumberOfCopies()); assertEquals(size, nonElectronicRecord.getProperties().getPhysicalSize()); - } + } + + /** + * Given a parent container that is a record folder + * And the record folder is closed + * When I try to create a non-electronic record within the parent container + * Then nothing happens + * And an error is reported + * @throws Exception on failed component creation + */ + @Test(description = "Non-electronic record can't be created in closed record folder") + public void noCreateInClosedFolder() throws Exception + { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent recordFolder = createFolderInFilePlan(); + + // the folder should be open + assertFalse(recordFolder.getProperties().getIsClosed()); + + // close the folder + closeFolder(recordFolder.getId()); + + try + { + filePlanComponentAPI.createFilePlanComponent( + new FilePlanComponent("Record " + getRandomAlphanumeric(), + NON_ELECTRONIC_RECORD_TYPE.toString(), + new FilePlanComponentProperties()), + recordFolder.getId()).getId(); + } + catch (Exception e) + { + } + + // verify the status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); + } + + /** + * Helper method to create a randomly-named / structure in fileplan + * @return record folder + * @throws Exception on failed creation + */ + private FilePlanComponent createFolderInFilePlan() throws Exception + { + // create root category + FilePlanComponent recordCategory = createCategory(FILE_PLAN_ALIAS.toString(), "Category " + getRandomAlphanumeric()); + + // and return a folder underneath + return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric()); + } } From 98488eaf21578d54c9d45ee272e53dc38ddc6769 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 14:04:37 +0000 Subject: [PATCH 06/12] RM-4391: mandatory parameters test. --- .../NonElectronicRecordTests.java | 83 +++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java index 257548c797..1e0136b52e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -31,11 +31,11 @@ import static java.util.Arrays.asList; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.testng.Assert.assertEquals; @@ -65,13 +65,14 @@ public class NonElectronicRecordTests extends BaseRestTest @Autowired private DataUser dataUser; - /** + *
      * Given a parent container that is NOT a record folder or an unfiled record folder
      * When I try to create a non-electronic record within the parent container
      * Then nothing happens
      * And an error is reported
-     * @throws Exception 
+     * 
+ * @throws Exception if prerequisites can't be created */ @Test(description = "Non-electronic record can't be created as a child of invalid parent Id") public void noCreateForInvalidParentIds() throws Exception @@ -110,11 +111,13 @@ public class NonElectronicRecordTests extends BaseRestTest } /** + *
      * Given a parent container that is a record folder
      * And the record folder is open
      * When I try to create a non-electronic record within the parent container
      * Then the non-electronic record is created
      * And the details of the new record are returned
+     * 
      * @throws Exception if record can't be created
      */
     @Test(description = "Non-electronic record can be created in open record folder")
@@ -171,12 +174,14 @@ public class NonElectronicRecordTests extends BaseRestTest
     }
     
     /**
+     * 
      * Given a parent container that is a record folder
      * And the record folder is closed 
      * When I try to create a non-electronic record within the parent container
      * Then nothing happens
      * And an error is reported
-     * @throws Exception on failed component creation
+     * 
+ * @throws Exception if prerequisites can't be created */ @Test(description = "Non-electronic record can't be created in closed record folder") public void noCreateInClosedFolder() throws Exception @@ -190,6 +195,7 @@ public class NonElectronicRecordTests extends BaseRestTest // close the folder closeFolder(recordFolder.getId()); + // try to create it, this should fail and throw an exception try { filePlanComponentAPI.createFilePlanComponent( @@ -205,6 +211,73 @@ public class NonElectronicRecordTests extends BaseRestTest // verify the status code filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); } + + /** + *
+     * Given a parent container that is a record folder
+     * And the record folder is open
+     * When I try to create a non-electronic record within the parent container
+     * And I do not provide all the required mandatory property values
+     * Then nothing happens
+     * And an error is reported
+     * 
+ * @throws Exception if prerequisites can't be created + */ + @Test(description = "Non-electronic record can only be created if all mandatory properties are given") + public void allMandatoryPropertiesRequired() throws Exception + { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent recordFolder = createFolderInFilePlan(); + assertFalse(recordFolder.getProperties().getIsClosed()); + + // component without name and title + FilePlanComponent noNameOrTitle = getDummyFilePlanComponent(); + + // component with title only + FilePlanComponent titleOnly = getDummyFilePlanComponent(); + FilePlanComponentProperties properties = new FilePlanComponentProperties(); + properties.setTitle("Title " + getRandomAlphanumeric()); + titleOnly.setProperties(properties); + + // component with name only + FilePlanComponent nameOnly = getDummyFilePlanComponent(); + nameOnly.setName("Name " + getRandomAlphanumeric()); + + // try to create invalid components + asList(noNameOrTitle, titleOnly, nameOnly).stream().forEach(c -> + { + try + { + logger.info("Creating non-electronic record with body:\n" + toJson(c)); + } + catch (Exception error) + { + } + + // this should fail and throw an exception + try + { + filePlanComponentAPI.createFilePlanComponent(c, recordFolder.getId()); + } + catch (Exception e) + { + } + + // verify the status code is BAD_REQUEST + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); + }); + } + + /** + * Helper function to return an empty FilePlanComponent for non-electronic record + * @return + */ + private FilePlanComponent getDummyFilePlanComponent() + { + FilePlanComponent component = new FilePlanComponent(); + component.setNodeType(NON_ELECTRONIC_RECORD_TYPE.toString()); + return component; + } /** * Helper method to create a randomly-named / structure in fileplan From 7923fef355d2b3eafd6b17b72bb7ea7efd2b1904 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 14:46:57 +0000 Subject: [PATCH 07/12] RM-4391: Added remaining unfiled records root + folders tests. --- .../NonElectronicRecordTests.java | 89 ++++++++++++++----- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java index 1e0136b52e..9d556a454a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -31,8 +31,10 @@ import static java.util.Arrays.asList; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -48,7 +50,9 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** @@ -65,6 +69,19 @@ public class NonElectronicRecordTests extends BaseRestTest @Autowired private DataUser dataUser; + /** Valid root containers where non-electronic records can be created */ + @DataProvider(name = "validContainers") + public Object[][] rootContainers() throws Exception { + return new Object[][] { + // an arbitrary record folder + { createFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) }, + // unfiled records root + { filePlanComponentAPI.getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS.toString()) }, + // an arbitrary unfiled records folder + { createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()) } + }; + } + /** *
      * Given a parent container that is NOT a record folder or an unfiled record folder
@@ -118,16 +135,28 @@ public class NonElectronicRecordTests extends BaseRestTest
      * Then the non-electronic record is created
      * And the details of the new record are returned
      * 
+     * and
+     * 
+     * Given a parent container that is an unfiled record folder or the root unfiled record container
+     * When I try to create a non-electronic record within the parent container
+     * Then the non-electronic record is created
+     * And the details of the new record are returned
+     * 
* @throws Exception if record can't be created */ - @Test(description = "Non-electronic record can be created in open record folder") - public void canCreateInOpenFolder() throws Exception + @Test + ( + dataProvider = "validContainers", + description = "Non-electronic records can be created in valid containers" + ) + public void canCreateInValidContainers(FilePlanComponent container) throws Exception { - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - FilePlanComponent recordFolder = createFolderInFilePlan(); - - // the folder should be open - assertFalse(recordFolder.getProperties().getIsClosed()); + logger.info("Root container:\n" + toJson(container)); + if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString())) + { + // only record folders can be open or closed + assertFalse(container.getProperties().getIsClosed()); + } // use these properties for non-electronic record to be created String title = "Title " + getRandomAlphanumeric(); @@ -155,7 +184,7 @@ public class NonElectronicRecordTests extends BaseRestTest new FilePlanComponent("Record " + getRandomAlphanumeric(), NON_ELECTRONIC_RECORD_TYPE.toString(), properties), - recordFolder.getId()).getId(); + container.getId()).getId(); // verify the create request status code filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); @@ -186,8 +215,7 @@ public class NonElectronicRecordTests extends BaseRestTest @Test(description = "Non-electronic record can't be created in closed record folder") public void noCreateInClosedFolder() throws Exception { - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - FilePlanComponent recordFolder = createFolderInFilePlan(); + FilePlanComponent recordFolder = createFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()); // the folder should be open assertFalse(recordFolder.getProperties().getIsClosed()); @@ -221,26 +249,41 @@ public class NonElectronicRecordTests extends BaseRestTest * Then nothing happens * And an error is reported *
+ * and + *
+     * Given a parent container that is an unfiled record folder or the root unfiled record container
+     * When I try to create a non-electronic record within the parent container
+     * And I do not provide all the required mandatory property values
+     * Then nothing happens
+     * And an error is reported
+     * 
* @throws Exception if prerequisites can't be created */ - @Test(description = "Non-electronic record can only be created if all mandatory properties are given") - public void allMandatoryPropertiesRequired() throws Exception + @Test + ( + dataProvider = "validContainers", + description = "Non-electronic record can only be created if all mandatory properties are given" + ) + public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception { - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - FilePlanComponent recordFolder = createFolderInFilePlan(); - assertFalse(recordFolder.getProperties().getIsClosed()); + logger.info("Root container:\n" + toJson(container)); + if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString())) + { + // only record folders can be open or closed + assertFalse(container.getProperties().getIsClosed()); + } // component without name and title - FilePlanComponent noNameOrTitle = getDummyFilePlanComponent(); + FilePlanComponent noNameOrTitle = getDummyNonElectronicRecord(); // component with title only - FilePlanComponent titleOnly = getDummyFilePlanComponent(); + FilePlanComponent titleOnly = getDummyNonElectronicRecord(); FilePlanComponentProperties properties = new FilePlanComponentProperties(); properties.setTitle("Title " + getRandomAlphanumeric()); titleOnly.setProperties(properties); // component with name only - FilePlanComponent nameOnly = getDummyFilePlanComponent(); + FilePlanComponent nameOnly = getDummyNonElectronicRecord(); nameOnly.setName("Name " + getRandomAlphanumeric()); // try to create invalid components @@ -257,7 +300,7 @@ public class NonElectronicRecordTests extends BaseRestTest // this should fail and throw an exception try { - filePlanComponentAPI.createFilePlanComponent(c, recordFolder.getId()); + filePlanComponentAPI.createFilePlanComponent(c, container.getId()); } catch (Exception e) { @@ -272,7 +315,7 @@ public class NonElectronicRecordTests extends BaseRestTest * Helper function to return an empty FilePlanComponent for non-electronic record * @return */ - private FilePlanComponent getDummyFilePlanComponent() + private FilePlanComponent getDummyNonElectronicRecord() { FilePlanComponent component = new FilePlanComponent(); component.setNodeType(NON_ELECTRONIC_RECORD_TYPE.toString()); @@ -284,10 +327,12 @@ public class NonElectronicRecordTests extends BaseRestTest * @return record folder * @throws Exception on failed creation */ - private FilePlanComponent createFolderInFilePlan() throws Exception + private FilePlanComponent createFolderInFilePlan(UserModel user, String parentId) throws Exception { + filePlanComponentAPI.usingRestWrapper().authenticateUser(user); + // create root category - FilePlanComponent recordCategory = createCategory(FILE_PLAN_ALIAS.toString(), "Category " + getRandomAlphanumeric()); + FilePlanComponent recordCategory = createCategory(parentId, "Category " + getRandomAlphanumeric()); // and return a folder underneath return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric()); From 1105894786552d2b0d53d5ac3cdcf838a63d2f74 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 14:59:24 +0000 Subject: [PATCH 08/12] RM-4391: Now with correct header. --- .../FilePlanComponentContent.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java index 9c90c35156..eb2f102266 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java @@ -4,9 +4,24 @@ * %% * Copyright (C) 2005 - 2016 Alfresco Software Limited * %% - * 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. + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . * #L% */ package org.alfresco.rest.rm.community.model.fileplancomponents; From e6ea93b481e90a3c0a8a9656b423096f179a0473 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Mon, 5 Dec 2016 14:52:55 +0000 Subject: [PATCH 09/12] RM-4391: User without rm privileges test. --- .../rest/rm/community/base/BaseRestTest.java | 46 ++++++++++++++- .../NonElectronicRecordTests.java | 57 ++++++++++++++++--- 2 files changed, 94 insertions(+), 9 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java index 601d1437e2..86d25ac5ac 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java @@ -47,11 +47,14 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent import org.alfresco.rest.rm.community.model.site.RMSite; import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.RMSiteAPI; +import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; +import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; /** @@ -84,7 +87,7 @@ public class BaseRestTest extends RestTest @Autowired private RMSiteAPI rmSiteAPI; - + @Autowired private DataUser dataUser; @@ -211,4 +214,45 @@ public class BaseRestTest extends RestTest restWrapper.assertStatusCodeIs(OK); return updatedComponent; } + + /** + * Create RM user with given role + *
+ * Checks whether the user exists in RM site and creates it if required, with password identical + * to username. Note the role is a Core API role, not an RM role. + *
+ * For already existing users, no role verification is performed. + *

+ * @param userName username to add + * @param userRole user's role + * @throws Exception + */ + public UserModel createRMUserWithRole(String userName, UserRole userRole) throws Exception + { + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + String siteId = rmSiteAPI.getSite().getId(); + logger.info("Site:" + rmSiteAPI.getSite() + " id: " + siteId); + + // check if user exists + UserModel user = new UserModel(); + user.setUsername(userName); + user.setPassword(userName); + rmSiteAPI.usingRestWrapper().withCoreAPI().usingSite(siteId).getSiteMember(user); + + if (rmSiteAPI.usingRestWrapper().getStatusCode().equals(HttpStatus.NOT_FOUND.toString())) + { + // user doesn't exist, create it + logger.info("user doesn't exist, creating"); + + user = dataUser.createUser(userName, userName); + user.setUserRole(userRole); + + rmSiteAPI.usingRestWrapper().withCoreAPI().usingSite(siteId).addPerson(user); + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); + } + logger.info("returning existing user"); + + return user; + } } \ No newline at end of file diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java index 9d556a454a..6848d39ba9 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -39,6 +39,7 @@ import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -49,6 +50,7 @@ import org.alfresco.rest.rm.community.base.BaseRestTest; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; +import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; @@ -68,7 +70,7 @@ public class NonElectronicRecordTests extends BaseRestTest @Autowired private DataUser dataUser; - + /** Valid root containers where non-electronic records can be created */ @DataProvider(name = "validContainers") public Object[][] rootContainers() throws Exception { @@ -92,7 +94,7 @@ public class NonElectronicRecordTests extends BaseRestTest * @throws Exception if prerequisites can't be created */ @Test(description = "Non-electronic record can't be created as a child of invalid parent Id") - public void noCreateForInvalidParentIds() throws Exception + public void cantCreateForInvalidParentIds() throws Exception { filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); @@ -151,6 +153,8 @@ public class NonElectronicRecordTests extends BaseRestTest ) public void canCreateInValidContainers(FilePlanComponent container) throws Exception { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + logger.info("Root container:\n" + toJson(container)); if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString())) { @@ -213,8 +217,9 @@ public class NonElectronicRecordTests extends BaseRestTest * @throws Exception if prerequisites can't be created */ @Test(description = "Non-electronic record can't be created in closed record folder") - public void noCreateInClosedFolder() throws Exception + public void cantCreateInClosedFolder() throws Exception { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent recordFolder = createFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()); // the folder should be open @@ -266,6 +271,8 @@ public class NonElectronicRecordTests extends BaseRestTest ) public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + logger.info("Root container:\n" + toJson(container)); if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString())) { @@ -282,12 +289,8 @@ public class NonElectronicRecordTests extends BaseRestTest properties.setTitle("Title " + getRandomAlphanumeric()); titleOnly.setProperties(properties); - // component with name only - FilePlanComponent nameOnly = getDummyNonElectronicRecord(); - nameOnly.setName("Name " + getRandomAlphanumeric()); - // try to create invalid components - asList(noNameOrTitle, titleOnly, nameOnly).stream().forEach(c -> + asList(noNameOrTitle, titleOnly).stream().forEach(c -> { try { @@ -311,6 +314,44 @@ public class NonElectronicRecordTests extends BaseRestTest }); } + /** + *

+     * Given that I am a user without RM privileges
+     * When I try to create a non-electronic record
+     * Then nothing happens
+     * And an error is reported
+     * 
+ * @throws Exception + */ + @Test + ( + dataProvider = "validContainers", + description = "Non-electronic record can't be created if user doesn't have RM privileges" + ) + public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception + { + String username = "zzzuser"; + UserModel user = createRMUserWithRole(username, UserRole.SiteConsumer); + + filePlanComponentAPI.usingRestWrapper().authenticateUser(user); + + // try to create a fileplan component + FilePlanComponent record = new FilePlanComponent("Record Name", NON_ELECTRONIC_RECORD_TYPE.toString(), + new FilePlanComponentProperties("Name", "Title")); + + // this should fail and throw an exception + try + { + filePlanComponentAPI.createFilePlanComponent(record, container.getId()); + } + catch (Exception e) + { + } + + // user who isn't an RM site member can't access the container path, hence NOT_FOUND + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); + } + /** * Helper function to return an empty FilePlanComponent for non-electronic record * @return From dc3be5a378c2dfbf5c996ade70feea89ae8219ff Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Mon, 5 Dec 2016 15:59:38 +0000 Subject: [PATCH 10/12] RM-4391: fixed core API use affecting RM base path --- .../rest/rm/community/base/BaseRestTest.java | 16 +++++----------- .../NonElectronicRecordTests.java | 5 +++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java index 86d25ac5ac..88c3426586 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java @@ -49,6 +49,7 @@ import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.RMSiteAPI; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -230,28 +231,21 @@ public class BaseRestTest extends RestTest public UserModel createRMUserWithRole(String userName, UserRole userRole) throws Exception { rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - String siteId = rmSiteAPI.getSite().getId(); - logger.info("Site:" + rmSiteAPI.getSite() + " id: " + siteId); // check if user exists UserModel user = new UserModel(); user.setUsername(userName); user.setPassword(userName); - rmSiteAPI.usingRestWrapper().withCoreAPI().usingSite(siteId).getSiteMember(user); - - if (rmSiteAPI.usingRestWrapper().getStatusCode().equals(HttpStatus.NOT_FOUND.toString())) + + if (!dataUser.isUserInRepo(userName)) { // user doesn't exist, create it - logger.info("user doesn't exist, creating"); - user = dataUser.createUser(userName, userName); user.setUserRole(userRole); - - rmSiteAPI.usingRestWrapper().withCoreAPI().usingSite(siteId).addPerson(user); - rmSiteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); + + dataUser.addUserToSite(user, new SiteModel(siteId), userRole); } - logger.info("returning existing user"); return user; } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java index 6848d39ba9..c556821f73 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -39,6 +39,7 @@ import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.testng.Assert.assertEquals; @@ -348,8 +349,8 @@ public class NonElectronicRecordTests extends BaseRestTest { } - // user who isn't an RM site member can't access the container path, hence NOT_FOUND - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); + // user who isn't an RM site member can't access the container path + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); } /** From c0b925e958fc344f26bd899b668c1f5b239767dc Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Mon, 5 Dec 2016 16:00:27 +0000 Subject: [PATCH 11/12] RM-4391: javadoc clarification --- .../java/org/alfresco/rest/rm/community/base/BaseRestTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java index 88c3426586..c0fcf4f566 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java @@ -222,7 +222,7 @@ public class BaseRestTest extends RestTest * Checks whether the user exists in RM site and creates it if required, with password identical * to username. Note the role is a Core API role, not an RM role. *
- * For already existing users, no role verification is performed. + * For already existing users, no site membership or role verification is performed. *

* @param userName username to add * @param userRole user's role From fc00aecbb63f6e5776799565dcb024a689d6301d Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Tue, 6 Dec 2016 11:23:48 +0000 Subject: [PATCH 12/12] RM-4391: CI remediation --- .../rest/rm/community/base/BaseRestTest.java | 37 ------------ .../NonElectronicRecordTests.java | 59 +++++++++++++++---- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java index c0fcf4f566..3fa9973b24 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java @@ -47,15 +47,11 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent import org.alfresco.rest.rm.community.model.site.RMSite; import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.RMSiteAPI; -import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataUser; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; /** @@ -216,37 +212,4 @@ public class BaseRestTest extends RestTest return updatedComponent; } - /** - * Create RM user with given role - *
- * Checks whether the user exists in RM site and creates it if required, with password identical - * to username. Note the role is a Core API role, not an RM role. - *
- * For already existing users, no site membership or role verification is performed. - *

- * @param userName username to add - * @param userRole user's role - * @throws Exception - */ - public UserModel createRMUserWithRole(String userName, UserRole userRole) throws Exception - { - rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - String siteId = rmSiteAPI.getSite().getId(); - - // check if user exists - UserModel user = new UserModel(); - user.setUsername(userName); - user.setPassword(userName); - - if (!dataUser.isUserInRepo(userName)) - { - // user doesn't exist, create it - user = dataUser.createUser(userName, userName); - user.setUserRole(userRole); - - dataUser.addUserToSite(user, new SiteModel(siteId), userRole); - } - - return user; - } } \ No newline at end of file diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java index c556821f73..69c197ea90 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -40,7 +40,6 @@ import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.FORBIDDEN; -import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -51,8 +50,10 @@ import org.alfresco.rest.rm.community.base.BaseRestTest; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; +import org.alfresco.rest.rm.community.requests.RMSiteAPI; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.DataProvider; @@ -72,6 +73,9 @@ public class NonElectronicRecordTests extends BaseRestTest @Autowired private DataUser dataUser; + @Autowired + private RMSiteAPI rmSiteAPI; + /** Valid root containers where non-electronic records can be created */ @DataProvider(name = "validContainers") public Object[][] rootContainers() throws Exception { @@ -230,17 +234,12 @@ public class NonElectronicRecordTests extends BaseRestTest closeFolder(recordFolder.getId()); // try to create it, this should fail and throw an exception - try - { - filePlanComponentAPI.createFilePlanComponent( - new FilePlanComponent("Record " + getRandomAlphanumeric(), - NON_ELECTRONIC_RECORD_TYPE.toString(), - new FilePlanComponentProperties()), - recordFolder.getId()).getId(); - } - catch (Exception e) - { - } + + filePlanComponentAPI.createFilePlanComponent( + new FilePlanComponent("Record " + getRandomAlphanumeric(), + NON_ELECTRONIC_RECORD_TYPE.toString(), + new FilePlanComponentProperties()), + recordFolder.getId()).getId(); // verify the status code filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); @@ -332,7 +331,7 @@ public class NonElectronicRecordTests extends BaseRestTest public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception { String username = "zzzuser"; - UserModel user = createRMUserWithRole(username, UserRole.SiteConsumer); + UserModel user = createUserWithRole(username, UserRole.SiteManager); filePlanComponentAPI.usingRestWrapper().authenticateUser(user); @@ -379,4 +378,38 @@ public class NonElectronicRecordTests extends BaseRestTest // and return a folder underneath return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric()); } + + /** + * Create user with given role and add it to RM site + *
+ * Checks whether the user exists in RM site and creates it if required, with password identical + * to username. Note the role is a Core API role, not an RM role. + *
+ * For already existing users, no site membership or role verification is performed. + *

+ * @param userName username to add + * @param userRole user's role + * @throws Exception + */ + private UserModel createUserWithRole(String userName, UserRole userRole) throws Exception + { + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + String siteId = rmSiteAPI.getSite().getId(); + + // check if user exists + UserModel user = new UserModel(); + user.setUsername(userName); + user.setPassword(userName); + + if (!dataUser.isUserInRepo(userName)) + { + // user doesn't exist, create it + user = dataUser.createUser(userName, userName); + user.setUserRole(userRole); + + dataUser.addUserToSite(user, new SiteModel(siteId), userRole); + } + + return user; + } }