Search in sources :

Example 21 with Container

use of com.structurizr.model.Container in project agile-architecture-documentation-system by Riduidel.

the class SequenceDiagramVisitorTest method can_read_a_model.

@Test
@Disabled
void can_read_a_model() {
    // Given all those elements
    Workspace workspace = new Workspace("test workspace", "test workspace");
    Model model = workspace.getModel();
    SoftwareSystem system = model.addSoftwareSystem("agile-architecture-documentation-system");
    Container sequenceGenerator = system.addContainer("sequence-generator", "generator", "Java/Maven");
    sequenceGenerator.addProperty(SequenceGenerator.GENERATES_WITH, StructurizrUtils.getCanonicalPath(sequenceGenerator));
    sequenceGenerator.addProperty(ModelElementKeys.JAVA_SOURCES, new File("src/main/java").toURI().toString());
    Component visitor = sequenceGenerator.addComponent(SequenceDiagramVisitor.class.getSimpleName(), "visitor building the sequence");
    visitor.addSupportingType(SequenceDiagramVisitor.class.getName());
    Component callGraphModel = sequenceGenerator.addComponent(CallGraphModel.class.getSimpleName(), "navigator accumulating data");
    callGraphModel.addSupportingType(CallGraphModel.class.getName());
    Component generator = sequenceGenerator.addComponent(SequenceDiagramGenerator.class.getSimpleName(), "Component producing the sequence diagram");
    generator.addSupportingType(SequenceDiagramGenerator.class.getName());
    // Let's build a sequence diagram visitor
    SequenceDiagramVisitor tested = new SequenceDiagramVisitor();
    tested.logger = Logger.getLogger(getClass().getName());
    tested.destination = new File("target/tests/" + getClass().getSimpleName());
    // Emulate the standard visit
    tested.startVisit(model);
    tested.startVisit(system);
    assertThat(tested.allContainers).hasSize(1);
    assertThat(tested.codeToComponents).hasSize(3);
    assertThat(tested.callGraphModel).isNull();
    // And finally, visit the container and parse source code
    tested.startVisit(sequenceGenerator);
    assertThat(tested.callGraphModel).isNotNull();
    // And visit components to see what happens
    assertThat(tested.startVisit(visitor)).isTrue();
    // And that something is generated
    tested.endVisit(visitor, new SimpleOutputBuilder(tested.destination));
    assertThat(tested.destination).isDirectoryContaining(file -> file.getName().equals(system.getName()));
}
Also used : Container(com.structurizr.model.Container) CallGraphModel(org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel) SequenceDiagramGenerator(org.ndx.agile.architecture.sequence.generator.javaparser.generator.SequenceDiagramGenerator) CallGraphModel(org.ndx.agile.architecture.sequence.generator.javaparser.adapter.CallGraphModel) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) Component(com.structurizr.model.Component) File(java.io.File) Workspace(com.structurizr.Workspace) SimpleOutputBuilder(org.ndx.agile.architecture.base.utils.SimpleOutputBuilder) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 22 with Container

use of com.structurizr.model.Container in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_containers_are_added_to_the_c4_model.

@Test
void assert_that_containers_are_added_to_the_c4_model() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(defaultContainerDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().map(Artifact::getContainer).filter(Optional::isPresent).map(Optional::get).distinct().forEach(c4ModelBuilder::container);
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Set<Component> components = containers.iterator().next().getComponents();
    assertThat(components).isEmpty();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Optional(java.util.Optional) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 23 with Container

use of com.structurizr.model.Container in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_misc_artifacts_are_added_to_the_c4_model.

@Test
void assert_that_misc_artifacts_are_added_to_the_c4_model() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).descriptor(referenceDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().filter(MiscArtifact.class::isInstance).forEach(c4ModelBuilder::artifact);
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Set<Component> components = containers.iterator().next().getComponents();
    assertThat(components).hasSize(1).extracting(Component::getName, Component::getTechnology).containsExactly(tuple("MiscArtifact1", "Misc"));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 24 with Container

use of com.structurizr.model.Container in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_relationship.

@Test
void assert_that_computation_rule_is_applied_to_relationship() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).descriptor(referenceDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().forEach(c4ModelBuilder::artifact);
    application.getRelationships().stream().forEach(c4ModelBuilder::relationship);
    final BuildingBlock source = application.getBuildingBlocksOfType(buildingBlockType1).iterator().next();
    final Artifact target = application.getArtifacts().stream().filter(MiscArtifact.class::isInstance).findFirst().get();
    c4ModelBuilder.relartionshipRule().predicate(a -> true).computation((relationship, lookup) -> Set.of(lookup.component(source).uses(lookup.component(target), "uses"), lookup.component(target).uses(lookup.component(source), "is used by")));
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Container container = containers.iterator().next();
    final Component class1ForBuildingBlockType1 = container.getComponentWithName("Class1ForBuildingBlockType1");
    assertThat(class1ForBuildingBlockType1).isNotNull();
    final Component miscArtifact1 = container.getComponentWithName("MiscArtifact1");
    assertThat(miscArtifact1).isNotNull();
    assertThat(container.getComponents()).flatMap(Component::getRelationships).hasSize(2).extracting(Relationship::getDescription, Relationship::getSource, Relationship::getDestination).containsExactlyInAnyOrder(tuple("uses", class1ForBuildingBlockType1, miscArtifact1), tuple("is used by", miscArtifact1, class1ForBuildingBlockType1));
}
Also used : ArtifactContainer(org.archifacts.core.model.ArtifactContainer) ArtifactContainerType(org.archifacts.core.model.ArtifactContainerType) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArtifactContainerDescriptor(org.archifacts.core.descriptor.ArtifactContainerDescriptor) Component(com.structurizr.model.Component) JavaField(com.tngtech.archunit.core.domain.JavaField) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Artifact(org.archifacts.core.model.Artifact) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) SourceBasedArtifactRelationshipDescriptor(org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Assertions.tuple(org.assertj.core.api.Assertions.tuple) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test) Application(org.archifacts.core.model.Application) Stream(java.util.stream.Stream) ArtifactRelationshipRole(org.archifacts.core.model.ArtifactRelationshipRole) Relationship(com.structurizr.model.Relationship) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) BuildingBlock(org.archifacts.core.model.BuildingBlock) Optional(java.util.Optional) BuildingBlockType(org.archifacts.core.model.BuildingBlockType) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) BuildingBlock(org.archifacts.core.model.BuildingBlock) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 25 with Container

use of com.structurizr.model.Container in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_referenced_artifacts_are_not_added_automatically.

@Test
void assert_that_referenced_artifacts_are_not_added_automatically() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).descriptor(referenceDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Set<Component> components = containers.iterator().next().getComponents();
    assertThat(components).hasSize(1).extracting(Component::getName, Component::getTechnology).containsExactly(tuple("Class1ForBuildingBlockType1", "BuildingBlockType1"));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Aggregations

Container (com.structurizr.model.Container)44 Test (org.junit.jupiter.api.Test)25 SoftwareSystem (com.structurizr.model.SoftwareSystem)23 Workspace (com.structurizr.Workspace)22 Component (com.structurizr.model.Component)21 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)10 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)10 Application (org.archifacts.core.model.Application)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 Model (com.structurizr.model.Model)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 Stream (java.util.stream.Stream)5 DynamicView (com.structurizr.view.DynamicView)4 Relationship (com.structurizr.model.Relationship)3 ComponentView (com.structurizr.view.ComponentView)3 JavaClass (com.tngtech.archunit.core.domain.JavaClass)3 JavaField (com.tngtech.archunit.core.domain.JavaField)3 File (java.io.File)3