use of org.jmeterplugins.repository.exception.DownloadException in project jmeter-plugins-manager by undera.
the class PluginManagerTest method testApplyChanges.
@Test
public void testApplyChanges() throws Exception {
String imgPath = "file:///" + new File(".").getAbsolutePath() + "/target/classes/org/jmeterplugins/logo.png";
String str = "{\"id\": 0, \"markerClass\": \"" + PluginsListTest.class.getName() + "\"," + " \"screenshotUrl\": \"" + imgPath + "\", \"name\": 3, \"description\": 4, \"helpUrl\": 5, \"vendor\": 5, \"installerClass\": \"test\", " + "\"versions\" : { \"0.1\" : { \"changes\": \"fix verified exception1\" }," + "\"0.2\" : { \"changes\": \"fix verified exception1\", \"libs\": {\n" + " \"jpgc-common\": \"http://httpstat.us/500\"\n" + " }}," + "\"0.3\" : { \"changes\": \"fix verified exception1\", \"downloadUrl\": \"http://httpstat.us/500\" } }}";
String addr = JMeterUtils.getPropDefault("jpgc.repo.address", "https://jmeter-plugins.org/repo/");
try {
JMeterUtils.setProperty("jpgc.repo.address", "http://httpstat.us/500");
Plugin p = Plugin.fromJSON(JSONObject.fromObject(str, new JsonConfig()));
PluginManager manager = new PluginManager();
// need to install
manager.allPlugins.put(p, true);
p.setCandidateVersion("9999");
try {
manager.applyChanges(new GenericCallback<String>() {
@Override
public void notify(String progress) {
}
}, true, null);
fail();
} catch (IllegalArgumentException ex) {
assertTrue(ex.getMessage().contains("Version 9999 not found for plugin"));
}
// need to install
manager.allPlugins.put(p, true);
p.setCandidateVersion("0.2");
try {
manager.applyChanges(new GenericCallback<String>() {
@Override
public void notify(String progress) {
}
}, true, null);
fail();
} catch (DownloadException ex) {
assertTrue(ex.getMessage().contains("Failed to download library"));
}
manager = new PluginManager();
// need to install
manager.allPlugins.put(p, true);
p.setCandidateVersion("0.3");
try {
manager.applyChanges(new GenericCallback<String>() {
@Override
public void notify(String progress) {
}
}, true, null);
fail();
} catch (DownloadException ex) {
assertTrue(ex.getMessage().contains("Failed to download plugin"));
}
} finally {
JMeterUtils.setProperty("jpgc.repo.address", addr);
}
}
use of org.jmeterplugins.repository.exception.DownloadException in project jmeter-plugins-manager by undera.
the class PluginManager method applyChanges.
public void applyChanges(GenericCallback<String> statusChanged, boolean doRestart, LinkedList<String> additionalJMeterOptions) {
try {
checkRW();
} catch (Throwable e) {
throw new RuntimeException("Cannot apply changes: " + e.getMessage(), e);
}
DependencyResolver resolver = new DependencyResolver(allPlugins);
Set<Plugin> additions = resolver.getAdditions();
Map<String, String> libInstalls = new HashMap<>();
for (Map.Entry<String, String> entry : resolver.getLibAdditions().entrySet()) {
try {
JARSource.DownloadResult dwn = jarSource.getJAR(entry.getKey(), entry.getValue(), statusChanged);
libInstalls.put(dwn.getTmpFile(), dwn.getFilename());
} catch (Throwable e) {
String msg = "Failed to download " + entry.getKey();
log.error(msg, e);
statusChanged.notify(msg);
throw new DownloadException("Failed to download library " + entry.getKey(), e);
}
}
for (Plugin plugin : additions) {
try {
plugin.download(jarSource, statusChanged);
} catch (IOException e) {
String msg = "Failed to download " + plugin;
log.error(msg, e);
statusChanged.notify(msg);
throw new DownloadException("Failed to download plugin " + plugin, e);
}
}
log.info("Restarting JMeter...");
statusChanged.notify("Restarting JMeter...");
Set<String> libDeletions = new HashSet<>();
for (String lib : resolver.getLibDeletions()) {
libDeletions.add(Plugin.getLibInstallPath(lib));
}
modifierHook(resolver.getDeletions(), additions, libInstalls, libDeletions, doRestart, additionalJMeterOptions);
}
Aggregations