Search in sources :

Example 1 with CustomElement

use of com.structurizr.model.CustomElement in project dsl by structurizr.

the class CustomElementParserTests method test_parse_CreatesACustomElement.

@Test
void test_parse_CreatesACustomElement() {
    parser.parse(context(), tokens("element", "Name"));
    assertEquals(1, model.getElements().size());
    CustomElement element = model.getCustomElementWithName("Name");
    assertNotNull(element);
    assertEquals("", element.getDescription());
    assertEquals("Element", element.getTags());
}
Also used : CustomElement(com.structurizr.model.CustomElement) Test(org.junit.jupiter.api.Test)

Example 2 with CustomElement

use of com.structurizr.model.CustomElement in project dsl by structurizr.

the class CustomElementParserTests method test_parse_CreatesACustomElementWithMetadataAndDescription.

@Test
void test_parse_CreatesACustomElementWithMetadataAndDescription() {
    parser.parse(context(), tokens("element", "Name", "Box", "Description"));
    assertEquals(1, model.getElements().size());
    CustomElement element = model.getCustomElementWithName("Name");
    assertNotNull(element);
    assertEquals("Box", element.getMetadata());
    assertEquals("Description", element.getDescription());
    assertEquals("Element", element.getTags());
}
Also used : CustomElement(com.structurizr.model.CustomElement) Test(org.junit.jupiter.api.Test)

Example 3 with CustomElement

use of com.structurizr.model.CustomElement in project dsl by structurizr.

the class CustomElementParserTests method test_parse_CreatesACustomElementWithMetadataAndDescriptionAndTags.

@Test
void test_parse_CreatesACustomElementWithMetadataAndDescriptionAndTags() {
    parser.parse(context(), tokens("element", "Name", "Box", "Description", "Tag 1, Tag 2"));
    assertEquals(1, model.getElements().size());
    CustomElement element = model.getCustomElementWithName("Name");
    assertNotNull(element);
    assertEquals("Box", element.getMetadata());
    assertEquals("Description", element.getDescription());
    assertEquals("Element,Tag 1,Tag 2", element.getTags());
}
Also used : CustomElement(com.structurizr.model.CustomElement) Test(org.junit.jupiter.api.Test)

Example 4 with CustomElement

use of com.structurizr.model.CustomElement in project dsl by structurizr.

the class CustomElementParser method parse.

CustomElement parse(GroupableDslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(TAGS_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(NAME_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    String name = tokens.get(NAME_INDEX);
    String metadata = "";
    if (tokens.includes(METADATA_INDEX)) {
        metadata = tokens.get(METADATA_INDEX);
    }
    String description = "";
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    CustomElement customElement = context.getWorkspace().getModel().addCustomElement(name, metadata, description);
    if (tokens.includes(TAGS_INDEX)) {
        String tags = tokens.get(TAGS_INDEX);
        customElement.addTags(tags.split(","));
    }
    if (context.hasGroup()) {
        customElement.setGroup(context.getGroup().getName());
    }
    return customElement;
}
Also used : CustomElement(com.structurizr.model.CustomElement)

Example 5 with CustomElement

use of com.structurizr.model.CustomElement in project java by structurizr.

the class CustomView method addAnimation.

/**
 * Adds an animation step, with the specified elements.
 *
 * @param elements      the elements that should be shown in the animation step
 */
public void addAnimation(CustomElement... elements) {
    if (elements == null || elements.length == 0) {
        throw new IllegalArgumentException("One or more elements must be specified.");
    }
    Set<String> elementIdsInPreviousAnimationSteps = new HashSet<>();
    for (Animation animationStep : animations) {
        elementIdsInPreviousAnimationSteps.addAll(animationStep.getElements());
    }
    Set<Element> elementsInThisAnimationStep = new HashSet<>();
    Set<Relationship> relationshipsInThisAnimationStep = new HashSet<>();
    for (CustomElement element : elements) {
        if (isElementInView(element)) {
            if (!elementIdsInPreviousAnimationSteps.contains(element.getId())) {
                elementIdsInPreviousAnimationSteps.add(element.getId());
                elementsInThisAnimationStep.add(element);
            }
        }
    }
    if (elementsInThisAnimationStep.size() == 0) {
        throw new IllegalArgumentException("None of the specified elements exist in this view.");
    }
    for (RelationshipView relationshipView : this.getRelationships()) {
        if ((elementsInThisAnimationStep.contains(relationshipView.getRelationship().getSource()) && elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getDestination().getId())) || (elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getSource().getId()) && elementsInThisAnimationStep.contains(relationshipView.getRelationship().getDestination()))) {
            relationshipsInThisAnimationStep.add(relationshipView.getRelationship());
        }
    }
    animations.add(new Animation(animations.size() + 1, elementsInThisAnimationStep, relationshipsInThisAnimationStep));
}
Also used : CustomElement(com.structurizr.model.CustomElement) Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship) CustomElement(com.structurizr.model.CustomElement) HashSet(java.util.HashSet)

Aggregations

CustomElement (com.structurizr.model.CustomElement)7 Test (org.junit.jupiter.api.Test)4 Element (com.structurizr.model.Element)2 Relationship (com.structurizr.model.Relationship)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1