use of net.sf.json.JsonConfig 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.JsonConfig 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.JsonConfig 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.JsonConfig in project jmeter-plugins-manager by undera.
the class JARSourceHTTP method getJSON.
protected JSON getJSON(String uri) throws IOException {
log.debug("Requesting " + uri);
HttpRequestBase get = new HttpGet(uri);
HttpParams requestParams = get.getParams();
get.setHeader("Accept-Encoding", "gzip");
requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
HttpResponse result = execute(get);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
HttpEntity entity = result.getEntity();
try {
entity.writeTo(bos);
byte[] bytes = bos.toByteArray();
if (bytes == null) {
bytes = "null".getBytes();
}
String response = isGZIPResponse(result) ? convertGZIPToString(bytes) : new String(bytes);
int statusCode = result.getStatusLine().getStatusCode();
if (statusCode >= 300) {
log.warn("Response with code " + result + ": " + response);
throw new IOException("Repository responded with wrong status code: " + statusCode);
} else {
log.debug("Response with code " + result + ": " + response);
}
return JSONSerializer.toJSON(response, new JsonConfig());
} finally {
get.abort();
try {
entity.getContent().close();
} catch (IOException | IllegalStateException e) {
log.warn("Exception in finalizing request", e);
}
}
}
use of net.sf.json.JsonConfig in project lobcder by skoulouzis.
the class JsonPropFindHandler method sendContent.
public void sendContent(PropFindableResource wrappedResource, String encodedUrl, OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException {
log.debug("sendContent: " + encodedUrl);
JsonConfig cfg = new JsonConfig();
cfg.setIgnoreTransientFields(true);
cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
JSON json;
Writer writer = new PrintWriter(out);
String[] arr;
if (propertyBuilder == null) {
if (wrappedResource instanceof CollectionResource) {
List<? extends Resource> children = ((CollectionResource) wrappedResource).getChildren();
json = JSONSerializer.toJSON(toSimpleList(children), cfg);
} else {
json = JSONSerializer.toJSON(toSimple(wrappedResource), cfg);
}
} else {
// use propfind handler
String sFields = params.get("fields");
Set<QName> fields = new HashSet<QName>();
Map<QName, String> aliases = new HashMap<QName, String>();
if (sFields != null && sFields.length() > 0) {
arr = sFields.split(",");
for (String s : arr) {
parseField(s, fields, aliases);
}
}
String sDepth = params.get("depth");
int depth = 1;
if (sDepth != null && sDepth.trim().length() > 0) {
depth = Integer.parseInt(sDepth);
}
String href = encodedUrl.replace("/_DAV/PROPFIND", "");
PropertiesRequest parseResult = new PropertiesRequest(toProperties(fields));
LogUtils.debug(log, "prop builder: ", propertyBuilder.getClass(), "href", href);
List<PropFindResponse> props;
try {
props = propertyBuilder.buildProperties(wrappedResource, depth, parseResult, href);
} catch (URISyntaxException ex) {
throw new RuntimeException("Requested url is not properly encoded: " + href, ex);
}
String where = params.get("where");
filterResults(props, where);
List<Map<String, Object>> list = helper.toMap(props, aliases);
json = JSONSerializer.toJSON(list, cfg);
}
json.write(writer);
writer.flush();
}
Aggregations