当前位置: 首页>>代码示例>>Java>>正文


Java Sql类代码示例

本文整理汇总了Java中org.springframework.test.context.jdbc.Sql的典型用法代码示例。如果您正苦于以下问题:Java Sql类的具体用法?Java Sql怎么用?Java Sql使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Sql类属于org.springframework.test.context.jdbc包,在下文中一共展示了Sql类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testQueryPublicConfigWithDataCenterFoundAndOverride

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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("{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"));
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:21,代码来源:ConfigControllerIntegrationTest.java

示例2: testPollNotificationWthPublicNamespaceAndDataCenter

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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(
          "{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());
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:24,代码来源:NotificationControllerIntegrationTest.java

示例3: loadDefaultMigrations

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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() throws Exception {
    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"));
}
 
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:19,代码来源:EmptyDatabaseIntegrationTest.java

示例4: loadAppendableTestMigrations

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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",
        "/db/test_migration/appendable/V1000_1__create_test_data.sql"
})
public void loadAppendableTestMigrations() throws Exception {
    assertThat(dataSource).isNotNull();

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

    assertThat(persons).extracting("id", "first_name", "last_name").containsExactlyInAnyOrder(
            tuple(1L, "Dave", "Syer"),
            tuple(2L, "Tom", "Hanks"));
}
 
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:18,代码来源:EmptyDatabaseIntegrationTest.java

示例5: loadDependentTestMigrations

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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() throws Exception {
    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"));
}
 
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:21,代码来源:EmptyDatabaseIntegrationTest.java

示例6: loadIndependentTestMigrations

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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() throws Exception {
    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"));
}
 
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:18,代码来源:EmptyDatabaseIntegrationTest.java

示例7: testUpdateRulesReleaseIdWithOldRuleExist

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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 testUpdateRulesReleaseIdWithOldRuleExist() {

  GrayReleaseRule rule = instanceGrayReleaseRule();
  namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, rule);

  long latestReleaseId = 100;

  namespaceBranchService
      .updateRulesReleaseId(testApp, testCluster, testNamespace, testBranchName, latestReleaseId, operator);

  GrayReleaseRule
      activeRule =
      namespaceBranchService.findBranchGrayRules(testApp, testCluster, testNamespace, testBranchName);

  Assert.assertNotNull(activeRule);
  Assert.assertEquals(Long.valueOf(latestReleaseId), activeRule.getReleaseId());
  Assert.assertEquals(rule.getRules(), activeRule.getRules());
  Assert.assertEquals(NamespaceBranchStatus.ACTIVE, activeRule.getBranchStatus());
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:23,代码来源:NamespaceBranchServiceTest.java

示例8: testCreateRoleWithPermissions

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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.findOne(created.getId());
  List<RolePermission> rolePermissions =
      rolePermissionRepository.findByRoleIdIn(Sets.newHashSet(createdFromDB.getId()));

  Set<Long> rolePermissionIds =
      FluentIterable.from(rolePermissions)
          .transform(RolePermission::getPermissionId).toSet();

  assertEquals(someRoleName, createdFromDB.getRoleName());
  assertEquals(2, rolePermissionIds.size());
  assertTrue(rolePermissionIds.containsAll(permissionIds));
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:24,代码来源:RolePermissionServiceTest.java

示例9: testAssignRoleToUsers

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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));
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:27,代码来源:RolePermissionServiceTest.java

示例10: testRemoveRoleFromUsers

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@Test
@Sql(scripts = "/sql/permission/insert-test-roles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/permission/insert-test-userroles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testRemoveRoleFromUsers() throws Exception {
  String someRoleName = "someRoleName";
  String someUser = "someUser";
  String anotherUser = "anotherUser";
  String operator = "operator";

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

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

  rolePermissionService.removeRoleFromUsers(someRoleName, users, operator);

  List<UserRole> userRolesAfterRemoval = userRoleRepository.findByRoleId(990);
  assertTrue(userRolesAfterRemoval.isEmpty());
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:21,代码来源:RolePermissionServiceTest.java

示例11: testUserHasPermission

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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));

}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:25,代码来源:RolePermissionServiceTest.java

示例12: testAddNormalFavorite

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@Test
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testAddNormalFavorite() {
  String testApp = "testApp";
  Favorite favorite = instanceOfFavorite(testUser, testApp);
  favoriteService.addFavorite(favorite);

  List<Favorite> createdFavorites = favoriteService.search(testUser, testApp, new PageRequest(0, 10));

  Assert.assertEquals(1, createdFavorites.size());

  Assert.assertEquals(FavoriteService.POSITION_DEFAULT, createdFavorites.get(0).getPosition());
  Assert.assertEquals(testUser, createdFavorites.get(0).getUserId());
  Assert.assertEquals(testApp, createdFavorites.get(0).getAppId());

}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:17,代码来源:FavoriteServiceTest.java

示例13: testConsumerHasPermission

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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));

}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:25,代码来源:ConsumerRolePermissionServiceTest.java

示例14: testCreateFailed

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:ControllerIntegrationExceptionTest.java

示例15: testCheckIfAppIdUnique

import org.springframework.test.context.jdbc.Sql; //导入依赖的package包/类
@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);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:19,代码来源:AppControllerTest.java


注:本文中的org.springframework.test.context.jdbc.Sql类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。