88import static org .assertj .core .api .Assertions .assertThat ;
99import static org .junit .jupiter .api .Assertions .assertEquals ;
1010import static org .junit .jupiter .api .Assertions .assertNotEquals ;
11+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
1112
1213import java .io .InputStreamReader ;
1314import java .util .Objects ;
1718import software .amazon .smithy .model .loader .ModelAssembler ;
1819import software .amazon .smithy .model .node .Node ;
1920import software .amazon .smithy .model .shapes .ModelSerializer ;
21+ import software .amazon .smithy .model .shapes .OperationShape ;
22+ import software .amazon .smithy .model .shapes .ShapeId ;
2023
2124public class AwsServiceBundlerTest {
2225
@@ -35,14 +38,37 @@ public void accessAnalyzer() {
3538 assertNotEquals (0 , config .getEndpoints ().size ());
3639 }
3740
41+ @ Test
42+ public void resourceApis () {
43+ var bundler = AwsServiceBundler .builder ()
44+ .serviceName ("access-analyzer" )
45+ .resolver (serviceName -> getModel ("accessanalyzer-2019-11-01.json" ))
46+ .readOnlyOperations ()
47+ .build ();
48+ var bundle = bundler .bundle ();
49+ var bundleModel = new ModelAssembler ().addUnparsedModel ("model.json" , bundle .getModel ())
50+ .disableValidation ()
51+ .putProperty (ModelAssembler .ALLOW_UNKNOWN_TRAITS , true )
52+ .assemble ()
53+ .unwrap ();
54+ //read resource APIS "GET", "LIST" should be present
55+ assertNotNull (bundleModel .expectShape (ShapeId .from ("com.amazonaws.accessanalyzer#GetAnalyzer" ),
56+ OperationShape .class ));
57+ assertNotNull (bundleModel .expectShape (ShapeId .from ("com.amazonaws.accessanalyzer#ListAnalyzers" ),
58+ OperationShape .class ));
59+
60+ //Write APIs should not be present.
61+ assertThat (bundleModel .getShape (ShapeId .from ("com.amazonaws.accessanalyzer#DeleteAnalyzer" ))).isEmpty ();
62+ }
63+
3864 @ Test
3965 public void testFilteringApis () {
4066 var filteredOperations = Set .of ("GetFindingsStatistics" , "GetFindingRecommendation" );
4167 var bundler = AwsServiceBundler .builder ()
4268 .serviceName ("access-analyzer" )
4369 .resolver (serviceName -> getModel ("accessanalyzer-2019-11-01.json" ))
4470 .exposedOperations (filteredOperations )
45- .build ();;
71+ .build ();
4672 var bundle = bundler .bundle ();
4773 var bundleModel = new ModelAssembler ().addUnparsedModel ("model.json" , bundle .getModel ())
4874 .disableValidation ()
@@ -106,14 +132,26 @@ void testOnlyOneServiceRetained() {
106132 .blockedPrefixes (ApiStandardTerminology .getWriteApiPrefixes ())
107133 .build ();
108134 var bundle = bundler .bundle ();
109- var bundleModel = new ModelAssembler ().addUnparsedModel ("model .json" , bundle .getModel ())
135+ var bundleModel = new ModelAssembler ().addUnparsedModel ("bundle .json" , bundle .getModel ())
110136 .disableValidation ()
111137 .putProperty (ModelAssembler .ALLOW_UNKNOWN_TRAITS , true )
112138 .assemble ()
113139 .unwrap ();
114140 assertThat (bundleModel .getServiceShapes ()).hasSize (1 );
141+
142+ var serviceShape = bundleModel .getServiceShapes ().iterator ().next ();
143+
144+ assertThat (serviceShape .getId ().toString ()).isEqualTo (bundle .getServiceName ());
145+ //We do not know which service gets picked because AwsServiceBundle chooses the first one it finds.
146+ String excludedNamespace ;
147+ if (bundle .getServiceName ().equals ("com.amazonaws.accessanalyzer#AccessAnalyzer" )) {
148+ excludedNamespace = "com.amazonaws.dynamodb" ;
149+ } else {
150+ excludedNamespace = "com.amazonaws.accessanalyzer" ;
151+ }
152+
115153 assertThat (bundleModel .getShapeIds ()).hasSizeLessThan (totalShapes )
116- .filteredOn (i -> i .toString ().startsWith ("com.amazonaws.accessanalyzer" ))
154+ .filteredOn (i -> i .toString ().startsWith (excludedNamespace ))
117155 .isEmpty ();
118156 }
119157
0 commit comments