Search in sources :

Example 6 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class PluginsZipTest method fileAccessErrorShouldContainPathToTheFolderInWhichTheErrorOccurred.

@Test
public void fileAccessErrorShouldContainPathToTheFolderInWhichTheErrorOccurred() throws Exception {
    SystemEnvironment systemEnvironmentFail = mock(SystemEnvironment.class);
    when(systemEnvironmentFail.get(SystemEnvironment.PLUGIN_FRAMEWORK_ENABLED)).thenReturn(true);
    when(systemEnvironmentFail.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn("/dummy");
    when(systemEnvironmentFail.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(externalPluginsDir.getAbsolutePath());
    when(systemEnvironmentFail.get(ALL_PLUGINS_ZIP_PATH)).thenReturn("");
    FileUtils.writeStringToFile(new File(externalPluginsDir, "external1.jar"), "External1");
    expectedException.expect(FileAccessRightsCheckException.class);
    expectedException.expectMessage("dummy");
    PluginsZip pluginsZipFail = new PluginsZip(systemEnvironmentFail, new ZipUtil());
    pluginsZipFail.create();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 7 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class GoPluginOSGiManifestTest method createPluginBundle.

private File createPluginBundle(String bundleName) throws IOException, URISyntaxException {
    File destinationPluginBundleLocation = new File(TMP_DIR, bundleName);
    destinationPluginBundleLocation.mkdirs();
    URL resource = getClass().getClassLoader().getResource("defaultFiles/descriptor-aware-test-plugin.jar");
    new ZipUtil().unzip(new File(resource.toURI()), destinationPluginBundleLocation);
    return destinationPluginBundleLocation;
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File) URL(java.net.URL)

Example 8 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class CommandRepositoryInitializerTest method setUp.

@Before
public void setUp() {
    serverHealthService = mock(ServerHealthService.class);
    systemEnvironment = mock(SystemEnvironment.class);
    zipUtil = mock(ZipUtil.class);
    zipInputStream = mock(ZipInputStream.class);
    when(systemEnvironment.get(SystemEnvironment.VERSION_FILE_IN_DEFAULT_COMMAND_REPOSITORY)).thenReturn("version.txt");
    CommandRepositoryInitializer initializer = new CommandRepositoryInitializer(systemEnvironment, zipUtil, serverHealthService);
    spy = spy(initializer);
    tempFiles = new TempFiles();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ZipInputStream(java.util.zip.ZipInputStream) ZipUtil(com.thoughtworks.go.util.ZipUtil) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) TempFiles(com.thoughtworks.go.util.TempFiles) Before(org.junit.Before)

Example 9 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class PluginsInitializerTest method setUp.

@Before
public void setUp() throws Exception {
    systemEnvironment = mock(SystemEnvironment.class);
    serverVersion = mock(ServerVersion.class);
    goPluginsDir = FileSystemUtils.createDirectory("go-plugins");
    when(systemEnvironment.get(SystemEnvironment.PLUGIN_GO_PROVIDED_PATH)).thenReturn(goPluginsDir.getAbsolutePath());
    when(systemEnvironment.get(SystemEnvironment.PLUGIN_FRAMEWORK_ENABLED)).thenReturn(true);
    pluginManager = mock(PluginManager.class);
    pluginsInitializer = spy(new PluginsInitializer(pluginManager, systemEnvironment, serverVersion, new ZipUtil()));
    doReturn(new ZipInputStream(new FileInputStream(new File("test/data/dummy-plugins.zip")))).when(pluginsInitializer).getPluginsZipStream();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) ZipInputStream(java.util.zip.ZipInputStream) ServerVersion(com.thoughtworks.go.server.util.ServerVersion) ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 10 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class PluginsInitializerTest method shouldUnzipPluginsAndRegisterZipUpdaterBeforeStartingPluginsFramework.

@Test
public void shouldUnzipPluginsAndRegisterZipUpdaterBeforeStartingPluginsFramework() throws IOException {
    ZipUtil zipUtil = mock(ZipUtil.class);
    pluginsInitializer = spy(new PluginsInitializer(pluginManager, systemEnvironment, serverVersion, zipUtil));
    doReturn(new ZipInputStream(new FileInputStream(new File("test/data/dummy-plugins.zip")))).when(pluginsInitializer).getPluginsZipStream();
    pluginsInitializer.initialize();
    InOrder inOrder = inOrder(zipUtil, pluginManager);
    inOrder.verify(zipUtil).unzip(Matchers.<ZipInputStream>any(), Matchers.<File>any());
    inOrder.verify(pluginManager, times(1)).startInfrastructure(true);
    inOrder.verify(pluginManager, times(1)).registerPluginsFolderChangeListener();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipUtil(com.thoughtworks.go.util.ZipUtil) InOrder(org.mockito.InOrder) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

ZipUtil (com.thoughtworks.go.util.ZipUtil)27 File (java.io.File)21 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)8 Before (org.junit.Before)7 Test (org.junit.Test)6 ZipInputStream (java.util.zip.ZipInputStream)5 ZipFile (java.util.zip.ZipFile)4 FileInputStream (java.io.FileInputStream)3 TempFiles (com.thoughtworks.go.util.TempFiles)2 IOException (java.io.IOException)2 TestStreamConsumer (com.thoughtworks.go.helper.TestStreamConsumer)1 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)1 ArtifactsDirHolder (com.thoughtworks.go.server.service.ArtifactsDirHolder)1 ServerVersion (com.thoughtworks.go.server.util.ServerVersion)1 ArtifactFolder (com.thoughtworks.go.server.web.ArtifactFolder)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 TestingClock (com.thoughtworks.go.util.TestingClock)1 URLService (com.thoughtworks.go.util.URLService)1 ChecksumValidator (com.thoughtworks.go.validation.ChecksumValidator)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1