You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileUtilsTest.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2012-present the original author or 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 org.pf4j.util;
  17. import org.junit.jupiter.api.Test;
  18. import org.junit.jupiter.api.io.TempDir;
  19. import org.pf4j.plugin.PluginZip;
  20. import java.nio.file.Files;
  21. import java.nio.file.Path;
  22. import java.nio.file.Paths;
  23. import static org.junit.jupiter.api.Assertions.assertEquals;
  24. import static org.junit.jupiter.api.Assertions.assertTrue;
  25. public class FileUtilsTest {
  26. @TempDir
  27. Path pluginsPath;
  28. @Test
  29. public void expandIfZipForZipWithOnlyModuleDescriptor() throws Exception {
  30. PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
  31. .pluginVersion("1.2.3")
  32. .build();
  33. Path unzipped = FileUtils.expandIfZip(pluginZip.path());
  34. assertEquals(pluginZip.unzippedPath(), unzipped);
  35. assertTrue(Files.exists(unzipped.resolve("plugin.properties")));
  36. }
  37. @Test
  38. public void expandIfZipForZipWithResourceFile() throws Exception {
  39. PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-second-plugin-1.2.3.zip"), "myPlugin")
  40. .pluginVersion("1.2.3")
  41. .addFile(Paths.get("classes/META-INF/plugin-file"), "plugin")
  42. .build();
  43. Path unzipped = FileUtils.expandIfZip(pluginZip.path());
  44. assertEquals(pluginZip.unzippedPath(), unzipped);
  45. assertTrue(Files.exists(unzipped.resolve("classes/META-INF/plugin-file")));
  46. }
  47. @Test
  48. public void expandIfZipNonZipFiles() throws Exception {
  49. // File without .suffix
  50. Path extra = pluginsPath.resolve("extra");
  51. assertEquals(extra, FileUtils.expandIfZip(extra));
  52. // Folder
  53. Path folder = pluginsPath.resolve("folder");
  54. assertEquals(folder, FileUtils.expandIfZip(folder));
  55. }
  56. }