Search in sources :

Example 86 with Workspace

use of com.structurizr.Workspace in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_containers_are_added_automatically.

@Test
void assert_that_containers_are_added_automatically() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).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)

Example 87 with Workspace

use of com.structurizr.Workspace in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_relationships_are_added_to_the_c4_model.

@Test
void assert_that_relationships_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().forEach(c4ModelBuilder::artifact);
    application.getRelationships().stream().forEach(c4ModelBuilder::relationship);
    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(1).extracting(Relationship::getDescription, Relationship::getSource, Relationship::getDestination).containsExactly(tuple("references", class1ForBuildingBlockType1, miscArtifact1));
}
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 88 with Workspace

use of com.structurizr.Workspace in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_an_IllegalStateException_is_thrown_if_an_Archifact_is_not_mapped_to_the_expected_type.

@Test
void assert_that_an_IllegalStateException_is_thrown_if_an_Archifact_is_not_mapped_to_the_expected_type() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).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 Artifact miscArtifact1 = application.getArtifacts().stream().filter(artifact -> artifact.getName().equals("MiscArtifact1")).findFirst().get();
    final Artifact class1ForBuildingBlockType1 = application.getArtifacts().stream().filter(artifact -> artifact.getName().equals("Class1ForBuildingBlockType1")).findFirst().get();
    assertThatIllegalStateException().isThrownBy(() -> c4Model.component(miscArtifact1)).withMessage("<MiscArtifact> org.archifacts.integration.c4.model.domain.MiscArtifact1 is not mapped to a C4 model item of type com.structurizr.model.Component");
    assertThatIllegalStateException().isThrownBy(() -> c4Model.relationship(miscArtifact1)).withMessage("<MiscArtifact> org.archifacts.integration.c4.model.domain.MiscArtifact1 is not mapped to a C4 model item of type com.structurizr.model.Relationship");
    assertThatIllegalStateException().isThrownBy(() -> c4Model.container(miscArtifact1)).withMessage("<MiscArtifact> org.archifacts.integration.c4.model.domain.MiscArtifact1 is not mapped to a C4 model item of type com.structurizr.model.Container");
    assertThatNoException().isThrownBy(() -> c4Model.component(class1ForBuildingBlockType1));
    assertThatIllegalStateException().isThrownBy(() -> c4Model.relationship(class1ForBuildingBlockType1)).withMessage("<BuildingBlockType1> org.archifacts.integration.c4.model.domain.Class1ForBuildingBlockType1 is not mapped to a C4 model item of type com.structurizr.model.Relationship");
    assertThatIllegalStateException().isThrownBy(() -> c4Model.container(class1ForBuildingBlockType1)).withMessage("<BuildingBlockType1> org.archifacts.integration.c4.model.domain.Class1ForBuildingBlockType1 is not mapped to a C4 model item of type com.structurizr.model.Container");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Application(org.archifacts.core.model.Application) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 89 with Workspace

use of com.structurizr.Workspace in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_relationships_are_not_added_automatically.

@Test
void assert_that_relationships_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.getArtifacts().stream().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(2).extracting(Component::getName, Component::getTechnology).containsExactlyInAnyOrder(tuple("Class1ForBuildingBlockType1", "BuildingBlockType1"), tuple("MiscArtifact1", "Misc"));
    assertThat(components).flatMap(Component::getRelationships).isEmpty();
}
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 90 with Workspace

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

the class Architecture method describeArchitecture.

/**
 * Creates the workspace object and add in it both the architecture components
 * AND the views used to display it
 *
 * @return
 */
public Workspace describeArchitecture() {
    // tag::structurizr-example-context[]
    String name = "agile-architecture-documentation-system";
    Workspace workspace = new Workspace(name, "This is the model of the agile architecture documentation system.");
    Model model = workspace.getModel();
    Person architect = model.addPerson("Architect", "The architect as team scribe is the writer of this kind of documentation.");
    Person stakeholder = model.addPerson("Stakeholder", "All project stakeholders are readers of this kind of documentation.");
    SoftwareSystem agileArchitecture = model.addSoftwareSystem(AGILE_ARCHITECTURE_DOCUMENTATION, "This software system generates the documentation.");
    agileArchitecture.addProperty(ModelElementKeys.ISSUE_MANAGER, "https://github.com/Riduidel/agile-architecture-documentation-system");
    agileArchitecture.addProperty(ADRExtractor.AGILE_ARCHITECTURE_TICKETS_PROJECT, name);
    agileArchitecture.addProperty(ADRExtractor.AGILE_ARCHITECTURE_TICKETS_ADR_LABEL, "decision");
    architect.uses(agileArchitecture, "Writes");
    stakeholder.uses(agileArchitecture, "Read");
    // end::structurizr-example-context[]
    // ///////////////////////////////////////////////////////////////////////////////////////
    // tag::structurizr-example-containers[]
    Container archetype = agileArchitecture.addContainer(CONTAINERS_ARCHETYPE, "Archetype generating a valid build", "maven archetype");
    archetype.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("archetype/pom.xml"));
    architect.uses(archetype, "Bootstrap a valid project");
    Container maven = agileArchitecture.addContainer(CONTAINERS_MAVEN, "Maven build tool", "Maven build tool");
    architect.uses(maven, "Generates documentation");
    Container base = agileArchitecture.addContainer(CONTAINERS_BASE, "Architecture base", "Java executable");
    base.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("base/pom.xml"));
    base.addProperty(ModelElementKeys.SCM_PATH, base.getName());
    // end::structurizr-example-containers[]
    // tag::structurizr-example-components[]
    ComponentFinder componentFinder = new ComponentFinder(base, // new SourceCodeComponentFinderStrategy(new File("../base/src/main/java")),
    ArchitectureModelProvider.class.getPackageName(), new StructurizrAnnotationsComponentFinderStrategy());
    // end::structurizr-example-components[]
    if (getClass().getClassLoader() instanceof URLClassLoader) {
        componentFinder.setUrlClassLoader((URLClassLoader) getClass().getClassLoader());
    }
    try {
        componentFinder.findComponents();
    } catch (Exception e) {
        throw new RuntimeException("Unable to locate components in ", e);
    }
    // model.addImplicitRelationships();
    // Damn, structurizr-annotations doesn't understand CDI. Let's supplement it!
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("DocumentsCollector"), "Collects documents in source folder");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("SCMLinkGenerator"), "Generates links to SCM sources");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("SCMReadmeReader"), "Includes elements readme when they exist");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("ImplicitIncludeManager"), "Generates includes for all enhancers");
    base.getComponentWithName("ArchitectureEnhancer").uses(base.getComponentWithName("GraphEmitter"), "Generates diagrams in PlantUML format");
    maven.uses(base.getComponentWithName("ArchitectureDocumentationBuilder"), "Invokes that Java executable during maven build");
    Component gitHub = base.addComponent("github-scm-handler", "GitHub SCM Handler", "java");
    gitHub.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("github-scm-handler/pom.xml"));
    gitHub.addProperty(ModelElementKeys.SCM_PATH, gitHub.getName());
    base.getComponentWithName("SCMLinkGenerator").uses(gitHub, "Get project source link");
    base.getComponentWithName("SCMReadmeReader").uses(gitHub, "Get project readme");
    Component gitLab = base.addComponent("gitlab-scm-handler", "GitLab SCM Handler", "java");
    gitLab.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("gitlab-scm-handler/pom.xml"));
    gitLab.addProperty(ModelElementKeys.SCM_PATH, gitLab.getName());
    base.getComponentWithName("SCMLinkGenerator").uses(gitLab, "Get project source link");
    base.getComponentWithName("SCMReadmeReader").uses(gitLab, "Get project readme");
    Component adrTicketsExtractor = base.addComponent("adr-tickets-extractor", "enhanced by maven");
    adrTicketsExtractor.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("adr-tickets-extractor/pom.xml"));
    adrTicketsExtractor.addProperty(ModelElementKeys.SCM_PATH, adrTicketsExtractor.getName());
    adrTicketsExtractor.uses(gitLab, "Read tickets from Gitlab if configured so");
    adrTicketsExtractor.uses(gitHub, "Read tickets from GitHub if configured so");
    base.getComponentWithName("ArchitectureEnhancer").uses(adrTicketsExtractor, "Produces ADR reporting");
    Component cdiConfigExtension = base.addComponent("cdi-config-extension", "CDI Config extensions", "java");
    cdiConfigExtension.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("cdi-config-extension/pom.xml"));
    cdiConfigExtension.addProperty(ModelElementKeys.SCM_PATH, cdiConfigExtension.getName());
    base.getComponentWithName("ArchitectureDocumentationBuilder").uses(cdiConfigExtension, "Eases out some CDI code");
    Component mavenEnhancer = base.addComponent("maven-metadata-inferer", "Enhanced by Maven");
    cdiConfigExtension.addProperty(MavenEnhancer.AGILE_ARCHITECTURE_MAVEN_POM, locate("maven-metadata-inferer/pom.xml"));
    cdiConfigExtension.addProperty(ModelElementKeys.SCM_PATH, mavenEnhancer.getName());
    base.getComponentWithName("ArchitectureDocumentationBuilder").uses(mavenEnhancer, "Infer most of element details from Maven infos");
    Container asciidoc = agileArchitecture.addContainer("asciidoc", "Asciidoc tooling", "Maven plugin");
    maven.uses(base, "Generates diagrams and asciidoc includes");
    maven.uses(asciidoc, "Generates documentation as usable text in HTML/PDF/...");
    // ///////////////////////////////////////////////////////////////////////////////////////
    // tag::structurizr-example-views[]
    ViewSet views = workspace.getViews();
    SystemContextView contextView = views.createSystemContextView(agileArchitecture, "SystemContext", "Illustration of agile-architecture-documentation usage");
    contextView.addAllSoftwareSystems();
    contextView.addAllPeople();
    ContainerView agileArchitectureContainers = views.createContainerView(agileArchitecture, "agile.architecture.containers", "Agile architecture containers");
    agileArchitectureContainers.addAllContainersAndInfluencers();
    ComponentView agileArchitectureBaseComponents = views.createComponentView(base, "agile.architecture.base.components", "Agile architecture base components view");
    agileArchitectureBaseComponents.addAllComponents();
    // styles.addElementStyle(Tags.PERSON).background("#08427b").color("#ffffff").shape(Shape.Person);
    return workspace;
}
Also used : ArchitectureModelProvider(org.ndx.agile.architecture.base.ArchitectureModelProvider) ComponentFinder(com.structurizr.analysis.ComponentFinder) StructurizrAnnotationsComponentFinderStrategy(com.structurizr.analysis.StructurizrAnnotationsComponentFinderStrategy) Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) ViewSet(com.structurizr.view.ViewSet) SystemContextView(com.structurizr.view.SystemContextView) URLClassLoader(java.net.URLClassLoader) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) ContainerView(com.structurizr.view.ContainerView) Component(com.structurizr.model.Component) Person(com.structurizr.model.Person) Workspace(com.structurizr.Workspace)

Aggregations

Workspace (com.structurizr.Workspace)155 Test (org.junit.Test)98 Test (org.junit.jupiter.api.Test)36 File (java.io.File)23 Container (com.structurizr.model.Container)22 SoftwareSystem (com.structurizr.model.SoftwareSystem)22 Component (com.structurizr.model.Component)12 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)12 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)12 Application (org.archifacts.core.model.Application)12 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 ArrayList (java.util.ArrayList)6 EncryptedWorkspace (com.structurizr.encryption.EncryptedWorkspace)5 Element (com.structurizr.model.Element)5 Model (com.structurizr.model.Model)5 Artifact (org.archifacts.core.model.Artifact)5 MiscArtifact (org.archifacts.core.model.MiscArtifact)5 Person (com.structurizr.model.Person)4 Relationship (com.structurizr.model.Relationship)4 SystemContextView (com.structurizr.view.SystemContextView)4