@AfterClass
  public void stopServer() throws Exception {
    closeQuietly(httpClient);

    if (server != null) {
      server.stop();
    }
  }
Ejemplo n.º 2
0
 public URI resolve(String path) {
   return server.getBaseUrl().resolve(path);
 }
Ejemplo n.º 3
0
 public URI getBaseUrl() {
   return server.getBaseUrl();
 }
 private URI uriFor(String path) {
   return server.getBaseUrl().resolve(path);
 }
 private HttpUriBuilder coordinatorUriBuilder() {
   return uriBuilderFrom(server.getBaseUrl());
 }
  @BeforeClass
  public void startServer() throws Exception {
    Map<String, String> properties =
        ImmutableMap.<String, String>builder()
            .put("airship.version", "123")
            .put("node.id", "this-coordinator-instance-id")
            .put("node.location", "/test/location")
            .put("coordinator.binary-repo", "http://*****:*****@agent.config")
            .put("coordinator.aws.access-key", "my-access-key")
            .put("coordinator.aws.secret-key", "my-secret-key")
            .put("coordinator.aws.agent.ami", "ami-0123abcd")
            .put("coordinator.aws.agent.keypair", "keypair")
            .put("coordinator.aws.agent.security-group", "default")
            .put("coordinator.aws.agent.default-instance-type", "t1.micro")
            .build();

    Injector injector =
        Guice.createInjector(
            new TestingHttpServerModule(),
            new TestingNodeModule(),
            new JsonModule(),
            new JaxrsModule(),
            new EventModule(),
            Modules.override(new StaticProvisionerModule())
                .with(
                    new Module() {
                      @Override
                      public void configure(Binder binder) {
                        binder
                            .bind(StateManager.class)
                            .to(InMemoryStateManager.class)
                            .in(SINGLETON);
                        binder.bind(MockProvisioner.class).in(SINGLETON);
                        binder
                            .bind(Provisioner.class)
                            .to(Key.get(MockProvisioner.class))
                            .in(SINGLETON);
                      }
                    }),
            Modules.override(new CoordinatorMainModule())
                .with(
                    new Module() {
                      public void configure(Binder binder) {
                        binder.bind(Repository.class).toInstance(MOCK_REPO);
                        binder
                            .bind(ServiceInventory.class)
                            .to(MockServiceInventory.class)
                            .in(Scopes.SINGLETON);
                      }

                      @Provides
                      @Singleton
                      public RemoteCoordinatorFactory getRemoteCoordinatorFactory(
                          MockProvisioner provisioner) {
                        return provisioner.getCoordinatorFactory();
                      }

                      @Provides
                      @Singleton
                      public RemoteAgentFactory getRemoteAgentFactory(MockProvisioner provisioner) {
                        return provisioner.getAgentFactory();
                      }
                    }),
            new ConfigurationModule(new ConfigurationFactory(properties)));

    server = injector.getInstance(TestingHttpServer.class);
    coordinator = injector.getInstance(Coordinator.class);
    stateManager = (InMemoryStateManager) injector.getInstance(StateManager.class);
    provisioner = (MockProvisioner) injector.getInstance(Provisioner.class);
    repository = injector.getInstance(Repository.class);

    server.start();
    httpClient = new JettyHttpClient();
  }