diff --git a/flow-lit-template/src/test/java/com/vaadin/flow/component/littemplate/internal/LitTemplateParserImplTest.java b/flow-lit-template/src/test/java/com/vaadin/flow/component/littemplate/internal/LitTemplateParserImplTest.java
index 6b92e2e671d..8d6a030d8a5 100644
--- a/flow-lit-template/src/test/java/com/vaadin/flow/component/littemplate/internal/LitTemplateParserImplTest.java
+++ b/flow-lit-template/src/test/java/com/vaadin/flow/component/littemplate/internal/LitTemplateParserImplTest.java
@@ -72,7 +72,7 @@ public void init() {
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- Mockito.when(resourceProvider.getApplicationResource(service,
+ Mockito.when(resourceProvider.getApplicationResource(
VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
.thenReturn(LitTemplateParserImplTest.class.getResource(
"/" + VAADIN_SERVLET_RESOURCES + "config/stats.json"));
diff --git a/flow-polymer-template/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java b/flow-polymer-template/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java
index 686afc13c7c..eab66a9e6c1 100644
--- a/flow-polymer-template/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java
+++ b/flow-polymer-template/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java
@@ -198,8 +198,7 @@ protected String getSourcesFromTemplate(VaadinService service, String tag,
.lookup(ResourceProvider.class);
InputStream content = null;
try {
- URL appResource = resourceProvider.getApplicationResource(service,
- url);
+ URL appResource = resourceProvider.getApplicationResource(url);
content = appResource == null ? null : appResource.openStream();
} catch (IOException exception) {
getLogger().warn("Coudln't get resource for the template '{}'", url,
diff --git a/flow-polymer-template/src/test/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParserTest.java b/flow-polymer-template/src/test/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParserTest.java
index 7e580e9dc23..14358236717 100644
--- a/flow-polymer-template/src/test/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParserTest.java
+++ b/flow-polymer-template/src/test/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParserTest.java
@@ -15,9 +15,6 @@
*/
package com.vaadin.flow.component.polymertemplate;
-import static com.vaadin.flow.server.Constants.STATISTICS_JSON_DEFAULT;
-import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
-
import java.util.Locale;
import java.util.Properties;
import java.util.stream.Stream;
@@ -43,6 +40,9 @@
import com.vaadin.flow.server.MockVaadinServletService;
import com.vaadin.flow.templatemodel.TemplateModel;
+import static com.vaadin.flow.server.Constants.STATISTICS_JSON_DEFAULT;
+import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
+
public class NpmTemplateParserTest {
private MockVaadinServletService service;
@@ -77,11 +77,11 @@ public void init() throws Exception {
resourceProvider = service.getContext().getAttribute(Lookup.class)
.lookup(ResourceProvider.class);
- Mockito.when(resourceProvider.getApplicationResource(
- Mockito.eq(service), Mockito.anyString()))
+ Mockito.when(
+ resourceProvider.getApplicationResource(Mockito.anyString()))
.thenAnswer(invocation -> NpmTemplateParserTest.class
.getResource('/'
- + invocation.getArgumentAt(1, String.class)));
+ + invocation.getArgumentAt(0, String.class)));
}
@Test
@@ -109,7 +109,7 @@ public void should_FindCorrectDataInStats() {
public void getTemplateContent_polymer2TemplateStyleInsertion_contentParsedCorrectly() {
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- Mockito.when(resourceProvider.getApplicationResource(service,
+ Mockito.when(resourceProvider.getApplicationResource(
VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
.thenReturn(NpmTemplateParser.class
.getResource("/" + VAADIN_SERVLET_RESOURCES
@@ -129,7 +129,7 @@ public void getTemplateContent_polymer2TemplateStyleInsertion_contentParsedCorre
public void getTemplateContent_polymer2TemplateStyleInsertion_severalDomModules_correctTemplateContentIsChosen() {
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- Mockito.when(resourceProvider.getApplicationResource(service,
+ Mockito.when(resourceProvider.getApplicationResource(
VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
.thenReturn(NpmTemplateParser.class
.getResource("/" + VAADIN_SERVLET_RESOURCES
@@ -188,7 +188,7 @@ public void getTypescriptTemplateContent_templateExists_getTemplateContent() {
public void should_throwException_when_LocalFileNotFound() {
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- Mockito.when(resourceProvider.getApplicationResource(service,
+ Mockito.when(resourceProvider.getApplicationResource(
VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
.thenReturn(NpmTemplateParser.class
.getResource("/META-INF/resources/foo-bar.json"));
@@ -250,7 +250,7 @@ public void nonLocalTemplate_shouldParseCorrectly() {
public void bableStats_shouldAlwaysParseCorrectly() {
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- Mockito.when(resourceProvider.getApplicationResource(service,
+ Mockito.when(resourceProvider.getApplicationResource(
VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
.thenReturn(NpmTemplateParser.class
.getResource("/" + VAADIN_SERVLET_RESOURCES
@@ -309,7 +309,7 @@ public void bableStats_shouldAlwaysParseCorrectly() {
public void hierarchicalTemplate_templateHasChild_childHasCorrectPosition() {
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- Mockito.when(resourceProvider.getApplicationResource(service,
+ Mockito.when(resourceProvider.getApplicationResource(
VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
.thenReturn(NpmTemplateParser.class
.getResource("/" + VAADIN_SERVLET_RESOURCES
diff --git a/flow-server/src/main/java/com/vaadin/flow/di/ResourceProvider.java b/flow-server/src/main/java/com/vaadin/flow/di/ResourceProvider.java
index e5d9dc81e04..70a416293fe 100644
--- a/flow-server/src/main/java/com/vaadin/flow/di/ResourceProvider.java
+++ b/flow-server/src/main/java/com/vaadin/flow/di/ResourceProvider.java
@@ -20,9 +20,6 @@
import java.net.URL;
import java.util.List;
-import com.vaadin.flow.server.VaadinService;
-import com.vaadin.flow.server.VaadinServlet;
-
/**
* Static "classpath" resources provider.
*
@@ -38,99 +35,34 @@ public interface ResourceProvider {
/**
* Gets the resource identified by {@code path} located in the application
- * bundle (jar) which may be found using the {@code contextClass}.
+ * bundle (jar) which may be found using this resource provider instance.
*
- * If the {@code contextClass} doesn't contain any information about
- * application bundle or there is no resource with the given path then this
- * method returns {@code null}.
+ * If the provider doesn't contain any information about application bundle
+ * or there is no resource with the given path then this method returns
+ * {@code null}.
*
- * @param contextClass
- * a class to find an application bundle
* @param path
* the resource path
* @return an URL of the resource, may be {@code null}
*/
- URL getApplicationResource(Class> contextClass, String path);
+ URL getApplicationResource(String path);
/**
* Gets all the resources identified by {@code path} located in in the
- * application bundle (jar) which may be found using the {@code
- * contextClass}.
- *
- * If the {@code contextClass} doesn't contain any information about
- * application bundle or there is no resource with the given path then this
- * method returns an empty list.
- *
- * @param contextClass
- * a class to find an application bundle @param path the resource
- * path @return a list of URLs of the resources or an empty list
- * if resources are not found
- * @throws IOException
- * if there is an I/O error
- */
- List getApplicationResources(Class> contextClass, String path)
- throws IOException;
-
- /**
- * Gets all the web application resources identified by the {@code path}
- * using the provided {@code context}.
+ * application bundle (jar) which may be found using this resource provider.
*
- * The context doesn't have to be in the same bundle as the resource. The
- * resource location is the web application bundle (WAR or WAB) which might
- * not contain the {@code context} declaration at all. The {@code context}
- * instance is only used to find the correct bundle where the resource is
- * located.
- *
- * A typical scenario could be : the {@code context} object is a
- * {@link VaadinService} or {@link VaadinServlet} instance and the path is
- * some resource in the web application (which is very specific for the
- * application), e.g. {@code "stats.json"}. Both {@link VaadinService} and
- * {@link VaadinServlet} are located in "flow-server" bundle which doesn't
- * know anything about web app specific resources. If a servlet is
- * registered manually in the WAB then its bundle may be used to find the
- * resource. Otherwise some context information about WAB should be
- * retrieved from the {@code context}.
+ * If the provider doesn't contain any information about application bundle
+ * or there is no resource with the given path then this method returns an
+ * empty list.
*
- * @param context
- * a context object
* @param path
* the resource path
* @return a list of URLs of the resources or an empty list if resources are
* not found
- *
* @throws IOException
* if there is an I/O error
*/
- List getApplicationResources(Object context, String path)
- throws IOException;
-
- /**
- * Gets the web application resource identified by the {@code path} using
- * the provided {@code context}.
- *
- * The context doesn't have to be in the same bundle as the resource. The
- * resource location is the web application bundle (WAR or WAB) which might
- * not contain the {@code context} declaration at all. The {@code context}
- * instance is only used to find the correct bundle where the resource is
- * located.
- *
- * A typical scenario could be : the {@code context} object is a
- * {@link VaadinService} or {@link VaadinServlet} instance and the path is
- * some resource in the web application (which is very specific for the
- * application), e.g. {@code "stats.json"}. Both {@link VaadinService} and
- * {@link VaadinServlet} are located in "flow-server" bundle which doesn't
- * know anything about web app specific resources. If a servlet is
- * registered manually in the WAB then its bundle may be used to find the
- * resource. Otherwise some context information about WAB should be
- * retrieved from the {@code context}.
- *
- * @param context
- * a context object
- * @param path
- * the resource path
- * @return an URL of the resource, may be {@code null}
- */
- URL getApplicationResource(Object context, String path);
+ List getApplicationResources(String path) throws IOException;
/**
* Gets "flow-client" bundle resource identified by the {@code path}.
diff --git a/flow-server/src/main/java/com/vaadin/flow/server/BootstrapUtils.java b/flow-server/src/main/java/com/vaadin/flow/server/BootstrapUtils.java
index 6fb656286e0..207143c3f69 100644
--- a/flow-server/src/main/java/com/vaadin/flow/server/BootstrapUtils.java
+++ b/flow-server/src/main/java/com/vaadin/flow/server/BootstrapUtils.java
@@ -257,8 +257,7 @@ private static InputStream getInlineResourceStream(VaadinRequest request,
VaadinService service = request.getService();
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- URL appResource = resourceProvider.getApplicationResource(service,
- file);
+ URL appResource = resourceProvider.getApplicationResource(file);
InputStream stream = null;
try {
diff --git a/flow-server/src/main/java/com/vaadin/flow/server/DeploymentConfigurationFactory.java b/flow-server/src/main/java/com/vaadin/flow/server/DeploymentConfigurationFactory.java
index f47f20e5e3c..ee8008829ce 100644
--- a/flow-server/src/main/java/com/vaadin/flow/server/DeploymentConfigurationFactory.java
+++ b/flow-server/src/main/java/com/vaadin/flow/server/DeploymentConfigurationFactory.java
@@ -29,8 +29,6 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
@@ -314,8 +312,7 @@ private static String getTokenFileContents(Class> systemPropertyBaseClass,
try {
json = getResourceFromFile(initParameters);
if (json == null) {
- json = getTokenFileFromClassloader(systemPropertyBaseClass,
- context);
+ json = getTokenFileFromClassloader(context);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
@@ -339,8 +336,7 @@ private static String getResourceFromFile(Properties initParameters)
}
/**
- * Gets token file from the classpath using the provided
- * {@code contextClass} and {@code context}.
+ * Gets token file from the classpath using the provided {@code context}.
*
* The {@code contextClass} may be a class which is defined in the Web
* Application module/bundle and in this case it may be used to get Web
@@ -353,8 +349,6 @@ private static String getResourceFromFile(Properties initParameters)
* can't be used to get Web Application resources since they are in
* different bundles.
*
- * @param contextClass
- * a context class whose module may contain the token file
* @param context
* a VaadinContext which may provide information how to get token
* file for the web application
@@ -362,22 +356,16 @@ private static String getResourceFromFile(Properties initParameters)
* @throws IOException
* if I/O fails during access to the token file
*/
- private static String getTokenFileFromClassloader(Class> contextClass,
- VaadinContext context) throws IOException {
+ private static String getTokenFileFromClassloader(VaadinContext context)
+ throws IOException {
String tokenResource = VAADIN_SERVLET_RESOURCES + TOKEN_FILE;
Lookup lookup = context.getAttribute(Lookup.class);
ResourceProvider resourceProvider = lookup
.lookup(ResourceProvider.class);
- List classResources = resourceProvider
- .getApplicationResources(contextClass, tokenResource);
- List contextResources = resourceProvider
- .getApplicationResources(context, tokenResource);
-
- List resources = Stream
- .concat(classResources.stream(), contextResources.stream())
- .collect(Collectors.toList());
+ List resources = resourceProvider
+ .getApplicationResources(tokenResource);
// Accept resource that doesn't contain
// 'jar!/META-INF/Vaadin/config/flow-build-info.json'
@@ -388,7 +376,7 @@ private static String getTokenFileFromClassloader(Class> contextClass,
// For no non jar build info, in production mode check for
// webpack.generated.json if it's in a jar then accept
// single jar flow-build-info.
- return getPossibleJarResource(contextClass, context, resources);
+ return getPossibleJarResource(context, resources);
}
return resource == null ? null
: FrontendUtils.streamToString(resource.openStream());
@@ -403,8 +391,8 @@ private static String getTokenFileFromClassloader(Class> contextClass,
* Else we will accept any flow-build-info and log a warning that it may not
* be the correct file, but it's the best we could find.
*/
- private static String getPossibleJarResource(Class> contextClass,
- VaadinContext context, List resources) throws IOException {
+ private static String getPossibleJarResource(VaadinContext context,
+ List resources) throws IOException {
Objects.requireNonNull(resources);
Lookup lookup = context.getAttribute(Lookup.class);
@@ -414,12 +402,8 @@ private static String getPossibleJarResource(Class> contextClass,
assert !resources
.isEmpty() : "Possible jar resource requires resources to be available.";
- URL webpackGenerated = resourceProvider.getApplicationResource(context,
- FrontendUtils.WEBPACK_GENERATED);
- if (webpackGenerated == null) {
- webpackGenerated = resourceProvider.getApplicationResource(
- contextClass, FrontendUtils.WEBPACK_GENERATED);
- }
+ URL webpackGenerated = resourceProvider
+ .getApplicationResource(FrontendUtils.WEBPACK_GENERATED);
// If jar!/ exists 2 times for webpack.generated.json then we are
// running from a jar
diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java
index cb091d4cb26..4b0e11943ef 100644
--- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java
+++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java
@@ -608,7 +608,7 @@ private static InputStream getStatsFromClassPath(VaadinService service) {
.replaceFirst("^/", "");
ResourceProvider resourceProvider = service.getContext()
.getAttribute(Lookup.class).lookup(ResourceProvider.class);
- URL statsUrl = resourceProvider.getApplicationResource(service, stats);
+ URL statsUrl = resourceProvider.getApplicationResource(stats);
InputStream stream = null;
try {
stream = statsUrl == null ? null : statsUrl.openStream();
diff --git a/flow-server/src/main/java/com/vaadin/flow/server/startup/LookupInitializer.java b/flow-server/src/main/java/com/vaadin/flow/server/startup/LookupInitializer.java
index 124eb9e14e5..867c25acf9d 100644
--- a/flow-server/src/main/java/com/vaadin/flow/server/startup/LookupInitializer.java
+++ b/flow-server/src/main/java/com/vaadin/flow/server/startup/LookupInitializer.java
@@ -33,7 +33,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -47,7 +46,6 @@
import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.di.ResourceProvider;
import com.vaadin.flow.internal.ReflectTools;
-import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinServletContext;
import com.vaadin.flow.server.frontend.EndpointGeneratorTaskFactory;
@@ -157,42 +155,21 @@ private static class ResourceProviderImpl implements ResourceProvider {
private Map cache = new ConcurrentHashMap<>();
@Override
- public URL getApplicationResource(Class> clazz, String path) {
- return Objects.requireNonNull(clazz).getClassLoader()
+ public URL getApplicationResource(String path) {
+ return ResourceProviderImpl.class.getClassLoader()
.getResource(path);
}
@Override
- public List getApplicationResources(Object context, String path)
+ public List getApplicationResources(String path)
throws IOException {
- if (context instanceof VaadinService) {
- return Collections.list(((VaadinService) context)
- .getClassLoader().getResources(path));
- }
- return Collections.list(
- context.getClass().getClassLoader().getResources(path));
- }
-
- @Override
- public List getApplicationResources(Class> clazz, String path)
- throws IOException {
- return Collections.list(Objects.requireNonNull(clazz)
- .getClassLoader().getResources(path));
- }
-
- @Override
- public URL getApplicationResource(Object context, String path) {
- Objects.requireNonNull(context);
- if (context instanceof VaadinService) {
- return ((VaadinService) context).getClassLoader()
- .getResource(path);
- }
- return getApplicationResource(context.getClass(), path);
+ return Collections.list(ResourceProviderImpl.class.getClassLoader()
+ .getResources(path));
}
@Override
public URL getClientResource(String path) {
- return getApplicationResource(ResourceProviderImpl.class, path);
+ return getApplicationResource(path);
}
@Override
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/BootstrapHandlerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/BootstrapHandlerTest.java
index 58ebe991970..abc85cb5e6a 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/BootstrapHandlerTest.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/BootstrapHandlerTest.java
@@ -402,13 +402,7 @@ private void initUI(UI ui, VaadinRequest request,
navigationTargets.forEach(routeConfiguration::setAnnotatedRoute);
});
- this.request = request;
-
- ui.doInit(request, 0);
- ui.getInternals().getRouter().initializeUI(ui, request);
- context = new BootstrapContext(request, null, session, ui,
- this::contextRootRelativePath);
- ui.getInternals().setContextRoot(contextRootRelativePath(request));
+ initUI(ui, request);
}
@Test
@@ -1077,28 +1071,23 @@ public void bootstrapListener_throwsInClientSideMode()
@Test
public void useDependencyFilters_removeDependenciesAndAddNewOnes()
throws ServiceException {
- List filters = Arrays.asList(
- (list, context) -> {
- list.clear(); // remove everything
- return list;
- },
- (list, context) -> {
- list.add(new Dependency(Dependency.Type.JAVASCRIPT,
- "imported-by-filter.js", LoadMode.EAGER));
- list.add(new Dependency(Dependency.Type.JAVASCRIPT,
- "imported-by-filter2.js", LoadMode.EAGER));
- return list;
- },
- (list, context) -> {
- list.remove(1); // removes the imported-by-filter2.js
- return list;
- },
- (list, context) -> {
- list.add(new Dependency(Dependency.Type.STYLESHEET,
- "imported-by-filter.css", LoadMode.EAGER));
- return list;
- }
- );
+ List filters = Arrays.asList((list, context) -> {
+ list.clear(); // remove everything
+ return list;
+ }, (list, context) -> {
+ list.add(new Dependency(Dependency.Type.JAVASCRIPT,
+ "imported-by-filter.js", LoadMode.EAGER));
+ list.add(new Dependency(Dependency.Type.JAVASCRIPT,
+ "imported-by-filter2.js", LoadMode.EAGER));
+ return list;
+ }, (list, context) -> {
+ list.remove(1); // removes the imported-by-filter2.js
+ return list;
+ }, (list, context) -> {
+ list.add(new Dependency(Dependency.Type.STYLESHEET,
+ "imported-by-filter.css", LoadMode.EAGER));
+ return list;
+ });
service.setDependencyFilters(filters);
initUI(testUI);
@@ -1334,17 +1323,14 @@ public void AnnotationsWithoutRoute_ExceptionThrown()
@Test
public void getBootstrapPage_jsModulesDoNotContainDeferAttribute()
throws ServiceException {
- List filters = Arrays.asList(
- (list, context) -> {
- list.clear(); // remove everything
- return list;
- },
- (list, context) -> {
- list.add(new Dependency(Dependency.Type.JS_MODULE, "//module.js",
- LoadMode.EAGER));
- return list;
- }
- );
+ List filters = Arrays.asList((list, context) -> {
+ list.clear(); // remove everything
+ return list;
+ }, (list, context) -> {
+ list.add(new Dependency(Dependency.Type.JS_MODULE, "//module.js",
+ LoadMode.EAGER));
+ return list;
+ });
service.setDependencyFilters(filters);
initUI(testUI);
@@ -1408,8 +1394,7 @@ public void getBootstrapPage_assetChunksIsAnARRAY_bootstrapParsesOk()
Lookup lookup = testUI.getSession().getService().getContext()
.getAttribute(Lookup.class);
ResourceProvider provider = lookup.lookup(ResourceProvider.class);
- Mockito.when(provider.getApplicationResource(
- Mockito.any(VaadinService.class), Mockito.anyString()))
+ Mockito.when(provider.getApplicationResource(Mockito.anyString()))
.thenReturn(tmpFile.toURI().toURL());
BootstrapContext bootstrapContext = new BootstrapContext(request, null,
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/DeploymentConfigurationFactoryTest.java b/flow-server/src/test/java/com/vaadin/flow/server/DeploymentConfigurationFactoryTest.java
index 6119695c426..86a509a57f8 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/DeploymentConfigurationFactoryTest.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/DeploymentConfigurationFactoryTest.java
@@ -45,7 +45,6 @@
import static com.vaadin.flow.server.frontend.FrontendUtils.PARAM_TOKEN_FILE;
import static com.vaadin.flow.server.frontend.FrontendUtils.TOKEN_FILE;
import static java.util.Collections.emptyMap;
-import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.mock;
@@ -486,11 +485,8 @@ public void createInitParameters_readTokenFileFromContext()
DeploymentConfigurationFactory.createInitParameters(
DeploymentConfigurationFactoryTest.class, config);
- Mockito.verify(resourceProvider).getApplicationResources(
- DeploymentConfigurationFactoryTest.class,
- VAADIN_SERVLET_RESOURCES + TOKEN_FILE);
- Mockito.verify(resourceProvider).getApplicationResources(context,
- VAADIN_SERVLET_RESOURCES + TOKEN_FILE);
+ Mockito.verify(resourceProvider)
+ .getApplicationResources(VAADIN_SERVLET_RESOURCES + TOKEN_FILE);
}
@Test
@@ -516,24 +512,18 @@ protected URLConnection openConnection(URL u) throws IOException {
};
URL url = new URL("file", "", -1, "foo.jar!/" + path, handler);
- Mockito.when(resourceProvider.getApplicationResources(
- DeploymentConfigurationFactoryTest.class, path))
+ Mockito.when(resourceProvider.getApplicationResources(path))
.thenReturn(Collections.singletonList(url));
- Mockito.when(resourceProvider.getApplicationResource(
- DeploymentConfigurationFactoryTest.class,
- FrontendUtils.WEBPACK_GENERATED))
+ Mockito.when(resourceProvider
+ .getApplicationResource(FrontendUtils.WEBPACK_GENERATED))
.thenReturn(tmpFile.toURI().toURL());
DeploymentConfigurationFactory.createInitParameters(
DeploymentConfigurationFactoryTest.class, config);
- Mockito.verify(resourceProvider).getApplicationResource(
- DeploymentConfigurationFactoryTest.class,
- FrontendUtils.WEBPACK_GENERATED);
-
- Mockito.verify(resourceProvider).getApplicationResource(context,
- FrontendUtils.WEBPACK_GENERATED);
+ Mockito.verify(resourceProvider)
+ .getApplicationResource(FrontendUtils.WEBPACK_GENERATED);
}
@@ -633,14 +623,10 @@ public T lookup(Class serviceClass) {
}
};
- expect(provider.getApplicationResources(VaadinServlet.class,
- VAADIN_SERVLET_RESOURCES + TOKEN_FILE))
+ expect(provider
+ .getApplicationResources(VAADIN_SERVLET_RESOURCES + TOKEN_FILE))
.andAnswer(() -> Collections.emptyList()).anyTimes();
- expect(provider.getApplicationResources(anyObject(Object.class),
- anyObject())).andAnswer(() -> Collections.emptyList())
- .anyTimes();
-
replay(provider);
expect(contextMock.getAttribute(Lookup.class.getName()))
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/MockServletServiceSessionSetup.java b/flow-server/src/test/java/com/vaadin/flow/server/MockServletServiceSessionSetup.java
index 630ad9e267d..905a882b480 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/MockServletServiceSessionSetup.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/MockServletServiceSessionSetup.java
@@ -310,11 +310,11 @@ public MockServletServiceSessionSetup(boolean sessionAvailable)
.thenAnswer(invocation -> new ByteArrayInputStream(
"jsFile=foo".getBytes(StandardCharsets.UTF_8)));
- Mockito.when(resourceProvider.getApplicationResource(
- Mockito.any(VaadinService.class), Mockito.anyString()))
+ Mockito.when(
+ resourceProvider.getApplicationResource(Mockito.anyString()))
.thenAnswer(invocation -> {
return MockServletServiceSessionSetup.class.getResource(
- "/" + invocation.getArgumentAt(1, String.class));
+ "/" + invocation.getArgumentAt(0, String.class));
});
servlet.init(servletConfig);
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/communication/WebComponentBootstrapHandlerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/communication/WebComponentBootstrapHandlerTest.java
index 8b1e9fac9dd..58baf64dcc4 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/communication/WebComponentBootstrapHandlerTest.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/communication/WebComponentBootstrapHandlerTest.java
@@ -31,6 +31,7 @@
import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.di.ResourceProvider;
+import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.MockVaadinServletService;
import com.vaadin.flow.server.MockVaadinSession;
import com.vaadin.flow.server.PwaConfiguration;
@@ -41,6 +42,7 @@
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinResponse;
import com.vaadin.flow.server.VaadinService;
+import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletRequest;
import com.vaadin.flow.server.VaadinServletService;
import com.vaadin.flow.server.VaadinSession;
@@ -48,8 +50,6 @@
import com.vaadin.flow.shared.ApplicationConstants;
import com.vaadin.tests.util.MockDeploymentConfiguration;
-import static com.vaadin.flow.server.Constants.STATISTICS_JSON_DEFAULT;
-import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
@@ -251,11 +251,16 @@ private void initLookup(VaadinServletService service) throws IOException {
Mockito.when(lookup.lookup(ResourceProvider.class))
.thenReturn(provider);
- Mockito.when(provider.getApplicationResource(service,
- VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
- .thenReturn(WebComponentBootstrapHandlerTest.class
- .getClassLoader().getResource(VAADIN_SERVLET_RESOURCES
- + STATISTICS_JSON_DEFAULT));
+ Class extends VaadinServlet> servletClass = service.getServlet()
+ .getClass();
+
+ Mockito.when(provider
+ .getApplicationResource(Constants.VAADIN_SERVLET_RESOURCES
+ + Constants.STATISTICS_JSON_DEFAULT))
+ .thenReturn(
+ WebComponentBootstrapHandlerTest.class.getClassLoader()
+ .getResource(Constants.VAADIN_SERVLET_RESOURCES
+ + Constants.STATISTICS_JSON_DEFAULT));
Mockito.when(provider.getClientResourceAsStream(
"/META-INF/resources/" + ApplicationConstants.CLIENT_ENGINE_PATH
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendUtilsTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendUtilsTest.java
index 8ac2728b1db..348e2ea339a 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendUtilsTest.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendUtilsTest.java
@@ -42,6 +42,8 @@
import com.vaadin.flow.server.ServiceException;
import com.vaadin.flow.server.VaadinContext;
import com.vaadin.flow.server.VaadinService;
+import com.vaadin.flow.server.VaadinServlet;
+import com.vaadin.flow.server.VaadinServletService;
import com.vaadin.tests.util.MockDeploymentConfiguration;
import static com.vaadin.flow.server.Constants.STATISTICS_JSON_DEFAULT;
@@ -276,25 +278,29 @@ public void commandToString_commandContainsBaseDir_baseDirIsReplaced() {
@Test
public void getStatsContent_getStatsFromClassPath_delegateToGetApplicationResource()
throws IOException {
- VaadinService service = Mockito.mock(VaadinService.class);
+ VaadinServletService service = mockServletService();
ResourceProvider provider = mockResourceProvider(service);
FrontendUtils.getStatsContent(service);
- Mockito.verify(provider).getApplicationResource(service, "foo");
+ VaadinServlet servlet = service.getServlet();
+
+ Mockito.verify(provider).getApplicationResource("foo");
}
@Test
public void getStatsAssetsByChunkName_getStatsFromClassPath_delegateToGetApplicationResource()
throws IOException {
- VaadinService service = Mockito.mock(VaadinService.class);
+ VaadinServletService service = mockServletService();
ResourceProvider provider = mockResourceProvider(service);
FrontendUtils.getStatsAssetsByChunkName(service);
- Mockito.verify(provider).getApplicationResource(service, "foo");
+ VaadinServlet servlet = service.getServlet();
+
+ Mockito.verify(provider).getApplicationResource("foo");
}
private ResourceProvider mockResourceProvider(VaadinService service) {
@@ -332,7 +338,8 @@ private VaadinService getServiceWithResource(String content)
throws ServiceException, IOException {
MockDeploymentConfiguration configuration = new MockDeploymentConfiguration();
configuration.setProductionMode(true);
- VaadinService service = new MockVaadinServletService(configuration);
+ MockVaadinServletService service = new MockVaadinServletService(
+ configuration);
VaadinContext context = service.getContext();
@@ -350,7 +357,8 @@ private VaadinService getServiceWithResource(String content)
tmpFile)) {
IOUtils.write(content, outputStream, StandardCharsets.UTF_8);
}
- Mockito.when(provider.getApplicationResource(service,
+ VaadinServlet servlet = service.getServlet();
+ Mockito.when(provider.getApplicationResource(
VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT))
.thenReturn(tmpFile.toURI().toURL());
}
@@ -358,4 +366,12 @@ private VaadinService getServiceWithResource(String content)
return service;
}
+ private VaadinServletService mockServletService() {
+ VaadinServletService service = Mockito.mock(VaadinServletService.class);
+
+ VaadinServlet servlet = Mockito.mock(VaadinServlet.class);
+ Mockito.when(service.getServlet()).thenReturn(servlet);
+ return service;
+ }
+
}
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/startup/LookupInitializerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/startup/LookupInitializerTest.java
index 789660b32c8..7007a8039ca 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/startup/LookupInitializerTest.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/startup/LookupInitializerTest.java
@@ -45,7 +45,6 @@
import com.vaadin.flow.di.InstantiatorFactory;
import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.di.ResourceProvider;
-import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.startup.testdata.AnotherTestInstantiatorFactory;
import com.vaadin.flow.server.startup.testdata.OneMoreTestInstantiatorFactory;
import com.vaadin.flow.server.startup.testdata.TestInstantiatorFactory;
@@ -165,68 +164,21 @@ public void processLookupInitializer_noResourcePorvider_defaultResourceProviderI
ResourceProvider resourceProvider = lookup
.lookup(ResourceProvider.class);
- // ======== resourceProvider.getApplicationResource(s)(Class, String)
- URL applicationResource = resourceProvider.getApplicationResource(
- LookupInitializerTest.class,
- "resource-provider/some-resource.json");
+ // ======== resourceProvider.getApplicationResource(s)(String)
+ URL applicationResource = resourceProvider
+ .getApplicationResource("resource-provider/some-resource.json");
Assert.assertNotNull(applicationResource);
List resources = resourceProvider.getApplicationResources(
- LookupInitializerTest.class,
- "resource-provider/some-resource.json");
-
- Assert.assertEquals(1, resources.size());
-
- Assert.assertNotNull(resources.get(0));
-
- URL nonExistent = resourceProvider.getApplicationResource(
- LookupInitializerTest.class,
- "resource-provider/non-existent.txt");
-
- Assert.assertNull(nonExistent);
-
- // ======== resourceProvider.getApplicationResource(s)(Object, String)
- String path = "foo/bar";
-
- // == sub test: check VaadinService instance
- VaadinService service = Mockito.mock(VaadinService.class);
- ClassLoader loader = Mockito.mock(ClassLoader.class);
-
- URL singleResourceURL = new URL("file:/baz");
- Mockito.when(loader.getResource(path)).thenReturn(singleResourceURL);
- Mockito.when(loader.getResources(path))
- .thenReturn(Collections.enumeration(Arrays
- .asList(new URL("file:/foo"), new URL("file:/bar"))));
-
- Mockito.when(service.getClassLoader()).thenReturn(loader);
- URL serviceResource = resourceProvider.getApplicationResource(service,
- path);
- Assert.assertEquals(singleResourceURL, serviceResource);
-
- List serviceResources = resourceProvider
- .getApplicationResources(service, path);
-
- Assert.assertEquals(2, serviceResources.size());
-
- Assert.assertEquals(new URL("file:/foo"), serviceResources.get(0));
- Assert.assertEquals(new URL("file:/bar"), serviceResources.get(1));
-
- // == sub test: check non VaadinService instance
- applicationResource = resourceProvider.getApplicationResource(
- initializer, "resource-provider/some-resource.json");
-
- Assert.assertNotNull(applicationResource);
-
- resources = resourceProvider.getApplicationResources(initializer,
"resource-provider/some-resource.json");
Assert.assertEquals(1, resources.size());
Assert.assertNotNull(resources.get(0));
- nonExistent = resourceProvider.getApplicationResource(initializer,
- "resource-provider/non-existent.txt");
+ URL nonExistent = resourceProvider
+ .getApplicationResource("resource-provider/non-existent.txt");
Assert.assertNull(nonExistent);
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/startup/ServletDeployerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/startup/ServletDeployerTest.java
index 8abd0a980db..bdd6aa64de0 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/startup/ServletDeployerTest.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/startup/ServletDeployerTest.java
@@ -258,12 +258,8 @@ private ServletContextEvent getContextEvent(boolean addRoutes,
ResourceProvider resourceProvider = mock(ResourceProvider.class);
- expect(resourceProvider.getApplicationResources(anyObject(),
- anyObject())).andReturn(Collections.emptyList()).anyTimes();
-
- expect(resourceProvider.getApplicationResources(anyObject(Object.class),
- anyObject())).andAnswer(() -> Collections.emptyList())
- .anyTimes();
+ expect(resourceProvider.getApplicationResources(anyObject()))
+ .andReturn(Collections.emptyList()).anyTimes();
replay(resourceProvider);
diff --git a/flow-server/src/test/java/com/vaadin/flow/server/startup/testdata/TestResourceProvider.java b/flow-server/src/test/java/com/vaadin/flow/server/startup/testdata/TestResourceProvider.java
index b29bea9d2e8..f10ff5890df 100644
--- a/flow-server/src/test/java/com/vaadin/flow/server/startup/testdata/TestResourceProvider.java
+++ b/flow-server/src/test/java/com/vaadin/flow/server/startup/testdata/TestResourceProvider.java
@@ -25,24 +25,12 @@
public class TestResourceProvider implements ResourceProvider {
@Override
- public URL getApplicationResource(Class> contextClass, String path) {
+ public URL getApplicationResource(String path) {
return null;
}
@Override
- public List getApplicationResources(Class> contextClass, String path)
- throws IOException {
- return null;
- }
-
- @Override
- public List getApplicationResources(Object context, String path)
- throws IOException {
- return null;
- }
-
- @Override
- public URL getApplicationResource(Object context, String path) {
+ public List getApplicationResources(String path) throws IOException {
return null;
}