Search in sources :

Example 6 with OpenItemDTO

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

the class OpenApiBeanUtils method transformFromNamespaceBO.

public static OpenNamespaceDTO transformFromNamespaceBO(NamespaceBO namespaceBO) {
    Preconditions.checkArgument(namespaceBO != null);
    OpenNamespaceDTO openNamespaceDTO = BeanUtils.transform(OpenNamespaceDTO.class, namespaceBO.getBaseInfo());
    // app namespace info
    openNamespaceDTO.setFormat(namespaceBO.getFormat());
    openNamespaceDTO.setComment(namespaceBO.getComment());
    openNamespaceDTO.setPublic(namespaceBO.isPublic());
    // items
    List<OpenItemDTO> items = new LinkedList<>();
    List<ItemBO> itemBOs = namespaceBO.getItems();
    if (!CollectionUtils.isEmpty(itemBOs)) {
        items.addAll(itemBOs.stream().map(itemBO -> transformFromItemDTO(itemBO.getItem())).collect(Collectors.toList()));
    }
    openNamespaceDTO.setItems(items);
    return openNamespaceDTO;
}
Also used : OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) ItemBO(com.ctrip.framework.apollo.portal.entity.bo.ItemBO) OpenNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO) LinkedList(java.util.LinkedList)

Example 7 with OpenItemDTO

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

the class ItemOpenApiServiceTest method testCreateOrUpdateItemWithError.

@Test(expected = RuntimeException.class)
public void testCreateOrUpdateItemWithError() throws Exception {
    String someKey = "someKey";
    String someValue = "someValue";
    String someCreatedBy = "someCreatedBy";
    OpenItemDTO itemDTO = new OpenItemDTO();
    itemDTO.setKey(someKey);
    itemDTO.setValue(someValue);
    itemDTO.setDataChangeCreatedBy(someCreatedBy);
    when(statusLine.getStatusCode()).thenReturn(400);
    itemOpenApiService.createOrUpdateItem(someAppId, someEnv, someCluster, someNamespace, itemDTO);
}
Also used : OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) Test(org.junit.Test)

Example 8 with OpenItemDTO

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

the class ItemOpenApiServiceTest method testUpdateItem.

@Test
public void testUpdateItem() throws Exception {
    String someKey = "someKey";
    String someValue = "someValue";
    String someModifiedBy = "someModifiedBy";
    OpenItemDTO itemDTO = new OpenItemDTO();
    itemDTO.setKey(someKey);
    itemDTO.setValue(someValue);
    itemDTO.setDataChangeLastModifiedBy(someModifiedBy);
    final ArgumentCaptor<HttpPut> request = ArgumentCaptor.forClass(HttpPut.class);
    itemOpenApiService.updateItem(someAppId, someEnv, someCluster, someNamespace, itemDTO);
    verify(httpClient, times(1)).execute(request.capture());
    HttpPut put = request.getValue();
    assertEquals(String.format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s", someBaseUrl, someEnv, someAppId, someCluster, someNamespace, someKey), put.getURI().toString());
}
Also used : OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 9 with OpenItemDTO

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

the class ItemOpenApiServiceTest method testCreateItem.

@Test
public void testCreateItem() throws Exception {
    String someKey = "someKey";
    String someValue = "someValue";
    String someCreatedBy = "someCreatedBy";
    OpenItemDTO itemDTO = new OpenItemDTO();
    itemDTO.setKey(someKey);
    itemDTO.setValue(someValue);
    itemDTO.setDataChangeCreatedBy(someCreatedBy);
    final ArgumentCaptor<HttpPost> request = ArgumentCaptor.forClass(HttpPost.class);
    itemOpenApiService.createItem(someAppId, someEnv, someCluster, someNamespace, itemDTO);
    verify(httpClient, times(1)).execute(request.capture());
    HttpPost post = request.getValue();
    assertEquals(String.format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s/items", someBaseUrl, someEnv, someAppId, someCluster, someNamespace), post.getURI().toString());
    StringEntity entity = (StringEntity) post.getEntity();
    assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
    assertEquals(gson.toJson(itemDTO), EntityUtils.toString(entity));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) Test(org.junit.Test)

Example 10 with OpenItemDTO

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

the class ItemOpenApiServiceTest method testCreateOrUpdateItem.

@Test
public void testCreateOrUpdateItem() throws Exception {
    String someKey = "someKey";
    String someValue = "someValue";
    String someCreatedBy = "someCreatedBy";
    OpenItemDTO itemDTO = new OpenItemDTO();
    itemDTO.setKey(someKey);
    itemDTO.setValue(someValue);
    itemDTO.setDataChangeCreatedBy(someCreatedBy);
    final ArgumentCaptor<HttpPut> request = ArgumentCaptor.forClass(HttpPut.class);
    itemOpenApiService.createOrUpdateItem(someAppId, someEnv, someCluster, someNamespace, itemDTO);
    verify(httpClient, times(1)).execute(request.capture());
    HttpPut put = request.getValue();
    assertEquals(String.format("%s/envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s?createIfNotExists=true", someBaseUrl, someEnv, someAppId, someCluster, someNamespace, someKey), put.getURI().toString());
}
Also used : OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

OpenItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenItemDTO)11 Test (org.junit.Test)6 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)2 HttpPut (org.apache.http.client.methods.HttpPut)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 OpenNamespaceDTO (com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO)1 ItemBO (com.ctrip.framework.apollo.portal.entity.bo.ItemBO)1 LinkedList (java.util.LinkedList)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1