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();
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations