mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-07 12:50:54 +01:00
Move tests to test classes
This commit is contained in:
@@ -3,17 +3,14 @@ package sonia.scm.it;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.repository.Changeset;
|
||||
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.RepositoryClientException;
|
||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -23,35 +20,6 @@ public class RepositoryUtil {
|
||||
|
||||
private static final RepositoryClientFactory REPOSITORY_CLIENT_FACTORY = new RepositoryClientFactory();
|
||||
|
||||
static void addRandomFileToRepository(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);
|
||||
}
|
||||
|
||||
static boolean canScmAdminCommit(String repositoryType, TemporaryFolder temporaryFolder) throws IOException {
|
||||
return canUserCommit("scmadmin", "scmadmin", repositoryType, temporaryFolder);
|
||||
}
|
||||
|
||||
static boolean canUserCommit(String username, String password, String repositoryType, TemporaryFolder temporaryFolder) throws IOException {
|
||||
RepositoryClient client = RepositoryUtil.createRepositoryClient(repositoryType, temporaryFolder.newFolder(), username, password);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
addRandomFileToRepository(client);
|
||||
}
|
||||
try{
|
||||
commit(client, username, "commit");
|
||||
}catch (RepositoryClientException e){
|
||||
return false;
|
||||
}
|
||||
RepositoryClient checkClient = RepositoryUtil.createRepositoryClient(repositoryType, temporaryFolder.newFolder(), username, password);
|
||||
return checkClient.getWorkingCopy().list().length == 6;
|
||||
}
|
||||
|
||||
static RepositoryClient createRepositoryClient(String repositoryType, File folder) throws IOException {
|
||||
return createRepositoryClient(repositoryType, folder, "scmadmin", "scmadmin");
|
||||
}
|
||||
@@ -69,25 +37,16 @@ public class RepositoryUtil {
|
||||
|
||||
return REPOSITORY_CLIENT_FACTORY.create(repositoryType, httpProtocolUrl, username, password, folder);
|
||||
}
|
||||
static void assertDeleteRepositoryOperation(String user, int deleteStatus, int getStatus, String password, String repositoryType) {
|
||||
given(VndMediaType.REPOSITORY, user, password)
|
||||
|
||||
.when()
|
||||
.delete(TestData.getDefaultRepositoryUrl(repositoryType))
|
||||
|
||||
.then()
|
||||
.statusCode(deleteStatus);
|
||||
|
||||
given(VndMediaType.REPOSITORY, user, password)
|
||||
|
||||
.when()
|
||||
.get(TestData.getDefaultRepositoryUrl(repositoryType))
|
||||
|
||||
.then()
|
||||
.statusCode(getStatus);
|
||||
static String addAndCommitRandomFile(RepositoryClient client, String username) throws IOException {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String name = "file-" + uuid + ".uuid";
|
||||
createAndCommitFile(client, username, name, uuid);
|
||||
return name;
|
||||
}
|
||||
static void createAndCommitFile(File folder, RepositoryClient repositoryClient, String username, String fileName, String content) throws IOException {
|
||||
Files.write(content, new File(folder, fileName), Charsets.UTF_8);
|
||||
|
||||
static void createAndCommitFile(RepositoryClient repositoryClient, String username, String fileName, String content) throws IOException {
|
||||
Files.write(content, new File(repositoryClient.getWorkingCopy(), fileName), Charsets.UTF_8);
|
||||
repositoryClient.getAddCommand().add(fileName);
|
||||
commit(repositoryClient, username, "added " + fileName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user