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

Features/301 allow visitors tests #302

Merged
merged 3 commits into from
Dec 14, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void main(String[] args) throws Throwable {
@Inject @UsesComponent(description = "Adds information to initial architecture description") ArchitectureEnhancer enhancer;
@Inject @UsesComponent(description = "Generates initial architecture description") @Any Instance<ArchitectureModelProvider> availableProviders;
@Inject @UsesComponent(description = "Read architecture description from workspace.dsl file") FromDsl fromDsl;
@Inject @UsesComponent(description="Uses all enhancers") Instance<Enhancer> enhancers;

/**
* Run method that will allow the description to be invoked and augmentations to be performed
Expand All @@ -54,7 +55,7 @@ public static void main(String[] args) throws Throwable {
public void run() throws IOException {
Workspace workspace = getArchitecture();
logger.info("Architecture has been described. Now enhancing it (including writing the diagrams)!");
enhancer.enhance(workspace);
enhancer.enhance(workspace, enhancers);
}

private Workspace getArchitecture() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;

import org.apache.commons.lang3.stream.Streams;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.deltaspike.core.api.config.ConfigProperty;
import org.ndx.aadarchi.base.enhancers.ModelElementKeys.ConfigProperties.DisabledEnhancers;
Expand All @@ -38,7 +40,6 @@
@com.structurizr.annotation.Component(technology = "Java, CDI")
@ApplicationScoped
public class ArchitectureEnhancer {
@Inject @UsesComponent(description="Uses all enhancers") Instance<Enhancer> enhancers;
@Inject Logger logger;
@Inject @ConfigProperty(name=EnhancementsDir.NAME, defaultValue = EnhancementsDir.VALUE) File enhancementsBase;
private Set<String> disabledEnhancers = Set.of();
Expand All @@ -49,8 +50,8 @@ public void loadDisabledEnhancers(@ConfigProperty(name=DisabledEnhancers.NAME) S
}
}

public Stream<Enhancer> getEnhancers() {
return enhancers.stream()
public Stream<Enhancer> getEnhancers(Iterable<Enhancer> enhancers) {
return StreamSupport.stream(enhancers.spliterator(), false)
.sorted(Comparator.comparingInt(e -> e.priority()))
.filter(this::filterEnhancer);
}
Expand Down Expand Up @@ -93,14 +94,14 @@ private boolean filterEnhancer(Enhancer enhancer) {
}
}

public void enhance(Workspace workspace) {
public void enhance(Workspace workspace, Iterable<Enhancer> enhancers) {
classloader = Thread.currentThread().getContextClassLoader();
logger.info(() -> String.format("Enhancers applied to this architecture are\n%s",
getEnhancers()
getEnhancers(enhancers)
.map(e -> String.format("%s => %d", e.getClass().getName(), e.priority()))
.collect(Collectors.joining("\n"))));
withStopWatch("Running all enhancements took %s",
() -> getEnhancers()
() -> getEnhancers(enhancers)
.forEach(enhancer -> enhancerVisitWorkspace(enhancer, workspace)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package org.ndx.aadarchi.inferer.maven;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import javax.inject.Inject;

import org.apache.maven.project.MavenProject;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.InstanceOfAssertFactory;
import org.jboss.weld.junit5.EnableWeld;
import org.jboss.weld.junit5.WeldInitiator;
import org.jboss.weld.junit5.WeldSetup;
import org.junit.jupiter.api.Test;
import org.ndx.aadarchi.base.ArchitectureEnhancer;
import org.ndx.aadarchi.base.OutputBuilder;
import org.ndx.aadarchi.base.enhancers.ModelElementKeys;

import com.structurizr.Workspace;
import com.structurizr.annotation.UsesComponent;
import com.structurizr.model.SoftwareSystem;

@EnableWeld
Expand All @@ -22,27 +28,59 @@ public class MavenDetailsInfererEnhancerTest {
public WeldInitiator weld = WeldInitiator.performDefaultDiscovery();

@Inject MavenDetailsInfererEnhancer tested;
@Inject ArchitectureEnhancer enhancer;

@Test public void can_visit_a_software_system_having_an_associated_pom() {
// Given
var w = new Workspace(getClass().getName(), "a test workspace");
SoftwareSystem system = w.getModel().addSoftwareSystem("The system to decorate with maven informations");
system.addProperty(ModelElementKeys.ConfigProperties.BasePath.NAME, new File(".").getAbsolutePath());
system.addProperty(ModelElementKeys.ConfigProperties.BasePath.NAME, getAadarchiRootPath());
// When
// We emulate in-depth visit (but do not really perform it)
tested.startVisit(w, null);
tested.startVisit(system);
tested.endVisit(system, null);
tested.endVisit(w, null);
enhancer.enhance(w, Arrays.asList(tested));
// Then
Assertions.assertThat(system.getProperties())
.containsOnlyKeys(
ModelElementKeys.ConfigProperties.BasePath.NAME,
MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_COORDINATES,
ModelElementKeys.Scm.PROJECT,
ModelElementKeys.ISSUE_MANAGER
);
// There are containers in system
Assertions.assertThat(system.getContainers()).isNotEmpty();
// There is even a contain
Assertions.assertThat(system.getContainerWithName("maven-metadata-inferer"))
.isNotNull()
.extracting(container -> container.getProperties())
.asInstanceOf(InstanceOfAssertFactories.MAP)
.containsOnlyKeys(
MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM,
ModelElementKeys.Scm.PATH,
MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_COORDINATES,
ModelElementKeys.Scm.PROJECT,
ModelElementKeys.JAVA_SOURCES,
ModelElementKeys.JAVA_PACKAGES,
ModelElementKeys.ISSUE_MANAGER
);

}

/**
* Obtain the aadarchi root path
* In fact, this method simply checks if the given path is the maven-metadata-inferer one.
* If so, it returns the parent, otherwise, it returns itself
* (this allows us to run the test both from JUnit and in Reactor build)
*/
public static String getAadarchiRootPath() {
File current = new File(".");
try {
current = current.getCanonicalFile();
if(current.getName().equals("maven-metadata-inferer"))
return current.getParent();
else
return current.getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("We should be able to get this folder path, no?", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class MavenPomReaderTest {
// Given
var w = new Workspace(getClass().getName(), "a test workspace");
var system = w.getModel().addSoftwareSystem("The system to decorate with maven informations");
system.addProperty(ModelElementKeys.ConfigProperties.BasePath.NAME, new File(".").getAbsolutePath());
system.addProperty(ModelElementKeys.ConfigProperties.BasePath.NAME, MavenDetailsInfererEnhancerTest.getAadarchiRootPath());
// When
var project = mavenPomReader.processModelElement(system);
// Then
Assertions.assertThat(project)
.get()
.extracting(mavenProject -> mavenProject.getArtifactId()).isEqualTo("maven-metadata-inferer")
.extracting(mavenProject -> mavenProject.getArtifactId()).isEqualTo("system")
;
}

Expand Down