Skip to content

Instantly share code, notes, and snippets.

Lenar Badretdinov LenarBad

Block or report user

Report or block LenarBad

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@LenarBad
LenarBad / GET HTTP Request.java
Created Feb 2, 2018
How to send GET Request and get Response with Apache Http Components
View GET HTTP Request.java
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);
@LenarBad
LenarBad / Skip TestNG tests based on condition.java
Last active Feb 16, 2018
How to skip TestNG tests based on condition using IInvokedMethodListener
View Skip TestNG tests based on condition.java
@Listeners(value = ConditionalSkipTestAnalyzer.class)
public class ExampleConditionalSkippingTest {
@NonProduction
@Test
public void test1() { }
@ProductionOnly
@Test
public void test2() { }
@LenarBad
LenarBad / HttpClient.java
Created Feb 26, 2018
Http Client with Apache Http Component
View HttpClient.java
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 / ResponseClassesForServiceClient.java
Last active Feb 27, 2018
Response Classes for service Client
View ResponseClassesForServiceClient.java
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 Feb 27, 2018
REST Service Client base on created HttpClient. Example for BookService
View ServiceClient.java
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 Mar 1, 2018
Usage in Tests - Http Client with Apache Http Components
View HttpClientExampleIT.java
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 / Logger.java
Last active Mar 1, 2018
AspectJ. How to log method invocation and print parameters as name:value map from ProceedingJoinPoint for TestNG tests
View Logger.java
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 Mar 2, 2018
Service Client - Usage in Tests
View ServiceClientExampleIT
@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 / mount.sh
Created Mar 5, 2018
How to mount a VirtualBox shared folder
View mount.sh
sudo mount -t vboxsf hostfolder guestFolder
@LenarBad
LenarBad / Spring Boot + TestNG pom.xml
Last active Apr 10, 2018
Spring Boot + TestNG minimal Maven dependencies.
View Spring Boot + TestNG pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.lenar.examples.spring</groupId>
<artifactId>start</artifactId>
<version>1.0-SNAPSHOT</version>
You can’t perform that action at this time.