Search in sources :

Example 1 with ServiceSpecificationCodec

use of co.cask.cdap.internal.app.ServiceSpecificationCodec in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testServiceSpecification.

@Test
public void testServiceSpecification() throws Exception {
    deploy(AppWithServices.class);
    HttpResponse response = doGet("/v3/namespaces/default/apps/AppWithServices/services/NoOpService");
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Set<ServiceHttpEndpoint> expectedEndpoints = ImmutableSet.of(new ServiceHttpEndpoint("GET", "/ping"), new ServiceHttpEndpoint("POST", "/multi"), new ServiceHttpEndpoint("GET", "/multi"), new ServiceHttpEndpoint("GET", "/multi/ping"));
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(ServiceSpecification.class, new ServiceSpecificationCodec());
    Gson gson = gsonBuilder.create();
    ServiceSpecification specification = readResponse(response, ServiceSpecification.class, gson);
    Set<ServiceHttpEndpoint> returnedEndpoints = new HashSet<>();
    for (HttpServiceHandlerSpecification httpServiceHandlerSpecification : specification.getHandlers().values()) {
        returnedEndpoints.addAll(httpServiceHandlerSpecification.getEndpoints());
    }
    Assert.assertEquals("NoOpService", specification.getName());
    Assert.assertTrue(returnedEndpoints.equals(expectedEndpoints));
}
Also used : ServiceHttpEndpoint(co.cask.cdap.api.service.http.ServiceHttpEndpoint) ServiceSpecificationCodec(co.cask.cdap.internal.app.ServiceSpecificationCodec) ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) GsonBuilder(com.google.gson.GsonBuilder) HttpResponse(org.apache.http.HttpResponse) Gson(com.google.gson.Gson) HttpServiceHandlerSpecification(co.cask.cdap.api.service.http.HttpServiceHandlerSpecification) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)1 HttpServiceHandlerSpecification (co.cask.cdap.api.service.http.HttpServiceHandlerSpecification)1 ServiceHttpEndpoint (co.cask.cdap.api.service.http.ServiceHttpEndpoint)1 ServiceSpecificationCodec (co.cask.cdap.internal.app.ServiceSpecificationCodec)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 HashSet (java.util.HashSet)1 HttpResponse (org.apache.http.HttpResponse)1 Test (org.junit.Test)1