@Override public void start(Future<Void> startFuture) throws Exception { LOGGER.debug("Initialising mock server"); new Imposter().start(); InjectorUtil.getInjector().injectMembers(this); startServer(startFuture); }
private void startServer(String[] originalArgs) { InjectorUtil.create(new BootstrapModule()).injectMembers(this); if (isNull(pluginClassNames) || 0 == pluginClassNames.length) { LOGGER.debug("No plugins specified - attempting to load defaults"); // check for list of comma-separated plugin classes to load if none specified pluginClassNames = ofNullable(MetaUtil.readMetaProperties().getProperty("plugins")) .map(plugin -> plugin.split(",")) .orElse(new String[0]); } final Map<String, String> splitArgs = Arrays.stream(ofNullable(pluginArgs).orElse(new String[0])) .map(arg -> arg.split("=")) .collect(Collectors.toMap(splitArg -> splitArg[0], splitArg -> splitArg[1])); imposterConfig.setConfigDirs(configDirs); imposterConfig.setPluginClassNames(pluginClassNames); imposterConfig.setListenPort(listenPort); imposterConfig.setHost(host); imposterConfig.setServerUrl(serverUrl); imposterConfig.setTlsEnabled(tlsEnabled); imposterConfig.setKeystorePath(keystorePath); imposterConfig.setKeystorePassword(keystorePassword); imposterConfig.setPluginArgs(splitArgs); final List<String> args = Lists.newArrayList(originalArgs); args.add(0, "run"); args.add(1, ImposterVerticle.class.getCanonicalName()); super.dispatch(args.toArray(new String[args.size()])); }
public void start() { InjectorUtil.createChildInjector(getModules()).injectMembers(this); // server config processConfiguration(); // load and configure plugins final Map<String, List<File>> pluginConfigs = loadPluginConfigs(imposterConfig.getConfigDirs()); instantiatePlugins(imposterConfig.getPluginClassNames(), pluginConfigs); configurePlugins(pluginConfigs); }
default void scriptHandler(C config, RoutingContext routingContext, Map<String, Object> additionalContext, Consumer<ResponseBehaviour> defaultBehaviourHandler) { final ResponseService responseService = InjectorUtil.getInjector().getInstance(ResponseService.class); try { final ResponseBehaviour responseBehaviour = responseService.getResponseBehaviour( routingContext, config, additionalContext, Collections.emptyMap()); if (ResponseBehaviourType.IMMEDIATE_RESPONSE.equals(responseBehaviour.getBehaviourType())) { routingContext.response() .setStatusCode(responseBehaviour.getStatusCode()) .end(); } else { // default behaviour defaultBehaviourHandler.accept(responseBehaviour); } } catch (Exception e) { routingContext.fail(e); } } }
@Before public void setUp(TestContext testContext) throws Exception { final Async async = testContext.async(); listenPort = findFreePort(); // simulate ImposterLauncher injector bootstrap final ImposterConfig imposterConfig = InjectorUtil.create(new BootstrapModule()).getInstance(ImposterConfig.class); configure(imposterConfig); rule.vertx().deployVerticle(ImposterVerticle.class.getCanonicalName(), completion -> { if (completion.succeeded()) { async.complete(); } else { testContext.fail(completion.cause()); } }); }
@Test public void testPluginLoadAndConfig(TestContext testContext) throws Exception { final PluginManager pluginManager = InjectorUtil.getInjector().getInstance(PluginManager.class); final TestPluginImpl plugin = pluginManager.getPlugin(TestPluginImpl.class.getCanonicalName()); testContext.assertNotNull(plugin); testContext.assertNotNull(plugin.getConfigs()); testContext.assertEquals(1, plugin.getConfigs().size()); final TestPluginConfig pluginConfig = plugin.getConfigs().get(0); testContext.assertEquals("/example", pluginConfig.getPath()); testContext.assertEquals("simple-plugin-data.json", pluginConfig.getResponseConfig().getStaticFile()); testContext.assertEquals("testValue", pluginConfig.getCustomProperty()); }