junit

junit test cases using embed mongodb de.flapdoodle.embed.mongo

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 04:16:06
问题 I wanted to setup mongodb junit environment with flapdoodle and I got a java.io.IOException when it tries to download the mongodb archive. I am using: spring-data-mongodb: 1.6.1.RELEASE de.flapdoodle.embed.mongo 1.47.3 org.springframework: 4.0.3.RELEASE I am getting following error: de.flapdoodle.embed.process.exceptions.DistributionException: java.io.IOException: Could not open inputStream for http://downloads.mongodb.org/win32/mongodb-win32-i386-3.0.2.zip Caused by: java.net

How to junit return type of a method in spring mvc controller

☆樱花仙子☆ 提交于 2020-01-03 04:07:26
问题 I am doing junit on my Spring MVC controller - @RequestMapping(value = "index", method = RequestMethod.GET) public HashMap<String, String> handleRequest() { HashMap<String, String> model = new HashMap<String, String>(); String name = "Hello World"; model.put("greeting", name); return model; } And below is my junit for the above method - public class ControllerTest { private MockMvc mockMvc; @Before public void setup() throws Exception { this.mockMvc = standaloneSetup(new Controller()).build()

Cannot create a secure XMLInputFactory

纵然是瞬间 提交于 2020-01-03 03:35:08
问题 Hello all, My application is based on PTV xServer modules and it is used of calculating best route and trip plan. It is a web application and I am using tomcat for it. So while running my application with tomcat it works find but when I executed this application with "main" method then I am getting error while calling xServer modules services/methods. com.ptvag.jabba.core.exception.UnexpectedException: Cannot create a secure XMLInputFactory at com.ptvag.jabba.core.exception.ExceptionAnalyzer

Get custom method annotation value from junit test

你离开我真会死。 提交于 2020-01-03 03:34:28
问题 I have a junit test where I'd like to use an annotation on methods to define test settings. I have a super class of the test class where I have abstracted some processing and where I'd like to read the method annotation values. I have seen examples of reading method annotations by looping over a class. I'm not sure this will work for what I need. How do I find which test method was called and then read those specific annotation values (TrialMethod.name)? public class MyUTest extends Processor

How to test JavaMailSender?

谁说胖子不能爱 提交于 2020-01-03 01:41:48
问题 I have little problem. I created MailService to send mails. When I run program, it works. All properties to email I have in resources/application.properties . I'm using spring-boot-starter-mail . @Service public class MailService { private JavaMailSender javaMailSender; @Autowired public MailService(JavaMailSender javaMailSender) { this.javaMailSender = javaMailSender; } public void sendMail(String subject, String messageContent, String recipient) throws MessagingException { MimeMessage

No test run when running maven test command

青春壹個敷衍的年華 提交于 2020-01-03 01:12:28
问题 There is a maven project hosted by someone else, which has src/main directory and src/test directory. The src/test dir contains a java file ending with Test , I'll just call it ATest.java , and the class ATest only contains a static void main function. It is like //omitted public class ATest { public static void main(String[] args) throws Exception { BTester.main(null); CTester.main(null); } } where BTester and CTester are both files under directory src/main/java/<package_path>/tester When I

How to get server port in spring boot test

一曲冷凌霜 提交于 2020-01-02 20:10:29
问题 I have Spring Boot 1.5.3 application. There is a line server.port = 8081 in application.properties file. Now I want to test ping method: private final Environment environment; @Autowired public ServerCommunicateServiceImpl(Environment environment) { this.environment = environment; } @Override public boolean pingHost(String host) { int port = environment.getProperty("server.port", Integer.class, DEFAULT_PORT); return pingHost(host, port, DEFAULT_TIMEOUT); } Test: @RunWith(SpringRunner.class)

writing test case for a DAO on a J2ee Application

随声附和 提交于 2020-01-02 10:08:35
问题 I am trying to write some test cases for my DAO classes in a J2EE applications. Methods in my DAO classes try to get connection to the Database based on a JDBC URL (which is on the app server). So from the front end if I click bunch of stuff and make the DAO trigger it runs fine. However, when I write tests cases for the DAO and the DAO object calls the method then it is not able to get the connection to the database. I think since the JDBC resource is on the App server that is why it is not

How to mock a call of an inner method from a Junit

自闭症网瘾萝莉.ら 提交于 2020-01-02 09:27:38
问题 I have MyClass and I am doing a test-class for every method (Method1Test) public class MyClass { public int method1(){ int a = method2(); return a; } public int method2(){ return 0; } } @RunWith(MockitoJUnitRunner.class) public class Method1Test { @InjectMocks private MyClass myClass = new MyClass(); @Before public void setup(){} @Test public void test01(){ Mockito.when(myClass.method2()).thenReturn(25); int a = myClass.method1(); assertTrue("We did it!!!",a==25); } } The problem is that I am

Jmeter: Using jmeter Junit Request with variables

感情迁移 提交于 2020-01-02 09:03:49
问题 As I said in the question, is it possible to pass jmeter variables (passed through -J) into a JUnit Request in order that it can be used internally to the junit test? It sounds feasible as the Apache Junit Request docs indicate that: ... JMeter currently runs the test methods directly, rather than leaving it to JUnit. ... This would indicate that jmeter could control passing parameters but I've found no supporting documentation and there's no obvious mechanism through the JUnit Request