org.springframework.test.context.jdbc.Sql Java Examples
The following examples show how to use
org.springframework.test.context.jdbc.Sql.
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 File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #2
Source File: NotificationControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #3
Source File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #4
Source File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #5
Source File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #6
Source File: ConsumerRolePermissionServiceTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #7
Source File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #8
Source File: ControllerIntegrationExceptionTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #9
Source File: GraphQLTest.java From elide-spring-boot with Apache License 2.0 | 6 votes |
@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 #10
Source File: RolePermissionServiceTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #11
Source File: NotificationControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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}¬ificationId={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 #12
Source File: NotificationControllerV2IntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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}¬ifications={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 #13
Source File: EmptyDatabaseIntegrationTest.java From embedded-database-spring-test with Apache License 2.0 | 6 votes |
@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 #14
Source File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #15
Source File: NotificationControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #16
Source File: ConfigFileControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #17
Source File: NotificationControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #18
Source File: AppControllerTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #19
Source File: NotificationControllerIntegrationTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #20
Source File: CarResourceTest.java From code-examples with MIT License | 6 votes |
@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 #21
Source File: EmptyDatabaseIntegrationTest.java From embedded-database-spring-test with Apache License 2.0 | 6 votes |
@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 #22
Source File: EmptyDatabaseIntegrationTest.java From embedded-database-spring-test with Apache License 2.0 | 6 votes |
@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 #23
Source File: RolePermissionServiceTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #24
Source File: RolePermissionServiceTest.java From apollo with Apache License 2.0 | 6 votes |
@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 #25
Source File: AppNamespaceServiceTest.java From apollo with Apache License 2.0 | 5 votes |
@Test @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 testFindPublicAppNamespaceByAppAndName() { Assert.assertNotNull(appNamespaceService.findByAppIdAndName("100003173", "datasourcexml")); Assert.assertNull(appNamespaceService.findByAppIdAndName("100003173", "TFF.song0711-02")); }
Example #26
Source File: AppNamespaceServiceTest.java From apollo with Apache License 2.0 | 5 votes |
@Test @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testCreateDefaultAppNamespace() { appNamespaceService.createDefaultAppNamespace(APP); AppNamespace appNamespace = appNamespaceService.findByAppIdAndName(APP, ConfigConsts.NAMESPACE_APPLICATION); Assert.assertNotNull(appNamespace); Assert.assertEquals(ConfigFileFormat.Properties.getValue(), appNamespace.getFormat()); }
Example #27
Source File: NotificationControllerV2IntegrationTest.java From apollo with Apache License 2.0 | 5 votes |
@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 testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated() throws Exception { long someOutDatedNotificationId = 1; ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange( "http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}¬ifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace, someOutDatedNotificationId)); long newNotificationId = 10; List<ApolloConfigNotification> notifications = result.getBody(); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals(1, notifications.size()); assertEquals(defaultNamespace, notifications.get(0).getNamespaceName()); assertEquals(newNotificationId, notifications.get(0).getNotificationId()); String key = assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION); ApolloNotificationMessages messages = result.getBody().get(0).getMessages(); assertEquals(1, messages.getDetails().size()); assertTrue(messages.has(key)); assertEquals(newNotificationId, messages.get(key).longValue()); }
Example #28
Source File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 5 votes |
@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 testQueryConfigFileWithNamespaceOK() throws Exception { ResponseEntity<ApolloConfig> response = restTemplate .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}", ApolloConfig.class, getHostUrl(), someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, someNamespace + ".xml"); ApolloConfig result = response.getBody(); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals("TEST-RELEASE-KEY5", result.getReleaseKey()); assertEquals("v1-file", result.getConfigurations().get("k1")); assertEquals("v2-file", result.getConfigurations().get("k2")); }
Example #29
Source File: RolePermissionServiceTest.java From apollo with Apache License 2.0 | 5 votes |
@Test @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testCreatePermission() throws Exception { String someTargetId = "someTargetId"; String somePermissionType = "somePermissionType"; Permission somePermission = assemblePermission(somePermissionType, someTargetId); Permission created = rolePermissionService.createPermission(somePermission); Permission createdFromDB = permissionRepository.findById(created.getId()).orElse(null); assertEquals(somePermissionType, createdFromDB.getPermissionType()); assertEquals(someTargetId, createdFromDB.getTargetId()); }
Example #30
Source File: ConfigControllerIntegrationTest.java From apollo with Apache License 2.0 | 5 votes |
@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 testQueryConfigNotModified() throws Exception { String releaseKey = "TEST-RELEASE-KEY2"; ResponseEntity<ApolloConfig> response = restTemplate .getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?releaseKey={releaseKey}", ApolloConfig.class, getHostUrl(), someAppId, someCluster, someNamespace, releaseKey); assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode()); }