Search in sources :

Example 66 with Workspace

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

the class ViewSetTests method test_createDeploymentView_ThrowsAnException_WhenADuplicateKeyIsUsed.

@Test
public void test_createDeploymentView_ThrowsAnException_WhenADuplicateKeyIsUsed() {
    Workspace workspace = new Workspace("Name", "Description");
    SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Name", "Description");
    workspace.getViews().createDeploymentView(softwareSystem, "deployment", "Description");
    try {
        workspace.getViews().createDeploymentView(softwareSystem, "deployment", "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A view with the key deployment already exists.", iae.getMessage());
    }
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 67 with Workspace

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

the class ViewSetTests method test_createDeploymentViewForASoftwareSystem_ThrowsAnException_WhenADuplicateKeyIsUsed.

@Test
public void test_createDeploymentViewForASoftwareSystem_ThrowsAnException_WhenADuplicateKeyIsUsed() {
    Workspace workspace = new Workspace("Name", "Description");
    SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Name", "Description");
    workspace.getViews().createDeploymentView(softwareSystem, "deployment", "Description");
    try {
        workspace.getViews().createDeploymentView(softwareSystem, "deployment", "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A view with the key deployment already exists.", iae.getMessage());
    }
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 68 with Workspace

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

the class ViewTests method test_copyLayoutInformationFrom.

@Test
public void test_copyLayoutInformationFrom() {
    Workspace workspace1 = new Workspace("", "");
    Model model1 = workspace1.getModel();
    SoftwareSystem softwareSystem1A = model1.addSoftwareSystem("System A", "Description");
    SoftwareSystem softwareSystem1B = model1.addSoftwareSystem("System B", "Description");
    Person person1 = model1.addPerson("Person", "Description");
    Relationship personUsesSoftwareSystem1 = person1.uses(softwareSystem1A, "Uses");
    // create a view with SystemA and Person (locations are set for both, relationship has vertices)
    StaticView staticView1 = new SystemContextView(softwareSystem1A, "context", "Description");
    staticView1.setPaperSize(PaperSize.A3_Landscape);
    staticView1.setDimensions(new Dimensions(123, 456));
    staticView1.add(softwareSystem1B);
    staticView1.getElementView(softwareSystem1B).setX(123);
    staticView1.getElementView(softwareSystem1B).setY(321);
    staticView1.add(person1);
    staticView1.getElementView(person1).setX(456);
    staticView1.getElementView(person1).setY(654);
    staticView1.getRelationshipView(personUsesSoftwareSystem1).setVertices(Arrays.asList(new Vertex(123, 456)));
    staticView1.getRelationshipView(personUsesSoftwareSystem1).setPosition(70);
    staticView1.getRelationshipView(personUsesSoftwareSystem1).setRouting(Routing.Orthogonal);
    // and create a dynamic view, as they are treated slightly differently
    DynamicView dynamicView1 = new DynamicView(model1, "dynamic", "Description");
    dynamicView1.add(person1, "Overridden description", softwareSystem1A);
    dynamicView1.getElementView(person1).setX(111);
    dynamicView1.getElementView(person1).setY(222);
    dynamicView1.getElementView(softwareSystem1A).setX(333);
    dynamicView1.getElementView(softwareSystem1A).setY(444);
    dynamicView1.getRelationshipView(personUsesSoftwareSystem1).setVertices(Arrays.asList(new Vertex(555, 666)));
    dynamicView1.getRelationshipView(personUsesSoftwareSystem1).setPosition(30);
    dynamicView1.getRelationshipView(personUsesSoftwareSystem1).setRouting(Routing.Direct);
    Workspace workspace2 = new Workspace("", "");
    Model model2 = workspace2.getModel();
    // creating these in the opposite order will cause them to get different internal IDs
    SoftwareSystem softwareSystem2B = model2.addSoftwareSystem("System B", "Description");
    SoftwareSystem softwareSystem2A = model2.addSoftwareSystem("System A", "Description");
    Person person2 = model2.addPerson("Person", "Description");
    Relationship personUsesSoftwareSystem2 = person2.uses(softwareSystem2A, "Uses");
    // create a view with SystemB and Person (locations are 0,0 for both)
    StaticView staticView2 = new SystemContextView(softwareSystem2A, "context", "Description");
    staticView2.add(softwareSystem2B);
    staticView2.add(person2);
    assertEquals(0, staticView2.getElementView(softwareSystem2B).getX());
    assertEquals(0, staticView2.getElementView(softwareSystem2B).getY());
    assertEquals(0, staticView2.getElementView(softwareSystem2B).getX());
    assertEquals(0, staticView2.getElementView(softwareSystem2B).getY());
    assertEquals(0, staticView2.getElementView(person2).getX());
    assertEquals(0, staticView2.getElementView(person2).getY());
    assertTrue(staticView2.getRelationshipView(personUsesSoftwareSystem2).getVertices().isEmpty());
    // and create a dynamic view (locations are 0,0)
    DynamicView dynamicView2 = new DynamicView(model2, "dynamic", "Description");
    dynamicView2.add(person2, "Overridden description", softwareSystem2A);
    staticView2.copyLayoutInformationFrom(staticView1);
    assertEquals(PaperSize.A3_Landscape, staticView2.getPaperSize());
    assertEquals(123, staticView2.getDimensions().getWidth());
    assertEquals(456, staticView2.getDimensions().getHeight());
    assertEquals(0, staticView2.getElementView(softwareSystem2A).getX());
    assertEquals(0, staticView2.getElementView(softwareSystem2A).getY());
    assertEquals(123, staticView2.getElementView(softwareSystem2B).getX());
    assertEquals(321, staticView2.getElementView(softwareSystem2B).getY());
    assertEquals(456, staticView2.getElementView(person2).getX());
    assertEquals(654, staticView2.getElementView(person2).getY());
    Vertex vertex1 = staticView2.getRelationshipView(personUsesSoftwareSystem2).getVertices().iterator().next();
    assertEquals(123, vertex1.getX());
    assertEquals(456, vertex1.getY());
    assertEquals(70, staticView2.getRelationshipView(personUsesSoftwareSystem2).getPosition().intValue());
    assertEquals(Routing.Orthogonal, staticView2.getRelationshipView(personUsesSoftwareSystem2).getRouting());
    dynamicView2.copyLayoutInformationFrom(dynamicView1);
    assertEquals(111, dynamicView2.getElementView(person2).getX());
    assertEquals(222, dynamicView2.getElementView(person2).getY());
    assertEquals(333, dynamicView2.getElementView(softwareSystem2A).getX());
    assertEquals(444, dynamicView2.getElementView(softwareSystem2A).getY());
    Vertex vertex2 = dynamicView2.getRelationshipView(personUsesSoftwareSystem2).getVertices().iterator().next();
    assertEquals(555, vertex2.getX());
    assertEquals(666, vertex2.getY());
    assertEquals(30, dynamicView2.getRelationshipView(personUsesSoftwareSystem2).getPosition().intValue());
    assertEquals(Routing.Direct, dynamicView2.getRelationshipView(personUsesSoftwareSystem2).getRouting());
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 69 with Workspace

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

the class ViewTests method test_addCustomElementWithoutRelationships_AddsTheCustomElementToTheView.

@Test
public void test_addCustomElementWithoutRelationships_AddsTheCustomElementToTheView() {
    Workspace workspace = new Workspace("", "");
    SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description");
    CustomElement box1 = workspace.getModel().addCustomElement("Box 1");
    CustomElement box2 = workspace.getModel().addCustomElement("Box 2");
    box1.uses(box2, "Uses");
    view.add(box1);
    assertEquals(1, view.getElements().size());
    assertEquals(0, view.getRelationships().size());
    view.add(box2, false);
    assertEquals(2, view.getElements().size());
    assertEquals(0, view.getRelationships().size());
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 70 with Workspace

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

the class ViewTests method test_removeCustomElement_RemovesTheCustomElementFromTheView.

@Test
public void test_removeCustomElement_RemovesTheCustomElementFromTheView() {
    Workspace workspace = new Workspace("", "");
    SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description");
    CustomElement box1 = workspace.getModel().addCustomElement("Box 1");
    view.add(box1);
    assertEquals(1, view.getElements().size());
    view.remove(box1);
    assertEquals(0, view.getElements().size());
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.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