Search in sources :

Example 31 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class EndpointAccessCheckerTest method should_showHelpfulMessage_When_accessDeniedInDevMode.

@Test
public void should_showHelpfulMessage_When_accessDeniedInDevMode() throws Exception {
    VaadinService mockService = Mockito.mock(VaadinService.class);
    DeploymentConfiguration mockDeploymentConfiguration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(mockService.getDeploymentConfiguration()).thenReturn(mockDeploymentConfiguration);
    Mockito.when(mockDeploymentConfiguration.isProductionMode()).thenReturn(false);
    CurrentInstance.set(VaadinService.class, mockService);
    try {
        class Test {

            public void test() {
            }
        }
        Method method = Test.class.getMethod("test");
        String accessDeniedMessage = checker.check(method, requestMock);
        assertEquals(EndpointAccessChecker.ACCESS_DENIED_MSG_DEV_MODE, accessDeniedMessage);
        assertTrue(accessDeniedMessage.contains(PermitAll.class.getSimpleName()));
        assertTrue(accessDeniedMessage.contains(RolesAllowed.class.getSimpleName()));
        assertTrue(accessDeniedMessage.contains(AnonymousAllowed.class.getSimpleName()));
    } finally {
        CurrentInstance.clearAll();
    }
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Method(java.lang.reflect.Method) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 32 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class ThemeUrlResolverTest method init.

@Before
public void init() throws Exception {
    assert VaadinSession.getCurrent() == null : "Required no current vaadin session.";
    assert VaadinRequest.getCurrent() == null : "Required no current vaadin request.";
    MockitoAnnotations.initMocks(this);
    servlet = new VaadinServlet() {

        @Override
        protected DeploymentConfiguration createDeploymentConfiguration() throws ServletException {
            return mockDeploymentConfiguration;
        }
    };
    Properties initParameters = new Properties();
    Mockito.when(servletConfig.getServletContext()).thenReturn(servletContext);
    Mockito.when(servletConfig.getInitParameterNames()).thenReturn((Enumeration<String>) initParameters.propertyNames());
    Mockito.when(servletContext.getInitParameterNames()).thenReturn((Enumeration<String>) initParameters.propertyNames());
    Mockito.when(servletContext.getResource(Mockito.anyString())).thenAnswer(i -> new URL("http://localhost" + i.getArguments()[0]));
    servlet.init(servletConfig);
    Mockito.when(session.getAttribute(VaadinUriResolverFactory.class)).thenReturn(uriResolverFactory);
    Mockito.when(uriResolverFactory.getUriResolver(Mockito.any())).thenReturn(vaadinUriResolver);
    Mockito.when(vaadinUriResolver.resolveVaadinUri(Mockito.anyString())).thenAnswer(i -> i.getArguments()[0]);
    VaadinSession.setCurrent(session);
    CurrentInstance.set(VaadinRequest.class, request);
}
Also used : ServletException(javax.servlet.ServletException) VaadinServlet(com.vaadin.flow.server.VaadinServlet) Properties(java.util.Properties) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) URL(java.net.URL) Before(org.junit.Before)

Example 33 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class CustomElementRegistryInitializerTest method createService.

@Override
protected VaadinService createService() {
    VaadinService service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(true);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    return service;
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 34 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class LegacyPropertyEnabledTestServlet method testValuesFromAnnotation.

@Test
public void testValuesFromAnnotation() throws ServletException {
    TestServlet servlet = new TestServlet();
    servlet.init(new MockServletConfig());
    DeploymentConfiguration configuration = servlet.getService().getDeploymentConfiguration();
    Assert.assertEquals(true, configuration.isProductionMode());
    Assert.assertEquals(true, configuration.isCloseIdleSessions());
    Assert.assertEquals(1234, configuration.getHeartbeatInterval());
    Class<? extends UI> uiClass = BootstrapHandler.getUIClass(new VaadinServletRequest(EasyMock.createMock(HttpServletRequest.class), servlet.getService()));
    Assert.assertEquals(MockUIContainingServlet.class, uiClass);
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 35 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class LegacyPropertyEnabledTestServlet method testValuesOverriddenForServlet.

@Test
public void testValuesOverriddenForServlet() throws ServletException {
    final boolean expectedBoolean = false;
    final int expectedInt = 1111;
    Properties servletInitParams = new Properties();
    servletInitParams.setProperty("sendUrlsAsParameters", Boolean.toString(expectedBoolean));
    servletInitParams.setProperty("heartbeatInterval", Integer.toString(expectedInt));
    TestServlet servlet = new TestServlet();
    servlet.init(new MockServletConfig(servletInitParams));
    DeploymentConfiguration configuration = servlet.getService().getDeploymentConfiguration();
    // Values from servlet init params take precedence
    Assert.assertEquals(expectedBoolean, configuration.isSendUrlsAsParameters());
    Assert.assertEquals(expectedInt, configuration.getHeartbeatInterval());
    // Other params are as defined in the annotation
    Assert.assertEquals(true, configuration.isCloseIdleSessions());
    Class<? extends UI> uiClass = BootstrapHandler.getUIClass(new VaadinServletRequest(EasyMock.createMock(HttpServletRequest.class), servlet.getService()));
    Assert.assertEquals(MockUIContainingServlet.class, uiClass);
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) Properties(java.util.Properties) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Aggregations

DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)63 Test (org.junit.Test)24 VaadinService (com.vaadin.flow.server.VaadinService)23 VaadinSession (com.vaadin.flow.server.VaadinSession)9 UI (com.vaadin.flow.component.UI)8 Before (org.junit.Before)8 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)6 URL (java.net.URL)6 Properties (java.util.Properties)6 VaadinContext (com.vaadin.flow.server.VaadinContext)5 PushConfiguration (com.vaadin.flow.component.PushConfiguration)4 HashMap (java.util.HashMap)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)3 Location (com.vaadin.flow.router.Location)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 Method (java.lang.reflect.Method)3 Set (java.util.Set)3 ServletConfig (javax.servlet.ServletConfig)3 ServletException (javax.servlet.ServletException)3 Div (com.vaadin.flow.component.html.Div)2