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;
}
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);
}
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());
}
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));
}
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());
}
Aggregations