Skip to content

Commit

Permalink
Create integration test for: extracting column info FrontEndART#6
Browse files Browse the repository at this point in the history
  • Loading branch information
fea-devteam committed May 28, 2022
1 parent 09d75fe commit f9672a8
Show file tree
Hide file tree
Showing 7 changed files with 9,688 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
<artifactId>eclipse-astparser</artifactId>
<version>8.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import lombok.Data;

import java.io.Serializable;

@Data
public class VulnerabilityEntry {
public class VulnerabilityEntry implements Serializable {

/**
* Normal vulnerability name that is mapped with the magic name
Expand Down
71 changes: 71 additions & 0 deletions src/test/java/eu/assuremoss/utils/ColumnInfoParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package eu.assuremoss.utils;

import eu.assuremoss.framework.api.VulnerabilityDetector;
import eu.assuremoss.framework.model.CodeModel;
import eu.assuremoss.framework.model.VulnerabilityEntry;
import eu.assuremoss.utils.factories.ToolFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

class ColumnInfoParserTest {
private static VulnerabilityDetector vulnDetector;
private static final String mockedResultsPath = String.valueOf(Paths.get("src","test", "resources", "mocked-results"));

@BeforeAll
static void beforeAll() throws IOException {
Configuration config = new Configuration("config.properties");
vulnDetector = ToolFactory.createOsa(config.properties);
}

private static List<CodeModel> mockedCodeModels() {
List<CodeModel> resList = new ArrayList<>();

String asg = String.valueOf(Paths.get(mockedResultsPath, "asg.jfif"));
String graphXML = String.valueOf(Paths.get(mockedResultsPath, "graph.xml"));
String findBugsXML = String.valueOf(Paths.get(mockedResultsPath, "FindBugs.xml"));

resList.add(new CodeModel(CodeModel.MODEL_TYPES.ASG, new File(asg)));
resList.add(new CodeModel(CodeModel.MODEL_TYPES.OSA_GRAPH_XML, new File(graphXML)));
resList.add(new CodeModel(CodeModel.MODEL_TYPES.FINDBUGS_XML, new File(findBugsXML)));

return resList;
}

@Test
void Should_Attach_Column_Info_For_Vulnerability_Entries() {
var expectedEntries = getExpectedEntries();
var result = vulnDetector.getVulnerabilityLocations(new File(""), mockedCodeModels());

Assertions.assertEquals(expectedEntries, result);
}

private List<VulnerabilityEntry> getExpectedEntries() {
var result = new ArrayList<VulnerabilityEntry>();

String vulnEntriesPath = String.valueOf(Paths.get(mockedResultsPath, "vulnEntries.ser").toAbsolutePath());

try {
FileInputStream fileIn = new FileInputStream(vulnEntriesPath);
ObjectInputStream in = new ObjectInputStream(fileIn);
result = (ArrayList<VulnerabilityEntry>) in.readObject();
in.close();
fileIn.close();
} catch (IOException i) {
i.printStackTrace();
} catch (ClassNotFoundException c) {
System.out.println("VulnerabilityEntry class not found");
c.printStackTrace();
}

return result;
}
}
489 changes: 489 additions & 0 deletions src/test/resources/mocked-results/FindBugs.xml

Large diffs are not rendered by default.

Binary file added src/test/resources/mocked-results/asg.ljsi
Binary file not shown.
Loading

0 comments on commit f9672a8

Please sign in to comment.