Skip to content

Commit

Permalink
Adds an inspection for when element metadata is hidden via an element…
Browse files Browse the repository at this point in the history
… style.
  • Loading branch information
simonbrowndotje committed Jan 11, 2024
1 parent 1cfd324 commit 0e6a235
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.structurizr.Workspace;
import com.structurizr.assistant.model.*;
import com.structurizr.assistant.view.ContainerViewsForMultipleSoftwareSystemsInspection;
import com.structurizr.assistant.view.ElementStyleMetadataInspection;
import com.structurizr.assistant.view.EmptyViewsInspection;
import com.structurizr.assistant.view.SystemContextViewsForMultipleSoftwareSystemsInspection;
import com.structurizr.assistant.workspace.WorkspaceScopeInspection;
import com.structurizr.model.*;
import com.structurizr.view.ElementStyle;

public class DefaultAssistant extends Assistant {

Expand Down Expand Up @@ -62,6 +64,10 @@ private void runViewInspections(Workspace workspace) {
add(new EmptyViewsInspection(workspace).run());
add(new SystemContextViewsForMultipleSoftwareSystemsInspection(workspace).run());
add(new ContainerViewsForMultipleSoftwareSystemsInspection(workspace).run());

for (ElementStyle elementStyle : workspace.getViews().getConfiguration().getStyles().getElements()) {
add(new ElementStyleMetadataInspection(workspace).run(elementStyle));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.structurizr.assistant.view;

import com.structurizr.Workspace;
import com.structurizr.assistant.Inspection;
import com.structurizr.assistant.Recommendation;
import com.structurizr.model.Element;
import com.structurizr.view.ElementStyle;
import com.structurizr.view.SystemContextView;

import java.util.HashSet;
import java.util.Set;

public class ElementStyleMetadataInspection extends Inspection {

public ElementStyleMetadataInspection(Workspace workspace) {
super(workspace);
}

public final Recommendation run(ElementStyle elementStyle) {
if (isEnabled(getType(), getWorkspace(), getWorkspace().getViews().getConfiguration())) {
return inspect(elementStyle);
}

return noRecommendation();
}

public Recommendation inspect(ElementStyle elementStyle) {
if (elementStyle.getMetadata() != null && !elementStyle.getMetadata()) {
return lowPriorityRecommendation("The element style for tag \"" + elementStyle.getTag() + "\" has metadata hidden, which may introduce ambiguity on rendered diagrams.");
}

return noRecommendation();
}

@Override
protected String getType() {
return "views.styles.element.metadata";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.structurizr.assistant.view;

import com.structurizr.Workspace;
import com.structurizr.assistant.Recommendation;
import com.structurizr.view.ElementStyle;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class ElementStyleMetadataInspectionTests {

@Test
public void run_WithMetadataFalse() {
Workspace workspace = new Workspace("Name", "Description");
ElementStyle elementStyle = workspace.getViews().getConfiguration().getStyles().addElementStyle("Tag").metadata(false);

Recommendation recommendation = new ElementStyleMetadataInspection(workspace).run(elementStyle);
Assertions.assertEquals(Recommendation.Priority.Low, recommendation.getPriority());
assertEquals("structurizr.recommendations.views.styles.element.metadata", recommendation.getType());
assertEquals("The element style for tag \"Tag\" has metadata hidden, which may introduce ambiguity on rendered diagrams.", recommendation.getDescription());
}

@Test
public void run_WithMetadataTrue() {
Workspace workspace = new Workspace("Name", "Description");
ElementStyle elementStyle = workspace.getViews().getConfiguration().getStyles().addElementStyle("Tag").metadata(true);

Recommendation recommendation = new ElementStyleMetadataInspection(workspace).run(elementStyle);
assertNull(recommendation);
}

@Test
public void run_WithMetadataUnset() {
Workspace workspace = new Workspace("Name", "Description");
ElementStyle elementStyle = workspace.getViews().getConfiguration().getStyles().addElementStyle("Tag");

Recommendation recommendation = new ElementStyleMetadataInspection(workspace).run(elementStyle);
assertNull(recommendation);
}

}

0 comments on commit 0e6a235

Please sign in to comment.