예제 #1
0
  static void testUpload(TestParams testParams) throws Exception {

    FormDataMultiPart part = new FormDataMultiPart();

    part.field(RestParams.COMMIT_ID, QUERY_PARAMS.get(RestParams.COMMIT_ID));
    part.field(RestParams.MODULE_GROUPID, QUERY_PARAMS.get(RestParams.MODULE_GROUPID));
    part.field(RestParams.MODULE_ARTIFACTID, QUERY_PARAMS.get(RestParams.MODULE_ARTIFACTID));
    part.field(RestParams.MODULE_VERSION, QUERY_PARAMS.get(RestParams.MODULE_VERSION));
    part.field(RestParams.USERNAME, QUERY_PARAMS.get(RestParams.USERNAME));
    part.field(RestParams.VCS_REPO_URL, "ssh://[email protected]:7999/chop/main.git");
    part.field(RestParams.TEST_PACKAGE, QUERY_PARAMS.get(RestParams.TEST_PACKAGE));
    part.field(RestParams.MD5, "d7d4829506f6cb8c0ab2da9cb1daca02");

    File tmpFile = File.createTempFile("runner", "jar");
    FileInputStream in = new FileInputStream(tmpFile);
    FormDataBodyPart body =
        new FormDataBodyPart(RestParams.CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE);
    part.bodyPart(body);

    ClientResponse response =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(UploadResource.ENDPOINT)
            .newWebResource()
            .path("/runner")
            .type(MediaType.MULTIPART_FORM_DATA)
            .accept(MediaType.TEXT_PLAIN)
            .post(ClientResponse.class, part);

    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());

    assertEquals(UploadResource.SUCCESSFUL_TEST_MESSAGE, response.getEntity(String.class));

    tmpFile.delete();
  }
예제 #2
0
  static void testRunnerRegistryRegister(TestParams testParams) {
    /*
     * Even though in test mode the runner is not used, a runner must
     * be sent over because the method is expecting the Runner as JSON.
     */
    RunnerBuilder builder = new RunnerBuilder();
    builder
        .setTempDir(".")
        .setServerPort(19023)
        .setUrl("https://localhost:19023")
        .setHostname("foobar")
        .setIpv4Address("127.0.0.1");

    Boolean result =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(RunnerRegistryResource.ENDPOINT)
            .newWebResource()
            .path("/register")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Boolean.class, builder.getRunner());

    assertFalse(result);
  }
예제 #3
0
 static void testAuthGetWithUnallowedRole(TestParams testParams) {
   testParams
       .addQueryParameters(QUERY_PARAMS)
       .setEndpoint(AuthResource.ENDPOINT_URL + AuthResource.UNALLOWED_ROLE_PATH)
       .newWebResource()
       .accept(MediaType.APPLICATION_JSON)
       .get(String.class);
 }
예제 #4
0
 static void testAuthPostWithWrongCredentials(TestParams testParams) {
   testParams
       .addQueryParameters(WRONG_USER_PARAMS)
       .setEndpoint(AuthResource.ENDPOINT_URL)
       .newWebResource()
       .accept(MediaType.APPLICATION_JSON)
       .post(String.class);
 }
예제 #5
0
  static void testGet(TestParams testParams) {
    String result =
        testParams
            .setEndpoint(TestGetResource.ENDPOINT_URL)
            .newWebResource()
            .accept(MediaType.TEXT_PLAIN)
            .get(String.class);

    assertEquals(TestGetResource.TEST_MESSAGE, result);
  }
예제 #6
0
  static void testStop(TestParams testParams) {
    BaseResult result =
        testParams
            .setEndpoint(StopResource.ENDPOINT)
            .newWebResource()
            .accept(MediaType.APPLICATION_JSON)
            .post(BaseResult.class);

    assertEquals(result.getEndpoint(), StopResource.ENDPOINT);
  }
예제 #7
0
  static void testAuthGetWithAllowedRole(TestParams testParams) {
    String result =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(AuthResource.ENDPOINT_URL + AuthResource.ALLOWED_ROLE_PATH)
            .newWebResource()
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);

    assertEquals(AuthResource.GET_WITH_ALLOWED_ROLE_MESSAGE, result);
  }
예제 #8
0
  static void testAuthPost(TestParams testParams) {
    String result =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(AuthResource.ENDPOINT_URL)
            .newWebResource()
            .accept(MediaType.APPLICATION_JSON)
            .post(String.class);

    assertEquals(AuthResource.POST_MESSAGE, result);
  }
예제 #9
0
  static void testRunnerRegistryUnregister(TestParams testParams) {
    Boolean result =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(RunnerRegistryResource.ENDPOINT)
            .newWebResource()
            .path("/unregister")
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Boolean.class);

    assertFalse(result);
  }
예제 #10
0
  static void testRunManagerNext(TestParams testParams) {
    Integer next =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(RunManagerResource.ENDPOINT)
            .newWebResource()
            .path("/next")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON)
            .get(Integer.class);

    assertEquals(0, next.intValue());
  }
예제 #11
0
  static void testRunnerRegistryList(TestParams testParams) {
    List<Runner> runnerList =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(RunnerRegistryResource.ENDPOINT)
            .newWebResource()
            .path("/list")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .get(new GenericType<List<Runner>>() {});

    assertNotNull(runnerList);
    assertEquals(0, runnerList.size());
  }
예제 #12
0
  static void testSetup(TestParams testParams) {
    ClientResponse response =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(SetupResource.ENDPOINT)
            .newWebResource()
            .queryParam(RestParams.RUNNER_COUNT, "5")
            .path("/stack")
            .type(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .post(ClientResponse.class);

    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());

    assertEquals("\"NotFound\"", response.getEntity(String.class));
  }
예제 #13
0
  static void testRunnerRegistrySequence(TestParams testParams) {
    /*
     * ------------------------------------------------------------
     * Let's register a runner first before we query for it
     * ------------------------------------------------------------
     */

    String commitId = UUID.randomUUID().toString();
    String hostname = RandomStringUtils.randomAlphabetic(8);

    RunnerBuilder builder = new RunnerBuilder();
    builder
        .setTempDir(".")
        .setServerPort(19023)
        .setUrl("https://localhost:19023")
        .setHostname(hostname)
        .setIpv4Address("127.0.0.1");

    Boolean result =
        testParams
            .addQueryParameters(QUERY_PARAMS)
            .setEndpoint(RunnerRegistryResource.ENDPOINT)
            .newWebResource(null)
            .queryParam(RestParams.COMMIT_ID, commitId)
            .path("/register")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Boolean.class, builder.getRunner());

    assertTrue(result);

    /*
     * ------------------------------------------------------------
     * Let's see if we can get the runner back from the registry
     * ------------------------------------------------------------
     */
    List<Runner> runnerList =
        testParams
            .setEndpoint(RunnerRegistryResource.ENDPOINT)
            .newWebResource(null)
            .queryParam(RestParams.COMMIT_ID, commitId)
            .path("/list")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .get(new GenericType<List<Runner>>() {});

    assertNotNull(runnerList);
    assertEquals(1, runnerList.size());

    Runner runner = runnerList.get(0);
    assertEquals(19023, runner.getServerPort());
    assertEquals("https://localhost:19023", runner.getUrl());
    assertEquals(hostname, runner.getHostname());
    assertEquals("127.0.0.1", runner.getIpv4Address());
    assertEquals(".", runner.getTempDir());

    /*
     * ------------------------------------------------------------
     * Let's unregister the runner from the registry and check
     * ------------------------------------------------------------
     */
    result =
        testParams
            .newWebResource(null)
            .queryParam(RestParams.RUNNER_URL, runner.getUrl())
            .path("/unregister")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Boolean.class);

    assertTrue(result);

    /*
     * ------------------------------------------------------------
     * Let's make sure we do NOT get the runner from the registry
     * ------------------------------------------------------------
     */
    runnerList.clear();
    runnerList =
        testParams
            .setEndpoint(RunnerRegistryResource.ENDPOINT)
            .newWebResource(null)
            .queryParam(RestParams.COMMIT_ID, commitId)
            .path("/list")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .get(new GenericType<List<Runner>>() {});

    assertNotNull(runnerList);
    assertEquals(0, runnerList.size());
  }