Search in sources :

Example 1 with RelationshipView

use of com.structurizr.view.RelationshipView in project dsl by structurizr.

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipToTheViewWithAnOverriddenDescription_WhenItAlreadyExistsInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipToTheViewWithAnOverriddenDescription_WhenItAlreadyExistsInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    user.uses(softwareSystem, "Uses");
    DynamicView view = views.createDynamicView("key", "Description");
    DynamicViewDslContext context = new DynamicViewDslContext(view);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("source", user);
    elements.register("destination", softwareSystem);
    context.setIdentifierRegister(elements);
    parser.parseRelationship(context, tokens("source", "->", "destination", "Does something with"));
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("Does something with", rv.getDescription());
    assertEquals("1", rv.getOrder());
}
Also used : RelationshipView(com.structurizr.view.RelationshipView) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Example 2 with RelationshipView

use of com.structurizr.view.RelationshipView in project dsl by structurizr.

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipToTheModelAndView_WhenItDoesNotAlreadyExistInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipToTheModelAndView_WhenItDoesNotAlreadyExistInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    DynamicView view = views.createDynamicView("key", "Description");
    DynamicViewDslContext context = new DynamicViewDslContext(view);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("source", user);
    elements.register("destination", softwareSystem);
    context.setIdentifierRegister(elements);
    assertEquals(0, model.getRelationships().size());
    parser.parseRelationship(context, tokens("source", "->", "destination", "Uses"));
    assertEquals(1, model.getRelationships().size());
    Relationship r = model.getRelationships().iterator().next();
    assertSame(user, r.getSource());
    assertSame(softwareSystem, r.getDestination());
    assertEquals("Uses", r.getDescription());
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("Uses", rv.getDescription());
    assertEquals("1", rv.getOrder());
}
Also used : RelationshipView(com.structurizr.view.RelationshipView) Relationship(com.structurizr.model.Relationship) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Example 3 with RelationshipView

use of com.structurizr.view.RelationshipView in project dsl by structurizr.

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    Relationship r1 = user.uses(softwareSystem, "Uses 1", "Tech 1");
    Relationship r2 = user.uses(softwareSystem, "Uses 2", "Tech 2");
    DynamicView view = views.createDynamicView("key", "Description");
    DynamicViewDslContext context = new DynamicViewDslContext(view);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("source", user);
    elements.register("destination", softwareSystem);
    context.setIdentifierRegister(elements);
    parser.parseRelationship(context, tokens("source", "->", "destination", "Description", "Tech 2"));
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(r2, rv.getRelationship());
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("Description", rv.getDescription());
    assertEquals("1", rv.getOrder());
}
Also used : RelationshipView(com.structurizr.view.RelationshipView) Relationship(com.structurizr.model.Relationship) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Example 4 with RelationshipView

use of com.structurizr.view.RelationshipView in project dsl by structurizr.

the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipToTheView_WhenItAlreadyExistsInTheModel.

@Test
void test_parseRelationship_AddsTheRelationshipToTheView_WhenItAlreadyExistsInTheModel() {
    Person user = model.addPerson("User", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    user.uses(softwareSystem, "Uses");
    DynamicView view = views.createDynamicView("key", "Description");
    DynamicViewDslContext context = new DynamicViewDslContext(view);
    IdentifiersRegister elements = new IdentifiersRegister();
    elements.register("source", user);
    elements.register("destination", softwareSystem);
    context.setIdentifierRegister(elements);
    parser.parseRelationship(context, tokens("source", "->", "destination"));
    assertEquals(1, view.getRelationships().size());
    RelationshipView rv = view.getRelationships().iterator().next();
    assertSame(user, rv.getRelationship().getSource());
    assertSame(softwareSystem, rv.getRelationship().getDestination());
    assertEquals("", rv.getDescription());
    assertEquals("1", rv.getOrder());
}
Also used : RelationshipView(com.structurizr.view.RelationshipView) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Person(com.structurizr.model.Person) Test(org.junit.jupiter.api.Test)

Example 5 with RelationshipView

use of com.structurizr.view.RelationshipView in project moduliths by moduliths.

the class Documenter method addComponentsToView.

private void addComponentsToView(Supplier<Stream<Module>> modules, ComponentView view, Options options, Consumer<ComponentView> afterCleanup) {
    Styles styles = view.getViewSet().getConfiguration().getStyles();
    Map<Module, Component> components = getComponents(options);
    // 
    modules.get().distinct().filter(// 
    options.getExclusions().negate()).map(// 
    it -> applyBackgroundColor(it, components, options, styles)).filter(// 
    options.getComponentFilter()).forEach(view::add);
    // view.getViewSet().getConfiguration().getStyles().findElementStyle(element).getBackground()
    // Remove filtered dependency types
    // 
    DependencyType.allBut(options.getDependencyTypes()).map(// 
    Object::toString).forEach(it -> view.removeRelationshipsWithTag(it));
    afterCleanup.accept(view);
    // Filter outgoing relationships of target-only modules
    // 
    modules.get().filter(options.getTargetOnly()).forEach(module -> {
        Component component = components.get(module);
        // 
        view.getRelationships().stream().map(// 
        RelationshipView::getRelationship).filter(// 
        it -> it.getSource().equals(component)).forEach(it -> view.remove(it));
    });
    // … as well as all elements left without a relationship
    if (options.hideElementsWithoutRelationships()) {
        view.removeElementsWithNoRelationships();
    }
    afterCleanup.accept(view);
    // Remove default relationships if more qualified ones exist
    // 
    view.getRelationships().stream().map(// 
    RelationshipView::getRelationship).collect(// 
    Collectors.groupingBy(Connection::of)).values().stream().forEach(it -> potentiallyRemoveDefaultRelationship(view, it));
}
Also used : RequiredArgsConstructor(lombok.RequiredArgsConstructor) Diagram(com.structurizr.io.Diagram) C4PlantUMLExporter(com.structurizr.io.plantuml.C4PlantUMLExporter) BasicPlantUMLWriter(com.structurizr.io.plantuml.BasicPlantUMLWriter) SpringBean(org.moduliths.model.SpringBean) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Path(java.nio.file.Path) With(lombok.With) Predicate(java.util.function.Predicate) SoftwareSystem(com.structurizr.model.SoftwareSystem) RelationshipView(com.structurizr.view.RelationshipView) Asciidoctor(org.moduliths.docs.Asciidoctor) Collectors(java.util.stream.Collectors) DependencyDepth(org.moduliths.model.Module.DependencyDepth) Shape(com.structurizr.view.Shape) Tags(com.structurizr.model.Tags) Stream(java.util.stream.Stream) Relationship(com.structurizr.model.Relationship) Writer(java.io.Writer) Entry(java.util.Map.Entry) Styles(com.structurizr.view.Styles) java.util(java.util) Getter(lombok.Getter) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Component(com.structurizr.model.Component) Value(lombok.Value) Modules(org.moduliths.model.Modules) AccessLevel(lombok.AccessLevel) BiConsumer(java.util.function.BiConsumer) View(com.structurizr.view.View) Nullable(org.springframework.lang.Nullable) Model(com.structurizr.model.Model) Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) File(java.io.File) Workspace(com.structurizr.Workspace) Consumer(java.util.function.Consumer) DependencyType(org.moduliths.model.Module.DependencyType) Module(org.moduliths.model.Module) Paths(java.nio.file.Paths) PlantUMLWriter(com.structurizr.io.plantuml.PlantUMLWriter) AllArgsConstructor(lombok.AllArgsConstructor) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Element(com.structurizr.model.Element) Assert(org.springframework.util.Assert) RelationshipView(com.structurizr.view.RelationshipView) Module(org.moduliths.model.Module) Component(com.structurizr.model.Component) Styles(com.structurizr.view.Styles)

Aggregations

SoftwareSystem (com.structurizr.model.SoftwareSystem)5 RelationshipView (com.structurizr.view.RelationshipView)5 Person (com.structurizr.model.Person)4 DynamicView (com.structurizr.view.DynamicView)4 Test (org.junit.jupiter.api.Test)4 Relationship (com.structurizr.model.Relationship)3 Workspace (com.structurizr.Workspace)1 Diagram (com.structurizr.io.Diagram)1 BasicPlantUMLWriter (com.structurizr.io.plantuml.BasicPlantUMLWriter)1 C4PlantUMLExporter (com.structurizr.io.plantuml.C4PlantUMLExporter)1 PlantUMLWriter (com.structurizr.io.plantuml.PlantUMLWriter)1 Component (com.structurizr.model.Component)1 Container (com.structurizr.model.Container)1 Element (com.structurizr.model.Element)1 Model (com.structurizr.model.Model)1 Tags (com.structurizr.model.Tags)1 ComponentView (com.structurizr.view.ComponentView)1 Shape (com.structurizr.view.Shape)1 Styles (com.structurizr.view.Styles)1 View (com.structurizr.view.View)1