Move scm-webapp integration tests to scm-it

This commit is contained in:
Sebastian Sdorra
2021-01-12 09:17:08 +01:00
committed by René Pfeuffer
parent 3e9160a600
commit 6b30da247a
15 changed files with 108 additions and 169 deletions

View File

@@ -51,6 +51,12 @@ dependencies {
testImplementation 'io.rest-assured:rest-assured:4.3.0'
testImplementation 'org.glassfish:javax.json:1.1.4'
// dependencies for tests in sonia.scm.it.webapp
testImplementation project(':scm-webapp')
testImplementation libraries.jerseyClientApi
testImplementation libraries.jerseyClientRuntime
testImplementation libraries.jacksonJaxbAnnotations
itWebApp project(path: ':scm-webapp', configuration: 'webapp')
itPlugin project(path: ':scm-plugins:scm-integration-test-plugin', configuration: 'smp')
}

View File

@@ -1,66 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
MIT License
Copyright (c) 2020-present Cloudogu GmbH and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<!-- increase header size for mercurial -->
<Set name="requestHeaderSize">16384</Set>
<Set name="responseHeaderSize">16384</Set>
</New>
<Call id="httpConnector" name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server">
<Ref refid="Server" />
</Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config">
<Ref refid="httpConfig" />
</Arg>
</New>
</Item>
</Array>
</Arg>
<Set name="host">
<Property name="jetty.host" />
</Set>
<Set name="port">
<Property name="jetty.port" default="8081" />
</Set>
<Set name="idleTimeout">
<Property name="http.timeout" default="30000"/>
</Set>
</New>
</Arg>
</Call>
</Configure>

View File

@@ -21,12 +21,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
//~--- non-JDK imports --------------------------------------------------------
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.webapp.IntegrationTestUtil.createAdminClient;
//~--- JDK imports ------------------------------------------------------------

View File

@@ -21,14 +21,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
//~--- non-JDK imports --------------------------------------------------------
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
@@ -40,9 +41,9 @@ import java.util.Collection;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.IntegrationTestUtil.createResource;
import static sonia.scm.it.IntegrationTestUtil.post;
import static sonia.scm.it.webapp.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.webapp.IntegrationTestUtil.createResource;
import static sonia.scm.it.webapp.IntegrationTestUtil.post;
//~--- JDK imports ------------------------------------------------------------
@@ -102,7 +103,7 @@ public abstract class AbstractPermissionITCaseBase<T>
ClientResponse response = UserITUtil.postUser(client, trillian);
assertNotNull(response);
assertEquals(201, response.getStatus());
Assert.assertEquals(201, response.getStatus());
response.close();
}
@@ -267,11 +268,11 @@ public abstract class AbstractPermissionITCaseBase<T>
if (credentials.isAnonymous())
{
assertEquals(401, response.getStatus());
Assert.assertEquals(401, response.getStatus());
}
else
{
assertEquals(403, response.getStatus());
Assert.assertEquals(403, response.getStatus());
}
response.close();

View File

@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
//~--- non-JDK imports --------------------------------------------------------

View File

@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -55,13 +55,13 @@ import java.net.URI;
import java.util.UUID;
import static org.junit.Assert.assertArrayEquals;
import static sonia.scm.it.IntegrationTestUtil.BASE_URL;
import static sonia.scm.it.IntegrationTestUtil.REST_BASE_URL;
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.IntegrationTestUtil.createResource;
import static sonia.scm.it.IntegrationTestUtil.readJson;
import static sonia.scm.it.RepositoryITUtil.createRepository;
import static sonia.scm.it.RepositoryITUtil.deleteRepository;
import static sonia.scm.it.webapp.IntegrationTestUtil.BASE_URL;
import static sonia.scm.it.webapp.IntegrationTestUtil.REST_BASE_URL;
import static sonia.scm.it.webapp.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.webapp.IntegrationTestUtil.createResource;
import static sonia.scm.it.webapp.IntegrationTestUtil.readJson;
import static sonia.scm.it.webapp.RepositoryITUtil.createRepository;
import static sonia.scm.it.webapp.RepositoryITUtil.deleteRepository;
/**
* Integration tests for git lfs.

View File

@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
@@ -42,13 +42,13 @@ import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static sonia.scm.it.IntegrationTestUtil.ADMIN_PASSWORD;
import static sonia.scm.it.IntegrationTestUtil.ADMIN_USERNAME;
import static sonia.scm.it.IntegrationTestUtil.BASE_URL;
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.IntegrationTestUtil.readJson;
import static sonia.scm.it.RepositoryITUtil.createRepository;
import static sonia.scm.it.RepositoryITUtil.deleteRepository;
import static sonia.scm.it.webapp.IntegrationTestUtil.ADMIN_PASSWORD;
import static sonia.scm.it.webapp.IntegrationTestUtil.ADMIN_USERNAME;
import static sonia.scm.it.webapp.IntegrationTestUtil.BASE_URL;
import static sonia.scm.it.webapp.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.webapp.IntegrationTestUtil.readJson;
import static sonia.scm.it.webapp.RepositoryITUtil.createRepository;
import static sonia.scm.it.webapp.RepositoryITUtil.deleteRepository;
/**
* Integration test for RepositoryPathMatching with ".git" and without ".git".

View File

@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
//~--- non-JDK imports --------------------------------------------------------

View File

@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
@@ -53,55 +53,55 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.core.AllOf.allOf;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static sonia.scm.it.IntegrationTestUtil.createResource;
import static sonia.scm.it.IntegrationTestUtil.readJson;
import static sonia.scm.it.RepositoryITUtil.createRepository;
import static sonia.scm.it.RepositoryITUtil.deleteRepository;
import static sonia.scm.it.webapp.IntegrationTestUtil.createResource;
import static sonia.scm.it.webapp.IntegrationTestUtil.readJson;
import static sonia.scm.it.webapp.RepositoryITUtil.createRepository;
import static sonia.scm.it.webapp.RepositoryITUtil.deleteRepository;
/**
* Integration tests for repository hooks.
*
*
* @author Sebastian Sdorra
*/
@RunWith(Parameterized.class)
public class RepositoryHookITCase extends AbstractAdminITCaseBase
{
private static final long WAIT_TIME = 125;
private static final RepositoryClientFactory REPOSITORY_CLIENT_FACTORY = new RepositoryClientFactory();
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
private final String repositoryType;
private RepositoryDto repository;
private File workingCopy;
private RepositoryClient repositoryClient;
/**
* Constructs a new instance with a repository type.
*
*
* @param repositoryType repository type
*/
public RepositoryHookITCase(String repositoryType)
{
this.repositoryType = repositoryType;
}
/**
* Creates a test repository.
*
* @throws IOException
*
* @throws IOException
*/
@Before
public void setUpTestRepository() throws IOException
public void setUpTestRepository() throws IOException
{
repository = createRepository(client, readJson("repository-" + repositoryType + ".json"));
workingCopy = tempFolder.newFolder();
repositoryClient = createRepositoryClient();
}
/**
* Removes the tests repository.
*/
@@ -112,59 +112,59 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
deleteRepository(client, repository);
}
}
/**
* Tests that the debug service has received the commit.
*
*
* @throws IOException
* @throws InterruptedException
* @throws InterruptedException
*/
@Test
public void testSimpleHook() throws IOException, InterruptedException
public void testSimpleHook() throws IOException, InterruptedException
{
// commit and push commit
Files.write("a", new File(workingCopy, "a.txt"), Charsets.UTF_8);
repositoryClient.getAddCommand().add("a.txt");
Changeset changeset = commit("added a");
// wait some time, because the debug hook is asnychron
Thread.sleep(WAIT_TIME);
// check debug servlet for pushed commit
WebResource.Builder wr = createResource(client, "../debug/" + repository.getNamespace() + "/" + repository.getName() + "/post-receive/last");
DebugHookData data = wr.get(DebugHookData.class);
assertNotNull(data);
assertThat(data.getChangesets(), contains(changeset.getId()));
}
/**
* Tests that the debug service receives only new commits.
*
*
* @throws IOException
* @throws InterruptedException
* @throws InterruptedException
*/
@Test
public void testOnlyNewCommit() throws IOException, InterruptedException
public void testOnlyNewCommit() throws IOException, InterruptedException
{
// skip test if branches are not supported by repository type
Assume.assumeTrue(repositoryClient.isCommandSupported(ClientCommand.BRANCH));
// push commit
Files.write("a", new File(workingCopy, "a.txt"), Charsets.UTF_8);
repositoryClient.getAddCommand().add("a.txt");
Changeset a = commit("added a");
// create branch
repositoryClient.getBranchCommand().branch("feature/added-b");
// commit and push again
Files.write("b", new File(workingCopy, "b.txt"), Charsets.UTF_8);
repositoryClient.getAddCommand().add("a.txt");
Changeset b = commit("added b");
// wait some time, because the debug hook is asnychron
Thread.sleep(WAIT_TIME);
// check debug servlet that only one commit is present
WebResource.Builder wr = createResource(client, String.format("../debug/%s/%s/post-receive/last", repository.getNamespace(), repository.getName()));
DebugHookData data = wr.get(DebugHookData.class);
@@ -176,7 +176,7 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
)
));
}
private Changeset commit(String message) throws IOException {
Changeset a = repositoryClient.getCommitCommand().commit(
new Person("scmadmin", "scmadmin@scm-manager.org"), message
@@ -186,8 +186,8 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
}
return a;
}
private RepositoryClient createRepositoryClient() throws IOException
private RepositoryClient createRepositoryClient() throws IOException
{
return REPOSITORY_CLIENT_FACTORY.create(repositoryType,
String.format("%srepo/%s/%s", IntegrationTestUtil.BASE_URL, repository.getNamespace(), repository.getName()),
@@ -195,7 +195,7 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
);
}
/**
* Returns repository types a test parameter.
*
@@ -206,5 +206,5 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
{
return IntegrationTestUtil.createRepositoryTypeParameters();
}
}

View File

@@ -21,13 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
//~--- non-JDK imports --------------------------------------------------------
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.junit.Assert;
import sonia.scm.api.rest.ObjectMapperProvider;
import sonia.scm.api.v2.resources.RepositoryDto;
import sonia.scm.web.VndMediaType;
@@ -38,9 +39,9 @@ import java.net.URI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static sonia.scm.it.IntegrationTestUtil.BASE_URL;
import static sonia.scm.it.IntegrationTestUtil.createResource;
import static sonia.scm.it.IntegrationTestUtil.getLink;
import static sonia.scm.it.webapp.IntegrationTestUtil.BASE_URL;
import static sonia.scm.it.webapp.IntegrationTestUtil.createResource;
import static sonia.scm.it.webapp.IntegrationTestUtil.getLink;
//~--- JDK imports ------------------------------------------------------------
@@ -57,7 +58,7 @@ public final class RepositoryITUtil
.post(ClientResponse.class, repositoryJson);
assertNotNull(response);
assertEquals(201, response.getStatus());
Assert.assertEquals(201, response.getStatus());
URI url = URI.create(response.getHeaders().get("Location").get(0));
@@ -79,13 +80,13 @@ public final class RepositoryITUtil
ClientResponse response = createResource(client, deleteUrl).delete(ClientResponse.class);
assertNotNull(response);
assertEquals(204, response.getStatus());
Assert.assertEquals(204, response.getStatus());
response.close();
URI selfUrl = getLink(repository, "self");
response = createResource(client, selfUrl).get(ClientResponse.class);
assertNotNull(response);
assertEquals(404, response.getStatus());
Assert.assertEquals(404, response.getStatus());
response.close();
}
@@ -95,7 +96,7 @@ public final class RepositoryITUtil
ClientResponse response = wr.get(ClientResponse.class);
assertNotNull(response);
assertEquals(200, response.getStatus());
Assert.assertEquals(200, response.getStatus());
String json = response.getEntity(String.class);
RepositoryDto repository = null;

View File

@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
//~--- non-JDK imports --------------------------------------------------------
@@ -30,6 +30,7 @@ import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import de.otto.edison.hal.HalRepresentation;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -42,9 +43,9 @@ import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.IntegrationTestUtil.createResource;
import static sonia.scm.it.IntegrationTestUtil.serialize;
import static sonia.scm.it.webapp.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.webapp.IntegrationTestUtil.createResource;
import static sonia.scm.it.webapp.IntegrationTestUtil.serialize;
//~--- JDK imports ------------------------------------------------------------
@@ -92,7 +93,7 @@ public class RepositorySimplePermissionITCase
ClientResponse response = wr.type(VndMediaType.REPOSITORY).post(ClientResponse.class, serialize(repository));
assertNotNull(response);
assertEquals(201, response.getStatus());
Assert.assertEquals(201, response.getStatus());
String repositoryUrl = response.getHeaders().getFirst("Location");
@@ -100,7 +101,7 @@ public class RepositorySimplePermissionITCase
response.close();
response = client.resource(repositoryUrl).get(ClientResponse.class);
assertNotNull(response);
assertEquals(200, response.getStatus());
Assert.assertEquals(200, response.getStatus());
repository = new ObjectMapperProvider().get().readValue(response.getEntity(String.class), RepositoryDto.class);
REPOSITORY_PATH = repository.getNamespace() + "/" + repository.getName();
assertNotNull(REPOSITORY_PATH);
@@ -129,7 +130,7 @@ public class RepositorySimplePermissionITCase
if (!credentials.isAnonymous())
{
assertNotNull(response);
assertEquals(200, response.getStatus());
Assert.assertEquals(200, response.getStatus());
HalRepresentation repositories =
null;
@@ -157,7 +158,7 @@ public class RepositorySimplePermissionITCase
if (!credentials.isAnonymous())
{
assertNotNull(response);
assertEquals(403, response.getStatus());
Assert.assertEquals(403, response.getStatus());
response.close();
}
}

View File

@@ -21,15 +21,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import java.util.Base64;
import static sonia.scm.it.IntegrationTestUtil.createClient;
import static sonia.scm.it.webapp.IntegrationTestUtil.createClient;
public class ScmClient {
private final String user;

View File

@@ -21,14 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
import com.sun.jersey.api.client.ClientResponse;
import sonia.scm.user.User;
import sonia.scm.web.VndMediaType;
import static sonia.scm.it.IntegrationTestUtil.post;
import static sonia.scm.it.webapp.IntegrationTestUtil.post;
public class UserITUtil {
public static ClientResponse postUser(ScmClient client, User user) {

View File

@@ -21,13 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.it;
package sonia.scm.it.webapp;
//~--- non-JDK imports --------------------------------------------------------
import com.sun.jersey.api.client.ClientResponse;
import de.otto.edison.hal.HalRepresentation;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -153,7 +154,7 @@ public class UserPermissionITCase extends AbstractPermissionITCaseBase<User>
if (!credentials.isAnonymous())
{
assertNotNull(response);
assertEquals(200, response.getStatus());
Assert.assertEquals(200, response.getStatus());
HalRepresentation repositories =
null;

View File

@@ -127,11 +127,6 @@ dependencies {
// shiro unit
testImplementation libraries.shiroUnit
// rest api client
// TODO do we need this?
testImplementation libraries.jerseyClientApi
testImplementation libraries.jerseyClientRuntime
}
war {