private HttpServer createHttpServer( Iterable<? extends RunnerSetting> settings, StartArgs startArgs) { HttpServer server = createBaseHttpServer(settings, startArgs); server .request(by(uri("/favicon.ico"))) .response(with(pathResource("favicon.png")), header("Content-Type", "image/png")); return server; }
@Ignore @Test public void testCreateProject() throws Exception { server .post( and( by(uri("/api/projects/create")), eq(query("key"), SonarCISClient.getKeyOf(getProject())), eq(query("name"), getProject().getProjectName()))) .response( with( "{\n" + " \"id\":\"12\",\n" + " \"k\":\"" + SonarCISClient.getKeyOf(getProject()) + "\",\n" + " \"nm\":\"yyy\",\n" + " \"sc\":\"PRJ\",\n" + " \"qu\":\"TRK\"\n" + "}"), status(200)); running( server, new Runnable() { @Override public void run() throws IOException { sonarCISClient.createProject(getProject()); } }); }
private HttpResponseSetting bindToSession(HttpServer server) { if (isMount()) { return server.mount(mount.getDir(), to(mount.getUri()), mount.getMountPredicates()); } if (isProxy()) { if (proxy.hasUrl()) { throw new IllegalArgumentException("It's not allowed to have URL in proxy from server"); } return server.proxy(proxy.getProxyConfig(), proxy.getFailover()); } if (isAnyResponse()) { return server.response(getResponseHandler()); } if (isRedirectResponse()) { return server.request(getRequestMatcher()).redirectTo(redirectTo); } return server.request(getRequestMatcher()).response(getResponseHandler()); }
@Before public void setUp() throws Exception { server .get(by(uri("/api/authentication/validate"))) .response(with("{\"validate\":true}"), status(200)); running( server, new Runnable() { @Override public void run() throws IOException { sonarCISClient = new SonarCISClient(new SonarConnectConfig(address2, username, password)); assert sonarCISClient.authenticate(); } }); }