类org.springframework.test.context.jdbc.Sql源码实例Demo

下面列出了怎么用org.springframework.test.context.jdbc.Sql的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: apollo   文件: ConfigControllerIntegrationTest.java
@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"));
}
 
源代码2 项目: elide-spring-boot   文件: GraphQLTest.java
@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));
}
 
@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());
}
 
@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());
}
 
源代码5 项目: apollo   文件: ConfigControllerIntegrationTest.java
@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"));
}
 
@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"));
}
 
@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"));
}
 
@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"));
}
 
源代码9 项目: code-examples   文件: CarResourceTest.java
@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());
}
 
@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());
}
 
@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"));
}
 
源代码12 项目: apollo   文件: ConfigControllerIntegrationTest.java
@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"));
}
 
@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());
}
 
@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());
}
 
源代码15 项目: apollo   文件: AppControllerTest.java
@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);
}
 
源代码16 项目: apollo   文件: RolePermissionServiceTest.java
@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));
}
 
源代码17 项目: apollo   文件: RolePermissionServiceTest.java
@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));
}
 
源代码18 项目: apollo   文件: RolePermissionServiceTest.java
@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));

}
 
@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());
}
 
源代码20 项目: apollo   文件: ConfigControllerIntegrationTest.java
@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"));
}
 
源代码21 项目: apollo   文件: ConfigControllerIntegrationTest.java
@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"));
}
 
源代码22 项目: apollo   文件: ConsumerRolePermissionServiceTest.java
@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));

}
 
源代码23 项目: apollo   文件: ConfigControllerIntegrationTest.java
@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"));
}
 
@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);
}
 
源代码25 项目: apollo   文件: AppNamespaceServiceTest.java
@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);
}
 
/**
 * 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);
}
 
源代码27 项目: apollo   文件: AppControllerTest.java
@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());
}
 
@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);
}
 
源代码29 项目: apollo   文件: AppControllerTest.java
@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());
}
 
源代码30 项目: apollo   文件: AppNamespaceServiceTest.java
@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);
}
 
 同包方法