23
23
import org .junit .jupiter .api .Test ;
24
24
import software .amazon .smithy .diff .ModelDiff ;
25
25
import software .amazon .smithy .model .Model ;
26
+ import software .amazon .smithy .model .shapes .BigDecimalShape ;
27
+ import software .amazon .smithy .model .shapes .BigIntegerShape ;
28
+ import software .amazon .smithy .model .shapes .BlobShape ;
29
+ import software .amazon .smithy .model .shapes .BooleanShape ;
30
+ import software .amazon .smithy .model .shapes .ByteShape ;
31
+ import software .amazon .smithy .model .shapes .DoubleShape ;
32
+ import software .amazon .smithy .model .shapes .FloatShape ;
33
+ import software .amazon .smithy .model .shapes .IntegerShape ;
26
34
import software .amazon .smithy .model .shapes .ListShape ;
35
+ import software .amazon .smithy .model .shapes .LongShape ;
27
36
import software .amazon .smithy .model .shapes .MemberShape ;
28
37
import software .amazon .smithy .model .shapes .Shape ;
38
+ import software .amazon .smithy .model .shapes .ShortShape ;
29
39
import software .amazon .smithy .model .shapes .StringShape ;
40
+ import software .amazon .smithy .model .shapes .StructureShape ;
41
+ import software .amazon .smithy .model .shapes .TimestampShape ;
42
+ import software .amazon .smithy .model .traits .EnumDefinition ;
43
+ import software .amazon .smithy .model .traits .EnumTrait ;
30
44
import software .amazon .smithy .model .traits .PrivateTrait ;
31
45
import software .amazon .smithy .model .validation .Severity ;
32
46
import software .amazon .smithy .model .validation .ValidationEvent ;
33
47
34
48
public class RemovedShapeTest {
35
49
@ Test
36
50
public void detectsShapeRemoval () {
37
- Shape shapeA1 = StringShape .builder ().id ("foo.baz#Baz" ).build ();
38
- Shape shapeB1 = StringShape .builder ().id ("foo.baz#Bam" ).build ();
51
+ Shape shapeA1 = StructureShape .builder ().id ("foo.baz#Baz" ).build ();
52
+ Shape shapeB1 = StructureShape .builder ().id ("foo.baz#Bam" ).build ();
39
53
Model modelA = Model .assembler ().addShapes (shapeA1 , shapeB1 ).assemble ().unwrap ();
40
54
Model modelB = Model .assembler ().addShapes (shapeB1 ).assemble ().unwrap ();
41
55
List <ValidationEvent > events = ModelDiff .compare (modelA , modelB );
@@ -45,6 +59,46 @@ public void detectsShapeRemoval() {
45
59
assertThat (TestHelper .findEvents (events , Severity .ERROR ).size (), equalTo (1 ));
46
60
}
47
61
62
+ @ Test
63
+ public void emitsNotesForScalarShapes () {
64
+ Shape [] scalarShapes = new Shape [] {
65
+ IntegerShape .builder ().id ("foo.baz#BazOne" ).build (),
66
+ BigDecimalShape .builder ().id ("foo.baz#BazTwo" ).build (),
67
+ BigIntegerShape .builder ().id ("foo.baz#BazThree" ).build (),
68
+ BlobShape .builder ().id ("foo.baz#BazFour" ).build (),
69
+ BooleanShape .builder ().id ("foo.baz#BazFive" ).build (),
70
+ ByteShape .builder ().id ("foo.baz#BazSix" ).build (),
71
+ DoubleShape .builder ().id ("foo.baz#BazSeven" ).build (),
72
+ FloatShape .builder ().id ("foo.baz#BazEight" ).build (),
73
+ ShortShape .builder ().id ("foo.baz#BazNine" ).build (),
74
+ TimestampShape .builder ().id ("foo.baz#BazTen" ).build (),
75
+ LongShape .builder ().id ("foo.baz#BazEleven" ).build (),
76
+ StringShape .builder ().id ("foo.baz#BazTwelve" ).build ()
77
+ };
78
+ Model modelA = Model .assembler ().addShapes (scalarShapes ).assemble ().unwrap ();
79
+ Model modelB = Model .assembler ().assemble ().unwrap ();
80
+ List <ValidationEvent > events = ModelDiff .compare (modelA , modelB );
81
+
82
+ assertThat (TestHelper .findEvents (events , "RemovedShape" ).size (), equalTo (12 ));
83
+ assertThat ("Scalar removals should be NOTE severity" ,
84
+ events .stream ().allMatch (event -> Severity .NOTE .equals (event .getSeverity ())));
85
+ }
86
+
87
+ @ Test
88
+ public void emitsErrorForEnumString () {
89
+ Shape shapeA1 = StringShape .builder ()
90
+ .id ("foo.baz#Baz" )
91
+ .addTrait (EnumTrait .builder ().addEnum (EnumDefinition .builder ().value ("val" ).build ()).build ())
92
+ .build ();
93
+ Model modelA = Model .assembler ().addShapes (shapeA1 ).assemble ().unwrap ();
94
+ Model modelB = Model .assembler ().addShapes ().assemble ().unwrap ();
95
+ List <ValidationEvent > events = ModelDiff .compare (modelA , modelB );
96
+
97
+ assertThat (TestHelper .findEvents (events , "RemovedShape" ).size (), equalTo (1 ));
98
+ assertThat (TestHelper .findEvents (events , shapeA1 .getId ()).size (), equalTo (1 ));
99
+ assertThat (TestHelper .findEvents (events , Severity .ERROR ).size (), equalTo (1 ));
100
+ }
101
+
48
102
@ Test
49
103
public void doesNotEmitForPrivateShapes () {
50
104
Shape shape = StringShape .builder ().id ("foo.baz#Baz" ).addTrait (new PrivateTrait ()).build ();
0 commit comments