示例#1
0
  public void testRESTRegservice() throws Exception {
    assertNotNull(restRegService);
    assertNotNull(binder);
    assertNotNull(handler);

    // List<ResourceClass> list = binder.getRootResources();
    // assertEquals(1, list.size());
    // assertEquals(3, list.get(0).getResourceMethods().size());

    repositoryService.setCurrentRepositoryName("db1");
    DummyContainerResponseWriter wr = new DummyContainerResponseWriter();
    URI reqUri = new URI(baseUri.toString() + "/registry/");

    ContainerResponse cres =
        request(
            handler,
            wr,
            "GET",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(200, cres.getStatus());

    // request to exo:services/exo_service
    // response status should be 404 (NOT_FOUND)
    wr.reset();
    reqUri =
        new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/exo_service");
    cres =
        request(
            handler,
            wr,
            "GET",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(404, cres.getStatus());
    assertNull(wr.getBody());

    // create exo:services/exo_service
    wr.reset();
    reqUri = new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES);
    cres =
        request(
            handler,
            wr,
            "POST",
            reqUri,
            baseUri,
            SERVICE_XML.getBytes(),
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(201, cres.getStatus());
    assertEquals(new URI(reqUri + "/exo_service"), wr.getHeaders().getFirst(HttpHeaders.LOCATION));

    // request to exo:services/exo_service
    wr.reset();
    reqUri =
        new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/exo_service");
    cres =
        request(
            handler,
            wr,
            "GET",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(200, cres.getStatus());

    // recreate exo:services/exo_service
    wr.reset();
    reqUri = new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES);
    cres =
        request(
            handler,
            wr,
            "PUT",
            reqUri,
            baseUri,
            SERVICE_XML.getBytes(),
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(201, cres.getStatus());
    assertEquals(new URI(reqUri + "/exo_service"), wr.getHeaders().getFirst(HttpHeaders.LOCATION));

    // delete exo:services/exo_service
    wr.reset();
    reqUri =
        new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/exo_service");
    cres =
        request(
            handler,
            wr,
            "DELETE",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(204, cres.getStatus());

    // request to exo:services/exo_service
    // request status should be 404 (NOT_FOUND)
    wr.reset();
    reqUri =
        new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/exo_service");
    cres =
        request(
            handler,
            wr,
            "GET",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(404, cres.getStatus());
    assertNull(wr.getBody());
  }
示例#2
0
  public void testCreateGetEntry() throws Exception {
    DummyContainerResponseWriter wr = new DummyContainerResponseWriter();
    InputStream in = new RegistryEntry("test").getAsInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int rd = -1;
    while ((rd = in.read()) != -1) {
      out.write(rd);
    }
    byte[] data = out.toByteArray();

    repositoryService.setCurrentRepositoryName("db1");

    // check for exo:services/group/test
    // response status should be 404 (NOT_FOUND)
    URI reqUri =
        new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/group/test");
    ContainerResponse cres =
        request(
            handler,
            wr,
            "GET",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(404, cres.getStatus());
    assertNull(wr.getBody());
    // create exo:services/group/test
    wr.reset();
    reqUri = new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/group/");
    cres =
        request(
            handler,
            wr,
            "POST",
            reqUri,
            baseUri,
            data,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(201, cres.getStatus());
    assertEquals(new URI(reqUri + "test"), wr.getHeaders().getFirst(HttpHeaders.LOCATION));

    // check again for exo:services/group/test
    wr.reset();
    reqUri =
        new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/group/test");
    cres =
        request(
            handler,
            wr,
            "GET",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(200, cres.getStatus());

    // remove
    wr.reset();
    reqUri = new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/group/");
    cres =
        request(
            handler,
            wr,
            "DELETE",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(204, cres.getStatus());

    // check for exo:services/group/test
    // response status should be 404 (NOT_FOUND)
    wr.reset();
    reqUri =
        new URI(baseUri.toString() + "/registry/" + RegistryService.EXO_SERVICES + "/group/test");
    cres =
        request(
            handler,
            wr,
            "GET",
            reqUri,
            baseUri,
            null,
            new InputHeadersMap(new MultivaluedMapImpl()));
    assertEquals(404, cres.getStatus());
    assertNull(wr.getBody());
  }