mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
improve scm-test
This commit is contained in:
@@ -17,6 +17,12 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-servlet_2.5_spec</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>sonia.scm</groupId>
|
||||
<artifactId>scm-core</artifactId>
|
||||
|
||||
123
scm-test/src/main/java/sonia/scm/AbstractTestBase.java
Normal file
123
scm-test/src/main/java/sonia/scm/AbstractTestBase.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* 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 org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class AbstractTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDownTest() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
preTearDown();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.delete(tempDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUpTest() throws Exception
|
||||
{
|
||||
tempDirectory = new File(System.getProperty("java.io.tmpdir"),
|
||||
UUID.randomUUID().toString());
|
||||
assertTrue(tempDirectory.mkdirs());
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempDirectory);
|
||||
postSetUp();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void postSetUp() throws Exception {}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void preTearDown() throws Exception {}
|
||||
|
||||
;
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
/** Field description */
|
||||
private File tempDirectory;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ import java.util.UUID;
|
||||
* @param <E>
|
||||
*/
|
||||
public abstract class ManagerTestBase<T extends TypedObject,
|
||||
E extends Exception>
|
||||
E extends Exception> extends AbstractTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -78,72 +78,29 @@ public abstract class ManagerTestBase<T extends TypedObject,
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDownTest() throws IOException
|
||||
@Override
|
||||
protected void postSetUp() throws Exception
|
||||
{
|
||||
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());
|
||||
provider = mock(SCMContextProvider.class);
|
||||
when(provider.getBaseDirectory()).thenReturn(tempDirectory);
|
||||
manager = createManager();
|
||||
manager.init(provider);
|
||||
manager.init(contextProvider);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
protected Provider<SecurityContext> getAdminSecurityContextProvider()
|
||||
@Override
|
||||
protected void preTearDown() throws Exception
|
||||
{
|
||||
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;
|
||||
manager.close();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected Manager<T, E> manager;
|
||||
|
||||
/** Field description */
|
||||
protected SCMContextProvider provider;
|
||||
|
||||
/** Field description */
|
||||
protected File tempDirectory;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public abstract class RepositoryManagerTestBase
|
||||
@Test(expected = RepositoryException.class)
|
||||
public void testModifyNotExisting() throws RepositoryException, IOException
|
||||
{
|
||||
manager.modify(getTestRepository());
|
||||
manager.modify(RepositoryTestData.createHeartOfGold());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +278,8 @@ public abstract class RepositoryManagerTestBase
|
||||
private Repository createSecondTestRepository()
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
return createRepository(getSecondTestRepository());
|
||||
return createRepository(
|
||||
RepositoryTestData.createHappyVerticalPeopleTransporter());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,50 +294,6 @@ public abstract class RepositoryManagerTestBase
|
||||
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;
|
||||
return createRepository(RepositoryTestData.createHeartOfGold());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class RepositoryTestData
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Repository createHappyVerticalPeopleTransporter()
|
||||
{
|
||||
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
|
||||
*/
|
||||
public static Repository createHeartOfGold()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
75
scm-test/src/main/java/sonia/scm/store/MemoryStore.java
Normal file
75
scm-test/src/main/java/sonia/scm/store/MemoryStore.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 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.store;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class MemoryStore<T> implements Store<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public T get()
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param obejct
|
||||
*/
|
||||
@Override
|
||||
public void set(T obejct)
|
||||
{
|
||||
this.object = obejct;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private T object;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 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.store;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class MemoryStoreFactory implements StoreFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T> Store<T> getStore(Class<T> type, String name)
|
||||
{
|
||||
return new MemoryStore<T>();
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public abstract class UserManagerTestBase
|
||||
@Test
|
||||
public void testCreate() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.create(zaphod);
|
||||
|
||||
@@ -94,12 +94,12 @@ public abstract class UserManagerTestBase
|
||||
@Test(expected = UserAllreadyExistException.class)
|
||||
public void testCreateExisting() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.create(zaphod);
|
||||
assertNotNull(manager.get("zaphod"));
|
||||
|
||||
User sameUser = getTestUser();
|
||||
User sameUser = UserTestData.createZaphod();
|
||||
|
||||
manager.create(sameUser);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public abstract class UserManagerTestBase
|
||||
@Test
|
||||
public void testDelete() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.create(zaphod);
|
||||
assertNotNull(manager.get("zaphod"));
|
||||
@@ -132,7 +132,7 @@ public abstract class UserManagerTestBase
|
||||
@Test
|
||||
public void testGet() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.create(zaphod);
|
||||
assertNotNull(manager.get("zaphod"));
|
||||
@@ -154,13 +154,12 @@ public abstract class UserManagerTestBase
|
||||
@Test
|
||||
public void testGetAll() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.create(zaphod);
|
||||
assertNotNull(manager.get("zaphod"));
|
||||
|
||||
User trillian = new User("trillian", "Tricia McMillan",
|
||||
"tricia.mcmillan@hitchhiker.com");
|
||||
User trillian = UserTestData.createTrillian();
|
||||
|
||||
manager.create(trillian);
|
||||
assertNotNull(manager.get("trillian"));
|
||||
@@ -228,7 +227,7 @@ public abstract class UserManagerTestBase
|
||||
@Test
|
||||
public void testModify() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.create(zaphod);
|
||||
assertNotNull(manager.get("zaphod"));
|
||||
@@ -251,7 +250,7 @@ public abstract class UserManagerTestBase
|
||||
@Test(expected = UserException.class)
|
||||
public void testModifyNotExisting() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.modify(zaphod);
|
||||
}
|
||||
@@ -310,7 +309,7 @@ public abstract class UserManagerTestBase
|
||||
@Test
|
||||
public void testRefresh() throws UserException, IOException
|
||||
{
|
||||
User zaphod = getTestUser();
|
||||
User zaphod = UserTestData.createZaphod();
|
||||
|
||||
manager.create(zaphod);
|
||||
assertNotNull(manager.get("zaphod"));
|
||||
@@ -334,20 +333,6 @@ public abstract class UserManagerTestBase
|
||||
assertEquals(user.getPassword(), otherUser.getPassword());
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private User getTestUser()
|
||||
{
|
||||
return new User("zaphod", "Zaphod Beeblebrox",
|
||||
"zaphod.beeblebrox@hitchhiker.com");
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
121
scm-test/src/main/java/sonia/scm/user/UserTestData.java
Normal file
121
scm-test/src/main/java/sonia/scm/user/UserTestData.java
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* 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.user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class UserTestData
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static User createAdams()
|
||||
{
|
||||
return new User("adams", "Douglas Adams", "douglas.adams@hitchhiker.com");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static User createDent()
|
||||
{
|
||||
return new User("dent", "Arthur Dent", "arthur.dent@hitchhiker.com");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static User createMarvin()
|
||||
{
|
||||
return new User("marvin", "Marvin", "paranoid.android@hitchhiker.com");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static User createPerfect()
|
||||
{
|
||||
return new User("perfect", "Ford Prefect", "ford.perfect@hitchhiker.com");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static User createSlarti()
|
||||
{
|
||||
return new User("slarti", "Slartibartfaß", "slartibartfass@hitchhiker.com");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static User createTrillian()
|
||||
{
|
||||
return new User("trillian", "Tricia McMillan",
|
||||
"tricia.mcmillan@hitchhiker.com");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static User createZaphod()
|
||||
{
|
||||
return new User("zaphod", "Zaphod Beeblebrox",
|
||||
"zaphod.beeblebrox@hitchhiker.com");
|
||||
}
|
||||
}
|
||||
125
scm-test/src/main/java/sonia/scm/util/MockUtil.java
Normal file
125
scm-test/src/main/java/sonia/scm/util/MockUtil.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* 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.util;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.security.SecurityContext;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class MockUtil
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HttpServletRequest getHttpServletRequest()
|
||||
{
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
|
||||
when(request.getContextPath()).thenReturn("/scm-webapp");
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static HttpServletResponse getHttpServletResponse()
|
||||
{
|
||||
return mock(HttpServletResponse.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static SCMContextProvider getSCMContextProvider(File directory)
|
||||
{
|
||||
SCMContextProvider provider = mock(SCMContextProvider.class);
|
||||
|
||||
when(provider.getBaseDirectory()).thenReturn(directory);
|
||||
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ package sonia.scm.repository;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.util.MockUtil;
|
||||
import sonia.scm.repository.xml.XmlRepositoryManager;
|
||||
import sonia.scm.store.JAXBStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
@@ -64,10 +65,10 @@ public class XmlRepositoryManagerTest extends RepositoryManagerTestBase
|
||||
Set<RepositoryHandler> handlerSet = new HashSet<RepositoryHandler>();
|
||||
StoreFactory factory = new JAXBStoreFactory();
|
||||
|
||||
factory.init(provider);
|
||||
factory.init(contextProvider);
|
||||
handlerSet.add(new DummyRepositoryHandler(factory));
|
||||
|
||||
return new XmlRepositoryManager(getAdminSecurityContextProvider(), factory,
|
||||
handlerSet);
|
||||
return new XmlRepositoryManager(MockUtil.getAdminSecurityContextProvider(),
|
||||
factory, handlerSet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.user;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.MockUtil;
|
||||
import sonia.scm.store.JAXBStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.user.xml.XmlUserManager;
|
||||
@@ -57,8 +58,9 @@ public class XmlUserManagerTest extends UserManagerTestBase
|
||||
{
|
||||
StoreFactory factory = new JAXBStoreFactory();
|
||||
|
||||
factory.init(provider);
|
||||
factory.init(contextProvider);
|
||||
|
||||
return new XmlUserManager(getAdminSecurityContextProvider(), factory);
|
||||
return new XmlUserManager(MockUtil.getAdminSecurityContextProvider(),
|
||||
factory);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user