@@ -142,7 +142,7 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
142142
143143 @BeforeEach
144144 fun beforeEach () {
145- every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
145+ every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
146146 every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns " test.user"
147147 every { getCurrentAuthenticatedRoles(any()) } returns listOf ()
148148 rediSearchIndexer.createIndexFor(Connector ::class .java)
@@ -153,11 +153,11 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
153153
154154 connectorSaved = connectorApiService.registerConnector(makeConnector())
155155
156- organization = makeOrganizationWithRole(" Organization " )
156+ organization = makeOrganizationWithRole()
157157 organizationSaved = organizationApiService.registerOrganization(organization)
158158 dataset = makeDatasetWithRole()
159159 datasetSaved = datasetApiService.createDataset(organizationSaved.id!! , dataset)
160- dataset2 = makeDatasetWithRole ()
160+ dataset2 = makeDataset ()
161161 solution = makeSolution()
162162 solutionSaved = solutionApiService.createSolution(organizationSaved.id!! , solution)
163163 workspace = makeWorkspace()
@@ -334,6 +334,69 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
334334 assertTrue { datasetCompatibilityList.isEmpty() }
335335 }
336336
337+ @Test
338+ fun `test find All Datasets as Platform Admin` () {
339+ organizationSaved = organizationApiService.registerOrganization(organization)
340+ val numberOfDatasets = 20
341+ val defaultPageSize = csmPlatformProperties.twincache.dataset.defaultPageSize
342+ val expectedSize = 15
343+ IntRange (1 , numberOfDatasets).forEach {
344+ datasetApiService.createDataset(
345+ organizationSaved.id!! , makeDataset(" d-dataset-$it " , " dataset-$it " ))
346+ }
347+ logger.info(" Change current user..." )
348+ every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
349+ every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns " test.admin"
350+ every { getCurrentAuthenticatedRoles(any()) } returns listOf (ROLE_PLATFORM_ADMIN )
351+
352+ logger.info(" should find all datasets and assert there are $numberOfDatasets " )
353+ var datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , null , null )
354+ assertEquals(numberOfDatasets + 1 , datasetList.size)
355+
356+ logger.info(" should find all datasets and assert it equals defaultPageSize: $defaultPageSize " )
357+ datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , 0 , null )
358+ assertEquals(defaultPageSize, datasetList.size)
359+
360+ logger.info(" should find all datasets and assert there are expected size: $expectedSize " )
361+ datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , 0 , expectedSize)
362+ assertEquals(expectedSize, datasetList.size)
363+
364+ logger.info(" should find all solutions and assert it returns the second / last page" )
365+ datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , 1 , expectedSize)
366+ assertEquals(numberOfDatasets - expectedSize + 1 , datasetList.size)
367+ }
368+
369+ @Test
370+ fun `test find All Datasets as Organization User` () {
371+ organizationSaved = organizationApiService.registerOrganization(organization)
372+ val numberOfDatasets = 20
373+ val defaultPageSize = csmPlatformProperties.twincache.dataset.defaultPageSize
374+ val expectedSize = 15
375+ IntRange (1 , numberOfDatasets).forEach {
376+ datasetApiService.createDataset(
377+ organizationSaved.id!! ,
378+ makeDatasetWithRole(
379+ organizationId = " d-dataset-$it " ,
380+ parentId = " dataset-$it " ,
381+ userName = " ANOTHER_USER" ))
382+ }
383+ logger.info(" should find all datasets and assert there are $numberOfDatasets " )
384+ var datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , null , null )
385+ assertEquals(0 , datasetList.size)
386+
387+ logger.info(" should find all datasets and assert it equals defaultPageSize: $defaultPageSize " )
388+ datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , 0 , null )
389+ assertEquals(0 , datasetList.size)
390+
391+ logger.info(" should find all datasets and assert there are expected size: $expectedSize " )
392+ datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , 0 , expectedSize)
393+ assertEquals(0 , datasetList.size)
394+
395+ logger.info(" should find all solutions and assert it returns the second / last page" )
396+ datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , 1 , expectedSize)
397+ assertEquals(0 , datasetList.size)
398+ }
399+
337400 @Test
338401 fun `test find All Datasets with different pagination params` () {
339402 organizationSaved = organizationApiService.registerOrganization(organization)
@@ -650,8 +713,7 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
650713 @Test
651714 fun `access control list shouldn't contain more than one time each user on creation` () {
652715 connectorSaved = connectorApiService.registerConnector(makeConnector())
653- organizationSaved =
654- organizationApiService.registerOrganization(makeOrganizationWithRole(" organization" ))
716+ organizationSaved = organizationApiService.registerOrganization(makeOrganizationWithRole())
655717 val brokenDataset =
656718 Dataset (
657719 name = " dataset" ,
@@ -671,8 +733,7 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
671733 @Test
672734 fun `access control list shouldn't contain more than one time each user on ACL addition` () {
673735 connectorSaved = connectorApiService.registerConnector(makeConnector())
674- organizationSaved =
675- organizationApiService.registerOrganization(makeOrganizationWithRole(" organization" ))
736+ organizationSaved = organizationApiService.registerOrganization(makeOrganizationWithRole())
676737 val workingDataset = makeDatasetWithRole(" dataset" , sourceType = DatasetSourceType .None )
677738 val datasetSaved = datasetApiService.createDataset(organizationSaved.id!! , workingDataset)
678739
@@ -925,7 +986,7 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
925986
926987 fun makeOrganizationWithRole (
927988 userName : String = TEST_USER_MAIL ,
928- role : String = ROLE_ADMIN
989+ role : String = ROLE_EDITOR
929990 ): Organization {
930991 return Organization (
931992 id = UUID .randomUUID().toString(),
@@ -939,6 +1000,23 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
9391000 OrganizationAccessControl (id = CONNECTED_ADMIN_USER , role = ROLE_ADMIN ),
9401001 OrganizationAccessControl (id = userName, role = role))))
9411002 }
1003+ fun makeDataset (
1004+ organizationId : String = organizationSaved.id!!,
1005+ parentId : String = "",
1006+ sourceType : DatasetSourceType = DatasetSourceType .File
1007+ ): Dataset {
1008+ return Dataset (
1009+ id = UUID .randomUUID().toString(),
1010+ name = " My datasetRbac" ,
1011+ organizationId = organizationId,
1012+ parentId = parentId,
1013+ ownerId = " ownerId" ,
1014+ connector = DatasetConnector (connectorSaved.id!! ),
1015+ twingraphId = " graph" ,
1016+ source = SourceInfo (" location" , " name" , " path" ),
1017+ tags = mutableListOf (" dataset" ),
1018+ sourceType = sourceType)
1019+ }
9421020
9431021 fun makeDatasetWithRole (
9441022 organizationId : String = organizationSaved.id!!,
@@ -967,7 +1045,11 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
9671045 DatasetAccessControl (id = userName, role = role))))
9681046 }
9691047
970- fun makeSolution (organizationId : String = organizationSaved.id!!): Solution {
1048+ fun makeSolution (
1049+ organizationId : String = organizationSaved.id!!,
1050+ userName : String = TEST_USER_MAIL ,
1051+ role : String = ROLE_EDITOR
1052+ ): Solution {
9711053 return Solution (
9721054 id = " solutionId" ,
9731055 key = UUID .randomUUID().toString(),
@@ -979,7 +1061,8 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
9791061 default = ROLE_NONE ,
9801062 accessControlList =
9811063 mutableListOf (
982- SolutionAccessControl (id = CONNECTED_ADMIN_USER , role = ROLE_ADMIN ))))
1064+ SolutionAccessControl (id = CONNECTED_ADMIN_USER , role = ROLE_ADMIN ),
1065+ SolutionAccessControl (id = userName, role = role))))
9831066 }
9841067
9851068 fun makeWorkspace (
0 commit comments