|
| 1 | +/* |
| 2 | + * Copyright 2015-2016 The original authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.vaadin.spring.web; |
| 17 | + |
| 18 | +import com.gargoylesoftware.htmlunit.WebClient; |
| 19 | +import com.vaadin.server.VaadinRequest; |
| 20 | +import com.vaadin.spring.annotation.SpringUI; |
| 21 | +import com.vaadin.ui.Button; |
| 22 | +import com.vaadin.ui.Notification; |
| 23 | +import com.vaadin.ui.UI; |
| 24 | +import com.vaadin.ui.VerticalLayout; |
| 25 | +import org.junit.Assert; |
| 26 | +import org.junit.Test; |
| 27 | +import org.junit.runner.RunWith; |
| 28 | +import org.springframework.beans.factory.annotation.Autowired; |
| 29 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 30 | +import org.springframework.boot.context.embedded.LocalServerPort; |
| 31 | +import org.springframework.boot.test.context.SpringBootTest; |
| 32 | +import org.springframework.context.annotation.Bean; |
| 33 | +import org.springframework.test.context.junit4.SpringRunner; |
| 34 | + |
| 35 | +/** |
| 36 | + * Web based test {@link com.vaadin.spring.server.SpringVaadinServlet} static resource handling |
| 37 | + * |
| 38 | + * @author Vaadin Ltd |
| 39 | + */ |
| 40 | +@RunWith(SpringRunner.class) |
| 41 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 42 | +public class TestStaticHttp { |
| 43 | + private static final String MANDATORY_BOOTSTRAP_PART = "log('Vaadin bootstrap loaded');"; |
| 44 | + @Autowired |
| 45 | + private WebClient webClient; |
| 46 | + |
| 47 | + @LocalServerPort |
| 48 | + private int port; |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testExample() throws Exception { |
| 52 | + String javaScriptUrl = "http://localhost:" + port + "/VAADIN/vaadinBootstrap.js?v=8.0-SNAPSHOT"; |
| 53 | + String content = this.webClient.getPage(javaScriptUrl).getWebResponse().getContentAsString(); |
| 54 | + Assert.assertTrue("Mandatory part of bootstrap is not found", |
| 55 | + content.contains(MANDATORY_BOOTSTRAP_PART)); |
| 56 | + } |
| 57 | + |
| 58 | + @SpringUI |
| 59 | + public static class MyUI extends UI { |
| 60 | + @Override |
| 61 | + protected void init(VaadinRequest vaadinRequest) { |
| 62 | + setContent( |
| 63 | + new VerticalLayout( |
| 64 | + new Button("Click me", event -> Notification.show("Thanks")))); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + @SpringBootApplication |
| 69 | + public static class MyConfig { |
| 70 | + @Bean |
| 71 | + public MyUI createUI() { |
| 72 | + return new MyUI(); |
| 73 | + } |
| 74 | + |
| 75 | + @Bean |
| 76 | + public WebClient createWebClient() { |
| 77 | + return new WebClient(); |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments