Search in sources :

Example 1 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class ClassifyByRules method classifyProject.

private void classifyProject(final Set<String> allFeatures, final String project) throws IOException, JsonParseException, JsonMappingException {
    final RepoFolders repos = new RepoFolders();
    final File learnFile = new File(repos.getClassificationFolder(), project + ".json");
    final File learnPropertyFile = repos.getProjectPropertyFile(project);
    final Classification learn = Constants.OBJECTMAPPER.readValue(learnFile, Classification.class);
    final VersionChangeProperties changes = Constants.OBJECTMAPPER.readValue(learnPropertyFile, VersionChangeProperties.class);
    final File methodFileFolder = new File(learnPropertyFile.getParentFile(), "methods");
    try (BufferedWriter csvWriter = new BufferedWriter(new FileWriter(new File(project + ".csv")))) {
        for (final Entry<String, ChangeProperties> version : changes.getVersions().entrySet()) {
            final File versionFolder = new File(methodFileFolder, version.getKey());
            for (final Entry<String, List<ChangeProperty>> testcase : version.getValue().getProperties().entrySet()) {
                for (final ChangeProperty property : testcase.getValue()) {
                    final VersionClass versionClass = learn.getVersions().get(version.getKey());
                    final ChangedEntity entity = new ChangedEntity(testcase.getKey(), "", property.getMethod());
                    final TestcaseClass testcaseClass = versionClass.getTestcases().get(entity);
                    final GuessDecider guesser = new GuessDecider(versionFolder);
                    final Set<String> types = testcaseClass.getTypes();
                    writeFeatures(allFeatures, csvWriter, property, guesser);
                    writeType(csvWriter, types);
                    csvWriter.write("\n");
                    csvWriter.flush();
                }
            }
        }
    }
}
Also used : VersionClass(de.dagere.peass.analysis.groups.VersionClass) FileWriter(java.io.FileWriter) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) BufferedWriter(java.io.BufferedWriter) Classification(de.dagere.peass.analysis.groups.Classification) ChangeProperties(de.dagere.peass.analysis.properties.ChangeProperties) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File) GuessDecider(de.dagere.peass.analysis.guessing.GuessDecider) RepoFolders(de.dagere.peass.analysis.all.RepoFolders) TestcaseClass(de.dagere.peass.analysis.groups.TestcaseClass)

Example 2 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class ReadProperties method detectVersionProperty.

private int detectVersionProperty(final File projectFolder, final File viewFolder, final BufferedWriter csvWriter, final VersionChangeProperties versionProperties, final Entry<String, Changes> versionChanges, final String predecessor, final ExecutionData data) throws IOException, JsonGenerationException, JsonMappingException {
    final File methodFolder = new File(out.getParentFile(), "methods");
    methodFolder.mkdirs();
    final String version = versionChanges.getKey();
    final ChangeProperties changeProperties = new ChangeProperties();
    changeProperties.setCommitText(GitUtils.getCommitText(projectFolder, version));
    changeProperties.setCommitter(GitUtils.getCommitter(projectFolder, version));
    versionProperties.getVersions().put(version, changeProperties);
    int count = 0;
    for (final Entry<String, List<Change>> changes : versionChanges.getValue().getTestcaseChanges().entrySet()) {
        final String testclazz = changes.getKey();
        String module = null;
        for (TestCase test : data.getVersions().get(versionChanges.getKey()).getTests()) {
            if (test.getClazz().equals(testclazz)) {
                module = test.getModule();
            }
        }
        final List<ChangeProperty> properties = new LinkedList<>();
        changeProperties.getProperties().put(testclazz, properties);
        for (final Change testcaseChange : changes.getValue()) {
            ExecutionConfig config = new ExecutionConfig();
            config.setVersion(version);
            config.setVersionOld(predecessor);
            ChangedEntity entity = new ChangedEntity(testclazz, module);
            final PropertyReadHelper reader = new PropertyReadHelper(config, entity, testcaseChange, projectFolder, viewFolder, methodFolder, null);
            final ChangeProperty currentProperty = reader.read();
            // if (currentProperty != null) {
            properties.add(currentProperty);
            Constants.OBJECTMAPPER.writeValue(out, versionProperties);
            writeCSVLine(csvWriter, currentProperty, projectFolder.getName());
            // }
            count++;
        }
    }
    return count;
}
Also used : PropertyReadHelper(de.dagere.peass.analysis.properties.PropertyReadHelper) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) Change(de.dagere.peass.analysis.changes.Change) ExecutionConfig(de.dagere.peass.config.ExecutionConfig) LinkedList(java.util.LinkedList) TestCase(de.dagere.peass.dependency.analysis.data.TestCase) ChangeProperties(de.dagere.peass.analysis.properties.ChangeProperties) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File)

Example 3 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class FindWrong method main.

public static void main(final String[] args) throws JsonParseException, JsonMappingException, IOException {
    final File executeCommands = new File("execute-wrong.sh");
    final PrintStream goal = new PrintStream(new FileOutputStream(executeCommands));
    final File folder = new File("/home/reichelt/daten3/diss/repos/properties/classification");
    int index = 0;
    for (final File project : folder.listFiles()) {
        if (project.getName().endsWith(".json")) {
            final String projectName = project.getName().substring(0, project.getName().indexOf('.'));
            final String url = Constants.defaultUrls.get(projectName);
            RunCommandWriter writer = new RunCommandWriterSlurm(goal, "wrong_rerun", projectName, url);
            if (url != null) {
                final Classification data = Constants.OBJECTMAPPER.readValue(project, Classification.class);
                for (final Map.Entry<String, VersionClass> version : data.getVersions().entrySet()) {
                    for (final Map.Entry<ChangedEntity, TestcaseClass> method : version.getValue().getTestcases().entrySet()) {
                        if (method.getValue().getTypes().contains("WRONG") || method.getValue().getTypes().contains("WRONGTEST")) {
                            // System.out.println(version.getKey() + " " + method.getKey());
                            writer.createSingleMethodCommand(index, version.getKey(), method.getKey().toString());
                            index++;
                        }
                    }
                }
            } else {
                System.err.println("Missing url: " + projectName);
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) VersionClass(de.dagere.peass.analysis.groups.VersionClass) RunCommandWriterSlurm(de.dagere.peass.measurement.utils.RunCommandWriterSlurm) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) FileOutputStream(java.io.FileOutputStream) Classification(de.dagere.peass.analysis.groups.Classification) RunCommandWriter(de.dagere.peass.measurement.utils.RunCommandWriter) File(java.io.File) Map(java.util.Map) TestcaseClass(de.dagere.peass.analysis.groups.TestcaseClass)

Example 4 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class TestShortening method testShorteningJUnit5Parameterized_methodItself.

@Test
public void testShorteningJUnit5Parameterized_methodItself() throws Exception {
    final File test = new File(folder, "src/test/java/de");
    test.mkdirs();
    final File testClazz = new File(test, "ExampleTestJUnit5Parameterized.java");
    try (JUnitTestShortener shortener = new JUnitTestShortener(transformer, folder, new ChangedEntity("de.ExampleTestJUnit5Parameterized", ""), "testMe")) {
        Assert.assertFalse(FileUtils.contentEquals(exampleTestFile5Parameterized, testClazz));
        try (FileInputStream inputStream = new FileInputStream(testClazz)) {
            String fileContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
            System.out.println(fileContent);
            int matches = StringUtils.countMatches(fileContent, "@Test");
            Assert.assertEquals(0, matches);
            int matchesParameterized = StringUtils.countMatches(fileContent, "@ParameterizedTest");
            Assert.assertEquals(1, matchesParameterized);
        }
    }
    Assert.assertTrue(FileUtils.contentEquals(exampleTestFile5Parameterized, testClazz));
}
Also used : ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) FileInputStream(java.io.FileInputStream) JUnitTestShortener(de.dagere.peass.testtransformation.JUnitTestShortener) Test(org.junit.jupiter.api.Test)

Example 5 with ChangedEntity

use of de.dagere.peass.dependency.analysis.data.ChangedEntity in project peass by DaGeRe.

the class TestShortening method testSubclassShortening.

@Test
public void testSubclassShortening() throws Exception {
    final File test = new File(folder, "src/test/java/de");
    test.mkdirs();
    final File testClazz = new File(test, "ExampleTest.java");
    final File subClazz = new File(test, "SubTest.java");
    try (JUnitTestShortener shortener = new JUnitTestShortener(transformer, folder, new ChangedEntity("de.SubTest", ""), "test3")) {
        Assert.assertFalse(FileUtils.contentEquals(exampleTestFile, testClazz));
        Assert.assertFalse(FileUtils.contentEquals(subTestFile, subClazz));
    }
    Assert.assertTrue(FileUtils.contentEquals(exampleTestFile, testClazz));
    Assert.assertTrue(FileUtils.contentEquals(subTestFile, subClazz));
}
Also used : ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) JUnitTestShortener(de.dagere.peass.testtransformation.JUnitTestShortener) Test(org.junit.jupiter.api.Test)

Aggregations

ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)136 Test (org.junit.jupiter.api.Test)58 File (java.io.File)57 ClazzChangeData (de.dagere.peass.dependency.changesreading.ClazzChangeData)41 TestCase (de.dagere.peass.dependency.analysis.data.TestCase)23 TestSet (de.dagere.peass.dependency.analysis.data.TestSet)20 ChangeManager (de.dagere.peass.dependency.ChangeManager)18 Set (java.util.Set)17 HashSet (java.util.HashSet)16 ExecutionConfig (de.dagere.peass.config.ExecutionConfig)14 HashMap (java.util.HashMap)14 Map (java.util.Map)12 DependencyReader (de.dagere.peass.dependency.reader.DependencyReader)11 FakeFileIterator (de.dagere.peass.dependencytests.helper.FakeFileIterator)11 VersionIterator (de.dagere.peass.vcs.VersionIterator)10 TreeMap (java.util.TreeMap)9 VersionStaticSelection (de.dagere.peass.dependency.persistence.VersionStaticSelection)8 EnvironmentVariables (de.dagere.peass.execution.utils.EnvironmentVariables)6 Node (com.github.javaparser.ast.Node)5 Change (de.dagere.peass.analysis.changes.Change)5