Skip to content

Instantly share code, notes, and snippets.

public class JsonArgumentsProvider implements ArgumentsProvider, AnnotationConsumer {
private String[] values;
private Class<?> type;
@Override
public void accept(final JsonSource annotation) {
values = annotation.value();
type = annotation.type();
}
@ParameterizedTest
@JsonSource(value = "{firstname:'Jane', lastname: 'Doe'}", type = Person.class)
void jsonSourceTest(Person param) {
System.out.println(param);
}
@Entity
@Table(name="city")
internal data class CityEntity(
@Id val id: Long? = null,
val name: String,
val description: String? = null) {
fun toDto(): CityDto = CityDto(
id = this.id!!,
name = this.name,
@Transactional(Transactional.TxType.MANDATORY)
internal interface CityRepository : JpaRepository<CityEntity, Long>
interface CityService {
fun retrieveCity(cityId: Long): CityDto?
fun retrieveCities(): List<CityDto>
fun addCity(city: CreateCityDto): CityDto
fun updateCity(id: Long, city: UpdateCityDto): CityDto
}
@Service
@Transactional
internal class JpaCityService(val cityRepo: CityRepository) : CityService {
override fun retrieveCity(cityId: Long) : CityDto? {
return cityRepo.findOne(cityId)?.toDto()
}
override fun retrieveCities() : List<CityDto> {
return cityRepo.findAll().map { it.toDto() }
@RunWith(SpringRunner::class)
@ContextConfiguration(classes = arrayOf(CityConfig::class))
@DataJpaTest
internal class JpaCityServiceTest {
@Autowired
lateinit var service: CityService
@Autowired
lateinit var repository: CityRepository
@dnno
dnno / media-backup.mount
Last active April 23, 2021 11:57
Serviced unit for mounting an external device
[Unit]
Description=Additional drive
[Mount]
What=/dev/disk/by-uuid/6080-1BC0
Where=/media/backup
Type=exfat
Options=defaults
[Install]
@dnno
dnno / media-backup.automount
Created April 23, 2021 11:57
Systemd unit for automounting an external device
[Unit]
Description=Automount USB Backup
[Automount]
Where=/media/backup
[Install]
WantedBy=multi-user.target
@dnno
dnno / vaultwarden-backup.service
Created May 10, 2021 11:13
Systemd Vaultwarden backup service
[Unit]
Description=backup the vaultwarden sqlite database and attachments
[Service]
Type=oneshot
WorkingDirectory=/media/backup
ExecStart=/usr/bin/env sh -c 'sqlite3 /home/pi/bw-data//db.sqlite3 ".backup backup-$(date -Is | tr : _).sq3"'
ExecStart=/usr/bin/env sh -c 'tar cvfz bw-attachments-$(date -Is | tr : _).tar.gz /home/pi/bw-data/attachments/'
ExecStart=/usr/bin/find . -type f -mtime +30 -name 'backup*' -delete
ExecStart=/usr/bin/find . -type f -mtime +30 -name 'bw-attachments*' -delete