use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.
the class BusinessGroupImportExportTest method importLearningGroupsAndAreasWithResource.
@Test
public void importLearningGroupsAndAreasWithResource() throws URISyntaxException {
RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_3.xml");
File importXml = new File(input.toURI());
businessGroupService.importGroups(resource, importXml);
dbInstance.commitAndCloseSession();
// check if all three groups are imported
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
Assert.assertNotNull(groups);
Assert.assertEquals(3, groups.size());
// check if all three areas are imported
List<BGArea> areas = areaManager.findBGAreasInContext(resource.getOlatResource());
Assert.assertNotNull(areas);
Assert.assertEquals(3, areas.size());
// check first area
BGArea area1 = areaManager.findBGArea("Area 1", resource.getOlatResource());
Assert.assertNotNull(area1);
Assert.assertEquals("Area 1", area1.getName());
Assert.assertEquals("<p>Area 1 description</p>", area1.getDescription());
// check relation to groups
List<BusinessGroup> groupArea1 = areaManager.findBusinessGroupsOfArea(area1);
Assert.assertNotNull(groupArea1);
Assert.assertEquals(2, groupArea1.size());
Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 1") || groupArea1.get(1).getName().equals("Export group 1"));
Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 2") || groupArea1.get(1).getName().equals("Export group 2"));
// check empty area
BGArea area3 = areaManager.findBGArea("Area 3", resource.getOlatResource());
Assert.assertNotNull(area1);
Assert.assertEquals("Area 3", area3.getName());
// check relation to groups
List<BusinessGroup> groupArea3 = areaManager.findBusinessGroupsOfArea(area3);
Assert.assertNotNull(groupArea3);
Assert.assertEquals(0, groupArea3.size());
}
use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.
the class BusinessGroupRelationDAOTest method findAndCountBusinessGroups.
@Test
public void findAndCountBusinessGroups() {
// prepare 2 resources + 3 groups with 3 owners
Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("wait-1-" + UUID.randomUUID().toString());
Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("wait-2-" + UUID.randomUUID().toString());
Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("wait-3-" + UUID.randomUUID().toString());
RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "rel-bg-part-one", "rel-bgis-1-desc", 0, 10, true, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group1, resource1);
businessGroupRelationDao.addRelationToResource(group1, resource2);
BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "rel-bg-part-two", "rel-bgis-2-desc", 0, 10, true, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group2, resource1);
BusinessGroup group3 = businessGroupDao.createAndPersist(id3, "rel-bg-part-three", "rel-bgis-3-desc", 0, 10, true, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group3, resource2);
dbInstance.commitAndCloseSession();
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
// check resource 1
int count1_1 = businessGroupDao.countBusinessGroups(params, resource1);
Assert.assertEquals(2, count1_1);
List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroups(params, resource1, 0, -1);
Assert.assertNotNull(groups1_1);
Assert.assertEquals(2, groups1_1.size());
Assert.assertTrue(groups1_1.contains(group1));
Assert.assertTrue(groups1_1.contains(group2));
// check owner 1 + resource 1
SearchBusinessGroupParams paramsRestricted = new SearchBusinessGroupParams(id1, true, true);
int count3_1 = businessGroupDao.countBusinessGroups(paramsRestricted, resource1);
Assert.assertEquals(1, count3_1);
List<BusinessGroup> groups3_1 = businessGroupDao.findBusinessGroups(paramsRestricted, resource1, 0, -1);
Assert.assertNotNull(groups3_1);
Assert.assertEquals(1, groups3_1.size());
Assert.assertEquals(group1, groups3_1.get(0));
}
use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.
the class BusinessGroupRelationDAOTest method addRelation.
@Test
public void addRelation() {
// create a relation
RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group = businessGroupDao.createAndPersist(null, "gdbo", "gdbo-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group, resource);
dbInstance.commitAndCloseSession();
// check
List<RepositoryEntry> resources = businessGroupRelationDao.findRepositoryEntries(Collections.singletonList(group), 0, -1);
Assert.assertNotNull(resources);
Assert.assertEquals(1, resources.size());
Assert.assertTrue(resources.contains(resource));
int count = businessGroupRelationDao.countResources(group);
Assert.assertEquals(1, count);
}
use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.
the class BusinessGroupRelationDAOTest method addGroupsAndRelations.
@Test
public void addGroupsAndRelations() {
// create a relation
RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry resource3 = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-1", "rel-bg-1-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group1, resource1);
businessGroupRelationDao.addRelationToResource(group1, resource2);
BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-2", "rel-bg-2-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(group2, resource2);
businessGroupRelationDao.addRelationToResource(group2, resource3);
dbInstance.commitAndCloseSession();
// check group1
List<RepositoryEntry> resources1 = businessGroupRelationDao.findRepositoryEntries(Collections.singletonList(group1), 0, -1);
Assert.assertNotNull(resources1);
Assert.assertEquals(2, resources1.size());
Assert.assertTrue(resources1.contains(resource1));
Assert.assertTrue(resources1.contains(resource2));
Assert.assertFalse(resources1.contains(resource3));
// check group2
List<RepositoryEntry> resources2 = businessGroupRelationDao.findRepositoryEntries(Collections.singletonList(group2), 0, -1);
Assert.assertNotNull(resources2);
Assert.assertEquals(2, resources2.size());
Assert.assertFalse(resources2.contains(resource1));
Assert.assertTrue(resources2.contains(resource2));
Assert.assertTrue(resources2.contains(resource3));
}
use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.
the class BusinessGroupRelationDAOTest method countResourcesOfBusinessGroups.
@Test
public void countResourcesOfBusinessGroups() {
// create 3 entries and 1 group
RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry re3 = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup group = businessGroupDao.createAndPersist(null, "rel-repo", "rel-repo-desc", 0, 10, true, false, false, false, false);
dbInstance.commitAndCloseSession();
businessGroupRelationDao.addRelationToResource(group, re1);
businessGroupRelationDao.addRelationToResource(group, re2);
businessGroupRelationDao.addRelationToResource(group, re3);
dbInstance.commitAndCloseSession();
// check with empty list of groups
boolean numOfResources1 = businessGroupRelationDao.hasResources(Collections.<BusinessGroup>emptyList());
Assert.assertFalse(numOfResources1);
// check with the group
boolean numOfResources2 = businessGroupRelationDao.hasResources(Collections.singletonList(group));
Assert.assertTrue(numOfResources2);
}
Aggregations