Search in sources :

Example 81 with Workspace

use of com.structurizr.Workspace in project tutorials by eugenp.

the class StructurizrSimple method getSoftwareSystem.

private static Workspace getSoftwareSystem() {
    Workspace workspace = new Workspace("Payment Gateway", "Payment Gateway");
    Model model = workspace.getModel();
    Person user = model.addPerson("Merchant", "Merchant");
    SoftwareSystem paymentTerminal = model.addSoftwareSystem(PAYMENT_TERMINAL, "Payment Terminal");
    user.uses(paymentTerminal, "Makes payment");
    SoftwareSystem fraudDetector = model.addSoftwareSystem(FRAUD_DETECTOR, "Fraud Detector");
    paymentTerminal.uses(fraudDetector, "Obtains fraud score");
    ViewSet viewSet = workspace.getViews();
    SystemContextView contextView = viewSet.createSystemContextView(workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL), SOFTWARE_SYSTEM_VIEW, "Payment Gateway Diagram");
    contextView.addAllElements();
    return workspace;
}
Also used : ViewSet(com.structurizr.view.ViewSet) SystemContextView(com.structurizr.view.SystemContextView) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) Person(com.structurizr.model.Person) Workspace(com.structurizr.Workspace)

Example 82 with Workspace

use of com.structurizr.Workspace in project cia by Hack23.

the class AwsPublicSystemDocumentation method main.

/**
 * The main method.
 *
 * @param args
 *            the arguments
 * @throws Exception
 *             the exception
 */
public static void main(final String[] args) throws Exception {
    final Workspace workspace = new Workspace("Citizen Intelligence Agency", "Public Aws System Documentation");
    final Model model = workspace.getModel();
    final ViewSet viewSet = workspace.getViews();
    final SoftwareSystem ciaSystem = model.addSoftwareSystem("Citizen Intelligence Agency", "Tracking politicians like bugs!");
    final DeploymentNode masterAccountNode = model.addDeploymentNode("Master Account", "AWS", "Aws Account");
    final Container awsAccountContainer = ciaSystem.addContainer("Master Account", "AWS", "Aws Account");
    final DeploymentNode iamAccountNode = model.addDeploymentNode("IAM Account", "AWS", "Aws Account");
    final Container iamAccountContainer = ciaSystem.addContainer("IAM Account", "AWS", "Aws Account");
    final DeploymentNode devAccountNode = model.addDeploymentNode("Development Account", "AWS", "Aws Account");
    final Container devAccountContainer = ciaSystem.addContainer("Development Account", "AWS", "Aws Account");
    final DeploymentNode opCenterAccountNode = model.addDeploymentNode("Operation Center Account", "AWS", "Aws Account");
    final Container opCenterAccountContainer = ciaSystem.addContainer("Operation Center Account", "AWS", "Aws Account");
    final DeploymentNode auditAccountNode = model.addDeploymentNode("Audit Account", "AWS", "Aws Account");
    final Container auditAccountContainer = ciaSystem.addContainer("Audit Account", "AWS", "Aws Account");
    final DeploymentNode appAccountNode = model.addDeploymentNode("Application Account", "AWS", "Aws Account");
    final Container appAccountContainer = ciaSystem.addContainer("Application Account", "AWS", "Aws Account");
    awsAccountContainer.uses(iamAccountContainer, "create/restrict");
    awsAccountContainer.uses(devAccountContainer, "create/restrict");
    awsAccountContainer.uses(opCenterAccountContainer, "create/restrict");
    awsAccountContainer.uses(auditAccountContainer, "create/restrict");
    awsAccountContainer.uses(appAccountContainer, "create/restrict");
    awsAccountContainer.uses(auditAccountContainer, "publish event/audit");
    iamAccountContainer.uses(auditAccountContainer, "publish event/audit");
    devAccountContainer.uses(auditAccountContainer, "publish event/audit");
    opCenterAccountContainer.uses(auditAccountContainer, "publish event/audit");
    appAccountContainer.uses(auditAccountContainer, "publish event/audit");
    opCenterAccountContainer.uses(auditAccountContainer, "Monitor event/audit");
    iamAccountContainer.uses(devAccountContainer, "manage access");
    iamAccountContainer.uses(appAccountContainer, "manage access");
    iamAccountContainer.uses(opCenterAccountContainer, "manage access");
    opCenterAccountNode.add(opCenterAccountContainer);
    devAccountNode.add(devAccountContainer);
    auditAccountNode.add(auditAccountContainer);
    appAccountNode.add(appAccountContainer);
    iamAccountNode.add(iamAccountContainer);
    masterAccountNode.add(awsAccountContainer);
    final DeploymentView developmentDeploymentView = viewSet.createDeploymentView(ciaSystem, "\"Production Aws Account structure\"", "\"Production Aws Account structure\"");
    developmentDeploymentView.add(masterAccountNode);
    developmentDeploymentView.add(iamAccountNode);
    developmentDeploymentView.add(devAccountNode);
    developmentDeploymentView.add(opCenterAccountNode);
    developmentDeploymentView.add(auditAccountNode);
    developmentDeploymentView.add(appAccountNode);
    final Styles styles = viewSet.getConfiguration().getStyles();
    styles.addElementStyle(Tags.COMPONENT).background("#1168bd").color("#ffffff");
    styles.addElementStyle(Tags.CONTAINER).background("#1168bd").color("#ffffff");
    styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#1168bd").color("#ffffff");
    styles.addElementStyle(Tags.PERSON).background("#519823").color("#ffffff").shape(Shape.Person);
    styles.addElementStyle("Database").shape(Shape.Cylinder);
    printPlantUml(workspace);
    System.setProperty("PLANTUML_LIMIT_SIZE", "8192");
    Run.main(new String[] { Paths.get(".").toAbsolutePath().normalize().toString() + File.separator + "target" + File.separator + "site" + File.separator + "architecture" + File.separator });
}
Also used : Container(com.structurizr.model.Container) ViewSet(com.structurizr.view.ViewSet) DeploymentNode(com.structurizr.model.DeploymentNode) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) DeploymentView(com.structurizr.view.DeploymentView) Styles(com.structurizr.view.Styles)

Example 83 with Workspace

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

the class C4ModelBuilderTest method assert_that_relationship_source_and_target_is_automatically_added_to_the_c4_model.

@Test
void assert_that_relationship_source_and_target_is_automatically_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.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 84 with Workspace

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

the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_container.

@Test
void assert_that_computation_rule_is_applied_to_container() {
    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);
    application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
    c4ModelBuilder.containerRule().predicate(a -> true).computation((container, lookup) -> Set.of(lookup.softwareSystem().addContainer("CustomName1", null, "CustomTechnology1"), lookup.softwareSystem().addContainer("CustomName2", null, "CustomTechnology2")));
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(2).extracting(Container::getName, Container::getTechnology).containsExactlyInAnyOrder(tuple("CustomName1", "CustomTechnology1"), tuple("CustomName2", "CustomTechnology2"));
}
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) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Optional(java.util.Optional) 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 85 with Workspace

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

the class C4ModelBuilderTest method assert_that_an_IllegalStateException_is_thrown_if_a_building_block_does_not_have_a_container.

@Test
void assert_that_an_IllegalStateException_is_thrown_if_a_building_block_does_not_have_a_container() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
    assertThatIllegalStateException().isThrownBy(() -> c4ModelBuilder.build()).withMessage("No container present for <BuildingBlockType1> org.archifacts.integration.c4.model.domain.Class1ForBuildingBlockType1");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Application(org.archifacts.core.model.Application) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

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