250+ TOP MCQs on Integration Testing and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Integration Testing”.

1. Base class to access the managed application context through the inherited getApplicationContext() method.
a) AbstractSingleSpringContextTests
b) AbstractSingleSpring
c) Test context listener
d) Test execution listener

Answer: a
Clarification: With Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractSingleSpringContextTests base class to access the managed application context through the inherited getApplicationContext() method.

2. The TestContext framework provides two test execution listeners related to context management:-
a) DependencyInjectionTestExecutionListener
b) DirtiesContextTestExecutionListener
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: They will be registered with a test context manager by default if you don’t specify your own explicitly.
• DependencyInjectionTestExecutionListener: This injects dependencies, including
the managed application context, into your tests.
• DirtiesContextTestExecutionListener: This handles the @DirtiesContext
annotation and reloads the application context when necessary.

3. Interface which can provide access to the managed application context through the protected field applicationContext
a) ApplicationContextAware
b) ApplicationContext
c) ApplicationContextAwareContext
d) None of the mentioned

Answer: a
Clarification: These classes integrate with a test context manager and implement the ApplicationContextAware interface, so they can provide access to the managed application context through the protected field applicationContext.

4. In JUnit 4, you can simply run your test with the test runner SpringJUnit4ClassRunner.
a) True
b) False

Answer: a
Clarification: In JUnit 4, you can simply run your test with the test runner SpringJUnit4ClassRunner to have a test context manager integrated. However, in TestNG, you have to integrate with a test context manager manually.

5. Method to indicate that the application context is dirty.
a) getDirty()
b) setDirty()
c) all of the mentioned
d) none of the mentioned

Answer: b
Clarification: You can call the setDirty() method to indicate that the application context is dirty so that it will be reloaded automatically for the next test method.

6. In JUnit4, to explicitly specify a Spring-specific test runner for running your test.
a) SpringJUnit4ClassRunner
b) SpringJUnit4Class
c) SpringJUnit4
d) None of the mentioned

Answer: a
Clarification: You have to explicitly specify a Spring-specific test runner for running your test—SpringJUnit4ClassRunner.

7. Annotation for SpringJUnit4ClassRunner:-
a) @Run
b) @RunWith
c) All of the mentioned
d) None of the mentioned

Answer: b
Clarification: For this option, you have to explicitly specify a Spring-specific test runner for running your test—SpringJUnit4ClassRunner. You can specify this in the @RunWith annotation at the class level.

8. This class implements the ApplicationContextAware interface, so you can get access to the managed application context:-
a) AbstractJUnit38SpringContext
b) AbstractJUnit38Spring
c) AbstractJUnit38SpringContextTests
d) None of the mentioned

Answer: c
Clarification: This class implements the ApplicationContextAware interface, so you can get access to the managed application context via the protected field applicationContext.

9. AbstractJUnit38SpringContext class also implements the ApplicationContextAware interface.
a) True
b) False

Answer: b
Clarification: AbstractTestNGSpringContextTests class also implements the ApplicationContextAware interface.

10. Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the:-
a) AbstractDependencyInjectionSpringContextTests
b) AbstractSingleSpringContextTests
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: When using Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractDependencyInjectionSpringContextTests base class, which is a subclass of AbstractSingleSpringContextTests, to have its test fixtures injected automatically.

11. AbstractDependencyInjectionSpringContextTests supports dependency injection.
a) auto-wires beans by type via setter methods
b) auto-wires beans by name via protected fields
c) none of the mentioned
d) all of the mentioned

Answer: c
Clarification: When using Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractDependencyInjectionSpringContextTests base class, which is a subclass of AbstractSingleSpringContextTests, to have its test fixtures injected automatically.

12. Test fixtures injected from the managed application context by annotating:-
a) @Autowired
b) @Resource
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: When using the TestContext framework to create tests, you can have their test fixtures injected from the managed application context by annotating a field or setter method with the @Autowired or @Resource annotations.

13. TestContext support class AbstractJUnit4SpringContextTests, you can also have test fixtures injected from the managed application context.
a) True
b) False

Answer: a
Clarification: By extending the TestContext support class AbstractJUnit4SpringContextTests, you can also have test fixtures injected from the managed application context. In this case, you don’t need to specify SpringJUnit4ClassRunner for your test, as it is inherited from the parent.

14. Starting from Spring 2.5, the TestContext framework provides a test execution listener related to transaction management:-
a) TransactionalTestExecutionListener
b) TransactionalTestExecution
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: It will be registered with a test context manager by default if you don’t specify your own explicitly.

15. Annotation for TransactionalTestExecutionListener:-
a) @Transactional
b) @RunWith
c) @Run
d) None of the mentioned

Answer: a
Clarification: TransactionalTestExecutionListener: This handles the @Transactional annotation at the class or method level and has the methods run within transactions automatically.

250+ TOP MCQs on JMS Messages and Transactions and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “JMS Messages and Transactions”.

1. Template which can send and receive JMS messages with much less code
a) JmsTemplate
b) EMail
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: With a JMS template (Spring framework class JmsTemplate), you can send and receive JMS messages with much less code.

2. The template handles the boilerplate tasks for you and also converts the JMS API JMSException hierarchy into Spring runtime exception:-
a) org.springframework.jms.Jms
b) org.springframework.jms.JmsException
c) org.springframework.jms.JmsTemplate
d) none of the mentioned
Answer: b
Clarification: The translation converts exceptions to a mirrored hierarchy of unchecked exceptions.

3. To address different JMS APIs, Spring provides :-
a) JmsTemplate
b) JmsTemplate102
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: To address different JMS APIs, Spring provides two JMS template classes, JmsTemplate and JmsTemplate102, for these two versions of JMS.

4. Before you can send and receive JMS messages, you need to install a JMS message broker:-
a) Apache ActiveM
b) Apache Active
c) Apache MQ
d) Apache ActiveMQ
Answer: d
Clarification: Before you can send and receive JMS messages, you need to install a JMS message broker. For simplicity’s sake, we have chosen Apache ActiveMQ (http://activemq.apache.org/) as our message broker, which is very easy to install and configure.

5. In the preceding sendMail() method, you first create JMS-specific ConnectionFactory.

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
public class FrontDeskImpl implements FrontDesk {
	public void sendMail(Mail mail) {
		ConnectionFactory cf =
		new ActiveMQConnectionFactory("tcp://localhost:61616");
		Destination destination = new ActiveMQQueue("mail.queue");
		Connection conn = null;
		try {
			conn = cf.createConnection();
			Session session =
			conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
			MessageProducer producer = session.createProducer(destination);
			MapMessage message = session.createMapMessage();
			message.setString("mailId", mail.getMailId());
			message.setString("country", mail.getCountry());
			message.setDouble("weight", mail.getWeight());
			producer.send(message);
			session.close();
			} catch (JMSException e) {
				throw new RuntimeException(e);
			} finally {
				if (conn != null) {
				try {
				conn.close();
				} catch (JMSException e) {
				}
			}
		}
	}
}

a) True
b) False
Answer: a
Clarification: In the preceding sendMail() method, you first create JMS-specific ConnectionFactory and Destination objects with the classes provided by ActiveMQ.

6.In JMS, there are two types of destinations:-

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
public class FrontDeskImpl implements FrontDesk {
	public void sendMail(Mail mail) {
		ConnectionFactory cf =
		new ActiveMQConnectionFactory("tcp://localhost:61616");
		Destination destination = new ActiveMQQueue("mail.queue");
		Connection conn = null;
		try {
			conn = cf.createConnection();
			Session session =
			conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
			MessageProducer producer = session.createProducer(destination);
			MapMessage message = session.createMapMessage();
			message.setString("mailId", mail.getMailId());
			message.setString("country", mail.getCountry());
			message.setDouble("weight", mail.getWeight());
			producer.send(message);
			session.close();
			} catch (JMSException e) {
				throw new RuntimeException(e);
			} finally {
				if (conn != null) {
				try {
				conn.close();
				} catch (JMSException e) {
				}
			}
		}
	}
}

a) topic
b) queue
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: The message broker URL is the default for ActiveMQ if you run it on localhost. In JMS, there are two types of destinations: queue and topic. As explained before, a queue is for the point-to-point communication model, while topic is for the publish-subscribe communication model.

7. There are several types of messages defined in the JMS API, including:-
a) TextMessage
b) MapMessage
c) BytesMessage
d) All of the mentioned
Answer: d
Clarification: There are several types of messages defined in the JMS API, including TextMessage, MapMessage, BytesMessage, ObjectMessage, and StreamMessage.

8. To send a JMS message with this template, you simply call:-
a) send
b) sendTo
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: To send a JMS message with this template, you simply call the send() method and provide a message destination, as well as a MessageCreator object, which creates the JMS message you are going to send.

9. The MessageCreator interface declares method:-
a) createMessage()
b) create()
c) createMsg()
d) none of the mentioned
Answer: a
Clarification: The MessageCreator interface declares only a createMessage() method for you to implement.

10. A JMS template helps you to obtain and release the JMS connection and session.
a) True
b) False
Answer: a
Clarification: A JMS template helps you to obtain and release the JMS connection and session, and it sends the JMS message created by your MessageCreator object.

11. JMS sender and receiver classes can also extend to retrieve a JMS template:-
a) JmsGatewaySupport
b) JmsGateway
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: Just like your DAO class can extend JdbcDaoSupport to retrieve a JDBCtemplate, your JMS sender and receiver classes can also extend JmsGatewaySupport to retrieve a JMS template.

12. When you need access to the JMS template.
a) setJmsTemplate
b) getJmsTemplate
c) getJms
d) none of the mentioned
Answer: b
Clarification: When you need access to the JMS template, you just make a call to getJmsTemplate().

13. Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received.
a) True
b) False
Answer: a
Clarification: Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received to a business object and the translation of a business object to a JMS message.

14. By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string.
a) True
b) False
Answer: a
Clarification: By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string, BytesMessage to or from a byte array, MapMessage to or from a map, and ObjectMessage to or from a serializable object.

15. For your front desk and back office classes, you can send and receive a map using the:-
a) convertAndSend()
b) receiveAndConvert()
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: For your front desk and back office classes, you can send and receive a map using the convertAndSend() and receiveAndConvert() methods, and the map will be converted to/from MapMessage.

250+ TOP MCQs on SpringSource dm Server and Toolings and Answers

Tough JavaSpring questions and answers on “Spring Source dm Server and Toolings”.

1. Support for deployment of traditional .war artifacts, enable use of some of the standard Java EE libraries, provide useful defaults for many de facto standard libraries, and provide fully integrated support for Spring Dynamic Modules.
a) Spring Dynamic Modules
b) Spring dm Server
c) Spring Tooling
d) All of the mentioned
Answer: b
Clarification: Use Spring dm Server, SpringSource’s tried and true OSGi–oriented server built on many technologies including Equinox and the Spring framework itself.

2. OSGi doesn’t solve framework concerns, instead focusing on infrastructure requirements for Java applications.
a) True
b) False
Answer: a
Clarification: Spring Dynamic Modules provides functionality that sits on top of those implementations, providing very powerful runtime sophistication for developers looking to produce and consume OSGi services in a Spring-friendly fashion.

3 Spring Dynamic Modules was, while powerful for those already invested in an OSGi platform, not the most natural accommodations for those trying to migrate large code into the OSGi environment, SpringSource created.
a) Spring Dynamic Modules
b) Spring dm Server
c) Spring Tooling
d) All of the mentioned
Answer: b
Clarification: SpringSource dm Server is a robust solution. There are several editions available.

4. SpringSource dm Server many advances focus on delivering a solution, and not just a framework, for delivering:-
a) Spring Tooling
b) Spring dm
c) OSGi
d) None of the mentioned
Answer: c
Clarification: SpringSource dm Server many advances focus on delivering a solution, and not just a framework, for delivering OSGi–based enterprise applications.

5. SpringSource dm Server provides value above and beyond a regular OSGi solution.
a) True
b) False
Answer: a
Clarification: It’s already well integrated.

6 OSGi–enabling all of these interwoven dependencies via the granular use of the Import-Package header would be tedious.
a) True
b) False
Answer: a
Clarification: Spring dm Server provides the ability to wholesale import an entire library and all packages therein to expedite the process.

7. SpringSource dm Server also allows you to bend the rules where necessary.
a) True
b) False
Answer: a
Clarification: For example, consider the application of an aspect using Spring’s AOP. This might require weaving of classes, which in the case of a pointcut that matches classes deployed across multiple bundles, would prove cumbersome. SpringSource dm Server can intervene on Spring’s behalf, propagating such changes across multiple bundles where necessary.

8. SpringSource dm Server works with several types of deployment formats:-
a) bundle
b) Java EE .war
c) platform archive
d) all of the mentioned
Answer: d
Clarification: SpringSource dm Server works with four types of deployment formats.

9. Application isolation is critical because it allows you to solve the issue of reconciliation of two services whose interfaces collide. You can use:-
a) .WAR
b) .XML
c) .PAR
d) All of the mentioned
Answer: c
Clarification: You can use a .PAR to isolate services within the deployment unit.

10. SpringSource dm Server provides the robustness needed to commoditize enterprise application development in an OSGi environment.
a) True
b) False
Answer: a
Clarification: For a really good reference, specifically on SpringSource dm Server, I (Josh Long) would humbly recommend you investigate my co-author in-depth treatment of the subject, Pro SpringSource dm Server, by Gary Mak and Daniel Rubio (Apress, 2009).

11. To begin with SpringSource dm Server but need a way to rapidly turnaround development.
a) Spring Dynamic Module
b) Spring Dynamic Server
c) SpringSource dm Server
d) None of the mentioned
Answer: c
Clarification: Use the SpringSource dm Server tooling available as part of SpringSource Tool Suite (STS).

12. SpringSource has provided solid tooling for Eclipse, called :-
a) Spring Dynamic Module
b) dm Server Tools
c) SpringSource dm Server
d) None of the mentioned
Answer: b
Clarification: SpringSource has provided solid tooling for Eclipse, called dm Server Tools, which facilitate executing applications directly in a development environment.

13. These tools—part of the broader SpringSource Tool Suite—are available as :-
a) plug-in
b) stand-alone environment
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: These tools—part of the broader SpringSource Tool Suite—are available as either a plug-in or as a stand-alone environment.


To practice tough questions and answers on all areas of Java Spring,