@Test public void shouldGenerateMultipleSchemasWhenScanningPackageWithTwoModelCandidates() throws Exception { final List<String> expectedSchemas = Lists.newArrayList(SchemaTestUtil.createJsonSchemaAsString(Dog.class), SchemaTestUtil.createJsonSchemaAsString(Cat.class)); when(mockS3Client.putObject(any(PutObjectRequest.class))).thenReturn(new PutObjectResult()); final PublishJsonSchemaBundle bundle = new PublishJsonSchemaBundle(mockS3Client); final SchemaContracts contractConfig = new SchemaContracts(MOCK_PUBLISH_DRIVE, MOCK_PUBLISH_PATH, SCAN_PACKAGE); final ApiConfiguration apiConfig = new ApiConfiguration(); apiConfig.setSchemaContracts(contractConfig); this.appConfig.setApi(apiConfig); bundle.run(this.appConfig, this.mockEnvironment); final ArgumentCaptor<PutObjectRequest> putRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); verify(mockS3Client, times(expectedSchemas.size())).putObject(putRequestArgumentCaptor.capture()); final List<PutObjectRequest> allCaputredPutRequests = putRequestArgumentCaptor.getAllValues(); assertThat(allCaputredPutRequests).hasSize(expectedSchemas.size()); final List<String> actualSchemas = SchemaTestUtil.converToStringList( allCaputredPutRequests.get(0).getInputStream(), allCaputredPutRequests.get(1).getInputStream()); assertThat(actualSchemas).hasSameElementsAs(expectedSchemas); }
@Override public void run(final AppConfiguration configuration, final Environment environment) throws Exception { if(this.models==null && this.path == null && (configuration.getApi() == null || configuration.getApi().getSchemaContracts() == null)){ LOGGER.debug("exiting Json Schema Publisher, No configuration was found for JsonSchema publisher"); return; } this.initialize(configuration); if(this.models!=null && this.path!=null){ final JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build(); final Set<SchemaModelPair> schemasModelPairs = this.generateSchema(v4generator, this.models); this.publish(schemasModelPairs); }else{ LOGGER.info("Json Schema will not be published, either models or schema publish path were not supplied"); } }
PublishJsonSchemaBundle implements ConfiguredBundle<AppConfiguration> { @Override public void run(final AppConfiguration configuration, final Environment environment) throws Exception { if(this.models==null && this.path == null && (configuration.getApi() == null || configuration.getApi().getSchemaContracts() == null)){ LOGGER.debug("exiting Json Schema Publisher, No configuration was found for JsonSchema publisher"); return; } this.initialize(configuration); if(this.models!=null && this.path!=null){ final JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build(); final Set<SchemaModelPair> schemasModelPairs = this.generateSchema(v4generator, this.models); this.publish(schemasModelPairs); }else{ LOGGER.info("Json Schema will not be published, either models or schema publish path were not supplied"); } } }
PublishJsonSchemaBundle implements ConfiguredBundle<AppConfiguration> { @Override public void run(final AppConfiguration configuration, final Environment environment) throws Exception { if(this.models==null && this.path == null && (configuration.getApi() == null || configuration.getApi().getSchemaContracts() == null)){ LOGGER.debug("exiting Json Schema Publisher, No configuration was found for JsonSchema publisher"); return; } this.initialize(configuration); if(this.models!=null && this.path!=null){ final JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build(); final Set<SchemaModelPair> schemasModelPairs = this.generateSchema(v4generator, this.models); this.publish(schemasModelPairs); }else{ LOGGER.info("Json Schema will not be published, either models or schema publish path were not supplied"); } } PublishJsonSchemaBundle();  PublishJsonSchemaBundle(final AmazonS3Client client, final FilePath path, final Set<Class<?>> models);  PublishJsonSchemaBundle(final AmazonS3Client client);  PublishJsonSchemaBundle(final S3Admin s3);  PublishJsonSchemaBundle(final S3Admin s3, final FilePath path, final Set<Class<?>> models); }
PublishJsonSchemaBundle implements ConfiguredBundle<AppConfiguration> { @Override public void run(final AppConfiguration configuration, final Environment environment) throws Exception { if(this.models==null && this.path == null && (configuration.getApi() == null || configuration.getApi().getSchemaContracts() == null)){ LOGGER.debug("exiting Json Schema Publisher, No configuration was found for JsonSchema publisher"); return; } this.initialize(configuration); if(this.models!=null && this.path!=null){ final JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build(); final Set<SchemaModelPair> schemasModelPairs = this.generateSchema(v4generator, this.models); this.publish(schemasModelPairs); }else{ LOGGER.info("Json Schema will not be published, either models or schema publish path were not supplied"); } } PublishJsonSchemaBundle();  PublishJsonSchemaBundle(final AmazonS3Client client, final FilePath path, final Set<Class<?>> models);  PublishJsonSchemaBundle(final AmazonS3Client client);  PublishJsonSchemaBundle(final S3Admin s3);  PublishJsonSchemaBundle(final S3Admin s3, final FilePath path, final Set<Class<?>> models); @Override void run(final AppConfiguration configuration, final Environment environment); @Override void initialize(Bootstrap<?> bootstrap); }
PublishJsonSchemaBundle implements ConfiguredBundle<AppConfiguration> { @Override public void run(final AppConfiguration configuration, final Environment environment) throws Exception { if(this.models==null && this.path == null && (configuration.getApi() == null || configuration.getApi().getSchemaContracts() == null)){ LOGGER.debug("exiting Json Schema Publisher, No configuration was found for JsonSchema publisher"); return; } this.initialize(configuration); if(this.models!=null && this.path!=null){ final JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build(); final Set<SchemaModelPair> schemasModelPairs = this.generateSchema(v4generator, this.models); this.publish(schemasModelPairs); }else{ LOGGER.info("Json Schema will not be published, either models or schema publish path were not supplied"); } } PublishJsonSchemaBundle();  PublishJsonSchemaBundle(final AmazonS3Client client, final FilePath path, final Set<Class<?>> models);  PublishJsonSchemaBundle(final AmazonS3Client client);  PublishJsonSchemaBundle(final S3Admin s3);  PublishJsonSchemaBundle(final S3Admin s3, final FilePath path, final Set<Class<?>> models); @Override void run(final AppConfiguration configuration, final Environment environment); @Override void initialize(Bootstrap<?> bootstrap);  }