Search in sources :

Example 21 with Workspace

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

the class DynamicViewTests method test_parallelSequence.

@Test
public void test_parallelSequence() {
    workspace = new Workspace("Name", "Description");
    model = workspace.getModel();
    SoftwareSystem softwareSystemA = model.addSoftwareSystem("A", "");
    SoftwareSystem softwareSystemB = model.addSoftwareSystem("B", "");
    SoftwareSystem softwareSystemC1 = model.addSoftwareSystem("C1", "");
    SoftwareSystem softwareSystemC2 = model.addSoftwareSystem("C2", "");
    SoftwareSystem softwareSystemD = model.addSoftwareSystem("D", "");
    SoftwareSystem softwareSystemE = model.addSoftwareSystem("E", "");
    // A -> B -> C1 -> D -> E
    // A -> B -> C2 -> D -> E
    softwareSystemA.uses(softwareSystemB, "uses");
    softwareSystemB.uses(softwareSystemC1, "uses");
    softwareSystemC1.uses(softwareSystemD, "uses");
    softwareSystemB.uses(softwareSystemC2, "uses");
    softwareSystemC2.uses(softwareSystemD, "uses");
    softwareSystemD.uses(softwareSystemE, "uses");
    DynamicView view = workspace.getViews().createDynamicView("key", "Description");
    view.add(softwareSystemA, softwareSystemB);
    view.startParallelSequence();
    view.add(softwareSystemB, softwareSystemC1);
    view.add(softwareSystemC1, softwareSystemD);
    view.endParallelSequence();
    view.startParallelSequence();
    view.add(softwareSystemB, softwareSystemC2);
    view.add(softwareSystemC2, softwareSystemD);
    view.endParallelSequence(true);
    view.add(softwareSystemD, softwareSystemE);
    assertEquals(1, view.getRelationships().stream().filter(r -> r.getOrder().equals("1")).count());
    assertEquals(2, view.getRelationships().stream().filter(r -> r.getOrder().equals("2")).count());
    assertEquals(2, view.getRelationships().stream().filter(r -> r.getOrder().equals("3")).count());
    assertEquals(1, view.getRelationships().stream().filter(r -> r.getOrder().equals("4")).count());
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 22 with Workspace

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

the class DynamicViewTests method test_normalSequence.

@Test
public void test_normalSequence() {
    workspace = new Workspace("Name", "Description");
    model = workspace.getModel();
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    Container container1 = softwareSystem.addContainer("Container 1", "Description", "Technology");
    Container container2 = softwareSystem.addContainer("Container 2", "Description", "Technology");
    Container container3 = softwareSystem.addContainer("Container 3", "Description", "Technology");
    container1.uses(container2, "Uses");
    container1.uses(container3, "Uses");
    DynamicView view = workspace.getViews().createDynamicView(softwareSystem, "key", "Description");
    view.add(container1, container2);
    view.add(container1, container3);
    assertSame(container2, view.getRelationships().stream().filter(r -> r.getOrder().equals("1")).findFirst().get().getRelationship().getDestination());
    assertSame(container3, view.getRelationships().stream().filter(r -> r.getOrder().equals("2")).findFirst().get().getRelationship().getDestination());
}
Also used : com.structurizr.model(com.structurizr.model) List(java.util.List) AbstractWorkspaceTestBase(com.structurizr.AbstractWorkspaceTestBase) Test(org.junit.Test) LinkedList(java.util.LinkedList) Assert(org.junit.Assert) Workspace(com.structurizr.Workspace) Before(org.junit.Before) ArrayList(java.util.ArrayList) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 23 with Workspace

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

the class DynamicViewTests method test_add_ThrowsAnException_WhenARelationshipBetweenTheSourceAndDestinationElementsWithTheSpecifiedTechnologyDoesNotExist.

@Test
public void test_add_ThrowsAnException_WhenARelationshipBetweenTheSourceAndDestinationElementsWithTheSpecifiedTechnologyDoesNotExist() {
    try {
        workspace = new Workspace("Name", "Description");
        model = workspace.getModel();
        SoftwareSystem ss1 = workspace.getModel().addSoftwareSystem("Software System 1", "");
        SoftwareSystem ss2 = workspace.getModel().addSoftwareSystem("Software System 2", "");
        ss1.uses(ss2, "Uses 1", "Tech 1");
        DynamicView view = workspace.getViews().createDynamicView("key", "Description");
        view.add(ss1, "Uses", "Tech 1", ss2);
        view.add(ss1, "Uses", "Tech 2", ss2);
        fail();
    } catch (Exception e) {
        assertEquals("A relationship between Software System 1 and Software System 2 with technology Tech 2 does not exist in model.", e.getMessage());
    }
}
Also used : Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 24 with Workspace

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

the class EncryptedJsonTests 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
    EncryptedJsonWriter jsonWriter = new EncryptedJsonWriter(true);
    AesEncryptionStrategy encryptionStrategy = new AesEncryptionStrategy("password");
    final EncryptedWorkspace encryptedWorkspace1 = new EncryptedWorkspace(workspace1, encryptionStrategy);
    StringWriter stringWriter = new StringWriter();
    jsonWriter.write(encryptedWorkspace1, stringWriter);
    // and read it back again
    EncryptedJsonReader jsonReader = new EncryptedJsonReader();
    StringReader stringReader = new StringReader(stringWriter.toString());
    final EncryptedWorkspace encryptedWorkspace2 = jsonReader.read(stringReader);
    assertEquals("Name", encryptedWorkspace2.getName());
    assertEquals("Description", encryptedWorkspace2.getDescription());
    encryptedWorkspace2.getEncryptionStrategy().setPassphrase(encryptionStrategy.getPassphrase());
    final Workspace workspace2 = encryptedWorkspace2.getWorkspace();
    assertEquals("Name", workspace2.getName());
    assertEquals("Description", workspace2.getDescription());
}
Also used : AesEncryptionStrategy(com.structurizr.encryption.AesEncryptionStrategy) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) EncryptedWorkspace(com.structurizr.encryption.EncryptedWorkspace) EncryptedWorkspace(com.structurizr.encryption.EncryptedWorkspace) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 25 with Workspace

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

the class EncryptedJsonWriterTests method test_write_ThrowsAnIllegalArgumentException_WhenANullWriterIsSpecified.

@Test
public void test_write_ThrowsAnIllegalArgumentException_WhenANullWriterIsSpecified() throws Exception {
    try {
        EncryptedJsonWriter writer = new EncryptedJsonWriter(true);
        Workspace workspace = new Workspace("Name", "Description");
        EncryptedWorkspace encryptedWorkspace = new EncryptedWorkspace(workspace, new AesEncryptionStrategy("password"));
        writer.write(encryptedWorkspace, null);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Writer cannot be null.", e.getMessage());
    }
}
Also used : AesEncryptionStrategy(com.structurizr.encryption.AesEncryptionStrategy) EncryptedWorkspace(com.structurizr.encryption.EncryptedWorkspace) EncryptedWorkspace(com.structurizr.encryption.EncryptedWorkspace) 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