Alexander Wels has uploaded a new change for review. Change subject: engine: fix unit test paths ......................................................................
engine: fix unit test paths - Fixed unit tests that would fail if working path had a strange character in it like @ Change-Id: I0f52947d052a3eb5c228fee9b4260b827a2e0de5 Signed-off-by: Alexander Wels <aw...@redhat.com> --- M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingCascadingResourceServletTest.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingThemeTest.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoaderTest.java 5 files changed, 25 insertions(+), 20 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/99/19299/1 diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingCascadingResourceServletTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingCascadingResourceServletTest.java index b8b0835..31156bc 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingCascadingResourceServletTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingCascadingResourceServletTest.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; @@ -57,19 +58,20 @@ * Test that serving works when the request is "/favicon". * @throws IOException * @throws ServletException + * @throws URISyntaxException */ @Test - public void testDoGet_ServeFavicon() throws IOException, ServletException { + public void testDoGet_ServeFavicon() throws IOException, ServletException, URISyntaxException { when(mockBrandingManager.getBrandingRootPath()).thenReturn( new File(this.getClass().getClassLoader(). getResource("./org/ovirt/engine/core/utils/branding") //$NON-NLS-1$ - .getFile())); + .toURI().getPath())); when(mockBrandingManager.getCascadingResource("favicon")).thenReturn(mockCascadingResource); //$NON-NLS-1$ when(mockCascadingResource.getFile()).thenReturn( new File(this.getClass().getClassLoader(). getResource("./org/ovirt/engine/core/utils/branding/02-test2.brand/images/favicon.ico") //$NON-NLS-1$ - .getFile())); + .toURI().getPath())); when(mockCascadingResource.getContentType()).thenReturn("madeUp/ContentType"); //$NON-NLS-1$ testServlet.doGet(mockRequest, mockResponse); verify(mockResponse).setHeader(eq("ETag"), anyString()); //$NON-NLS-1$ @@ -80,13 +82,14 @@ * Test that a 404 is served when no resources are available. * @throws IOException * @throws ServletException + * @throws URISyntaxException */ @Test - public void testDoGet_ServeFaviconNotFound() throws IOException, ServletException { + public void testDoGet_ServeFaviconNotFound() throws IOException, ServletException, URISyntaxException { when(mockBrandingManager.getBrandingRootPath()).thenReturn( new File(this.getClass().getClassLoader(). getResource("./org/ovirt/engine/core/utils/branding") //$NON-NLS-1$ - .getFile())); + .toURI().getPath())); when(mockBrandingManager.getCascadingResource("favicon")).thenReturn(null); //$NON-NLS-1$ testServlet.doGet(mockRequest, mockResponse); verify(mockResponse).sendError(HttpServletResponse.SC_NOT_FOUND); diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java index 1233965..1a6eb7e2 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -26,7 +27,7 @@ @Before public void setUp() throws Exception { File etcDir = new File(this.getClass().getClassLoader(). - getResource("./org/ovirt/engine/core/utils").getFile()); //$NON-NLS-1$ + getResource("./org/ovirt/engine/core/utils").toURI().getPath()); //$NON-NLS-1$ testManager = new BrandingManager(etcDir); } @@ -67,10 +68,9 @@ } @Test - public void testGetBrandingRootPath() { + public void testGetBrandingRootPath() throws URISyntaxException { String rootPath = this.getClass().getClassLoader(). - getResource("./org/ovirt/engine/core/utils/") //$NON-NLS-1$ - .getFile() + "/branding"; //$NON-NLS-1$ + getResource("./org/ovirt/engine/core/utils/").toURI().getPath() + "/branding"; //$NON-NLS-1$ //$NON-NLS-2$ assertEquals("Root paths don't match", new File(rootPath), testManager.getBrandingRootPath()); //$NON-NLS-1$ } diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java index 4b68889..5409e76 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; @@ -53,7 +54,7 @@ when(mockResponse.getOutputStream()).thenReturn(mockResponseOutputStream); testFile = new File(this.getClass().getClassLoader(). getResource("./org/ovirt/engine/core/utils/branding/BrandingServletTest.class") //$NON-NLS-1$ - .getFile()); + .toURI().getPath()); } @Test @@ -71,11 +72,11 @@ } @Test - public void testDoGet_ExistingFile() throws IOException, ServletException { + public void testDoGet_ExistingFile() throws IOException, ServletException, URISyntaxException { when(mockRequest.getPathInfo()) .thenReturn("/org/ovirt/engine/core/utils/branding/BrandingServletTest.class"); //$NON-NLS-1$ when(mockFile.getAbsolutePath()).thenReturn(this.getClass().getClassLoader(). - getResource(".").getFile()); //$NON-NLS-1$ + getResource(".").toURI().getPath()); //$NON-NLS-1$ testServlet.doGet(mockRequest, mockResponse); verify(mockResponse).setHeader(eq("ETag"), anyString()); //$NON-NLS-1$ } diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingThemeTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingThemeTest.java index ee60ca9..2a8eee1 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingThemeTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingThemeTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.net.URISyntaxException; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; @@ -25,8 +26,7 @@ @Before public void setUp() throws Exception { File testThemeRootPath = new File(this.getClass().getClassLoader(). - getResource("./org/ovirt/engine/core/utils/branding") //$NON-NLS-1$ - .getFile()); + getResource("./org/ovirt/engine/core/utils/branding").toURI().getPath()); //$NON-NLS-1$ File testThemePath = new File(testThemeRootPath.getAbsoluteFile(), "01-test.brand"); //$NON-NLS-1$ testTheme = new BrandingTheme(testThemePath.getAbsolutePath(), testThemeRootPath, 1); @@ -76,10 +76,10 @@ } @Test - public void testGetCascadingResource_missingResourcesFile() { + public void testGetCascadingResource_missingResourcesFile() throws URISyntaxException { File testThemeRootPath = new File(this.getClass().getClassLoader(). getResource("./org/ovirt/engine/core/utils/branding") //$NON-NLS-1$ - .getFile()); + .toURI().getPath()); // theme 4 is purposely missing a resources.properties file File testThemePath = new File(testThemeRootPath.getAbsoluteFile(), "04-test4.brand"); //$NON-NLS-1$ BrandingTheme theme4 = new BrandingTheme(testThemePath.getAbsolutePath(), @@ -91,10 +91,10 @@ } @Test - public void testGetCascadingResource_missingResourcesProperty() { + public void testGetCascadingResource_missingResourcesProperty() throws URISyntaxException { File testThemeRootPath = new File(this.getClass().getClassLoader(). getResource("./org/ovirt/engine/core/utils/branding") //$NON-NLS-1$ - .getFile()); + .toURI().getPath()); // theme 5 is purposely missing a resources key in branding.properties File testThemePath = new File(testThemeRootPath.getAbsoluteFile(), "05-test5.brand"); //$NON-NLS-1$ BrandingTheme theme5 = new BrandingTheme(testThemePath.getAbsolutePath(), diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoaderTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoaderTest.java index 538d53b..a8c5c36 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoaderTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoaderTest.java @@ -1,6 +1,7 @@ package org.ovirt.engine.core.utils.osinfo; import java.io.File; +import java.net.URISyntaxException; import java.nio.file.Path; import org.junit.Assert; @@ -10,8 +11,8 @@ public class OsInfoPreferencesLoaderTest { @BeforeClass - public static void init() { - Path directoryPath = new File(OsInfoPreferencesLoader.class.getResource("/osinfo.conf.d").getPath()).toPath(); + public static void init() throws URISyntaxException { + Path directoryPath = new File(OsInfoPreferencesLoader.class.getResource("/osinfo.conf.d").toURI().getPath()).toPath(); OsInfoPreferencesLoader.INSTANCE.init(directoryPath); } @Test -- To view, visit http://gerrit.ovirt.org/19299 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0f52947d052a3eb5c228fee9b4260b827a2e0de5 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alexander Wels <aw...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches