Skip to content

Commit

Permalink
XENOPS-1081 fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
hechmi-dammak-xenit committed Apr 26, 2023
1 parent 3afd1c8 commit 7977862
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
integration-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
alfresco_version: [ 62, 70, 71, 72, 73 ]
steps:
Expand All @@ -50,6 +51,8 @@ jobs:
registry: private.docker.xenit.eu
username: ${{ secrets.CLOUDSMITH_USER }}
password: ${{ secrets.CLOUDSMITH_APIKEY }}
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
- name: Integration test and apix impl test
uses: gradle/gradle-build-action@v2.3.0
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testGetAllNodeInfoOfMultipleNodes() throws IOException, JSONExceptio

@Test
public void testGetAllNodeInfoWithNoNodesListed() throws IOException {
String jsonString = json("{}");
String jsonString = json("");

final CloseableHttpClient httpclient = HttpClients.createDefault();
final String url = makeAlfrescoBaseurl("admin", "admin") + "/apix/v1/nodes/nodeInfo";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package eu.xenit.apix.rest.v1.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import eu.xenit.apix.alfresco.ApixToAlfrescoConversion;
import eu.xenit.apix.data.NodeRef;
import eu.xenit.apix.versionhistory.Version;
import eu.xenit.apix.versionhistory.VersionHistory;
import java.io.IOException;
import java.util.HashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeService;
Expand All @@ -22,6 +15,7 @@
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
Expand All @@ -36,10 +30,17 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.io.IOException;
import java.util.HashMap;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


public class VersionHistoryTest extends RestV1BaseTest {

private final static Logger logger = LoggerFactory.getLogger(VersionHistoryTest.class);
private static final Logger logger = LoggerFactory.getLogger(VersionHistoryTest.class);
@Autowired
@Qualifier("TransactionService")
TransactionService transactionService;
Expand Down Expand Up @@ -119,12 +120,10 @@ public void testSetVersionHistoryWithoutBody() throws IOException {
return null;
}, true, true);

int statusCode = Request.Put(versionHistoryUrl)
HttpResponse response = Request.Put(versionHistoryUrl)
.execute()
.returnResponse()
.getStatusLine()
.getStatusCode();
assertEquals(200, statusCode);
.returnResponse();
assertEquals(200, response.getStatusLine().getStatusCode());

transactionService.getRetryingTransactionHelper()
.doInTransaction(() -> {
Expand Down Expand Up @@ -170,12 +169,12 @@ public void testSetVersionHistoryWithoutBody() throws IOException {

HttpPut httpPut = new HttpPut(versionHistoryUrl2);
httpPut.setEntity(new StringEntity(json(requestBody), ContentType.APPLICATION_JSON));
int statusCode2 = HttpClients.createDefault()
.execute(httpPut)
CloseableHttpResponse httpResponse = HttpClients.createDefault()
.execute(httpPut);
System.out.println(new String(httpResponse.getEntity().getContent().readAllBytes()));
assertEquals(200, httpResponse
.getStatusLine()
.getStatusCode();

assertEquals(200, statusCode2);
.getStatusCode());

transactionService.getRetryingTransactionHelper()
.doInTransaction(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testGetAllNodeInfoOfMultipleNodes() throws IOException, JSONExceptio

@Test
public void testGetAllNodeInfoWithNoNodesListed() throws IOException {
String jsonString = json("{}");
String jsonString = json("");

final CloseableHttpClient httpclient = HttpClients.createDefault();
final String url = makeAlfrescoBaseurl("admin", "admin") + "/apix/v2/nodes/nodeInfo";
Expand Down
5 changes: 4 additions & 1 deletion apix-interface/src/main/java/eu/xenit/apix/data/NodeRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.io.Serializable;

/**
Expand All @@ -14,9 +15,11 @@ public class NodeRef implements Serializable {

private static final String FORWARD_SLASH = "/";
private static final String SPACESTORE_DIVIDER = "://";

private String value;

public NodeRef() {
}

@JsonCreator
public NodeRef(String s) {
value = s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

public class WorkflowOrTaskChanges {
Expand All @@ -13,6 +14,9 @@ public WorkflowOrTaskChanges(@JsonProperty("propertiesToSet") Map<String, String
this.propertiesToSet = propertiesToSet;
}

public WorkflowOrTaskChanges() {
}

public Map<String, String> getPropertiesToSet() {
return propertiesToSet;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package eu.xenit.apix.rest.staging.workflow;

public class WorkflowClaimsBody {
private String id;
private String userName;

public WorkflowClaimsBody(String id, String userName) {
this.id = id;
this.userName = userName;
}

public WorkflowClaimsBody() {
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package eu.xenit.apix.rest.staging.workflow;

public class WorkflowReleaseBody {
private String id;

public WorkflowReleaseBody() {
}

public WorkflowReleaseBody(String id) {
this.id = id;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@Override
public String toString() {
return "WorkflowReleaseBody{" +
"id='" + id + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
import eu.xenit.apix.workflow.search.TaskOrWorkflowSearchResult;
import eu.xenit.apix.workflow.search.TaskSearchQuery;
import eu.xenit.apix.workflow.search.WorkflowSearchQuery;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,6 +24,12 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

@RestController
public class WorkflowWebscript {
private static final Logger logger = LoggerFactory.getLogger(WorkflowWebscript.class);
Expand Down Expand Up @@ -93,7 +94,7 @@ public ResponseEntity<Void> task(@PathVariable final String id) {

@PutMapping(value = "/workflows/{id}")
public ResponseEntity<Workflow> updateWorkflow(@PathVariable final String id,
@RequestBody final WorkflowOrTaskChanges changes) {
@RequestBody final WorkflowOrTaskChanges changes) {
return responseFrom(workflowService.updateWorkflow(id, changes));
}

Expand All @@ -104,8 +105,8 @@ public ResponseEntity<Void> cancelWorkflow(@PathVariable final String id) {
}

@PutMapping(value = "/tasks/{id}")
public ResponseEntity<Task> updateTask(@PathVariable final String id,
@RequestBody final WorkflowOrTaskChanges changes) {
public ResponseEntity<Task> updateTask(@PathVariable final String id,
@RequestBody final WorkflowOrTaskChanges changes) {
try {
return responseFrom(workflowService.updateTask(id, changes));
} catch (Error ex) {
Expand All @@ -114,27 +115,22 @@ public ResponseEntity<Task> updateTask(@PathVariable final String id,
}

@PostMapping(value = "/staging/tasks/claim")
public ResponseEntity<Task> claimTask(@RequestBody final Map<String, String> body) {
logger.debug("Input: {}", body);
String id = body.get("id");
String userName = body.get("userName");

public ResponseEntity<Task> claimTask(@RequestBody final WorkflowClaimsBody workflowClaimsBody) {
Task wfTask;
if (userName != null) {
logger.debug("Setting owner of task with id {} to {}", id, userName);
wfTask = workflowService.claimWorkflowTask(id, userName);
if (workflowClaimsBody.getUserName() != null) {
logger.debug("Setting owner of task with id {} to {}", workflowClaimsBody.getId(), workflowClaimsBody.getUserName());
wfTask = workflowService.claimWorkflowTask(workflowClaimsBody.getId(), workflowClaimsBody.getUserName());
} else {
logger.debug("Setting owner of task with id ");
wfTask = workflowService.claimWorkflowTask(id);
wfTask = workflowService.claimWorkflowTask(workflowClaimsBody.getId());
}
return responseFrom(wfTask);
}

@PostMapping(value = "/staging/tasks/release")
public ResponseEntity<Task> releaseTask(@RequestBody final Map<String, String> body) {
logger.debug("Setting owner of task {}", body);
String id = body.get("id");
Task wfTask = workflowService.releaseWorkflowTask(id);
public ResponseEntity<Task> releaseTask(@RequestBody final WorkflowReleaseBody workflowReleaseBody) {
logger.debug("Setting owner of task {}", workflowReleaseBody);
Task wfTask = workflowService.releaseWorkflowTask(workflowReleaseBody.getId());
return responseFrom(wfTask);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.xenit.apix.rest.v1;


import eu.xenit.apix.data.NodeRef;
import eu.xenit.apix.filefolder.IFileFolderService;
import eu.xenit.apix.node.ChildParentAssociation;
Expand Down Expand Up @@ -63,24 +64,24 @@ protected List<NodeInfo> nodeRefToNodeInfo(NodeInfoRequest nodeInfoRequest,
}

protected NodeInfo nodeRefToNodeInfo(NodeRef nodeRef, IFileFolderService fileFolderService,
INodeService nodeService, IPermissionService permissionService) {
INodeService nodeService, IPermissionService permissionService) {
return nodeRefToNodeInfo(nodeRef, fileFolderService, nodeService, permissionService,
true, true, true, true,
true, true, true, true);
}

protected NodeInfo nodeRefToNodeInfo(NodeRef nodeRef,
IFileFolderService fileFolderService,
INodeService nodeService,
IPermissionService permissionService,
boolean retrievePath,
boolean retrieveMetadata,
boolean retrievePermissions,
boolean retrieveAssocs,
boolean retrieveChildAssocs,
boolean retrieveParentAssocs,
boolean retrieveTargetAssocs,
boolean retrieveSourceAssocs) {
IFileFolderService fileFolderService,
INodeService nodeService,
IPermissionService permissionService,
boolean retrievePath,
boolean retrieveMetadata,
boolean retrievePermissions,
boolean retrieveAssocs,
boolean retrieveChildAssocs,
boolean retrieveParentAssocs,
boolean retrieveTargetAssocs,
boolean retrieveSourceAssocs) {
if (!permissionService.hasPermission(nodeRef, IPermissionService.READ)) {
logger.warn("Excluding node {} from results due to insufficient permissions", nodeRef);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ public class ChangeAclsOptions {
private boolean inheritFromParent;
private Set<Access> ownAccessList;

public ChangeAclsOptions( boolean inheritFromParent,
Set<Access> ownAccessList) {
public ChangeAclsOptions() {
}

@JsonCreator
public ChangeAclsOptions(@JsonProperty("inheritFromParent") boolean inheritFromParent,
@JsonProperty("ownAccessList") Set<Access> ownAccessList) {
this.ownAccessList = ownAccessList;
this.inheritFromParent = inheritFromParent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package eu.xenit.apix.rest.v1.nodes;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Created by Michiel Huygen on 12/05/2016.
*/
Expand All @@ -8,7 +11,8 @@ class ChangeParentOptions {
private String parent;


public ChangeParentOptions(String parent) {
@JsonCreator
public ChangeParentOptions(@JsonProperty("parent") String parent) {
this.parent = parent;
}

Expand Down
Loading

0 comments on commit 7977862

Please sign in to comment.