Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Eriksson committed Nov 3, 2021
1 parent 74832c1 commit 571caf9
Showing 1 changed file with 0 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
package com.vaadin.flow.component.polymertemplate;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.stream.Stream;

import org.apache.commons.io.IOUtils;
import org.jsoup.nodes.Element;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;

import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.server.MockVaadinServletService;
import com.vaadin.flow.server.frontend.FrontendUtils;

import elemental.json.Json;
import elemental.json.JsonObject;

import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;

public class BundleParserTest {

private static final String statsFile = VAADIN_SERVLET_RESOURCES
+ "config/stats.json";

private static JsonObject stats;

private MockVaadinServletService service;
private DeploymentConfiguration configuration;

@BeforeClass
public static void initClass() throws IOException {
InputStream stream = BundleParserTest.class.getClassLoader()
.getResourceAsStream(statsFile);
String statsFileContents = IOUtils.toString(stream,
StandardCharsets.UTF_8);
stats = BundleParser.parseJsonStatistics(statsFileContents);
}

@Before
public void init() {
configuration = Mockito.mock(DeploymentConfiguration.class);
Expand All @@ -70,51 +52,6 @@ public void init() {
service.init(instantiator);
}

@Test
public void nonLocalTemplate_sourcesShouldBeFound() {
final String source = BundleParser.getSourceFromStatistics(
"./src/hello-world.js", stats, service);
Assert.assertNotNull("Source expected in stats.json", source);
}

@Test
public void nonLocalTemplate_sourcesShouldBeFoundInTargetFolder() {
final String source = BundleParser.getSourceFromStatistics(
"./src/hello-world2.js", stats, service);
Assert.assertNotNull("Source expected in stats.json", source);
}

@Test
public void nonLocalTemplate_windowsPath_sourcesShouldBeFoundInTargetFolder() {
Mockito.when(configuration.getFlowResourcesFolder()).thenReturn(
"target\\" + FrontendUtils.DEFAULT_FLOW_RESOURCES_FOLDER);
final String source = BundleParser.getSourceFromStatistics(
"./src/hello-world2.js", stats, service);
Assert.assertNotNull("Source expected in stats.json", source);
}

@Test
public void frontendPrefix_sourcesShouldBeFound() {
final String source = BundleParser.getSourceFromStatistics(
"./frontend/src/hello-world.js", stats, service);
Assert.assertNotNull("Source expected in stats.json", source);
}

@Test
public void typeScriptExtension_sourcesShouldBeFound() {
final String source = BundleParser.getSourceFromStatistics(
"./frontend/my-form.ts", stats, service);
Assert.assertNotNull("TypeScript sources expected in stats.json",
source);
}

@Test
public void frontendProtocol_sourcesShouldBeFound() {
final String source = BundleParser.getSourceFromStatistics(
"frontend:///src/hello-world.js", stats, service);
Assert.assertNotNull("Source expected in stats.json", source);
}

@Test
public void startsWithSingleLetterDirector_sourcesShouldNotBeFound() {
// This test exposes a common error in String#replaceFirst (unescaped
Expand Down

0 comments on commit 571caf9

Please sign in to comment.