JAVA-21298 Fix failing tests in spring-boot-testing module (#14289)
This commit is contained in:
-23
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.boot
|
||||
|
||||
import com.baeldung.boot.controller.rest.WebController
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import spock.lang.Narrative
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Title
|
||||
|
||||
@Title("Application Specification")
|
||||
@Narrative("Specification which beans are expected")
|
||||
@SpringBootTest
|
||||
class LoadContextTest extends Specification {
|
||||
|
||||
@Autowired(required = false)
|
||||
private WebController webController
|
||||
|
||||
|
||||
def "when context is loaded then all expected beans are created"() {
|
||||
expect: "the WebController is created"
|
||||
webController
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package com.baeldung.boot
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
|
||||
import spock.lang.Narrative
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Title
|
||||
|
||||
@Title("WebController Specification")
|
||||
@Narrative("The Specification of the behaviour of the WebController. It can greet a person, change the name and reset it to 'world'")
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@EnableAutoConfiguration(exclude= SecurityAutoConfiguration.class)
|
||||
class WebControllerTest extends Specification {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc
|
||||
|
||||
def "when get is performed then the response has status 200 and content is 'Hello world!'"() {
|
||||
expect: "Status is 200 and the response is 'Hello world!'"
|
||||
mvc.perform(MockMvcRequestBuilders.get("/hello")).andExpect(MockMvcResultMatchers.status().isOk()).andReturn().response.contentAsString == "Hello world!"
|
||||
}
|
||||
|
||||
def "when set and delete are performed then the response has status 204 and content changes as expected"() {
|
||||
given: "a new name"
|
||||
def NAME = "Emmy"
|
||||
|
||||
when: "the name is set"
|
||||
mvc.perform(MockMvcRequestBuilders.put("/hello").content(NAME)).andExpect(MockMvcResultMatchers.status().isNoContent())
|
||||
|
||||
then: "the salutation uses the new name"
|
||||
mvc.perform(MockMvcRequestBuilders.get("/hello")).andExpect(MockMvcResultMatchers.status().isOk()).andReturn().response.contentAsString == "Hello $NAME!"
|
||||
|
||||
when: "the name is deleted"
|
||||
mvc.perform(MockMvcRequestBuilders.delete("/hello")).andExpect(MockMvcResultMatchers.status().isNoContent())
|
||||
|
||||
then: "the salutation uses the default name"
|
||||
mvc.perform(MockMvcRequestBuilders.get("/hello")).andExpect(MockMvcResultMatchers.status().isOk()).andReturn().response.contentAsString == "Hello world!"
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
+4
@@ -0,0 +1,4 @@
|
||||
validate.propertiesMap.first=prop1
|
||||
validate.propertiesMap.second=prop2
|
||||
|
||||
validate.mail_config.address=user1@test
|
||||
Reference in New Issue
Block a user