List of usage examples for java.lang Class getDeclaredMethod
@CallerSensitive public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
@Test public void testGetPhysicalLink() throws Exception { PhysicalLinkId physicalLinkId = mock(PhysicalLinkId.class); PhysicalLink physicalLink;/*from ww w.j av a 2s. co m*/ Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("getPhysicalLink", new Class[] { PhysicalLinkId.class }); method.setAccessible(true); physicalLink = (PhysicalLink) method.invoke(phyConfigLoader, physicalLinkId); Assert.assertTrue(physicalLink == null); }
From source file:br.com.uol.runas.classloader.ClassLoaderGC.java
private void releaseFromLoggers(WeakReference<ClassLoader> classLoader) { try {// ww w .ja va 2 s .c o m final Class<?> logFactoryClass = classLoader.get().loadClass("org.apache.commons.logging.LogFactory"); final Method releaseMethod = logFactoryClass.getDeclaredMethod("release", ClassLoader.class); releaseMethod.invoke(null, classLoader.get()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { final Class<?> logginHandlerClass = classLoader.get() .loadClass("org.openqa.selenium.logging.LoggingHandler"); final Object instance = Reflections.getStaticFieldValue(logginHandlerClass, "instance"); final Method closeMethod = logginHandlerClass.getDeclaredMethod("close"); closeMethod.invoke(instance, (Object[]) null); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { final Class<?> remoteWebDriverClass = classLoader.get() .loadClass("org.openqa.selenium.remote.RemoteWebDriver"); final Object logger = Reflections.getStaticFieldValue(remoteWebDriverClass, "logger"); // final Class<?> loggingClass = classLoader.get().loadClass("java.util.logging.Logger"); final List<?> handlers = Reflections.getFieldValue(logger, "handlers"); handlers.clear(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ca.quadrilateral.btester.discovery.ParentInclusiveTestableMethodDiscoverer.java
private Method getMethod(final Class<?> clazz, final String methodName, final Class<?> returnType) throws NoSuchMethodException { if (clazz == null) { throw new NoSuchMethodException("No method with name " + methodName + " found"); }/*from ww w .j a va 2 s. c o m*/ try { return clazz.getDeclaredMethod(methodName, returnType); } catch (NoSuchMethodException e) { return getMethod(clazz.getSuperclass(), methodName, returnType); } }
From source file:org.opendaylight.nemo.renderer.cli.physicalnetwork.PhysicalResourceLoaderTest.java
@Test public void testBuildNodes() throws Exception { Class<PhysicalResourceLoader> class1 = PhysicalResourceLoader.class; Method method = class1.getDeclaredMethod("buildNodes", new Class[] { JsonNode.class }); method.setAccessible(true);/*from w w w . j av a2s. c o m*/ List<PhysicalNode> result = new ArrayList<PhysicalNode>(); JsonNode nodesRoot = mock(JsonNode.class); JsonNode nodes = mock(JsonNode.class); JsonNode node = mock(JsonNode.class); JsonNode node_temp_buildnode = mock(JsonNode.class); JsonNode ports = mock(JsonNode.class); JsonNode attributes = mock(JsonNode.class); JsonNode port = mock(JsonNode.class); JsonNode port_temp_buildport = mock(JsonNode.class); JsonNode portAttributes = mock(JsonNode.class); JsonNode portAttribute = mock(JsonNode.class); JsonNode port_temp_buildPortAttribute = mock(JsonNode.class); JsonNode portAttribute_father = mock(JsonNode.class); JsonNode attribute_temp_father = mock(JsonNode.class); when(nodesRoot.path(any(String.class))).thenReturn(nodes); when(nodes.size()).thenReturn(1); when(nodes.get(any(Integer.class))).thenReturn(node); //get into method "build Node" when(node.get(any(String.class))).thenReturn(node_temp_buildnode); when(node_temp_buildnode.asText()).thenReturn(new String(""))//test null .thenReturn(new String("test"))//node id .thenReturn(new String("switch"));// node type result = (List<PhysicalNode>) method.invoke(physicalResourceLoader, nodesRoot); Assert.assertTrue(result.size() == 0); verify(node_temp_buildnode).asText(); when(node.path(any(String.class))).thenReturn(ports)//get into method "build ports" .thenReturn(attributes); //get into method "build attributes" ////get into method"build ports" when(ports.size()).thenReturn(1); when(ports.get(any(Integer.class))).thenReturn(port); //////get into method "build port" when(port.get(any(String.class))).thenReturn(port_temp_buildport); when(port_temp_buildport.asText()).thenReturn(new String("test"))//port id .thenReturn(new String("external"))//port type .thenReturn(new String("00:11:22:33:44:55"))//if(!(port.get("port-mac-address").asText().equals(""))) get in .thenReturn(new String("00:11:22:33:44:55"))//mac address .thenReturn(new String(""));// if(port.get("bandwidth").asText().equals("")) get in when(port.path(any(String.class))).thenReturn(portAttributes); ////////get into method "buildPortAttributes" args(portAttributes) when(portAttributes.size()).thenReturn(1); when(portAttributes.get(any(Integer.class))).thenReturn(portAttribute); ////////// get into method "buildPortAttribute" args(portAttribute) when(portAttribute.path(any(String.class))).thenReturn(port_temp_buildPortAttribute); when(port_temp_buildPortAttribute.asText()).thenReturn(new String("test"))//ATTRIBUTE_NAME .thenReturn(new String("test"));//ATTRIBUTE_VALUE ////return to method "buildnode" and get into method "..............buildNodeAttributes" when(attributes.size()).thenReturn(1); when(attributes.get(any(Integer.class))).thenReturn(portAttribute_father); //////get into method "..............buildNodeAttribute" when(portAttribute_father.path(any(String.class))).thenReturn(attribute_temp_father); when(attribute_temp_father.asText()).thenReturn(new String("test"))//ATTRIBUTE_NAME .thenReturn(new String("test"));//ATTRIBUTE_VALUE result = (List<PhysicalNode>) method.invoke(physicalResourceLoader, nodesRoot); //return empty list Assert.assertTrue(result.size() == 1); verify(port_temp_buildport, times(5)).asText(); verify(attribute_temp_father, times(2)).asText(); }
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
@Test public PhysicalLink testBuildLink(JsonNode arg) throws Exception { if (arg == null) return null; PhysicalLink physicalLink = mock(PhysicalLink.class); JsonNode jsonNode = mock(JsonNode.class); JsonNode jsonNode1 = mock(JsonNode.class); Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildLink", new Class[] { JsonNode.class }); method.setAccessible(true);//from w w w.j a v a 2 s. c om when(jsonNode.get(any(String.class))).thenReturn(jsonNode1).thenReturn(jsonNode1); when(jsonNode1.asText()).thenReturn(new String("test")); when(jsonNode1.asLong()).thenReturn((long) 1); physicalLink = (PhysicalLink) method.invoke(phyConfigLoader, jsonNode); Assert.assertTrue(physicalLink != null); Assert.assertTrue(physicalLink != mock(PhysicalLink.class)); return physicalLink; }
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
@Test public void testBuildLinks() throws Exception { List<PhysicalLink> list; JsonNode hostsNode = mock(JsonNode.class); JsonNode hosts = mock(JsonNode.class); JsonNode jsonNode = mock(JsonNode.class); JsonNode jsonNode1 = mock(JsonNode.class); PhysicalHost physicalHost;//from w ww .j av a 2s .co m Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildLinks", new Class[] { JsonNode.class }); method.setAccessible(true); when(hostsNode.path(any(String.class))).thenReturn(hosts); when(hosts.size()).thenReturn(1); when(hosts.get(any(Integer.class))).thenReturn(jsonNode); when(jsonNode.get(any(String.class))).thenReturn(jsonNode1).thenReturn(jsonNode1); when(jsonNode1.asText()).thenReturn(new String("test")); when(jsonNode1.asLong()).thenReturn((long) 1); list = (List<PhysicalLink>) method.invoke(phyConfigLoader, hostsNode); Assert.assertTrue(list.size() == 1); }
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
public void testBuildPortAttributes() throws Exception { Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildPortAttributes", new Class[] { JsonNode.class }); method.setAccessible(true);/*from ww w. ja va 2s . co m*/ List<Attribute> attributeList; JsonNode attributes = mock(JsonNode.class); JsonNode portAttribute = mock(JsonNode.class); JsonNode jsonNode_temp = mock(JsonNode.class); when(attributes.size()).thenReturn(1); when(attributes.get(any(Integer.class))).thenReturn(portAttribute); //get into method "buildPortAttribute" when(portAttribute.path(any(String.class))).thenReturn(jsonNode_temp); when(jsonNode_temp.asText()).thenReturn(new String(""))//branch null .thenReturn(new String("zm")); attributeList = (List<Attribute>) method.invoke(phyConfigLoader, attributes); Assert.assertTrue(attributeList.size() == 0); //new AttributeName("zm"); attributeList = (List<Attribute>) method.invoke(phyConfigLoader, attributes); Assert.assertTrue(attributeList.size() == 1); verify(portAttribute, times(3)).path(any(String.class)); verify(jsonNode_temp, times(3)).asText(); }
From source file:net.chaosserver.timelord.swingui.engine.BringToFrontThread.java
/** * Trigger an annoy by un-minimizing the window and bringing it to the * front.//from w w w . ja v a 2s.c o m */ protected void annoy() { lastAnnoy = System.currentTimeMillis(); getFrame().setExtendedState(Frame.NORMAL); getFrame().toFront(); getTimelord().showTodayTab(); // This bounces the Dock in Panther/Tiger try { Class<?> nsApplicationClass = Class.forName("com.apple.cocoa.application.NSApplication"); Method sharedAppMethod = nsApplicationClass.getDeclaredMethod("sharedApplication", new Class[] {}); Object nsApplicationObject = sharedAppMethod.invoke(null, new Object[] {}); Field userAttentionRequestCriticalField = nsApplicationClass .getDeclaredField("UserAttentionRequestCritical"); Method requestUserAttentionMethod = nsApplicationClass.getDeclaredMethod("requestUserAttention", new Class[] { userAttentionRequestCriticalField.getType() }); requestUserAttentionMethod.invoke(nsApplicationObject, new Object[] { userAttentionRequestCriticalField.get(null) }); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Issue bouncing dock", e); } } if (log.isTraceEnabled()) { log.trace("Bringing Window to Front"); } }
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
@Test public void testBuildExternals() throws Exception { JsonNode externalRoot = mock(JsonNode.class); JsonNode exNetworkNodes = mock(JsonNode.class); JsonNode exNetworkNode = mock(JsonNode.class); JsonNode jsonNode = mock(JsonNode.class); String nodeId = new String("1"); String portId = new String("2"); String peerMac = new String("00:11:22:33:44:55"); Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildExternals", new Class[] { JsonNode.class }); method.setAccessible(true);/*from w w w .jav a 2s . c o m*/ when(externalRoot.path(any(String.class))).thenReturn(exNetworkNodes); when(exNetworkNodes.size()).thenReturn(1); when(exNetworkNodes.get(any(Integer.class))).thenReturn(exNetworkNode); //get into method "buildExNetwork" when(exNetworkNode.get(any(String.class))).thenReturn(jsonNode); when(jsonNode.asText()).thenReturn(nodeId).thenReturn(portId).thenReturn(peerMac); method.invoke(phyConfigLoader, externalRoot); verify(externalRoot).path(any(String.class)); verify(exNetworkNodes, times(2)).size(); verify(exNetworkNodes).get(any(Integer.class)); verify(exNetworkNode, times(3)).get(any(String.class)); verify(jsonNode, times(3)).asText(); }
From source file:net.sourceforge.fullsync.cli.Main.java
@Override public void launchGui(Injector injector) throws Exception { String arch = "x86"; //$NON-NLS-1$ String osName = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$ String os = "unknown"; //$NON-NLS-1$ if (-1 != System.getProperty("os.arch").indexOf("64")) { //$NON-NLS-1$ //$NON-NLS-2$ arch = "x86_64"; //$NON-NLS-1$ }/*from www .jav a2s .c o m*/ if (-1 != osName.indexOf("linux")) { //$NON-NLS-1$ os = "gtk.linux"; //$NON-NLS-1$ } else if (-1 != osName.indexOf("windows")) { //$NON-NLS-1$ os = "win32.win32"; //$NON-NLS-1$ } else if (-1 != osName.indexOf("mac")) { //$NON-NLS-1$ os = "cocoa.macosx"; //$NON-NLS-1$ } CodeSource cs = getClass().getProtectionDomain().getCodeSource(); String libDirectory = cs.getLocation().toURI().toString().replaceAll("^(.*)/[^/]+\\.jar$", "$1/"); //$NON-NLS-1$ //$NON-NLS-2$ List<URL> jars = new ArrayList<>(); jars.add(new URL(libDirectory + "net.sourceforge.fullsync-fullsync-assets.jar")); //$NON-NLS-1$ jars.add(new URL(libDirectory + "net.sourceforge.fullsync-fullsync-ui.jar")); //$NON-NLS-1$ // add correct SWT implementation to the class-loader jars.add(new URL(libDirectory + String.format("org.eclipse.platform-org.eclipse.swt.%s.%s.jar", os, arch))); //$NON-NLS-1$ // instantiate an URL class-loader with the constructed class-path and load the UI URLClassLoader cl = new URLClassLoader(jars.toArray(new URL[jars.size()]), Main.class.getClassLoader()); Thread.currentThread().setContextClassLoader(cl); Class<?> cls = cl.loadClass("net.sourceforge.fullsync.ui.GuiController"); //$NON-NLS-1$ Method launchUI = cls.getDeclaredMethod("launchUI", Injector.class); //$NON-NLS-1$ launchUI.invoke(null, injector); }