Skip to content

Instantly share code, notes, and snippets.

@LenarBad
LenarBad / ServiceClientExampleIT
Last active March 2, 2018 22:03
Service Client - Usage in Tests
@SpringBootTest(classes = TestNGWithSpringApplication.class)
public class BookServiceClientExampleIT extends AbstractTestNGSpringContextTests {
@Autowired
BookServiceClient client;
@Test
public void createUpdateDeleteScenarioTest() throws IOException {
Book createdBook = client.createBook(new Book("Title", "Author")).dto();
String id = createdBook.getId();
@LenarBad
LenarBad / Logger.java
Last active October 21, 2021 16:41
AspectJ. How to log method invocation and print parameters as name:value map from ProceedingJoinPoint for TestNG tests
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.testng.Reporter;
@LenarBad
LenarBad / mount.sh
Created March 5, 2018 22:39
How to mount a VirtualBox shared folder
sudo mount -t vboxsf hostfolder guestFolder
@LenarBad
LenarBad / Spring Boot + TestNG - BaseIT.java
Last active May 7, 2018 22:19
BaseIT class for Spring Booot and TestNG tests
package io.lenar.examples.spring.start;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(classes = TestNGWithSpringApplication.class)
public class BaseIT extends AbstractTestNGSpringContextTests {
// Common methods, variables and constants
@LenarBad
LenarBad / Selenium WebDriver open local file.java
Created April 27, 2018 19:48
Selenium WebDriver - open a local html file. The file should be placed in the resources folder
String path = this.getClass().getResource("/my-local-form-page.html").getPath();
driver.get("file://" + path);
driver.findElement(By.id("button")).click();
String script = "arguments[0].innerHTML='" + StringEscapeUtils.escapeEcmaScript(innerHtml) + "'";
((JavascriptExecutor) driver).executeScript(script, webElement);
@LenarBad
LenarBad / JUnitWithSpringBootExampleIT.java
Last active May 14, 2018 20:31
Spring Boot + JUnit minimal required code
package io.lenar.examples.junitspringboot.tests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@LenarBad
LenarBad / Jenkins build periodically examples.md
Last active June 1, 2018 19:22
Jenkins build periodically

Build every hour:
H * * * *

Build every 20 minutes:
H/20 * * * *

Build every 20 minutes 2am to 11pm:
H/20 5-23 * * *

Build every 20 minutes, work time/days (8am-6pm, MON-FRI) only:
H/20 8-18 * * 1-5

Build every hour MON-WED and FRI only:
H * * * 1-3,5

@LenarBad
LenarBad / SpringDataProviderRunner.java
Created June 14, 2018 19:09
JUnit data providers for Spring
import static java.lang.Character.toUpperCase;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;
@LenarBad
LenarBad / isWiderPrimitive.java
Created July 24, 2018 17:43
Checks if object is auto-boxed primitive + String and Void
public boolean isWiderPrimitive(Object object) {
if (object == null) {
return false;
}
Class clazz = object.getClass();
if (clazz == Boolean.class || clazz == Character.class ||
clazz == Byte.class || clazz == Short.class ||
clazz == Integer.class || clazz == Long.class ||
clazz == Float.class || clazz == Double.class ||
clazz == String.class || clazz == Void.class) {