Skip to content

Instantly share code, notes, and snippets.

@LenarBad
LenarBad / Choose Source for Default Value.groovy
Last active May 18, 2018 14:15
Jenkins dynamic Extended Choice Parameter with service call (Groovy Script)
// host will be passed in the groovy bindings for extended choice plugin.
def getVersion = { host, path ->
try {
def version = new groovy.json.JsonSlurper().parse(new URL("https://${host}${path}")).version
return version
} catch(Exception e) {
return null
}
}
@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>
@Component
public class TestData extends FileReader {
@Value("${testData.users.file}")
private String usersFile;
public List<User> getUsers() {
Gson gson = new Gson();
return Arrays.asList(gson.fromJson(getFileAsString(usersFile), User[].class));
}
@LenarBad
LenarBad / ReadFileIntoListOfStrings.java
Created December 8, 2017 18:23
How to read file into String with Apache Commons IO
public List<String> getFileAsListOfStrings(String fileName) throws IOException {
InputStream input = this.getClass().getResourceAsStream("/" + fileName);
return IOUtils.readLines(input, StandardCharsets.UTF_8);
}
@LenarBad
LenarBad / ReadFileIntoListOfStringsGuava.java
Created December 8, 2017 18:19
How to read file into List of Strings with Google Guava
public List<String> getFileAsListOfStringsGuava(String fileName) throws IOException {
InputStream input = this.getClass().getResourceAsStream("/" + fileName);
return CharStreams.readLines(new InputStreamReader(input, StandardCharsets.UTF_8));
}
@LenarBad
LenarBad / ReadFileIntoStringGuava.java
Created December 5, 2017 19:44
How to read file into String with Google Guava
public String getFileIntoStringGuava(String fileName) throws IOException {
InputStream input = this.getClass().getResourceAsStream("/" + fileName);
return CharStreams.toString(new InputStreamReader(input, StandardCharsets.UTF_8));
}
@LenarBad
LenarBad / ReadFileIntoString.java
Last active December 7, 2017 06:49
How to read file into String with Commons IO
public String readFileIntoString(String fileName) throws IOException {
InputStream input = this.getClass().getResourceAsStream("/" + fileName);
return IOUtils.toString(input, StandardCharsets.UTF_8);
}
package io.lenar.examples.spring.start;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestNGWithSpringApplication {
public static void main(String[] args) {
SpringApplication.run(TestNGWithSpringApplication.class, args);
@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 / Spring Boot + TestNG test class TestNGTestsWithSpringBootIT.java
Last active December 15, 2018 02:05
Spring Boot and TestNG example - test class
package io.lenar.examples.spring.start;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.boot.test.context.SpringBootTest;
import org.testng.Assert;
import org.testng.annotations.Test;
@SpringBootTest(classes = TestNGWithSpringApplication.class)
public class TestNGTestsWithSpringBootIT extends AbstractTestNGSpringContextTests {