Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
About the Author
About the Reviewers

Getting started with Spring

Spring is an open source enterprise application development framework for Java. It was first written by Rod Johnson and released under the Apache 2.0 license in June 2003.

Spring Framework provides comprehensive infrastructure support for developing Java applications. Spring handles the infrastructure for us and allows us to focus on our application logic. Spring enables us to build applications from Plain Old Java Objects (POJOs) and apply enterprise services non-invasively to POJOs.

The following are examples of POJO-based application development:

  • A Java method can handle an HTTP POST/GET request; you don't have to write a servlet or work with servlet APIs

  • A Java method can act as a RESTful web service without dealing with web service APIs

  • A Java method can execute a database transaction without dealing with transaction APIs

  • A local Java method can participate in a remote procedure call (RPC) without having to deal with remote APIs

  • A Java method can consume or handle messages without having to deal with JMS APIs

  • A Java method can work as a management extension without dealing with JMX APIs

In a nutshell, Spring can be described as follows:

  • An open source application framework

  • One of the available enterprise application frameworks and a lightweight solution for enterprise applications

  • Non-invasive (POJO-based)

  • Modular

  • Extensible for other frameworks

  • The de facto standard of Java enterprise applications

The following are advantages of Spring:

  • Lightweight and minimally invasive development with POJOs

  • Loose coupling through dependency injection and interface-orientation

  • Declarative programming through aspects and common conventions

  • Boilerplate code reduction through aspects and templates

Spring projects provide infrastructure for building security configuration, web applications, big data, LDAP, and so on. Spring Framework is one of the Spring projects.

There are various Spring projects that can be used. In this book, we'll be using Spring 4.

The following are the icons of some Spring projects:

The following are all Spring projects as of September 2014:

  • The Spring IO platform: Spring IO brings together the core Spring APIs into a cohesive and versioned foundational platform for modern applications. Spring IO is comprised of the Spring IO Foundation and Spring IO Execution layers.

  • Spring Boot: This helps in creating production-grade Spring applications that can be run any time with the minimal Spring configuration. It follows the convention-over-configuration approach.

  • Spring Framework: This is an open source framework for Java enterprise applications. It provides an inversion of control container for Java beans. The framework offers a number of templates for the developers; the templates hide the infrastructure code and allow us to concentrate on the business logic.

  • Spring XD: This is a unified, distributed, and extensible system for data ingestion, real-time analytics, batch processing, and data export. The goal of the project is to simplify the development of big data applications.

  • Spring Cloud: Spring Cloud builds on Spring Boot by providing a bunch of libraries that enhance the behavior of an application when added to the classpath. You can take advantage of the basic default behavior to get started really quickly, and then when you need to, you can configure or extend it to create a custom solution.

  • Spring Data: This simplifies data access, offers APIs to work with the relational databases, NoSQL or non-relational databases, big data or the map-reduce algorithm, and so on.

  • Spring Integration: This follows Enterprise Integration Patterns (EIP) to enable us lightweight, POJO-based messaging for Spring applications to integrate with external systems.

  • Spring Batch: This is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems.

    The following image displays the icons of the following spring projects: security, HATEOAS, social, AMQP, web services, Mobile, Android, web flow, Spring LDAP and Grails

  • Spring Security: This is a powerful and highly customizable authentication and access-control framework. It is the de facto standard for securing Spring-based applications.

  • Spring HATEOAS: This allows you to create REST representations that follow the HATEOAS principle from your Spring-based applications.

  • Spring Social: Connect your Spring application with Software as a Service (SaaS) API providers such as Facebook, Twitter, and LinkedIn.

  • Spring AMQP: The Advanced Message Queuing Protocol (AMQP) is an open standard for messaging. Spring AMQP offers solutions for AMQP-based messaging, for example, it can be used with the AMQP broker RabbitMQ.

  • Spring Mobile: This is an extension to Spring MVC that aims to simplify the development of mobile web applications.

  • Spring for Android: This is an extension of Spring Framework that aims to simplify the development of native Android applications.

  • Spring Web Flow: This provides the infrastructure to build process workflows for web-based Spring applications, such as page navigation, navigation triggers, application state, and services to invoke. This is stateful and can be a short-lived process flow or long-running flow.

  • Spring Web Services: This aims to facilitate contract-first SOAP service development, and this allows the creation of flexible web services using one of the many ways to manipulate XML payloads.

  • Spring LDAP: This makes it easier to build Spring-based applications that use the Lightweight Directory Access Protocol (LDAP).