Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
80bb9c50
Commit
80bb9c50
authored
Feb 24, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add smoke test for r2dbc support
See gh-19988 Co-authored-by:
Mark Paluch
<
mpaluch@pivotal.io
>
parent
45e60587
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
265 additions
and
0 deletions
+265
-0
build.gradle
...moke-tests/spring-boot-smoke-test-data-r2dbc/build.gradle
+16
-0
City.java
...t-data-r2dbc/src/main/java/smoketest/data/r2dbc/City.java
+61
-0
CityController.java
...bc/src/main/java/smoketest/data/r2dbc/CityController.java
+45
-0
CityRepository.java
...bc/src/main/java/smoketest/data/r2dbc/CityRepository.java
+23
-0
SampleR2dbcApplication.java
...ain/java/smoketest/data/r2dbc/SampleR2dbcApplication.java
+45
-0
application.properties
...test-data-r2dbc/src/main/resources/application.properties
+1
-0
database-init.sql
...moke-test-data-r2dbc/src/main/resources/database-init.sql
+10
-0
SampleR2dbcApplicationTests.java
...ava/smoketest/data/r2dbc/SampleR2dbcApplicationTests.java
+64
-0
No files found.
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/build.gradle
0 → 100644
View file @
80bb9c50
plugins
{
id
"java"
id
"org.springframework.boot.conventions"
}
description
=
"Spring Boot Data R2DBC smoke test"
dependencies
{
implementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-data-r2dbc"
))
implementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-webflux"
))
implementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"
))
runtimeOnly
(
"io.r2dbc:r2dbc-h2"
)
testImplementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-test"
))
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/src/main/java/smoketest/data/r2dbc/City.java
0 → 100644
View file @
80bb9c50
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
data
.
r2dbc
;
import
org.springframework.data.annotation.Id
;
public
class
City
{
@Id
private
Long
id
;
private
String
name
;
private
String
state
;
private
String
country
;
protected
City
()
{
}
public
City
(
String
name
,
String
country
)
{
this
.
name
=
name
;
this
.
country
=
country
;
}
public
Long
getId
()
{
return
this
.
id
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
String
getState
()
{
return
this
.
state
;
}
public
String
getCountry
()
{
return
this
.
country
;
}
@Override
public
String
toString
()
{
return
getName
()
+
","
+
getState
()
+
","
+
getCountry
();
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/src/main/java/smoketest/data/r2dbc/CityController.java
0 → 100644
View file @
80bb9c50
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
data
.
r2dbc
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
public
class
CityController
{
private
final
CityRepository
repository
;
public
CityController
(
CityRepository
repository
)
{
this
.
repository
=
repository
;
}
@GetMapping
(
"/cities"
)
public
Flux
<
City
>
findCities
()
{
return
this
.
repository
.
findAll
();
}
@GetMapping
(
"/cities/{id}"
)
public
Mono
<
City
>
findCityById
(
@PathVariable
long
id
)
{
return
this
.
repository
.
findById
(
id
);
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/src/main/java/smoketest/data/r2dbc/CityRepository.java
0 → 100644
View file @
80bb9c50
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
data
.
r2dbc
;
import
org.springframework.data.repository.reactive.ReactiveCrudRepository
;
public
interface
CityRepository
extends
ReactiveCrudRepository
<
City
,
Long
>
{
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/src/main/java/smoketest/data/r2dbc/SampleR2dbcApplication.java
0 → 100644
View file @
80bb9c50
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
data
.
r2dbc
;
import
io.r2dbc.spi.ConnectionFactory
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.data.r2dbc.connectionfactory.init.ResourceDatabasePopulator
;
@SpringBootApplication
public
class
SampleR2dbcApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SampleR2dbcApplication
.
class
,
args
);
}
@Bean
public
ApplicationRunner
initializeDatabase
(
ConnectionFactory
connectionFactory
,
ResourceLoader
resourceLoader
)
{
return
(
arguments
)
->
{
Resource
[]
scripts
=
new
Resource
[]
{
resourceLoader
.
getResource
(
"classpath:database-init.sql"
)
};
new
ResourceDatabasePopulator
(
scripts
).
execute
(
connectionFactory
).
block
();
};
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/src/main/resources/application.properties
0 → 100644
View file @
80bb9c50
management.endpoint.health.show-details
=
always
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/src/main/resources/database-init.sql
0 → 100644
View file @
80bb9c50
CREATE
TABLE
CITY
(
id
INTEGER
IDENTITY
PRIMARY
KEY
,
name
VARCHAR
(
30
),
state
VARCHAR
(
30
),
country
VARCHAR
(
30
)
);
INSERT
INTO
CITY
(
ID
,
NAME
,
STATE
,
COUNTRY
)
values
(
2000
,
'Washington'
,
'DC'
,
'US'
);
INSERT
INTO
CITY
(
ID
,
NAME
,
STATE
,
COUNTRY
)
values
(
2001
,
'San Francisco'
,
'CA'
,
'US'
);
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-r2dbc/src/test/java/smoketest/data/r2dbc/SampleR2dbcApplicationTests.java
0 → 100644
View file @
80bb9c50
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
smoketest
.
data
.
r2dbc
;
import
javax.sql.DataSource
;
import
net.minidev.json.JSONArray
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
properties
=
"spring.r2dc.generate-unique-name=true"
)
class
SampleR2dbcApplicationTests
{
@Autowired
private
WebTestClient
webClient
;
@Autowired
private
ApplicationContext
applicationContext
;
@Test
void
citiesEndpointReturnInitialState
()
{
this
.
webClient
.
get
().
uri
(
"/cities"
).
exchange
().
expectBody
().
jsonPath
(
"$[*].id"
)
.
isEqualTo
(
new
JSONArray
().
appendElement
(
2000
).
appendElement
(
2001
));
}
@Test
void
citiesEndpointByIdWithExistingIdReturnCity
()
{
this
.
webClient
.
get
().
uri
(
"/cities/2001"
).
exchange
().
expectBody
().
jsonPath
(
"$.name"
).
isEqualTo
(
"San Francisco"
);
}
@Test
void
healthEndpointHasR2dbcEntry
()
{
this
.
webClient
.
get
().
uri
(
"/actuator/health"
).
exchange
().
expectStatus
().
isOk
().
expectBody
()
.
jsonPath
(
"components.r2dbc.status"
).
isEqualTo
(
"UP"
).
jsonPath
(
"components.r2dbc.details.database"
)
.
isEqualTo
(
"H2"
);
}
@Test
void
dataSourceIsNotAutoConfigured
()
{
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
DataSource
.
class
)).
isEmpty
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment