Merge branch 'master' of https://gitlab.alfresco.com/records-management/records-management into feature/RM-4361_ReadRecordsRestAPI

# Conflicts:
#	rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java
#	rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java
This commit is contained in:
Rodica Sutu
2017-01-03 17:48:23 +02:00
37 changed files with 1577 additions and 1244 deletions

View File

@@ -12,6 +12,7 @@
</parent> </parent>
<properties> <properties>
<maven.build.sourceVersion>1.8</maven.build.sourceVersion>
<alfresco.rm.share>alfresco-rm-community-share</alfresco.rm.share> <alfresco.rm.share>alfresco-rm-community-share</alfresco.rm.share>
<alfresco.rm.repo>alfresco-rm-community-repo</alfresco.rm.repo> <alfresco.rm.repo>alfresco-rm-community-repo</alfresco.rm.repo>
<tas.restapi.version>5.2.0-0</tas.restapi.version> <tas.restapi.version>5.2.0-0</tas.restapi.version>

View File

@@ -0,0 +1,88 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.core;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* Extends {@link RestProperties} to be able to change/add properties
*
* @author Tuna Aksoy
* @since 2.6
*/
@Configuration
@PropertySource(value = {"classpath:default.properties", "classpath:config.properties"})
@PropertySource(value = "classpath:module.properties", ignoreResourceNotFound = true)
@PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true)
public class RMRestProperties extends RestProperties
{
@Value ("${alfresco.scheme}")
private String scheme;
@Value ("${alfresco.server}")
private String server;
@Value ("${alfresco.port}")
private String port;
@Value ("${rest.rmPath}")
private String restRmPath;
/**
* @return the scheme
*/
public String getScheme()
{
return this.scheme;
}
/**
* @return the server
*/
public String getServer()
{
return this.server;
}
/**
* @return the port
*/
public String getPort()
{
return this.port;
}
/**
* @return the restRmPath
*/
public String getRestRmPath()
{
return this.restRmPath;
}
}

View File

@@ -0,0 +1,53 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.core;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
/**
* Extends {@link RestWrapper} in order to call IG APIs with our own properties
*
* @author Tuna Aksoy
* @since 2.6
*/
@Primary
@Service
@Scope(value = "prototype")
public class RMRestWrapper extends RestWrapper
{
@Autowired
private RMRestProperties rmRestProperties;
public RestIGCoreAPI withIGCoreAPI()
{
return new RestIGCoreAPI(this, rmRestProperties);
}
}

View File

@@ -0,0 +1,87 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.core;
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
/**
* REST API Factory Implementation
*
* @author Tuna Aksoy
* @since 2.6
*/
@Service
@Scope(value = "prototype")
public class RestAPIFactory
{
@Autowired
private DataUser dataUser;
@Autowired
private RMRestWrapper rmRestWrapper;
/**
* @return the rmRestWrapper
*/
public RMRestWrapper getRmRestWrapper()
{
return this.rmRestWrapper;
}
private RestIGCoreAPI getRestIGCoreAPI(UserModel userModel)
{
getRmRestWrapper().authenticateUser(userModel != null ? userModel : dataUser.getAdminUser());
return getRmRestWrapper().withIGCoreAPI();
}
public RMSiteAPI getRMSiteAPI()
{
return getRestIGCoreAPI(null).usingRMSite();
}
public RMSiteAPI getRMSiteAPI(UserModel userModel)
{
return getRestIGCoreAPI(userModel).usingRMSite();
}
public FilePlanComponentAPI getFilePlanComponentsAPI()
{
return getRestIGCoreAPI(null).usingFilePlanComponents();
}
public FilePlanComponentAPI getFilePlanComponentsAPI(UserModel userModel)
{
return getRestIGCoreAPI(userModel).usingFilePlanComponents();
}
}

View File

@@ -37,9 +37,12 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.utility.model.TestModel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
@@ -51,9 +54,10 @@ import lombok.NoArgsConstructor;
*/ */
@Builder @Builder
@Data @Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class FilePlanComponent public class FilePlanComponent extends TestModel
{ {
@JsonProperty (required = true) @JsonProperty (required = true)
private String id; private String id;
@@ -114,5 +118,4 @@ public class FilePlanComponent
@JsonProperty (value = RELATIVE_PATH) @JsonProperty (value = RELATIVE_PATH)
private String relativePath; private String relativePath;
} }

View File

@@ -26,58 +26,16 @@
*/ */
package org.alfresco.rest.rm.community.model.fileplancomponents; package org.alfresco.rest.rm.community.model.fileplancomponents;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString;
/** /**
* File plan component alias enumeration * File plan component alias
* *
* @author Tuna Aksoy * @author Tuna Aksoy
* @since 2.6 * @since 2.6
*/ */
public enum FilePlanComponentAlias public class FilePlanComponentAlias
{ {
FILE_PLAN_ALIAS("-filePlan-"), public static final String FILE_PLAN_ALIAS = "-filePlan-";
TRANSFERS_ALIAS("-transfers-"), public static final String TRANSFERS_ALIAS = "-transfers-";
UNFILED_RECORDS_CONTAINER_ALIAS("-unfiled-"), public static final String UNFILED_RECORDS_CONTAINER_ALIAS = "-unfiled-";
HOLDS_ALIAS("-holds-"); public static final String HOLDS_ALIAS = "-holds-";
private String alias;
private FilePlanComponentAlias(String alias)
{
this.alias = alias;
}
public static final FilePlanComponentAlias getFilePlanComponentAlias(String alias)
{
mandatoryString("alias", alias);
FilePlanComponentAlias result = null;
FilePlanComponentAlias[] values = values();
for (FilePlanComponentAlias filePlanComponentAlias : values)
{
if (filePlanComponentAlias.toString().equals(alias))
{
result = filePlanComponentAlias;
break;
}
}
if (result == null)
{
throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'.");
}
return result;
}
/**
* @see java.lang.Enum#toString()
*/
@Override
public String toString()
{
return this.alias;
}
} }

View File

@@ -35,6 +35,7 @@ import lombok.NoArgsConstructor;
/** /**
* POJO for FilePlanComponent content field * POJO for FilePlanComponent content field
*
* @author Kristijan Conkas * @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
@@ -55,5 +56,4 @@ public class FilePlanComponentContent
@JsonProperty (required = true) @JsonProperty (required = true)
private Integer sizeInBytes; private Integer sizeInBytes;
} }

View File

@@ -30,11 +30,13 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.rest.core.RestModels;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.alfresco.rest.core.RestModels;
/** /**
* POJO for file plan component entry * POJO for file plan component entry
@@ -44,11 +46,11 @@ import org.alfresco.rest.core.RestModels;
*/ */
@Builder @Builder
@Data @Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class FilePlanComponentEntry extends RestModels<FilePlanComponent, FilePlanComponentEntry> public class FilePlanComponentEntry extends RestModels<FilePlanComponent, FilePlanComponentEntry>
{ {
@JsonProperty(ENTRY) @JsonProperty(ENTRY)
FilePlanComponent filePlanComponent; FilePlanComponent filePlanComponentModel;
} }

View File

@@ -45,5 +45,4 @@ public class FilePlanComponentIdNamePair
{ {
public String id; public String id;
public String name; public String name;
} }

View File

@@ -37,7 +37,7 @@ import lombok.NoArgsConstructor;
/** /**
* POJO for FilePlanComponent path parameter * POJO for FilePlanComponent path parameter
* <br> *
* @author Kristijan Conkas * @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
@@ -51,5 +51,4 @@ public class FilePlanComponentPath
private String name; private String name;
private Boolean isComplete; private Boolean isComplete;
private List<FilePlanComponentIdNamePair> elements; private List<FilePlanComponentIdNamePair> elements;
} }

View File

@@ -67,7 +67,6 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
public class FilePlanComponentProperties public class FilePlanComponentProperties
{ {
@JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR) @JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR)
private Boolean vitalRecord; private Boolean vitalRecord;
@@ -85,28 +84,26 @@ public class FilePlanComponentProperties
@JsonProperty(PROPERTIES_REVIEW_PERIOD) @JsonProperty(PROPERTIES_REVIEW_PERIOD)
@JsonSerialize (using = ReviewPeriodSerializer.class) @JsonSerialize (using = ReviewPeriodSerializer.class)
private ReviewPeriod reviewPeriod; private FilePlanComponentReviewPeriod reviewPeriod;
@JsonProperty(PROPERTIES_LOCATION) @JsonProperty(PROPERTIES_LOCATION)
private String location; private String location;
@JsonProperty(value = PROPERTIES_IS_CLOSED, required = false) @JsonProperty(value = PROPERTIES_IS_CLOSED, required = false)
private Boolean isClosed; private Boolean isClosed;
@JsonProperty(value = PROPERTIES_BOX, required = false) @JsonProperty(value = PROPERTIES_BOX, required = false)
private String box; private String box;
@JsonProperty(value = PROPERTIES_FILE, required = false) @JsonProperty(value = PROPERTIES_FILE, required = false)
private String file; private String file;
@JsonProperty(value = PROPERTIES_SHELF, required = false) @JsonProperty(value = PROPERTIES_SHELF, required = false)
private String shelf; private String shelf;
@JsonProperty(value = PROPERTIES_NUMBER_OF_COPIES, required = false) @JsonProperty(value = PROPERTIES_NUMBER_OF_COPIES, required = false)
private Integer numberOfCopies; private Integer numberOfCopies;
@JsonProperty(value = PROPERTIES_PHYSICAL_SIZE, required = false) @JsonProperty(value = PROPERTIES_PHYSICAL_SIZE, required = false)
private Integer physicalSize; private Integer physicalSize;
} }

View File

@@ -32,7 +32,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* POJO for the review period * POJO for the file plan component review period
* *
* @author Rodica Sutu * @author Rodica Sutu
* @since 2.6 * @since 2.6
@@ -41,7 +41,7 @@ import lombok.NoArgsConstructor;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ReviewPeriod public class FilePlanComponentReviewPeriod
{ {
private String periodType; private String periodType;
private String expression; private String expression;

View File

@@ -26,66 +26,24 @@
*/ */
package org.alfresco.rest.rm.community.model.fileplancomponents; package org.alfresco.rest.rm.community.model.fileplancomponents;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString;
/** /**
* File plan component type enumeration * File plan component type
* *
* @author Tuna Aksoy * @author Tuna Aksoy
* @since 2.6 * @since 2.6
*/ */
public enum FilePlanComponentType public class FilePlanComponentType
{ {
FILE_PLAN_TYPE("rma:filePlan"), public static final String FILE_PLAN_TYPE = "rma:filePlan";
RECORD_CATEGORY_TYPE("rma:recordCategory"), public static final String RECORD_CATEGORY_TYPE = "rma:recordCategory";
RECORD_FOLDER_TYPE("rma:recordFolder"), public static final String RECORD_FOLDER_TYPE = "rma:recordFolder";
HOLD_TYPE("rma:hold"), public static final String HOLD_TYPE = "rma:hold";
UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder"), public static final String UNFILED_RECORD_FOLDER_TYPE = "rma:unfiledRecordFolder";
HOLD_CONTAINER_TYPE("rma:holdContainer"), public static final String HOLD_CONTAINER_TYPE = "rma:holdContainer";
TRANSFER_TYPE("rma:transfer"), public static final String TRANSFER_TYPE = "rma:transfer";
TRANSFER_CONTAINER_TYPE("rma:transferContainer"), public static final String TRANSFER_CONTAINER_TYPE = "rma:transferContainer";
UNFILED_CONTAINER_TYPE("rma:unfiledRecordContainer"), public static final String UNFILED_CONTAINER_TYPE = "rma:unfiledRecordContainer";
FOLDER_TYPE("cm:folder"), public static final String FOLDER_TYPE = "cm:folder";
CONTENT_TYPE("cm:content"), public static final String CONTENT_TYPE = "cm:content";
NON_ELECTRONIC_RECORD_TYPE("rma:nonElectronicDocument"); public static final String NON_ELECTRONIC_RECORD_TYPE = "rma:nonElectronicDocument";
private String type;
private FilePlanComponentType(String type)
{
this.type = type;
}
public static final FilePlanComponentType getFilePlanComponentType(String type)
{
mandatoryString("type", type);
FilePlanComponentType result = null;
FilePlanComponentType[] values = values();
for (FilePlanComponentType filePlanComponentType : values)
{
if (filePlanComponentType.toString().equals(filePlanComponentType))
{
result = filePlanComponentType;
break;
}
}
if (result == null)
{
throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'.");
}
return result;
}
/**
* @see java.lang.Enum#toString()
*/
@Override
public String toString()
{
return this.type;
}
} }

View File

@@ -45,5 +45,4 @@ public class FilePlanComponentUserInfo
{ {
private String id; private String id;
private String displayName; private String displayName;
} }

View File

@@ -30,11 +30,13 @@ import static org.alfresco.rest.rm.community.model.site.RMSiteFields.COMPLIANCE;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.rest.model.RestSiteModel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.alfresco.rest.model.RestSiteModel;
/** /**
* POJO for RM Site component * POJO for RM Site component
@@ -44,11 +46,11 @@ import org.alfresco.rest.model.RestSiteModel;
*/ */
@Builder @Builder
@Data @Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class RMSite extends RestSiteModel public class RMSite extends RestSiteModel
{ {
@JsonProperty (value = COMPLIANCE,required = true) @JsonProperty (value = COMPLIANCE, required = true)
private RMSiteCompliance compliance; private RMSiteCompliance compliance;
} }

View File

@@ -0,0 +1,58 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.requests;
import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.requests.ModelRequest;
/**
* Extends {@link ModelRequest} to set {@link RMRestWrapper}
*
* @author Tuna Aksoy
* @since 2.6
*/
public abstract class RMModelRequest extends ModelRequest
{
private RMRestWrapper rmRestWrapper;
/**
* @return the rmRestWrapper
*/
protected RMRestWrapper getRMRestWrapper()
{
return this.rmRestWrapper;
}
/**
* @param restWrapper
*/
public RMModelRequest(RMRestWrapper rmRestWrapper)
{
super(rmRestWrapper);
this.rmRestWrapper = rmRestWrapper;
}
}

View File

@@ -24,16 +24,18 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.rm.community.requests; package org.alfresco.rest.rm.community.requests.igCoreAPI;
import static com.jayway.restassured.RestAssured.basic; import static com.jayway.restassured.RestAssured.basic;
import static com.jayway.restassured.RestAssured.given; import static com.jayway.restassured.RestAssured.given;
import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest; import static org.alfresco.rest.core.RestRequest.simpleRequest;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject; import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryObject;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString; import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString;
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.springframework.http.HttpMethod.DELETE; import static org.springframework.http.HttpMethod.DELETE;
import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpMethod.POST;
@@ -50,25 +52,30 @@ import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.http.ContentType; import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response; import com.jayway.restassured.response.Response;
import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.RMModelRequest;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/** /**
* File plan component REST API Wrapper * File plan component REST API Wrapper
* *
* @author Tuna Aksoy * @author Tuna Aksoy
* @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
@Component public class FilePlanComponentAPI extends RMModelRequest
@Scope(value = "prototype")
public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{ {
/**
* Constructor
*
* @param restWrapper
*/
public FilePlanComponentAPI(RMRestWrapper rmRestWrapper)
{
super(rmRestWrapper);
}
/** /**
* Get a file plan component * Get a file plan component
* *
@@ -85,10 +92,31 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{ {
mandatoryString("filePlanComponentId", filePlanComponentId); mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModel(FilePlanComponent.class, simpleRequest( return getFilePlanComponent(filePlanComponentId, EMPTY);
}
/**
* Get a file plan component
*
* @param filePlanComponentId The id of the file plan component to get
* @param parameters The URL parameters to add
* @return The {@link FilePlanComponent} for the given file plan component id
* @throws Exception for the following cases:
* <ul>
* <li>{@code fileplanComponentId} is not a valid format</li>
* <li>authentication fails</li>
* <li>{@code fileplanComponentId} does not exist</li>
* </ul>
*/
public FilePlanComponent getFilePlanComponent(String filePlanComponentId, String parameters) throws Exception
{
mandatoryString("filePlanComponentId", filePlanComponentId);
return getRMRestWrapper().processModel(FilePlanComponent.class, simpleRequest(
GET, GET,
"fileplan-components/{fileplanComponentId}?{parameters}", "fileplan-components/{fileplanComponentId}?{parameters}",
filePlanComponentId, getParameters() filePlanComponentId,
parameters
)); ));
} }
@@ -108,7 +136,7 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{ {
mandatoryString("filePlanComponentId", filePlanComponentId); mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest( return getRMRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest(
GET, GET,
"fileplan-components/{fileplanComponentId}/children?{parameters}", "fileplan-components/{fileplanComponentId}/children?{parameters}",
filePlanComponentId, getParameters() filePlanComponentId, getParameters()
@@ -135,15 +163,41 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{ {
mandatoryObject("filePlanComponentProperties", filePlanComponentModel); mandatoryObject("filePlanComponentProperties", filePlanComponentModel);
mandatoryString("parentId", parentId); mandatoryString("parentId", parentId);
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody( return createFilePlanComponent(filePlanComponentModel, parentId, EMPTY);
POST,
toJson(filePlanComponentModel),
"fileplan-components/{fileplanComponentId}/children?{parameters}",
parentId,
getParameters()));
} }
/**
* Creates a file plan component with the given properties under the parent node with the given id
*
* @param filePlanComponentModel The properties of the file plan component to be created
* @param parameters The URL parameters to add
* @param parentId The id of the parent where the new file plan component should be created
* @return The {@link FilePlanComponent} with the given properties
* @throws Exception for the following cases:
* <ul>
* <li>{@code fileplanComponentId} is not a valid format</li>
* <li>authentication fails</li>
* <li>current user does not have permission to add children to {@code fileplanComponentId}</li>
* <li>{@code fileplanComponentId} does not exist</li>
* <li>new name clashes with an existing node in the current parent container</li>
* <li>model integrity exception, including node name with invalid characters</li>
* </ul>
*/
public FilePlanComponent createFilePlanComponent(FilePlanComponent filePlanComponentModel, String parentId, String parameters) throws Exception
{
mandatoryObject("filePlanComponentProperties", filePlanComponentModel);
mandatoryString("parentId", parentId);
return getRMRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
POST,
toJson(filePlanComponentModel),
"fileplan-components/{fileplanComponentId}/children?{parameters}",
parentId,
parameters
));
}
/** /**
* Create electronic record from file resource * Create electronic record from file resource
* @param electronicRecordModel {@link FilePlanComponent} for electronic record to be created * @param electronicRecordModel {@link FilePlanComponent} for electronic record to be created
@@ -156,7 +210,7 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{ {
return createElectronicRecord(electronicRecordModel, new File(Resources.getResource(fileName).getFile()), parentId); return createElectronicRecord(electronicRecordModel, new File(Resources.getResource(fileName).getFile()), parentId);
} }
/** /**
* Create electronic record from file resource * Create electronic record from file resource
* @param electronicRecordModel {@link FilePlanComponent} for electronic record to be created * @param electronicRecordModel {@link FilePlanComponent} for electronic record to be created
@@ -167,53 +221,42 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
*/ */
public FilePlanComponent createElectronicRecord(FilePlanComponent electronicRecordModel, File recordContent, String parentId) throws Exception public FilePlanComponent createElectronicRecord(FilePlanComponent electronicRecordModel, File recordContent, String parentId) throws Exception
{ {
mandatoryObject("filePlanComponentProperties", electronicRecordModel); mandatoryObject("electronicRecordModel", electronicRecordModel);
mandatoryString("parentId", parentId); mandatoryString("parentId", parentId);
if (!electronicRecordModel.getNodeType().equals(FilePlanComponentType.CONTENT_TYPE.toString())) if (!electronicRecordModel.getNodeType().equals(CONTENT_TYPE))
{ {
fail("Only electronic records are supported"); fail("Only electronic records are supported");
} }
UserModel currentUser = usingRestWrapper().getTestUser(); UserModel currentUser = getRMRestWrapper().getTestUser();
/* /*
* For file uploads nodeBodyCreate is ignored hence can't be used. Append all FilePlanComponent fields * For file uploads nodeBodyCreate is ignored hence can't be used. Append all FilePlanComponent fields
* to the request. * to the request.
*/ */
RequestSpecBuilder builder = new RequestSpecBuilder(); RequestSpecBuilder builder = new RequestSpecBuilder();
builder.setAuth(basic(currentUser.getUsername(), currentUser.getPassword())); builder.setAuth(basic(currentUser.getUsername(), currentUser.getPassword()));
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(toJson(electronicRecordModel)); JsonNode root = mapper.readTree(toJson(electronicRecordModel));
Iterator<String> fieldNames = root.fieldNames(); Iterator<String> fieldNames = root.fieldNames();
while (fieldNames.hasNext()) while (fieldNames.hasNext())
{ {
String f = fieldNames.next(); String fieldName = fieldNames.next();
try builder.addMultiPart(fieldName, root.get(fieldName).asText(), ContentType.JSON.name());
{
builder.addMultiPart(f, root.get(f).asText(), ContentType.JSON.name());
}
catch (Exception error)
{
LOG.error("Failed to set " + f + " error: " + error);
}
} }
builder.addMultiPart("filedata", recordContent, ContentType.BINARY.name()); builder.addMultiPart("filedata", recordContent, ContentType.BINARY.name());
/*
* RestWrapper adds some headers which break multipart/form-data uploads and also assumes json POST requests.
* Upload the file using RestAssured library. * Upload the file using RestAssured library.
*/ */
Response response = given() Response response = given()
.spec(builder.build()) .spec(builder.build())
.when() .when()
.post("fileplan-components/{fileplanComponentId}/children?{parameters}", parentId, getParameters()) .post("fileplan-components/{fileplanComponentId}/children?{parameters}", parentId, getRMRestWrapper().getParameters())
.andReturn(); .andReturn();
usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); getRMRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
LOG.info("electronic record created: " + response.getBody().prettyPrint());
/* return a FilePlanComponent object representing Response */ /* return a FilePlanComponent object representing Response */
return response.jsonPath().getObject("entry", FilePlanComponent.class); return response.jsonPath().getObject("entry", FilePlanComponent.class);
} }
@@ -221,7 +264,7 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
/** /**
* Updates a file plan component * Updates a file plan component
* *
* @param filePlanComponent The properties to be updated * @param filePlanComponentModel The properties to be updated
* @param filePlanComponentId The id of the file plan component which will be updated * @param filePlanComponentId The id of the file plan component which will be updated
* @param returns The updated {@link FilePlanComponent} * @param returns The updated {@link FilePlanComponent}
* @throws Exception for the following cases: * @throws Exception for the following cases:
@@ -234,17 +277,42 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
* <li>model integrity exception, including node name with invalid characters</li> * <li>model integrity exception, including node name with invalid characters</li>
* </ul> * </ul>
*/ */
public FilePlanComponent updateFilePlanComponent(FilePlanComponent filePlanComponent, String filePlanComponentId) throws Exception public FilePlanComponent updateFilePlanComponent(FilePlanComponent filePlanComponentModel, String filePlanComponentId) throws Exception
{
mandatoryObject("filePlanComponentProperties", filePlanComponentModel);
mandatoryString("filePlanComponentId", filePlanComponentId);
return updateFilePlanComponent(filePlanComponentModel, filePlanComponentId, EMPTY);
}
/**
* Updates a file plan component
*
* @param filePlanComponentModel The properties to be updated
* @param parameters The URL parameters to add
* @param filePlanComponentId The id of the file plan component which will be updated
* @param returns The updated {@link FilePlanComponent}
* @throws Exception for the following cases:
* <ul>
* <li>the update request is invalid or {@code fileplanComponentId} is not a valid format or {@code filePlanComponentProperties} is invalid</li>
* <li>authentication fails</li>
* <li>current user does not have permission to update {@code fileplanComponentId}</li>
* <li>{@code fileplanComponentId} does not exist</li>
* <li>the updated name clashes with an existing node in the current parent folder</li>
* <li>model integrity exception, including node name with invalid characters</li>
* </ul>
*/
public FilePlanComponent updateFilePlanComponent(FilePlanComponent filePlanComponent, String filePlanComponentId, String parameters) throws Exception
{ {
mandatoryObject("filePlanComponentProperties", filePlanComponent); mandatoryObject("filePlanComponentProperties", filePlanComponent);
mandatoryString("filePlanComponentId", filePlanComponentId); mandatoryString("filePlanComponentId", filePlanComponentId);
return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody( return getRMRestWrapper().processModel(FilePlanComponent.class, requestWithBody(
PUT, PUT,
toJson(filePlanComponent), toJson(filePlanComponent),
"fileplan-components/{fileplanComponentId}?{parameters}", "fileplan-components/{fileplanComponentId}?{parameters}",
filePlanComponentId, filePlanComponentId,
getParameters() parameters
)); ));
} }
@@ -265,11 +333,10 @@ public class FilePlanComponentAPI extends RestAPI<FilePlanComponentAPI>
{ {
mandatoryString("filePlanComponentId", filePlanComponentId); mandatoryString("filePlanComponentId", filePlanComponentId);
usingRestWrapper().processEmptyModel(simpleRequest( getRMRestWrapper().processEmptyModel(simpleRequest(
DELETE, DELETE,
"fileplan-components/{fileplanComponentId}", "fileplan-components/{fileplanComponentId}",
filePlanComponentId filePlanComponentId
)); ));
} }
} }

View File

@@ -24,7 +24,7 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.rm.community.requests; package org.alfresco.rest.rm.community.requests.igCoreAPI;
import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.requestWithBody;
import static org.alfresco.rest.core.RestRequest.simpleRequest; import static org.alfresco.rest.core.RestRequest.simpleRequest;
@@ -36,26 +36,27 @@ import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.PUT; import static org.springframework.http.HttpMethod.PUT;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.rm.community.model.site.RMSite; import org.alfresco.rest.rm.community.model.site.RMSite;
import org.alfresco.utility.data.DataUser; import org.alfresco.rest.rm.community.requests.RMModelRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/** /**
* File plan component REST API Wrapper * RM Site REST API Wrapper
* *
* @author Tuna Aksoy * @author Tuna Aksoy
* @author Rodica Sutu
* @since 2.6 * @since 2.6
*/ */
@Component public class RMSiteAPI extends RMModelRequest
@Scope (value = "prototype")
public class RMSiteAPI extends RestAPI<RMSiteAPI>
{ {
@Autowired /**
private DataUser dataUser; * Constructor
*
* @param rmRestWrapper RM REST Wrapper
*/
public RMSiteAPI(RMRestWrapper rmRestWrapper)
{
super(rmRestWrapper);
}
/** /**
* Get the RM site * Get the RM site
@@ -71,7 +72,7 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
*/ */
public RMSite getSite() throws Exception public RMSite getSite() throws Exception
{ {
return usingRestWrapper().processModel(RMSite.class, simpleRequest( return getRMRestWrapper().processModel(RMSite.class, simpleRequest(
GET, GET,
"ig-sites/rm" "ig-sites/rm"
)); ));
@@ -90,13 +91,13 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
* <li>Api Response code default Unexpected error</li> * <li>Api Response code default Unexpected error</li>
* </ul> * </ul>
*/ */
public RMSite createRMSite(RMSite rmSite) throws Exception public RMSite createRMSite(RMSite rmSiteModel) throws Exception
{ {
mandatoryObject("rmSiteProperties", rmSite); mandatoryObject("rmSiteModel", rmSiteModel);
return usingRestWrapper().processModel(RMSite.class, requestWithBody( return getRMRestWrapper().processModel(RMSite.class, requestWithBody(
POST, POST,
toJson(rmSite), toJson(rmSiteModel),
"ig-sites" "ig-sites"
)); ));
} }
@@ -114,7 +115,7 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
*/ */
public void deleteRMSite() throws Exception public void deleteRMSite() throws Exception
{ {
usingRestWrapper().processEmptyModel(simpleRequest( getRMRestWrapper().processEmptyModel(simpleRequest(
DELETE, DELETE,
"ig-sites/rm" "ig-sites/rm"
)); ));
@@ -127,20 +128,20 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
* @return The updated {@link RMSite} * @return The updated {@link RMSite}
* @throws Exception for the following cases: * @throws Exception for the following cases:
* <ul> * <ul>
* <li>Api Response code 400 the update request is invalid {@code rmSiteProperties} is invalid</li> * <li>Api Response code 400 the update request is invalid {@code rmSiteModel} is invalid</li>
* <li>Api Response code 401 If authentication fails</li> * <li>Api Response code 401 If authentication fails</li>
* <li>Api Response code 403 does not have permission to update {@code RMSite}</li> * <li>Api Response code 403 does not have permission to update {@code RMSite}</li>
* <li>Api Response code 404 {@code RMSite} does not exist</li> * <li>Api Response code 404 {@code RMSiteModel} does not exist</li>
* <li>Api Response code default Unexpected error,model integrity exception</li> * <li>Api Response code default Unexpected error,model integrity exception</li>
* </ul> * </ul>
*/ */
public RMSite updateRMSite(RMSite rmSiteProperties) throws Exception public RMSite updateRMSite(RMSite rmSiteModel) throws Exception
{ {
mandatoryObject("rmSiteProperties", rmSiteProperties); mandatoryObject("rmSiteProperties", rmSiteModel);
return usingRestWrapper().processModel(RMSite.class, requestWithBody( return getRMRestWrapper().processModel(RMSite.class, requestWithBody(
PUT, PUT,
toJson(rmSiteProperties), toJson(rmSiteModel),
"ig-sites/rm" "ig-sites/rm"
)); ));
} }
@@ -159,8 +160,7 @@ public class RMSiteAPI extends RestAPI<RMSiteAPI>
*/ */
public boolean existsRMSite() throws Exception public boolean existsRMSite() throws Exception
{ {
usingRestWrapper().authenticateUser(dataUser.getAdminUser());
getSite(); getSite();
return usingRestWrapper().getStatusCode().equals(OK.toString()); return getRMRestWrapper().getStatusCode().equals(OK.toString());
} }
} }

View File

@@ -24,52 +24,62 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.rm.community.requests; package org.alfresco.rest.rm.community.requests.igCoreAPI;
import static com.jayway.restassured.RestAssured.given; import static com.jayway.restassured.RestAssured.given;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import com.google.gson.JsonObject;
import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response; import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.RequestSpecification;
import org.alfresco.dataprep.AlfrescoHttpClient; import org.alfresco.dataprep.AlfrescoHttpClient;
import org.alfresco.dataprep.AlfrescoHttpClientFactory; import org.alfresco.dataprep.AlfrescoHttpClientFactory;
import org.alfresco.dataprep.UserService;
import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RestAPI;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.utility.data.DataUser; 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.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* RM user management API * RM user management API
* *
* @author Kristijan Conkas * @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
// FIXME: As of December 2016 there is no v1-style API for managing RM users and users' // FIXME: As of December 2016 there is no v1-style API for managing RM users and users'
// roles. Until such APIs have become available, methods in this class are just proxies to // roles/permissions. Until such APIs have become available, methods in this class are just proxies to
// "old-style" API calls. // "old-style" API calls.
@Component @Component
@Scope (value = "prototype") @Scope (value = "prototype")
public class RMUserAPI extends RestAPI<RMUserAPI> public class RMUserAPI extends RestAPI<RMUserAPI>
{ {
@Autowired
private UserService userService;
@Autowired @Autowired
private DataUser dataUser; private DataUser dataUser;
@Autowired @Autowired
private AlfrescoHttpClientFactory alfrescoHttpClientFactory; private AlfrescoHttpClientFactory alfrescoHttpClientFactory;
public void assignRoleToUser(String userName, String userRole) throws Exception public void assignRoleToUser(String userName, String userRole) throws Exception
{ {
// get an "old-style" REST API client // get an "old-style" REST API client
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
// override v1 baseURI and basePath // override v1 baseURI and basePath
RequestSpecification spec = new RequestSpecBuilder() RequestSpecification spec = new RequestSpecBuilder()
.setBaseUri(client.getApiUrl()) .setBaseUri(client.getApiUrl())
.setBasePath("/") .setBasePath("/")
.build(); .build();
Response response = given() Response response = given()
.spec(spec) .spec(spec)
.log().all() .log().all()
@@ -83,4 +93,61 @@ public class RMUserAPI extends RestAPI<RMUserAPI>
.andReturn(); .andReturn();
usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
} }
/**
* Helper method to add permission on a component to user
* @param component {@link FilePlanComponent} on which permission should be given
* @param user {@link UserModel} for a user to be granted permission
* @param permission {@link UserPermissions} to be granted
*/
public void addUserPermission(FilePlanComponent component, UserModel user, String permission)
{
// get an "old-style" REST API client
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
JsonObject bodyJson = buildObject()
.addArray("permissions")
.addObject()
.add("authority", user.getUsername())
.add("role", permission)
.end()
.getJson();
// override v1 baseURI and basePath
RequestSpecification spec = new RequestSpecBuilder()
.setBaseUri(client.getApiUrl())
.setBasePath("/")
.build();
// execute an "old-style" API call
Response response = given()
.spec(spec)
.auth().basic(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword())
.contentType(ContentType.JSON)
.body(bodyJson.toString())
.pathParam("nodeId", component.getId())
.log().all()
.when()
.post("/node/workspace/SpacesStore/{nodeId}/rmpermissions")
.prettyPeek()
.andReturn();
usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
}
/**
* Creates a user with the given name using the old APIs
*
* @param userName The user name
* @return <code>true</code> if the user was created successfully, <code>false</code> otherwise.
*/
public boolean createUser(String userName)
{
return userService.create(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(),
userName,
"password",
"default@alfresco.com",
userName,
userName);
}
} }

View File

@@ -0,0 +1,80 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.requests.igCoreAPI;
import static java.lang.Integer.parseInt;
import static java.lang.String.format;
import com.jayway.restassured.RestAssured;
import org.alfresco.rest.core.RMRestProperties;
import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.rm.community.requests.RMModelRequest;
/**
* Defines the entire IG Core API
* {@link http://host:port/ig-api-explorer} select "IG Core API"
*
* @author Tuna Aksoy
* @since 2.6
*/
public class RestIGCoreAPI extends RMModelRequest
{
/**
* Constructor
*
* @param rmRestWrapper RM REST Wrapper
* @param rmRestProperties RM REST Properties
*/
public RestIGCoreAPI(RMRestWrapper rmRestWrapper, RMRestProperties rmRestProperties)
{
super(rmRestWrapper);
RestAssured.baseURI = format("%s://%s", rmRestProperties.getScheme(), rmRestProperties.getServer());
RestAssured.port = parseInt(rmRestProperties.getPort());
RestAssured.basePath = rmRestProperties.getRestRmPath();
}
/**
* Provides DSL on all REST calls under <code>ig-sites/rm/...</code> API path
*
* @return {@link RMSiteAPI}
*/
public RMSiteAPI usingRMSite()
{
return new RMSiteAPI(getRMRestWrapper());
}
/**
* Provides DSL on all REST calls under <code>fileplan-components/...</code> API path
*
* @return {@link FilePlanComponentAPI}
*/
public FilePlanComponentAPI usingFilePlanComponents()
{
return new FilePlanComponentAPI(getRMRestWrapper());
}
}

View File

@@ -57,7 +57,6 @@ public class PojoUtility
{ {
//return the json object //return the json object
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model);
} }
catch (JsonGenerationException e) catch (JsonGenerationException e)
{ {

View File

@@ -33,8 +33,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import org.alfresco.rest.rm.community.model.fileplancomponents.ReviewPeriod; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentReviewPeriod;
/** /**
* Utility class for serializing the Review Period type * Utility class for serializing the Review Period type
@@ -42,9 +41,8 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.ReviewPeriod;
* @author Rodica Sutu * @author Rodica Sutu
* @since 2.6 * @since 2.6
*/ */
public class ReviewPeriodSerializer extends JsonSerializer<ReviewPeriod> public class ReviewPeriodSerializer extends JsonSerializer<FilePlanComponentReviewPeriod>
{ {
/** /**
* @param value The Review Period value that is being serialized. * @param value The Review Period value that is being serialized.
* @param gen Jackson utility is responsible for writing JSON * @param gen Jackson utility is responsible for writing JSON
@@ -53,12 +51,9 @@ public class ReviewPeriodSerializer extends JsonSerializer<ReviewPeriod>
* @throws JsonProcessingException * @throws JsonProcessingException
*/ */
@Override @Override
public void serialize(ReviewPeriod value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException public void serialize(FilePlanComponentReviewPeriod value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException
{ {
//create the custom string value for the Review Period type //create the custom string value for the Review Period type
gen.writeString(new StringBuilder().append(value.getPeriodType()).append("|").append(value.getExpression()).toString()); gen.writeString(new StringBuilder().append(value.getPeriodType()).append("|").append(value.getExpression()).toString());
} }
} }

View File

@@ -0,0 +1,356 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.base;
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_TITLE;
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_TITLE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_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.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createFilePlanComponentModel;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createStandardRMSiteModel;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestAPIFactory;
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.igCoreAPI.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
/**
* Base class for all IG REST API Tests
*
* @author Kristijan Conkas
* @author Tuna Aksoy
* @since 2.6
*/
public class BaseRMRestTest extends RestTest
{
@Autowired
private RestAPIFactory restAPIFactory;
@Autowired
private DataUser dataUser;
/**
* Gets the REST API Factory
*
* @return the restAPIFactory The REST API Factory
*/
protected RestAPIFactory getRestAPIFactory()
{
return this.restAPIFactory;
}
/**
* Gets the data user
*
* @return the dataUser The data user
*/
protected DataUser getDataUser()
{
return this.dataUser;
}
/**
* Asserts the given status code
*
* @param statusCode The status code to assert
*/
protected void assertStatusCode(HttpStatus statusCode)
{
getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(statusCode);
}
/**
* Gets the admin user
*
* @return The admin user
*/
protected UserModel getAdminUser()
{
return getDataUser().getAdminUser();
}
/** Valid root containers where electronic and non-electronic records can be created */
@DataProvider(name = "validRootContainers")
public Object[][] getValidRootContainers() throws Exception
{
return new Object[][]
{
// an arbitrary record folder
{ createCategoryFolderInFilePlan() },
// unfiled records root
{ getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS) },
// an arbitrary unfiled records folder
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric()) }
};
}
/**
* @see org.alfresco.rest.RestTest#checkServerHealth()
*/
@Override
@BeforeClass (alwaysRun = true)
public void checkServerHealth() throws Exception
{
// Create RM Site if not exist
createRMSiteIfNotExists();
}
/**
* Helper method to create the RM Site via the POST request
* if the site doesn't exist
*/
public void createRMSiteIfNotExists() throws Exception
{
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
// Check RM site doesn't exist
if (!rmSiteAPI.existsRMSite())
{
// Create the RM site
rmSiteAPI.createRMSite(createStandardRMSiteModel());
// Verify the status code
assertStatusCode(CREATED);
}
}
/**
* Helper method to create child category
*
* @param user The user under whose privileges this structure is going to be created
* @param parentCategoryId The id of the parent category
* @param categoryName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(UserModel user, String parentCategoryId, String categoryName) throws Exception
{
return createComponent(user, parentCategoryId, categoryName, RECORD_CATEGORY_TYPE, CATEGORY_TITLE);
}
/**
* Helper method to create child category as the admin user
*
* @param parentCategoryId The id of the parent category
* @param categoryName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createCategory(getAdminUser(), parentCategoryId, categoryName);
}
/**
* Helper method to create child folder
*
* @param user The user under whose privileges this structure is going to be created
* @param parentCategoryId The id of the parent category
* @param folderName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createFolder(UserModel user, String parentCategoryId, String folderName) throws Exception
{
return createComponent(user, parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
/**
* Helper method to create child folder as the admin user
*
* @param parentCategoryId The id of the parent category
* @param folderName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createFolder(String parentCategoryId, String folderName) throws Exception
{
return createFolder(getAdminUser(), parentCategoryId, folderName);
}
/**
* Helper method to create child unfiled record folder
*
* @param user The user under whose privileges this structure is going to be created
* @param parentId The id of the parent folder
* @param folderName The name of the folder
* @return The created folder
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createUnfiledRecordsFolder(UserModel user, String parentId, String folderName) throws Exception
{
return createComponent(user, parentId, folderName, UNFILED_RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
/**
* Helper method to create child unfiled record folder as the admin user
*
* @param parentId The id of the parent folder
* @param folderName The name of the folder
* @return The created folder
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createUnfiledRecordsFolder(String parentId, String folderName) throws Exception
{
return createUnfiledRecordsFolder(getAdminUser(), parentId, folderName);
}
/**
* Helper method to create generic child component
*
* @param user user under whose privileges this structure is going to be created
* @param parentComponentId The id of the parent file plan component
* @param componentName The name of the file plan component
* @param componentType The type of the file plan component
* @param componentTitle The title of the file plan component
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(UserModel user, String parentComponentId, String componentName, String componentType, String componentTitle) throws Exception
{
FilePlanComponent filePlanComponentModel = createFilePlanComponentModel(componentName, componentType, componentTitle);
FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI(user).createFilePlanComponent(filePlanComponentModel, parentComponentId);
assertStatusCode(CREATED);
return filePlanComponent;
}
/**
* Helper method to close folder
*
* @param folderId The id of the folder
* @return The closed folder
* @throws Exception
*/
protected FilePlanComponent closeFolder(String folderId) throws Exception
{
// build file plan component + properties for update request
FilePlanComponentProperties properties = new FilePlanComponentProperties();
properties.setIsClosed(true);
FilePlanComponent filePlanComponent = new FilePlanComponent();
filePlanComponent.setProperties(properties);
FilePlanComponent updatedComponent = getRestAPIFactory().getFilePlanComponentsAPI().updateFilePlanComponent(filePlanComponent, folderId);
assertStatusCode(OK);
return updatedComponent;
}
/**
* Helper method to create a randomly-named <category>/<folder> structure in file plan
*
* @param user The user under whose privileges this structure is going to be created
* @param parentId parent container id
* @return record folder
* @throws Exception on failed creation
*/
public FilePlanComponent createCategoryFolderInFilePlan(UserModel user) throws Exception
{
// create root category
FilePlanComponent recordCategory = createCategory(user, FILE_PLAN_ALIAS, "Category " + getRandomAlphanumeric());
// and return a folder underneath
return createFolder(user, recordCategory.getId(), "Folder " + getRandomAlphanumeric());
}
/**
* Helper method to create a randomly-named <category>/<folder> structure in file plan as the admin user
*
* @param parentId parent container id
* @return record folder
* @throws Exception on failed creation
*/
public FilePlanComponent createCategoryFolderInFilePlan() throws Exception
{
return createCategoryFolderInFilePlan(getAdminUser());
}
/**
* Helper method to retrieve a file plan component with user's privilege
*
* @param user user under whose privileges a component is to be read
* @param componentId id of the component to read
* @return {@link FilePlanComponent} for given componentId
* @throws Exception if user doesn't have sufficient privileges
*/
public FilePlanComponent getFilePlanComponentAsUser(UserModel user, String componentId) throws Exception
{
return getRestAPIFactory().getFilePlanComponentsAPI(user).getFilePlanComponent(componentId);
}
/**
* Helper method to retrieve a file plan component with user's privilege as the admin user
*
* @param componentId id of the component to read
* @return {@link FilePlanComponent} for given componentId
* @throws Exception if user doesn't have sufficient privileges
*/
public FilePlanComponent getFilePlanComponent(String componentId) throws Exception
{
return getFilePlanComponentAsUser(getAdminUser(), componentId);
}
/**
* Create temp file with content
*
* @param name file name
* @return {@link File} file
*/
public static File createTempFile(final String name,String content)
{
try
{
// create file
final File file = File.createTempFile(name, ".txt");
// create writer
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, Charset.forName("UTF-8").newEncoder()))
{
// place content in file
writer.write(content);
}
return file;
} catch (Exception exception)
{
throw new RuntimeException("Unable to create test file.", exception);
}
}
}

View File

@@ -1,362 +0,0 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.base;
import static java.lang.Integer.parseInt;
import static com.jayway.restassured.RestAssured.given;
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_TITLE;
import static org.alfresco.rest.rm.community.base.TestData.FOLDER_TITLE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_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.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
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.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import com.google.gson.JsonObject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
import org.alfresco.dataprep.AlfrescoHttpClient;
import org.alfresco.dataprep.AlfrescoHttpClientFactory;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
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.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.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
/**
* Base class for all IG REST API Tests
*
* @author Kristijan Conkas
* @author Tuna Aksoy
* @since 2.6
*/
@Configuration
@PropertySource(value = {"classpath:default.properties", "classpath:config.properties"})
@PropertySource(value = "classpath:module.properties", ignoreResourceNotFound = true)
@PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true)
public class BaseRestTest extends RestTest
{
@Value ("${alfresco.scheme}")
private String scheme;
@Value ("${alfresco.server}")
private String server;
@Value ("${alfresco.port}")
private String port;
@Value ("${rest.rmPath}")
private String restRmPath;
@Value ("${rest.basePath}")
private String restCorePath;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
@Autowired
public FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private AlfrescoHttpClientFactory alfrescoHttpClientFactory;
// Constants
public static final String RM_ID = "rm";
public static final String RM_TITLE = "Records Management";
public static final String RM_DESCRIPTION = "Records Management Site";
/** Valid root containers where electronic and non-electronic records can be created */
@DataProvider(name = "validRootContainers")
public Object[][] getValidRootContainers() throws Exception {
return new Object[][] {
// an arbitrary record folder
{ createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) },
// unfiled records root
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), UNFILED_RECORDS_CONTAINER_ALIAS.toString()) },
// an arbitrary unfiled records folder
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()) }
};
}
/**
* @see org.alfresco.rest.RestTest#checkServerHealth()
*/
@Override
@BeforeClass (alwaysRun = true)
public void checkServerHealth() throws Exception
{
RestAssured.baseURI = scheme + "://" + server;
RestAssured.port = parseInt(port);
RestAssured.basePath = restRmPath;
// Create RM Site if not exist
createRMSiteIfNotExists();
}
/**
* Helper method to create the RM Site via the POST request
* if the site doesn't exist
*/
public void createRMSiteIfNotExists() throws Exception
{
// Check RM site doesn't exist
if (!rmSiteAPI.existsRMSite())
{
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the RM site
RMSite rmSite = RMSite.builder().compliance(STANDARD).build();
rmSite.setTitle(RM_TITLE);
rmSite.setDescription(RM_DESCRIPTION);
rmSiteAPI.createRMSite(rmSite);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
}
}
/**
* Helper method to create child category
*
* @param parentCategoryId The id of the parent category
* @param categoryName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE, CATEGORY_TITLE);
}
/**
* Helper method to create child folder
*
* @param parentCategoryId The id of the parent category
* @param folderName The name of the category
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createFolder(String parentCategoryId, String folderName) throws Exception
{
return createComponent(parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
/**
* Helper method to create child unfiled record folder
*
* @param parentId The id of the parent folder
* @param folderName The name of the folder
* @return The created folder
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createUnfiledRecordsFolder(String parentId, String folderName) throws Exception
{
return createComponent(parentId, folderName, UNFILED_RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
/**
* Helper method to create generic child component
*
* @param parentComponentId The id of the parent file plan component
* @param componentName The name of the file plan component
* @param componentType The name of the file plan component
* @param componentTitle
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType, String componentTitle) throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
.name(componentName)
.nodeType(componentType.toString())
.properties(FilePlanComponentProperties.builder()
.title(componentTitle)
.build())
.build();
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(filePlanComponent, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
return fpc;
}
/**
* Helper method to close folder
* @param folderId
* @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;
}
/**
* Helper method to create a randomly-named <category>/<folder> structure in fileplan
* @param user user under whose privileges this structure is going to be created
* @param parentId parent container id
* @return record folder
* @throws Exception on failed creation
*/
public FilePlanComponent createCategoryFolderInFilePlan(UserModel user, String parentId) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
// create root category
FilePlanComponent recordCategory = createCategory(parentId, "Category " + getRandomAlphanumeric());
// and return a folder underneath
return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric());
}
/**
* Helper method to retieve a fileplan component with user's privilege
* @param user user under whose privileges a component is to be read
* @param componentId id of the component to read
* @return {@link FilePlanComponent} for given componentId
* @throws Exception if user doesn't have sufficient privileges
*/
public FilePlanComponent getFilePlanComponentAsUser(UserModel user, String componentId) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
return filePlanComponentAPI.getFilePlanComponent(componentId);
}
/**
* Helper method to add permission on a component to user
* @param component {@link FilePlanComponent} on which permission should be given
* @param user {@link UserModel} for a user to be granted permission
* @param permission {@link UserPermissions} to be granted
*/
// FIXME: As of December 2016 there is no v1-style API for managing RM permissions.
// Until such APIs have become available, this method is just a proxy to an "old-style"
// API call.
public void addUserPermission(FilePlanComponent component, UserModel user, String permission)
{
// get an "old-style" REST API client
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
JsonObject bodyJson = buildObject()
.addArray("permissions")
.addObject()
.add("authority", user.getUsername())
.add("role", permission)
.end()
.getJson();
// override v1 baseURI and basePath
RequestSpecification spec = new RequestSpecBuilder()
.setBaseUri(client.getApiUrl())
.setBasePath("/")
.build();
// execute an "old-style" API call
Response response = given()
.spec(spec)
.auth().basic(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword())
.contentType(ContentType.JSON)
.body(bodyJson.toString())
.pathParam("nodeId", component.getId())
.log().all()
.when()
.post("/node/workspace/SpacesStore/{nodeId}/rmpermissions")
.prettyPeek()
.andReturn();
filePlanComponentAPI.usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
}
/**
* Create temp file with content
*
* @param name file name
* @return {@link File} file
*/
public static File createTempFile(final String name,String content)
{
try
{
// create file
final File file = File.createTempFile(name, ".txt");
// create writer
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, Charset.forName("UTF-8").newEncoder()))
{
// place content in file
writer.write(content);
}
return file;
} catch (Exception exception)
{
throw new RuntimeException("Unable to create test file.", exception);
}
}
}

View File

@@ -50,7 +50,7 @@ import org.testng.annotations.DataProvider;
* @since 2.6 * @since 2.6
*/ */
public interface TestData public interface TestData
{ {
/** /**
* A user with ALFRESCO_ADMINISTRATORS role. * A user with ALFRESCO_ADMINISTRATORS role.
* <p>"GROUP_ANOTHER_ADMIN_EXISTS" The ANOTHER_ADMIN user has been created. * <p>"GROUP_ANOTHER_ADMIN_EXISTS" The ANOTHER_ADMIN user has been created.
@@ -75,10 +75,10 @@ public interface TestData
public static Object[][] getContainers() public static Object[][] getContainers()
{ {
return new Object[][] { return new Object[][] {
{ FILE_PLAN_ALIAS.toString() }, { FILE_PLAN_ALIAS },
{ TRANSFERS_ALIAS.toString() }, { TRANSFERS_ALIAS },
{ HOLDS_ALIAS.toString() }, { HOLDS_ALIAS },
{ UNFILED_RECORDS_CONTAINER_ALIAS.toString() }, { UNFILED_RECORDS_CONTAINER_ALIAS },
}; };
} }
@@ -102,7 +102,7 @@ public interface TestData
/** /**
* The default CATEGORY name used when creating categories * The default CATEGORY name used when creating categories
*/ */
public static String CATEGORY_NAME = "CATEGORY NAME"+ getRandomAlphanumeric(); public static String CATEGORY_NAME = "CATEGORY NAME" + getRandomAlphanumeric();
/** /**
* The default CATEGORY title used when creating categories * The default CATEGORY title used when creating categories
@@ -130,15 +130,15 @@ public interface TestData
public static Object[][] childrenNotAllowedForCategory() public static Object[][] childrenNotAllowedForCategory()
{ {
return new Object[][] { return new Object[][] {
{ FILE_PLAN_TYPE.toString() }, { FILE_PLAN_TYPE },
{ TRANSFER_CONTAINER_TYPE.toString() }, { TRANSFER_CONTAINER_TYPE },
{ HOLD_CONTAINER_TYPE.toString() }, { HOLD_CONTAINER_TYPE },
{ UNFILED_CONTAINER_TYPE.toString() }, { UNFILED_CONTAINER_TYPE },
{ UNFILED_RECORD_FOLDER_TYPE.toString()}, { UNFILED_RECORD_FOLDER_TYPE },
{ HOLD_TYPE.toString()}, { HOLD_TYPE },
{ TRANSFER_TYPE.toString()}, { TRANSFER_TYPE },
{ FOLDER_TYPE.toString()}, { FOLDER_TYPE },
{ CONTENT_TYPE.toString()} { CONTENT_TYPE }
}; };
} }
} }

View File

@@ -26,27 +26,24 @@
*/ */
package org.alfresco.rest.rm.community.fileplancomponents; package org.alfresco.rest.rm.community.fileplancomponents;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_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.CONTENT_TYPE; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel;
import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
import org.alfresco.rest.rm.community.base.BaseRestTest; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.user.UserPermissions; import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.rm.community.model.user.UserRoles; import org.alfresco.rest.rm.community.model.user.UserRoles;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.RMSiteAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMUserAPI;
import org.alfresco.rest.rm.community.requests.RMUserAPI;
import org.alfresco.test.AlfrescoTest; import org.alfresco.test.AlfrescoTest;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -61,22 +58,10 @@ import org.testng.annotations.Test;
* @author Kristijan Conkas * @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
public class DeleteRecordTests extends BaseRestTest public class DeleteRecordTests extends BaseRMRestTest
{ {
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired @Autowired
private RMUserAPI rmUserAPI; private RMUserAPI rmUserAPI;
@Autowired
private DataUser dataUser;
@Autowired
private RMSiteAPI rmSiteAPI;
/** image resource file to be used for records body */
private static final String IMAGE_FILE = "money.JPG";
/** /**
* <pre> * <pre>
@@ -86,7 +71,7 @@ public class DeleteRecordTests extends BaseRestTest
* When I delete the record * When I delete the record
* Then it is deleted from the file plan * Then it is deleted from the file plan
* </pre> * </pre>
* *
* @param container * @param container
* @throws Exception * @throws Exception
*/ */
@@ -98,19 +83,13 @@ public class DeleteRecordTests extends BaseRestTest
@AlfrescoTest(jira="RM-4363") @AlfrescoTest(jira="RM-4363")
public void adminCanDeleteElectronicRecord(FilePlanComponent container) throws Exception public void adminCanDeleteElectronicRecord(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent newRecord = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, container.getId());
// create an electronic record assertStatusCode(CREATED);
FilePlanComponent record = FilePlanComponent.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
deleteAndVerify(newRecord); deleteAndVerify(newRecord);
} }
/** /**
* <pre> * <pre>
* Given a record * Given a record
@@ -119,7 +98,7 @@ public class DeleteRecordTests extends BaseRestTest
* When I delete the record * When I delete the record
* Then it is deleted from the file plan * Then it is deleted from the file plan
* </pre> * </pre>
* *
* @param container * @param container
* @throws Exception * @throws Exception
*/ */
@@ -131,21 +110,14 @@ public class DeleteRecordTests extends BaseRestTest
@AlfrescoTest(jira="RM-4363") @AlfrescoTest(jira="RM-4363")
public void adminCanDeleteNonElectronicRecord(FilePlanComponent container) throws Exception public void adminCanDeleteNonElectronicRecord(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// create a non-electronic record // create a non-electronic record
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent newRecord = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(createNonElectronicRecordModel(), container.getId());
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) assertStatusCode(CREATED);
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createFilePlanComponent(
record,
container.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
deleteAndVerify(newRecord); deleteAndVerify(newRecord);
} }
/** /**
* <pre> * <pre>
* Given a record * Given a record
@@ -154,7 +126,7 @@ public class DeleteRecordTests extends BaseRestTest
* Then nothing happens * Then nothing happens
* And error gets reported * And error gets reported
* </pre> * </pre>
* *
* @param container * @param container
* @throws Exception * @throws Exception
*/ */
@@ -165,37 +137,26 @@ public class DeleteRecordTests extends BaseRestTest
@AlfrescoTest(jira="RM-4363") @AlfrescoTest(jira="RM-4363")
public void userWithoutWritePermissionsCantDeleteRecord() throws Exception public void userWithoutWritePermissionsCantDeleteRecord() throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// create a non-electronic record in unfiled records // create a non-electronic record in unfiled records
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent newRecord = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(createNonElectronicRecordModel(), UNFILED_RECORDS_CONTAINER_ALIAS);
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) assertStatusCode(CREATED);
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createFilePlanComponent(
record,
UNFILED_RECORDS_CONTAINER_ALIAS.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
// create test user and add it with collab. privileges // create test user and add it with collab. privileges
UserModel deleteUser = dataUser.createRandomTestUser("delnoperm"); UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm");
deleteUser.setUserRole(UserRole.SiteCollaborator); deleteUser.setUserRole(UserRole.SiteCollaborator);
logger.info("test user: " + deleteUser.getUsername()); logger.info("test user: " + deleteUser.getUsername());
dataUser.addUserToSite(deleteUser, new SiteModel(rmSiteAPI.getSite().getId()), UserRole.SiteCollaborator); getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
// add RM role to user // add RM role to user
rmUserAPI.assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER); rmUserAPI.assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER);
rmUserAPI.usingRestWrapper().assertStatusCodeIs(OK); rmUserAPI.usingRestWrapper().assertStatusCodeIs(OK);
// log in as deleteUser
filePlanComponentAPI.usingRestWrapper().authenticateUser(deleteUser);
// try to delete newRecord // try to delete newRecord
filePlanComponentAPI.deleteFilePlanComponent(newRecord.getId()); getRestAPIFactory().getFilePlanComponentsAPI(deleteUser).deleteFilePlanComponent(newRecord.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); assertStatusCode(FORBIDDEN);
} }
/** /**
* <pre> * <pre>
* Given a record * Given a record
@@ -204,7 +165,7 @@ public class DeleteRecordTests extends BaseRestTest
* Then nothing happens * Then nothing happens
* And error gets reported * And error gets reported
* </pre> * </pre>
* *
* @param container * @param container
* @throws Exception * @throws Exception
*/ */
@@ -215,51 +176,41 @@ public class DeleteRecordTests extends BaseRestTest
@AlfrescoTest(jira="RM-4363") @AlfrescoTest(jira="RM-4363")
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// create test user and add it with collab. privileges // create test user and add it with collab. privileges
UserModel deleteUser = dataUser.createRandomTestUser("delnoperm"); UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm");
deleteUser.setUserRole(UserRole.SiteCollaborator); deleteUser.setUserRole(UserRole.SiteCollaborator);
dataUser.addUserToSite(deleteUser, new SiteModel(rmSiteAPI.getSite().getId()), UserRole.SiteCollaborator); getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
logger.info("test user: " + deleteUser.getUsername()); logger.info("test user: " + deleteUser.getUsername());
// add RM role to user, RM Power User doesn't have the Delete Record capabilities // add RM role to user, RM Power User doesn't have the Delete Record capabilities
rmUserAPI.assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER); rmUserAPI.assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER);
rmUserAPI.usingRestWrapper().assertStatusCodeIs(OK); rmUserAPI.usingRestWrapper().assertStatusCodeIs(OK);
// create random folder // create random folder
FilePlanComponent randomFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()); FilePlanComponent randomFolder = createCategoryFolderInFilePlan();
logger.info("random folder:" + randomFolder.getName()); logger.info("random folder:" + randomFolder.getName());
// grant deleteUser Filing privileges on randomFolder category, this will be // grant deleteUser Filing privileges on randomFolder category, this will be
// inherited to randomFolder // inherited to randomFolder
addUserPermission(filePlanComponentAPI.getFilePlanComponent(randomFolder.getParentId()), FilePlanComponentAPI filePlanComponentsAPIAsAdmin = getRestAPIFactory().getFilePlanComponentsAPI();
rmUserAPI.addUserPermission(filePlanComponentsAPIAsAdmin.getFilePlanComponent(randomFolder.getParentId()),
deleteUser, UserPermissions.PERMISSION_FILING); deleteUser, UserPermissions.PERMISSION_FILING);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); rmUserAPI.usingRestWrapper().assertStatusCodeIs(OK);
// create a non-electronic record in randomFolder // create a non-electronic record in randomFolder
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent newRecord = filePlanComponentsAPIAsAdmin.createFilePlanComponent(createNonElectronicRecordModel(), randomFolder.getId());
.name("Record " + getRandomAlphanumeric()) assertStatusCode(CREATED);
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createFilePlanComponent(
record,
randomFolder.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
// log in as deleteUser
filePlanComponentAPI.usingRestWrapper().authenticateUser(deleteUser);
// verify the user can see the newRecord // verify the user can see the newRecord
filePlanComponentAPI.getFilePlanComponent(newRecord.getId()); FilePlanComponentAPI filePlanComponentsAPIAsUser = getRestAPIFactory().getFilePlanComponentsAPI(deleteUser);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); filePlanComponentsAPIAsUser.getFilePlanComponent(newRecord.getId());
assertStatusCode(OK);
// try to delete newRecord // try to delete newRecord
filePlanComponentAPI.deleteFilePlanComponent(newRecord.getId()); filePlanComponentsAPIAsUser.deleteFilePlanComponent(newRecord.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); assertStatusCode(FORBIDDEN);
} }
/** /**
* Utility method to delete a record and verify successful deletion * Utility method to delete a record and verify successful deletion
* @param record * @param record
@@ -267,14 +218,14 @@ public class DeleteRecordTests extends BaseRestTest
*/ */
private void deleteAndVerify(FilePlanComponent record) throws Exception private void deleteAndVerify(FilePlanComponent record) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
// delete it and verify status // delete it and verify status
filePlanComponentAPI.deleteFilePlanComponent(record.getId()); filePlanComponentsAPI.deleteFilePlanComponent(record.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NO_CONTENT); assertStatusCode(NO_CONTENT);
// try to get deleted file plan component // try to get deleted file plan component
filePlanComponentAPI.getFilePlanComponent(record.getId()); filePlanComponentsAPI.getFilePlanComponent(record.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); assertStatusCode(NOT_FOUND);
} }
} }

View File

@@ -32,18 +32,17 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_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.rest.rm.community.util.PojoUtility.toJson;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel;
import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import org.alfresco.rest.rm.community.base.BaseRestTest; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@@ -56,30 +55,22 @@ import org.testng.annotations.Test;
* @author Kristijan Conkas * @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
public class ElectronicRecordTests extends BaseRestTest public class ElectronicRecordTests extends BaseRMRestTest
{ {
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
/** image resource file to be used for records body */
private static final String IMAGE_FILE = "money.JPG";
/** Valid root containers where electronic records can be created */ /** Valid root containers where electronic records can be created */
@DataProvider(name = "invalidParentContainers") @DataProvider(name = "invalidParentContainers")
public Object[][] invalidContainers() throws Exception { public Object[][] invalidContainers() throws Exception
return new Object[][] { {
return new Object[][]
{
// record category // record category
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), { getFilePlanComponent(createCategoryFolderInFilePlan().getParentId()) },
createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()).getParentId()) },
// file plan root // file plan root
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) }, { getFilePlanComponent(FILE_PLAN_ALIAS) },
// transfers // transfers
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), TRANSFERS_ALIAS.toString()) }, { getFilePlanComponent(TRANSFERS_ALIAS) },
// holds // holds
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), HOLDS_ALIAS.toString()) }, { getFilePlanComponent(HOLDS_ALIAS) },
}; };
} }
@@ -100,17 +91,11 @@ public class ElectronicRecordTests extends BaseRestTest
) )
public void cantCreateElectronicRecordsInInvalidContainers(FilePlanComponent container) throws Exception public void cantCreateElectronicRecordsInInvalidContainers(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Build object the filePlan // Build object the filePlan
FilePlanComponent record = FilePlanComponent.builder() getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, container.getId());
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.build();
filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId());
// verify the create request status code // verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
/** /**
@@ -126,8 +111,7 @@ public class ElectronicRecordTests extends BaseRestTest
@Test(description = "Electronic record can't be created in closed record folder") @Test(description = "Electronic record can't be created in closed record folder")
public void cantCreateElectronicRecordInClosedFolder() throws Exception public void cantCreateElectronicRecordInClosedFolder() throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent recordFolder = createCategoryFolderInFilePlan();
FilePlanComponent recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
// the folder should be open // the folder should be open
assertFalse(recordFolder.getProperties().getIsClosed()); assertFalse(recordFolder.getProperties().getIsClosed());
@@ -136,14 +120,10 @@ public class ElectronicRecordTests extends BaseRestTest
closeFolder(recordFolder.getId()); closeFolder(recordFolder.getId());
// try to create it, this should fail // try to create it, this should fail
FilePlanComponent record = FilePlanComponent.builder() getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(createElectronicRecordModel(), IMAGE_FILE, recordFolder.getId());
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.build();
filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, recordFolder.getId());
// verify the status code // verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
/** /**
@@ -173,10 +153,9 @@ public class ElectronicRecordTests extends BaseRestTest
) )
public void canCreateElectronicRecordOnlyWithMandatoryProperties(FilePlanComponent container) throws Exception public void canCreateElectronicRecordOnlyWithMandatoryProperties(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
logger.info("Root container:\n" + toJson(container)); logger.info("Root container:\n" + toJson(container));
if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString()))
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
{ {
// only record folders can be open or closed // only record folders can be open or closed
assertFalse(container.getProperties().getIsClosed()); assertFalse(container.getProperties().getIsClosed());
@@ -184,14 +163,14 @@ public class ElectronicRecordTests extends BaseRestTest
// component without name // component without name
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent record = FilePlanComponent.builder()
.nodeType(CONTENT_TYPE.toString()) .nodeType(CONTENT_TYPE)
.build(); .build();
// try to create it // try to create it
filePlanComponentAPI.createFilePlanComponent(record, container.getId()); getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(record, container.getId());
// verify the status code is BAD_REQUEST // verify the status code is BAD_REQUEST
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); assertStatusCode(BAD_REQUEST);
} }
/** /**
@@ -218,19 +197,15 @@ public class ElectronicRecordTests extends BaseRestTest
) )
public void canCreateElectronicRecordsInValidContainers(FilePlanComponent container) throws Exception public void canCreateElectronicRecordsInValidContainers(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent record = createElectronicRecordModel();
FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent record = FilePlanComponent.builder() String newRecordId = filePlanComponentsAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.build();
String newRecordId = filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
// verify the create request status code // verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// get newly created electonic record and verify its properties // get newly created electronic record and verify its properties
FilePlanComponent electronicRecord = filePlanComponentAPI.getFilePlanComponent(newRecordId); FilePlanComponent electronicRecord = filePlanComponentsAPI.getFilePlanComponent(newRecordId);
// created record will have record identifier inserted in its name but will be prefixed with // created record will have record identifier inserted in its name but will be prefixed with
// the name it was created as // the name it was created as
assertTrue(electronicRecord.getName().startsWith(record.getName())); assertTrue(electronicRecord.getName().startsWith(record.getName()));
@@ -249,20 +224,19 @@ public class ElectronicRecordTests extends BaseRestTest
) )
public void recordNameDerivedFromFileName(FilePlanComponent container) throws Exception public void recordNameDerivedFromFileName(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// record object without name set // record object without name set
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent record = FilePlanComponent.builder()
.nodeType(CONTENT_TYPE.toString()) .nodeType(CONTENT_TYPE)
.build(); .build();
String newRecordId = filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId(); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
String newRecordId = filePlanComponentsAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
// verify the create request status code // verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// get newly created electonic record and verify its properties // get newly created electonic record and verify its properties
FilePlanComponent electronicRecord = filePlanComponentAPI.getFilePlanComponent(newRecordId); FilePlanComponent electronicRecord = filePlanComponentsAPI.getFilePlanComponent(newRecordId);
// record will have record identifier inserted in its name but will for sure start with file name // record will have record identifier inserted in its name but will for sure start with file name
// and end with its extension // and end with its extension
assertTrue(electronicRecord.getName().startsWith(IMAGE_FILE.substring(0, IMAGE_FILE.indexOf(".")))); assertTrue(electronicRecord.getName().startsWith(IMAGE_FILE.substring(0, IMAGE_FILE.indexOf("."))));

View File

@@ -43,19 +43,14 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.base.TestData; import org.alfresco.rest.rm.community.base.TestData;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI;
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug; import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@@ -65,20 +60,8 @@ import org.testng.annotations.Test;
* @author Rodica Sutu * @author Rodica Sutu
* @since 2.6 * @since 2.6
*/ */
public class FilePlanTests extends BaseRestTest public class FilePlanTests extends BaseRMRestTest
{ {
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
protected RestWrapper restWrapper;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
/** /**
* Given that the RM site doesn't exist * Given that the RM site doesn't exist
* When I use the API to get the File Plan/Holds/Unfiled Records Container/Transfers * When I use the API to get the File Plan/Holds/Unfiled Records Container/Transfers
@@ -90,8 +73,10 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class, dataProviderClass = TestData.class,
dataProvider = "getContainers" dataProvider = "getContainers"
) )
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception public void getFilePlanComponentWhenRMIsNotCreated(String filePlanComponentAlias) throws Exception
{ {
RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
// Check RM Site Exist // Check RM Site Exist
if (rmSiteAPI.existsRMSite()) if (rmSiteAPI.existsRMSite())
{ {
@@ -99,18 +84,13 @@ public class FilePlanTests extends BaseRestTest
rmSiteAPI.deleteRMSite(); rmSiteAPI.deleteRMSite();
} }
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the file plan component // Get the file plan component
filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString()); getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponentAlias);
//check the response code is NOT_FOUND //check the response code is NOT_FOUND
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); assertStatusCode(NOT_FOUND);
} }
/** /**
* Given that a file plan exists * Given that a file plan exists
* When I ask the API for the details of the file plan * When I ask the API for the details of the file plan
@@ -122,22 +102,19 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class, dataProviderClass = TestData.class,
dataProvider = "getContainersAndTypes" dataProvider = "getContainersAndTypes"
) )
public void getFilePlanComponentWhenRMIsCreated(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception public void getFilePlanComponentWhenRMIsCreated(String filePlanComponentAlias, String filePlanComponentType) throws Exception
{ {
// Create RM Site if doesn't exist // Create RM Site if doesn't exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the file plan special container // Get the file plan special container
FilePlanComponent filePlanComponent = filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString()); FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponentAlias);
// Check the response code // Check the response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); assertStatusCode(OK);
// Check the response contains the right node type // Check the response contains the right node type
assertEquals(filePlanComponent.getNodeType(), rmType.toString()); assertEquals(filePlanComponent.getNodeType(), filePlanComponentType);
} }
/** /**
@@ -156,14 +133,11 @@ public class FilePlanTests extends BaseRestTest
// Create RM Site if doesn't exist // Create RM Site if doesn't exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the file plan special containers with the optional parameter allowableOperations // Get the file plan special containers with the optional parameter allowableOperations
FilePlanComponent filePlanComponent = filePlanComponentAPI.withParams("include="+ ALLOWABLE_OPERATIONS).getFilePlanComponent(specialContainerAlias); FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(specialContainerAlias, "include=" + ALLOWABLE_OPERATIONS);
// Check the list of allowableOperations returned // Check the list of allowableOperations returned
if(specialContainerAlias.equals(TRANSFERS_ALIAS.toString())) if(specialContainerAlias.equals(TRANSFERS_ALIAS))
{ {
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE)), assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE)),
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString()); "Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
@@ -195,9 +169,6 @@ public class FilePlanTests extends BaseRestTest
// Create RM Site if doesn't exist // Create RM Site if doesn't exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Build object for updating the filePlan // Build object for updating the filePlan
FilePlanComponent filePlanComponent = FilePlanComponent.builder() FilePlanComponent filePlanComponent = FilePlanComponent.builder()
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
@@ -207,10 +178,10 @@ public class FilePlanTests extends BaseRestTest
.build(); .build();
// Update the record category // Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanComponent,FILE_PLAN_ALIAS.toString()); FilePlanComponent renamedFilePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().updateFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS);
// Verify the response status code // Verify the response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); assertStatusCode(OK);
// Verify the returned description field for the file plan component // Verify the returned description field for the file plan component
assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION); assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION);
@@ -230,19 +201,16 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class, dataProviderClass = TestData.class,
dataProvider = "getContainers" dataProvider = "getContainers"
) )
public void deleteFilePlanSpecialComponents(String filePlanAlias) throws Exception public void deleteFilePlanSpecialComponents(String filePlanComponentAlias) throws Exception
{ {
// Create RM Site if doesn't exist // Create RM Site if doesn't exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Delete the file plan component // Delete the file plan component
filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString()); getRestAPIFactory().getFilePlanComponentsAPI().deleteFilePlanComponent(filePlanComponentAlias);
// Check the DELETE response status code // Check the DELETE response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
/** /**
@@ -256,27 +224,19 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class, dataProviderClass = TestData.class,
dataProvider = "getContainers" dataProvider = "getContainers"
) )
public void deleteFilePlanSpecialComponentsNonRMUser(String filePlanAlias) throws Exception public void deleteFilePlanSpecialComponentsNonRMUser(String filePlanComponentAlias) throws Exception
{ {
// Create RM Site if doesn't exist // Create RM Site if doesn't exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Disconnect the current user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Authenticate admin user to Alfresco REST API
restClient.authenticateUser(dataUser.getAdminUser());
// Create a random user // Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser"); UserModel nonRMuser = getDataUser().createRandomTestUser("testUser");
// Authenticate using the random user
filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser);
// Delete the file plan component // Delete the file plan component
filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString()); getRestAPIFactory().getFilePlanComponentsAPI(nonRMuser).deleteFilePlanComponent(filePlanComponentAlias);
// Check the DELETE response status code // Check the DELETE response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); assertStatusCode(FORBIDDEN);
} }
/** /**
@@ -291,40 +251,36 @@ public class FilePlanTests extends BaseRestTest
dataProvider = "getContainersAndTypes" dataProvider = "getContainersAndTypes"
) )
@Bug(id = "RM-4296") @Bug(id = "RM-4296")
public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception public void createFilePlanSpecialContainerWhenExists(String filePlanComponentAlias, String filePlanComponentType) throws Exception
{ {
// Create RM Site if doesn't exist // Create RM Site if doesn't exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Get the RM site ID // Get the RM site ID
String rmSiteId = rmSiteAPI.getSite().getGuid(); String rmSiteId = getRestAPIFactory().getRMSiteAPI().getSite().getGuid();
String name = filePlanAlias + getRandomAlphanumeric(); String name = filePlanComponentAlias + getRandomAlphanumeric();
// Build the file plan root properties // Build the file plan root properties
FilePlanComponent filePlanComponent = FilePlanComponent.builder() FilePlanComponent filePlanComponent = FilePlanComponent.builder()
.name(name) .name(name)
.nodeType(rmType.toString()) .nodeType(filePlanComponentType)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.build()) .build())
.build(); .build();
// Authenticate with admin user FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the special containers into RM site - parent folder // Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(filePlanComponent, rmSiteId); filePlanComponentsAPI.createFilePlanComponent(filePlanComponent, rmSiteId);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
// Create the special containers into RM site - parent folder // Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS.toString()); filePlanComponentsAPI.createFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
// Create the special containers into the root of special containers containers // Create the special containers into the root of special containers containers
filePlanComponentAPI.createFilePlanComponent(filePlanComponent, filePlanAlias.toString()); filePlanComponentsAPI.createFilePlanComponent(filePlanComponent, filePlanComponentAlias);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
/** /**
@@ -338,27 +294,18 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class, dataProviderClass = TestData.class,
dataProvider = "getContainers" dataProvider = "getContainers"
) )
public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanComponentAlias) throws Exception
{ {
// Create RM Site if doesn't exist // Create RM Site if doesn't exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Disconnect user from REST API session
rmSiteAPI.usingRestWrapper().disconnect();
// Authenticate admin user to Alfresco REST API
restClient.authenticateUser(dataUser.getAdminUser());
// Create a random user // Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser"); UserModel nonRMuser = getDataUser().createRandomTestUser("testUser");
// Authenticate using the random user
filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser);
// Get the special file plan components // Get the special file plan components
filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString()); getRestAPIFactory().getFilePlanComponentsAPI(nonRMuser).getFilePlanComponent(filePlanComponentAlias);
// Check the response status code is FORBIDDEN // Check the response status code is FORBIDDEN
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); assertStatusCode(FORBIDDEN);
} }
} }

View File

@@ -35,6 +35,8 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_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.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.alfresco.rest.rm.community.util.PojoUtility.toJson;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel;
import static org.alfresco.utility.constants.UserRole.SiteManager;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.CREATED;
@@ -45,16 +47,13 @@ import static org.testng.Assert.assertFalse;
import java.util.Random; import java.util.Random;
import org.alfresco.rest.rm.community.base.BaseRestTest; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@@ -63,17 +62,8 @@ import org.testng.annotations.Test;
* @author Kristijan Conkas * @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
public class NonElectronicRecordTests extends BaseRestTest public class NonElectronicRecordTests extends BaseRMRestTest
{ {
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
@Autowired
private RMSiteAPI rmSiteAPI;
/** /**
* <pre> * <pre>
* Given a parent container that is NOT a record folder or an unfiled record folder * Given a parent container that is NOT a record folder or an unfiled record folder
@@ -86,37 +76,30 @@ public class NonElectronicRecordTests extends BaseRestTest
@Test(description = "Non-electronic record can't be created as a child of invalid parent Id") @Test(description = "Non-electronic record can't be created as a child of invalid parent Id")
public void cantCreateForInvalidParentIds() throws Exception public void cantCreateForInvalidParentIds() throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// non-electronic record object to be used for create tests
FilePlanComponent nonElectronicRecord = FilePlanComponent.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.build();
// create record category, non-electronic records can't be its children // create record category, non-electronic records can't be its children
FilePlanComponent recordCategoryModel = FilePlanComponent.builder() FilePlanComponent recordCategoryModel = FilePlanComponent.builder()
.name("Category " + getRandomAlphanumeric()) .name("Category " + getRandomAlphanumeric())
.nodeType(RECORD_CATEGORY_TYPE.toString()) .nodeType(RECORD_CATEGORY_TYPE)
.build(); .build();
FilePlanComponent recordCategory = filePlanComponentAPI.createFilePlanComponent(recordCategoryModel, FILE_PLAN_ALIAS.toString()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent recordCategory = filePlanComponentsAPI.createFilePlanComponent(recordCategoryModel, FILE_PLAN_ALIAS);
// iterate through all invalid parent containers and try to create/file an electronic record // 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()) asList(FILE_PLAN_ALIAS, TRANSFERS_ALIAS, HOLDS_ALIAS, recordCategory.getId())
.stream() .stream()
.forEach(id -> .forEach(id ->
{ {
try try
{ {
filePlanComponentAPI.createFilePlanComponent(nonElectronicRecord, id); filePlanComponentsAPI.createFilePlanComponent(createNonElectronicRecordModel(), id);
} }
catch (Exception error) catch (Exception error)
{ {
} }
// Verify the status code // Verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
}); });
} }
@@ -144,10 +127,9 @@ public class NonElectronicRecordTests extends BaseRestTest
) )
public void canCreateInValidContainers(FilePlanComponent container) throws Exception public void canCreateInValidContainers(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
logger.info("Root container:\n" + toJson(container)); logger.info("Root container:\n" + toJson(container));
if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString()))
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
{ {
// only record folders can be open or closed // only record folders can be open or closed
assertFalse(container.getProperties().getIsClosed()); assertFalse(container.getProperties().getIsClosed());
@@ -168,7 +150,7 @@ public class NonElectronicRecordTests extends BaseRestTest
// set values of all available properties for the non electronic records // set values of all available properties for the non electronic records
FilePlanComponent filePlanComponent = FilePlanComponent.builder() FilePlanComponent filePlanComponent = FilePlanComponent.builder()
.name("Record " + getRandomAlphanumeric()) .name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .nodeType(NON_ELECTRONIC_RECORD_TYPE)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.title(title) .title(title)
.description(description) .description(description)
@@ -182,15 +164,16 @@ public class NonElectronicRecordTests extends BaseRestTest
.build(); .build();
// create non-electronic record // create non-electronic record
String nonElectronicId = filePlanComponentAPI.createFilePlanComponent( FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
String nonElectronicId = filePlanComponentsAPI.createFilePlanComponent(
filePlanComponent, filePlanComponent,
container.getId()).getId(); container.getId()).getId();
// verify the create request status code // verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// get newly created non-electonic record and verify its properties // get newly created non-electonic record and verify its properties
FilePlanComponent nonElectronicRecord = filePlanComponentAPI.getFilePlanComponent(nonElectronicId); FilePlanComponent nonElectronicRecord = filePlanComponentsAPI.getFilePlanComponent(nonElectronicId);
assertEquals(title, nonElectronicRecord.getProperties().getTitle()); assertEquals(title, nonElectronicRecord.getProperties().getTitle());
assertEquals(description, nonElectronicRecord.getProperties().getDescription()); assertEquals(description, nonElectronicRecord.getProperties().getDescription());
@@ -215,8 +198,7 @@ public class NonElectronicRecordTests extends BaseRestTest
@Test(description = "Non-electronic record can't be created in closed record folder") @Test(description = "Non-electronic record can't be created in closed record folder")
public void cantCreateInClosedFolder() throws Exception public void cantCreateInClosedFolder() throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent recordFolder = createCategoryFolderInFilePlan();
FilePlanComponent recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
// the folder should be open // the folder should be open
assertFalse(recordFolder.getProperties().getIsClosed()); assertFalse(recordFolder.getProperties().getIsClosed());
@@ -225,16 +207,10 @@ public class NonElectronicRecordTests extends BaseRestTest
closeFolder(recordFolder.getId()); closeFolder(recordFolder.getId());
// try to create it, this should fail and throw an exception // try to create it, this should fail and throw an exception
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(createNonElectronicRecordModel(), recordFolder.getId());
filePlanComponentAPI.createFilePlanComponent(FilePlanComponent.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.build(),
recordFolder.getId())
.getId();
// verify the status code // verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
/** /**
@@ -263,10 +239,8 @@ public class NonElectronicRecordTests extends BaseRestTest
) )
public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
logger.info("Root container:\n" + toJson(container)); logger.info("Root container:\n" + toJson(container));
if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString())) if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
{ {
// only record folders can be open or closed // only record folders can be open or closed
assertFalse(container.getProperties().getIsClosed()); assertFalse(container.getProperties().getIsClosed());
@@ -296,14 +270,14 @@ public class NonElectronicRecordTests extends BaseRestTest
// this should fail and throw an exception // this should fail and throw an exception
try try
{ {
filePlanComponentAPI.createFilePlanComponent(c, container.getId()); getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(c, container.getId());
} }
catch (Exception e) catch (Exception e)
{ {
} }
// verify the status code is BAD_REQUEST // verify the status code is BAD_REQUEST
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); assertStatusCode(BAD_REQUEST);
}); });
} }
@@ -323,33 +297,30 @@ public class NonElectronicRecordTests extends BaseRestTest
) )
public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception
{ {
String username = "zzzuser"; UserModel user = createUserWithRole("zzzuser", SiteManager);
UserModel user = createUserWithRole(username, UserRole.SiteManager);
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
// try to create a fileplan component // try to create a fileplan component
FilePlanComponent record=FilePlanComponent.builder() FilePlanComponent record = FilePlanComponent.builder()
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.description("Description") .description("Description")
.title("Title") .title("Title")
.build()) .build())
.name("Record Name") .name("Record Name")
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build(); .build();
// this should fail and throw an exception // this should fail and throw an exception
try try
{ {
filePlanComponentAPI.createFilePlanComponent(record, container.getId()); getRestAPIFactory().getFilePlanComponentsAPI(user).createFilePlanComponent(record, container.getId());
} }
catch (Exception e) catch (Exception e)
{ {
} }
// user who isn't an RM site member can't access the container path // user who isn't an RM site member can't access the container path
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); assertStatusCode(FORBIDDEN);
} }
/** /**
@@ -358,8 +329,8 @@ public class NonElectronicRecordTests extends BaseRestTest
*/ */
private FilePlanComponent getDummyNonElectronicRecord() private FilePlanComponent getDummyNonElectronicRecord()
{ {
FilePlanComponent component=FilePlanComponent.builder() FilePlanComponent component = FilePlanComponent.builder()
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build(); .build();
return component; return component;
} }
@@ -378,21 +349,20 @@ public class NonElectronicRecordTests extends BaseRestTest
*/ */
private UserModel createUserWithRole(String userName, UserRole userRole) throws Exception private UserModel createUserWithRole(String userName, UserRole userRole) throws Exception
{ {
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); String siteId = getRestAPIFactory().getRMSiteAPI().getSite().getId();
String siteId = rmSiteAPI.getSite().getId();
// check if user exists // check if user exists
UserModel user = new UserModel(); UserModel user = new UserModel();
user.setUsername(userName); user.setUsername(userName);
user.setPassword(userName); user.setPassword(userName);
if (!dataUser.isUserInRepo(userName)) if (!getDataUser().isUserInRepo(userName))
{ {
// user doesn't exist, create it // user doesn't exist, create it
user = dataUser.createUser(userName, userName); user = getDataUser().createUser(userName, userName);
user.setUserRole(userRole); user.setUserRole(userRole);
dataUser.addUserToSite(user, new SiteModel(siteId), userRole); getDataUser().addUserToSite(user, new SiteModel(siteId), userRole);
} }
return user; return user;

View File

@@ -386,7 +386,7 @@ public class ReadRecordTests extends BaseRestTest
} }
); );
} }
/** /**
* Given a record * Given a record
* When I try to read the children * When I try to read the children

View File

@@ -44,17 +44,13 @@ import static org.testng.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.base.TestData; import org.alfresco.rest.rm.community.base.TestData;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.report.Bug; import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@@ -64,14 +60,8 @@ import org.testng.annotations.Test;
* @author Tuna Aksoy * @author Tuna Aksoy
* @since 2.6 * @since 2.6
*/ */
public class RecordCategoryTest extends BaseRestTest public class RecordCategoryTest extends BaseRMRestTest
{ {
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
// Number of children (for children creation test) // Number of children (for children creation test)
private static final int NUMBER_OF_CHILDREN = 10; private static final int NUMBER_OF_CHILDREN = 10;
@@ -87,16 +77,13 @@ public class RecordCategoryTest extends BaseRestTest
) )
public void createCategoryTest() throws Exception public void createCategoryTest() throws Exception
{ {
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String categoryName = "Category name " + getRandomAlphanumeric(); String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric(); String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties // Build the record category properties
FilePlanComponent recordCategory = FilePlanComponent.builder() FilePlanComponent recordCategory = FilePlanComponent.builder()
.name(categoryName) .name(categoryName)
.nodeType(RECORD_CATEGORY_TYPE.toString()) .nodeType(RECORD_CATEGORY_TYPE)
.properties( .properties(
FilePlanComponentProperties.builder() FilePlanComponentProperties.builder()
.title(categoryTitle) .title(categoryTitle)
@@ -104,10 +91,10 @@ public class RecordCategoryTest extends BaseRestTest
.build(); .build();
// Create the record category // Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS.toString()); FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// Verify the returned file plan component // Verify the returned file plan component
assertTrue(filePlanComponent.getIsCategory()); assertTrue(filePlanComponent.getIsCategory());
@@ -115,9 +102,9 @@ public class RecordCategoryTest extends BaseRestTest
assertFalse(filePlanComponent.getIsRecordFolder()); assertFalse(filePlanComponent.getIsRecordFolder());
assertEquals(filePlanComponent.getName(), categoryName); assertEquals(filePlanComponent.getName(), categoryName);
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString()); assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE);
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
// Verify the returned file plan component properties // Verify the returned file plan component properties
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties(); FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
@@ -138,9 +125,6 @@ public class RecordCategoryTest extends BaseRestTest
) )
public void renameCategory() throws Exception public void renameCategory() throws Exception
{ {
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first // Create record category first
String categoryName = "Category name " + getRandomAlphanumeric(); String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric(); String categoryTitle = "Category title " + getRandomAlphanumeric();
@@ -148,7 +132,7 @@ public class RecordCategoryTest extends BaseRestTest
// Build the record category properties // Build the record category properties
FilePlanComponent recordCategory = FilePlanComponent.builder() FilePlanComponent recordCategory = FilePlanComponent.builder()
.name(categoryName) .name(categoryName)
.nodeType(RECORD_CATEGORY_TYPE.toString()) .nodeType(RECORD_CATEGORY_TYPE)
.properties( .properties(
FilePlanComponentProperties.builder() FilePlanComponentProperties.builder()
.title(categoryTitle) .title(categoryTitle)
@@ -156,7 +140,8 @@ public class RecordCategoryTest extends BaseRestTest
.build(); .build();
// Create the record category // Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS.toString()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent filePlanComponent = filePlanComponentsAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
String newCategoryName = "Rename " + categoryName; String newCategoryName = "Rename " + categoryName;
@@ -164,16 +149,16 @@ public class RecordCategoryTest extends BaseRestTest
FilePlanComponent recordCategoryUpdated = FilePlanComponent.builder().name(newCategoryName).build(); FilePlanComponent recordCategoryUpdated = FilePlanComponent.builder().name(newCategoryName).build();
// Update the record category // Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(recordCategoryUpdated, filePlanComponent.getId()); FilePlanComponent renamedFilePlanComponent = filePlanComponentsAPI.updateFilePlanComponent(recordCategoryUpdated, filePlanComponent.getId());
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(OK); assertStatusCode(OK);
// Verify the returned file plan component // Verify the returned file plan component
assertEquals(renamedFilePlanComponent.getName(), newCategoryName); assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
// Get actual FILE_PLAN_ALIAS id // Get actual FILE_PLAN_ALIAS id
FilePlanComponent parentComponent = filePlanComponentAPI.getFilePlanComponent(FILE_PLAN_ALIAS.toString()); FilePlanComponent parentComponent = filePlanComponentsAPI.getFilePlanComponent(FILE_PLAN_ALIAS);
// verify renamed component still has this parent // verify renamed component still has this parent
assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId()); assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId());
@@ -191,9 +176,6 @@ public class RecordCategoryTest extends BaseRestTest
) )
public void deleteCategory() throws Exception public void deleteCategory() throws Exception
{ {
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create record category first // Create record category first
String categoryName = "Category name " + getRandomAlphanumeric(); String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric(); String categoryTitle = "Category title " + getRandomAlphanumeric();
@@ -201,7 +183,7 @@ public class RecordCategoryTest extends BaseRestTest
// Build the record category properties // Build the record category properties
FilePlanComponent recordCategory = FilePlanComponent.builder() FilePlanComponent recordCategory = FilePlanComponent.builder()
.name(categoryName) .name(categoryName)
.nodeType(RECORD_CATEGORY_TYPE.toString()) .nodeType(RECORD_CATEGORY_TYPE)
.properties( .properties(
FilePlanComponentProperties.builder() FilePlanComponentProperties.builder()
.title(categoryTitle) .title(categoryTitle)
@@ -209,17 +191,18 @@ public class RecordCategoryTest extends BaseRestTest
.build(); .build();
// Create the record category // Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS.toString()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent filePlanComponent = filePlanComponentsAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
// Delete the record category // Delete the record category
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponent.getId()); filePlanComponentsAPI.deleteFilePlanComponent(filePlanComponent.getId());
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT); assertStatusCode(NO_CONTENT);
// Deleted component should no longer be retrievable // Deleted component should no longer be retrievable
filePlanComponentAPI.getFilePlanComponent(filePlanComponent.getId()); filePlanComponentsAPI.getFilePlanComponent(filePlanComponent.getId());
restWrapper.assertStatusCodeIs(NOT_FOUND); assertStatusCode(NOT_FOUND);
} }
/** /**
@@ -235,7 +218,7 @@ public class RecordCategoryTest extends BaseRestTest
public void createSubcategory() throws Exception public void createSubcategory() throws Exception
{ {
// Create root level category // Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric()); FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS, getRandomAlphanumeric());
assertNotNull(rootCategory.getId()); assertNotNull(rootCategory.getId());
// Create subcategory as a child of rootCategory // Create subcategory as a child of rootCategory
@@ -249,7 +232,7 @@ public class RecordCategoryTest extends BaseRestTest
assertTrue(childCategory.getIsCategory()); assertTrue(childCategory.getIsCategory());
assertFalse(childCategory.getIsFile()); assertFalse(childCategory.getIsFile());
assertFalse(childCategory.getIsRecordFolder()); assertFalse(childCategory.getIsRecordFolder());
assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE.toString()); assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE);
} }
/** /**
@@ -267,7 +250,7 @@ public class RecordCategoryTest extends BaseRestTest
public void listChildren() throws Exception public void listChildren() throws Exception
{ {
// Create root level category // Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric()); FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS, getRandomAlphanumeric());
assertNotNull(rootCategory.getId()); assertNotNull(rootCategory.getId());
// Add child categories/folders // Add child categories/folders
@@ -283,20 +266,17 @@ public class RecordCategoryTest extends BaseRestTest
children.add(child); children.add(child);
} }
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// List children from API // List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(rootCategory.getId()); FilePlanComponentsCollection apiChildren = getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(rootCategory.getId());
// Check status code // Check status code
restWrapper.assertStatusCodeIs(OK); assertStatusCode(OK);
logger.info("parent: " + rootCategory.getId()); logger.info("parent: " + rootCategory.getId());
// Check listed children against created list // Check listed children against created list
apiChildren.getEntries().forEach(c -> apiChildren.getEntries().forEach(c ->
{ {
FilePlanComponent filePlanComponent = c.getFilePlanComponent(); FilePlanComponent filePlanComponent = c.getFilePlanComponentModel();
assertNotNull(filePlanComponent.getId()); assertNotNull(filePlanComponent.getId());
logger.info("Checking child " + filePlanComponent.getId()); logger.info("Checking child " + filePlanComponent.getId());
@@ -309,7 +289,7 @@ public class RecordCategoryTest extends BaseRestTest
.get(); .get();
// Created by // Created by
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
// Is parent Id set correctly? // Is parent Id set correctly?
assertEquals(filePlanComponent.getParentId(), rootCategory.getId()); assertEquals(filePlanComponent.getParentId(), rootCategory.getId());
@@ -319,7 +299,7 @@ public class RecordCategoryTest extends BaseRestTest
// Boolean properties related to node type // Boolean properties related to node type
// Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created // Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString())) if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE))
{ {
assertTrue(filePlanComponent.getIsCategory()); assertTrue(filePlanComponent.getIsCategory());
assertFalse(filePlanComponent.getIsRecordFolder()); assertFalse(filePlanComponent.getIsRecordFolder());
@@ -361,11 +341,8 @@ public class RecordCategoryTest extends BaseRestTest
{ {
String COMPONENT_NAME = "Component"+getRandomAlphanumeric(); String COMPONENT_NAME = "Component"+getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//Create the category //Create the category
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), COMPONENT_NAME); FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, COMPONENT_NAME);
//Build node properties //Build node properties
FilePlanComponent recordCategory = FilePlanComponent.builder() FilePlanComponent recordCategory = FilePlanComponent.builder()
@@ -378,8 +355,8 @@ public class RecordCategoryTest extends BaseRestTest
.build(); .build();
//create the invalid node type //create the invalid node type
filePlanComponentAPI.createFilePlanComponent(recordCategory, category.getId()); getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, category.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
@@ -405,20 +382,20 @@ public class RecordCategoryTest extends BaseRestTest
* @return The created file plan component * @return The created file plan component
* @throws Exception * @throws Exception
*/ */
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType) throws Exception private FilePlanComponent createComponent(String parentComponentId, String componentName, String componentType) throws Exception
{ {
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Build node properties
//Build node properties
FilePlanComponent component = FilePlanComponent.builder() FilePlanComponent component = FilePlanComponent.builder()
.name(componentName) .name(componentName)
.nodeType(componentType.toString()) .nodeType(componentType)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.title("Title for " + componentName) .title("Title for " + componentName)
.build()) .build())
.build(); .build();
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(component, parentComponentId); FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(component, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
return fpc;
return filePlanComponent;
} }
} }

View File

@@ -49,17 +49,14 @@ import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.base.TestData; import org.alfresco.rest.rm.community.base.TestData;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentReviewPeriod;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.model.fileplancomponents.ReviewPeriod; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.report.Bug; import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@@ -70,15 +67,9 @@ import org.testng.annotations.Test;
* @author Rodica Sutu * @author Rodica Sutu
* @since 2.6 * @since 2.6
*/ */
public class RecordFolderTests extends BaseRestTest public class RecordFolderTests extends BaseRMRestTest
{ {
@Autowired private static final int NUMBER_OF_FOLDERS = 5;
public FilePlanComponentAPI filePlanComponentAPI;
@Autowired
public DataUser dataUser;
private static final int NUMBER_OF_FOLDERS= 5;
/** /**
* Given that a record category exists * Given that a record category exists
* When I use the API to create a new record folder * When I use the API to create a new record folder
@@ -91,23 +82,22 @@ public class RecordFolderTests extends BaseRestTest
public void createFolderTest() throws Exception public void createFolderTest() throws Exception
{ {
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user // Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent filePlanComponent = createCategory(FILE_PLAN_ALIAS, CATEGORY);
FilePlanComponent filePlanComponent = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent recordFolder = FilePlanComponent.builder() FilePlanComponent recordFolder = FilePlanComponent.builder()
.name(FOLDER_NAME) .name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString()) .nodeType(RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.title(FOLDER_TITLE) .title(FOLDER_TITLE)
.build()) .build())
.build(); .build();
// Create the record folder // Create the record folder
FilePlanComponent folder = filePlanComponentAPI.createFilePlanComponent(recordFolder, filePlanComponent.getId()); FilePlanComponent folder = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordFolder, filePlanComponent.getId());
assertStatusCode(CREATED);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
// Check folder has been created within the category created // Check folder has been created within the category created
assertEquals(filePlanComponent.getId(),folder.getParentId()); assertEquals(filePlanComponent.getId(),folder.getParentId());
@@ -117,8 +107,8 @@ public class RecordFolderTests extends BaseRestTest
assertTrue(folder.getIsRecordFolder()); assertTrue(folder.getIsRecordFolder());
assertEquals(folder.getName(), FOLDER_NAME); assertEquals(folder.getName(), FOLDER_NAME);
assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE.toString()); assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE);
assertEquals(folder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); assertEquals(folder.getCreatedByUser().getId(), getAdminUser().getUsername());
// Verify the returned file plan component properties // Verify the returned file plan component properties
FilePlanComponentProperties folderProperties = folder.getProperties(); FilePlanComponentProperties folderProperties = folder.getProperties();
@@ -139,25 +129,23 @@ public class RecordFolderTests extends BaseRestTest
@Bug(id="RM-4327") @Bug(id="RM-4327")
public void createFolderIntoSpecialContainers(String filePlanComponent) throws Exception public void createFolderIntoSpecialContainers(String filePlanComponent) throws Exception
{ {
// Authenticate with admin user FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); String componentID = filePlanComponentsAPI.getFilePlanComponent(filePlanComponent).getId();
String componentID = filePlanComponentAPI.getFilePlanComponent(filePlanComponent).getId();
// Build the record category properties // Build the record category properties
FilePlanComponent recordFolder = FilePlanComponent.builder() FilePlanComponent recordFolder = FilePlanComponent.builder()
.name(FOLDER_NAME) .name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString()) .nodeType(RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.title(FOLDER_TITLE) .title(FOLDER_TITLE)
.build()) .build())
.build(); .build();
// Create a record folder // Create a record folder
filePlanComponentAPI.createFilePlanComponent(recordFolder, componentID); filePlanComponentsAPI.createFilePlanComponent(recordFolder, componentID);
// Check the API Response code // Check the API Response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
/** /**
@@ -172,25 +160,23 @@ public class RecordFolderTests extends BaseRestTest
public void checkTheRecordFolderProperties() throws Exception public void checkTheRecordFolderProperties() throws Exception
{ {
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder = createFolder(category.getId(),FOLDER_NAME); FilePlanComponent folder = createFolder(category.getId(),FOLDER_NAME);
FilePlanComponent folderDetails = filePlanComponentAPI.withParams("include="+IS_CLOSED).getFilePlanComponent(folder.getId()); FilePlanComponent folderDetails = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(folder.getId(), "include=" + IS_CLOSED);
// Verify the returned properties for the file plan component - record folder // Verify the returned properties for the file plan component - record folder
assertEquals(RECORD_FOLDER_TYPE.toString(),folderDetails.getNodeType()); assertEquals(RECORD_FOLDER_TYPE, folderDetails.getNodeType());
assertTrue(folderDetails.getIsRecordFolder()); assertTrue(folderDetails.getIsRecordFolder());
assertFalse(folderDetails.getIsCategory()); assertFalse(folderDetails.getIsCategory());
assertFalse(folderDetails.getIsFile()); assertFalse(folderDetails.getIsFile());
assertFalse(folderDetails.getIsClosed()); assertFalse(folderDetails.getIsClosed());
assertEquals(FOLDER_NAME,folderDetails.getName()); assertEquals(FOLDER_NAME,folderDetails.getName());
assertEquals(dataUser.getAdminUser().getUsername(),folderDetails.getCreatedByUser().getId()); assertEquals(getAdminUser().getUsername(),folderDetails.getCreatedByUser().getId());
assertEquals(dataUser.getAdminUser().getUsername(), folderDetails.getModifiedByUser().getId()); assertEquals(getAdminUser().getUsername(), folderDetails.getModifiedByUser().getId());
assertEquals(FOLDER_TITLE,folderDetails.getProperties().getTitle()); assertEquals(FOLDER_TITLE,folderDetails.getProperties().getTitle());
} }
@@ -208,10 +194,9 @@ public class RecordFolderTests extends BaseRestTest
public void updateTheRecordFolderProperties() throws Exception public void updateTheRecordFolderProperties() throws Exception
{ {
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//Create a record category //Create a record category
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
//Create a record folder //Create a record folder
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME); FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
@@ -229,16 +214,16 @@ public class RecordFolderTests extends BaseRestTest
.title(folderTitle) .title(folderTitle)
.description(folderDescription) .description(folderDescription)
.vitalRecord(true) .vitalRecord(true)
.reviewPeriod(new ReviewPeriod("month","1")) .reviewPeriod(new FilePlanComponentReviewPeriod("month","1"))
.location(location) .location(location)
.build()) .build())
.build(); .build();
// Update the record category // Update the record category
FilePlanComponent folderUpdated = filePlanComponentAPI.updateFilePlanComponent(recordFolder, folder.getId()); FilePlanComponent folderUpdated = getRestAPIFactory().getFilePlanComponentsAPI().updateFilePlanComponent(recordFolder, folder.getId());
// Check the Response Status Code // Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); assertStatusCode(OK);
// Verify the returned properties for the file plan component - record folder // Verify the returned properties for the file plan component - record folder
assertEquals(folderName, folderUpdated.getName()); assertEquals(folderName, folderUpdated.getName());
@@ -264,22 +249,22 @@ public class RecordFolderTests extends BaseRestTest
{ {
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the record category // Create the record category
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
// Create the record folder // Create the record folder
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME); FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
// Delete the Record folder // Delete the Record folder
filePlanComponentAPI.deleteFilePlanComponent(folder.getId()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
filePlanComponentsAPI.deleteFilePlanComponent(folder.getId());
// Check the Response Status Code // Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NO_CONTENT); assertStatusCode(NO_CONTENT);
// Check the File Plan Component is not found // Check the File Plan Component is not found
filePlanComponentAPI.getFilePlanComponent(folder.getId()); filePlanComponentsAPI.getFilePlanComponent(folder.getId());
// Check the Response Status Code // Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); assertStatusCode(NOT_FOUND);
} }
/** /**
@@ -299,8 +284,7 @@ public class RecordFolderTests extends BaseRestTest
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user // Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
// Add child olders // Add child olders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>(); ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
@@ -313,19 +297,16 @@ public class RecordFolderTests extends BaseRestTest
children.add(child); children.add(child);
} }
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// List children from API // List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(category.getId()); FilePlanComponentsCollection apiChildren = getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(category.getId());
// Check status code // Check status code
restWrapper.assertStatusCodeIs(OK); assertStatusCode(OK);
// Check listed children against created list // Check listed children against created list
apiChildren.getEntries().forEach(c -> apiChildren.getEntries().forEach(c ->
{ {
FilePlanComponent filePlanComponent = c.getFilePlanComponent(); FilePlanComponent filePlanComponent = c.getFilePlanComponentModel();
assertNotNull(filePlanComponent.getId()); assertNotNull(filePlanComponent.getId());
logger.info("Checking child " + filePlanComponent.getId()); logger.info("Checking child " + filePlanComponent.getId());
@@ -338,7 +319,7 @@ public class RecordFolderTests extends BaseRestTest
.get(); .get();
// Created by // Created by
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
// Is parent Id set correctly // Is parent Id set correctly
assertEquals(filePlanComponent.getParentId(), category.getId()); assertEquals(filePlanComponent.getParentId(), category.getId());
@@ -376,21 +357,20 @@ public class RecordFolderTests extends BaseRestTest
public void createFolderWithRelativePath() throws Exception public void createFolderWithRelativePath() throws Exception
{ {
//RelativePath specify the container structure to create relative to the record folder to be created //RelativePath specify the container structure to create relative to the record folder to be created
String RELATIVE_PATH = LocalDateTime.now().getYear()+"/"+ LocalDateTime.now().getMonth()+"/"+ LocalDateTime.now().getDayOfMonth(); String relativePath = LocalDateTime.now().getYear() + "/" + LocalDateTime.now().getMonth() + "/" + LocalDateTime.now().getDayOfMonth();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
//The record folder to be created //The record folder to be created
FilePlanComponent recordFolder = FilePlanComponent.builder() FilePlanComponent recordFolder = FilePlanComponent.builder()
.name(FOLDER_NAME) .name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString()) .nodeType(RECORD_FOLDER_TYPE)
.relativePath(RELATIVE_PATH) .relativePath(relativePath)
.build(); .build();
// Create the record folder // Create the record folder
FilePlanComponent folder = filePlanComponentAPI.withParams("include="+ PATH).createFilePlanComponent(recordFolder,FILE_PLAN_ALIAS.toString()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent folder = filePlanComponentsAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS, "include=" + PATH);
//Check the API response code //Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// Verify the returned properties for the file plan component - record folder // Verify the returned properties for the file plan component - record folder
assertFalse(folder.getIsCategory()); assertFalse(folder.getIsCategory());
@@ -398,35 +378,35 @@ public class RecordFolderTests extends BaseRestTest
assertTrue(folder.getIsRecordFolder()); assertTrue(folder.getIsRecordFolder());
//Check the path return contains the RELATIVE_PATH //Check the path return contains the RELATIVE_PATH
assertTrue(folder.getPath().getName().contains(RELATIVE_PATH)); assertTrue(folder.getPath().getName().contains(relativePath));
//check the parent is a category //check the parent is a category
assertTrue(filePlanComponentAPI.getFilePlanComponent(folder.getParentId()).getIsCategory()); assertTrue(filePlanComponentsAPI.getFilePlanComponent(folder.getParentId()).getIsCategory());
//check the created folder from the server //check the created folder from the server
folder=filePlanComponentAPI.withParams("include=" + PATH).getFilePlanComponent(folder.getId()); folder = filePlanComponentsAPI.getFilePlanComponent(folder.getId(), "include=" + PATH);
//Check the API response code //Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); assertStatusCode(OK);
// Verify the returned properties for the file plan component - record folder // Verify the returned properties for the file plan component - record folder
assertFalse(folder.getIsCategory()); assertFalse(folder.getIsCategory());
assertFalse(folder.getIsFile()); assertFalse(folder.getIsFile());
assertTrue(folder.getIsRecordFolder()); assertTrue(folder.getIsRecordFolder());
//Check the path return contains the RELATIVE_PATH //Check the path return contains the RELATIVE_PATH
assertTrue(folder.getPath().getName().contains(RELATIVE_PATH)); assertTrue(folder.getPath().getName().contains(relativePath));
//New Relative Path only a part of containers need to be created before the record folder //New Relative Path only a part of containers need to be created before the record folder
String NEW_RELATIVE_PATH = LocalDateTime.now().getYear() + "/" + LocalDateTime.now().getMonth() + "/" +( LocalDateTime.now().getDayOfMonth()+1); String NEW_RELATIVE_PATH = LocalDateTime.now().getYear() + "/" + LocalDateTime.now().getMonth() + "/" + (LocalDateTime.now().getDayOfMonth() + 1);
//The record folder to be created //The record folder to be created
FilePlanComponent recordFolder2 = FilePlanComponent.builder() FilePlanComponent recordFolder2 = FilePlanComponent.builder()
.name(FOLDER_NAME) .name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString()) .nodeType(RECORD_FOLDER_TYPE)
.relativePath(NEW_RELATIVE_PATH) .relativePath(NEW_RELATIVE_PATH)
.build(); .build();
// Create the record folder // Create the record folder
FilePlanComponent folder2 = filePlanComponentAPI.withParams("include=" + PATH).createFilePlanComponent(recordFolder2, FILE_PLAN_ALIAS.toString()); FilePlanComponent folder2 = filePlanComponentsAPI.createFilePlanComponent(recordFolder2, FILE_PLAN_ALIAS, "include=" + PATH);
//Check the API response code //Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// Verify the returned properties for the file plan component - record folder // Verify the returned properties for the file plan component - record folder
assertFalse(folder2.getIsCategory()); assertFalse(folder2.getIsCategory());
@@ -436,12 +416,12 @@ public class RecordFolderTests extends BaseRestTest
assertTrue(folder2.getPath().getName().contains(NEW_RELATIVE_PATH)); assertTrue(folder2.getPath().getName().contains(NEW_RELATIVE_PATH));
//check the parent is a category //check the parent is a category
assertTrue(filePlanComponentAPI.getFilePlanComponent(folder.getParentId()).getIsCategory()); assertTrue(filePlanComponentsAPI.getFilePlanComponent(folder.getParentId()).getIsCategory());
// Check the folder created on the server // Check the folder created on the server
folder2 = filePlanComponentAPI.withParams("include=" + PATH).getFilePlanComponent(folder2.getId()); folder2 = filePlanComponentsAPI.getFilePlanComponent(folder2.getId(), "include=" + PATH);
//Check the API response code //Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); assertStatusCode(OK);
// Verify the returned properties for the file plan component - record folder // Verify the returned properties for the file plan component - record folder
assertFalse(folder2.getIsCategory()); assertFalse(folder2.getIsCategory());
@@ -454,12 +434,12 @@ public class RecordFolderTests extends BaseRestTest
@AfterClass (alwaysRun = true) @AfterClass (alwaysRun = true)
public void tearDown() throws Exception public void tearDown() throws Exception
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
filePlanComponentAPI.listChildComponents(FILE_PLAN_ALIAS.toString()).getEntries().forEach(filePlanComponentEntry -> filePlanComponentsAPI.listChildComponents(FILE_PLAN_ALIAS).getEntries().forEach(filePlanComponentEntry ->
{ {
try try
{ {
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponent().getId()); filePlanComponentsAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponentModel().getId());
} }
catch (Exception e) catch (Exception e)
{ {
@@ -467,7 +447,4 @@ public class RecordFolderTests extends BaseRestTest
} }
}); });
} }
} }

View File

@@ -48,15 +48,11 @@ import static org.testng.Assert.assertTrue;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
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.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@@ -66,27 +62,23 @@ import org.testng.annotations.Test;
* @author Kristijan Conkas * @author Kristijan Conkas
* @since 2.6 * @since 2.6
*/ */
public class UnfiledRecordsFolderTests extends BaseRestTest public class UnfiledRecordsFolderTests extends BaseRMRestTest
{ {
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
/** invalid root level types, at unfiled records root level these shouldn't be possible to create */ /** invalid root level types, at unfiled records root level these shouldn't be possible to create */
@DataProvider(name = "invalidRootTypes") @DataProvider(name = "invalidRootTypes")
public Object[][] createData1() { public Object[][] createData1()
return new Object[][] { {
{ FILE_PLAN_TYPE }, return new Object[][]
{ RECORD_CATEGORY_TYPE }, {
{ RECORD_FOLDER_TYPE }, { FILE_PLAN_TYPE },
{ HOLD_TYPE }, { RECORD_CATEGORY_TYPE },
{ HOLD_CONTAINER_TYPE }, { RECORD_FOLDER_TYPE },
{ TRANSFER_CONTAINER_TYPE }, { HOLD_TYPE },
{ UNFILED_CONTAINER_TYPE } { HOLD_CONTAINER_TYPE },
}; { TRANSFER_CONTAINER_TYPE },
{ UNFILED_CONTAINER_TYPE }
};
} }
/** /**
@@ -99,9 +91,6 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
@Test(description = "Create root unfiled records folder") @Test(description = "Create root unfiled records folder")
public void createRootUnfiledRecordsFolder() throws Exception public void createRootUnfiledRecordsFolder() throws Exception
{ {
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String folderName = "Folder " + getRandomAlphanumeric(); String folderName = "Folder " + getRandomAlphanumeric();
String folderTitle = folderName + " Title"; String folderTitle = folderName + " Title";
String folderDescription = folderName + " Description"; String folderDescription = folderName + " Description";
@@ -109,18 +98,17 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
// Build unfiled records folder properties // Build unfiled records folder properties
FilePlanComponent unfiledFolder = FilePlanComponent.builder() FilePlanComponent unfiledFolder = FilePlanComponent.builder()
.name(folderName) .name(folderName)
.nodeType(UNFILED_RECORD_FOLDER_TYPE.toString()) .nodeType(UNFILED_RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.title(folderTitle) .title(folderTitle)
.description(folderDescription) .description(folderDescription)
.build()) .build())
.build(); .build();
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(unfiledFolder, FilePlanComponent filePlanComponent = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(unfiledFolder, UNFILED_RECORDS_CONTAINER_ALIAS);
UNFILED_RECORDS_CONTAINER_ALIAS.toString());
// Verify the status code // Verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// Verify the returned file plan component // Verify the returned file plan component
assertFalse(filePlanComponent.getIsCategory()); assertFalse(filePlanComponent.getIsCategory());
@@ -128,9 +116,9 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
assertFalse(filePlanComponent.getIsRecordFolder()); // it is not a _normal_ record folder! assertFalse(filePlanComponent.getIsRecordFolder()); // it is not a _normal_ record folder!
assertEquals(filePlanComponent.getName(), folderName); assertEquals(filePlanComponent.getName(), folderName);
assertEquals(filePlanComponent.getNodeType(), UNFILED_RECORD_FOLDER_TYPE.toString()); assertEquals(filePlanComponent.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername());
// Verify the returned file plan component properties // Verify the returned file plan component properties
FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties(); FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
@@ -146,20 +134,18 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
dataProvider = "invalidRootTypes", dataProvider = "invalidRootTypes",
description = "Only unfiled records folders can be created at unfiled records root level" description = "Only unfiled records folders can be created at unfiled records root level"
) )
public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(FilePlanComponentType componentType) public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(String filePlanComponentType)
{ {
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String folderName = "Folder " + getRandomAlphanumeric(); String folderName = "Folder " + getRandomAlphanumeric();
String folderTitle = folderName + " Title"; String folderTitle = folderName + " Title";
String folderDescription = folderName + " Description"; String folderDescription = folderName + " Description";
logger.info("creating " + componentType.toString()); logger.info("creating " + filePlanComponentType);
// Build unfiled records folder properties // Build unfiled records folder properties
FilePlanComponent unfiledFolder = FilePlanComponent.builder() FilePlanComponent unfiledFolder = FilePlanComponent.builder()
.name(folderName) .name(folderName)
.nodeType(componentType.toString()) .nodeType(filePlanComponentType)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.title(folderTitle) .title(folderTitle)
.description(folderDescription) .description(folderDescription)
@@ -168,15 +154,14 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
try try
{ {
filePlanComponentAPI.createFilePlanComponent(unfiledFolder, getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(unfiledFolder, UNFILED_RECORDS_CONTAINER_ALIAS);
UNFILED_RECORDS_CONTAINER_ALIAS.toString());
} }
catch (Exception error) catch (Exception error)
{ {
} }
// Verify the status code // Verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); assertStatusCode(UNPROCESSABLE_ENTITY);
} }
/** /**
@@ -189,21 +174,19 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
@Test(description = "Child unfiled records folder can be created in a parent unfiled records folder") @Test(description = "Child unfiled records folder can be created in a parent unfiled records folder")
public void childUnfiledRecordsFolderCanBeCreated() throws Exception public void childUnfiledRecordsFolderCanBeCreated() throws Exception
{ {
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String parentFolderName = "Parent Folder " + getRandomAlphanumeric(); String parentFolderName = "Parent Folder " + getRandomAlphanumeric();
String childFolderName = "Child Folder " + getRandomAlphanumeric(); String childFolderName = "Child Folder " + getRandomAlphanumeric();
String childFolderTitle = childFolderName + " Title"; String childFolderTitle = childFolderName + " Title";
String childFolderDescription = childFolderName + " Description"; String childFolderDescription = childFolderName + " Description";
// No need for fine control, create it using utility function // No need for fine control, create it using utility function
FilePlanComponent parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), parentFolderName); FilePlanComponent parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, parentFolderName);
assertEquals(parentFolderName, parentFolder.getName()); assertEquals(parentFolderName, parentFolder.getName());
// Build the unfiled records folder properties // Build the unfiled records folder properties
FilePlanComponent unfiledFolder = FilePlanComponent.builder() FilePlanComponent unfiledFolder = FilePlanComponent.builder()
.name(childFolderName) .name(childFolderName)
.nodeType(UNFILED_RECORD_FOLDER_TYPE.toString()) .nodeType(UNFILED_RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder() .properties(FilePlanComponentProperties.builder()
.title(childFolderTitle) .title(childFolderTitle)
.description(childFolderDescription) .description(childFolderDescription)
@@ -211,11 +194,11 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
.build(); .build();
// Create it as a child of parentFolder // Create it as a child of parentFolder
FilePlanComponent childFolder = filePlanComponentAPI.createFilePlanComponent(unfiledFolder, FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
parentFolder.getId()); FilePlanComponent childFolder = filePlanComponentsAPI.createFilePlanComponent(unfiledFolder, parentFolder.getId());
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// Verify the returned file plan component // Verify the returned file plan component
assertFalse(childFolder.getIsCategory()); assertFalse(childFolder.getIsCategory());
@@ -223,8 +206,8 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
assertFalse(childFolder.getIsRecordFolder()); // it is not a _normal_ record folder! assertFalse(childFolder.getIsRecordFolder()); // it is not a _normal_ record folder!
assertEquals(childFolder.getName(), childFolderName); assertEquals(childFolder.getName(), childFolderName);
assertEquals(childFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE.toString()); assertEquals(childFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
assertEquals(childFolder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); assertEquals(childFolder.getCreatedByUser().getId(), getAdminUser().getUsername());
// Verify the returned file plan component properties // Verify the returned file plan component properties
FilePlanComponentProperties childProperties = childFolder.getProperties(); FilePlanComponentProperties childProperties = childFolder.getProperties();
@@ -236,11 +219,11 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
// Does child's parent point to it? // Does child's parent point to it?
// Perform another call as our parentFolder had been executed before childFolder existed // Perform another call as our parentFolder had been executed before childFolder existed
FilePlanComponentsCollection parentsChildren = filePlanComponentAPI.listChildComponents(parentFolder.getId()); FilePlanComponentsCollection parentsChildren = filePlanComponentsAPI.listChildComponents(parentFolder.getId());
restWrapper.assertStatusCodeIs(OK); assertStatusCode(OK);
List<String> childIds = parentsChildren.getEntries() List<String> childIds = parentsChildren.getEntries()
.stream() .stream()
.map(c -> c.getFilePlanComponent().getId()) .map(c -> c.getFilePlanComponentModel().getId())
.collect(Collectors.toList()); .collect(Collectors.toList());
// Child folder is listed in parent // Child folder is listed in parent
@@ -260,12 +243,11 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
@Test(description = "Unfiled record folder") @Test(description = "Unfiled record folder")
public void editUnfiledRecordsFolder() throws Exception public void editUnfiledRecordsFolder() throws Exception
{ {
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String modified = "Modified "; String modified = "Modified ";
String folderName = "Folder To Modify" + getRandomAlphanumeric(); String folderName = "Folder To Modify" + getRandomAlphanumeric();
// No need for fine control, create it using utility function // No need for fine control, create it using utility function
FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName); FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, folderName);
assertEquals(folderName, folderToModify.getName()); assertEquals(folderName, folderToModify.getName());
// Build the properties which will be updated // Build the properties which will be updated
@@ -278,12 +260,13 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
.build(); .build();
// Update the unfiled records folder // Update the unfiled records folder
filePlanComponentAPI.updateFilePlanComponent(folderToUpdate, folderToModify.getId()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
filePlanComponentsAPI.updateFilePlanComponent(folderToUpdate, folderToModify.getId());
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(OK); assertStatusCode(OK);
// This is to ensure the change was actually applied, rather than simply trusting the object returned by PUT // This is to ensure the change was actually applied, rather than simply trusting the object returned by PUT
FilePlanComponent renamedFolder = filePlanComponentAPI.getFilePlanComponent(folderToModify.getId()); FilePlanComponent renamedFolder = filePlanComponentsAPI.getFilePlanComponent(folderToModify.getId());
// Verify the returned file plan component // Verify the returned file plan component
assertEquals(modified + folderToModify.getName(), renamedFolder.getName()); assertEquals(modified + folderToModify.getName(), renamedFolder.getName());
@@ -301,21 +284,21 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
@Test(description = "Delete unfiled record folder") @Test(description = "Delete unfiled record folder")
public void deleteUnfiledRecordsFolder() throws Exception public void deleteUnfiledRecordsFolder() throws Exception
{ {
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String folderName = "Folder To Delete" + getRandomAlphanumeric(); String folderName = "Folder To Delete" + getRandomAlphanumeric();
// Create folderToDelete // Create folderToDelete
FilePlanComponent folderToDelete = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName); FilePlanComponent folderToDelete = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, folderName);
assertEquals(folderName, folderToDelete.getName()); assertEquals(folderName, folderToDelete.getName());
// Delete folderToDelete // Delete folderToDelete
filePlanComponentAPI.deleteFilePlanComponent(folderToDelete.getId()); FilePlanComponentAPI filePlanComponentsAPI = getRestAPIFactory().getFilePlanComponentsAPI();
filePlanComponentsAPI.deleteFilePlanComponent(folderToDelete.getId());
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT); assertStatusCode(NO_CONTENT);
// Deleted component should no longer be retrievable // Deleted component should no longer be retrievable
filePlanComponentAPI.getFilePlanComponent(folderToDelete.getId()); filePlanComponentsAPI.getFilePlanComponent(folderToDelete.getId());
restWrapper.assertStatusCodeIs(NOT_FOUND); assertStatusCode(NOT_FOUND);
} }
} }

View File

@@ -27,10 +27,16 @@
package org.alfresco.rest.rm.community.site; package org.alfresco.rest.rm.community.site;
import static org.alfresco.rest.rm.community.base.TestData.ANOTHER_ADMIN; import static org.alfresco.rest.rm.community.base.TestData.ANOTHER_ADMIN;
import static org.alfresco.rest.rm.community.base.TestData.DEFAULT_EMAIL;
import static org.alfresco.rest.rm.community.base.TestData.DEFAULT_PASSWORD; import static org.alfresco.rest.rm.community.base.TestData.DEFAULT_PASSWORD;
import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.DOD5015; import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.DOD5015;
import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.STANDARD; import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.STANDARD;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.RM_DESCRIPTION;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.RM_ID;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.RM_TITLE;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createDOD5015RMSiteModel;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createRMSiteModel;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createStandardRMSiteModel;
import static org.alfresco.utility.constants.UserRole.SiteManager;
import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CONFLICT;
import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.CREATED;
@@ -42,13 +48,10 @@ import static org.springframework.social.alfresco.api.entities.Site.Visibility.P
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import org.alfresco.dataprep.UserService; import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.model.site.RMSite; import org.alfresco.rest.rm.community.model.site.RMSite;
import org.alfresco.rest.rm.community.requests.RMSiteAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI;
import org.alfresco.utility.constants.UserRole; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMUserAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData; import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug; import org.alfresco.utility.report.Bug;
@@ -62,16 +65,10 @@ import org.testng.annotations.Test;
* @author Rodica Sutu * @author Rodica Sutu
* @since 2.6 * @since 2.6
*/ */
public class RMSiteTests extends BaseRestTest public class RMSiteTests extends BaseRMRestTest
{ {
@Autowired @Autowired
private UserService userService; private RMUserAPI rmUserAPI;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
/** /**
* Given that RM module is installed * Given that RM module is installed
@@ -84,8 +81,7 @@ public class RMSiteTests extends BaseRestTest
) )
public void createRMSiteAsAdminUser() throws Exception public void createRMSiteAsAdminUser() throws Exception
{ {
// Authenticate with admin user RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists // Check if the RM site exists
if (rmSiteAPI.existsRMSite()) if (rmSiteAPI.existsRMSite())
@@ -95,14 +91,10 @@ public class RMSiteTests extends BaseRestTest
} }
// Create the RM site // Create the RM site
RMSite rmSite =RMSite.builder().compliance(STANDARD).build(); RMSite rmSiteResponse = rmSiteAPI.createRMSite(createStandardRMSiteModel());
rmSite.setTitle(RM_TITLE);
rmSite.setDescription(RM_DESCRIPTION);
RMSite rmSiteResponse = rmSiteAPI.createRMSite(rmSite);
// Verify the status code // Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// Verify the returned file plan component // Verify the returned file plan component
assertEquals(rmSiteResponse.getId(), RM_ID); assertEquals(rmSiteResponse.getId(), RM_ID);
@@ -110,7 +102,7 @@ public class RMSiteTests extends BaseRestTest
assertEquals(rmSiteResponse.getDescription(), RM_DESCRIPTION); assertEquals(rmSiteResponse.getDescription(), RM_DESCRIPTION);
assertEquals(rmSiteResponse.getCompliance(), STANDARD); assertEquals(rmSiteResponse.getCompliance(), STANDARD);
assertEquals(rmSiteResponse.getVisibility(), PUBLIC); assertEquals(rmSiteResponse.getVisibility(), PUBLIC);
assertEquals(rmSiteResponse.getRole(), UserRole.SiteManager.toString()); assertEquals(rmSiteResponse.getRole(), SiteManager.toString());
} }
/** /**
@@ -127,22 +119,16 @@ public class RMSiteTests extends BaseRestTest
// Create the RM site if it does not exist // Create the RM site if it does not exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Construct new properties // Construct new properties
String newTitle = RM_TITLE + "createRMSiteWhenSiteExists"; String newTitle = RM_TITLE + "createRMSiteWhenSiteExists";
String newDescription = RM_DESCRIPTION + "createRMSiteWhenSiteExists"; String newDescription = RM_DESCRIPTION + "createRMSiteWhenSiteExists";
// Create the RM site // Create the RM site
RMSite rmSite = RMSite.builder().compliance(STANDARD).build(); RMSite rmSiteModel = createRMSiteModel(STANDARD, newTitle, newDescription);
rmSite.setTitle(newTitle); getRestAPIFactory().getRMSiteAPI().createRMSite(rmSiteModel);
rmSite.setDescription(newDescription);
rmSiteAPI.createRMSite(rmSite);
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(CONFLICT); assertStatusCode(CONFLICT);
} }
/** /**
@@ -156,14 +142,14 @@ public class RMSiteTests extends BaseRestTest
) )
public void deleteRMSite() throws Exception public void deleteRMSite() throws Exception
{ {
// Authenticate with admin user // Create the RM site if it does not exist
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); createRMSiteIfNotExists();
// Delete the RM site // Delete the RM site
rmSiteAPI.deleteRMSite(); getRestAPIFactory().getRMSiteAPI().deleteRMSite();
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT); assertStatusCode(NO_CONTENT);
} }
/** /**
@@ -177,27 +163,26 @@ public class RMSiteTests extends BaseRestTest
) )
public void getRMSite() throws Exception public void getRMSite() throws Exception
{ {
// Authenticate with admin user RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Check if RM site exists // Check if RM site exists
if (!rmSiteAPI.existsRMSite()) if (!rmSiteAPI.existsRMSite())
{ {
// Verify the status code when RM site doesn't exist // Verify the status code when RM site doesn't exist
restWrapper.assertStatusCodeIs(NOT_FOUND); assertStatusCode(NOT_FOUND);
createRMSiteIfNotExists(); createRMSiteIfNotExists();
} }
else else
{ {
// Get the RM site // Get the RM site
RMSite rmSite = rmSiteAPI.getSite(); RMSite rmSiteModel = rmSiteAPI.getSite();
// Verify the status code // Verify the status code
restWrapper.assertStatusCodeIs(OK); assertStatusCode(OK);
assertEquals(rmSite.getId(), RM_ID); assertEquals(rmSiteModel.getId(), RM_ID);
assertEquals(rmSite.getDescription(), RM_DESCRIPTION); assertEquals(rmSiteModel.getDescription(), RM_DESCRIPTION);
assertEquals(rmSite.getCompliance(), STANDARD); assertEquals(rmSiteModel.getCompliance(), STANDARD);
assertEquals(rmSite.getVisibility(), PUBLIC); assertEquals(rmSiteModel.getVisibility(), PUBLIC);
} }
} }
@@ -213,8 +198,7 @@ public class RMSiteTests extends BaseRestTest
@Bug (id="RM-4289") @Bug (id="RM-4289")
public void createRMSiteAsAnotherAdminUser() throws Exception public void createRMSiteAsAnotherAdminUser() throws Exception
{ {
// Authenticate with admin user RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI();
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists // Check if the RM site exists
if (rmSiteAPI.existsRMSite()) if (rmSiteAPI.existsRMSite())
@@ -223,40 +207,22 @@ public class RMSiteTests extends BaseRestTest
rmSiteAPI.deleteRMSite(); rmSiteAPI.deleteRMSite();
} }
// Disconnect the current user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Create user // Create user
userService.create(dataUser.getAdminUser().getUsername(), rmUserAPI.createUser(ANOTHER_ADMIN);
dataUser.getAdminUser().getPassword(),
ANOTHER_ADMIN,
DEFAULT_PASSWORD,
DEFAULT_EMAIL,
ANOTHER_ADMIN,
ANOTHER_ADMIN);
// Build the user model
UserModel userModel = new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD);
// Authenticate as that new user
rmSiteAPI.usingRestWrapper().authenticateUser(userModel);
// Create the RM site // Create the RM site
RMSite rmSite = RMSite.builder().compliance(DOD5015).build(); RMSite rmSiteModel = getRestAPIFactory().getRMSiteAPI(new UserModel(ANOTHER_ADMIN, DEFAULT_PASSWORD)).createRMSite(createDOD5015RMSiteModel());
rmSite.setTitle(RM_TITLE);
rmSite.setDescription(RM_DESCRIPTION);
rmSite=rmSiteAPI.createRMSite(rmSite);
// Verify the status code // Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); assertStatusCode(CREATED);
// Verify the returned file plan component // Verify the returned file plan component
assertEquals(rmSite.getId(), RM_ID); assertEquals(rmSiteModel.getId(), RM_ID);
assertEquals(rmSite.getTitle(), RM_TITLE); assertEquals(rmSiteModel.getTitle(), RM_TITLE);
assertEquals(rmSite.getDescription(), RM_DESCRIPTION); assertEquals(rmSiteModel.getDescription(), RM_DESCRIPTION);
assertEquals(rmSite.getCompliance(), DOD5015); assertEquals(rmSiteModel.getCompliance(), DOD5015);
assertEquals(rmSite.getVisibility(), PUBLIC); assertEquals(rmSiteModel.getVisibility(), PUBLIC);
assertEquals(rmSite.getRole(), UserRole.SiteManager.toString()); assertEquals(rmSiteModel.getRole(), SiteManager.toString());
} }
/** /**
@@ -267,55 +233,37 @@ public class RMSiteTests extends BaseRestTest
* Then RM site details are updated * Then RM site details are updated
*/ */
@Test @Test
public void updateRMSiteDetails()throws Exception public void updateRMSiteDetails() throws Exception
{ {
String NEW_TITLE = RM_TITLE + RandomData.getRandomAlphanumeric(); String NEW_TITLE = RM_TITLE + RandomData.getRandomAlphanumeric();
String NEW_DESCRIPTION = RM_DESCRIPTION+ RandomData.getRandomAlphanumeric(); String NEW_DESCRIPTION = RM_DESCRIPTION + RandomData.getRandomAlphanumeric();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the site if it does not exist // Create the site if it does not exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
//Create RM site model // Create RM site model
RMSite rmSiteToUpdate = new RMSite(); RMSite rmSiteToUpdate = RMSite.builder().build();
rmSiteToUpdate.setTitle(NEW_TITLE); rmSiteToUpdate.setTitle(NEW_TITLE);
rmSiteToUpdate.setDescription(NEW_DESCRIPTION); rmSiteToUpdate.setDescription(NEW_DESCRIPTION);
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
// Authenticate as that random user
rmSiteAPI.usingRestWrapper().authenticateUser(nonRMuser);
// Create the RM site // Create the RM site
rmSiteAPI.updateRMSite(rmSiteToUpdate); getRestAPIFactory().getRMSiteAPI(getDataUser().createRandomTestUser("testUser")).updateRMSite(rmSiteToUpdate);
// Verify the status code // Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); assertStatusCode(FORBIDDEN);
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Update the RM Site // Update the RM Site
RMSite rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate); RMSite rmSiteModel = getRestAPIFactory().getRMSiteAPI().updateRMSite(rmSiteToUpdate);
// Verify the response status code // Verify the response status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(OK); assertStatusCode(OK);
// Verify the returned file plan component // Verify the returned file plan component
assertEquals(rmSite.getId(), RM_ID); assertEquals(rmSiteModel.getId(), RM_ID);
assertEquals(rmSite.getTitle(), NEW_TITLE); assertEquals(rmSiteModel.getTitle(), NEW_TITLE);
assertEquals(rmSite.getDescription(), NEW_DESCRIPTION); assertEquals(rmSiteModel.getDescription(), NEW_DESCRIPTION);
assertNotNull(rmSite.getCompliance()); assertNotNull(rmSiteModel.getCompliance());
assertEquals(rmSite.getVisibility(), PUBLIC); assertEquals(rmSiteModel.getVisibility(), PUBLIC);
} }
/** /**
@@ -326,19 +274,16 @@ public class RMSiteTests extends BaseRestTest
@Test @Test
public void updateRMSiteComplianceAsAdmin() throws Exception public void updateRMSiteComplianceAsAdmin() throws Exception
{ {
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
// Create the RM site if it does not exist // Create the RM site if it does not exist
createRMSiteIfNotExists(); createRMSiteIfNotExists();
// Build the RM site properties // Build the RM site properties
RMSite rmSiteToUpdate = RMSite.builder().compliance(DOD5015).build(); RMSite rmSiteToUpdate = RMSite.builder().compliance(DOD5015).build();
// Update the RM site // Update the RM site
rmSiteAPI.updateRMSite(rmSiteToUpdate); getRestAPIFactory().getRMSiteAPI().updateRMSite(rmSiteToUpdate);
// Verify the response status code // Verify the response status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); assertStatusCode(BAD_REQUEST);
} }
} }

View File

@@ -0,0 +1,104 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.utils;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
/**
* Utility class for file plan component models
*
* @author Tuna Aksoy
* @since 2.6
*/
public class FilePlanComponentsUtil
{
private FilePlanComponentsUtil()
{
// Intentionally blank
}
/** image resource file to be used for records body */
public static final String IMAGE_FILE = "money.JPG";
/**
* Creates a record model with the given type and a random name (with "Record " prefix)
*
* @param nodeType The node type
* @return The {@link FilePlanComponent} with for the given node type
*/
private static FilePlanComponent createRecordModel(String nodeType)
{
return FilePlanComponent.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(nodeType)
.build();
}
/**
* Creates an electronic record model with a random name (with "Record " prefix)
*
* @return The electronic record as {@link FilePlanComponent}
*/
public static FilePlanComponent createElectronicRecordModel()
{
return createRecordModel(CONTENT_TYPE);
}
/**
* Creates a non-electronic record model with a random name (with "Record " prefix)
*
* @return The non-electronic record as {@link FilePlanComponent}
*/
public static FilePlanComponent createNonElectronicRecordModel()
{
return createRecordModel(NON_ELECTRONIC_RECORD_TYPE);
}
/**
* Creates a file plan component with the given name, type and title
*
* @param name The name of the file plan component
* @param type The type of the file plan component
* @param title The title of the file plan component
* @return The {@link FilePlanComponent} with the given details
*/
public static FilePlanComponent createFilePlanComponentModel(String name, String type, String title)
{
return FilePlanComponent.builder()
.name(name)
.nodeType(type)
.properties(FilePlanComponentProperties.builder()
.title(title)
.build())
.build();
}
}

View File

@@ -0,0 +1,99 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2017 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.utils;
import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.DOD5015;
import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.STANDARD;
import org.alfresco.rest.rm.community.model.site.RMSiteCompliance;
import org.alfresco.rest.rm.community.model.site.RMSite;
/**
* Utility class for the RM Site
*
* @author Tuna Aksoy
* @since 2.6
*/
public class RMSiteUtil
{
private RMSiteUtil()
{
// Intentionally blank
}
/** Constants */
public static final String RM_ID = "rm";
public static final String RM_TITLE = "Records Management";
public static final String RM_DESCRIPTION = "Records Management Site";
/**
* Creates an RM Site model for the given compliance, title and description
*
* @param compliance The RM site compliance
* @param title The site title
* @param description The site description
* @return The {@link RMSite} with the given details
*/
public static RMSite createRMSiteModel(RMSiteCompliance compliance, String title, String description)
{
RMSite rmSiteModel = RMSite.builder().compliance(compliance).build();
rmSiteModel.setTitle(title);
rmSiteModel.setDescription(description);
return rmSiteModel;
}
/**
* Creates an RM Site for the given compliance and default title and description
*
* @param The RM site compliance
* @return The {@link RMSite} with the given details
*/
private static RMSite createRMSiteModel(RMSiteCompliance compliance)
{
return createRMSiteModel(compliance, RM_TITLE, RM_DESCRIPTION);
}
/**
* Creates a standard RM site with the default title and description
*
* @return The standard RM site
*/
public static RMSite createStandardRMSiteModel()
{
return createRMSiteModel(STANDARD);
}
/**
* Creates a DOD5015 compliance RM site with the default title and description
*
* @return The DOD5015 compliance RM site
*/
public static RMSite createDOD5015RMSiteModel()
{
return createRMSiteModel(DOD5015);
}
}