-
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an inspection for when element metadata is hidden via an element…
… style.
- Loading branch information
1 parent
1cfd324
commit 0e6a235
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ssistant/src/main/java/com/structurizr/assistant/view/ElementStyleMetadataInspection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...ant/src/test/java/com/structurizr/assistant/view/ElementStyleMetadataInspectionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |