added unit tests for RepositoryManager

This commit is contained in:
Sebastian Sdorra
2010-12-04 17:34:47 +01:00
parent 0a87a98393
commit 73bfd991fd
6 changed files with 723 additions and 121 deletions

View File

@@ -0,0 +1,148 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Provider;
import org.junit.After;
import org.junit.Before;
import sonia.scm.security.SecurityContext;
import sonia.scm.user.User;
import sonia.scm.util.IOUtil;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.UUID;
/**
*
* @author Sebastian Sdorra
*
* @param <T>
* @param <E>
*/
public abstract class ManagerTestBase<T extends TypedObject,
E extends Exception>
{
/**
* Method description
*
*
* @return
*/
protected abstract Manager<T, E> createManager();
/**
* Method description
*
*
* @throws IOException
*/
@After
public void tearDownTest() throws IOException
{
try
{
manager.close();
}
finally
{
IOUtil.delete(tempDirectory);
}
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*/
@Before
public void setUpTest()
{
tempDirectory = new File(System.getProperty("java.io.tmpdir"),
UUID.randomUUID().toString());
assertTrue(tempDirectory.mkdirs());
manager = createManager();
SCMContextProvider provider = mock(SCMContextProvider.class);
when(provider.getBaseDirectory()).thenReturn(tempDirectory);
manager.init(provider);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
protected Provider<SecurityContext> getAdminSecurityContextProvider()
{
User admin = new User("scmadmin", "SCM Admin", "scmadmin@scm.org");
admin.setAdmin(true);
SecurityContext context = mock(SecurityContext.class);
when(context.getUser()).thenReturn(admin);
Provider<SecurityContext> scp = mock(Provider.class);
when(scp.get()).thenReturn(context);
return scp;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected Manager<T, E> manager;
/** Field description */
protected File tempDirectory;
}

View File

@@ -0,0 +1,122 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Type;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*/
public class DummyRepositoryHandler
extends AbstractSimpleRepositoryHandler<SimpleRepositoryConfig>
{
/** Field description */
public static final String TYPE_DISPLAYNAME = "Dummy";
/** Field description */
public static final String TYPE_NAME = "dummy";
/** Field description */
public static final Type TYPE = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Type getType()
{
return TYPE;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
* @param directory
*
* @throws IOException
* @throws RepositoryException
*/
@Override
protected void create(Repository repository, File directory)
throws RepositoryException, IOException
{
// do nothing
}
/**
* Method description
*
*
* @return
*/
@Override
protected SimpleRepositoryConfig createInitialConfig()
{
return new SimpleRepositoryConfig();
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected Class<SimpleRepositoryConfig> getConfigClass()
{
return SimpleRepositoryConfig.class;
}
}

View File

@@ -0,0 +1,342 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import sonia.scm.ManagerTestBase;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.Collection;
/**
*
* @author Sebastian Sdorra
*/
public abstract class RepositoryManagerTestBase
extends ManagerTestBase<Repository, RepositoryException>
{
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testCreate() throws RepositoryException, IOException
{
Repository heartOfGold = createTestRepository();
Repository dbRepo = manager.get(heartOfGold.getId());
assertNotNull(dbRepo);
assertRepositoriesEquals(dbRepo, heartOfGold);
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test(expected = RepositoryAllreadyExistExeption.class)
public void testCreateExisting() throws RepositoryException, IOException
{
createTestRepository();
createTestRepository();
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testDelete() throws RepositoryException, IOException
{
Repository heartOfGold = createTestRepository();
String id = heartOfGold.getId();
manager.delete(heartOfGold);
assertNull(manager.get(id));
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testGet() throws RepositoryException, IOException
{
Repository heartOfGold = createTestRepository();
String id = heartOfGold.getId();
String description = heartOfGold.getDescription();
assertNotNull(description);
// test for reference
heartOfGold.setDescription("prototype ship");
heartOfGold = manager.get(id);
assertNotNull(heartOfGold);
assertEquals(description, heartOfGold.getDescription());
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testGetAll() throws RepositoryException, IOException
{
Repository heartOfGold = createTestRepository();
Repository happyVerticalPeopleTransporter = createSecondTestRepository();
boolean foundHeart = false;
boolean foundTransporter = false;
Collection<Repository> repositories = manager.getAll();
assertNotNull(repositories);
assertFalse(repositories.isEmpty());
assertTrue(repositories.size() >= 2);
Repository heartReference = null;
for (Repository repository : repositories)
{
if (repository.getId().equals(heartOfGold.getId()))
{
assertRepositoriesEquals(heartOfGold, repository);
foundHeart = true;
heartReference = repository;
}
else if (repository.getId().equals(
happyVerticalPeopleTransporter.getId()))
{
assertRepositoriesEquals(happyVerticalPeopleTransporter, repository);
foundTransporter = true;
}
}
assertTrue(foundHeart);
assertTrue(foundTransporter);
// test for reference
assertNotSame(heartOfGold, heartReference);
heartReference.setDescription("prototype ship");
assertFalse(
heartOfGold.getDescription().equals(heartReference.getDescription()));
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testModify() throws RepositoryException, IOException
{
Repository heartOfGold = createTestRepository();
heartOfGold.setDescription("prototype ship");
manager.modify(heartOfGold);
Repository hearReference = manager.get(heartOfGold.getId());
assertNotNull(hearReference);
assertEquals(hearReference.getDescription(), "prototype ship");
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test(expected = RepositoryException.class)
public void testModifyNotExisting() throws RepositoryException, IOException
{
manager.modify(getTestRepository());
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testRefresh() throws RepositoryException, IOException
{
Repository heartOfGold = createTestRepository();
String description = heartOfGold.getDescription();
heartOfGold.setDescription("prototype ship");
manager.refresh(heartOfGold);
assertEquals(description, heartOfGold.getDescription());
}
/**
* Method description
*
*
* @param repo
* @param other
*/
private void assertRepositoriesEquals(Repository repo, Repository other)
{
assertEquals(repo.getId(), other.getId());
assertEquals(repo.getName(), other.getName());
assertEquals(repo.getDescription(), other.getDescription());
assertEquals(repo.getContact(), other.getContact());
assertEquals(repo.getCreationDate(), other.getCreationDate());
assertEquals(repo.getLastModified(), other.getLastModified());
}
/**
* Method description
*
*
*
* @param repository
* @return
*
* @throws IOException
* @throws RepositoryException
*/
private Repository createRepository(Repository repository)
throws RepositoryException, IOException
{
manager.create(repository);
assertNotNull(repository.getId());
assertNotNull(manager.get(repository.getId()));
assertTrue(repository.getCreationDate() > 0);
assertTrue(repository.getCreationDate() < System.currentTimeMillis());
return repository;
}
/**
* Method description
*
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
private Repository createSecondTestRepository()
throws RepositoryException, IOException
{
return createRepository(getSecondTestRepository());
}
/**
* Method description
*
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
private Repository createTestRepository()
throws RepositoryException, IOException
{
return createRepository(getTestRepository());
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
private Repository getSecondTestRepository()
{
Repository happyVerticalPeopleTransporter = new Repository();
happyVerticalPeopleTransporter.setType(DummyRepositoryHandler.TYPE_NAME);
happyVerticalPeopleTransporter.setContact(
"zaphod.beeblebrox@hitchhiker.com");
happyVerticalPeopleTransporter.setName("happyVerticalPeopleTransporter");
happyVerticalPeopleTransporter.setDescription(
"Happy Vertical People Transporter");
happyVerticalPeopleTransporter.setUrl(
"http://hitchhiker.com/dummy/HeartOfGold");
return happyVerticalPeopleTransporter;
}
/**
* Method description
*
*
* @return
*/
private Repository getTestRepository()
{
Repository heartOfGold = new Repository();
heartOfGold.setType(DummyRepositoryHandler.TYPE_NAME);
heartOfGold.setContact("zaphod.beeblebrox@hitchhiker.com");
heartOfGold.setName("HeartOfGold");
heartOfGold.setDescription(
"Heart of Gold is the first prototype ship to successfully utilise the revolutionary Infinite Improbability Drive");
heartOfGold.setUrl("http://hitchhiker.com/dummy/HeartOfGold");
return heartOfGold;
}
}

View File

@@ -0,0 +1,69 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Manager;
import sonia.scm.repository.xml.XmlRepositoryManager;
//~--- JDK imports ------------------------------------------------------------
import java.util.HashSet;
import java.util.Set;
/**
*
* @author Sebastian Sdorra
*/
public class XmlRepositoryManagerTest extends RepositoryManagerTestBase
{
/**
* Method description
*
*
* @return
*/
@Override
protected Manager<Repository, RepositoryException> createManager()
{
Set<RepositoryHandler> handlerSet = new HashSet<RepositoryHandler>();
handlerSet.add(new DummyRepositoryHandler());
return new XmlRepositoryManager(getAdminSecurityContextProvider(),
handlerSet);
}
}

View File

@@ -35,20 +35,15 @@ package sonia.scm.user;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import sonia.scm.SCMContextProvider;
import sonia.scm.util.IOUtil;
import sonia.scm.Manager;
import sonia.scm.ManagerTestBase;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -61,6 +56,7 @@ import java.util.UUID;
* @author Sebastian Sdorra
*/
public abstract class UserManagerTestBase
extends ManagerTestBase<User, UserException>
{
/** Field description */
@@ -68,33 +64,6 @@ public abstract class UserManagerTestBase
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public abstract UserManager createUserHandler();
/**
* Method description
*
*
* @throws IOException
*/
@After
public void tearDownTest() throws IOException
{
try
{
userManager.close();
}
finally
{
IOUtil.delete(tempDirectory);
}
}
/**
* Method description
*
@@ -107,9 +76,9 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.create(zaphod);
manager.create(zaphod);
User otherUser = userManager.get("zaphod");
User otherUser = manager.get("zaphod");
assertNotNull(otherUser);
assertUserEquals(zaphod, otherUser);
@@ -127,12 +96,12 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.create(zaphod);
assertNotNull(userManager.get("zaphod"));
manager.create(zaphod);
assertNotNull(manager.get("zaphod"));
User sameUser = getTestUser();
userManager.create(sameUser);
manager.create(sameUser);
}
/**
@@ -147,10 +116,10 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.create(zaphod);
assertNotNull(userManager.get("zaphod"));
userManager.delete(zaphod);
assertNull(userManager.get("zaphod"));
manager.create(zaphod);
assertNotNull(manager.get("zaphod"));
manager.delete(zaphod);
assertNull(manager.get("zaphod"));
}
/**
@@ -165,12 +134,12 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.create(zaphod);
assertNotNull(userManager.get("zaphod"));
manager.create(zaphod);
assertNotNull(manager.get("zaphod"));
// test for reference
zaphod.setDisplayName("Tricia McMillan");
zaphod = userManager.get("zaphod");
zaphod = manager.get("zaphod");
assertNotNull(zaphod);
assertEquals("Zaphod Beeblebrox", zaphod.getDisplayName());
}
@@ -187,18 +156,18 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.create(zaphod);
assertNotNull(userManager.get("zaphod"));
manager.create(zaphod);
assertNotNull(manager.get("zaphod"));
User trillian = new User("trillian", "Tricia McMillan",
"tricia.mcmillan@hitchhiker.com");
userManager.create(trillian);
assertNotNull(userManager.get("trillian"));
manager.create(trillian);
assertNotNull(manager.get("trillian"));
boolean foundZaphod = false;
boolean foundTrillian = false;
Collection<User> users = userManager.getAll();
Collection<User> users = manager.getAll();
assertNotNull(users);
assertFalse(users.isEmpty());
@@ -237,7 +206,7 @@ public abstract class UserManagerTestBase
User reference = null;
for (User u : userManager.getAll())
for (User u : manager.getAll())
{
if (u.getName().equals("trillian"))
{
@@ -261,12 +230,12 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.create(zaphod);
assertNotNull(userManager.get("zaphod"));
manager.create(zaphod);
assertNotNull(manager.get("zaphod"));
zaphod.setDisplayName("Tricia McMillan");
userManager.modify(zaphod);
manager.modify(zaphod);
User otherUser = userManager.get("zaphod");
User otherUser = manager.get("zaphod");
assertNotNull(otherUser);
assertEquals(otherUser.getDisplayName(), "Tricia McMillan");
@@ -284,7 +253,7 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.modify(zaphod);
manager.modify(zaphod);
}
/**
@@ -299,12 +268,12 @@ public abstract class UserManagerTestBase
public void testMultiThreaded()
throws UserException, IOException, InterruptedException
{
int initialSize = userManager.getAll().size();
int initialSize = manager.getAll().size();
List<MultiThreadTester> testers = new ArrayList<MultiThreadTester>();
for (int i = 0; i < THREAD_COUNT; i++)
{
testers.add(new MultiThreadTester(userManager));
testers.add(new MultiThreadTester(manager));
}
for (MultiThreadTester tester : testers)
@@ -328,7 +297,7 @@ public abstract class UserManagerTestBase
}
}
assertTrue((initialSize + THREAD_COUNT) == userManager.getAll().size());
assertTrue((initialSize + THREAD_COUNT) == manager.getAll().size());
}
/**
@@ -343,35 +312,13 @@ public abstract class UserManagerTestBase
{
User zaphod = getTestUser();
userManager.create(zaphod);
assertNotNull(userManager.get("zaphod"));
manager.create(zaphod);
assertNotNull(manager.get("zaphod"));
zaphod.setDisplayName("Tricia McMillan");
userManager.refresh(zaphod);
manager.refresh(zaphod);
assertEquals(zaphod.getDisplayName(), "Zaphod Beeblebrox");
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*/
@Before
public void setUpTest()
{
tempDirectory = new File(System.getProperty("java.io.tmpdir"),
UUID.randomUUID().toString());
assertTrue(tempDirectory.mkdirs());
userManager = createUserHandler();
SCMContextProvider provider = mock(SCMContextProvider.class);
when(provider.getBaseDirectory()).thenReturn(tempDirectory);
userManager.init(provider);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -419,9 +366,9 @@ public abstract class UserManagerTestBase
*
* @param userManager
*/
public MultiThreadTester(UserManager userManager)
public MultiThreadTester(Manager<User, UserException> userManager)
{
this.userManager = userManager;
this.manager = userManager;
}
//~--- methods ------------------------------------------------------------
@@ -463,7 +410,7 @@ public abstract class UserManagerTestBase
User user = new User(id, id.concat(" displayName"),
id.concat("@mail.com"));
userManager.create(user);
manager.create(user);
return user;
}
@@ -484,14 +431,14 @@ public abstract class UserManagerTestBase
String nd = name.concat(" new displayname");
user.setDisplayName(nd);
userManager.modify(user);
manager.modify(user);
User otherUser = userManager.get(name);
User otherUser = manager.get(name);
assertNotNull(otherUser);
assertEquals(nd, otherUser.getDisplayName());
userManager.delete(user);
otherUser = userManager.get(name);
manager.delete(user);
otherUser = manager.get(name);
assertNull(otherUser);
}
@@ -501,15 +448,6 @@ public abstract class UserManagerTestBase
private boolean finished = false;
/** Field description */
private UserManager userManager;
private Manager<User, UserException> manager;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private File tempDirectory;
/** Field description */
private UserManager userManager;
}

View File

@@ -35,13 +35,8 @@ package sonia.scm.user;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Provider;
import sonia.scm.security.SecurityContext;
import sonia.scm.user.xml.XmlUserManager;
import static org.mockito.Mockito.*;
/**
*
* @author Sebastian Sdorra
@@ -56,20 +51,8 @@ public class XmlUserManagerTest extends UserManagerTestBase
* @return
*/
@Override
public UserManager createUserHandler()
public UserManager createManager()
{
User admin = new User("scmadmin", "SCM Admin", "scmadmin@scm.org");
admin.setAdmin(true);
SecurityContext context = mock(SecurityContext.class);
when(context.getUser()).thenReturn(admin);
Provider<SecurityContext> scp = mock(Provider.class);
when(scp.get()).thenReturn(context);
return new XmlUserManager(scp);
return new XmlUserManager(getAdminSecurityContextProvider());
}
}