List of usage examples for java.lang.reflect Method setAccessible
@Override @CallerSensitive public void setAccessible(boolean flag)
From source file:org.apache.pulsar.client.api.AuthenticationTlsHostnameVerificationTest.java
/** * This test verifies {@link DefaultHostnameVerifier} behavior and gives fair idea about host matching result * * @throws Exception/* www. ja va 2s .c o m*/ */ @Test public void testDefaultHostVerifier() throws Exception { log.info("-- Starting {} test --", methodName); Method matchIdentityStrict = DefaultHostnameVerifier.class.getDeclaredMethod("matchIdentityStrict", String.class, String.class, PublicSuffixMatcher.class); matchIdentityStrict.setAccessible(true); Assert.assertTrue((boolean) matchIdentityStrict.invoke(null, "pulsar", "pulsar", null)); Assert.assertFalse((boolean) matchIdentityStrict.invoke(null, "pulsar.com", "pulsar", null)); Assert.assertTrue((boolean) matchIdentityStrict.invoke(null, "pulsar-broker1.com", "pulsar*.com", null)); // unmatched remainder: "1-broker." should not contain "." Assert.assertFalse((boolean) matchIdentityStrict.invoke(null, "pulsar-broker1.com", "pulsar*com", null)); Assert.assertFalse((boolean) matchIdentityStrict.invoke(null, "pulsar.com", "*", null)); log.info("-- Exiting {} test --", methodName); }
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); 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 a v a 2 s . 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:de.thkwalter.et.schlupfbezifferung.SchlupfbezifferungControllerTest.java
/** * Test der Methode {@link SchlupfbezifferungController#schlupfbezifferungBestimmenIntern()}. * /* w w w . ja v a2s . c om*/ * @throws SecurityException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalArgumentException * @throws IllegalAccessException */ @Test public void testSchlupfbezifferungBestimmenIntern() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Die zu testende Methode wird aufgerufen. Method methode = SchlupfbezifferungController.class.getDeclaredMethod("schlupfbezifferungBestimmenIntern", (Class<?>[]) null); methode.setAccessible(true); methode.invoke(this.schlupfbezifferungController, (Object[]) null); // Es wird berprft, ob das berechnete Inversionszentrum (in A) korrekt berechnet und im Datenmodell der // Schlupfbezifferungsbestimmung gespeichert worden ist. assertEquals(9.257, this.testSchlupfbezifferungModell.getInversionszentrum().getX(), 9.257 / 1000.0); assertEquals(-1.339, this.testSchlupfbezifferungModell.getInversionszentrum().getY(), 1.339 / 1000.0); // Es wird berprft, ob der Drehpunkt der Schlupfgeraden (inA) korrekt berechnet und im Datenmodell der // Schlupfbezifferungsbestimmung gespeichert worden ist. assertEquals(6.077, this.testSchlupfbezifferungModell.getDrehpunktSchlupfgerade().getX(), 6.077 / 1000.0); assertEquals(-2.656, this.testSchlupfbezifferungModell.getDrehpunktSchlupfgerade().getY(), 2.656 / 1000.0); }
From source file:com.app.test.util.SearchResultUtilTest.java
@Test public void testAddNewResults() throws Exception { _addSearchResult("1234"); List<SearchResult> searchResults = SearchResultUtil.getSearchQueryResults(_SEARCH_QUERY_ID); Method method = _clazz.getDeclaredMethod("_addNewResults", List.class); method.setAccessible(true); method.invoke(_classInstance, searchResults); searchResults = SearchResultUtil.getSearchQueryResults(_SEARCH_QUERY_ID); SearchResult searchResult = searchResults.get(0); Assert.assertEquals(_SEARCH_QUERY_ID, searchResult.getSearchQueryId()); Assert.assertEquals("1234", searchResult.getItemId()); Assert.assertEquals("First Item", searchResult.getItemTitle()); Assert.assertEquals("$10.00", searchResult.getAuctionPrice()); Assert.assertEquals("$14.99", searchResult.getFixedPrice()); Assert.assertEquals("http://www.ebay.com/itm/1234", searchResult.getItemURL()); Assert.assertEquals("http://www.ebay.com/123.jpg", searchResult.getGalleryURL()); Assert.assertEquals(1, SearchQueryPreviousResultUtil.getSearchQueryPreviousResultsCount(_SEARCH_QUERY_ID)); }
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
@Test public void testGetPhysicalNode() throws Exception { PhysicalNodeId physicalNodeId = mock(PhysicalNodeId.class); PhysicalNode physicalNode;//from ww w . j a v a 2s . c o m Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("getPhysicalNode", new Class[] { PhysicalNodeId.class }); method.setAccessible(true); physicalNode = (PhysicalNode) method.invoke(phyConfigLoader, physicalNodeId); Assert.assertTrue(physicalNode == null); }
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
@Test public void testGetPhysicalPort() throws Exception { PhysicalPortId physicalPortId = mock(PhysicalPortId.class); PhysicalPort physicalPort;/* w ww . j a va2 s .com*/ Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("getPhysicalPort", new Class[] { PhysicalPortId.class }); method.setAccessible(true); physicalPort = (PhysicalPort) method.invoke(phyConfigLoader, physicalPortId); Assert.assertTrue(physicalPort == null); }
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 w w w .j a v a2 s .c om 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:io.stallion.plugins.javascript.JavaToJsHelpers.java
private Object getDebugSupport() { //return new NashornDebugHelper(); try {/*ww w .j a va2 s. c o m*/ Class<?> c = Class.forName("jdk.nashorn.internal.runtime.DebuggerSupport");//full package name //note: getConstructor() can return only public constructors, //you need to use Method method = c.getDeclaredMethod("eval", ScriptObject.class, Object.class, String.class, boolean.class); //Constructor<?> constructor = c.getDeclaredConstructor(); method.setAccessible(true); return method; //constructor.setAccessible(true); //Object o = constructor.newInstance(null); //return o; } catch (Exception e) { Log.error(e); return null; } }
From source file:io.stallion.plugins.javascript.JavaToJsHelpers.java
public Object eval(ScriptObject o, Object scope, String source, boolean returnStuff) { if (!Settings.instance().getLocalMode()) { Log.error("You can only call 'eval' in local mode"); return ""; }//w w w .j a va 2s. co m try { //new jdk.nashorn.internal.runtime.DebugLogger(). Class<?> c = Class.forName("jdk.nashorn.internal.runtime.DebuggerSupport");//full package name //note: getConstructor() can return only public constructors, //you need to use Method method = c.getDeclaredMethod("eval", ScriptObject.class, Object.class, String.class, boolean.class); //Constructor<?> constructor = c.getDeclaredConstructor(); method.setAccessible(true); return method.invoke(null, o, scope, source, returnStuff); } catch (Exception e) { Log.error(e); return null; } }