From 6297b4be8b0f73cfacf73c33b36d0afc500c5f9f Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 20 Nov 2017 11:03:31 +0000
Subject: [PATCH] SSDM-5724: JS tests: test for getRoleAssignments

SVN: 38917
---
 .../openbis-v3-api-test/html/test/common.js   | 36 +++++++++++++++++++
 .../openbis-v3-api-test/html/test/dtos.js     |  5 +++
 .../html/test/openbis-execute-operations.js   |  8 +++++
 .../html/test/test-delete.js                  |  1 +
 .../openbis-v3-api-test/html/test/test-get.js | 27 ++++++++++++--
 5 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js
index 81fefe0c421..25dce12d4a4 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js
@@ -30,6 +30,8 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.VocabularyTermCreation = dtos.VocabularyTermCreation;
 		this.TagCreation = dtos.TagCreation;
 		this.AuthorizationGroupCreation = dtos.AuthorizationGroupCreation;
+		this.RoleAssignmentCreation = dtos.RoleAssignmentCreation;
+		this.Role = require('as/dto/roleassignment/Role');
 		this.SemanticAnnotationCreation = dtos.SemanticAnnotationCreation;
 		this.DataSetCreation = dtos.DataSetCreation;
 		this.FullDataSetCreation = dtos.FullDataSetCreation;
@@ -81,6 +83,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.VocabularyPermId = dtos.VocabularyPermId;
 		this.VocabularyTermPermId = dtos.VocabularyTermPermId;
 		this.AuthorizationGroupPermId = dtos.AuthorizationGroupPermId;
+		this.RoleAssignmentTechId = dtos.RoleAssignmentTechId;
 		this.TagPermId = dtos.TagPermId;
 		this.TagCode = dtos.TagCode;
 		this.SemanticAnnotationsPermId = dtos.SemanticAnnotationsPermId;
@@ -117,6 +120,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.VocabularyTermFetchOptions = dtos.VocabularyTermFetchOptions;
 		this.TagFetchOptions = dtos.TagFetchOptions;
 		this.AuthorizationGroupFetchOptions = dtos.AuthorizationGroupFetchOptions;
+		this.RoleAssignmentFetchOptions = dtos.RoleAssignmentFetchOptions;
 		this.PropertyTypeFetchOptions = dtos.PropertyTypeFetchOptions;
 		this.PropertyAssignmentFetchOptions = dtos.PropertyAssignmentFetchOptions;
 		this.SemanticAnnotationFetchOptions = dtos.SemanticAnnotationFetchOptions;
@@ -154,6 +158,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.GetVocabularyTermsOperation = dtos.GetVocabularyTermsOperation;
 		this.GetTagsOperation = dtos.GetTagsOperation;
 		this.GetAuthorizationGroupsOperation = dtos.GetAuthorizationGroupsOperation;
+		this.GetRoleAssignmentsOperation = dtos.GetRoleAssignmentsOperation;
 		this.GetExternalDmsOperation = dtos.GetExternalDmsOperation;
 		this.GetSemanticAnnotationsOperation = dtos.GetSemanticAnnotationsOperation;
 
@@ -170,6 +175,7 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.CreateVocabularyTermsOperation = dtos.CreateVocabularyTermsOperation;
 		this.CreateTagsOperation = dtos.CreateTagsOperation;
 		this.CreateAuthorizationGroupsOperation = dtos.CreateAuthorizationGroupsOperation;
+		this.CreateRoleAssignmentsOperation = dtos.CreateRoleAssignmentsOperation;
 		this.CreateSemanticAnnotationsOperation = dtos.CreateSemanticAnnotationsOperation;
 		this.CreateExternalDmsOperation = dtos.CreateExternalDmsOperation;
 
@@ -251,6 +257,16 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 		this.getDtos = function() {
 			return dtos;
 		}
+		
+		this.getId = function(entity) {
+			if (typeof entity["getPermId"] === 'function') {
+				return entity.getPermId();
+			}
+			if (typeof entity["getId"] === 'function') {
+				return entity.getId();
+			}
+			this.fail("Neither 'getPermId()' nor 'getId()' are functions of entity " + entity);
+		}
 
 		this.generateId = function(base) {
 			var date = new Date();
@@ -414,6 +430,19 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 			});
 		}.bind(this);
 		
+		this.createRoleAssignment = function(facade, space) {
+			var c = this;
+			return c.createSpace(facade).then(function(spaceId) {
+				var creation = new dtos.RoleAssignmentCreation();
+				creation.setRole(c.Role.ADMIN);
+				creation.setUserId(new c.PersonPermId("power_user"));
+				creation.setSpaceId(spaceId);
+				return facade.createRoleAssignments([ creation ]).then(function(permIds) {
+					return permIds[0];
+				});
+			});
+		}.bind(this);
+		
 		this.createSemanticAnnotation = function(facade) {
 			var c = this;
 			var creation = new dtos.SemanticAnnotationCreation();
@@ -836,6 +865,13 @@ define([ 'jquery', 'openbis', 'underscore', 'test/dtos' ], function($, defaultOp
 			return fo;
 		};
 		
+		this.createRoleAssignmentFetchOptions = function() {
+			var fo = new dtos.RoleAssignmentFetchOptions();
+			fo.withProject();
+			fo.withSpace();
+			return fo;
+		};
+		
 		this.createPropertyTypeFetchOptions = function() {
 			var fo = new dtos.PropertyTypeFetchOptions();
 			fo.withVocabulary();
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
index 7ed9feebd42..4668dcfb121 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/dtos.js
@@ -417,8 +417,13 @@ var sources = [
 	'as/dto/property/PropertyAssignment',
 	'as/dto/property/PropertyType',
 	
+	'as/dto/roleassignment/create/RoleAssignmentCreation',
+	'as/dto/roleassignment/create/CreateRoleAssignmentsOperation',
+	'as/dto/roleassignment/create/CreateRoleAssignmentsOperationResult',
 	'as/dto/roleassignment/fetchoptions/RoleAssignmentFetchOptions',
 	'as/dto/roleassignment/fetchoptions/RoleAssignmentSortOptions',
+	'as/dto/roleassignment/get/GetRoleAssignmentsOperation',
+	'as/dto/roleassignment/get/GetRoleAssignmentsOperationResult',
 	'as/dto/roleassignment/id/IRoleAssignmentId',
 	'as/dto/roleassignment/id/RoleAssignmentTechId',
 	'as/dto/roleassignment/Role',
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
index 047cd28786f..b7149eca358 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/openbis-execute-operations.js
@@ -141,6 +141,10 @@ define([ 'jquery', 'openbis', 'test/common' ], function($, openbis, common) {
 			return this._executeCreateOperation(new c.CreateAuthorizationGroupsOperation(creations));
 		}
 		
+		this.createRoleAssignments = function(creations) {
+			return this._executeCreateOperation(new c.CreateRoleAssignmentsOperation(creations));
+		}
+		
 		this.createSemanticAnnotations = function(creations) {
 			return this._executeCreateOperation(new c.CreateSemanticAnnotationsOperation(creations));
 		}
@@ -229,6 +233,10 @@ define([ 'jquery', 'openbis', 'test/common' ], function($, openbis, common) {
 			return this._executeGetOperation(new c.GetAuthorizationGroupsOperation(ids, fetchOptions));
 		}
 		
+		this.getRoleAssignments = function(ids, fetchOptions) {
+			return this._executeGetOperation(new c.GetRoleAssignmentsOperation(ids, fetchOptions));
+		}
+		
 		this.getSemanticAnnotations = function(ids, fetchOptions) {
 			return this._executeGetOperation(new c.GetSemanticAnnotationsOperation(ids, fetchOptions));
 		}
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js
index 88ce615ee6b..b5f2c00e641 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-delete.js
@@ -44,6 +44,7 @@ define([ 'jquery', 'underscore', 'openbis', 'test/openbis-execute-operations', '
 							c.ok("Got before deletions");
 							return fDelete(facade, permId).then(function(deletionId) {
 								c.ok("Entity was deleted");
+								c.assertNotEqual(deletionId.getTechId(), "", "Deletion tech id not an empty string");
 								return facade.searchDeletions(new c.DeletionSearchCriteria(), new c.DeletionFetchOptions()).then(function(afterDeletions) {
 									c.ok("Got after deletions");
 									c.assertEqual(afterDeletions.getObjects().length, beforeDeletions.getObjects().length + 1, "One new deletion");
diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js
index 784ae7f79e1..7f8cd22da42 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-get.js
@@ -12,14 +12,14 @@ define([ 'jquery', 'underscore', 'openbis', 'test/openbis-execute-operations', '
 						permIds.forEach(function(permId) {
 							var entity = map[permId];
 							testFetchOptionsResults(c, fechOptionsTestConfig, true, entity);
-							c.assertEqual(entity.getPermId().toString(), permId.toString(), "Entity perm id matches");
+							c.assertEqual(c.getId(entity).toString(), permId.toString(), "Entity perm id matches");
 						});
 						return fGetEmptyFetchOptions(facade, permIds).then(function(map) {
 							c.assertEqual(Object.keys(map).length, permIds.length, "Entity map size is correct");
 							permIds.forEach(function(permId) {
 								var entity = map[permId];
 								testFetchOptionsResults(c, fechOptionsTestConfig, false, entity);
-								c.assertEqual(entity.getPermId().toString(), permId.toString(), "Entity perm id matches");
+								c.assertEqual(c.getId(entity).toString(), permId.toString(), "Entity perm id matches");
 							});
 							c.finish();
 						});
@@ -368,6 +368,29 @@ define([ 'jquery', 'underscore', 'openbis', 'test/openbis-execute-operations', '
 			testGet(c, fCreate, fGet, fGetEmptyFetchOptions, fechOptionsTestConfig);
 		});
 		
+		QUnit.test("getRoleAssignments()", function(assert) {
+			var c = new common(assert, openbis);
+			var fo = new c.RoleAssignmentFetchOptions();
+			var fechOptionsTestConfig = getConfigForFetchOptions(fo);
+			
+			var fCreate = function(facade) {
+				return $.when(c.createRoleAssignment(facade)).then(function(id) {
+					return [ id ];
+				});
+			}
+			
+			var fGet = function(facade, permIds) {
+				testFetchOptionsAssignation(c, fo, fechOptionsTestConfig);
+				return facade.getRoleAssignments(permIds, fo);
+			}
+			
+			var fGetEmptyFetchOptions = function(facade, permIds) {
+				return facade.getRoleAssignments(permIds, new c.RoleAssignmentFetchOptions());
+			}
+			
+			testGet(c, fCreate, fGet, fGetEmptyFetchOptions, fechOptionsTestConfig);
+		});
+		
 		QUnit.test("getOperationExecutions()", function(assert) {
 			var c = new common(assert, openbis);
 			var fo = new c.OperationExecutionFetchOptions();
-- 
GitLab