@Test public void shouldGenerateJsonSchemaFromSuppliedPathAndModel() throws Exception { final InputStream expectedInputStream = SchemaTestUtil.createJsonSchemaAsInputStream(Dog.class);; InputStream actualInputStream = null; try{ when(mockS3Client.putObject(any(PutObjectRequest.class))).thenReturn(new PutObjectResult()); final Set<Class<?>> models = Sets.newHashSet(); models.add(Dog.class); final PublishJsonSchemaBundle bundle = new PublishJsonSchemaBundle(mockS3Client, FilePath.as("my-s3-bucket", "api/contracts/animals"), models); bundle.run(this.appConfig, this.mockEnvironment); final ArgumentCaptor<PutObjectRequest> putRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); verify(mockS3Client, times(1)).putObject(putRequestArgumentCaptor.capture()); actualInputStream = putRequestArgumentCaptor.getValue().getInputStream(); assertThat(actualInputStream).hasContentEqualTo(expectedInputStream); }finally{ CloseableUtil.closeQuietly(actualInputStream); CloseableUtil.closeQuietly(expectedInputStream); } }
@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);  }