SecurityContextUtil { public static String requestId() { final InvocationInstance ii = SecurityContextUtil.getContext().getContent(InvocationInstance.class); RESTAssert.assertNotNull(ii, Status.INTERNAL_SERVER_ERROR); return ii.getMessageId(); }  static SecurityContext getSC(); static void assertSC(); static void assertLoggedIn(); static String getUser(); static IUser getUserObject(); static boolean hasRole(String role); static String requestId(); static boolean isLoggedIn();  }
@Test public void requestIdWithNullInstance() throws Exception { MessageContext messageContext = PowerMockito.mock(MessageContext.class); PowerMockito.when(messageContext.getContent(InvocationInstance.class)).thenReturn(null); PowerMockito.spy(SecurityContextUtil.class); PowerMockito.doReturn(messageContext).when(SecurityContextUtil.class, "getContext"); try { SecurityContextUtil.requestId(); Assert.fail("Should not get past requestId"); } catch (Exception e) { Assert.assertEquals(WebApplicationException.class, e.getClass()); Assert.assertEquals(500, ((WebApplicationException) e).getResponse().getStatus()); } }
@Test public void requestIdWithValidInstance() throws Exception { InvocationInstance ii = new InvocationInstance(UUID.randomUUID().toString(), "/"); MessageContext messageContext = PowerMockito.mock(MessageContext.class); PowerMockito.when(messageContext.getContent(InvocationInstance.class)).thenReturn(ii); PowerMockito.spy(SecurityContextUtil.class); PowerMockito.doReturn(messageContext).when(SecurityContextUtil.class, "getContext"); Assert.assertEquals(ii.getMessageId(), SecurityContextUtil.requestId()); }