Search in sources :

Example 21 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class ReleaseControllerTest method testReleaseBuild.

@Test
@Sql(scripts = "/controller/test-release.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testReleaseBuild() {
    String appId = "someAppId";
    AppDTO app = restTemplate.getForObject("http://localhost:" + port + "/apps/" + appId, AppDTO.class);
    ClusterDTO cluster = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/default", ClusterDTO.class);
    NamespaceDTO namespace = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/application", NamespaceDTO.class);
    Assert.assertEquals("someAppId", app.getAppId());
    Assert.assertEquals("default", cluster.getName());
    Assert.assertEquals("application", namespace.getNamespaceName());
    ItemDTO[] items = restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/items", ItemDTO[].class);
    Assert.assertEquals(3, items.length);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.add("name", "someReleaseName");
    parameters.add("comment", "someComment");
    parameters.add("operator", "test");
    HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(parameters, headers);
    ResponseEntity<ReleaseDTO> response = restTemplate.postForEntity("http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/releases", entity, ReleaseDTO.class);
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    ReleaseDTO release = response.getBody();
    Assert.assertEquals("someReleaseName", release.getName());
    Assert.assertEquals("someComment", release.getComment());
    Assert.assertEquals("someAppId", release.getAppId());
    Assert.assertEquals("default", release.getClusterName());
    Assert.assertEquals("application", release.getNamespaceName());
    Map<String, String> configurations = new HashMap<>();
    configurations.put("k1", "v1");
    configurations.put("k2", "v2");
    configurations.put("k3", "v3");
    Assert.assertEquals(GSON.toJson(configurations), release.getConfigurations());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) HashMap(java.util.HashMap) ClusterDTO(com.ctrip.framework.apollo.common.dto.ClusterDTO) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) AppDTO(com.ctrip.framework.apollo.common.dto.AppDTO) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 22 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class ConfigsExportServiceTest method genItem.

private ItemBO genItem(String key, String value) {
    ItemBO itemBO = new ItemBO();
    ItemDTO itemDTO = new ItemDTO();
    itemDTO.setKey(key);
    itemDTO.setValue(value);
    itemBO.setItem(itemDTO);
    return itemBO;
}
Also used : ItemBO(com.ctrip.framework.apollo.portal.entity.bo.ItemBO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Example 23 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class NamespaceBOUtils method convertNonProperties2configFileContent.

/**
 * namespace must not be {@link ConfigFileFormat#Properties}. the content of namespace in item's value which item's
 * key is {@link ConfigConsts#CONFIG_FILE_CONTENT_KEY}.
 *
 * @param namespaceBO namespace
 * @return content of non-properties's namespace
 */
static String convertNonProperties2configFileContent(NamespaceBO namespaceBO) {
    List<ItemBO> itemBOS = namespaceBO.getItems();
    for (ItemBO itemBO : itemBOS) {
        String key = itemBO.getItem().getKey();
        // special namespace format(not properties)
        if (ConfigConsts.CONFIG_FILE_CONTENT_KEY.equals(key)) {
            ItemDTO dto = itemBO.getItem();
            dto.setId(0);
            dto.setNamespaceId(0);
            return GSON.toJson(Lists.newArrayList(dto));
        }
    }
    return "";
}
Also used : ItemBO(com.ctrip.framework.apollo.portal.entity.bo.ItemBO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Example 24 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class PropertyResolverTest method mockBaseItemHas3Key.

/**
 * a=b b=c c=d
 */
private List<ItemDTO> mockBaseItemHas3Key() {
    ItemDTO item1 = new ItemDTO("a", "b", "", 1);
    ItemDTO item2 = new ItemDTO("b", "c", "", 2);
    ItemDTO item3 = new ItemDTO("c", "d", "", 3);
    return Arrays.asList(item1, item2, item3);
}
Also used : ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Example 25 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class PropertyResolverTest method mockBaseItemWith2Key1Comment1Blank.

/**
 * #qqqq
 * a=b
 *
 * b=c
 */
private List<ItemDTO> mockBaseItemWith2Key1Comment1Blank() {
    ItemDTO i1 = new ItemDTO("", "", "#qqqq", 1);
    ItemDTO i2 = new ItemDTO("a", "b", "", 2);
    ItemDTO i3 = new ItemDTO("", "", "", 3);
    ItemDTO i4 = new ItemDTO("b", "c", "", 4);
    i4.setLineNum(4);
    return Arrays.asList(i1, i2, i3, i4);
}
Also used : ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Aggregations

ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)44 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)14 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)12 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)11 Test (org.junit.Test)11 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Item (com.ctrip.framework.apollo.biz.entity.Item)6 OpenItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenItemDTO)6 HashMap (java.util.HashMap)6 ItemBO (com.ctrip.framework.apollo.portal.entity.bo.ItemBO)5 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)4 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)4 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Sql (org.springframework.test.context.jdbc.Sql)4 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)3 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)3 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)3 RestTemplate (org.springframework.web.client.RestTemplate)3