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