-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
微调配置注解的位置,将@EnableFeignClients挪到FeignConfig。因为将@EnableFeignClients放在@…
…SpringBootApplication上会导致使用@WebMvcTest的测试失败 spring-projects/spring-boot#7270
- Loading branch information
Showing
17 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
gulimall-common/src/main/java/com/atguigu/common/config/FeignConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.atguigu.common.config; | ||
|
||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Configuration; | ||
@EnableFeignClients | ||
@Configuration | ||
public class FeignConfig { | ||
} |
9 changes: 9 additions & 0 deletions
9
gulimall-common/src/main/java/com/atguigu/common/config/NacosConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.atguigu.common.config; | ||
|
||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@EnableDiscoveryClient | ||
@Configuration | ||
public class NacosConfig { | ||
} |
13 changes: 13 additions & 0 deletions
13
gulimall-common/src/main/java/com/atguigu/common/config/RestClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.atguigu.common.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class RestClientConfig { | ||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
gulimall-common/src/testFixtures/java/com/atguigu/common/ResponseBodyMatchers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.atguigu.common; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.assertj.core.api.Assertions; | ||
import org.springframework.test.web.servlet.ResultMatcher; | ||
|
||
public class ResponseBodyMatchers { | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public <T> ResultMatcher containsObjectAsJson( | ||
Object expectedObject, Class<T> targetClass) { | ||
return mvcResult -> { | ||
String json = mvcResult.getResponse().getContentAsString(); | ||
T actualObject = objectMapper.readValue(json, targetClass); | ||
Assertions.assertThat(actualObject).isEqualToComparingFieldByField(expectedObject); | ||
}; | ||
} | ||
|
||
public static ResponseBodyMatchers responseBody() { | ||
return new ResponseBodyMatchers(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
gulimall-common/src/testFixtures/java/com/atguigu/common/Rmatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.atguigu.common; | ||
|
||
import com.atguigu.common.utils.R; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.assertj.core.api.Assertions; | ||
import org.springframework.test.web.servlet.ResultMatcher; | ||
|
||
public class Rmatcher { | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public <T> ResultMatcher hasKeyValue(String key, T val, Class<T> valClass) { | ||
return mvcResult -> { | ||
String json = mvcResult.getResponse().getContentAsString(); | ||
R r = objectMapper.readValue(json, R.class); | ||
Assertions.assertThat(r.get(key)).isInstanceOf(valClass); | ||
Assertions.assertThat(r.get(key)).isEqualToComparingFieldByField(val); | ||
}; | ||
} | ||
|
||
|
||
public static Rmatcher Rm() { | ||
return new Rmatcher(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
gulimall-common/src/testFixtures/java/com/atguigu/common/WebMvcTestConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.atguigu.common; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class WebMvcTestConfig { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters