Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 pom.xml
Last active April 10, 2018 15:12
Spring Boot + TestNG minimal Maven dependencies.
<?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>
@LenarBad
LenarBad / Exclude Tomcat from Spring Boot in Maven.xml
Created December 22, 2017 22:21
How to exclude Tomcat from Spring Boot in Maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
@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);