Search in sources :

Example 1 with ServiceSpecificationCodec

use of io.cdap.cdap.internal.app.ServiceSpecificationCodec in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testServiceSpecification.

@Test
public void testServiceSpecification() throws Exception {
    deploy(AppWithServices.class, 200);
    HttpResponse response = doGet("/v3/namespaces/default/apps/AppWithServices/services/NoOpService");
    Assert.assertEquals(200, response.getResponseCode());
    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.assertEquals(returnedEndpoints, expectedEndpoints);
}
Also used : ServiceHttpEndpoint(io.cdap.cdap.api.service.http.ServiceHttpEndpoint) ServiceSpecificationCodec(io.cdap.cdap.internal.app.ServiceSpecificationCodec) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) GsonBuilder(com.google.gson.GsonBuilder) HttpResponse(io.cdap.common.http.HttpResponse) Gson(com.google.gson.Gson) HttpServiceHandlerSpecification(io.cdap.cdap.api.service.http.HttpServiceHandlerSpecification) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

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