Search in sources :

Example 51 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class HttpServletControlTest method runTestSetResponseHeader.

protected void runTestSetResponseHeader(boolean mshtml, boolean cspEnabled, String method, boolean expectCspHeader) {
    CspEnabledProperty cspProperty = Mockito.mock(CspEnabledProperty.class);
    Mockito.when(cspProperty.getValue(ArgumentMatchers.<String>any())).thenReturn(cspEnabled);
    s_beans.add(TestingUtility.registerBean(new BeanMetaData(CspEnabledProperty.class, cspProperty)));
    HttpClientInfo httpClientInfo = Mockito.mock(HttpClientInfo.class);
    Mockito.when(httpClientInfo.isMshtml()).thenReturn(mshtml);
    HttpServletControl httpServletControl = new HttpServletControl();
    httpServletControl.setCspToken(TEST_CSP_TOKEN);
    HttpServlet servlet = Mockito.mock(HttpServlet.class);
    HttpSession session = Mockito.mock(HttpSession.class);
    HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse resp = Mockito.mock(HttpServletResponse.class);
    Mockito.when(req.getMethod()).thenReturn(method);
    Mockito.when(req.getSession(false)).thenReturn(session);
    Mockito.when(session.getAttribute(HttpClientInfo.HTTP_CLIENT_INFO_ATTRIBUTE_NAME)).thenReturn(httpClientInfo);
    httpServletControl.setResponseHeaders(servlet, req, resp);
    Mockito.verifyZeroInteractions(servlet);
    if (expectCspHeader) {
        Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_X_FRAME_OPTIONS, HttpServletControl.SAMEORIGIN);
        Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_X_XSS_PROTECTION, HttpServletControl.XSS_MODE_BLOCK);
        if (mshtml) {
            Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_CSP_LEGACY, TEST_CSP_TOKEN);
        } else {
            Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_CSP, TEST_CSP_TOKEN);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) HttpServlet(javax.servlet.http.HttpServlet) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) CspEnabledProperty(org.eclipse.scout.rt.server.commons.ServerCommonsConfigProperties.CspEnabledProperty)

Example 52 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class InvocationContextTest method before.

@Before
public void before() {
    m_port = mock(TestPort.class);
    when(m_port.getRequestContext()).thenReturn(new HashMap<String, Object>());
    m_commitListener = mock(ICommitListener.class);
    m_rollbackListener = mock(IRollbackListener.class);
    m_implementorSpecifics = mock(JaxWsImplementorSpecifics.class);
    when(m_commitListener.onCommitPhase1()).thenReturn(true);
    m_beans = TestingUtility.registerBeans(new BeanMetaData(BEANS.get(JaxWsImplementorSpecifics.class).getClass(), m_implementorSpecifics).withReplace(true));
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) Matchers.anyString(org.mockito.Matchers.anyString) JaxWsImplementorSpecifics(org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics) Before(org.junit.Before)

Example 53 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class JaxWsPlatformListener method installImplementorSpecifics.

protected void installImplementorSpecifics(final IBeanManager beanManager) {
    final String jaxwsImplementor = CONFIG.getPropertyValue(JaxWsImplementorProperty.class);
    if (jaxwsImplementor == null) {
        return;
    }
    try {
        final Class<?> jaxwsImplementorClazz = Class.forName(jaxwsImplementor);
        Assertions.assertTrue(JaxWsImplementorSpecifics.class.isAssignableFrom(jaxwsImplementorClazz), "Implementor class must be of type '{}'.", JaxWsImplementorSpecifics.class.getName());
        // Unregister the Bean first, so it can be registered with @Replace annotation anew.
        beanManager.unregisterClass(jaxwsImplementorClazz);
        beanManager.registerBean(new BeanMetaData(jaxwsImplementorClazz).withReplace(true));
        LOG.info("JAX-WS implementor specific class installed: {}", jaxwsImplementorClazz.getName());
    } catch (final ClassNotFoundException e) {
        throw new PlatformException("Configured JAX-WS implementor specific class", e);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) JaxWsImplementorSpecifics(org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics)

Aggregations

BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)53 Test (org.junit.Test)18 Before (org.junit.Before)11 IBean (org.eclipse.scout.rt.platform.IBean)9 IBeanManager (org.eclipse.scout.rt.platform.IBeanManager)6 TestEnvironmentClientSession (org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession)5 Callable (java.util.concurrent.Callable)3 JobCompletionDelayOnSessionShutdown (org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown)3 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)3 After (org.junit.After)3 ArrayList (java.util.ArrayList)2 Subject (javax.security.auth.Subject)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 IMomImplementor (org.eclipse.scout.rt.mom.api.IMomImplementor)2 NullMomImplementor (org.eclipse.scout.rt.mom.api.NullMomImplementor)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 JaxWsImplementorSpecifics (org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics)2 IClusterSynchronizationService (org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService)2