use of org.apache.jmeter.testbeans.gui.TestBeanGUI in project jmeter by apache.
the class GUIFactory method registerGUI.
/**
* Register a GUI class so that it can later be retrieved via
* {@link #getGUI(Class)}. The key should match the fully-qualified class
* name for the class used as the parameter when retrieving the GUI.
*
* @param key
* the name which can be used to retrieve this GUI later
* @param guiClass
* the class object for the GUI component
* @param testClass
* the class of the objects edited by this GUI
*
* @throws InstantiationException
* if an instance of the GUI class can not be instantiated
* @throws IllegalAccessException
* if access rights do not permit an instance of the GUI class
* to be created
*/
public static void registerGUI(String key, Class<?> guiClass, Class<?> testClass) throws InstantiationException, IllegalAccessException {
// TODO: This method doesn't appear to be used.
JMeterGUIComponent gui;
if (guiClass == TestBeanGUI.class) {
gui = new TestBeanGUI(testClass);
} else {
gui = (JMeterGUIComponent) guiClass.newInstance();
}
GUI_MAP.put(key, gui);
}
use of org.apache.jmeter.testbeans.gui.TestBeanGUI in project jmeter by apache.
the class JMeterTest method suiteBeanComponents.
/*
* Test GUI elements - create the suite of tests
*/
private static Test suiteBeanComponents() throws Exception {
TestSuite suite = new TestSuite("BeanComponents");
for (Object o : getObjects(TestBean.class)) {
Class<?> c = o.getClass();
try {
JMeterGUIComponent item = new TestBeanGUI(c);
TestSuite ts = new TestSuite(item.getClass().getName());
ts.addTest(new JMeterTest("GUIComponents2", item));
ts.addTest(new JMeterTest("runGUITitle", item));
suite.addTest(ts);
} catch (IllegalArgumentException e) {
System.out.println("o.a.j.junit.JMeterTest Cannot create test for " + c.getName() + " " + e);
e.printStackTrace(System.out);
}
}
return suite;
}
use of org.apache.jmeter.testbeans.gui.TestBeanGUI in project jmeter by apache.
the class GuiPackage method getGuiFromCache.
/**
* Get an instance of the specified JMeterGUIComponent class. If an instance
* of the GUI class has previously been created and it is not marked as an
* {@link UnsharedComponent}, that shared instance will be returned.
* Otherwise, a new instance of the component will be created, and shared
* components will be cached for future retrieval.
*
* @param guiClass
* the fully qualified class name of the GUI component. This
* class must implement JMeterGUIComponent.
* @param testClass
* the fully qualified class name of the test elements edited by
* this GUI component. This class must implement TestElement.
* @return an instance of the specified class
*
* @throws InstantiationException
* if an instance of the object cannot be created
* @throws IllegalAccessException
* if access rights do not allow the default constructor to be
* called
*/
private JMeterGUIComponent getGuiFromCache(Class<?> guiClass, Class<?> testClass) throws InstantiationException, IllegalAccessException {
JMeterGUIComponent comp;
if (guiClass == TestBeanGUI.class) {
comp = testBeanGUIs.get(testClass);
if (comp == null) {
comp = new TestBeanGUI(testClass);
testBeanGUIs.put(testClass, comp);
}
} else {
comp = guis.get(guiClass);
if (comp == null) {
comp = (JMeterGUIComponent) guiClass.newInstance();
if (!(comp instanceof UnsharedComponent)) {
guis.put(guiClass, comp);
}
}
}
return comp;
}
use of org.apache.jmeter.testbeans.gui.TestBeanGUI in project jmeter by apache.
the class GuiPackage method createTestElement.
/**
* Create a TestElement for a GUI or TestBean class.
* <p>
* This is a utility method to help actions do with one single String
* parameter.
*
* @param objClass
* the fully qualified class name of the GUI component or of the
* TestBean subclass for which a TestBeanGUI is wanted.
* @return the test element corresponding to the specified GUI class.
*/
public TestElement createTestElement(String objClass) {
JMeterGUIComponent comp;
Class<?> c;
try {
c = Class.forName(objClass);
if (TestBean.class.isAssignableFrom(c)) {
comp = getGuiFromCache(TestBeanGUI.class, c);
} else {
comp = getGuiFromCache(c, null);
}
comp.clearGui();
TestElement node = comp.createTestElement();
nodesToGui.put(node, comp);
return node;
} catch (NoClassDefFoundError e) {
log.error("Problem retrieving gui for " + objClass, e);
String msg = "Cannot find class: " + e.getMessage();
JOptionPane.showMessageDialog(null, msg, "Missing jar? See log file.", JOptionPane.ERROR_MESSAGE);
// Probably a missing jar
throw new RuntimeException(e.toString(), e);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
log.error("Problem retrieving gui for " + objClass, e);
// Programming error: bail out.
throw new RuntimeException(e.toString(), e);
}
}
use of org.apache.jmeter.testbeans.gui.TestBeanGUI in project jmeter by apache.
the class MenuFactory method initializeMenus.
private static void initializeMenus() {
try {
List<String> guiClasses = ClassFinder.findClassesThatExtend(JMeterUtils.getSearchPaths(), new Class[] { JMeterGUIComponent.class, TestBean.class });
Collections.sort(guiClasses);
for (String name : guiClasses) {
/*
* JMeterTreeNode and TestBeanGUI are special GUI classes, and
* aren't intended to be added to menus
*
* TODO: find a better way of checking this
*/
if (// $NON-NLS-1$
name.endsWith("JMeterTreeNode") || name.endsWith("TestBeanGUI")) {
// Don't try to instantiate these
continue;
}
if (elementsToSkip.contains(name)) {
// No point instantiating class
log.info("Skipping {}", name);
continue;
}
// Should the TestBean be hidden?
boolean hideBean = false;
JMeterGUIComponent item = null;
try {
Class<?> c = Class.forName(name);
if (TestBean.class.isAssignableFrom(c)) {
TestBeanGUI tbgui = new TestBeanGUI(c);
hideBean = tbgui.isHidden() || (tbgui.isExpert() && !JMeterUtils.isExpertMode());
item = tbgui;
} else {
item = (JMeterGUIComponent) c.newInstance();
}
} catch (NoClassDefFoundError e) {
log.warn("Configuration error, probably corrupt or missing third party library(jar) ? Could not create class: {}. {}", name, e, e);
continue;
} catch (HeadlessException e) {
// NOSONAR
log.warn("Could not instantiate class: {}", name, e);
continue;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
// NOSONAR
log.warn("Could not instantiate class: {}", name, e);
continue;
}
if (hideBean || elementsToSkip.contains(item.getStaticLabel())) {
log.info("Skipping {}", name);
continue;
} else {
// Don't add it again
elementsToSkip.add(name);
}
Collection<String> categories = item.getMenuCategories();
if (categories == null) {
log.debug("{} participates in no menus.", name);
continue;
}
if (categories.contains(THREADS)) {
threads.add(new MenuInfo(item, name));
}
if (categories.contains(FRAGMENTS)) {
fragments.add(new MenuInfo(item, name));
}
if (categories.contains(TIMERS)) {
timers.add(new MenuInfo(item, name));
}
if (categories.contains(POST_PROCESSORS)) {
postProcessors.add(new MenuInfo(item, name));
}
if (categories.contains(PRE_PROCESSORS)) {
preProcessors.add(new MenuInfo(item, name));
}
if (categories.contains(CONTROLLERS)) {
controllers.add(new MenuInfo(item, name));
}
if (categories.contains(SAMPLERS)) {
samplers.add(new MenuInfo(item, name));
}
if (categories.contains(NON_TEST_ELEMENTS)) {
nonTestElements.add(new MenuInfo(item, name));
}
if (categories.contains(LISTENERS)) {
listeners.add(new MenuInfo(item, name));
}
if (categories.contains(CONFIG_ELEMENTS)) {
configElements.add(new MenuInfo(item, name));
}
if (categories.contains(ASSERTIONS)) {
assertions.add(new MenuInfo(item, name));
}
}
} catch (IOException e) {
log.error("IO Exception while initializing menus.", e);
}
}
Aggregations