Skip to content

Instantly share code, notes, and snippets.

@kiransvkumar
kiransvkumar / TimeZoneConversion.java
Last active May 16, 2023 15:31
Converting dates between different time zones using java
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/**
* This method converts the input date given in the below format from UTC time zone to AUS time zone
*
* ipDt = "2019-09-08T21:15:10";
*/
public void changeTheTimeZone(String ipDt) {
@kiransvkumar
kiransvkumar / wsdl2pojo.xml
Last active November 8, 2017 09:03
Generates jaxb classes from wsdl using pom.xml
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<phase>clean</phase>
@kiransvkumar
kiransvkumar / css-101.css
Created November 8, 2017 02:10
get started with css styles for input text, date, button, labels
button, input {
font-family: inherit;
font-size: 100%;
}
input {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
label {
display: block;
@kiransvkumar
kiransvkumar / html-101.html
Last active November 8, 2017 02:11
Get started with html with few simple tags
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 101</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- links the style sheet applicable for this html -->
<link href="css-101.css" rel="stylesheet"/>
</head>
<body>
@kiransvkumar
kiransvkumar / ExceptionTest.java
Created August 20, 2017 11:56
Unit testing for exceptions thrown by a class
import org.hamcrest.CoreMatchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ValidatorTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@kiransvkumar
kiransvkumar / HandlingNFException.java
Last active August 9, 2017 14:43
Handling number format exception in SpringBoot exception handling framework
@ExceptionHandler (value = {NumberFormatException.class})
public final ResponseEntity<ServiceErrorResponse> invalidNumberHandling(Exception e) {
ServiceErrorResponse serviceResponse = new ServiceErrorResponse(
HttpStatus.BAD_REQUEST.value(),
HttpStatus.BAD_REQUEST.value() * 1000
+ 101, e.getMessage());
return new ResponseEntity<ServiceErrorResponse>(serviceResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST);
}
@kiransvkumar
kiransvkumar / SampleDefaultExceptionHandler.java
Last active August 9, 2017 14:46
Sample exception handler class for a spring boot application handling invalid request parameters
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
// annotation that ties up controller and this handler class
@ControllerAdvice
public class SampleDefaultExceptionHandler extends ResponseEntityExceptionHandler{
@kiransvkumar
kiransvkumar / ValidatePDFDocument.java
Last active August 7, 2017 10:12
Validate a pdf document by extracting its content
import java.awt.Rectangle;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripperByArea;
// import other apis as required
@Test
public void getDocByIdTest() throws Exception {
// mock input data
@kiransvkumar
kiransvkumar / SampleSpringBootContorllerTest.java
Last active August 7, 2017 09:23
SpringBoot controller test class that uses SpringBoot starter libraries and runs on a server during JUnit testing
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.junit.runner.RunWith;
@kiransvkumar
kiransvkumar / ValidateJsonResponse.java
Last active August 3, 2017 01:41
compares json objects, json strings
import org.json.JSONObject;
import org.skyscreamer.jsonassert.JSONAssert;
public class ValidateJsonResponse {
// used for unit testing purposes
public static void main(String[] args) {
String expectedResponse = "{\"fault\":{\"detail\":{\"errorcode\":\"User unauthorized\"},\"faultstring\":\"Invalid access token\"}}";