From 9f5dffbe22d3af15b4b6c6196d137f6429a94d97 Mon Sep 17 00:00:00 2001 From: rkv Date: Tue, 9 Apr 2013 05:04:10 +0000 Subject: [PATCH] Added test of search by study readers. --- .../test/splat/service/TestSearchService.java | 95 ++++++++++++++++--- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/Workspace/Siman-Common/src/test/splat/service/TestSearchService.java b/Workspace/Siman-Common/src/test/splat/service/TestSearchService.java index 458a176..28d8209 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestSearchService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestSearchService.java @@ -20,6 +20,7 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.KnowledgeElementType; import org.splat.dal.bo.som.ProgressState; +import org.splat.dal.bo.som.ReaderRelation; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; @@ -215,11 +216,15 @@ public class TestSearchService extends BaseTest { _userDAO.create(otherUser); User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser"); _userDAO.create(thirdUser); + User reader = TestEntitiesGenerator.getTestUser("readerUser"); + _userDAO.create(reader); - // ============== STUDY 0: Private : goodUser + // ============== STUDY 0: Private : goodUser : readerUser is reader : otherUser is contributor // Create private study Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser); aStudy.setTitle("0.This is private study"); + aStudy.addRelation(new ReaderRelation(aStudy, reader)); + aStudy.addRelation(new ContributorRelation(aStudy, otherUser)); Long privateStudyId = _studyDAO.create(aStudy); // Add simulation context to the study 0 @@ -251,7 +256,7 @@ public class TestSearchService extends BaseTest { aStudy.setReference("TEST_REF"); Long refStudyId = _studyDAO.create(aStudy); - // ============== STUDY 3: Private : inDraft : thirdUser : otherUser is contributor + // ============== STUDY 3: Private : inDraft : thirdUser : otherUser is reviewer // Create private study of third user with otherUser as a reviewer aStudy = TestEntitiesGenerator.getTestStudy(thirdUser); aStudy.setTitle("3.This is a private study of third user"); @@ -281,17 +286,28 @@ public class TestSearchService extends BaseTest { Assert.assertEquals(res.size(), 1); Assert.assertEquals(res.get(0).getIndex(), titleStudyId); - // Search for other logged in study contributor + // Search for logged in study contributor otherUser filter = new StudySearchFilterDTO(); filter.setConnectedUserId(otherUser.getIndex()); res = _searchService.selectStudiesWhere(filter); Assert.assertNotNull(res); + Assert.assertEquals(res.size(), 4); + Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // OtherUser is contributor in this study + Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study + Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study + Assert.assertEquals(res.get(3).getIndex(), reviewStudyId); // OtherUser is reviewer in this study + + // Search for logged in study reader readerUser + filter = new StudySearchFilterDTO(); + filter.setConnectedUserId(reader.getIndex()); + res = _searchService.selectStudiesWhere(filter); + Assert.assertNotNull(res); Assert.assertEquals(res.size(), 3); - Assert.assertEquals(res.get(0).getIndex(), refStudyId); // Public study - Assert.assertEquals(res.get(1).getIndex(), titleStudyId); // Public study - Assert.assertEquals(res.get(2).getIndex(), reviewStudyId); // OtherUser is reviewer in this study + Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // readerUser is reader in this study + Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study + Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study - // Search for logged in study contributor + // Search for logged in study contributor goodUser filter = new StudySearchFilterDTO(); filter.setConnectedUserId(goodUser.getIndex()); res = _searchService.selectStudiesWhere(filter); @@ -301,8 +317,7 @@ public class TestSearchService extends BaseTest { Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study - // Search for logged in study contributor - // filtered by state + // Search for logged in study contributor otherUser filtered by Draft state filter = new StudySearchFilterDTO(); filter.setConnectedUserId(otherUser.getIndex()); filter.setState(ProgressState.inDRAFT); @@ -428,6 +443,8 @@ public class TestSearchService extends BaseTest { _userDAO.create(otherUser); User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser"); _userDAO.create(thirdUser); + User reader = TestEntitiesGenerator.getTestUser("readerUser"); + _userDAO.create(reader); KnowledgeElementType ktype1 = new KnowledgeElementType("testKType1"); KnowledgeElementType ktype2 = new KnowledgeElementType("testKType2"); ktype2.setState(ProgressState.inWORK); @@ -509,7 +526,7 @@ public class TestSearchService extends BaseTest { _knowledgeElementDAO.create(kelm22); ht.flush(); - // ============== STUDY 3: Private : thirdUser : otherUser is contributor + // ============== STUDY 3: Private : thirdUser : otherUser is reviewer // Create private study of third user with otherUser as a reviewer aStudy = TestEntitiesGenerator.getTestStudy(thirdUser); aStudy.setTitle("3.This is a private study of third user"); @@ -538,6 +555,30 @@ public class TestSearchService extends BaseTest { _knowledgeElementDAO.create(kelm31); _knowledgeElementDAO.create(kelm32); ht.flush(); + + // ============== STUDY 4: Private : thirdUser : otherUser is contributor : readerUser is reader + // Create private study of third user with otherUser as a reviewer + aStudy = TestEntitiesGenerator.getTestStudy(thirdUser); + aStudy.setTitle("4.This is a private study of third user"); + aStudy.addRelation(new ContributorRelation(aStudy, otherUser)); + aStudy.addRelation(new ReaderRelation(aStudy, reader)); + _studyDAO.create(aStudy); + + ht.flush(); + // Add a scenario to the study 4 + scen = TestEntitiesGenerator.getTestScenario(aStudy); + _scenarioDAO.create(scen); + ht.flush(); + + // Add knowledge elements to the scenario + KnowledgeElement kelm41 = TestEntitiesGenerator + .getTestKnowledgeElement(scen, ktype1, "TestKelm41 title"); + KnowledgeElement kelm42 = TestEntitiesGenerator + .getTestKnowledgeElement(scen, ktype2, "TestKelm42 title"); + _knowledgeElementDAO.create(kelm41); + _knowledgeElementDAO.create(kelm42); + ht.flush(); + calend = java.util.Calendar.getInstance(); calend.roll(Calendar.DATE, true); Date afterCreation = calend.getTime(); @@ -566,15 +607,17 @@ public class TestSearchService extends BaseTest { filter.setConnectedUserId(otherUser.getIndex()); res = _searchService.selectKnowledgeElementsWhere(filter); Assert.assertNotNull(res); - Assert.assertEquals(res.size(), 6); + Assert.assertEquals(res.size(), 8); Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle()); Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle()); Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle()); Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle()); Assert.assertEquals(res.get(4).getTitle(), kelm31.getTitle()); Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle()); + Assert.assertEquals(res.get(6).getTitle(), kelm41.getTitle()); + Assert.assertEquals(res.get(7).getTitle(), kelm42.getTitle()); - // Search for logged in study contributor + // Search for logged in goodUser filter = new KnowledgeSearchFilterDTO(); filter.setConnectedUserId(goodUser.getIndex()); res = _searchService.selectKnowledgeElementsWhere(filter); @@ -587,6 +630,34 @@ public class TestSearchService extends BaseTest { Assert.assertEquals(res.get(4).getTitle(), kelm21.getTitle()); Assert.assertEquals(res.get(5).getTitle(), kelm22.getTitle()); + // Search for logged in study contributor otherUser + filter = new KnowledgeSearchFilterDTO(); + filter.setConnectedUserId(otherUser.getIndex()); + res = _searchService.selectKnowledgeElementsWhere(filter); + Assert.assertNotNull(res); + Assert.assertEquals(res.size(), 8); + Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle()); + Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle()); + Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle()); + Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle()); + Assert.assertEquals(res.get(4).getTitle(), kelm31.getTitle()); + Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle()); + Assert.assertEquals(res.get(6).getTitle(), kelm41.getTitle()); + Assert.assertEquals(res.get(7).getTitle(), kelm42.getTitle()); + + // Search for logged in study reader readerUser + filter = new KnowledgeSearchFilterDTO(); + filter.setConnectedUserId(reader.getIndex()); + res = _searchService.selectKnowledgeElementsWhere(filter); + Assert.assertNotNull(res); + Assert.assertEquals(res.size(), 6); + Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle()); + Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle()); + Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle()); + Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle()); + Assert.assertEquals(res.get(4).getTitle(), kelm41.getTitle()); + Assert.assertEquals(res.get(5).getTitle(), kelm42.getTitle()); + // Search by title contents filter = new KnowledgeSearchFilterDTO(); filter.setWords("TestKelm22"); -- 2.39.2