Commit 35550092 authored by Johannes Salentin's avatar Johannes Salentin
Browse files

first test

added testing structure
parent a5ac6d77
Pipeline #158090 failed with stages
in 56 seconds
......@@ -20,8 +20,12 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.4.2" level="project" />
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.0" level="project" />
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-core:2.3.0" level="project" />
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.3.0" level="project" />
......
......@@ -67,14 +67,25 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
......
......@@ -14,7 +14,7 @@ public class ModelAdapter {
private static ModelType model;
ModelAdapter(String xmlFile, String xsdSchema) {
public ModelAdapter(String xmlFile, String xsdSchema) {
try {
model = JAXBMarshalUnmarshal.unmarshal(xmlFile, ModelType.class, xsdSchema);
System.out.println("Successfully loaded " + xmlFile);
......@@ -65,25 +65,33 @@ public class ModelAdapter {
return res;
}
public List<ElementType> getReferencedElementsOf(ElementType source, String type) {
public List<ElementType> getReferencedElementsOf(ElementType source, String[] types) {
List<ElementType> res = new ArrayList<>();
for (RelationshipType rel : getRelationships()) {
ElementType sour = (ElementType) rel.getSource();
if (sour.equals(source) && rel.getClass().getName().equals("de.example.model." + type)) {
ElementType tar = (ElementType) rel.getTarget();
res.add(tar);
if (sour.equals(source)) {
for (String type : types) {
if (rel.getClass().getName().equals("de.example.model." + type)) {
ElementType tar = (ElementType) rel.getTarget();
res.add(tar);
}
}
}
}
return res;
}
public List<ElementType> getElementsWithReferenceTo(ElementType target, String type) {
public List<ElementType> getElementsWithReferenceTo(ElementType target, String[] types) {
List<ElementType> res = new ArrayList<>();
for (RelationshipType rel : getRelationships()) {
ElementType tar = (ElementType) rel.getTarget();
if (tar.equals(target) && rel.getClass().getName().equals("de.example.model." + type)) {
ElementType sour = (ElementType) rel.getSource();
res.add(sour);
if (tar.equals(target)) {
for (String type : types) {
if (rel.getClass().getName().equals("de.example.model." + type)) {
ElementType sour = (ElementType) rel.getSource();
res.add(sour);
}
}
}
}
return res;
......@@ -133,12 +141,10 @@ public class ModelAdapter {
return res.toString();
}
public List<ElementType> getIdentifiersInLayer(String layer) {
public List<ElementType> getElementsInLayer(String layer) {
List<OrganizationType> l = model.getOrganizations().get(0).getItem().stream().filter(e -> e.getLabelGroup().get(0).getValue().toLowerCase().contains(layer.toLowerCase())).collect(Collectors.toList());
if (l.isEmpty()) {
return new ArrayList<>();
} else if (l.get(0).getItem().isEmpty()) {
return new ArrayList<>();
} else {
l = l.get(0).getItem();
List<ElementType> res = new ArrayList<>();
......
......@@ -14,8 +14,9 @@ public class SharedPersistency extends Detector {
public List<EASmell> detect() {
List<ElementType> databaseElements = model.getElements().stream().filter(e -> e.getClass().getSimpleName().equals("SystemSoftware") && (e.getNameGroup().get(0).getValue().contains("database") || e.getNameGroup().get(0).getValue().contains("DBMS"))).collect(Collectors.toList());
for (ElementType databaseElement : databaseElements) {
List<ElementType> referencedElements = model.getReferencedElementsOf(databaseElement, "Association");
referencedElements.addAll(model.getElementsWithReferenceTo(databaseElement, "Association"));
String[] types = {"Association"};
List<ElementType> referencedElements = model.getReferencedElementsOf(databaseElement, types);
referencedElements.addAll(model.getElementsWithReferenceTo(databaseElement, types));
if (referencedElements.size() > 1) {
addToSmells(new EASmell(getSmellName(), databaseElement));
}
......
......@@ -13,8 +13,8 @@ public class StrictLayersViolation extends Detector {
public List<EASmell> detect() {
List<RelationshipType> relationships = model.getRelationships();
List<ElementType> businessElements = model.getIdentifiersInLayer("Business");
List<ElementType> technologyElements = model.getIdentifiersInLayer("Technology");
List<ElementType> businessElements = model.getElementsInLayer("Business");
List<ElementType> technologyElements = model.getElementsInLayer("Technology");
if (!businessElements.isEmpty() && !technologyElements.isEmpty()) {
for (RelationshipType relationship : relationships) {
ElementType source = (ElementType) relationship.getSource();
......
......@@ -17,8 +17,12 @@ public class WeakenedModularity extends Detector {
for (ElementType element : elements) {
//String type = element.getClass().getSimpleName();
//if (!(type.contains("Process") || type.contains("Event") || type.contains("Function"))) {
int internal = model.getReferencedElementsOf(element, "Composition").size() + model.getReferencedElementsOf(element, "Aggregation").size() + model.getElementsWithReferenceTo(element, "Aggregation").size();
int external = model.getElementsWithReferenceTo(element, "Composition").size() + model.getElementsWithReferenceTo(element, "Triggering").size() + model.getReferencedElementsOf(element, "Triggering").size();
String[] internalReferencedElements = {"Composition", "Aggregation"};
String[] internalElementsWithReference = {"Aggregation"};
int internal = model.getReferencedElementsOf(element, internalReferencedElements).size() + model.getElementsWithReferenceTo(element, internalElementsWithReference).size();
String[] externalReferencedElements = {"Triggering"};
String[] externalElementsWithReference = {"Composition", "Triggering"};
int external = model.getElementsWithReferenceTo(element, externalElementsWithReference).size() + model.getReferencedElementsOf(element, externalReferencedElements).size();
double mr = (double) internal / (double) external;
if (mr < MODULARITY_RATIO && mr > 0) {
addToSmells(new EASmell("Weakened Modularity", element, " with a modularity ratio of " + mr));
......
package de.example.smells;
import de.example.main.ModelAdapter;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class TestCyclicDependency {
private ModelAdapter model = new ModelAdapter("Test.xml", null);
private CyclicDependency detector = new CyclicDependency();
@Test
void test() {
Detector.setModel(model);
assertEquals(detector.detect().size(), 3);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment