mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
Migrate IT for read and commit from/to repository to new module
This commit is contained in:
@@ -21,6 +21,52 @@
|
|||||||
<artifactId>scm-core</artifactId>
|
<artifactId>scm-core</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm</groupId>
|
||||||
|
<artifactId>scm-test</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-git-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-git-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-hg-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-hg-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-svn-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-svn-plugin</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.rest-assured</groupId>
|
<groupId>io.rest-assured</groupId>
|
||||||
<artifactId>rest-assured</artifactId>
|
<artifactId>rest-assured</artifactId>
|
||||||
|
|||||||
@@ -36,19 +36,29 @@ package sonia.scm.it;
|
|||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import sonia.scm.repository.Person;
|
||||||
|
import sonia.scm.repository.client.api.ClientCommand;
|
||||||
|
import sonia.scm.repository.client.api.RepositoryClient;
|
||||||
|
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||||
import sonia.scm.web.VndMediaType;
|
import sonia.scm.web.VndMediaType;
|
||||||
|
|
||||||
import javax.json.Json;
|
import javax.json.Json;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static sonia.scm.it.RegExMatcher.matchesPattern;
|
import static sonia.scm.it.RegExMatcher.matchesPattern;
|
||||||
import static sonia.scm.it.RestUtil.createResourceUrl;
|
import static sonia.scm.it.RestUtil.createResourceUrl;
|
||||||
import static sonia.scm.it.RestUtil.given;
|
import static sonia.scm.it.RestUtil.given;
|
||||||
@@ -56,6 +66,11 @@ import static sonia.scm.it.RestUtil.given;
|
|||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class RepositoriesITCase {
|
public class RepositoriesITCase {
|
||||||
|
|
||||||
|
public static final Person AUTHOR = new Person("SCM Administrator", "scmadmin@scm-manager.org");
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
private final String repositoryType;
|
private final String repositoryType;
|
||||||
|
|
||||||
private String repositoryUrl;
|
private String repositoryUrl;
|
||||||
@@ -138,6 +153,47 @@ public class RepositoriesITCase {
|
|||||||
.statusCode(HttpStatus.SC_CONFLICT);
|
.statusCode(HttpStatus.SC_CONFLICT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCloneRepository() throws IOException {
|
||||||
|
RepositoryClient rc = createRepositoryClient();
|
||||||
|
assertEquals(1, rc.getWorkingCopy().list().length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCommitFiles() throws IOException {
|
||||||
|
RepositoryClient rc = createRepositoryClient();
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
createRandomFile(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
commit(rc, "added some test files");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createRandomFile(RepositoryClient client) throws IOException {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
String name = "file-" + uuid + ".uuid";
|
||||||
|
|
||||||
|
File file = new File(client.getWorkingCopy(), name);
|
||||||
|
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||||
|
out.write(uuid.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
client.getAddCommand().add(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commit(RepositoryClient repositoryClient, String message) throws IOException {
|
||||||
|
repositoryClient.getCommitCommand().commit(AUTHOR, message);
|
||||||
|
if ( repositoryClient.isCommandSupported(ClientCommand.PUSH) ) {
|
||||||
|
repositoryClient.getPushCommand().push();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RepositoryClient createRepositoryClient() throws IOException {
|
||||||
|
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
|
||||||
|
return clientFactory.create(repositoryType, "http://localhost:8081/scm/" + repositoryType + "/scmadmin/HeartOfGold-" + repositoryType, "scmadmin", "scmadmin", temporaryFolder.newFolder());
|
||||||
|
}
|
||||||
|
|
||||||
private String repositoryJson() {
|
private String repositoryJson() {
|
||||||
return Json.createObjectBuilder()
|
return Json.createObjectBuilder()
|
||||||
.add("contact", "zaphod.beeblebrox@hitchhiker.com")
|
.add("contact", "zaphod.beeblebrox@hitchhiker.com")
|
||||||
|
|||||||
@@ -48,19 +48,14 @@ import de.otto.edison.hal.HalRepresentation;
|
|||||||
import sonia.scm.api.rest.JSONContextResolver;
|
import sonia.scm.api.rest.JSONContextResolver;
|
||||||
import sonia.scm.api.rest.ObjectMapperProvider;
|
import sonia.scm.api.rest.ObjectMapperProvider;
|
||||||
import sonia.scm.repository.Person;
|
import sonia.scm.repository.Person;
|
||||||
import sonia.scm.repository.client.api.ClientCommand;
|
|
||||||
import sonia.scm.repository.client.api.RepositoryClient;
|
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -125,43 +120,6 @@ public final class IntegrationTestUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit and push changes.
|
|
||||||
*
|
|
||||||
* @param repositoryClient repository client
|
|
||||||
* @param message commit message
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*
|
|
||||||
* @since 1.51
|
|
||||||
*/
|
|
||||||
public static void commit(RepositoryClient repositoryClient, String message) throws IOException {
|
|
||||||
repositoryClient.getCommitCommand().commit(IntegrationTestUtil.AUTHOR, message);
|
|
||||||
if ( repositoryClient.isCommandSupported(ClientCommand.PUSH) ) {
|
|
||||||
repositoryClient.getPushCommand().push();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
* @param client
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static void createRandomFile(RepositoryClient client) throws IOException
|
|
||||||
{
|
|
||||||
String uuid = UUID.randomUUID().toString();
|
|
||||||
String name = "file-" + uuid + ".uuid";
|
|
||||||
|
|
||||||
File file = new File(client.getWorkingCopy(), name);
|
|
||||||
try (FileOutputStream out = new FileOutputStream(file)) {
|
|
||||||
out.write(uuid.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
client.getAddCommand().add(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<String> createRepositoryTypeParameters() {
|
public static Collection<String> createRepositoryTypeParameters() {
|
||||||
Collection<String> params = new ArrayList<>();
|
Collection<String> params = new ArrayList<>();
|
||||||
|
|
||||||
@@ -206,20 +164,6 @@ public final class IntegrationTestUtil
|
|||||||
return URI.create(REST_BASE_URL).resolve(url);
|
return URI.create(REST_BASE_URL).resolve(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static File createTempDirectory() {
|
|
||||||
File directory = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
|
|
||||||
|
|
||||||
IOUtil.mkdirs(directory);
|
|
||||||
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readJson(String jsonFileName) {
|
public static String readJson(String jsonFileName) {
|
||||||
URL url = Resources.getResource(jsonFileName);
|
URL url = Resources.getResource(jsonFileName);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,311 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.it;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
|
||||||
import sonia.scm.api.v2.resources.RepositoryDto;
|
|
||||||
import sonia.scm.repository.client.api.RepositoryClient;
|
|
||||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
|
||||||
import sonia.scm.user.User;
|
|
||||||
import sonia.scm.user.UserTestData;
|
|
||||||
import sonia.scm.util.IOUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.ADMIN_PASSWORD;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.ADMIN_USERNAME;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.commit;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.createRandomFile;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.createRepositoryTypeParameters;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.createResource;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.createTempDirectory;
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.readJson;
|
|
||||||
import static sonia.scm.it.RepositoryITUtil.createUrl;
|
|
||||||
import static sonia.scm.it.UserITUtil.postUser;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class RepositoryITCaseBase
|
|
||||||
{
|
|
||||||
|
|
||||||
private static final Collection<RepositoryDto> CREATED_REPOSITORIES = new ArrayList<>();
|
|
||||||
|
|
||||||
protected User nopermUser;
|
|
||||||
protected User ownerUser;
|
|
||||||
protected String password;
|
|
||||||
protected User readUser;
|
|
||||||
protected RepositoryDto repository;
|
|
||||||
protected User writeUser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
* @param owner
|
|
||||||
* @param write
|
|
||||||
* @param read
|
|
||||||
* @param noperm
|
|
||||||
* @param password
|
|
||||||
*/
|
|
||||||
public RepositoryITCaseBase(RepositoryDto repository, User owner, User write,
|
|
||||||
User read, User noperm, String password)
|
|
||||||
{
|
|
||||||
this.repository = repository;
|
|
||||||
this.ownerUser = owner;
|
|
||||||
this.writeUser = write;
|
|
||||||
this.readUser = read;
|
|
||||||
this.nopermUser = noperm;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param client
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static void addTestFiles(RepositoryClient client) throws IOException
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
createRandomFile(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
commit(client, "added some test files");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static void addTestFiles(RepositoryDto repository, String username,
|
|
||||||
String password)
|
|
||||||
{
|
|
||||||
File directory = createTempDirectory();
|
|
||||||
|
|
||||||
try {
|
|
||||||
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
|
|
||||||
RepositoryClient client = clientFactory.create(
|
|
||||||
repository.getType(), createUrl(repository),
|
|
||||||
username, password, directory
|
|
||||||
);
|
|
||||||
|
|
||||||
addTestFiles(client);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
IOUtil.delete(directory);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void cleanup()
|
|
||||||
{
|
|
||||||
ScmClient client = createAdminClient();
|
|
||||||
|
|
||||||
deleteUser(client, UserTestData.createTrillian());
|
|
||||||
deleteUser(client, UserTestData.createZaphod());
|
|
||||||
deleteUser(client, UserTestData.createMarvin());
|
|
||||||
deleteUser(client, UserTestData.createPerfect());
|
|
||||||
|
|
||||||
for (RepositoryDto r : CREATED_REPOSITORIES)
|
|
||||||
{
|
|
||||||
createResource(client, "repositories/" + r.getNamespace() + "/" + r.getName()).delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Parameters(name = "{6}")
|
|
||||||
public static Collection<Object[]> createParameters() throws IOException
|
|
||||||
{
|
|
||||||
Collection<Object[]> params = new ArrayList<>();
|
|
||||||
User owner = UserTestData.createTrillian();
|
|
||||||
|
|
||||||
createUser(owner);
|
|
||||||
|
|
||||||
User write = UserTestData.createZaphod();
|
|
||||||
|
|
||||||
createUser(write);
|
|
||||||
|
|
||||||
User read = UserTestData.createMarvin();
|
|
||||||
|
|
||||||
createUser(read);
|
|
||||||
|
|
||||||
User noperm = UserTestData.createPerfect();
|
|
||||||
|
|
||||||
createUser(noperm);
|
|
||||||
createRepositoryTypeParameters().forEach(t -> appendTestParameter(params, t, owner, write, read, noperm));
|
|
||||||
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param params
|
|
||||||
* @param type
|
|
||||||
* @param owner
|
|
||||||
* @param write
|
|
||||||
* @param read
|
|
||||||
* @param noperm
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
private static void appendTestParameter(Collection<Object[]> params,
|
|
||||||
String type, User owner, User write, User read, User noperm)
|
|
||||||
{
|
|
||||||
RepositoryDto repository = createTestRepository(type, owner, write, read);
|
|
||||||
params.add(new Object[]
|
|
||||||
{
|
|
||||||
repository, owner, write, read, noperm, "secret", repository.getType() + "-" + owner.getId()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param owner
|
|
||||||
* @param write
|
|
||||||
* @param read
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
private static RepositoryDto createTestRepository(String type,
|
|
||||||
User owner, User write, User read)
|
|
||||||
{
|
|
||||||
ScmClient client = createAdminClient();
|
|
||||||
|
|
||||||
// TODO Activate for tests when implemented
|
|
||||||
// repository.setPermissions(Arrays.asList(
|
|
||||||
// new Permission(owner.getName(), PermissionType.OWNER),
|
|
||||||
// new Permission(write.getName(), PermissionType.WRITE),
|
|
||||||
// new Permission(read.getName(), PermissionType.READ))
|
|
||||||
// );
|
|
||||||
String repositoryJson = readJson("repository-" + type + ".json");
|
|
||||||
RepositoryDto repository = RepositoryITUtil.createRepository(client, repositoryJson);
|
|
||||||
|
|
||||||
CREATED_REPOSITORIES.add(repository);
|
|
||||||
|
|
||||||
addTestFiles(repository, ADMIN_USERNAME, ADMIN_PASSWORD);
|
|
||||||
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
*/
|
|
||||||
private static void createUser(User user)
|
|
||||||
{
|
|
||||||
ScmClient client = createAdminClient();
|
|
||||||
|
|
||||||
user.setPassword("secret");
|
|
||||||
|
|
||||||
postUser(client, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param client
|
|
||||||
* @param user
|
|
||||||
*/
|
|
||||||
private static void deleteUser(ScmClient client, User user)
|
|
||||||
{
|
|
||||||
createResource(client, "users/".concat(user.getName())).delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
* @param directory
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
protected RepositoryClient createRepositoryClient(User user, File directory) throws IOException
|
|
||||||
{
|
|
||||||
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
|
|
||||||
return clientFactory.create(repository.getType(), createUrl(repository),
|
|
||||||
user.getName(), password, directory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user