-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Simon Brown
committed
Feb 18, 2024
1 parent
3d8da34
commit 51cadb6
Showing
6 changed files
with
223 additions
and
5 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
24 changes: 24 additions & 0 deletions
24
...rizr-inspection/src/main/java/com/structurizr/inspection/view/AbstractViewInspection.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,24 @@ | ||
package com.structurizr.inspection.view; | ||
|
||
import com.structurizr.inspection.Inspection; | ||
import com.structurizr.inspection.Inspector; | ||
import com.structurizr.inspection.Severity; | ||
import com.structurizr.inspection.Violation; | ||
import com.structurizr.view.View; | ||
|
||
abstract class AbstractViewInspection extends Inspection { | ||
|
||
public AbstractViewInspection(Inspector inspector) { | ||
super(inspector); | ||
} | ||
|
||
public final Violation run(View view) { | ||
Severity severity = getInspector().getSeverityStrategy().getSeverity(this, view); | ||
Violation violation = inspect(view); | ||
|
||
return violation == null ? null : violation.withSeverity(severity); | ||
} | ||
|
||
protected abstract Violation inspect(View view); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...rizr-inspection/src/main/java/com/structurizr/inspection/view/GeneratedKeyInspection.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,28 @@ | ||
package com.structurizr.inspection.view; | ||
|
||
import com.structurizr.inspection.Inspector; | ||
import com.structurizr.inspection.Violation; | ||
import com.structurizr.view.ModelView; | ||
import com.structurizr.view.View; | ||
|
||
public class GeneratedKeyInspection extends AbstractViewInspection { | ||
|
||
public GeneratedKeyInspection(Inspector inspector) { | ||
super(inspector); | ||
} | ||
|
||
@Override | ||
public Violation inspect(View view) { | ||
if (view.isGeneratedKey()) { | ||
return violation("The view with key \"" + view.getKey() + "\" has an automatically generated view key, which is not guaranteed to be stable over time."); | ||
} | ||
|
||
return noViolation(); | ||
} | ||
|
||
@Override | ||
protected String getType() { | ||
return "views.view.key"; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...rizr-inspection/src/main/java/com/structurizr/inspection/view/ManualLayoutInspection.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,27 @@ | ||
package com.structurizr.inspection.view; | ||
|
||
import com.structurizr.inspection.Inspector; | ||
import com.structurizr.inspection.Violation; | ||
import com.structurizr.view.ModelView; | ||
|
||
public class ManualLayoutInspection extends AbstractModelViewInspection { | ||
|
||
public ManualLayoutInspection(Inspector inspector) { | ||
super(inspector); | ||
} | ||
|
||
@Override | ||
public Violation inspect(ModelView view) { | ||
if (view.isGeneratedKey() && view.getAutomaticLayout() == null) { | ||
return violation("The view with key \"" + view.getKey() + "\" has an automatically generated view key, which may cause manual layout information to be lost in the future."); | ||
} | ||
|
||
return noViolation(); | ||
} | ||
|
||
@Override | ||
protected String getType() { | ||
return "views.view.layout"; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...inspection/src/test/java/com/structurizr/inspection/view/GeneratedKeyInspectionTests.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,36 @@ | ||
package com.structurizr.inspection.view; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.inspection.DefaultInspector; | ||
import com.structurizr.inspection.Severity; | ||
import com.structurizr.inspection.Violation; | ||
import com.structurizr.view.SystemLandscapeView; | ||
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 GeneratedKeyInspectionTests { | ||
|
||
@Test | ||
public void run_GeneratedKey() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("", "Description"); | ||
|
||
Violation violation = new GeneratedKeyInspection(new DefaultInspector(workspace)).run(view); | ||
Assertions.assertEquals(Severity.ERROR, violation.getSeverity()); | ||
assertEquals("views.view.key", violation.getType()); | ||
assertEquals("The view with key \"SystemLandscape-001\" has an automatically generated view key, which is not guaranteed to be stable over time.", violation.getMessage()); | ||
} | ||
|
||
@Test | ||
public void run_NonGeneratedKey() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description"); | ||
|
||
Violation violation = new GeneratedKeyInspection(new DefaultInspector(workspace)).run(view); | ||
assertNull(violation); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...inspection/src/test/java/com/structurizr/inspection/view/ManualLayoutInspectionTests.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,56 @@ | ||
package com.structurizr.inspection.view; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.inspection.DefaultInspector; | ||
import com.structurizr.inspection.Severity; | ||
import com.structurizr.inspection.Violation; | ||
import com.structurizr.view.SystemLandscapeView; | ||
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 ManualLayoutInspectionTests { | ||
|
||
@Test | ||
public void run_GeneratedKeyAndManualLayout() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("", "Description"); | ||
|
||
Violation violation = new ManualLayoutInspection(new DefaultInspector(workspace)).run(view); | ||
Assertions.assertEquals(Severity.ERROR, violation.getSeverity()); | ||
assertEquals("views.view.layout", violation.getType()); | ||
assertEquals("The view with key \"SystemLandscape-001\" has an automatically generated view key, which may cause manual layout information to be lost in the future.", violation.getMessage()); | ||
} | ||
|
||
@Test | ||
public void run_GeneratedKeyAndAutomaticLayout() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("", "Description"); | ||
view.enableAutomaticLayout(); | ||
|
||
Violation violation = new ManualLayoutInspection(new DefaultInspector(workspace)).run(view); | ||
assertNull(violation); | ||
} | ||
|
||
@Test | ||
public void run_NonGeneratedKeyAndManualLayout() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description"); | ||
|
||
Violation violation = new ManualLayoutInspection(new DefaultInspector(workspace)).run(view); | ||
assertNull(violation); | ||
} | ||
|
||
@Test | ||
public void run_NonGeneratedKeyAndAutomaticLayout() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description"); | ||
view.enableAutomaticLayout(); | ||
|
||
Violation violation = new ManualLayoutInspection(new DefaultInspector(workspace)).run(view); | ||
assertNull(violation); | ||
} | ||
|
||
} |