use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.
the class DependencyResolverTest method testLibVersionManagement.
@Test
public void testLibVersionManagement() throws Exception {
URL url = PluginManagerTest.class.getResource("/lib_versions.json");
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
Map<Plugin, Boolean> map = new HashMap<>();
for (Object obj : jsonArray) {
Plugin plugin = Plugin.fromJSON((JSONObject) obj);
plugin.detectInstalled(new HashSet<Plugin>());
map.put(plugin, true);
}
DependencyResolver resolver = new DependencyResolver(map);
Map<String, String> libs = resolver.getLibAdditions();
for (String libName : libs.keySet()) {
if (libName.equals("jmeter-plugins-cmn-jmeter")) {
assertEquals("jmeter-plugins-cmn-jmeter-0.4.jar", libs.get(libName));
} else if (libName.equals("kafka_2.8.2")) {
assertEquals("kafka_2.8.2_v0.8.jar", libs.get(libName));
} else if (libName.equals("commons-io")) {
assertEquals("commons-io.jar", libs.get(libName));
} else if (libName.equals("kafka_2.1.0")) {
assertEquals("kafka_2.1.0_v.0.1.jar", libs.get(libName));
} else if (libName.equals("lib")) {
assertEquals("lib-0.8.jar", libs.get(libName));
} else if (libName.equals("lib2")) {
assertEquals("lib2-0.2.jar", libs.get(libName));
} else {
fail("Unexpected lib name: " + libName);
}
}
}
use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.
the class DependencyResolverTest method testResolveLibBeforeDetete.
@Test
public void testResolveLibBeforeDetete() throws Exception {
URL url = PluginManagerTest.class.getResource("/lib_for_delete");
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
Map<Plugin, Boolean> map = new HashMap<>();
for (Object obj : jsonArray) {
Plugin plugin = Plugin.fromJSON((JSONObject) obj);
plugin.detectInstalled(new HashSet<Plugin>());
plugin.installedPath = "";
plugin.installedVersion = "0.1";
map.put(plugin, !plugin.getName().startsWith("delete"));
}
DependencyResolver resolver = new DependencyResolver(map);
Set<String> libs = resolver.getLibDeletions();
assertEquals(3, libs.size());
assertTrue(libs.contains("ApacheJMeter_core"));
assertTrue(libs.contains("commons-lang3"));
assertTrue(libs.contains("commons-httpclient"));
}
use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.
the class DependencyResolverTest method testResolveDowngradeWithNPE.
@Test
public void testResolveDowngradeWithNPE() throws Exception {
URL url = PluginManagerTest.class.getResource("/self_npe.json");
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
Map<Plugin, Boolean> map = new HashMap<>();
for (Object obj : jsonArray) {
Plugin plugin = Plugin.fromJSON((JSONObject) obj);
plugin.detectInstalled(new HashSet<Plugin>());
plugin.installedPath = "";
plugin.installedVersion = "0.14";
plugin.candidateVersion = "0.13";
map.put(plugin, true);
}
DependencyResolver resolver = new DependencyResolver(map);
Map<String, String> libs = resolver.getLibAdditions();
assertEquals(1, libs.size());
assertNotNull(libs.get("cmdbeginner"));
Set<Plugin> pluginsAdd = resolver.getAdditions();
assertEquals(1, pluginsAdd.size());
assertEquals("jpgc-plugins-manager", pluginsAdd.toArray(new Plugin[1])[0].getID());
Set<Plugin> pluginsDelete = resolver.getDeletions();
assertEquals(1, pluginsDelete.size());
assertEquals("jpgc-plugins-manager", pluginsDelete.toArray(new Plugin[1])[0].getID());
}
use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.
the class DependencyResolverTest method testUpdateWhenInstall.
@Test
public void testUpdateWhenInstall() throws Exception {
URL url = PluginManagerTest.class.getResource("/installed.json");
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
Map<Plugin, Boolean> map = new HashMap<>();
for (Object obj : jsonArray) {
Plugin plugin = Plugin.fromJSON((JSONObject) obj);
plugin.detectInstalled(new HashSet<Plugin>());
map.put(plugin, true);
}
DependencyResolver resolver = new DependencyResolver(map);
Set<String> libsDeletions = resolver.getLibDeletions();
assertEquals(1, libsDeletions.size());
assertTrue(libsDeletions.contains("commons-codec"));
Map<String, String> libsAdditions = resolver.getLibAdditions();
assertEquals(1, libsAdditions.size());
assertEquals("commons-codec-99.99.jar", libsAdditions.get("commons-codec"));
}
use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.
the class Plugin method getDepends.
public Set<String> getDepends() {
Set<String> depends = new HashSet<>();
JSONObject version = versions.getJSONObject(getCandidateVersion());
if (version.containsKey("depends")) {
JSONArray list = version.getJSONArray("depends");
for (Object o : list) {
if (o instanceof String) {
String dep = (String) o;
Matcher m = dependsParser.matcher(dep);
if (!m.find()) {
throw new IllegalArgumentException("Cannot parse depend str: " + dep);
}
depends.add(m.group(1));
}
}
}
return depends;
}
Aggregations