Http Basics lessons fails to load #53
This commit is contained in:
@ -1,40 +0,0 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class GlobalPropertiesTest {
|
||||
|
||||
@Test
|
||||
public void propertyFilesShouldBeLoaded() throws IOException {
|
||||
Path tempDirectory = PluginTestHelper.createTmpDir();
|
||||
Path pluginDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "plugins"));
|
||||
Path directory = Files.createDirectory(Paths.get(tempDirectory.toString(), "i18n"));
|
||||
Path globalProperties = Files.createFile(Paths.get(directory.toString(), "global.properties"));
|
||||
Files.write(globalProperties, Arrays.asList("test=label for test"), StandardCharsets.UTF_8);
|
||||
new GlobalProperties(pluginDirectory).loadProperties(directory);
|
||||
|
||||
ClassLoader propertyFilesClassLoader =
|
||||
ResourceBundleClassLoader.createPropertyFilesClassLoader();
|
||||
assertNotNull(propertyFilesClassLoader.getResourceAsStream("global.properties"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void propertyFilesDirectoryNotFoundShouldRaiseError() throws IOException {
|
||||
Path tempDirectory = PluginTestHelper.createTmpDir();
|
||||
Path pluginDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "plugins"));
|
||||
Path directory = Files.createDirectory(Paths.get(tempDirectory.toString(), "i18n"));
|
||||
Files.delete(directory);
|
||||
|
||||
new GlobalProperties(pluginDirectory).loadProperties(directory);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package org.owasp.webgoat.util;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class LabelProviderTest {
|
||||
|
||||
@Test
|
||||
public void defaultLabelsShouldBePresent() {
|
||||
LabelProvider labelProvider = new LabelProvider();
|
||||
assertThat(labelProvider.get(Locale.ENGLISH, "LessonCompleted"), CoreMatchers.equalTo(
|
||||
"Congratulations. You have successfully completed this lesson."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadingPluginLabels() throws IOException {
|
||||
LabelProvider labelProvider = new LabelProvider();
|
||||
labelProvider.updatePluginResources(new ClassPathResource("log4j.properties").getFile().toPath());
|
||||
LabelProvider.refresh();
|
||||
assertThat(labelProvider.get(Locale.ENGLISH, "LessonCompleted"), CoreMatchers.equalTo(
|
||||
"Congratulations. You have successfully completed this lesson."));
|
||||
assertThat(labelProvider.get(Locale.ENGLISH, "log4j.appender.CONSOLE.Target"), CoreMatchers.equalTo(
|
||||
"System.out"));
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user