Add Rest configuration for test

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-04-25 10:45:48 +02:00
parent 347fb8d5fe
commit 5cfb933ca1
20 changed files with 175 additions and 84 deletions

View File

@@ -0,0 +1,52 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.rest.configuration;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.hawkbit.rest.util.FilterHttpResponse;
import org.eclipse.hawkbit.rest.util.HttpResponseFactoryBean;
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.WebApplicationContext;
/**
* Configuration for Rest api.
*/
@Configuration
public class RestConfiguration {
/**
* Create filter for {@link HttpServletResponse}.
*/
@Bean
public FilterHttpResponse filterHttpResponse() {
return new FilterHttpResponse();
}
/**
* Create factory bean for {@link HttpServletResponse}.
*/
@Bean
public FactoryBean<HttpServletResponse> httpResponseFactoryBean() {
return new HttpResponseFactoryBean();
}
/**
* Create factory bean for {@link HttpServletResponse}.
*/
@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST)
public RequestResponseContextHolder requestResponseContextHolder() {
return new RequestResponseContextHolder();
}
}

View File

@@ -19,10 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
*/
public class RequestResponseContextHolder {
@Autowired
private HttpServletRequest httpServletRequest;
@Resource(name = HttpResponseFactoryBean.FACTORY_BEAN_NAME)
private HttpServletResponse httpServletResponse;
public HttpServletRequest getHttpServletRequest() {
@@ -32,4 +30,14 @@ public class RequestResponseContextHolder {
public HttpServletResponse getHttpServletResponse() {
return httpServletResponse;
}
@Autowired
public void setHttpServletRequest(final HttpServletRequest httpServletRequest) {
this.httpServletRequest = httpServletRequest;
}
@Resource(name = HttpResponseFactoryBean.FACTORY_BEAN_NAME)
public void setHttpServletResponse(final HttpServletResponse httpServletResponse) {
this.httpServletResponse = httpServletResponse;
}
}

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.rest;
import org.eclipse.hawkbit.AbstractIntegrationTest;
import org.eclipse.hawkbit.rest.configuration.RestConfiguration;
import org.eclipse.hawkbit.rest.util.FilterHttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
/**
* Abstract Test for Rest tests.
*/
@SpringApplicationConfiguration(classes = { RestConfiguration.class })
public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest {
@Autowired
private FilterHttpResponse filterHttpResponse;
@Override
protected DefaultMockMvcBuilder createMvcWebAppContext() {
return super.createMvcWebAppContext().addFilter(filterHttpResponse);
}
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.rest;
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.rest.configuration.RestConfiguration;
import org.eclipse.hawkbit.rest.util.FilterHttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
/**
* Abstract Test for Rest tests.
*/
@SpringApplicationConfiguration(classes = { RestConfiguration.class })
public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB {
@Autowired
private FilterHttpResponse filterHttpResponse;
@Override
protected DefaultMockMvcBuilder createMvcWebAppContext() {
return super.createMvcWebAppContext().addFilter(filterHttpResponse);
}
}