de.dagere.peass.debugtools.CompareDependencies Maven / Gradle / Ivy
The newest version!
package de.dagere.peass.debugtools;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import de.dagere.nodeDiffDetector.data.MethodCall;
import de.dagere.nodeDiffDetector.data.TestCase;
import de.dagere.nodeDiffDetector.data.TestMethodCall;
import de.dagere.peass.dependency.persistence.InitialCallList;
import de.dagere.peass.dependency.persistence.StaticTestSelection;
import de.dagere.peass.utils.Constants;
/**
* Compares two dependency files in order to find whether one is missing some testcases
* @author reichelt
*
*/
public class CompareDependencies {
public static void main(final String[] args) throws JsonParseException, JsonMappingException, IOException {
final File oldDependenciesFile = new File(args[0]);
final File newDependenciesFile = new File(args[1]);
final StaticTestSelection oldDependencies = Constants.OBJECTMAPPER.readValue(oldDependenciesFile, StaticTestSelection.class) ;
final StaticTestSelection newDependencies = Constants.OBJECTMAPPER.readValue(newDependenciesFile, StaticTestSelection.class);
int addedCount = 0, missingCount = 0;
final List notFoundNewDependencies = new LinkedList<>();
notFoundNewDependencies.addAll(newDependencies.getInitialcommit().getInitialDependencies().keySet());
for (final Entry initialDepOld : oldDependencies.getInitialcommit().getInitialDependencies().entrySet()) {
for (final Entry initialDepNew : newDependencies.getInitialcommit().getInitialDependencies().entrySet()) {
if (initialDepNew.getKey().equals(initialDepOld.getKey())) {
final List missing = getDifference(initialDepOld.getValue(), initialDepNew.getValue());
final List added = getDifference(initialDepNew.getValue(), initialDepOld.getValue());
if (missing.size() > 0 || added.size() > 0) {
System.out.println("Test: " + initialDepNew.getKey() + "(" + initialDepNew.getValue().getEntities().size()
+" " + initialDepOld.getValue().getEntities().size() + ")");
System.out.println("Missing: " + missing);
System.out.println("Added: " + added);
addedCount+=added.size();
missingCount+=missing.size();
}
notFoundNewDependencies.remove(initialDepNew.getKey());
}
}
}
System.out.println("Added: " + addedCount + " Missing: " + missingCount);
System.out.println("Missing testcases: " + notFoundNewDependencies.size());
for (final TestCase change : notFoundNewDependencies) {
System.out.println("Missing: " + change.toString());
}
}
private static List getDifference(final InitialCallList initialDepOld, final InitialCallList initialDepNew) {
final List missing = new LinkedList<>();
for (final MethodCall clazz : initialDepOld.getEntities()){
missing.add(clazz.toString());
}
for (final MethodCall clazz : initialDepNew.getEntities()){
missing.remove(clazz.toString());
}
for (final Iterator it = missing.iterator(); it.hasNext();) {
final String current = it.next();
if (current.endsWith("getMaximalTime") || current.endsWith("getExecutionTimes") || current.endsWith("getWarmupExecutions")) {
it.remove();
}
}
return missing;
}
}