Search in sources :

Example 1 with App

use of com.ctrip.framework.apollo.common.entity.App 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 App

use of com.ctrip.framework.apollo.common.entity.App 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 3 with App

use of com.ctrip.framework.apollo.common.entity.App 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 4 with App

use of com.ctrip.framework.apollo.common.entity.App in project apollo by ctripcorp.

the class AppController method delete.

@RequestMapping(value = "/apps/{appId:.+}", method = RequestMethod.DELETE)
public void delete(@PathVariable("appId") String appId, @RequestParam String operator) {
    App entity = appService.findOne(appId);
    if (entity == null) {
        throw new NotFoundException("app not found for appId " + appId);
    }
    appService.delete(entity.getId(), operator);
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with App

use of com.ctrip.framework.apollo.common.entity.App in project apollo by ctripcorp.

the class AdminServiceTest method testCreateNewApp.

@Test
public void testCreateNewApp() {
    String appId = "someAppId";
    App app = new App();
    app.setAppId(appId);
    app.setName("someAppName");
    String owner = "someOwnerName";
    app.setOwnerName(owner);
    app.setOwnerEmail("someOwnerName@ctrip.com");
    app.setDataChangeCreatedBy(owner);
    app.setDataChangeLastModifiedBy(owner);
    app.setDataChangeCreatedTime(new Date());
    app = adminService.createNewApp(app);
    Assert.assertEquals(appId, app.getAppId());
    List<Cluster> clusters = clusterService.findParentClusters(app.getAppId());
    Assert.assertEquals(1, clusters.size());
    Assert.assertEquals(ConfigConsts.CLUSTER_NAME_DEFAULT, clusters.get(0).getName());
    List<Namespace> namespaces = namespaceService.findNamespaces(appId, clusters.get(0).getName());
    Assert.assertEquals(1, namespaces.size());
    Assert.assertEquals(ConfigConsts.NAMESPACE_APPLICATION, namespaces.get(0).getNamespaceName());
    List<Audit> audits = auditService.findByOwner(owner);
    Assert.assertEquals(4, audits.size());
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) Audit(com.ctrip.framework.apollo.biz.entity.Audit) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Date(java.util.Date) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest)

Aggregations

App (com.ctrip.framework.apollo.common.entity.App)28 Test (org.junit.Test)13 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)8 Transactional (org.springframework.transaction.annotation.Transactional)8 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)6 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)6 Sql (org.springframework.test.context.jdbc.Sql)5 Date (java.util.Date)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)2 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)2 Audit (com.ctrip.framework.apollo.biz.entity.Audit)1 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)1 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)1 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)1 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)1 ConfigConsts (com.ctrip.framework.apollo.core.ConfigConsts)1 PermissionType (com.ctrip.framework.apollo.portal.constant.PermissionType)1 RoleType (com.ctrip.framework.apollo.portal.constant.RoleType)1 Permission (com.ctrip.framework.apollo.portal.entity.po.Permission)1