/** Creates a GATEWAY_HOME, starts a gateway instance and deploys a test topology. */ public void setupGateway(GatewayTestConfig config, String cluster, XMLTag topology, boolean use) throws Exception { this.useGateway = use; this.config = config; File targetDir = new File(System.getProperty("user.dir"), "target"); File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID()); gatewayDir.mkdirs(); config.setGatewayHomeDir(gatewayDir.getAbsolutePath()); File topoDir = new File(config.getGatewayTopologyDir()); topoDir.mkdirs(); File deployDir = new File(config.getGatewayDeploymentDir()); deployDir.mkdirs(); File descriptor = new File(topoDir, cluster + ".xml"); FileOutputStream stream = new FileOutputStream(descriptor); topology.toStream(stream); stream.close(); DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String, String> options = new HashMap<String, String>(); options.put("persist-master", "false"); options.put("master", "password"); try { srvcs.init(config, options); } catch (ServiceLifecycleException e) { e.printStackTrace(); // I18N not required. } File stacksDir = new File(config.getGatewayServicesDir()); stacksDir.mkdirs(); // TODO: [sumit] This is a hack for now, need to find a better way to locate the source // resources for 'stacks' to be tested String pathToStacksSource = "gateway-service-definitions/src/main/resources/services"; File stacksSourceDir = new File(targetDir.getParent(), pathToStacksSource); if (!stacksSourceDir.exists()) { stacksSourceDir = new File(targetDir.getParentFile().getParent(), pathToStacksSource); } if (stacksSourceDir.exists()) { FileUtils.copyDirectoryToDirectory(stacksSourceDir, stacksDir); } gateway = GatewayServer.startGateway(config, srvcs); MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue()); log.info("Gateway port = " + gateway.getAddresses()[0].getPort()); }
@AfterClass public static void cleanupSuite() throws Exception { LOG_ENTER(); gateway.stop(); ldap.stop(true); // FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); // NoOpAppender.tearDown( appenders ); LOG_EXIT(); }
public static void setupGateway() throws Exception { File targetDir = new File(System.getProperty("user.dir"), "target"); File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID()); gatewayDir.mkdirs(); GatewayTestConfig testConfig = new GatewayTestConfig(); config = testConfig; testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath()); File topoDir = new File(testConfig.getGatewayTopologyDir()); topoDir.mkdirs(); File deployDir = new File(testConfig.getGatewayDeploymentDir()); deployDir.mkdirs(); File descriptor = new File(topoDir, "test-cluster.xml"); FileOutputStream stream = new FileOutputStream(descriptor); createTopology().toStream(stream); stream.close(); DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String, String> options = new HashMap<String, String>(); options.put("persist-master", "false"); options.put("master", "password"); try { srvcs.init(testConfig, options); } catch (ServiceLifecycleException e) { e.printStackTrace(); // I18N not required. } gateway = GatewayServer.startGateway(testConfig, srvcs); MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue()); LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort()); gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath(); clusterUrl = gatewayUrl + "/test-cluster"; }
public void cleanup() throws Exception { gateway.stop(); FileUtils.deleteQuietly(new File(config.getGatewayTopologyDir())); FileUtils.deleteQuietly(new File(config.getGatewayConfDir())); FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir())); FileUtils.deleteQuietly(new File(config.getGatewayDeploymentDir())); FileUtils.deleteQuietly(new File(config.getGatewayDataDir())); FileUtils.deleteQuietly(new File(config.getGatewayServicesDir())); for (Service service : services.values()) { service.server.stop(); } services.clear(); ldap.stop(true); }
public String getUrl(String serviceRole, boolean real) { String url; String localHostName = getLocalHostName(); Service service = services.get(serviceRole); if (useGateway && !real) { url = "http://" + localHostName + ":" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath() + service.gatewayPath; } else if (service.mock) { url = "http://" + localHostName + ":" + service.server.getPort(); } else { url = service.realUrl.toASCIIString(); } return url; }