Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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 / mount.sh
Created March 5, 2018 22:39
How to mount a VirtualBox shared folder
sudo mount -t vboxsf hostfolder guestFolder
@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 / 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 / ResponseClassesForServiceClient.java
Last active February 27, 2018 21:03
Response Classes for service Client
public class Response {
private ResponseStatus status;
public Response(HttpResponse httpResponse) {
this.status = new ResponseStatus(httpResponse);
}
public ResponseStatus getStatus() {
return status;
}
@LenarBad
LenarBad / ServiceClient.java
Last active February 27, 2018 21:04
REST Service Client base on created HttpClient. Example for BookService
import java.io.IOException;
import io.lenar.examples.spring.clients.response.BookResponse;
import io.lenar.examples.spring.clients.response.BooksResponse;
import io.lenar.examples.spring.clients.response.Response;
import io.lenar.examples.spring.http.HttpClient;
import io.lenar.examples.spring.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@LenarBad
LenarBad / HttpClientExampleIT.java
Last active March 1, 2018 00:57
Usage in Tests - Http Client with Apache Http Components
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import io.lenar.examples.spring.TestNGWithSpringApplication;
import io.lenar.examples.spring.http.HttpClient;
import io.lenar.examples.spring.model.Book;
import org.apache.commons.io.IOUtils;
@LenarBad
LenarBad / HttpClient.java
Created February 26, 2018 16:52
Http Client with Apache Http Component
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
@LenarBad
LenarBad / Skip TestNG tests based on condition.java
Last active November 20, 2020 08:49
How to skip TestNG tests based on condition using IInvokedMethodListener
@Listeners(value = ConditionalSkipTestAnalyzer.class)
public class ExampleConditionalSkippingTest {
@NonProduction
@Test
public void test1() { }
@ProductionOnly
@Test
public void test2() { }
@LenarBad
LenarBad / GET HTTP Request.java
Created February 2, 2018 21:50
How to send GET Request and get Response with Apache Http Components
String url = "https://www.some-web-service/api/endpoint";
HttpGet get = new HttpGet(url);
Header headers[] = { new BasicHeader("Accept", "application/json")};
get.setHeaders(headers);
CloseableHttpClient client = HttpClients.custom().build();
HttpResponse response = client.execute(get);