In this post under JJWT, I will explain with example, how to verify or assert the presence of standard claim in JWT token. JJWT framework provides a list of methods through which1) we can verify whether a standard claim exist in the JWT or not.2) we can verify whether a standard claim’s value is equal…… Continue reading Asserting the presence of a standard claim in JWT
AssertSame Example
In this post under JUnit, I will show with example the purpose of AssertSame assertion method. JUnit 5 has added new assertion method “assertSame” that checks for Object reference equality. How “assertSame” is different from “assertEquals” assertion method is that latter check for Object value equality whereas former checks for Object reference equality. Object value…… Continue reading AssertSame Example
Configuring UniformRandomBackOffPolicy (using annotations)
In this post, under Spring Retry I will show with example how to configure UniformRandomBackOffPolicy using annotations For our example we will use the below service class Service class 1 package defaultPackage; 2 3 import java.util.Date; 4 5 import org.springframework.retry.annotation.Backoff; 6 import org.springframework.retry.annotation.Retryable; 7 import org.springframework.stereotype.Service; 8 9 @Service 10 public class Service14 { 11…… Continue reading Configuring UniformRandomBackOffPolicy (using annotations)
Creating and Parsing a secret key signed JWT containing payload
In this post under JWT, I will show with example how to create and parse a signed JWT containing payload. As mentioned in previous posts we will use an instance of “JwtBuilder” to construct a JSON Web Token. Below is the code snippet for your reference Snippet 1 1 JwtBuilder jwtBuilder = Jwts.builder();2 3 jwtBuilder.header().add(“alg”,…… Continue reading Creating and Parsing a secret key signed JWT containing payload
Parsing simple unsigned JWT containing plaintext as payload
In this post under JJWT, I will show with example how to parse unsigned JWT containing plaintext as payload instead of serialized Claims object. As shown in previous post under JJWT, whenever we need to parse a JWT string. We need to create an instance of “JwtParser” as shown below JwtParserBuilder jwtParserBuilder = Jwts.parser(); jwtParserBuilder.unsecured();…… Continue reading Parsing simple unsigned JWT containing plaintext as payload
Creating a simple unsecured JSON Web Token containing payload
In this post under JJWT, I will show with example how to generate unsecured JWT containing payload. In previous post under JJWT, I talked about JWT containing claims. So what is the difference between claims and payload. Its simple, payload is noting but any String data, whereas claims is a map. Now with the difference…… Continue reading Creating a simple unsecured JSON Web Token containing payload
Creating and Parsing a secret key signed JWT containing claims
In this post under JWT, I will show with example how to create and parse a signed JWT containing claims. As mentioned in previous posts we will use an instance of “JwtBuilder” to construct a JSON Web Token. Below is the code snippet for your recap Snippet 1 1 JwtBuilder jwtBuilder = Jwts.builder();2 3 jwtBuilder.header().add(“alg”,…… Continue reading Creating and Parsing a secret key signed JWT containing claims
AssertDoesNotThrow Example
In this post under JUnit, I will explain with example what is the purpose and how to use “AssertDoesNotThrow” assertion method. AssertDoesNotThrow takes an executable code and assert that the method doesn’t throw any exception during execution. Below is the javadoc of “assertDoesNotThrow” exception public static void assertDoesNotThrow(Executable executable) Where “Executable” is a functional interface…… Continue reading AssertDoesNotThrow Example
Checking whether JWT is secured or not
In this post under JJWT I will show with example how to check whether a JWT is secured or not. JwtParser class has a “isSigned” method which will figure out whether the JWT is secured or not. All we need is to pass the test JWT string as an argument to this method. This method…… Continue reading Checking whether JWT is secured or not
Assumptions in JUnit5
In this post under Junit5, I will show with example, how to use Assumptions feature. Sometimes test case assertions depend on certain conditions. If a condition is met, then test case should be asserted otherwise we should skip the assertion. To test whether the condition is met or not, we take the help of “assumeTrue”…… Continue reading Assumptions in JUnit5