use of org.springframework.web.context.request.RequestAttributes in project irida by phac-nml.
the class CartControllerTest method testGetCartMap.
@Test
public void testGetCartMap() {
RequestAttributes ra = new ServletRequestAttributes(new MockHttpServletRequest());
RequestContextHolder.setRequestAttributes(ra);
Map<Project, Set<Sample>> selected = new HashMap<>();
selected.put(project, samples);
controller.setSelected(selected);
Map<String, Object> cartMap = controller.getCartMap();
assertTrue(cartMap.containsKey("projects"));
@SuppressWarnings("unchecked") List<Map<String, Object>> pList = (List<Map<String, Object>>) cartMap.get("projects");
Map<String, Object> projectMap = pList.iterator().next();
assertTrue(projectMap.containsKey("samples"));
@SuppressWarnings("unchecked") List<Map<String, Object>> sList = (List<Map<String, Object>>) projectMap.get("samples");
for (Map<String, Object> map : sList) {
assertTrue(map.containsKey("id"));
assertTrue(map.containsKey("label"));
assertTrue(map.containsKey("href"));
}
}
use of org.springframework.web.context.request.RequestAttributes in project irida by phac-nml.
the class UserControllerTest method setUp.
@Before
public void setUp() {
userService = mock(UserService.class);
projectService = mock(ProjectService.class);
controller = new RESTUsersController(userService, projectService);
// fake out the servlet response so that the URI builder will work.
RequestAttributes ra = new ServletRequestAttributes(new MockHttpServletRequest());
RequestContextHolder.setRequestAttributes(ra);
}
use of org.springframework.web.context.request.RequestAttributes in project spring-boot-jpa by ssherwood.
the class BootJpaApplication method errorAttributes.
/**
* Customized ErrorAttribute bean.
* We really need to find a cleaner way of handling these error messages.
*
* @return customized ErrorAttributes
*/
@Bean
public ErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(final RequestAttributes requestAttributes, final boolean includeStackTrace) {
Map<String, Object> attributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
Throwable error = getError(requestAttributes);
if (error instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException ex = ((MethodArgumentNotValidException) error);
attributes.put("errors", ex.getMessage());
}
return attributes;
}
};
}
use of org.springframework.web.context.request.RequestAttributes in project spring-security by spring-projects.
the class SecurityReactorContextConfigurationTests method createSubscriberIfNecessaryWhenNotServletRequestAttributesThenStillCreate.
@Test
public void createSubscriberIfNecessaryWhenNotServletRequestAttributesThenStillCreate() {
RequestContextHolder.setRequestAttributes(new RequestAttributes() {
@Override
public Object getAttribute(String name, int scope) {
return null;
}
@Override
public void setAttribute(String name, Object value, int scope) {
}
@Override
public void removeAttribute(String name, int scope) {
}
@Override
public String[] getAttributeNames(int scope) {
return new String[0];
}
@Override
public void registerDestructionCallback(String name, Runnable callback, int scope) {
}
@Override
public Object resolveReference(String key) {
return null;
}
@Override
public String getSessionId() {
return null;
}
@Override
public Object getSessionMutex() {
return null;
}
});
CoreSubscriber<Object> subscriber = this.subscriberRegistrar.createSubscriberIfNecessary(Operators.emptySubscriber());
assertThat(subscriber).isInstanceOf(SecurityReactorContextConfiguration.SecurityReactorContextSubscriber.class);
}
use of org.springframework.web.context.request.RequestAttributes in project pinpoint by naver.
the class RequestContextPropagatingTaskDecoratorTest method requestContextShouldBePropagated.
@Test
public void requestContextShouldBePropagated() throws InterruptedException {
// Given
final int testCount = 100;
final CountDownLatch completeLatch = new CountDownLatch(testCount);
final AtomicBoolean verifiedFlag = new AtomicBoolean(true);
final TestWorker.Callback workerCallback = new TestWorker.Callback() {
@Override
public void onRun() {
RequestAttributes actualRequestAttributes = RequestContextHolder.getRequestAttributes();
boolean verified = requestAttributes == actualRequestAttributes;
verifiedFlag.compareAndSet(true, verified);
}
@Override
public void onError() {
// do nothing
}
};
// When
RequestContextHolder.setRequestAttributes(requestAttributes);
for (int i = 0; i < testCount; i++) {
executor.execute(new TestWorker(completeLatch, workerCallback));
}
completeLatch.await(5, TimeUnit.SECONDS);
// Then
boolean testVerified = verifiedFlag.get();
Assert.assertTrue("RequestContext has not been propagated", testVerified);
}
Aggregations