use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class JDBCGroupDatabaseTest method testDelete.
@Test
public void testDelete() throws WikiException {
// First, count the number of groups in the db now.
int oldUserCount = m_db.groups().length;
// Create a new group with random name
String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
Group group = new Group(name, m_wiki);
Principal al = new WikiPrincipal("Al");
Principal bob = new WikiPrincipal("Bob");
group.add(al);
group.add(bob);
m_db.save(group, new WikiPrincipal("Tester"));
// Make sure the profile saved successfully
group = backendGroup(name);
Assert.assertEquals(name, group.getName());
Assert.assertEquals(oldUserCount + 1, m_db.groups().length);
// Now delete the profile; should be back to old count
m_db.delete(group);
Assert.assertEquals(oldUserCount, m_db.groups().length);
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class JDBCGroupDatabaseTest method testSave.
@Test
public void testSave() throws Exception {
// Create a new group with random name
String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
Group group = new Group(name, m_wiki);
Principal al = new WikiPrincipal("Al");
Principal bob = new WikiPrincipal("Bob");
Principal cookie = new WikiPrincipal("Cookie");
group.add(al);
group.add(bob);
group.add(cookie);
m_db.save(group, new WikiPrincipal("Tester"));
// Make sure the profile saved successfully
group = backendGroup(name);
Assert.assertEquals(name, group.getName());
Assert.assertEquals(3, group.members().length);
Assert.assertTrue(group.isMember(new WikiPrincipal("Al")));
Assert.assertTrue(group.isMember(new WikiPrincipal("Bob")));
Assert.assertTrue(group.isMember(new WikiPrincipal("Cookie")));
// The back-end should have timestamped the create/modify fields
Assert.assertNotNull(group.getCreator());
Assert.assertEquals("Tester", group.getCreator());
Assert.assertNotNull(group.getCreated());
Assert.assertNotNull(group.getModifier());
Assert.assertEquals("Tester", group.getModifier());
Assert.assertNotNull(group.getLastModified());
Assert.assertNotSame(group.getCreated(), group.getLastModified());
// Remove the group
m_db.delete(group);
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class XMLGroupDatabaseTest method testResave.
@Test
public void testResave() throws Exception {
// Create a new group with random name & 3 members
String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
Group group = new Group(name, m_wiki);
Principal al = new WikiPrincipal("Al");
Principal bob = new WikiPrincipal("Bob");
Principal cookie = new WikiPrincipal("Cookie");
group.add(al);
group.add(bob);
group.add(cookie);
m_db.save(group, new WikiPrincipal("Tester"));
// Make sure the profile saved successfully
group = backendGroup(name);
Assert.assertEquals(name, group.getName());
// Modify the members by adding the group; re-add Al while we're at it
Principal dave = new WikiPrincipal("Dave");
group.add(al);
group.add(dave);
m_db.save(group, new WikiPrincipal("SecondTester"));
// We should see 4 members and new timestamp info
Principal[] members = group.members();
Assert.assertEquals(4, members.length);
Assert.assertNotNull(group.getCreator());
Assert.assertEquals("Tester", group.getCreator());
Assert.assertNotNull(group.getCreated());
Assert.assertNotNull(group.getModifier());
Assert.assertEquals("SecondTester", group.getModifier());
Assert.assertNotNull(group.getLastModified());
// Check the back-end; We should see the same thing
group = backendGroup(name);
members = group.members();
Assert.assertEquals(4, members.length);
Assert.assertNotNull(group.getCreator());
Assert.assertEquals("Tester", group.getCreator());
Assert.assertNotNull(group.getCreated());
Assert.assertNotNull(group.getModifier());
Assert.assertEquals("SecondTester", group.getModifier());
Assert.assertNotNull(group.getLastModified());
// Remove the group
m_db.delete(group);
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class XMLGroupDatabaseTest method testSave.
@Test
public void testSave() throws Exception {
// Create a new group with random name
String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
Group group = new Group(name, m_wiki);
Principal al = new WikiPrincipal("Al");
Principal bob = new WikiPrincipal("Bob");
Principal cookie = new WikiPrincipal("Cookie");
group.add(al);
group.add(bob);
group.add(cookie);
m_db.save(group, new WikiPrincipal("Tester"));
// Make sure the profile saved successfully
group = backendGroup(name);
Assert.assertEquals(name, group.getName());
Assert.assertEquals(3, group.members().length);
Assert.assertTrue(group.isMember(new WikiPrincipal("Al")));
Assert.assertTrue(group.isMember(new WikiPrincipal("Bob")));
Assert.assertTrue(group.isMember(new WikiPrincipal("Cookie")));
// The back-end should have timestamped the create/modify fields
Assert.assertNotNull(group.getCreator());
Assert.assertEquals("Tester", group.getCreator());
Assert.assertNotNull(group.getCreated());
Assert.assertNotNull(group.getModifier());
Assert.assertEquals("Tester", group.getModifier());
Assert.assertNotNull(group.getLastModified());
Assert.assertNotSame(group.getCreated(), group.getLastModified());
// Remove the group
m_db.delete(group);
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class XMLGroupDatabaseTest method testDelete.
@Test
public void testDelete() throws WikiException {
// First, count the number of groups in the db now.
int oldUserCount = m_db.groups().length;
// Create a new group with random name
String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
Group group = new Group(name, m_wiki);
Principal al = new WikiPrincipal("Al");
Principal bob = new WikiPrincipal("Bob");
group.add(al);
group.add(bob);
m_db.save(group, new WikiPrincipal("Tester"));
// Make sure the profile saved successfully
group = backendGroup(name);
Assert.assertEquals(name, group.getName());
Assert.assertEquals(oldUserCount + 1, m_db.groups().length);
// Now delete the profile; should be back to old count
m_db.delete(group);
Assert.assertEquals(oldUserCount, m_db.groups().length);
}
Aggregations