Skip to content

Instantly share code, notes, and snippets.

@thetekst
thetekst / Child.java
Created April 7, 2018 20:31
powermock. мокаем конструктор внутри класса
package ru;
import lombok.Data;
/**
* Created by Dmitry Tkachenko on 4/7/18
*/
@Data
public class Child {
@thetekst
thetekst / .gitignore
Last active April 19, 2018 09:23
gradle Spring Boot 2 setup
/.gradle/
/.idea/
/build/
**/*.iml
**/target/
**/out
**/log
@thetekst
thetekst / build.gradle
Created June 18, 2018 15:03 — forked from javiyt/build.gradle
Send Mail using spring boot, based on http://www.baeldung.com/spring-email
dependencies {
compile 'org.springframework.boot:spring-boot-starter-mail:1.5.7.RELEASE'
}
@thetekst
thetekst / EmailServiceTest.java
Last active June 19, 2018 12:54
SpringBoot Spock test send email
package ru.mailer.service
import com.icegreen.greenmail.util.GreenMail
import com.icegreen.greenmail.util.ServerSetup
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import ru.mailer.mq.model.MessageDto
import spock.lang.Shared
import spock.lang.Specification
@thetekst
thetekst / docker-compose.yml
Last active November 8, 2018 10:42
Spring boot docker-compose.yml
version: "2"
services:
redis:
image: redis:latest
ports:
- 6379:6379
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
redisCli:
@thetekst
thetekst / SecurityConfig.java
Created August 9, 2018 09:48
Spring Boot 2 Security config auth
package ru.rtln.mailer.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@thetekst
thetekst / ValidateEmails.java
Created September 21, 2018 15:05
Validate emails and each email length apart
@Data
@ToString(exclude = {"password"})
public class MyRequest {
@NotEmpty
@Size(min = 1, max = 64)
private String password;
private Set<String> emails;
@thetekst
thetekst / MyController.java
Last active October 18, 2018 12:24
Spring Boot Security Role and using @secured for controller
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("channel")
public class MyController {
// Если бы мы в UserPrincipal добавили public final static String ROLE_ADMIN_NAME = ROLE_PREFIX + Role.ADMIN;
// или Role.ADMIN.name(),
// то при использовании @Secured(UserPrincipal.ROLE_ADMIN_NAME) мы бы получили: Attribute value must be constant.
// Т.к. здесь используется вызов функции Role. или Role.ADMIN., а это уже не константа
@thetekst
thetekst / test.groovy
Last active November 12, 2018 08:10
groovy script. Convert object with map attribute to json
def testMapToJson() {
def obj = new DictionaryRow()
obj.id = 1L
obj.values = [
(new DictionaryField().setId(1)) : 1,
(new DictionaryField().setId(2)) : 2] as Map
println new JsonBuilder(obj).toPrettyString()
}
@thetekst
thetekst / 2018_12_14--01-dictionary.groovy
Last active February 15, 2019 12:37
Add liquibase to Spring Boot project. Generate changelog from existed DB in IDEA > Gradle > Tasks > liquibase > generateChangelog. Before make generateChangelog be sure that directory liquibase is exists
# current file location: src/main/liquibase/v-1.0/2018_12_14--01-dictionary.groovy
databaseChangeLog() {
changeSet(id: '1547828693315-1', author: 'dmitry_tkachenko (generated)') {
createSequence(cacheSize: 0, cycle: false, incrementBy: 1, maxValue: 9999999999999999999999999999, minValue: 1, ordered: false, sequenceName: 'CHANNEL_SEQ', startValue: 3)
}
changeSet(id: '1547828693315-41', author: 'dmitry_tkachenko (generated)') {
createTable(tableName: 'TEMPLATE_CHANNEL_TAB') {
column(name: 'TEMPLATE_ID', type: 'NUMBER(19, 0)') {
constraints(nullable: false)