Search in sources :

Example 6 with JsonConfig

use of net.sf.json.JsonConfig in project Java by Everything1sPossible.

the class jsonUtil method pageToJsonNotDatelist.

/**
 * ����ҳʵ������ת��json,�ɹ����ֶ�
 * @param result:��ҳʵ������
 * @param filterFields:��Ҫ���˵�����
 * @param dateFormat:���ڸ�ʽ��
 * @return
 */
public static <T> String pageToJsonNotDatelist(PageResult<T> result, String[] filterFields, String dateFormat) {
    Map<String, Object> jsonMap = new HashMap<String, Object>();
    jsonMap.put("pageNo", result.getPageNo());
    jsonMap.put("pageSize", result.getPageSize());
    jsonMap.put("total", result.getTotal());
    jsonMap.put("pages", result.getPages());
    JsonConfig config = new JsonConfig();
    if (filterFields != null) {
        config.setExcludes(filterFields);
    }
    // 1 �������ڸ�ʽ
    if (dateFormat == null || dateFormat.equals("")) {
        // Ĭ��Ϊ������
        dateFormat = "yyyy-MM-dd";
    }
    if (dateFormat != null) {
        config.registerJsonValueProcessor(Date.class, new JsonDateTransform(dateFormat));
    }
    return JSONObject.fromObject(jsonMap, config).toString();
}
Also used : HashMap(java.util.HashMap) JsonConfig(net.sf.json.JsonConfig) JSONObject(net.sf.json.JSONObject)

Example 7 with JsonConfig

use of net.sf.json.JsonConfig 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);
    }
}
Also used : JsonConfig(net.sf.json.JsonConfig) DownloadException(org.jmeterplugins.repository.exception.DownloadException) File(java.io.File) Test(org.junit.Test)

Example 8 with JsonConfig

use of net.sf.json.JsonConfig in project jmeter-plugins-manager by undera.

the class PluginsListTest method testFlow.

@Test
public void testFlow() 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\", \"downloadUrl\": \"https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-webdriver/0.3/jmeter-plugins-webdriver-0.1.jar\" }," + "\"0.2\" : { \"changes\": \"fix verified exception1\", \"downloadUrl\": \"https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-webdriver/0.3/jmeter-plugins-webdriver-0.2.jar\"}," + "\"0.3\" : { \"changes\": \"fix verified exception1\", " + "\"downloadUrl\": \"https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-webdriver/0.3/jmeter-plugins-webdriver-0.3.jar\"} }}";
    Plugin p = Plugin.fromJSON(JSONObject.fromObject(str, new JsonConfig()));
    Set<Plugin> set = new HashSet<>();
    set.add(p);
    PluginsListExt pluginsList = new PluginsListExt(set, null, null);
    pluginsList.getList().setSelectedIndex(0);
    ListSelectionEvent event = new ListSelectionEvent("0.2", 0, 2, false);
    pluginsList.valueChanged(event);
    p.setCandidateVersion("0.3");
    assertEquals("0.3", pluginsList.getCbVersion(pluginsList.getCheckboxItem(p, null)));
    String desc = pluginsList.getDescriptionHTML(p);
    assertFalse(desc.indexOf(EXPECTED_DESC_MAVEN) < 0);
    assertFalse(desc.indexOf(EXPECTED_DESC_CHANGES) < 0);
    p.detectInstalled(null);
    assertEquals(Plugin.VER_STOCK, pluginsList.getCbVersion(pluginsList.getCheckboxItem(p, null)));
    pluginsList.setEnabled(false);
    assertFalse(pluginsList.getList().isEnabled());
    assertFalse(pluginsList.getVersion().isEnabled());
    assertFalse(pluginsList.getList().getModel().getElementAt(0).isEnabled());
    JTextField searchField = pluginsList.searchField;
    ListModel model = pluginsList.getList().getModel();
    searchField.setText("not found plugin");
    KeyEvent keyEvent = new KeyEvent(pluginsList.searchField, KeyEvent.KEY_RELEASED, 20, 1, KeyEvent.VK_Z, 'z');
    KeyboardFocusManager.getCurrentKeyboardFocusManager().redispatchEvent(searchField, keyEvent);
    searchField.dispatchEvent(keyEvent);
    assertEquals(0, pluginsList.getList().getModel().getSize());
    assertFalse(model == pluginsList.getList().getModel());
    searchField.setText("");
    KeyboardFocusManager.getCurrentKeyboardFocusManager().redispatchEvent(searchField, keyEvent);
    searchField.dispatchEvent(keyEvent);
    assertEquals(1, pluginsList.getList().getModel().getSize());
    assertEquals(model, pluginsList.getList().getModel());
}
Also used : KeyEvent(java.awt.event.KeyEvent) JsonConfig(net.sf.json.JsonConfig) ListModel(javax.swing.ListModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JTextField(javax.swing.JTextField) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with JsonConfig

use of net.sf.json.JsonConfig in project jmeter-plugins-manager by undera.

the class RepoTest method testAll.

public void testAll() throws IOException {
    Map<String, String> env = System.getenv();
    if (env.containsKey("TRAVIS")) {
        System.out.println("Not running test inside Travis CI");
        return;
    }
    List<String> problems = new ArrayList<>();
    File[] files = getRepoFiles();
    JSONArray merged = new JSONArray();
    for (File repoFile : files) {
        System.out.println("Checking repo: " + repoFile.getCanonicalPath());
        String content = new String(Files.readAllBytes(Paths.get(repoFile.getAbsolutePath())), "UTF-8");
        JSON json = JSONSerializer.toJSON(content, new JsonConfig());
        JSONArray list = (JSONArray) json;
        for (Object item : list) {
            JSONObject spec = (JSONObject) item;
            checkPlugin(problems, repoFile, spec);
            merged.add(spec);
        }
    }
    if (problems.size() > 0) {
        throw new AssertionFailedError(problems.toString());
    }
    try (PrintWriter out = new PrintWriter(new File(repo.getAbsolutePath() + s + "all.json"))) {
        out.print(merged.toString(1));
    }
}
Also used : JsonConfig(net.sf.json.JsonConfig) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) JSON(net.sf.json.JSON) JSONObject(net.sf.json.JSONObject) JSONObject(net.sf.json.JSONObject) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 10 with JsonConfig

use of net.sf.json.JsonConfig 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);
        }
    }
}
Also used : HashMap(java.util.HashMap) JsonConfig(net.sf.json.JsonConfig) JSONArray(net.sf.json.JSONArray) URL(java.net.URL) JSONObject(net.sf.json.JSONObject) File(java.io.File) Test(org.junit.Test)

Aggregations

JsonConfig (net.sf.json.JsonConfig)28 JSONObject (net.sf.json.JSONObject)17 File (java.io.File)10 HashMap (java.util.HashMap)10 JSONArray (net.sf.json.JSONArray)10 Test (org.junit.Test)10 URL (java.net.URL)7 PrintWriter (java.io.PrintWriter)5 JSON (net.sf.json.JSON)5 Writer (java.io.Writer)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 NewBeanInstanceStrategy (net.sf.json.util.NewBeanInstanceStrategy)2 FlexClass (org.jaffa.flexfields.FlexClass)2 FlexCriteriaBean (org.jaffa.flexfields.FlexCriteriaBean)2 Status (io.milton.http.Response.Status)1 NameAndError (io.milton.http.webdav.PropFindResponse.NameAndError)1 CollectionResource (io.milton.resource.CollectionResource)1