@Test public void test_createSystemContextView_ThrowsAnException_WhenADuplicateKeyIsSpecified() { try { Workspace workspace = new Workspace("Name", "Description"); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description"); workspace.getViews().createSystemContextView(softwareSystem, "key", "Description"); workspace.getViews().createSystemContextView(softwareSystem, "key", "Description"); fail(); } catch (IllegalArgumentException iae) { assertEquals("A view with the key key already exists.", iae.getMessage()); } }
@Test public void test_createSystemContextView_ThrowsAnException_WhenASoftwareSystemIsSpecified() { try { new Workspace("", "").getViews().createSystemContextView(null, null, "Description"); fail(); } catch (IllegalArgumentException iae) { assertEquals("A software system must be specified.", iae.getMessage()); } }
@Test public void test_writeView_SpaceInKey() throws Exception { workspace = new Workspace("", ""); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("My software system", ""); Person user = workspace.getModel().addPerson("A user", ""); user.uses(softwareSystem, "Uses"); workspace.getViews().createSystemContextView(softwareSystem, "the key", "").addAllElements(); // Space in key plantUMLWriter.clearSkinParams(); plantUMLWriter.write(workspace, stringWriter); assertEquals("@startuml(id=the_key)" + System.lineSeparator() + // Quotes added "scale max 1999x1999" + System.lineSeparator() + "title My software system - System Context" + System.lineSeparator() + "" + System.lineSeparator() + "rectangle \"A user\" <<Person>> as 2 #dddddd" + System.lineSeparator() + "rectangle \"My software system\" <<Software System>> as 1 #dddddd" + System.lineSeparator() + "2 .[#707070].> 1 : Uses" + System.lineSeparator() + "@enduml" + System.lineSeparator(), stringWriter.toString()); }
@Test public void test_addPersonWithoutRelationships_DoesNotAddRelationships() { Person user = model.addPerson("User", ""); SoftwareSystem softwareSystem = model.addSoftwareSystem("Software system 2", ""); user.uses(softwareSystem, "uses"); view = views.createSystemContextView(softwareSystem, "key", "description"); view.add(user, false); assertEquals(2, view.getElements().size()); assertEquals(0, view.getRelationships().size()); }
@Test public void test_addSoftwareSystemWithoutRelationships_DoesNotAddRelationships() { SoftwareSystem softwareSystem1 = model.addSoftwareSystem("Software system 1", ""); SoftwareSystem softwareSystem2 = model.addSoftwareSystem("Software system 2", ""); softwareSystem1.uses(softwareSystem2, "uses"); view = views.createSystemContextView(softwareSystem1, "key", "description"); view.add(softwareSystem2, false); assertEquals(2, view.getElements().size()); assertEquals(0, view.getRelationships().size()); }
@Test public void test_createSystemContextView_ThrowsAnException_WhenAnEmptyKeyIsSpecified() { try { Workspace workspace = new Workspace("Name", "Description"); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description"); workspace.getViews().createSystemContextView(softwareSystem, " ", "Description"); fail(); } catch (IllegalArgumentException iae) { assertEquals("A key must be specified.", iae.getMessage()); } }
@Test public void test_createSystemContextView_ThrowsAnException_WhenANullKeyIsSpecified() { try { Workspace workspace = new Workspace("Name", "Description"); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description"); workspace.getViews().createSystemContextView(softwareSystem, null, "Description"); fail(); } catch (IllegalArgumentException iae) { assertEquals("A key must be specified.", iae.getMessage()); } }
@Test public void test_removePerson_RemovesThePersonAndRelationshipsFromTheView() { Person person = model.addPerson("Person", ""); person.uses(softwareSystem, "uses"); softwareSystem.delivers(person, "delivers something to"); view = views.createSystemContextView(softwareSystem, "key", "description"); view.add(person); assertEquals(2, view.getElements().size()); assertEquals(2, view.getRelationships().size()); view.remove(person); assertEquals(1, view.getElements().size()); assertEquals(0, view.getRelationships().size()); }
@Test public void test_removeSoftwareSystem_RemovesTheSoftwareSystemAndRelationshipsFromTheView() { SoftwareSystem softwareSystem1 = model.addSoftwareSystem("Software system 1", ""); SoftwareSystem softwareSystem2 = model.addSoftwareSystem("Software system 2", ""); softwareSystem1.uses(softwareSystem2, "uses"); softwareSystem2.uses(softwareSystem1, "uses"); view = views.createSystemContextView(softwareSystem1, "key", "description"); view.add(softwareSystem2); assertEquals(2, view.getElements().size()); assertEquals(2, view.getRelationships().size()); view.remove(softwareSystem2); assertEquals(1, view.getElements().size()); assertEquals(0, view.getRelationships().size()); }
public static void main(String[] args) throws Exception { Workspace workspace = new Workspace("Documentation - Automatic", "An empty software architecture document using the Structurizr template."); Model model = workspace.getModel(); ViewSet views = workspace.getViews(); Person user = model.addPerson("User", "A user of my software system."); SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "My software system."); user.uses(softwareSystem, "Uses"); SystemContextView contextView = views.createSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram."); contextView.addAllSoftwareSystems(); contextView.addAllPeople(); Styles styles = views.getConfiguration().getStyles(); styles.addElementStyle(Tags.PERSON).shape(Shape.Person); // this directory includes a mix of Markdown and AsciiDoc files File documentationRoot = new File("./structurizr-examples/src/com/structurizr/example/documentation/automatic"); AutomaticDocumentationTemplate template = new AutomaticDocumentationTemplate(workspace); template.addSections(softwareSystem, documentationRoot); StructurizrClient structurizrClient = new StructurizrClient(API_KEY, API_SECRET); structurizrClient.putWorkspace(WORKSPACE_ID, workspace); }
@Test public void test_copyLayoutInformationFrom_WhenTheSystemContextViewKeysMatch() { Workspace workspace1 = createWorkspace(); SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view1 = workspace1.getViews().createSystemContextView(softwareSystem1, "context", "Description"); 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"); view2.addAllElements(); workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews()); assertEquals(100, view2.getElements().iterator().next().getX()); assertEquals(PaperSize.A3_Landscape, view2.getPaperSize()); }
@Test public void test_copyLayoutInformationFrom_CopiesThePaperSize_WhenThePaperSizeIsNotSet() { Workspace workspace1 = createWorkspace(); SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view1 = workspace1.getViews().createSystemContextView(softwareSystem1, "context", "Description"); view1.setPaperSize(PaperSize.A3_Landscape); Workspace workspace2 = createWorkspace(); SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view2 = workspace2.getViews().createSystemContextView(softwareSystem2, "context", "Description"); workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews()); assertEquals(PaperSize.A3_Landscape, view2.getPaperSize()); }
@Test public void test_copyLayoutInformationFrom_WhenAViewKeyHasBeenIntroduced() { Workspace workspace1 = createWorkspace(); SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view1 = workspace1.getViews().createSystemContextView(softwareSystem1, "context", "Description"); view1.setKey(null); // this simulates views created by previous versions of the client library 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"); view2.addAllElements(); workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews()); assertEquals(100, view2.getElements().iterator().next().getX()); assertEquals(PaperSize.A3_Landscape, view2.getPaperSize()); }
@Test public void test_copyLayoutInformationFrom_DoesNotDoAnythingIfThereIsNoSystemContextViewToCopyInformationFrom() { Workspace workspace1 = createWorkspace(); Workspace workspace2 = createWorkspace(); SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view2 = workspace2.getViews().createSystemContextView(softwareSystem2, "context", "Description"); view2.addAllElements(); workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews()); assertEquals(0, view2.getElements().iterator().next().getX()); // default assertNull(view2.getPaperSize()); // default }
public static void main(String[] args) throws Exception { Workspace workspace = new Workspace("Corporate Branding", "This is a model of my software system."); Model model = workspace.getModel(); Person user = model.addPerson("User", "A user of my software system."); SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "My software system."); user.uses(softwareSystem, "Uses"); ViewSet views = workspace.getViews(); SystemContextView contextView = views.createSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram."); contextView.addAllSoftwareSystems(); contextView.addAllPeople(); Styles styles = views.getConfiguration().getStyles(); styles.addElementStyle(Tags.PERSON).shape(Shape.Person); StructurizrDocumentationTemplate template = new StructurizrDocumentationTemplate(workspace); template.addContextSection(softwareSystem, Format.Markdown, "Here is some context about the software system...\n\n"); Branding branding = views.getConfiguration().getBranding(); branding.setLogo(ImageUtils.getImageAsDataUri(new File("./docs/images/structurizr-logo.png"))); StructurizrClient structurizrClient = new StructurizrClient(API_KEY, API_SECRET); structurizrClient.putWorkspace(WORKSPACE_ID, workspace); }
@Test public void test_copyLayoutInformationFrom_WhenAViewKeyIsNotSetButTheViewTitlesMatch() { Workspace workspace1 = createWorkspace(); SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view1 = workspace1.getViews().createSystemContextView(softwareSystem1, "context", "Description"); view1.setKey(null); // this simulates views created by previous versions of the client library 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"); view2.setKey(null); // this simulates views created by previous versions of the client library view2.addAllElements(); workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews()); assertEquals(100, view2.getElements().iterator().next().getX()); assertEquals(PaperSize.A3_Landscape, view2.getPaperSize()); }
@Test public void test_copyLayoutInformationFrom_IgnoresThePaperSize_WhenThePaperSizeIsSet() { Workspace workspace1 = createWorkspace(); SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view1 = workspace1.getViews().createSystemContextView(softwareSystem1, "context", "Description"); view1.setPaperSize(PaperSize.A3_Landscape); Workspace workspace2 = createWorkspace(); SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System"); SystemContextView view2 = workspace2.getViews().createSystemContextView(softwareSystem2, "context", "Description"); view2.setPaperSize(PaperSize.A5_Portrait); workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews()); assertEquals(PaperSize.A5_Portrait, view2.getPaperSize()); }
@Test public void test_createSystemContextView() { Workspace workspace = new Workspace("Name", "Description"); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description"); SystemContextView systemContextView = workspace.getViews().createSystemContextView(softwareSystem, "key", "Description"); assertEquals("key", systemContextView.getKey()); assertEquals("Description", systemContextView.getDescription()); assertSame(softwareSystem, systemContextView.getSoftwareSystem()); }
public static void main(String[] args) throws Exception { Workspace workspace = new Workspace("Client-side encrypted workspace", "This is a client-side encrypted workspace. The passphrase is 'password'."); Model model = workspace.getModel(); Person user = model.addPerson("User", "A user of my software system."); SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "My software system."); user.uses(softwareSystem, "Uses"); ViewSet views = workspace.getViews(); SystemContextView contextView = views.createSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram."); contextView.addAllSoftwareSystems(); contextView.addAllPeople(); Styles styles = views.getConfiguration().getStyles(); styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#d34407").color("#ffffff"); styles.addElementStyle(Tags.PERSON).background("#f86628").color("#ffffff").shape(Shape.Person); StructurizrClient structurizrClient = new StructurizrClient(API_KEY, API_SECRET); structurizrClient.setEncryptionStrategy(new AesEncryptionStrategy("password")); structurizrClient.putWorkspace(WORKSPACE_ID, workspace); }
@Test public void test_putAndGetWorkspace_WithoutEncryption() throws Exception { Workspace workspace = new Workspace("Structurizr client library tests - without encryption", "A test workspace for the Structurizr client library"); SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description"); Person person = workspace.getModel().addPerson("Person", "Description"); person.uses(softwareSystem, "Uses"); SystemContextView systemContextView = workspace.getViews().createSystemContextView(softwareSystem, "SystemContext", "Description"); systemContextView.addAllElements(); structurizrClient.putWorkspace(20081, workspace); workspace = structurizrClient.getWorkspace(20081); assertTrue(workspace.getModel().contains(softwareSystem)); assertTrue(workspace.getModel().contains(person)); assertEquals(1, workspace.getModel().getRelationships().size()); assertEquals(1, workspace.getViews().getSystemContextViews().size()); // and check the archive version is readable Workspace archivedWorkspace = new JsonReader().read(new FileReader(getArchivedWorkspace())); assertEquals(20081, archivedWorkspace.getId()); assertEquals("Structurizr client library tests - without encryption", archivedWorkspace.getName()); assertEquals(1, archivedWorkspace.getModel().getSoftwareSystems().size()); }