Java Code Examples for com.vaadin.flow.server.VaadinService#setCurrent()

The following examples show how to use com.vaadin.flow.server.VaadinService#setCurrent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebComponentConfigurationRegistryInitializerTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    Mockito.when(vaadinService.getContext()).thenReturn(context);
    Mockito.when(
            context.getAttribute(WebComponentConfigurationRegistry.class))
            .thenReturn(registry);
    Mockito.when(context.getAttribute(
            eq(WebComponentConfigurationRegistry.class), anyObject()))
            .thenReturn(registry);

    initializer = new WebComponentConfigurationRegistryInitializer();
    when(servletContext.getAttribute(
            WebComponentConfigurationRegistry.class.getName()))
                    .thenReturn(registry);

    VaadinService.setCurrent(vaadinService);
    when(vaadinService.getInstantiator())
            .thenReturn(new MockInstantiator());
}
 
Example 2
Source File: RouteConfigurationTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    servletContext = new MockServletContext();
    vaadinContext = new VaadinServletContext(servletContext);
    registry = ApplicationRouteRegistry
            .getInstance(vaadinContext);

    vaadinService = Mockito.mock(MockService.class);
    Mockito.when(vaadinService.getRouteRegistry()).thenReturn(registry);
    Mockito.when(vaadinService.getContext()).thenReturn(vaadinContext);

    VaadinService.setCurrent(vaadinService);

    session = new MockVaadinSession(vaadinService) {
        @Override
        public VaadinService getService() {
            return vaadinService;
        }
    };
}
 
Example 3
Source File: RouterConfigurationUrlResolvingTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    super.init();
    ui = new RouterTestUI(router);
    ui.getSession().lock();
    ui.getSession().setConfiguration(configuration);

    VaadinService.setCurrent(service);

    Mockito.when(service.getDeploymentConfiguration())
            .thenReturn(configuration);
    Mockito.when(service.getRouter()).thenReturn(router);

    Mockito.when(configuration.isProductionMode()).thenReturn(true);
    routeConfiguration = RouteConfiguration
            .forRegistry(router.getRegistry());
}
 
Example 4
Source File: RouterTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Override
@Before
public void init() throws NoSuchFieldException, SecurityException,
        IllegalArgumentException, IllegalAccessException {
    super.init();
    ui = new RouterTestUI(router);
    ui.getSession().lock();
    ui.getSession().setConfiguration(configuration);

    VaadinService.setCurrent(service);

    Mockito.when(service.getDeploymentConfiguration())
            .thenReturn(configuration);
    Mockito.when(service.getRouter()).thenReturn(router);

    Mockito.when(configuration.isProductionMode()).thenReturn(true);
}
 
Example 5
Source File: VaadinConnectControllerTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void should_bePossibeToGetPrincipalInEndpoint() {
    MockVaadinServletService service = new MockVaadinServletService();
    VaadinService.setCurrent(service);
    when(principal.getName()).thenReturn("foo");

    VaadinConnectController vaadinController = createVaadinController(
            TEST_ENDPOINT, new VaadinConnectAccessChecker());

    ResponseEntity<String> response = vaadinController.serveEndpoint(
            TEST_ENDPOINT_NAME, "getUserName",
            createRequestParameters("{}"), requestMock);

    assertEquals("\"foo\"", response.getBody());
}
 
Example 6
Source File: WebComponentConfigurationRegistryTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    VaadinService service = mock(VaadinService.class);
    context = mock(VaadinContext.class);
    VaadinService.setCurrent(service);
    Mockito.when(service.getContext()).thenReturn(context);
    WebComponentConfigurationRegistry instance = createRegistry();
    Mockito.when(
            context.getAttribute(WebComponentConfigurationRegistry.class))
            .thenReturn(instance);
    Mockito.when(context.getAttribute(
            eq(WebComponentConfigurationRegistry.class), anyObject()))
            .thenReturn(instance);
    registry = WebComponentConfigurationRegistry.getInstance(context);
}
 
Example 7
Source File: PublishedServerEventHandlerRpcHandlerTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    Assert.assertNull(System.getSecurityManager());
    service = Mockito.mock(VaadinService.class);

    DeploymentConfiguration configuration = Mockito
            .mock(DeploymentConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    Mockito.when(service.getDeploymentConfiguration())
            .thenReturn(configuration);
    VaadinService.setCurrent(service);
}
 
Example 8
Source File: HasCurrentService.java    From flow with Apache License 2.0 5 votes vote down vote up
@Before
public void setUpCurrentService() {
    clearCurrentService();
    assertNull(VaadinService.getCurrent());

    service = createService();
    VaadinService.setCurrent(service);
}
 
Example 9
Source File: CompositeTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    compositeWithComponent = new CompositeWithComponent() {
        @Override
        public String toString() {
            return "Composite";
        }
    };

    layoutWithSingleComponentComposite = new TestLayout() {
        @Override
        public String toString() {
            return "Layout";
        }
    };
    layoutWithSingleComponentComposite.addComponent(compositeWithComponent);

    ((TracksAttachDetach) componentInsideLayoutInsideComposite).track();
    compositeWithComponent.track();
    layoutInsideComposite.track();
    layoutWithSingleComponentComposite.track();

    Assert.assertNull(VaadinService.getCurrent());
    VaadinService service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration configuration = Mockito
            .mock(DeploymentConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(true);
    Mockito.when(service.getDeploymentConfiguration())
            .thenReturn(configuration);
    VaadinService.setCurrent(service);
}
 
Example 10
Source File: InternalServerErrorTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    VaadinService.setCurrent(service);

    Mockito.when(service.getDeploymentConfiguration())
            .thenReturn(configuration);

    Location location = new Location("bar");
    Mockito.when(event.getLocation()).thenReturn(location);
}
 
Example 11
Source File: PublishedServerEventHandlerRpcHandlerTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    service = null;
    VaadinService.setCurrent(null);
}
 
Example 12
Source File: HasCurrentService.java    From flow with Apache License 2.0 4 votes vote down vote up
@After
public void clearCurrentService() {
    VaadinService.setCurrent(null);
    service = null;
}
 
Example 13
Source File: CompositeTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    VaadinService.setCurrent(null);
}
 
Example 14
Source File: InternalServerErrorTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    VaadinService.setCurrent(null);
}