Search in sources :

Example 36 with Workspace

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

the class ViewSetTests method test_hydrate.

@Test
public void test_hydrate() {
    Workspace workspace = new Workspace("Name", "Description");
    Model model = workspace.getModel();
    ViewSet views = workspace.getViews();
    Person person = model.addPerson("Person", "Description");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    Container container = softwareSystem.addContainer("Container", "Description", "Technology");
    Component component = container.addComponent("Component", "Description", "Technology");
    Relationship personUsesSoftwareSystemRelationship = person.uses(softwareSystem, "uses");
    DeploymentNode deploymentNode = model.addDeploymentNode("Deployment Node", "Description", "Technology");
    ContainerInstance containerInstance = deploymentNode.add(container);
    SystemLandscapeView systemLandscapeView = new SystemLandscapeView();
    // this is used for the filtered view below
    systemLandscapeView.setKey("systemLandscape");
    systemLandscapeView.setElements(elementViewsFor(person, softwareSystem));
    systemLandscapeView.setRelationships(relationshipViewsFor(personUsesSoftwareSystemRelationship));
    views.setSystemLandscapeViews(Collections.singleton(systemLandscapeView));
    SystemContextView systemContextView = new SystemContextView();
    systemContextView.setKey("systemContext");
    systemContextView.setSoftwareSystemId(softwareSystem.getId());
    systemContextView.setElements(elementViewsFor(softwareSystem));
    views.setSystemContextViews(Collections.singleton(systemContextView));
    ContainerView containerView = new ContainerView();
    containerView.setKey("containers");
    containerView.setSoftwareSystemId(softwareSystem.getId());
    containerView.setElements(elementViewsFor(container));
    views.setContainerViews(Collections.singleton(containerView));
    ComponentView componentView = new ComponentView();
    componentView.setKey("components");
    componentView.setSoftwareSystemId(softwareSystem.getId());
    componentView.setContainerId(container.getId());
    componentView.setElements(elementViewsFor(component));
    views.setComponentViews(Collections.singleton(componentView));
    DynamicView dynamicView = new DynamicView();
    dynamicView.setKey("dynamic");
    dynamicView.setElementId(softwareSystem.getId());
    dynamicView.setElements(elementViewsFor(component));
    views.setDynamicViews(Collections.singleton(dynamicView));
    DeploymentView deploymentView = new DeploymentView();
    deploymentView.setKey("deployment");
    deploymentView.setSoftwareSystemId(softwareSystem.getId());
    deploymentView.setElements(elementViewsFor(deploymentNode, containerInstance));
    views.setDeploymentViews(Collections.singleton(deploymentView));
    FilteredView filteredView = new FilteredView();
    filteredView.setKey("filtered");
    filteredView.setBaseViewKey(systemLandscapeView.getKey());
    views.setFilteredViews(Collections.singleton(filteredView));
    workspace.getViews().hydrate(model);
    assertSame(model, systemLandscapeView.getModel());
    assertSame(views, systemLandscapeView.getViewSet());
    assertSame(person, systemLandscapeView.getElementView(person).getElement());
    assertSame(softwareSystem, systemLandscapeView.getElementView(softwareSystem).getElement());
    assertSame(personUsesSoftwareSystemRelationship, systemLandscapeView.getRelationshipView(personUsesSoftwareSystemRelationship).getRelationship());
    assertSame(model, systemContextView.getModel());
    assertSame(views, systemContextView.getViewSet());
    assertSame(softwareSystem, systemContextView.getSoftwareSystem());
    assertSame(softwareSystem, systemContextView.getElementView(softwareSystem).getElement());
    assertSame(model, containerView.getModel());
    assertSame(views, containerView.getViewSet());
    assertSame(softwareSystem, containerView.getSoftwareSystem());
    assertSame(container, containerView.getElementView(container).getElement());
    assertSame(model, componentView.getModel());
    assertSame(views, componentView.getViewSet());
    assertSame(softwareSystem, componentView.getSoftwareSystem());
    assertSame(container, componentView.getContainer());
    assertSame(component, componentView.getElementView(component).getElement());
    assertSame(model, dynamicView.getModel());
    assertSame(views, dynamicView.getViewSet());
    assertSame(softwareSystem, dynamicView.getSoftwareSystem());
    assertSame(softwareSystem, dynamicView.getElement());
    assertSame(component, dynamicView.getElementView(component).getElement());
    assertSame(model, deploymentView.getModel());
    assertSame(views, deploymentView.getViewSet());
    assertSame(softwareSystem, deploymentView.getSoftwareSystem());
    assertSame(deploymentNode, deploymentView.getElementView(deploymentNode).getElement());
    assertSame(containerInstance, deploymentView.getElementView(containerInstance).getElement());
    assertSame(systemLandscapeView, filteredView.getView());
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 37 with Workspace

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

the class ViewSetTests method test_createDynamicView_ThrowsAnException_WhenANullKeyIsSpecified.

@Test
public void test_createDynamicView_ThrowsAnException_WhenANullKeyIsSpecified() {
    try {
        Workspace workspace = new Workspace("Name", "Description");
        workspace.getViews().createDynamicView(null, "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A key must be specified.", iae.getMessage());
    }
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 38 with Workspace

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

the class ViewSetTests method test_createDynamicViewForASoftwareSystem_ThrowsAnException_WhenAnEmptyKeyIsSpecified.

@Test
public void test_createDynamicViewForASoftwareSystem_ThrowsAnException_WhenAnEmptyKeyIsSpecified() {
    try {
        Workspace workspace = new Workspace("Name", "Description");
        SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description");
        workspace.getViews().createDynamicView(softwareSystem, " ", "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A key must be specified.", iae.getMessage());
    }
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 39 with Workspace

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

the class ViewSetTests method test_copyLayoutInformationFrom_WhenAViewKeyIsNotSetButTheViewTitlesMatch.

@Test
public void test_copyLayoutInformationFrom_WhenAViewKeyIsNotSetButTheViewTitlesMatch() {
    Workspace workspace1 = createWorkspace();
    SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System");
    SystemContextView view1 = workspace1.getViews().createSystemContextView(softwareSystem1, "context", "Description");
    // this simulates views created by previous versions of the client library
    view1.setKey(null);
    view1.addAllElements();
    view1.getElements().iterator().next().setX(100);
    view1.setPaperSize(PaperSize.A3_Landscape);
    Workspace workspace2 = createWorkspace();
    SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System");
    SystemContextView view2 = workspace2.getViews().createSystemContextView(softwareSystem2, "context", "Description");
    // this simulates views created by previous versions of the client library
    view2.setKey(null);
    view2.addAllElements();
    workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews());
    assertEquals(100, view2.getElements().iterator().next().getX());
    assertEquals(PaperSize.A3_Landscape, view2.getPaperSize());
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 40 with Workspace

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

the class ViewSetTests method test_copyLayoutInformationFrom_DoesNotDoAnythingIfThereIsNoContainerViewToCopyInformationFrom.

@Test
public void test_copyLayoutInformationFrom_DoesNotDoAnythingIfThereIsNoContainerViewToCopyInformationFrom() {
    Workspace workspace1 = createWorkspace();
    Workspace workspace2 = createWorkspace();
    SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "containers", "Description");
    view2.addAllElements();
    workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews());
    // default
    assertEquals(0, view2.getElements().iterator().next().getX());
    // default
    assertNull(view2.getPaperSize());
}
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