List of usage examples for java.lang.reflect Method setAccessible
@Override @CallerSensitive public void setAccessible(boolean flag)
From source file:io.riox.springxd.sinks.websocket.WebsocketSinkTests.java
@Test public void testMultiplePaths() throws Exception { final List<String> messages1 = new ArrayList<String>(); final List<String> messages2 = new ArrayList<String>(); Field f1 = WebsocketSink.class.getDeclaredField("port"); f1.setAccessible(true);/*from w w w . j a va 2s .c om*/ Field f2 = WebsocketSink.class.getDeclaredField("path"); f2.setAccessible(true); WebsocketSink sink1 = configs.get(0).sink; WebsocketSink sink2 = configs.get(1).sink; Method m1 = WebsocketSink.class.getDeclaredMethod("input"); m1.setAccessible(true); final MessageChannel channel1 = (MessageChannel) m1.invoke(sink1); final MessageChannel channel2 = (MessageChannel) m1.invoke(sink2); URI uri1 = new URI("http://localhost:" + configs.get(0).port + configs.get(0).path); URI uri2 = new URI("http://localhost:" + configs.get(1).port + configs.get(1).path); URI uri3 = new URI("http://localhost:" + configs.get(1).port + "/invalid_path"); /* create WS clients */ final int numMsg1 = 2000; final int numMsg2 = 3000; final CountDownLatch connectLatch = new CountDownLatch(3); final CountDownLatch messagesLatch = new CountDownLatch(numMsg1 + numMsg2); WebSocketClient c1 = new WebSocketClient(uri1) { public void onMessage(String msg) { messages1.add(msg); messagesLatch.countDown(); } public void onClose(int arg0, String arg1, boolean arg2) { } public void onError(Exception e) { } public void onOpen(ServerHandshake arg0) { connectLatch.countDown(); } }; c1.connect(); WebSocketClient c2 = new WebSocketClient(uri2) { public void onMessage(String msg) { messages2.add(msg); messagesLatch.countDown(); } public void onClose(int arg0, String arg1, boolean arg2) { } public void onError(Exception e) { } public void onOpen(ServerHandshake arg0) { connectLatch.countDown(); } }; c2.connect(); WebSocketClient c3 = new WebSocketClient(uri3) { public void onMessage(String msg) { messagesLatch.countDown(); } public void onClose(int arg0, String arg1, boolean arg2) { } public void onError(Exception e) { e.printStackTrace(); } public void onOpen(ServerHandshake arg0) { connectLatch.countDown(); } }; c3.connect(); connectLatch.await(1, TimeUnit.SECONDS); /* send test messages */ new Thread() { public void run() { for (int i = 0; i < numMsg1; i++) { channel1.send(new GenericMessage<String>("foo")); } } }.start(); new Thread() { public void run() { for (int i = 0; i < numMsg2; i++) { channel2.send(new GenericMessage<String>("bar")); } } }.start(); /* assertions */ assertTrue(messagesLatch.await(5, TimeUnit.SECONDS)); assertEquals(numMsg1, messages1.size()); assertEquals(numMsg2, messages2.size()); for (String m : messages1) { assertEquals("foo", m); } for (String m : messages2) { assertEquals("bar", m); } }
From source file:com.app.test.mail.SendGridMailSenderTest.java
@Test public void testPopulateContactMessage() throws Exception { Method populateContactMessageMethod = _clazz.getDeclaredMethod("_populateContactMessage", String.class, String.class); populateContactMessageMethod.setAccessible(true); Mail mail = (Mail) populateContactMessageMethod.invoke(_classInstance, "user@test.com", "Sample contact message"); Assert.assertEquals("You Have A New Message From user@test.com", mail.getSubject()); List<Content> mailContent = mail.getContent(); Content content = mailContent.get(0); Assert.assertEquals("text/html", content.getType()); Assert.assertEquals("Sample contact message", content.getValue()); }
From source file:net.sf.ehcache.openjpa.datacache.TestEhCache.java
private void evictAllOfType(final Class<?> aClass, final boolean subClasses) { EntityManagerFactory emf = em.getEntityManagerFactory(); OpenJPAEntityManagerFactory openJPAEntityManagerFactory = OpenJPAPersistence.cast(emf); DataCache cache = ((StoreCacheImpl) openJPAEntityManagerFactory.getStoreCache()).getDelegate(); if (cache instanceof EhCacheDataCache) { EhCacheDataCache ehCache = (EhCacheDataCache) cache; try {//w ww . java 2 s . com Method method = EhCacheDataCache.class.getDeclaredMethod("removeAllInternal", Class.class, Boolean.TYPE); method.setAccessible(true); method.invoke(ehCache, aClass, subClasses); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.hp.mqm.clt.CliParserTest.java
@Test public void testArgs_duplicates() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ParseException, IOException { CliParser cliParser = new CliParser(); Method argsValidation = cliParser.getClass().getDeclaredMethod("areCmdArgsValid", CommandLine.class); argsValidation.setAccessible(true); CommandLineParser parser = new DefaultParser(); CommandLine cmdArgs = parser.parse(options, new String[] { "-r", "1", "test.xml" }); Boolean result = (Boolean) argsValidation.invoke(cliParser, cmdArgs); Assert.assertTrue(result);//from ww w . j a v a 2 s .c om cmdArgs = parser.parse(options, new String[] { "-r", "1", "-r", "2", "test.xml" }); result = (Boolean) argsValidation.invoke(cliParser, cmdArgs); Assert.assertFalse(result); cmdArgs = parser.parse(options, new String[] {}); result = (Boolean) argsValidation.invoke(cliParser, cmdArgs); Assert.assertFalse(result); File outputFolder = temporaryFolder.newFolder(); cmdArgs = parser.parse(options, new String[] { "--output-file", outputFolder.getPath() + File.separator + "testResults.xml", "JUnit1.xml", "JUnit2.xml" }); result = (Boolean) argsValidation.invoke(cliParser, cmdArgs); Assert.assertFalse(result); cmdArgs = parser.parse(options, new String[] { "--output-file", outputFolder.getPath() + File.separator + "testResults.xml", "JUnit.xml" }); result = (Boolean) argsValidation.invoke(cliParser, cmdArgs); Assert.assertTrue(result); }
From source file:com.app.test.mail.SendGridMailSenderTest.java
@Test public void testPopulateAccountDeletionMessage() throws Exception { _initializeVelocityTemplate(_clazz, _classInstance); Method populateMessageMethod = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class, String.class); populateMessageMethod.setAccessible(true); Mail mail = (Mail) populateMessageMethod.invoke(_classInstance, "user@test.com", "Account Deletion Successful", "account_deletion_email.vm"); Assert.assertEquals("Account Deletion Successful", mail.getSubject()); List<Content> mailContent = mail.getContent(); Content content = mailContent.get(0); Assert.assertEquals("text/html", content.getType()); Assert.assertEquals(_ACCOUNT_DELETION_EMAIL, content.getValue()); }
From source file:com.app.test.mail.SendGridMailSenderTest.java
@Test public void testPopulateCancellationMessage() throws Exception { _initializeVelocityTemplate(_clazz, _classInstance); Method populateMessageMethod = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class, String.class); populateMessageMethod.setAccessible(true); Mail mail = (Mail) populateMessageMethod.invoke(_classInstance, "user@test.com", "Cancellation Successful", "cancellation_email.vm"); Assert.assertEquals("Cancellation Successful", mail.getSubject()); List<Content> mailContent = mail.getContent(); Content content = mailContent.get(0); Assert.assertEquals("text/html", content.getType()); Assert.assertEquals(_CANCELLATION_EMAIL, content.getValue()); }
From source file:com.app.test.mail.SendGridMailSenderTest.java
@Test public void testPopulateCardDetailsMessage() throws Exception { _initializeVelocityTemplate(_clazz, _classInstance); Method populateMessageMethod = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class, String.class); populateMessageMethod.setAccessible(true); Mail mail = (Mail) populateMessageMethod.invoke(_classInstance, "user@test.com", "Card Details Updated", "card_details_email.vm"); Assert.assertEquals("Card Details Updated", mail.getSubject()); List<Content> mailContent = mail.getContent(); Content content = mailContent.get(0); Assert.assertEquals("text/html", content.getType()); Assert.assertEquals(_CARD_DETAILS_EMAIL, content.getValue()); }
From source file:com.app.test.mail.SendGridMailSenderTest.java
@Test public void testPopulatePaymentFailedMessage() throws Exception { _initializeVelocityTemplate(_clazz, _classInstance); Method populateMessageMethod = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class, String.class); populateMessageMethod.setAccessible(true); Mail mail = (Mail) populateMessageMethod.invoke(_classInstance, "user@test.com", "Payment Failed", "payment_failed_email.vm"); Assert.assertEquals("Payment Failed", mail.getSubject()); List<Content> mailContent = mail.getContent(); Content content = mailContent.get(0); Assert.assertEquals("text/html", content.getType()); Assert.assertEquals(_PAYMENT_FAILED_EMAIL, content.getValue()); }
From source file:com.app.test.mail.SendGridMailSenderTest.java
@Test public void testPopulateResubscribeMessage() throws Exception { _initializeVelocityTemplate(_clazz, _classInstance); Method populateMessageMethod = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class, String.class); populateMessageMethod.setAccessible(true); Mail mail = (Mail) populateMessageMethod.invoke(_classInstance, "user@test.com", "Resubscribe Successful", "resubscribe_email.vm"); Assert.assertEquals("Resubscribe Successful", mail.getSubject()); List<Content> mailContent = mail.getContent(); Content content = mailContent.get(0); Assert.assertEquals("text/html", content.getType()); Assert.assertEquals(_RESUBSCRIBE_EMAIL, content.getValue()); }
From source file:com.app.test.mail.SendGridMailSenderTest.java
@Test public void testPopulateWelcomeMessage() throws Exception { _initializeVelocityTemplate(_clazz, _classInstance); Method populateMessageMethod = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class, String.class); populateMessageMethod.setAccessible(true); Mail mail = (Mail) populateMessageMethod.invoke(_classInstance, "user@test.com", "Welcome", "welcome_email.vm"); Assert.assertEquals("Welcome", mail.getSubject()); List<Content> mailContent = mail.getContent(); Content content = mailContent.get(0); Assert.assertEquals("text/html", content.getType()); Assert.assertEquals(_WELCOME_EMAIL, content.getValue()); }