public static void enableAnyoneLogin(Server server) { ManagementContext mgmt = getManagementContextFromJettyServerAttributes(server); enableAnyoneLogin(mgmt); }
public static void forceUseOfDefaultCatalogWithJavaClassPath(Server server) { ManagementContext mgmt = getManagementContextFromJettyServerAttributes(server); forceUseOfDefaultCatalogWithJavaClassPath(mgmt); }
/** returns REST endpoint, with trailing slash */ public static String getBaseUriRest(Server server) { return getBaseUriHostAndPost(server)+"/v1/"; }
@Test public void testJavascriptWithRest() throws Exception { server = BrooklynJavascriptGuiLauncher.startJavascriptAndRest(); BrooklynRestApiLauncherTestFixture.forceUseOfDefaultCatalogWithJavaClassPath(server); BrooklynRestApiLauncherTestFixture.enableAnyoneLogin(server); checkEventuallyHealthy(); checkUrlContains("/index.html", "Brooklyn"); checkUrlContains("/v1/catalog/entities", "BrooklynNode"); }
protected String httpGet(String user, String path) throws Exception { HttpToolResponse response = HttpTool.httpGet(newClient(user), URI.create(getBaseUriRest()).resolve(path), ImmutableMap.<String, String>of()); assertHealthyStatusCode(response); return response.getContentAsString(); }
protected HttpToolResponse httpPost(String user, String path, byte[] body, Map<String, String> headers) throws Exception { final URI uri = URI.create(getBaseUriRest()).resolve(path); return HttpTool.httpPost(newClient(user), uri, headers, body); }
@Override protected BrooklynRestApiLauncher baseLauncher() { return super.baseLauncher() .forceUseOfDefaultCatalogWithJavaClassPath(true); }
protected String getBaseUriRest() { return getBaseUriRest(server); } /** returns REST endpoint, with trailing slash */
protected String httpGet(String path) throws Exception { return httpGet(null, path); }
protected HttpToolResponse httpPost(String user, String path, byte[] body) throws Exception { return httpPost(user, path, body, ImmutableMap.<String, String>of()); }
@AfterMethod(alwaysRun=true) public void stopServer() throws Exception { if (server!=null) { ManagementContext mgmt = getManagementContextFromJettyServerAttributes(server); server.stop(); if (mgmt!=null) Entities.destroyAll(mgmt); server = null; } }
public static ManagementContext getManagementContextFromJettyServerAttributes(Server server) { return getManagementContext((ContextHandler) server.getHandler()); }
protected Server newServer() { try { Server server = baseLauncher() .forceUseOfDefaultCatalogWithJavaClassPath(true) .start(); return server; } catch (Exception e) { throw Exceptions.propagate(e); } }
protected HttpClient newClient(String user) throws Exception { HttpTool.HttpClientBuilder builder = httpClientBuilder() .uri(getBaseUriRest()); if (user != null) { builder.credentials(new UsernamePasswordCredentials(user, "ignoredPassword")); } return builder.build(); }
protected String getBaseUriHostAndPost() { return getBaseUriHostAndPost(server); } /** returns base of server, without trailing slash - e.g. <code>http://localhost:8081</code> */
/** @deprecated since 0.9.0 use {@link #getBaseUriHostAndPost(Server)} or {@link #getBaseUriRest(Server)} */ @Deprecated public static String getBaseUri(Server server) { return getBaseUriHostAndPost(server); }