Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3: Added tests for Cryo #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>


<checkstyle.plugin.version>2.15</checkstyle.plugin.version>

<org.jboss.jboss-dmr.version>1.1.6.Final</org.jboss.jboss-dmr.version>
Expand Down Expand Up @@ -90,18 +89,6 @@
<artifactId>argparse4j</artifactId>
<version>${version.net.sourceforge.argparse4j}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${version.testng}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
Expand All @@ -119,6 +106,12 @@
<artifactId>jboss-logmanager</artifactId>
<version>${version.org.jboss.logmanager}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -174,6 +167,7 @@
<artifactId>wildfly-build-config</artifactId>
<version>${org.wildfly.wildfly.build.config.version}</version>
</dependency>

</dependencies>
<executions>
<execution>
Expand All @@ -187,7 +181,7 @@
</plugin>
</plugins>
</pluginManagement>
</build>
</build>
<repositories>
<repository>
<id>jboss-public-repository-group</id>
Expand All @@ -204,4 +198,4 @@
</snapshots>
</repository>
</repositories>
</project>
</project>
188 changes: 188 additions & 0 deletions src/test/java/CryoAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.jboss.set.aphrodite.Aphrodite;
import org.jboss.set.aphrodite.config.AphroditeConfig;
import org.jboss.set.aphrodite.config.IssueTrackerConfig;
import org.jboss.set.aphrodite.config.RepositoryConfig;
import org.jboss.set.aphrodite.config.StreamConfig;
import org.jboss.set.aphrodite.config.StreamType;
import org.jboss.set.aphrodite.repository.services.common.RepositoryType;
import org.jboss.set.aphrodite.repository.services.github.GithubPullRequestHomeService;
import org.jboss.set.aphrodite.spi.AphroditeException;
import org.jboss.set.cryo.Cryo;
import org.jboss.set.cryo.process.BisectablePullRequest;
import org.jboss.set.cryo.process.ExecuteProcess;

public class CryoAccess extends Cryo {
private static final String testDirLocation = System.getProperty("user.dir") + "/cryo-tests/";
protected static final String[] COMMAND_GIT_CHECKOUT_MASTER = new String[] { "git", "checkout", "master" };
protected static final String[] COMMAND_GIT_DELETE_FUTURE = new String[] { "git", "branch", "-D", "masterfuture" };
protected static final String[] COMMAND_GIT_LOG = new String[] { "git", "log" };
protected static Aphrodite aphro;

CryoAccess() {
super(new File(testDirLocation), true, false, false, new HashSet<String>(),
CryoAccess.createIncludeList(new String[] { "1" }), "future", "", new String[] {});
}

CryoAccess(String[] includeList) {
super(new File(testDirLocation), true, false, false, new HashSet<String>(),
CryoAccess.createIncludeList(includeList), "future", "", new String[] {});
}

private static List<String> createIncludeList(String[] includeList) {
List<String> include;
include = new ArrayList<>();
for (String pr : includeList)
include.add(pr);
return include;
}

public boolean createOperationCenter() {
return super.createOperationCenter();
}

public boolean determineRepositoryURL() {
return super.determineRepositoryURL();
}

public boolean determineCurrentBranch() {
return super.determineCurrentBranch();
}

public boolean fetchPRList(String repoUrl) throws MalformedURLException {
determineCurrentBranch();
super.repositoryURL = new URL(repoUrl);
return super.fetchPRList();
}

public URL getRepositoryURL() {
return super.repositoryURL;
}

public void initializeAphrodite() throws MalformedURLException {

RepositoryConfig githubService = new RepositoryConfig("https://github.com/", "fazer1929",
"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",
RepositoryType.GITHUB);
List<RepositoryConfig> repositoryConfigs = new ArrayList<>();
repositoryConfigs.add(githubService);

List<IssueTrackerConfig> issueTrackerConfigs = new ArrayList<>();

StreamConfig streamService = new StreamConfig(
new URL("https://raw.githubusercontent.com/jboss-set/jboss-streams/master/streams.json"), StreamType.JSON);
List<StreamConfig> streamConfigs = new ArrayList<>();
streamConfigs.add(streamService);

try {
AphroditeConfig aphroditeConfig = new AphroditeConfig(issueTrackerConfigs, repositoryConfigs, streamConfigs);
this.aphrodite = Aphrodite.instance(aphroditeConfig);
GithubPullRequestHomeService GithubPullRequestHomeService = new GithubPullRequestHomeService(aphrodite);
super.aphrodite = this.aphrodite;
} catch (AphroditeException e) {
e.printStackTrace();
}
}

public void setUpCryo(String repoURL) throws MalformedURLException {
ProcessBuilder processBuilder = new ProcessBuilder(
new String[] { "git", "clone", repoURL });
ExecuteProcess executeProcess = new ExecuteProcess(processBuilder);
executeProcess.getProcessResult();

this.createOperationCenter();
if (CryoAccess.aphro == null) {
this.initializeAphrodite();
CryoAccess.aphro = super.aphrodite;
} else {
this.aphrodite = CryoAccess.aphro;
super.aphrodite = CryoAccess.aphro;
}
}

private void cleanupFutureBranch() {
ProcessBuilder processBuilder = new ProcessBuilder(
COMMAND_GIT_CHECKOUT_MASTER);
processBuilder.directory(new File(testDirLocation));
ExecuteProcess executeProcess = new ExecuteProcess(processBuilder);
executeProcess.getProcessResult();
processBuilder = new ProcessBuilder(
COMMAND_GIT_DELETE_FUTURE);
processBuilder.directory(new File(testDirLocation));
executeProcess = new ExecuteProcess(processBuilder);
executeProcess.getProcessResult();
}

public boolean setUpFutureBranch() {
if (super.setUpFutureBranch()) {
cleanupFutureBranch();
return true;
}
return false;
}

private boolean checkShaExists() {
// Getting latest commit ids of every eligible PR
List<String> shas = new ArrayList<>();
for (BisectablePullRequest bpr : coldStorage) {
shas.add(bpr.getPullRequest().getCommits().get(0).getSha());
}
boolean includesAll = true;

// Getting the logs of directory cryo created

ProcessBuilder processBuilder = new ProcessBuilder(
COMMAND_GIT_LOG);
processBuilder.directory(new File(testDirLocation));
ExecuteProcess executeProcess = new ExecuteProcess(processBuilder);
String logs = executeProcess.getProcessResult().getOutput();

// Checking id all the commits exist
for (String sha : shas) {
includesAll = logs.contains(sha);
if (!includesAll)
break;
}
return includesAll;
}

public boolean mergePRs() {
try {
cleanupFutureBranch();
super.createStorage();
if (checkShaExists())
return true;
return false;
} catch (Exception e) {
return false;
}
}
}
101 changes: 101 additions & 0 deletions src/test/java/TestCryo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

import static junit.framework.TestCase.assertEquals;

import java.net.MalformedURLException;
import java.net.URL;

import org.jboss.set.cryo.process.ExecuteProcess;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestCryo {
private static CryoAccess cryo;
private static String repoURL;
protected static final String[] COMMAND_REMOVE_TEST_DIR = new String[]{"rm", "-rf", "cryo-tests"};

public TestCryo() throws MalformedURLException {
repoURL = "https://github.com/jboss-set/cryo-tests";
cryo = new CryoAccess();
System.setProperty("aphrodite.config", "/home/abagrawa/Desktop/aphrodite.properties.json");
cryo.setUpCryo(repoURL);

}

@BeforeClass
public static void setup() throws MalformedURLException {
System.out.println("Lol");
}

@Test
public void test1DetermineRepositoryURL() throws MalformedURLException {
assertEquals(cryo.determineRepositoryURL(), true);
assertEquals(cryo.getRepositoryURL(), new URL(repoURL));
}

@Test
public void test2DetermineCurrentBranch() {
assertEquals(cryo.determineCurrentBranch(), true);
}

@Test
public void test3FetchPRList() throws MalformedURLException {
assertEquals(cryo.fetchPRList(repoURL), true);
}

@Test
public void test4SetupFutureBranch() throws Exception {
cryo.fetchPRList(repoURL);
assertEquals(cryo.setUpFutureBranch(), true);
}

@Test
public void test5MergeSinglePR() throws MalformedURLException {
assertEquals(cryo.mergePRs(), true);
}

@Test
public void test6MergemultiplePRs() throws MalformedURLException {
cryo = new CryoAccess(new String[]{"2", "3"});
cryo.setUpCryo(repoURL);
assertEquals(cryo.mergePRs(), true);
}

@Test
public void test7MergePRWithDependency() throws MalformedURLException {
cryo = new CryoAccess(new String[]{"10", "11", "12"});
cryo.setUpCryo(repoURL);
assertEquals(cryo.mergePRs(), true);
}

@AfterClass
public static void removeDir() {
ProcessBuilder processBuilder = new ProcessBuilder(COMMAND_REMOVE_TEST_DIR);
ExecuteProcess executeProcess = new ExecuteProcess(processBuilder);
executeProcess.getProcessResult();
}
}