Skip to content
Snippets Groups Projects
Commit 856ac51c authored by srosse's avatar srosse
Browse files

OO-291: add unit tests for import of business group (based on the old version with contexts)

parent 7f31bb5b
No related branches found
No related tags found
No related merge requests found
......@@ -42,11 +42,11 @@ import org.olat.group.manager.GroupXStream;
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class GroupImportExportTest {
public class BusinessGroupImportExportXStreamTest {
@Test
public void importLearningGroupTest() {
InputStream input = GroupImportExportTest.class.getResourceAsStream("learninggroupexport.xml");
InputStream input = BusinessGroupImportExportXStreamTest.class.getResourceAsStream("learninggroupexport.xml");
GroupXStream xstream = new GroupXStream();
OLATGroupExport export = xstream.fromXML(input);
assertNotNull(export);
......@@ -66,7 +66,7 @@ public class GroupImportExportTest {
@Test
public void importRightGroupTest() {
InputStream input = GroupImportExportTest.class.getResourceAsStream("rightgroupexport.xml");
InputStream input = BusinessGroupImportExportXStreamTest.class.getResourceAsStream("rightgroupexport.xml");
GroupXStream xstream = new GroupXStream();
OLATGroupExport export = xstream.fromXML(input);
assertNotNull(export);
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.group.test;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
import org.olat.collaboration.CollaborationTools;
import org.olat.collaboration.CollaborationToolsFactory;
import org.olat.core.commons.persistence.DB;
import org.olat.group.BusinessGroup;
import org.olat.group.BusinessGroupService;
import org.olat.group.area.BGArea;
import org.olat.group.area.BGAreaManager;
import org.olat.group.model.DisplayMembers;
import org.olat.group.model.SearchBusinessGroupParams;
import org.olat.resource.OLATResource;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class BusinessGroupImportExportTest extends OlatTestCase {
@Autowired
private DB dbInstance;
@Autowired
private BusinessGroupService businessGroupService;
@Autowired
private BGAreaManager areaManager;
@Test
public void importGroupsWithoutResource() throws URISyntaxException {
URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_2.xml");
File importXml = new File(input.toURI());
businessGroupService.importGroups(null, importXml);
dbInstance.commitAndCloseSession();
}
@Test
public void importLearningGroupsWithResource() throws URISyntaxException {
OLATResource resource = JunitTestHelper.createRandomResource();
URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_2.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, null, false, false, resource, 0, -1);
Assert.assertNotNull(groups);
Assert.assertEquals(3, groups.size());
//get first group (members true, true, false) (no collaboration tools)
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
params.setExactName("Export group 1");
List<BusinessGroup> group1List = businessGroupService.findBusinessGroups(params, null, false, false, resource, 0, -1);
Assert.assertNotNull(group1List);
Assert.assertEquals(1, group1List.size());
//check settings of the first group
BusinessGroup group1 = group1List.get(0);
Assert.assertEquals("Export group 1", group1.getName());
Assert.assertEquals("<p>Export group 1</p>", group1.getDescription());
Assert.assertFalse(group1.getAutoCloseRanksEnabled().booleanValue());
Assert.assertFalse(group1.getWaitingListEnabled().booleanValue());
//check display members settings
DisplayMembers displayMembersGroup1 = businessGroupService.getDisplayMembers(group1);
Assert.assertTrue(displayMembersGroup1.isShowOwners());
Assert.assertTrue(displayMembersGroup1.isShowParticipants());
Assert.assertFalse(displayMembersGroup1.isShowWaitingList());
//check collaboration tools
CollaborationTools toolGroup1 = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(group1);
Assert.assertNotNull(toolGroup1);
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CHAT));
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_CONTACT));
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_FOLDER));
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_FORUM));
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_NEWS));
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
Assert.assertFalse(toolGroup1.isToolEnabled(CollaborationTools.TOOL_WIKI));
//get third group (members true, true, true) (all collaboration tools)
params.setExactName("Export group 3");
List<BusinessGroup> group3List = businessGroupService.findBusinessGroups(params, null, false, false, resource, 0, -1);
Assert.assertNotNull(group3List);
Assert.assertEquals(1, group3List.size());
//check settings of the first group
BusinessGroup group3 = group3List.get(0);
Assert.assertEquals("Export group 3", group3.getName());
Assert.assertEquals("<p>Export group 2</p>", group3.getDescription());
Assert.assertFalse(group3.getAutoCloseRanksEnabled().booleanValue());
Assert.assertTrue(group3.getWaitingListEnabled().booleanValue());
Assert.assertEquals(new Integer(25), group3.getMaxParticipants());
//check display members settings
DisplayMembers displayMembersGroup3 = businessGroupService.getDisplayMembers(group3);
Assert.assertTrue(displayMembersGroup3.isShowOwners());
Assert.assertTrue(displayMembersGroup3.isShowParticipants());
Assert.assertTrue(displayMembersGroup3.isShowWaitingList());
//check collaboration tools
CollaborationTools toolGroup3 = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(group3);
Assert.assertNotNull(toolGroup3);
Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
//Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CHAT)); chat is not enabled during unit tests
Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_CONTACT));
Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_FOLDER));
Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_FORUM));
Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_NEWS));
Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
Assert.assertTrue(toolGroup3.isToolEnabled(CollaborationTools.TOOL_WIKI));
Assert.assertEquals("<p>Hello Mitglied</p>", toolGroup3.lookupNews());
}
@Test
public void importLearningGroupsAndAreasWithResource() throws URISyntaxException {
OLATResource resource = JunitTestHelper.createRandomResource();
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, null, false, false, resource, 0, -1);
Assert.assertNotNull(groups);
Assert.assertEquals(3, groups.size());
//check if all three areas are imported
List<BGArea> areas = areaManager.findBGAreasOfBGContext(resource);
Assert.assertNotNull(areas);
Assert.assertEquals(3, areas.size());
//check first area
BGArea area1 = areaManager.findBGArea("Area 1", resource);
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);
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());
}
}
<OLATGroupExport>
<AreaCollection/>
<GroupCollection>
<Group name="Export group 1" waitingList="false" autoCloseRanks="false" showOwners="true" showParticipants="true" showWaitingList="false">
<Description>&lt;p&gt;Export group 1&lt;/p&gt;</Description>
<CollabTools hasNews="false" hasContactForm="false" hasCalendar="false" hasFolder="false" hasForum="false" hasChat="false" hasWiki="false" hasPortfolio="false"/>
</Group>
<Group name="Export group 2" maxParticipants="25" waitingList="true" autoCloseRanks="false" showOwners="true" showParticipants="false" showWaitingList="false">
<Description>&lt;p&gt;Export group 1&lt;/p&gt;</Description>
<CollabTools hasNews="false" hasContactForm="false" hasCalendar="false" hasFolder="false" hasForum="false" hasChat="false" hasWiki="false" hasPortfolio="false"/>
</Group>
<Group name="Export group 3" maxParticipants="25" waitingList="true" autoCloseRanks="false" showOwners="true" showParticipants="true" showWaitingList="true" info="&lt;p&gt;Hello Mitglied&lt;/p&gt;">
<Description>&lt;p&gt;Export group 2&lt;/p&gt;</Description>
<CollabTools hasNews="true" hasContactForm="true" hasCalendar="true" hasFolder="true" hasForum="true" hasChat="true" hasWiki="true" hasPortfolio="true"/>
</Group>
</GroupCollection>
</OLATGroupExport>
\ No newline at end of file
<OLATGroupExport>
<AreaCollection>
<Area name="Area 1">
<Description>&lt;p&gt;Area 1 description&lt;/p&gt;</Description>
</Area>
<Area name="Area 2">
<Description>&lt;p&gt;Area 2 description&lt;/p&gt;</Description>
</Area>
<Area name="Area 3">
<Description>&lt;p&gt;Area 3 empty&lt;/p&gt;</Description>
</Area>
</AreaCollection>
<GroupCollection>
<Group name="Export group 1" waitingList="false" autoCloseRanks="false" showOwners="true" showParticipants="true" showWaitingList="false">
<Description>&lt;p&gt;Export group 1&lt;/p&gt;</Description>
<CollabTools hasNews="false" hasContactForm="false" hasCalendar="false" hasFolder="false" hasForum="false" hasChat="false" hasWiki="false" hasPortfolio="false"/>
<AreaRelation>Area 1</AreaRelation>
<AreaRelation>Area 2</AreaRelation>
</Group>
<Group name="Export group 2" maxParticipants="25" waitingList="true" autoCloseRanks="false" showOwners="true" showParticipants="false" showWaitingList="false">
<Description>&lt;p&gt;Export group 1&lt;/p&gt;</Description>
<CollabTools hasNews="false" hasContactForm="false" hasCalendar="false" hasFolder="false" hasForum="false" hasChat="false" hasWiki="false" hasPortfolio="false"/>
<AreaRelation>Area 1</AreaRelation>
<AreaRelation>Area 2</AreaRelation>
</Group>
<Group name="Export group 3" maxParticipants="25" waitingList="true" autoCloseRanks="false" showOwners="true" showParticipants="true" showWaitingList="true" info="&lt;p&gt;Hello Mitglied&lt;/p&gt;">
<Description>&lt;p&gt;Export group 2&lt;/p&gt;</Description>
<CollabTools hasNews="true" hasContactForm="true" hasCalendar="true" hasFolder="true" hasForum="true" hasChat="true" hasWiki="true" hasPortfolio="true"/>
<AreaRelation>Area 2</AreaRelation>
</Group>
</GroupCollection>
</OLATGroupExport>
\ No newline at end of file
......@@ -148,7 +148,8 @@ import org.junit.runners.Suite;
org.olat.restapi.UserMgmtTest.class,
org.olat.restapi.ContactsTest.class,
de.bps.olat.portal.institution.InstitutionPortletTest.class,
org.olat.group.manager.GroupImportExportTest.class,
org.olat.group.manager.BusinessGroupImportExportXStreamTest.class,
org.olat.group.test.BusinessGroupImportExportTest.class,
org.olat.resource.accesscontrol.ACFrontendManagerTest.class,
org.olat.resource.accesscontrol.ACMethodManagerTest.class,
org.olat.resource.accesscontrol.ACOfferManagerTest.class,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment