Search in sources :

Example 1 with Sql

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

the class AppControllerTest method testDelete.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testDelete() {
    AppDTO dto = generateSampleDTOData();
    App app = BeanUtils.transfrom(App.class, dto);
    app = appRepository.save(app);
    restTemplate.delete("http://localhost:{port}/apps/{appId}?operator={operator}", port, app.getAppId(), "test");
    App deletedApp = appRepository.findOne(app.getId());
    Assert.assertNull(deletedApp);
}
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)

Example 2 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 3 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.findOne(first.getId());
    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 4 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.transfrom(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)

Example 5 with Sql

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

the class NamespaceBranchServiceTest method testUpdateBranchGrayRulesWithUpdateTwice.

@Test
@Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testUpdateBranchGrayRulesWithUpdateTwice() {
    GrayReleaseRule firstRule = instanceGrayReleaseRule();
    namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, firstRule);
    GrayReleaseRule secondRule = instanceGrayReleaseRule();
    secondRule.setRules("[{\"clientAppId\":\"branch-test\",\"clientIpList\":[\"10.38.57.112\"]}]");
    namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, secondRule);
    GrayReleaseRule activeRule = namespaceBranchService.findBranchGrayRules(testApp, testCluster, testNamespace, testBranchName);
    Assert.assertNotNull(secondRule);
    Assert.assertEquals(secondRule.getAppId(), activeRule.getAppId());
    Assert.assertEquals(secondRule.getRules(), activeRule.getRules());
    Assert.assertEquals(Long.valueOf(0), activeRule.getReleaseId());
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, testCluster, testNamespace, pageable);
    ReleaseHistory firstReleaseHistory = releaseHistories.getContent().get(1);
    ReleaseHistory secondReleaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(2, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.APPLY_GRAY_RULES, firstReleaseHistory.getOperation());
    Assert.assertEquals(ReleaseOperation.APPLY_GRAY_RULES, secondReleaseHistory.getOperation());
    Assert.assertTrue(firstReleaseHistory.getOperationContext().contains(firstRule.getRules()));
    Assert.assertFalse(firstReleaseHistory.getOperationContext().contains(secondRule.getRules()));
    Assert.assertTrue(secondReleaseHistory.getOperationContext().contains(firstRule.getRules()));
    Assert.assertTrue(secondReleaseHistory.getOperationContext().contains(secondRule.getRules()));
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

Sql (org.springframework.test.context.jdbc.Sql)102 Test (org.junit.Test)91 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)26 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)23 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)19 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)14 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 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Release (com.ctrip.framework.apollo.biz.entity.Release)8 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)7 Favorite (com.ctrip.framework.apollo.portal.entity.po.Favorite)6 CustomerData (io.codekvast.common.customer.CustomerData)6 PageRequest (org.springframework.data.domain.PageRequest)6 App (com.ctrip.framework.apollo.common.entity.App)5