added JerseyClientRepositoryClientHandlerITCase

This commit is contained in:
Sebastian Sdorra
2011-05-11 18:50:04 +02:00
parent 4bc38ef107
commit 48fbaf53bd
6 changed files with 280 additions and 34 deletions

View File

@@ -51,6 +51,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>sonia.scm</groupId>
<artifactId>scm-test</artifactId>
<version>1.3-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -0,0 +1,111 @@
/**
* 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.client.it;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.client.JerseyClientProvider;
import sonia.scm.client.JerseyClientSession;
import sonia.scm.client.ScmClientException;
/**
*
* @author Sebastian Sdorra
*/
public class AbstractITCaseBase
{
/** Field description */
public static final String ADMIN_PASSWORD = "scmadmin";
/** Field description */
public static final String ADMIN_USERNAME = "scmadmin";
/** Field description */
public static final String REPOSITORY_TYPE = "git";
/** Field description */
public static final String URL_BASE = "http://localhost:8081/scm";
/** Field description */
public static final boolean REQUEST_LOGGING = false;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*
* @throws ScmClientException
*/
protected JerseyClientSession createAdminSession() throws ScmClientException
{
return createSession(ADMIN_USERNAME, ADMIN_PASSWORD);
}
/**
* Method description
*
*
* @return
*
* @throws ScmClientException
*/
protected JerseyClientSession createAnonymousSession()
throws ScmClientException
{
return createSession(null, null);
}
/**
* Method description
*
*
* @param username
* @param password
*
* @return
*
* @throws ScmClientException
*/
protected JerseyClientSession createSession(String username, String password)
throws ScmClientException
{
JerseyClientProvider provider = new JerseyClientProvider(REQUEST_LOGGING);
return provider.createSession(URL_BASE, username, password);
}
}

View File

@@ -38,7 +38,6 @@ package sonia.scm.client.it;
import org.junit.Test;
import sonia.scm.client.ClientUtil;
import sonia.scm.client.JerseyClientProvider;
import sonia.scm.client.JerseyClientSession;
import sonia.scm.client.ScmClientException;
import sonia.scm.client.ScmUrlProvider;
@@ -51,33 +50,41 @@ import static org.junit.Assert.*;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*/
public class JerseyClientProviderITCase
public class JerseyClientProviderITCase extends AbstractITCaseBase
{
/**
* Method description
*
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test(expected = ScmClientException.class)
public void createSessionAnonymousFailedTest() throws ScmClientException
public void createSessionAnonymousFailedTest()
throws ScmClientException, IOException
{
createSession(null, null);
createAnonymousSession().close();
}
/**
* Method description
*
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test
public void createSessionAnonymousTest() throws ScmClientException
public void createSessionAnonymousTest()
throws ScmClientException, IOException
{
JerseyClientSession adminSession = createSession("scmadmin", "scmadmin");
@@ -85,78 +92,68 @@ public class JerseyClientProviderITCase
ScmUrlProvider up = adminSession.getUrlProvider();
Client client = adminSession.getClient();
WebResource resource = ClientUtil.createResource(client,
up.getResourceUrl("config"), true);
up.getResourceUrl("config"), REQUEST_LOGGING);
ScmConfiguration config = resource.get(ScmConfiguration.class);
config.setAnonymousAccessEnabled(true);
resource.post(config);
// test anonymous access
createSession(null, null);
createAnonymousSession().close();
// disable anonymous access
config.setAnonymousAccessEnabled(false);
resource.post(config);
adminSession.close();
}
/**
* Method description
*
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test
public void createSessionTest() throws ScmClientException
public void createSessionTest() throws ScmClientException, IOException
{
JerseyClientSession session = createSession("scmadmin", "scmadmin");
JerseyClientSession session = createAdminSession();
assertNotNull(session);
assertNotNull(session.getState());
assertNotNull(session.getState().getUser());
assertEquals(session.getState().getUser().getName(), "scmadmin");
session.close();
}
/**
* Method description
*
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test(expected = ScmClientException.class)
public void createSessionWithUnkownUserTest() throws ScmClientException
public void createSessionWithUnkownUserTest()
throws ScmClientException, IOException
{
createSession("dent", "dent123");
createSession("dent", "dent123").close();
}
/**
* Method description
*
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test(expected = ScmClientException.class)
public void createSessionWithWrongPasswordTest() throws ScmClientException
public void createSessionWithWrongPasswordTest()
throws ScmClientException, IOException
{
createSession("scmadmin", "ka123");
}
/**
* Method description
*
*
* @param username
* @param password
*
* @return
*
* @throws ScmClientException
*/
private JerseyClientSession createSession(String username, String password)
throws ScmClientException
{
JerseyClientProvider provider = new JerseyClientProvider(true);
return provider.createSession("http://localhost:8081/scm", username,
password);
createSession("scmadmin", "ka123").close();
}
}

View File

@@ -0,0 +1,130 @@
/**
* 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.client.it;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import sonia.scm.client.JerseyClientSession;
import sonia.scm.client.RepositoryClientHandler;
import sonia.scm.client.ScmClientException;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryTestData;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*/
public class JerseyClientRepositoryClientHandlerITCase
extends AbstractITCaseBase
{
/**
* Method description
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test
public void testCreate() throws ScmClientException, IOException
{
JerseyClientSession session = createAdminSession();
Repository hog = RepositoryTestData.createHeartOfGold(REPOSITORY_TYPE);
RepositoryClientHandler handler = session.getRepositoryHandler();
handler.create(hog);
assertNotNull(hog.getId());
assertNotNull(hog.getCreationDate());
String id = hog.getId();
Repository r = handler.get(id);
assertNotNull(r);
assertEquals(hog, r);
session.close();
}
/**
* Method description
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test(expected = ScmClientException.class)
public void testCreateAnonymous() throws ScmClientException, IOException
{
JerseyClientSession session = createAnonymousSession();
Repository p42 = RepositoryTestData.create42Puzzle(REPOSITORY_TYPE);
session.getRepositoryHandler().create(p42);
session.close();
}
/**
* Method description
*
*
* @throws IOException
* @throws ScmClientException
*/
@Test
public void testDelete() throws ScmClientException, IOException
{
JerseyClientSession session = createAdminSession();
Repository hvpt =
RepositoryTestData.createHappyVerticalPeopleTransporter(REPOSITORY_TYPE);
RepositoryClientHandler handler = session.getRepositoryHandler();
handler.create(hvpt);
assertNotNull(hvpt.getId());
assertNotNull(hvpt.getCreationDate());
String id = hvpt.getId();
handler.delete(hvpt);
Repository r = handler.get(id);
assertNull(r);
}
}

View File

@@ -273,6 +273,7 @@
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<contextPath>/scm</contextPath>
<source>${project.build.javaLevel}</source>
<target>${project.build.javaLevel}</target>
<encoding>${project.build.sourceEncoding}</encoding>

View File

@@ -64,7 +64,7 @@ public class IntegrationTestUtil
/** Field description */
public static final String BASE_URL =
"http://localhost:8081/scm-webapp/api/rest/";
"http://localhost:8081/scm/api/rest/";
/** Field description */
public static final String EXTENSION = ".xml";