Java Code Examples for org.springframework.test.context.jdbc.Sql

The following examples show how to use org.springframework.test.context.jdbc.Sql. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: apollo   Source File: ConfigControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-gray-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicGrayConfigWithNoOverride() throws Exception {
  AtomicBoolean stop = new AtomicBoolean();
  periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
      stop);

  TimeUnit.MILLISECONDS.sleep(500);

  stop.set(true);

  ResponseEntity<ApolloConfig> response = restTemplate
      .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?ip={clientIp}", ApolloConfig.class,
          getHostUrl(), someAppId, someCluster, somePublicNamespace, someClientIp);
  ApolloConfig result = response.getBody();

  assertEquals(HttpStatus.OK, response.getStatusCode());
  assertEquals("TEST-GRAY-RELEASE-KEY2", result.getReleaseKey());
  assertEquals("gray-v1", result.getConfigurations().get("k1"));
  assertEquals("gray-v2", result.getConfigurations().get("k2"));
}
 
Example 2
Source Project: elide-spring-boot   Source File: GraphQLTest.java    License: Apache License 2.0 6 votes vote down vote up
@Sql(statements = {
    "insert into account(id, username, password) values (233, 'alice', '123')",
    "delete from book",
    "insert into book(id, unique_number) values (666, 1)"
})
@Test
public void testReadByArray() throws Exception {
  String accountQuery = toJsonQuery("query { account { edges { node { id username password } } } }", null);
  String bookQuery = toJsonQuery("query { book { edges { node { id uniqueNumber } } } }", null);

  mockMvc.perform(post("/api/graphql")
      .contentType(MediaType.APPLICATION_JSON)
      .accept(MediaType.APPLICATION_JSON)
      .content("[" + accountQuery + "," + bookQuery + "]"))
      .andDo(print())
      .andExpect(status().isOk())
      .andExpect(jsonPath("$.length()").value(2))
      .andExpect(jsonPath("$[0].data.account.edges[0].node.id").value("233"))
      .andExpect(jsonPath("$[1].data.book.edges[0].node.id").value("666"))
      .andExpect(jsonPath("$[1].data.book.edges[0].node.uniqueNumber").value(1));
}
 
Example 3
@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-message.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithPublicNamespaceWithNotificationIdOutDated() throws Exception {
  long someOutDatedNotificationId = 1;
  ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
      "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}",
      ApolloConfigNotification.class,
      getHostUrl(), someAppId, someCluster, somePublicNamespace, someOutDatedNotificationId);

  ApolloConfigNotification notification = result.getBody();
  assertEquals(HttpStatus.OK, result.getStatusCode());
  assertEquals(somePublicNamespace, notification.getNamespaceName());
  assertEquals(20, notification.getNotificationId());
}
 
Example 4
@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespace() throws Exception {
  AtomicBoolean stop = new AtomicBoolean();
  String key = assembleKey(someAppId, someCluster, defaultNamespace);
  periodicSendMessage(executorService, key, stop);

  ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
      "http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}",
      HttpMethod.GET, null, typeReference,
      getHostUrl(), someAppId, someCluster,
      transformApolloConfigNotificationsToString(defaultNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));

  stop.set(true);

  List<ApolloConfigNotification> notifications = result.getBody();
  assertEquals(HttpStatus.OK, result.getStatusCode());
  assertEquals(1, notifications.size());
  assertEquals(defaultNamespace, notifications.get(0).getNamespaceName());
  assertNotEquals(0, notifications.get(0).getNotificationId());

  ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
  assertEquals(1, messages.getDetails().size());
  assertTrue(messages.has(key));
  assertNotEquals(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, messages.get(key).longValue());
}
 
Example 5
Source Project: apollo   Source File: ConfigControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-dc-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigWithDataCenterFoundAndOverride() throws Exception {
  ResponseEntity<ApolloConfig> response = restTemplate
      .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
          ApolloConfig.class,
          getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);
  ApolloConfig result = response.getBody();

  assertEquals(
      "TEST-RELEASE-KEY6" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY4",
      result.getReleaseKey());
  assertEquals(someAppId, result.getAppId());
  assertEquals(someDC, result.getCluster());
  assertEquals(somePublicNamespace, result.getNamespaceName());
  assertEquals("override-someDC-v1", result.getConfigurations().get("k1"));
  assertEquals("someDC-v2", result.getConfigurations().get("k2"));
}
 
Example 6
@Test
@Sql(statements = "create schema if not exists test")
@Sql(scripts = {
        "/db/migration/V0001_1__create_person_table.sql",
        "/db/migration/V0002_1__rename_surname_column.sql"
})
public void loadDefaultMigrations() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    assertThat(persons).isNotNull().hasSize(1);

    Map<String, Object> person = persons.get(0);
    assertThat(person).containsExactly(
            entry("id", 1L),
            entry("first_name", "Dave"),
            entry("last_name", "Syer"));
}
 
Example 7
@Test
@Sql(statements = "create schema if not exists test")
@Sql(scripts = {
        "/db/migration/V0001_1__create_person_table.sql",
        "/db/test_migration/dependent/V0001_2__add_full_name_column.sql",
        "/db/migration/V0002_1__rename_surname_column.sql"
})
public void loadDependentTestMigrations() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    assertThat(persons).isNotNull().hasSize(1);

    Map<String, Object> person = persons.get(0);
    assertThat(person).containsExactly(
            entry("id", 1L),
            entry("first_name", "Dave"),
            entry("last_name", "Syer"),
            entry("full_name", "Dave Syer"));
}
 
Example 8
@Test
@Sql(statements = "create schema if not exists test")
@Sql(scripts = {
        "/db/test_migration/separated/V1000_1__create_test_person_table.sql"
})
public void loadIndependentTestMigrations() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    assertThat(persons).isNotNull().hasSize(1);

    Map<String, Object> person = persons.get(0);
    assertThat(person).containsExactly(
            entry("id", 1L),
            entry("first_name", "Tom"),
            entry("last_name", "Hanks"));
}
 
Example 9
Source Project: code-examples   Source File: CarResourceTest.java    License: MIT License 6 votes vote down vote up
@Test
@Sql("/insert_car.sql")
void updateCar() throws Exception {
    // given
    CarDto carDto = CarDto.builder()
            .id(UUID.fromString("1b104b1a-8539-4e06-aea7-9d77f2193b80"))
            .name("vw")
            .color("white")
            .build();

    // when
    mockMvc.perform(
            put("/cars")
                    .content(objectMapper.writeValueAsString(carDto))
                    .contentType(MediaType.APPLICATION_JSON)
    )
            // then
            .andExpect(status().isOk());
}
 
Example 10
@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithPrivateNamespaceAsFile() throws Exception {
  String namespace = "someNamespace.xml";
  AtomicBoolean stop = new AtomicBoolean();
  periodicSendMessage(executorService, assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace), stop);

  ResponseEntity<ApolloConfigNotification> result = restTemplate
      .getForEntity(
          "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
          ApolloConfigNotification.class,
          getHostUrl(), someAppId, someCluster, namespace);

  stop.set(true);

  ApolloConfigNotification notification = result.getBody();
  assertEquals(HttpStatus.OK, result.getStatusCode());
  assertEquals(namespace, notification.getNamespaceName());
  assertNotEquals(0, notification.getNotificationId());
}
 
Example 11
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-dc-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigAsJson() throws Exception {
  ResponseEntity<String> response =
      restTemplate
          .getForEntity(
              "http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
              String.class,
              getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);

  Map<String, String> configs = gson.fromJson(response.getBody(), mapResponseType);

  assertEquals(HttpStatus.OK, response.getStatusCode());
  assertEquals("override-someDC-v1", configs.get("k1"));
  assertEquals("someDC-v2", configs.get("k2"));
}
 
Example 12
Source Project: apollo   Source File: ConfigControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-dc-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigWithIncorrectCaseAndDataCenterFoundAndOverride() throws Exception {
  ResponseEntity<ApolloConfig> response = restTemplate
      .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
          ApolloConfig.class,
          getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), someDC);
  ApolloConfig result = response.getBody();

  assertEquals(
      "TEST-RELEASE-KEY6" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY4",
      result.getReleaseKey());
  assertEquals("override-someDC-v1", result.getConfigurations().get("k1"));
  assertEquals("someDC-v2", result.getConfigurations().get("k2"));
}
 
Example 13
@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespace() throws Exception {
  AtomicBoolean stop = new AtomicBoolean();
  periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop);

  ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
      "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
      ApolloConfigNotification.class,
      getHostUrl(), someAppId, someCluster, defaultNamespace);

  stop.set(true);

  ApolloConfigNotification notification = result.getBody();
  assertEquals(HttpStatus.OK, result.getStatusCode());
  assertEquals(defaultNamespace, notification.getNamespaceName());
  assertNotEquals(0, notification.getNotificationId());
}
 
Example 14
@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWthPublicNamespaceAndDataCenter() throws Exception {
  String publicAppId = "somePublicAppId";
  String someDC = "someDC";

  AtomicBoolean stop = new AtomicBoolean();
  periodicSendMessage(executorService, assembleKey(publicAppId, someDC, somePublicNamespace), stop);

  ResponseEntity<ApolloConfigNotification> result = restTemplate
      .getForEntity(
          "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
          ApolloConfigNotification.class,
          getHostUrl(), someAppId, someCluster, somePublicNamespace, someDC);

  stop.set(true);

  ApolloConfigNotification notification = result.getBody();
  assertEquals(HttpStatus.OK, result.getStatusCode());
  assertEquals(somePublicNamespace, notification.getNamespaceName());
  assertNotEquals(0, notification.getNotificationId());
}
 
Example 15
Source Project: apollo   Source File: AppControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 16
Source Project: apollo   Source File: RolePermissionServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/sql/permission/insert-test-permissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateRoleWithPermissions() throws Exception {
  String someRoleName = "someRoleName";
  Role role = assembleRole(someRoleName);

  Set<Long> permissionIds = Sets.newHashSet(990L, 991L);

  Role created = rolePermissionService.createRoleWithPermissions(role, permissionIds);

  Role createdFromDB = roleRepository.findById(created.getId()).orElse(null);
  List<RolePermission> rolePermissions =
      rolePermissionRepository.findByRoleIdIn(Sets.newHashSet(createdFromDB.getId()));

  Set<Long> rolePermissionIds = rolePermissions.stream().map(RolePermission::getPermissionId).collect(Collectors.toSet());

  assertEquals(someRoleName, createdFromDB.getRoleName());
  assertEquals(2, rolePermissionIds.size());
  assertTrue(rolePermissionIds.containsAll(permissionIds));
}
 
Example 17
Source Project: apollo   Source File: RolePermissionServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/sql/permission/insert-test-roles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testAssignRoleToUsers() throws Exception {
  String someRoleName = "someRoleName";
  String someUser = "someUser";
  String anotherUser = "anotherUser";
  String operator = "operator";

  Set<String> users = Sets.newHashSet(someUser, anotherUser);

  rolePermissionService
      .assignRoleToUsers(someRoleName, users, operator);

  List<UserRole> userRoles = userRoleRepository.findByRoleId(990);

  Set<String> usersWithRole = Sets.newHashSet();
  for (UserRole userRole : userRoles) {
    assertEquals(operator, userRole.getDataChangeCreatedBy());
    assertEquals(operator, userRole.getDataChangeLastModifiedBy());
    usersWithRole.add(userRole.getUserId());
  }

  assertEquals(2, usersWithRole.size());
  assertTrue(usersWithRole.containsAll(users));
}
 
Example 18
Source Project: apollo   Source File: RolePermissionServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/sql/permission/insert-test-roles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/permission/insert-test-permissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/permission/insert-test-userroles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/permission/insert-test-rolepermissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testUserHasPermission() throws Exception {
  String someTargetId = "someTargetId";
  String anotherTargetId = "anotherTargetId";
  String somePermissionType = "somePermissionType";
  String anotherPermissionType = "anotherPermissionType";
  String someUser = "someUser";
  String anotherUser = "anotherUser";
  String someUserWithNoPermission = "someUserWithNoPermission";

  assertTrue(rolePermissionService.userHasPermission(someUser, somePermissionType, someTargetId));
  assertTrue(rolePermissionService.userHasPermission(someUser, anotherPermissionType, anotherTargetId));
  assertTrue(rolePermissionService.userHasPermission(anotherUser, somePermissionType, someTargetId));
  assertTrue(rolePermissionService.userHasPermission(anotherUser, anotherPermissionType, anotherTargetId));

  assertFalse(rolePermissionService.userHasPermission(someUserWithNoPermission, somePermissionType, someTargetId));
  assertFalse(rolePermissionService.userHasPermission(someUserWithNoPermission, anotherPermissionType, anotherTargetId));

}
 
Example 19
@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWthPublicNamespaceAsFile() throws Exception {
  String publicAppId = "somePublicAppId";
  String someDC = "someDC";

  AtomicBoolean stop = new AtomicBoolean();
  periodicSendMessage(executorService, assembleKey(publicAppId, someDC, somePublicNamespace), stop);

  ResponseEntity<ApolloConfigNotification> result = restTemplate
      .getForEntity(
          "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
          ApolloConfigNotification.class,
          getHostUrl(), someAppId, someCluster, somePublicNamespace + ".properties", someDC);

  stop.set(true);

  ApolloConfigNotification notification = result.getBody();
  assertEquals(HttpStatus.OK, result.getStatusCode());
  assertEquals(somePublicNamespace, notification.getNamespaceName());
  assertNotEquals(0, notification.getNotificationId());
}
 
Example 20
Source Project: apollo   Source File: ConfigControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigWithDataCenterFoundAndNoOverride() throws Exception {
  ResponseEntity<ApolloConfig> response = restTemplate
      .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
          ApolloConfig.class,
          getHostUrl(), someAppId, someCluster, somePublicNamespace, someDC);
  ApolloConfig result = response.getBody();

  assertEquals("TEST-RELEASE-KEY4", result.getReleaseKey());
  assertEquals(someAppId, result.getAppId());
  assertEquals(someCluster, result.getCluster());
  assertEquals(somePublicNamespace, result.getNamespaceName());
  assertEquals("someDC-v1", result.getConfigurations().get("k1"));
  assertEquals("someDC-v2", result.getConfigurations().get("k2"));
}
 
Example 21
Source Project: apollo   Source File: ConfigControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigForNoAppIdPlaceHolder() throws Exception {
  ResponseEntity<ApolloConfig> response = restTemplate
      .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
          ApolloConfig.class,
          getHostUrl(), ConfigConsts.NO_APPID_PLACEHOLDER, someCluster, somePublicNamespace, someDC);
  ApolloConfig result = response.getBody();

  assertEquals("TEST-RELEASE-KEY4", result.getReleaseKey());
  assertEquals(ConfigConsts.NO_APPID_PLACEHOLDER, result.getAppId());
  assertEquals(someCluster, result.getCluster());
  assertEquals(somePublicNamespace, result.getNamespaceName());
  assertEquals("someDC-v1", result.getConfigurations().get("k1"));
  assertEquals("someDC-v2", result.getConfigurations().get("k2"));
}
 
Example 22
Source Project: apollo   Source File: ConsumerRolePermissionServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/sql/permission/insert-test-roles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/permission/insert-test-permissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/permission/insert-test-consumerroles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/permission/insert-test-rolepermissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testConsumerHasPermission() throws Exception {
  String someTargetId = "someTargetId";
  String anotherTargetId = "anotherTargetId";
  String somePermissionType = "somePermissionType";
  String anotherPermissionType = "anotherPermissionType";
  long someConsumerId = 1;
  long anotherConsumerId = 2;
  long someConsumerWithNoPermission = 3;

  assertTrue(consumerRolePermissionService.consumerHasPermission(someConsumerId, somePermissionType, someTargetId));
  assertTrue(consumerRolePermissionService.consumerHasPermission(someConsumerId, anotherPermissionType, anotherTargetId));
  assertTrue(consumerRolePermissionService.consumerHasPermission(anotherConsumerId, somePermissionType, someTargetId));
  assertTrue(consumerRolePermissionService.consumerHasPermission(anotherConsumerId, anotherPermissionType, anotherTargetId));

  assertFalse(consumerRolePermissionService.consumerHasPermission(someConsumerWithNoPermission, somePermissionType, someTargetId));
  assertFalse(consumerRolePermissionService.consumerHasPermission(someConsumerWithNoPermission, anotherPermissionType, anotherTargetId));

}
 
Example 23
Source Project: apollo   Source File: ConfigControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPrivateConfigFileWithPublicNamespaceExists() throws Exception {
  String namespaceName = "anotherNamespace";
  ResponseEntity<ApolloConfig> response = restTemplate
      .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}",
          ApolloConfig.class,
          getHostUrl(), someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName);
  ApolloConfig result = response.getBody();

  assertEquals("TEST-RELEASE-KEY6", result.getReleaseKey());
  assertEquals(someAppId, result.getAppId());
  assertEquals(ConfigConsts.CLUSTER_NAME_DEFAULT, result.getCluster());
  assertEquals(namespaceName, result.getNamespaceName());
  assertEquals("v1-file", result.getConfigurations().get("k1"));
  assertEquals(null, result.getConfigurations().get("k2"));
}
 
Example 24
Source Project: apollo   Source File: ControllerIntegrationExceptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateFailed() {
  AppDTO dto = generateSampleDTOData();

  when(adminService.createNewApp(any(App.class))).thenThrow(new RuntimeException("save failed"));

  try {
    restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
  } catch (HttpStatusCodeException e) {
    @SuppressWarnings("unchecked")
    Map<String, String> attr = gson.fromJson(e.getResponseBodyAsString(), Map.class);
    Assert.assertEquals("save failed", attr.get("message"));
  }
  App savedApp = appService.findOne(dto.getAppId());
  Assert.assertNull(savedApp);
}
 
Example 25
Source Project: apollo   Source File: AppNamespaceServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = BadRequestException.class)
@Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreatePublicAppNamespaceExisted() {
  AppNamespace appNamespace = assembleBaseAppNamespace();
  appNamespace.setPublic(true);
  appNamespace.setName("old");
  appNamespace.setFormat(ConfigFileFormat.Properties.getValue());

  appNamespaceService.createAppNamespaceInLocal(appNamespace);
}
 
Example 26
/**
 * Overriding {@code @Sql} declaration to reference scripts using relative path.
 */
@Test
@Sql({ "../../jdbc/drop-schema.sql", "../../jdbc/schema.sql", "../../jdbc/data.sql", "../../jdbc/data-add-dogbert.sql" })
@Override
// test##_ prefix is required for @FixMethodOrder.
public void test02_methodLevelScripts() {
	assertNumUsers(2);
}
 
Example 27
Source Project: apollo   Source File: AppControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testCreate() {
  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);

  App savedApp = appRepository.findById(result.getId()).orElse(null);
  Assert.assertEquals(dto.getAppId(), savedApp.getAppId());
  Assert.assertNotNull(savedApp.getDataChangeCreatedTime());
}
 
Example 28
Source Project: java-technology-stack   Source File: SqlConfigInterfaceTests.java    License: MIT License 5 votes vote down vote up
@Test
@Sql(scripts = "/org/springframework/test/context/jdbc/schema.sql", //
		config = @SqlConfig(separator = ";"))
@Sql("/org/springframework/test/context/jdbc/data-add-users-with-custom-script-syntax.sql")
public void methodLevelScripts() {
	assertNumUsers(3);
}
 
Example 29
Source Project: apollo   Source File: AppControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 30
Source Project: apollo   Source File: AppNamespaceServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = BadRequestException.class)
@Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreatePrivateAppNamespaceExistedInAnotherAppIdAsPublic() {
  AppNamespace appNamespace = assembleBaseAppNamespace();
  appNamespace.setPublic(false);
  appNamespace.setName("SCC.song0711-03");
  appNamespace.setAppId("100003173");
  appNamespace.setFormat(ConfigFileFormat.Properties.getValue());

  appNamespaceService.createAppNamespaceInLocal(appNamespace);
}