@Before public void setUp() throws Exception { BasicConfigurator.configure(); server = new LocalTestServer(null, null); server.register("/hitme/*", new HttpRequestHandler() { @Override public void handle(HttpRequest req, HttpResponse resp, HttpContext ctx) throws HttpException, IOException { resp.setStatusCode(200); resp.setEntity(new StringEntity("Hello World")); } }); server.start(); client = new HttpClient(); }
@Override @Before public void setUp() throws Exception { OAuthTokenService.INSTANCE.clearToken(); HttpRequestHandler tokenHandler = new TokenHandler(); HttpRequestHandler resourceHandler = new ResourceHandler(); testServer = new LocalTestServer(null, null); testServer.register("/v3/rest/*", resourceHandler); testServer.register("/v3/token", tokenHandler); testServer.start(); port = testServer.getServicePort(); host = testServer.getServiceHostName(); // System.out.println("LocalTestServer available via http://" + host + ":" + port); params = new HashMap<String, String>(); params.put("username", userName); params.put("password", password); params.put("scope", scope); params.put("grant_type", grantType); client = MasheryClientBuilder.masheryClient().withHost(host).withProtocol("http").withPort(port).withApiKey(apiKey).withApiSecret(apiSecret).withTokenRequestParams(params).build(); }
@Before public void setUp() throws Exception { handler = mock(HttpRequestHandler.class); server = new LocalTestServer(null, null); server.register("/*", handler); server.start(); // report how to access the server System.out.println("LocalTestServer available at " + server.getServiceAddress()); primaryServiceAddress = server.getServiceAddress().getHostName() + ":" + server.getServiceAddress().getPort(); secondaryServiceAddress = server.getServiceAddress().getAddress().getHostAddress() + ":" + server.getServiceAddress().getPort(); impl = new Sosumi("http://" + primaryServiceAddress, "user", "pass"); }
@Before public void setUp() throws Exception { // use local test server to intercept http requests sent by the reporter server = new LocalTestServer(null, null); server.register("*", handler); server.start(); serverUrl = "http://localhost:" + server.getServiceAddress().getPort() + "/"; Properties properties = new Properties(); properties.put(BounceProxyControllerPropertyKeys.PROPERTY_BPC_SEND_CREATE_CHANNEL_MAX_RETRY_COUNT, "3"); properties.put(BounceProxyControllerPropertyKeys.PROPERTY_BPC_SEND_CREATE_CHANNEL_RETRY_INTERVAL_MS, "100"); Injector injector = Guice.createInjector(new PropertyLoadingModule(properties), new AbstractModule() { @Override protected void configure() { bind(CloseableHttpClient.class).toInstance(HttpClients.createDefault()); } }); bpFacade = injector.getInstance(RemoteBounceProxyFacade.class); }
@Before public void startStorageServers() throws Exception { for (int i = 0; i < 3; i++) { localServers[i] = new LocalTestServer(null, null); localServers[i].register("*", new HttpStorageRequestHandler()); localServers[i].start(); } cfg = String.format("1 http://localhost:%d\n2 http://localhost:%d\n3 http://localhost:%d\n", localServers[0].getServiceAddress().getPort(), localServers[1].getServiceAddress().getPort(), localServers[2].getServiceAddress().getPort()); }
@After public void killStorageServers() { for (LocalTestServer s: localServers) { try { s.stop(); } catch (Exception e) { } } }
public static String getTestServerAddress(LocalTestServer server) { return String.format( "http://%s:%s", server.getServiceAddress().getHostName(), server.getServiceAddress().getPort() ); }
public FakeConduit(Map<String, JSONObject> responses) throws Exception { server = new LocalTestServer(null, null); this.requestBodies = new ArrayList<String>(); for (Map.Entry<String, JSONObject> entry : responses.entrySet()) { register(entry.getKey(), entry.getValue()); } server.start(); }
@Before public void setUp() throws Exception { handler = Mockito.mock(HttpRequestHandler.class); server = new LocalTestServer(null, null); server.register("/jenkinstest/*", handler); server.start(); serverUrl = "http://" + server.getServiceHostName() + ":" + server.getServicePort() + "/jenkinstest/123"; // report how to access the server System.out.println("LocalTestServer available at " + serverUrl); j.get(PluginDescriptorImpl.class).setUrl(serverUrl); }
public void setUp(HttpRequestHandler handler) throws Exception { server = new LocalTestServer(null, null); server.register("/*", handler); server.start(); // report how to access the server address = "http://" + server.getServiceAddress().getHostName() + ":" + server.getServiceAddress().getPort(); System.out.println("LocalTestServer available at " + address); }
@Before public void setUp() throws Exception { // use local test server to intercept http requests sent by the reporter server = new LocalTestServer(null, null); server.register("*", handler); server.start(); final String serverUrl = "http://localhost:" + server.getServiceAddress().getPort(); // set test properties manually for a better overview of // what is tested Properties properties = new Properties(); // have to set the BPC base url manually as this is the // mock server which gets port settings dynamically properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_CONTROLLER_BASE_URL, serverUrl); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_ID, "X.Y"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_BPC, "http://joyn-bpX.muc/bp"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_CC, "http://joyn-bpX.de/bp"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_MONITORING_FREQUENCY_MS, "100"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_SEND_LIFECYCLE_REPORT_RETRY_INTERVAL_MS, "100"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_MAX_SEND_SHUTDOWN_TIME_SECS, "1"); Injector injector = Guice.createInjector(new PropertyLoadingModule(properties), new ControlledBounceProxyModule() { @Override protected void configure() { bind(ChannelService.class).to(DefaultBounceProxyChannelServiceImpl.class); bind(BounceProxyLifecycleMonitor.class).to(MonitoringServiceClient.class); bind(TimestampProvider.class).toInstance(mockTimestampProvider); bind(BounceProxyInformation.class).toProvider(BounceProxyInformationProvider.class); } }); reporter = injector.getInstance(MonitoringServiceClient.class); }
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.register(CHANNELPATH, new HttpRequestHandler() { @Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setStatusCode(createChannelResponseCode); response.setHeader("Location", bounceProxyUrl + "channels/" + channelId); } }); server.start(); serviceAddress = "http://" + server.getServiceAddress().getHostName() + ":" + server.getServiceAddress().getPort(); bounceProxyUrl = serviceAddress + BOUNCEPROXYPATH; Properties properties = new Properties(); properties.put(MessagingPropertyKeys.CHANNELID, channelId); properties.put(MessagingPropertyKeys.BOUNCE_PROXY_URL, bounceProxyUrl); Injector injector = Guice.createInjector(new AbstractModule() { @Override public void configure() { bind(HttpRequestFactory.class).to(ApacheHttpRequestFactory.class); bind(CloseableHttpClient.class).toProvider(HttpClientProvider.class).in(Singleton.class); bind(RequestConfig.class).toProvider(HttpDefaultRequestConfigProvider.class).in(Singleton.class); bind(MessagingSettings.class).to(ConfigurableMessagingSettings.class); } }, new JoynrPropertiesModule(properties), new JsonMessageSerializerModule(), new DummyDiscoveryModule()); longpollingChannelLifecycle = injector.getInstance(LongPollingChannelLifecycle.class); }
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.start(); }
public LocalTestServer getServer() { return server; }
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.start(); client = getDefaultClient(); }
@Before public void setUp () throws Exception { LocalTestServer server = new LocalTestServer(null, null); server.register("/manager/text/*", new HttpRequestHandler() { @Override public void handle ( HttpRequest request, HttpResponse response, HttpContext content ) throws HttpException, IOException { final String uri = request.getRequestLine().getUri(); if (uri.contains("list")) { response.setEntity(new StringEntity("OK - Listed applications for virtual host localhost\n" + "/:running:0:ROOT\n" + "/host-manager:running:0:/usr/share/tomcat7-admin/host-manager\n" + "/manager:running:3:/usr/share/tomcat7-admin/manager\n" + "/good-app:running:4:/var/lib/tomcat7/webapps/good-app\n" + "/bad-app:stopped:0:/var/lib/tomcat7/webapps/bad-app\n")); response.setStatusCode(200); } else if (uri.contains("start") || uri.contains("stop") || uri.contains("undeploy")) { response.setEntity(new StringEntity("OK - Operation executed")); response.setStatusCode(200); } else { response.setStatusCode(400); } } }); server.start(); hostName = server.getServiceAddress().getHostName(); port = server.getServiceAddress().getPort(); tomcatManagerService = new TomcatManagerServiceImpl("http://" + hostName + ":" + port + "/manager/text", null, null); }
@Before public void setUp() throws Exception { // use local test server to intercept http requests sent by the reporter server = new LocalTestServer(null, null); server.register("*", mockHandler); server.start(); final String serverUrl = "http://localhost:" + server.getServiceAddress().getPort(); // set test properties manually for a better overview of // what is tested Properties properties = new Properties(); // have to set the BPC base url manually as this is the // mock server which gets port settings dynamically properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_CONTROLLER_BASE_URL, serverUrl); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_ID, "X.Y"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_BPC, "http://joyn-bpX.muc/bp"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_CC, "http://joyn-bpX.de/bp"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_MONITORING_FREQUENCY_MS, "100"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_SEND_LIFECYCLE_REPORT_RETRY_INTERVAL_MS, "500"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_MAX_SEND_SHUTDOWN_TIME_SECS, "2"); Injector injector = Guice.createInjector(new PropertyLoadingModule(properties), new AbstractModule() { @Override protected void configure() { bind(ScheduledExecutorService.class).toInstance(mockExecutorService); bind(BounceProxyPerformanceMonitor.class).toInstance(mockPerformanceMonitor); bind(BounceProxyLifecycleMonitor.class).toInstance(mockLifecycleMonitor); bind(CloseableHttpClient.class).toInstance(HttpClients.createDefault()); } }); reporter = injector.getInstance(BounceProxyPerformanceReporter.class); // fake the clock for a more robust testing clock = new Clock(); Answer<Void> mockScheduledExecutor = new Answer<Void>() { @Override public Void answer(final InvocationOnMock invocation) throws Throwable { long frequencyMs = (Long) invocation.getArguments()[2]; Runnable runnable = (Runnable) invocation.getArguments()[0]; clock.setFrequencyMs(frequencyMs); clock.setRunnable(runnable); return null; } }; Mockito.doAnswer(mockScheduledExecutor) .when(mockExecutorService) .scheduleWithFixedDelay(Mockito.any(Runnable.class), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(TimeUnit.class)); }