25 changed files with 812 additions and 258 deletions
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.cassandra; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest; |
||||||
|
|
||||||
|
@DataCassandraTest |
||||||
|
class MyDataCassandraTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
@SuppressWarnings("unused") |
||||||
|
private SomeRepository repository; |
||||||
|
|
||||||
|
} |
||||||
|
// @chomp:file
|
||||||
|
|
||||||
|
interface SomeRepository { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.jdbc; |
||||||
|
|
||||||
|
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; |
||||||
|
import org.springframework.transaction.annotation.Propagation; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
@JdbcTest |
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED) |
||||||
|
class MyTransactionalTests { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.jpa; |
||||||
|
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
||||||
|
import org.springframework.transaction.annotation.Propagation; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
@DataJpaTest |
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED) |
||||||
|
class MyNonTransactionalTests { |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.jpa; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||||
|
|
||||||
|
@DataJpaTest |
||||||
|
class MyRepositoryTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TestEntityManager entityManager; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private UserRepository repository; |
||||||
|
|
||||||
|
@Test |
||||||
|
void testExample() throws Exception { |
||||||
|
this.entityManager.persist(new User("sboot", "1234")); |
||||||
|
User user = this.repository.findByUsername("sboot"); |
||||||
|
assertThat(user.getUsername()).isEqualTo("sboot"); |
||||||
|
assertThat(user.getEmployeeNumber()).isEqualTo("1234"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
// @chomp:file
|
||||||
|
|
||||||
|
class User { |
||||||
|
|
||||||
|
User(String username, String employeeNumber) { |
||||||
|
} |
||||||
|
|
||||||
|
String getEmployeeNumber() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String getUsername() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
interface UserRepository { |
||||||
|
|
||||||
|
User findByUsername(String username); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.jpa.db; |
||||||
|
|
||||||
|
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; |
||||||
|
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; |
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
||||||
|
|
||||||
|
@DataJpaTest |
||||||
|
@AutoConfigureTestDatabase(replace = Replace.NONE) |
||||||
|
class MyRepositoryTests { |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.ldap; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest; |
||||||
|
import org.springframework.ldap.core.LdapTemplate; |
||||||
|
|
||||||
|
@DataLdapTest |
||||||
|
class MyDataLdapTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
@SuppressWarnings("unused") |
||||||
|
private LdapTemplate ldapTemplate; |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.ldap.server; |
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration; |
||||||
|
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest; |
||||||
|
|
||||||
|
@DataLdapTest(excludeAutoConfiguration = EmbeddedLdapAutoConfiguration.class) |
||||||
|
class MyDataLdapTests { |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.mongodb; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; |
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate; |
||||||
|
|
||||||
|
@DataMongoTest |
||||||
|
class MyDataMongoDbTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
@SuppressWarnings("unused") |
||||||
|
private MongoTemplate mongoTemplate; |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.mongodb.db; |
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; |
||||||
|
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; |
||||||
|
|
||||||
|
@DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class) |
||||||
|
class MyDataMongoDbTests { |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.neo4j; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest; |
||||||
|
|
||||||
|
@DataNeo4jTest |
||||||
|
class MyDataNeo4jTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
@SuppressWarnings("unused") |
||||||
|
private SomeRepository repository; |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
|
// @chomp:file
|
||||||
|
|
||||||
|
interface SomeRepository { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.neo4j.tx; |
||||||
|
|
||||||
|
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest; |
||||||
|
import org.springframework.transaction.annotation.Propagation; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
@DataNeo4jTest |
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED) |
||||||
|
class MyDataNeo4jTests { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.data.redis; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest; |
||||||
|
|
||||||
|
@DataRedisTest |
||||||
|
class MyDataRedisTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
@SuppressWarnings("unused") |
||||||
|
private SomeRepository repository; |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
|
// @chomp:file
|
||||||
|
|
||||||
|
interface SomeRepository { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.jooq; |
||||||
|
|
||||||
|
import org.jooq.DSLContext; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.jooq.JooqTest; |
||||||
|
|
||||||
|
@JooqTest |
||||||
|
class MyJooqTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
@SuppressWarnings("unused") |
||||||
|
private DSLContext dslContext; |
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.mvc; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.test.web.servlet.MockMvc; |
||||||
|
|
||||||
|
import static org.mockito.BDDMockito.given; |
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
||||||
|
|
||||||
|
@WebMvcTest(UserVehicleController.class) |
||||||
|
class MyControllerTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private MockMvc mvc; |
||||||
|
|
||||||
|
@MockBean |
||||||
|
private UserVehicleService userVehicleService; |
||||||
|
|
||||||
|
@Test |
||||||
|
void testExample() throws Exception { |
||||||
|
// @formatter:off
|
||||||
|
given(this.userVehicleService.getVehicleDetails("sboot")) |
||||||
|
.willReturn(new VehicleDetails("Honda", "Civic")); |
||||||
|
this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().string("Honda Civic")); |
||||||
|
// @formatter:on
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.mvc; |
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient; |
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlPage; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||||
|
import static org.mockito.BDDMockito.given; |
||||||
|
|
||||||
|
@WebMvcTest(UserVehicleController.class) |
||||||
|
class MyHtmlUnitTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private WebClient webClient; |
||||||
|
|
||||||
|
@MockBean |
||||||
|
private UserVehicleService userVehicleService; |
||||||
|
|
||||||
|
@Test |
||||||
|
void testExample() throws Exception { |
||||||
|
given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); |
||||||
|
HtmlPage page = this.webClient.getPage("/sboot/vehicle.html"); |
||||||
|
assertThat(page.getBody().getTextContent()).isEqualTo("Honda Civic"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.mvc; |
||||||
|
|
||||||
|
class UserVehicleController { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.mvc; |
||||||
|
|
||||||
|
class UserVehicleService { |
||||||
|
|
||||||
|
VehicleDetails getVehicleDetails(String name) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.mvc; |
||||||
|
|
||||||
|
class VehicleDetails { |
||||||
|
|
||||||
|
VehicleDetails(String make, String model) { |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.restclient; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.test.web.client.MockRestServiceServer; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||||
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; |
||||||
|
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; |
||||||
|
|
||||||
|
@RestClientTest(RemoteVehicleDetailsService.class) |
||||||
|
class MyRestClientTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private RemoteVehicleDetailsService service; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private MockRestServiceServer server; |
||||||
|
|
||||||
|
@Test |
||||||
|
void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() throws Exception { |
||||||
|
this.server.expect(requestTo("/greet/details")).andRespond(withSuccess("hello", MediaType.TEXT_PLAIN)); |
||||||
|
String greeting = this.service.callRestService(); |
||||||
|
assertThat(greeting).isEqualTo("hello"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
// @chomp:file
|
||||||
|
|
||||||
|
class RemoteVehicleDetailsService { |
||||||
|
|
||||||
|
String callRestService() { |
||||||
|
return "hello"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.webflux; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; |
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.test.web.reactive.server.WebTestClient; |
||||||
|
|
||||||
|
import static org.mockito.BDDMockito.given; |
||||||
|
|
||||||
|
@WebFluxTest(UserVehicleController.class) |
||||||
|
class MyControllerTests { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private WebTestClient webClient; |
||||||
|
|
||||||
|
@MockBean |
||||||
|
private UserVehicleService userVehicleService; |
||||||
|
|
||||||
|
@Test |
||||||
|
void testExample() throws Exception { |
||||||
|
// @formatter:off
|
||||||
|
given(this.userVehicleService.getVehicleDetails("sboot")) |
||||||
|
.willReturn(new VehicleDetails("Honda", "Civic")); |
||||||
|
this.webClient.get().uri("/sboot/vehicle").accept(MediaType.TEXT_PLAIN).exchange() |
||||||
|
.expectStatus().isOk() |
||||||
|
.expectBody(String.class).isEqualTo("Honda Civic"); |
||||||
|
// @formatter:on
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.webflux; |
||||||
|
|
||||||
|
class UserVehicleController { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.webflux; |
||||||
|
|
||||||
|
class UserVehicleService { |
||||||
|
|
||||||
|
VehicleDetails getVehicleDetails(String name) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2012-2021 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 org.springframework.boot.docs.springbootfeatures.testing.applications.webflux; |
||||||
|
|
||||||
|
class VehicleDetails { |
||||||
|
|
||||||
|
VehicleDetails(String make, String model) { |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue