Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Downloading plugin from url
Browse files Browse the repository at this point in the history
  • Loading branch information
pimotte committed Sep 23, 2014
1 parent a0a9a1d commit c2b8739
Showing 1 changed file with 106 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.lang.reflect.Field;
Expand All @@ -43,7 +42,7 @@
import org.syncany.util.EnvironmentUtil;

public class PluginOperationTest {

@Test
public void testPluginListLocalOnly() throws Exception {
// Setup
Expand All @@ -53,17 +52,17 @@ public void testPluginListLocalOnly() throws Exception {
PluginOperationOptions pluginOptions = new PluginOperationOptions();
pluginOptions.setAction(PluginAction.LIST);
pluginOptions.setListMode(PluginListMode.LOCAL);

// Run
PluginOperationResult pluginResult = client.plugin(pluginOptions);
List<Plugin> pluginList = Plugins.list(); // for comparison only!

// Test
assertNotNull(pluginResult);
assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
assertEquals(pluginList.size(), pluginResult.getPluginList().size());
assertEquals(2, pluginResult.getPluginList().size()); // local and unreliable_local

for (ExtendedPluginInfo pluginInfo : pluginResult.getPluginList()) {
assertNull(pluginInfo.getRemotePluginInfo());

Expand All @@ -72,21 +71,21 @@ public void testPluginListLocalOnly() throws Exception {
assertNull(pluginInfo.getLocalPluginInfo().getSha256sum());

assertNotNull(pluginInfo.getLocalPluginInfo().getPluginId());
assertNotNull(pluginInfo.getLocalPluginInfo().getPluginVersion());
assertNotNull(pluginInfo.getLocalPluginInfo().getPluginVersion());
// The rest is not important for processing ...

assertNotNull(Plugins.get(pluginInfo.getLocalPluginInfo().getPluginId()));
}

// Tear down
client.deleteTestData();
client.deleteTestData();
}

@Test
public void testPluginListRemoteOnlyReleasesOnly() throws Exception {
// Tests which plugin releases are available. This is difficult because
// that will change. So we can only test the bare minimum.

// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient client = new TestClient("A", testConnection);
Expand All @@ -95,21 +94,21 @@ public void testPluginListRemoteOnlyReleasesOnly() throws Exception {
pluginOptions.setAction(PluginAction.LIST);
pluginOptions.setListMode(PluginListMode.REMOTE);
pluginOptions.setSnapshots(false);
PluginOperationResult pluginResult = client.plugin(pluginOptions);

PluginOperationResult pluginResult = client.plugin(pluginOptions);

assertNotNull(pluginResult);
assertEquals(PluginResultCode.OK, pluginResult.getResultCode());

// Tear down
client.deleteTestData();
client.deleteTestData();
}

@Test
public void testPluginListRemoteOnlyIncludingSnapshots() throws Exception {
// Tests which plugin snapshots are available. This is difficult because
// that will change. So we can only test the bare minimum.

// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient client = new TestClient("A", testConnection);
Expand All @@ -118,58 +117,116 @@ public void testPluginListRemoteOnlyIncludingSnapshots() throws Exception {
pluginOptions.setAction(PluginAction.LIST);
pluginOptions.setListMode(PluginListMode.REMOTE);
pluginOptions.setSnapshots(true);
PluginOperationResult pluginResult = client.plugin(pluginOptions);

PluginOperationResult pluginResult = client.plugin(pluginOptions);

assertNotNull(pluginResult);
assertEquals(PluginResultCode.OK, pluginResult.getResultCode());

// Tear down
client.deleteTestData();
client.deleteTestData();
}

@Test
public void testPluginInstallAndPluginRemove() throws Exception {
public void testPluginInstall() throws Exception {
// Test the installation of FTP plugin


// Note that we would like to test removal of plugins.
// However, this is highly non-trivial due to the fact
// that classpath hacks would be needed to load plugins
// that are not in default locations.

if (EnvironmentUtil.isWindows()) {
// Test is Unix-specific.
return;
}

// Set the directory for the global config
Field userAppDirUnix = UserConfig.class.getDeclaredField("USER_APP_DIR_UNIX_LIKE");
userAppDirUnix.setAccessible(true);
File configDir = TestFileUtil.createTempDirectoryInSystemTemp();
userAppDirUnix.set(null, configDir);

// Forget the current global config
Field userConfigDir = UserConfig.class.getDeclaredField("userConfigDir");
userConfigDir.setAccessible(true);
userConfigDir.set(null, null);

// Reinitialize global config
UserConfig.init();


File configDir = setupCleanConfigDir();

// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient client = new TestClient("A", testConnection);

PluginOperationOptions pluginOptions = new PluginOperationOptions();
pluginOptions.setAction(PluginAction.INSTALL);
pluginOptions.setPluginId("ftp");

PluginOperationResult pluginResult = client.plugin(pluginOptions);


PluginOperationResult pluginResult = client.plugin(pluginOptions);

assertNotNull(pluginResult);
assertEquals(PluginResultCode.OK, pluginResult.getResultCode());

// Only one file should be in here: the jar for ftp.
assertEquals(1, (new File(configDir, "plugins/lib/")).list().length);

// Tear down
client.deleteTestData();
TestFileUtil.deleteDirectory(configDir);
System.setProperty("user.home", "/tmp");
}

@Test
public void testPluginInstallUrl() throws Exception {
// Test the installation of FTP plugin, through a url.
// First a list is done to get the url, then this is used to download.

if (EnvironmentUtil.isWindows()) {
// Test is Unix-specific.
return;
}

File configDir = setupCleanConfigDir();

// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient client = new TestClient("A", testConnection);

PluginOperationOptions pluginOptions = new PluginOperationOptions();
pluginOptions.setAction(PluginAction.LIST);
pluginOptions.setListMode(PluginListMode.REMOTE);
pluginOptions.setSnapshots(false);

PluginOperationResult pluginResult = client.plugin(pluginOptions);

String pluginDownloadUrl = null;
for (ExtendedPluginInfo pluginInfo : pluginResult.getPluginList()) {
if (pluginInfo.getRemotePluginInfo().getPluginId().equals("ftp")) {
pluginDownloadUrl = pluginInfo.getRemotePluginInfo().getDownloadUrl();
}
}

pluginOptions = new PluginOperationOptions();
pluginOptions.setAction(PluginAction.INSTALL);
pluginOptions.setPluginId(pluginDownloadUrl);

pluginResult = client.plugin(pluginOptions);

assertNotNull(pluginResult);
assertEquals(PluginResultCode.OK, pluginResult.getResultCode());

// Only one file should be in here: the jar for ftp.
assertTrue((new File(configDir, "plugins/lib/")).list().length == 1);
assertEquals(1, (new File(configDir, "plugins/lib/")).list().length);

// Tear down
client.deleteTestData();
client.deleteTestData();
TestFileUtil.deleteDirectory(configDir);
System.setProperty("user.home", "/tmp");
}
}

private File setupCleanConfigDir() throws Exception {
// Set the directory for the global config
Field userAppDirUnix = UserConfig.class.getDeclaredField("USER_APP_DIR_UNIX_LIKE");
userAppDirUnix.setAccessible(true);
File configDir = TestFileUtil.createTempDirectoryInSystemTemp();
userAppDirUnix.set(null, configDir);

// Forget the current global config
Field userConfigDir = UserConfig.class.getDeclaredField("userConfigDir");
userConfigDir.setAccessible(true);
userConfigDir.set(null, null);

// Reinitialize global config
UserConfig.init();
return configDir;
}
}

0 comments on commit c2b8739

Please sign in to comment.