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());
}
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());
}
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());
}
}
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());
}
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());
}
}
Aggregations