我正在尝试进行集成测试,以查看我的注册端点失败时的行为。我的注册端点是由外部来源提供的API(由Spring OAuth保护)。客户端网站正在使用客户端Spring Oauth与API进行通信。
我想做的是模拟API,但是,我遇到了一些问题,即请求没有针对模拟端点进行;org.springframework.web.client.ResourceAccessException:“ http:// localhost:8081 / oauth / token ”的POST请求出现I / O错误:拒绝连接:connect; 嵌套的异常是java.net.ConnectException:拒绝连接:connect。以下是我的测试:
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:RegistrationControllerIntegrationTest-context.xml"})
public class RegistrationControllerIntegrationTest {
@Resource
RegistrationController registrationController;
@Resource
private WebApplicationContext webApplicationContext;
MockMvc mockMvc;
@Value("${oauth.accessTokenUri}")
private String oauthUri;
private MockRestServiceServer mockRestServiceServer;
private OAuth2RestTemplate clientCredRest;
@Resource(name = "clientCredentialRest")
public void setClientCredRest(OAuth2RestTemplate clientCredRest) {
this.clientCredRest = clientCredRest;
}
@Before
public void setUp()
{
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
this.mockRestServiceServer = MockRestServiceServer.createServer(this.clientCredRest);
}
@Test
public void testRegistrationThatReturnsBadRequestWhenUserAlreadyExist()
{
this.mockRestServiceServer.expect(MockRestRequestMatchers.requestTo("localhost:8081/oauth/token")).andExpect(MockRestRequestMatchers.method(HttpMethod.POST))
.andRespond(MockRestResponseCreators.withSuccess().contentType(MediaType.APPLICATION_JSON).body("{\n" +
"\"access_token\": \"8ecd93d4-2484-46de-922a-652fa79d027d\",\n" +
"\"token_type\": …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 docker-compose up 在 Docker 上运行 ElasticSearch。每当我尝试启动容器时,都会收到此错误:
Running as non-root...
elasticsearch | 2017-01-06 00:08:23,861 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
elasticsearch | at java.security.AccessControlContext.checkPermission(AccessControlContext.jav a:472)
elasticsearch | at java.lang.SecurityManager.checkPermission(SecurityManager.java:585)
elasticsearch | at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)
elasticsearch | at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Default MBeanServerInterceptor.java:322)
elasticsearch | at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
elasticsearch | at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)
elasticsearch | at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)
elasticsearch | at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
elasticsearch | at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:541)
elasticsearch | at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:258)
elasticsearch | at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:206)
elasticsearch | at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:220)
elasticsearch | at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:197)
elasticsearch …Run Code Online (Sandbox Code Playgroud) 美好的一天:
我目前正在研究NodeJs + MongoDB项目。我的解决方案很简单,我有3个集合(客户,范围,授权)。范围在“客户与赠款”集合之间形成了多对多关系。目前,我正在查询一个Client记录,然后获取分配给该Client的所有Scope集合,最后,最后获取我先前查询的Scope集合中的所有Grant记录。这是我的代码:
getClient (clientId, clientSecret, callback) {
let that = this;
this.mongoClient.collection('client').findOne({"client" : clientId, "client_secret" : clientSecret}, function (err, client) {
if (err) {
return callback(err, null);
}
that.mongoClient.collection('scope').find({'client_id': client._id}, {"service_id":1}, function(err, serviceIds) {
that.mongoClient.collection('grant').find({'_id': { $exists : true, $in : serviceIds }}, function(err, grants) {
console.log(grants.toArray());
callback(err, client);
})
});
});
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我得到的是:
Promise {
<rejected> Error: cyclic dependency detected
at serializeObject (/home/vagrant/api/node_modules/bson/lib/bson/parser/serializer.js:296:33)
at serializeInto (/home/vagrant/api/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at …Run Code Online (Sandbox Code Playgroud) 我在詹金斯(Jenkins)中运行Maven build遇到了一个小问题。它正在尝试运行我的集成测试,但是,继续抛出此错误:
java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2d10dd87 declaringClass = 'com.xxxx.api.services.MessageServiceImplIntegrationTest', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader']
Run Code Online (Sandbox Code Playgroud)
不知道这里发生了什么.我的XML bean定义架构正在使用:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
Run Code Online (Sandbox Code Playgroud)
定义中有问题的bean:
<beans:bean profile="dev,qa,prod">
<beans:bean parent="propertyConfigurer">
<beans:property name="order" value="0"></beans:property>
<beans:property name="locations">
<beans:list>
<beans:value>classpath:messages.properties</beans:value>
<beans:value>classpath:common.properties</beans:value>
<beans:value>classpath*:META-INF/properties/local.properties</beans:value>
</beans:list>
</beans:property>
</beans:bean>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)
但是,我得到了:
cvc-complex-type.3.2.2: Attribute 'profile' is not allowed to appear in element 'beans:bean'
Run Code Online (Sandbox Code Playgroud)
有任何想法吗