Search in sources :

Example 26 with Container

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

the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_artifact.

@Test
void assert_that_computation_rule_is_applied_to_artifact() {
    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));
    final Set<ArtifactContainer> artifactContainers = application.getContainersOfType(containerType1);
    assertThat(artifactContainers).hasSize(1);
    final ArtifactContainer defaultContainer = artifactContainers.iterator().next();
    application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
    c4ModelBuilder.artifactRule().predicate(artifact -> artifact.getName().equals("Class1ForBuildingBlockType1")).computation((artifact, lookup) -> Set.of(lookup.container(defaultContainer).addComponent("CustomName1", null, "CustomTechnology1"), lookup.container(defaultContainer).addComponent("CustomName2", null, "CustomTechnology2")));
    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("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) 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 27 with Container

use of com.structurizr.model.Container in project tutorials by eugenp.

the class StructurizrSimple method addSpringComponents.

private static void addSpringComponents(Workspace workspace) throws Exception {
    Container jvm2 = workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL).getContainerWithName("JVM-2");
    findComponents(jvm2);
    ComponentView view = workspace.getViews().createComponentView(jvm2, JVM2_COMPONENT_VIEW, "JVM2ComponentView");
    view.addAllComponents();
}
Also used : Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView)

Example 28 with Container

use of com.structurizr.model.Container in project tutorials by eugenp.

the class StructurizrSimple method addComponents.

private static void addComponents(Workspace workspace) {
    Model model = workspace.getModel();
    SoftwareSystem paymentTerminal = model.getSoftwareSystemWithName(PAYMENT_TERMINAL);
    Container jvm1 = paymentTerminal.getContainerWithName("JVM-1");
    Component jaxrs = jvm1.addComponent("jaxrs-jersey", "restful webservice implementation", "rest");
    Component gemfire = jvm1.addComponent("gemfire", "Clustered Cache Gemfire", "cache");
    Component hibernate = jvm1.addComponent("hibernate", "Data Access Layer", "jpa");
    jaxrs.uses(gemfire, "");
    gemfire.uses(hibernate, "");
    ComponentView componentView = workspace.getViews().createComponentView(jvm1, COMPONENT_VIEW, "JVM Components");
    componentView.addAllComponents();
}
Also used : Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Model(com.structurizr.model.Model) SoftwareSystem(com.structurizr.model.SoftwareSystem) Component(com.structurizr.model.Component)

Example 29 with Container

use of com.structurizr.model.Container 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 30 with Container

use of com.structurizr.model.Container 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)

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