Search in sources :

Example 31 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class AppControllerTest method testCreateTwice.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateTwice() {
    AppDTO dto = generateSampleDTOData();
    ResponseEntity<AppDTO> response = restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
    AppDTO first = response.getBody();
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    Assert.assertEquals(dto.getAppId(), first.getAppId());
    Assert.assertTrue(first.getId() > 0);
    App savedApp = appRepository.findById(first.getId()).orElse(null);
    Assert.assertEquals(dto.getAppId(), savedApp.getAppId());
    Assert.assertNotNull(savedApp.getDataChangeCreatedTime());
    try {
        restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
    } catch (HttpClientErrorException e) {
        Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
    }
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) AppDTO(com.ctrip.framework.apollo.common.dto.AppDTO) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 32 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class AppControllerTest method shouldFailedWhenAppIdIsInvalid.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void shouldFailedWhenAppIdIsInvalid() {
    AppDTO dto = generateSampleDTOData();
    dto.setAppId("invalid app id");
    try {
        restTemplate.postForEntity(getBaseAppUrl(), dto, String.class);
        Assert.fail("Should throw");
    } catch (HttpClientErrorException e) {
        Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
        Assert.assertThat(new String(e.getResponseBodyAsByteArray()), containsString(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) AppDTO(com.ctrip.framework.apollo.common.dto.AppDTO) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 33 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class AppControllerTest method testCheckIfAppIdUnique.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testCheckIfAppIdUnique() {
    AppDTO dto = generateSampleDTOData();
    ResponseEntity<AppDTO> response = restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
    AppDTO result = response.getBody();
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    Assert.assertEquals(dto.getAppId(), result.getAppId());
    Assert.assertTrue(result.getId() > 0);
    Boolean falseUnique = restTemplate.getForObject(getBaseAppUrl() + dto.getAppId() + "/unique", Boolean.class);
    Assert.assertFalse(falseUnique);
    Boolean trueUnique = restTemplate.getForObject(getBaseAppUrl() + dto.getAppId() + "true" + "/unique", Boolean.class);
    Assert.assertTrue(trueUnique);
}
Also used : AppDTO(com.ctrip.framework.apollo.common.dto.AppDTO) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 34 with Sql

use of org.springframework.test.context.jdbc.Sql 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 35 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class AppControllerTest method testFind.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testFind() {
    AppDTO dto = generateSampleDTOData();
    App app = BeanUtils.transform(App.class, dto);
    app = appRepository.save(app);
    AppDTO result = restTemplate.getForObject(getBaseAppUrl() + dto.getAppId(), AppDTO.class);
    Assert.assertEquals(dto.getAppId(), result.getAppId());
    Assert.assertEquals(dto.getName(), result.getName());
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) AppDTO(com.ctrip.framework.apollo.common.dto.AppDTO) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

Sql (org.springframework.test.context.jdbc.Sql)122 Test (org.junit.Test)111 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)26 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)26 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)23 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)17 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)17 ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)17 List (java.util.List)17 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)16 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)13 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)11 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)10 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Release (com.ctrip.framework.apollo.biz.entity.Release)8 AbstractControllerTest (com.ctrip.framework.apollo.adminservice.controller.AbstractControllerTest)6 Favorite (com.ctrip.framework.apollo.portal.entity.po.Favorite)6 CustomerData (io.codekvast.common.customer.CustomerData)6 HttpHeaders (org.springframework.http.HttpHeaders)6