public RelationshipView add(@Nonnull Element source, @Nonnull Element destination) { return add(source, "", destination); }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsASoftwareSystemAndTheSameSoftwareSystemIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView(softwareSystemA, "key", "Description"); dynamicView.add(softwareSystemA, containerA1); fail(); } catch (Exception e) { assertEquals("Software System A is already the scope of this view and cannot be added to it.", e.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsASoftwareSystemButAComponentIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView(softwareSystemA, "key", "Description"); dynamicView.add(componentA1, containerA1); fail(); } catch (Exception e) { assertEquals("Components can't be added to a dynamic view when the scope is a software system.", e.getMessage()); } }
@Test public void test_write_createsAWebSequenceDiagram() throws Exception { Model model = workspace.getModel(); SoftwareSystem a = model.addSoftwareSystem("System A", ""); SoftwareSystem b = model.addSoftwareSystem("System B", ""); SoftwareSystem c = model.addSoftwareSystem("System C", ""); a.uses(b, ""); b.uses(c, "", "", InteractionStyle.Asynchronous); DynamicView view = workspace.getViews().createDynamicView("Some Key", "A description of the diagram"); view.add(a, "Does something using", b); view.add(b, "Does something then using", c); webSequenceDiagramsWriter.write(workspace, stringWriter); assertEquals("title Dynamic - Some Key" + System.lineSeparator() + System.lineSeparator() + "System A->System B: Does something using" + System.lineSeparator() + "System B->>System C: Does something then using" + System.lineSeparator() + System.lineSeparator(), stringWriter.toString()); }
@Test public void test_add_ThrowsAnException_WhenPassedANullDestinationElement() { try { DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); dynamicView.add(person, null); fail(); } catch (IllegalArgumentException iae) { assertEquals("A destination element must be specified.", iae.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsASoftwareSystemButAContainerInAnotherSoftwareSystemIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView(softwareSystemA, "key", "Description"); dynamicView.add(containerB1, containerA1); fail(); } catch (Exception e) { assertEquals("Only containers that reside inside Software System A can be added to this view.", e.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsAContainerAndTheSameContainerIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView(containerA1, "key", "Description"); dynamicView.add(containerA1, containerA2); fail(); } catch (Exception e) { assertEquals("Container A1 is already the scope of this view and cannot be added to it.", e.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsAContainerAndAComponentInAnotherContainerIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView(containerA1, "key", "Description"); dynamicView.add(componentA2, containerA2); fail(); } catch (Exception e) { assertEquals("Only components that reside inside Container A1 can be added to this view.", e.getMessage()); } }
@Test public void test_add_AddsTheSourceAndDestinationElements_WhenARelationshipBetweenThemExists() { final DynamicView dynamicView = workspace.getViews().createDynamicView(softwareSystemA, "key", "Description"); dynamicView.add(containerA1, containerA2); assertEquals(2, dynamicView.getElements().size()); }
@Test public void test_add_ThrowsAnException_WhenPassedANullSouceElement() { try { DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); dynamicView.add(null, softwareSystemA); fail(); } catch (IllegalArgumentException iae) { assertEquals("A source element must be specified.", iae.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsAContainerAndTheParentSoftwareSystemIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView(containerA1, "key", "Description"); dynamicView.add(softwareSystemA, containerA2); fail(); } catch (Exception e) { assertEquals("Software System A is already the scope of this view and cannot be added to it.", e.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsAContainerAndAContainerInAnotherSoftwareSystemIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView(containerA1, "key", "Description"); dynamicView.add(containerB1, containerA2); fail(); } catch (Exception e) { assertEquals("Only containers that reside inside Software System A can be added to this view.", e.getMessage()); } }
@Test public void test_add_AddsTheSourceAndDestinationElements_WhenARelationshipBetweenThemExistsAndTheDestinationIsAnExternalSoftwareSystem() { DynamicView dynamicView = workspace.getViews().createDynamicView(softwareSystemA, "key", "Description"); containerA2.uses(softwareSystemB, "", ""); dynamicView.add(containerA2, softwareSystemB); assertEquals(2, dynamicView.getElements().size()); }
@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()); }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsNotSpecifiedButAComponentIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); DeploymentNode deploymentNode = workspace.getModel().addDeploymentNode("Deployment node", "Description", "Technology"); dynamicView.add(componentA1, componentA1); fail(); } catch (IllegalArgumentException iae) { assertEquals("Only people and software systems can be added to this dynamic view.", iae.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenADeploymentNodeIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); DeploymentNode deploymentNode = workspace.getModel().addDeploymentNode("Deployment node", "Description", "Technology"); dynamicView.add(deploymentNode, softwareSystemA); fail(); } catch (IllegalArgumentException iae) { assertEquals("Only people, software systems, containers and components can be added to dynamic views.", iae.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenTheScopeOfTheDynamicViewIsNotSpecifiedButAContainerIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); DeploymentNode deploymentNode = workspace.getModel().addDeploymentNode("Deployment node", "Description", "Technology"); dynamicView.add(containerA1, containerA1); fail(); } catch (IllegalArgumentException iae) { assertEquals("Only people and software systems can be added to this dynamic view.", iae.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenAContainerInstanceIsAdded() { try { DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); DeploymentNode deploymentNode = workspace.getModel().addDeploymentNode("Deployment node", "Description", "Technology"); ContainerInstance containerInstance = deploymentNode.add(containerA1); dynamicView.add(containerInstance, softwareSystemA); fail(); } catch (IllegalArgumentException iae) { assertEquals("Only people, software systems, containers and components can be added to dynamic views.", iae.getMessage()); } }
@Test public void test_add_ThrowsAnException_WhenARelationshipBetweenTheSourceAndDestinationElementsDoesNotExist() { try { DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); SoftwareSystem ss1 = workspace.getModel().addSoftwareSystem("Software System 1", ""); SoftwareSystem ss2 = workspace.getModel().addSoftwareSystem("Software System 2", ""); dynamicView.add(ss1, ss2); fail(); } catch (Exception e) { assertEquals("A relationship between Software System 1 and Software System 2 does not exist in model.", e.getMessage()); } }
@Test public void test_copyLayoutInformationFrom_DoesNotDoAnythingIfThereIsNoDynamicViewToCopyInformationFrom() { Workspace workspace1 = createWorkspace(); Workspace workspace2 = createWorkspace(); Person person2 = workspace2.getModel().getPersonWithName("Person"); SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System"); DynamicView view2 = workspace2.getViews().createDynamicView("context", "Description"); view2.add(person2, softwareSystem2); workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews()); assertEquals(0, view2.getElements().iterator().next().getX()); // default assertNull(view2.getPaperSize()); // default }