Search in sources :

Example 26 with Workspace

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

the class JsonTests method test_backwardsCompatibilityOfRenamingEnterpriseContextViewsToSystemLandscapeViews.

@Test
public void test_backwardsCompatibilityOfRenamingEnterpriseContextViewsToSystemLandscapeViews() throws Exception {
    Workspace workspace = new Workspace("Name", "Description");
    workspace.getViews().createSystemLandscapeView("key", "description");
    JsonWriter jsonWriter = new JsonWriter(false);
    StringWriter stringWriter = new StringWriter();
    jsonWriter.write(workspace, stringWriter);
    String workspaceAsJson = stringWriter.toString();
    workspaceAsJson = workspaceAsJson.replaceAll("systemLandscapeViews", "enterpriseContextViews");
    JsonReader jsonReader = new JsonReader();
    StringReader stringReader = new StringReader(workspaceAsJson);
    workspace = jsonReader.read(stringReader);
    assertEquals(1, workspace.getViews().getSystemLandscapeViews().size());
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 27 with Workspace

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

the class JsonTests method test_write_and_read.

@Test
public void test_write_and_read() throws Exception {
    final Workspace workspace1 = new Workspace("Name", "Description");
    // output the model as JSON
    JsonWriter jsonWriter = new JsonWriter(true);
    StringWriter stringWriter = new StringWriter();
    jsonWriter.write(workspace1, stringWriter);
    // and read it back again
    JsonReader jsonReader = new JsonReader();
    StringReader stringReader = new StringReader(stringWriter.toString());
    final Workspace workspace2 = jsonReader.read(stringReader);
    assertEquals("Name", workspace2.getName());
    assertEquals("Description", workspace2.getDescription());
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 28 with Workspace

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

the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenAnElementNameAndDescriptionAndIdHaveChanged.

@Test
public void test_copyLayoutInformation_WhenAnElementNameAndDescriptionAndIdHaveChanged() {
    Workspace workspace1 = new Workspace("1", "");
    SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
    Container container1 = softwareSystem1.addContainer("Container", "Container description", "");
    ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
    view1.add(container1);
    view1.getElementView(container1).setX(123);
    view1.getElementView(container1).setY(456);
    Workspace workspace2 = new Workspace("2", "");
    SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
    // this element has ID 2
    softwareSystem2.addContainer("Web Application", "Description", "");
    Container container2 = softwareSystem2.addContainer("Database", "Description", "");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
    view2.add(container2);
    DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
    strategy.copyLayoutInformation(view1, view2);
    assertEquals(0, view2.getElementView(container2).getX());
    assertEquals(0, view2.getElementView(container2).getY());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 29 with Workspace

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

the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenAnElementNameHasChangedButTheDescriptionHasNotChanged.

@Test
public void test_copyLayoutInformation_WhenAnElementNameHasChangedButTheDescriptionHasNotChanged() {
    Workspace workspace1 = new Workspace("1", "");
    SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
    Container container1 = softwareSystem1.addContainer("Container", "Container description", "");
    ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
    view1.add(container1);
    view1.getElementView(container1).setX(123);
    view1.getElementView(container1).setY(456);
    Workspace workspace2 = new Workspace("2", "");
    SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
    Container container2 = softwareSystem2.addContainer("Container with a new name", "Container description", "");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
    view2.add(container2);
    DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
    strategy.copyLayoutInformation(view1, view2);
    assertEquals(123, view2.getElementView(container2).getX());
    assertEquals(456, view2.getElementView(container2).getY());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 30 with Workspace

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

the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenAnElementNameAndDescriptionHaveChangedButTheIdHasNotChanged.

@Test
public void test_copyLayoutInformation_WhenAnElementNameAndDescriptionHaveChangedButTheIdHasNotChanged() {
    Workspace workspace1 = new Workspace("1", "");
    SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
    Container container1 = softwareSystem1.addContainer("Container", "Container description", "");
    ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
    view1.add(container1);
    view1.getElementView(container1).setX(123);
    view1.getElementView(container1).setY(456);
    Workspace workspace2 = new Workspace("2", "");
    SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
    Container container2 = softwareSystem2.addContainer("Container with a new name", "Container with a new description", "");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
    view2.add(container2);
    DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
    strategy.copyLayoutInformation(view1, view2);
    assertEquals(123, view2.getElementView(container2).getX());
    assertEquals(456, view2.getElementView(container2).getY());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) 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