/** * Resolves the logical endpoint into a real endpoint provided by the {@link IGatewayTestServer}. * * @param endpoint */ protected String resolveEndpoint(String endpoint) { if ("api".equals(endpoint)) { return gatewayServer.getApiEndpoint(); } else if ("gateway".equals(endpoint)) { return gatewayServer.getGatewayEndpoint(); } else { return TestUtil.doPropertyReplacement(endpoint); } }
/** @see org.junit.runners.ParentRunner#run(org.junit.runner.notification.RunNotifier) */ @Override public void run(RunNotifier notifier) { setup(); log(""); log("-------------------------------------------------------------------------------"); log("Executing REST Test"); log("-------------------------------------------------------------------------------"); log(""); System.setProperty("apiman-gateway-test.endpoints.echo", gatewayServer.getEchoTestEndpoint()); try { super.run(notifier); } finally { try { shutdown(); } catch (Throwable e) { e.printStackTrace(); } resetSystemProperties(); } log(""); log("-------------------------------------------------------------------------------"); log("REST Test complete"); log("-------------------------------------------------------------------------------"); log(""); }
/** @throws Exception */ protected static void stopServer() { try { gatewayServer.stop(); } catch (Exception e) { throw new RuntimeException(e); } }
/** Creates a gateway from a gateway test config file. */ protected static void createAndConfigureGateway() { String testConfig = System.getProperty("apiman.gateway-test.config", null); if (testConfig == null) { testConfig = "default"; } URL configUrl = GatewayRestTester.class .getClassLoader() .getResource("test-configs/" + testConfig + ".json"); ObjectMapper mapper = new ObjectMapper(); try { JsonNode config = mapper.readTree(configUrl); String factoryFQN = config.get("factory").asText(); IGatewayTestServerFactory factory = (IGatewayTestServerFactory) Class.forName(factoryFQN).newInstance(); gatewayServer = factory.createGatewayTestServer(); gatewayServer.configure(config); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } }