Search in sources :

Example 1 with OpenClusterDTO

use of com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO in project apollo by ctripcorp.

the class ServerClusterOpenApiService method createCluster.

@Override
public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) {
    ClusterDTO toCreate = OpenApiBeanUtils.transformToClusterDTO(openClusterDTO);
    ClusterDTO createdClusterDTO = clusterService.createCluster(Env.valueOf(env), toCreate);
    return OpenApiBeanUtils.transformFromClusterDTO(createdClusterDTO);
}
Also used : OpenClusterDTO(com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO) ClusterDTO(com.ctrip.framework.apollo.common.dto.ClusterDTO)

Example 2 with OpenClusterDTO

use of com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO in project apollo by ctripcorp.

the class ClusterOpenApiServiceTest method testCreateClusterWithError.

@Test(expected = RuntimeException.class)
public void testCreateClusterWithError() throws Exception {
    String someCluster = "someCluster";
    String someCreatedBy = "someCreatedBy";
    OpenClusterDTO clusterDTO = new OpenClusterDTO();
    clusterDTO.setAppId(someAppId);
    clusterDTO.setName(someCluster);
    clusterDTO.setDataChangeCreatedBy(someCreatedBy);
    when(statusLine.getStatusCode()).thenReturn(400);
    clusterOpenApiService.createCluster(someEnv, clusterDTO);
}
Also used : OpenClusterDTO(com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO) Test(org.junit.Test)

Example 3 with OpenClusterDTO

use of com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO in project apollo by ctripcorp.

the class ClusterOpenApiServiceTest method testCreateCluster.

@Test
public void testCreateCluster() throws Exception {
    String someCluster = "someCluster";
    String someCreatedBy = "someCreatedBy";
    OpenClusterDTO clusterDTO = new OpenClusterDTO();
    clusterDTO.setAppId(someAppId);
    clusterDTO.setName(someCluster);
    clusterDTO.setDataChangeCreatedBy(someCreatedBy);
    final ArgumentCaptor<HttpPost> request = ArgumentCaptor.forClass(HttpPost.class);
    clusterOpenApiService.createCluster(someEnv, clusterDTO);
    verify(httpClient, times(1)).execute(request.capture());
    HttpPost post = request.getValue();
    assertEquals(String.format("%s/envs/%s/apps/%s/clusters", someBaseUrl, someEnv, someAppId), post.getURI().toString());
    StringEntity entity = (StringEntity) post.getEntity();
    assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
    assertEquals(gson.toJson(clusterDTO), EntityUtils.toString(entity));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) OpenClusterDTO(com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO) Test(org.junit.Test)

Aggregations

OpenClusterDTO (com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO)3 Test (org.junit.Test)2 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1