package org.jmeterplugins.repository;

import kg.apc.emulators.TestJMeterUtils;
import org.apache.jmeter.util.JMeterUtils;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.swing.*;
import java.awt.*;

public class PluginManagerDialogTest {
    @BeforeClass
    public static void setup() {
        TestJMeterUtils.createJmeterEnv();
    }

    @Test
    public void displayGUI() throws Throwable {
        if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
            //JMeterUtils.setProperty("jpgc.repo.address", "/home/undera/Sources/JMeter/jmeter-plugins/manager/target/jpgc-repo/all.json");
            System.setProperty("http.proxyHost", "localhost");
            System.setProperty("http.proxyPort", "81");
            PluginManager aManager = new PluginManager();
            //aManager.load();
            PluginManagerDialog frame = new PluginManagerDialog(aManager);

            frame.setPreferredSize(new Dimension(800, 600));
            frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
            while (frame.isVisible()) {
                Thread.sleep(1000);
            }
            JMeterUtils.getJMeterProperties().remove("jpgc.repo.address");
        }
    }
}
@@ -84,42 +84,169 @@
 ort 
-org.apache.jmeter.util.JMeterUtils
+net.sf.json.JSONObject;%0Aimport net.sf.json.JsonConfig;%0Aimport org.apache.jmeter.util.JMeterUtils;%0Aimport org.jmeterplugins.repository.exception.DownloadException
 ;%0Aim
@@ -337,16 +337,103 @@
 a.awt.*;
+%0Aimport java.util.*;%0Aimport java.util.List;%0A%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Apublic
@@ -1418,24 +1418,24 @@
           %7D%0A
-
             
@@ -1513,9 +1513,1440 @@
 %7D%0A    %7D%0A
+%0A%0A%0A    @Test%0A    public void testFailDownload() throws Exception %7B%0A        String addr = JMeterUtils.getPropDefault(%22jpgc.repo.address%22, %22https://jmeter-plugins.org/repo/%22);%0A        try %7B%0A            JMeterUtils.setProperty(%22jpgc.repo.address%22, %22http://httpstat.us/500%22);%0A            PluginManager aManager = new PluginManager();%0A            PluginManagerDialog frame = new PluginManagerDialog(aManager);%0A            frame.componentShown(null);%0A            List%3CJEditorPane%3E panes = new ArrayList%3C%3E();%0A            getJEditorPane(frame, panes);%0A%0A            assertTrue(panes.size() %3E 0);%0A            boolean isOk = false;%0A            for (JEditorPane p : panes) %7B%0A                if (p.getText().contains(%22Failed to download plugins repository.%22)) %7B%0A                    isOk = true;%0A                    break;%0A                %7D%0A            %7D%0A            assertTrue(isOk);%0A        %7D finally %7B%0A            JMeterUtils.setProperty(%22jpgc.repo.address%22, addr);%0A        %7D%0A    %7D%0A%0A    private void getJEditorPane(Container component, List%3CJEditorPane%3E result) %7B%0A        Component%5B%5D components = component.getComponents();%0A        for (Component component1 : components) %7B%0A%0A            if (component1 instanceof JEditorPane) %7B%0A                result.add((JEditorPane) component1);%0A            %7D%0A%0A            if (component1 instanceof Container) %7B%0A                getJEditorPane((Container) component1, result);%0A            %7D%0A        %7D%0A    %7D%0A
 %7D

add pmgr show test