Posts

Showing posts from November, 2022

Why you need Mockito?

## Table of Contents 1. [Mockito](#mockito) 2. [Important Jargon](#important-jargon) 3. [How to get Mockito](#how-to-get-mockito) 4. [Annotations in Mockito library](#annotations-in-mockito-library) 5. [Mockito Exceptions](#mockito-exceptions) 6. [Mocking best practices](#mocking-best-practices) 7. [Drawbacks of Mocking](#drawback-of-mocking) ## Mockito [Mockito](https://site.mockito.org/) is an Open Source Mocking framework. It is a Java library mostly used for unit testing of Java application. The Mockito library enables mock **creation**, **verification** and **stubbing**. It simplifies the process of testing by creating mock objects and avoiding external dependencies like connecting to database. At present, Mockito frameworks consists of following set of libraries: * **mockito-all** - It consist of mockito core library and other dependencies like *hamcrest*. This is <mark>outdated library with no future release</mark>. Developer should use mockito-core instead. * ...

What is CORS ?

As a security reasons, web browsers implement same-origin policy, which means requesting data from same domain is allowed. Data requested using different domain will throw an error. CORS (Cross-Origin Resource Sharing) is a http-based mechanism that enables the browser to access resources outside a given domain. When a browser makes a cross-origin request, it will add an http Origin header that states the protocol and port number. The server responds and add an "Access-Control-Allow-Origin" header in the response to browser. If the header's origin is the same as the origin sent in the request then access to the resourse is granted. The CORS mechanism supports secure cross-origin requests and data transfers between browsers and servers. ### What kind of requests uses CORS ? CORS enable the cross origin requests like: 1. Access CSS resource like web-fonts , images etc. 2. Invocations of the XMLHttpRequest or Fetch APIs (The Fetch API provides an interface for f...

Eclipse MicroProfile configuration

Microprofile config, helps application to read the configurations from different configurations sources. Different sources for configuration could be: 1. Operating system environment variables ( mostly used in cloud native environment) 2. JVM system properties. 3. Database, LDAP or any other key-value store ( example: [HasiCorp vault] (https://www.hashicorp.com/products/vault) ) 4. External configuration files. #### Reading config properties ##### Programmatic: An application can obtain its configuration programmatically via the `ConfigProvider`. ``` Config config = ConfigProvider.getConfig(); ConfigValue databaseName = config.getConfigValue("myapplication.databaseName"); connect(dbUsername.getValue()); ``` ##### Dependency Injection: MicroProfile Config also provides ways to inject configured values into your beans using the `@Inject` and the `@ConfigProperty` qualifier ``` @Inject @ConfigProperty(name="myapplication.propertyname", def...