Spring Boot RESTFul

The main idea behind creating a RESTful application is that you will create logical resources (GET, POST, UPDATE and DELETE) consumed by clients usign HTTP request. This resources should be nouns no verbs. In this example we will create a RESTful application using a person resource. So we can have: GET /persons - Retrieves a list of persons GET /persons/1234 - Retrieves a specific person POST /persons - Creates a new person PUT /persons/1234 - Updates #1234 person DELETE /persons/1234 - Deletes #1234 person NOTE: If you need to know what tools you need to have installed in your computer in order to create a Spring Boot basic project, please refer my previous post: Spring Boot [Read More]

Aspect Oriented Programming

Apply same logic in several points in your application is called cross cutting concerns, and in Spring we can implement it using AOP, some basics aspects are: Advice: Action taken. Different types of advice include “around,” “before” and “after” advice. Pointcut: Where the action should be applied. In this example we are going to define an AfterThrowingAdvice which means an action is executed after some exception has been thrown, so first we need to define a general exception in our application. [Read More]

Spring Boot

What is Spring Boot? Open source Java framework used to create micro services but also to create easy web or stand-alone applications. It provides the next features: No XML configuration is required Netty (Starter Webflux) or Tomcat (Starter Web) Convention over configuration Easy setup Very lightweight Easy to test Topics Spring Boot AOP Spring Boot RESTful Spring Boot Handler Exception Spring Boot Internationalization Spring Boot JPA Spring Boot Externalization Spring Boot Bootstrap Spring Boot Testing Spring Boot Validation Spring Boot Testing Validation Spring Boot Security Spring Boot Security using Database Spring Boot Rest Client Spring Boot Actuator Spring Boot JDBC Template Spring Boot Flyway Spring Boot Liquibase Spring Boot Logback Spring Boot Thymeleaf Layouts Spring Boot Swagger Spring Boot Oauth2 with Google Spring Boot Ehcache Spring Boot Appium Cucumber Spring Boot Parameters Spring Boot Profiles Spring Boot Retrofit2 Cucumber & Junit5 Spring Boot Testing Web Layer Spring Boot Publishing an Artifactory Library Spring Webflux Basics Spring Webflux Server Spring Webflux Client Spring Webflux Security Spring Webflux Security Database Spring Webflux with Thymeleaf Spring Boot JMS Spring Webflux Cucumber Spring Boot WebClient Spring Boot WebClient Cucumber and Junit5 Spring Webflux Multi-Module Spring Weblux Internationalization Spring Weblux Testing Web Layer Spring Boot Hazelcast Spring Boot JsonNode Spring Boot Server-sent Event Spring Boot Server-sent Event Client Spring Boot H2 Spring Webflux URI Validator Spring Webflux Webclient Headers Spring Boot XML Schema Spring Webflux JAXB Spring Webflux Constructor Injection Spring Webflux WebSockets This post shows you how to create a simple Spring Boot project with this features: [Read More]

Mailosaur Getting Started

If you want to create end-to-end tests that rely on email verification such as sent, confirmation, password reset, etc. Mailosaur is your friend. Note: You will need a Mailosaur account to create a new trial account; sign up here. In this technical post, we will go over the required configuration to set up an email sent validation. Let’s start by creating a new Gradle - Java project with Kotlin DSL script :) build. [Read More]

Builder Design Pattern

An immutable object is one in which the state cannot be modified after it is created. In functional programming, it is a fundamental piece, unfortunately, Java does not support functional programming by design so we need to implement it. Why is immutability important?, well: Data will not change their state, so once it is verified it remainds valid. Thread safe No side effects So, since this object needs to be set/validated in creation, we can use the builder design pattern which allows us to construct objects step by step. [Read More]

Using Optional

Once called a Billion-dollar mistake. NullPointerException is by far one of the most frequent exceptions in Java and since version 8 we can use it as a way to avoid this exception. Optional is a container that can has a value or not. In this technical post we will review basic concepts about Optional. Please consider this example where we are creating an empty optional. @Test void shouldCreateAnEmptyOptional() { Optional<String> empty = Optional. [Read More]

JFairy

Jfairy is a Java fake data generator project and this time I will show you how to use this library to generate random testing information data. First let’s create an empty basic Java project using lazybones. In order to install lazybones in your computer, please use this tool: sdkman. Then execute this command from your command line: lazybones create java-basic jfairy-workshop You should get this output: Creating project from template java-basic (latest) in 'jfairy-workshop' Java Application project template ------------------------------------ You have just created a basic Java application. [Read More]

From Anonymous to Lambda

Anonymous classes traditionally enable you to declare and instantiate a class at the same time. They are like local classes except that they do not have a name. With lambda expressions introduced in Java 8 we can move anonymous classes to lambda expressions and with that we will have less code, clean code and more assertive functionality definition. This time I will show you how to transfrom a anonymous class to lambda expression in two steps. [Read More]

JUnit 5

JUnit 5 is JUnit next generation; it requires Java 8 or above since it was born as a JUnit Lambda project, that project wanted to take full advantage of Java 8 new features, especially lambda expressions. Assertions Assumptions Conditions Parameterized Tests Test Execution Order Using Gradle, you need to create a build.gradle file with the following structure: plugins { id 'java' } def junitJupiterVersion = '5.9.2' repositories { mavenCentral() } dependencies { testImplementation "org. [Read More]

Lambda Expressions

Since Java 8 we have Lambda expressions which is a function defined under some interface contract and the main purpose is to implement functional programming in Java. Basically lambda expression is an argument list follow by an arrow token and a body or code expression. Example 1: (x, y) -> x + y; Example 2: () -> "Hello World!"; Example 3: x -> x.toLowerCase(); Lambdas should be an expression, not a narrative [Read More]