@Test public void testGenerateScenariosWithBeandDefinitionRegistry() { HttpScenarioGenerator scenarioGenerator = new HttpScenarioGenerator(new ClassPathResource("swagger/swagger-api.json")); reset(beanRegistry); doAnswer(invocation -> { BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1]; Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet"); Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, HttpMethod.class).getValue(), HttpMethod.POST); Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue()); Assert.assertNull(scenario.getPropertyValues().get("inboundDataDictionary")); Assert.assertNull(scenario.getPropertyValues().get("outboundDataDictionary")); return null; }).when(beanRegistry).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class)); doAnswer(invocation -> { BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1]; Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}"); Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, HttpMethod.class).getValue(), HttpMethod.GET); Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue()); Assert.assertNull(scenario.getPropertyValues().get("inboundDataDictionary")); Assert.assertNull(scenario.getPropertyValues().get("outboundDataDictionary")); return null; }).when(beanRegistry).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class)); doAnswer(invocation -> { BeanDefinition scenario = (BeanDefinition) invocation.getArguments()[1]; Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue(), "/v2/pet/{petId}"); Assert.assertEquals(scenario.getConstructorArgumentValues().getArgumentValue(1, HttpMethod.class).getValue(), HttpMethod.DELETE); Assert.assertNotNull(scenario.getConstructorArgumentValues().getArgumentValue(2, Operation.class).getValue()); Assert.assertNull(scenario.getPropertyValues().get("inboundDataDictionary")); Assert.assertNull(scenario.getPropertyValues().get("outboundDataDictionary")); return null; }).when(beanRegistry).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class)); scenarioGenerator.postProcessBeanFactory(beanRegistry); verify(beanRegistry).registerBeanDefinition(eq("addPet"), any(BeanDefinition.class)); verify(beanRegistry).registerBeanDefinition(eq("getPetById"), any(BeanDefinition.class)); verify(beanRegistry).registerBeanDefinition(eq("deletePet"), any(BeanDefinition.class)); }
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { try { Assert.notNull(swaggerResource, "Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation"); Swagger swagger = new SwaggerParser().parse(FileUtils.readToString(swaggerResource)); for (Map.Entry<String, Path> path : swagger.getPaths().entrySet()) { for (Map.Entry<io.swagger.models.HttpMethod, Operation> operation : path.getValue().getOperationMap().entrySet()) { if (beanFactory instanceof BeanDefinitionRegistry) { log.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId()); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class) .addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey()) .addConstructorArgValue(HttpMethod.valueOf(operation.getKey().name())) .addConstructorArgValue(operation.getValue()) .addConstructorArgValue(swagger.getDefinitions()); if (beanFactory.containsBeanDefinition("inboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("inboundDataDictionary", "inboundJsonDataDictionary"); } if (beanFactory.containsBeanDefinition("outboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("outboundDataDictionary", "outboundJsonDataDictionary"); } ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(operation.getValue().getOperationId(), beanDefinitionBuilder.getBeanDefinition()); } else { log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId()); beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), HttpMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions())); } } } } catch (IOException e) { throw new SimulatorException("Failed to read swagger api resource", e); } }
HttpScenarioGenerator implements BeanFactoryPostProcessor { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { try { Assert.notNull(swaggerResource, "Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation"); Swagger swagger = new SwaggerParser().parse(FileUtils.readToString(swaggerResource)); for (Map.Entry<String, Path> path : swagger.getPaths().entrySet()) { for (Map.Entry<io.swagger.models.HttpMethod, Operation> operation : path.getValue().getOperationMap().entrySet()) { if (beanFactory instanceof BeanDefinitionRegistry) { log.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId()); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class) .addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey()) .addConstructorArgValue(HttpMethod.valueOf(operation.getKey().name())) .addConstructorArgValue(operation.getValue()) .addConstructorArgValue(swagger.getDefinitions()); if (beanFactory.containsBeanDefinition("inboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("inboundDataDictionary", "inboundJsonDataDictionary"); } if (beanFactory.containsBeanDefinition("outboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("outboundDataDictionary", "outboundJsonDataDictionary"); } ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(operation.getValue().getOperationId(), beanDefinitionBuilder.getBeanDefinition()); } else { log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId()); beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), HttpMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions())); } } } } catch (IOException e) { throw new SimulatorException("Failed to read swagger api resource", e); } } }
HttpScenarioGenerator implements BeanFactoryPostProcessor { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { try { Assert.notNull(swaggerResource, "Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation"); Swagger swagger = new SwaggerParser().parse(FileUtils.readToString(swaggerResource)); for (Map.Entry<String, Path> path : swagger.getPaths().entrySet()) { for (Map.Entry<io.swagger.models.HttpMethod, Operation> operation : path.getValue().getOperationMap().entrySet()) { if (beanFactory instanceof BeanDefinitionRegistry) { log.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId()); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class) .addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey()) .addConstructorArgValue(HttpMethod.valueOf(operation.getKey().name())) .addConstructorArgValue(operation.getValue()) .addConstructorArgValue(swagger.getDefinitions()); if (beanFactory.containsBeanDefinition("inboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("inboundDataDictionary", "inboundJsonDataDictionary"); } if (beanFactory.containsBeanDefinition("outboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("outboundDataDictionary", "outboundJsonDataDictionary"); } ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(operation.getValue().getOperationId(), beanDefinitionBuilder.getBeanDefinition()); } else { log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId()); beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), HttpMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions())); } } } } catch (IOException e) { throw new SimulatorException("Failed to read swagger api resource", e); } } HttpScenarioGenerator(Environment environment);  HttpScenarioGenerator(Resource swaggerResource); }
HttpScenarioGenerator implements BeanFactoryPostProcessor { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { try { Assert.notNull(swaggerResource, "Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation"); Swagger swagger = new SwaggerParser().parse(FileUtils.readToString(swaggerResource)); for (Map.Entry<String, Path> path : swagger.getPaths().entrySet()) { for (Map.Entry<io.swagger.models.HttpMethod, Operation> operation : path.getValue().getOperationMap().entrySet()) { if (beanFactory instanceof BeanDefinitionRegistry) { log.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId()); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class) .addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey()) .addConstructorArgValue(HttpMethod.valueOf(operation.getKey().name())) .addConstructorArgValue(operation.getValue()) .addConstructorArgValue(swagger.getDefinitions()); if (beanFactory.containsBeanDefinition("inboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("inboundDataDictionary", "inboundJsonDataDictionary"); } if (beanFactory.containsBeanDefinition("outboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("outboundDataDictionary", "outboundJsonDataDictionary"); } ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(operation.getValue().getOperationId(), beanDefinitionBuilder.getBeanDefinition()); } else { log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId()); beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), HttpMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions())); } } } } catch (IOException e) { throw new SimulatorException("Failed to read swagger api resource", e); } } HttpScenarioGenerator(Environment environment);  HttpScenarioGenerator(Resource swaggerResource); @Override void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory); String getContextPath(); void setContextPath(String contextPath); }
HttpScenarioGenerator implements BeanFactoryPostProcessor { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { try { Assert.notNull(swaggerResource, "Missing either swagger api system property setting or explicit swagger api resource for scenario auto generation"); Swagger swagger = new SwaggerParser().parse(FileUtils.readToString(swaggerResource)); for (Map.Entry<String, Path> path : swagger.getPaths().entrySet()) { for (Map.Entry<io.swagger.models.HttpMethod, Operation> operation : path.getValue().getOperationMap().entrySet()) { if (beanFactory instanceof BeanDefinitionRegistry) { log.info("Register auto generated scenario as bean definition: " + operation.getValue().getOperationId()); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpOperationScenario.class) .addConstructorArgValue((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey()) .addConstructorArgValue(HttpMethod.valueOf(operation.getKey().name())) .addConstructorArgValue(operation.getValue()) .addConstructorArgValue(swagger.getDefinitions()); if (beanFactory.containsBeanDefinition("inboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("inboundDataDictionary", "inboundJsonDataDictionary"); } if (beanFactory.containsBeanDefinition("outboundJsonDataDictionary")) { beanDefinitionBuilder.addPropertyReference("outboundDataDictionary", "outboundJsonDataDictionary"); } ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(operation.getValue().getOperationId(), beanDefinitionBuilder.getBeanDefinition()); } else { log.info("Register auto generated scenario as singleton: " + operation.getValue().getOperationId()); beanFactory.registerSingleton(operation.getValue().getOperationId(), createScenario((contextPath + (swagger.getBasePath() != null ? swagger.getBasePath() : "")) + path.getKey(), HttpMethod.valueOf(operation.getKey().name()), operation.getValue(), swagger.getDefinitions())); } } } } catch (IOException e) { throw new SimulatorException("Failed to read swagger api resource", e); } } HttpScenarioGenerator(Environment environment);  HttpScenarioGenerator(Resource swaggerResource); @Override void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory); String getContextPath(); void setContextPath(String contextPath);  }