EmailServiceMock.java
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bremersee.dccon.service;
import java.util.Locale;
import lombok.extern.slf4j.Slf4j;
import org.bremersee.dccon.config.DomainControllerProperties;
import org.bremersee.dccon.model.DomainUser;
import org.bremersee.dccon.repository.DomainUserRepository;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
/**
* The email service mock.
*
* @author Christian Bremer
*/
@Component("emailServiceMock")
@ConditionalOnProperty(name = "spring.mail.host", matchIfMissing = true, havingValue = "false")
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Slf4j
public class EmailServiceMock extends AbstractEmailService {
/**
* Instantiates a new Email service mock.
*
* @param properties the properties
* @param userRepository the user repository
* @param templateEngine the template engine
*/
public EmailServiceMock(
DomainControllerProperties properties,
DomainUserRepository userRepository,
TemplateEngine templateEngine) {
super(properties, userRepository, templateEngine);
}
/**
* Init.
*/
@EventListener(ApplicationReadyEvent.class)
public void init() {
log.warn("\n"
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
+ "!! MOCK is running: EmailServiceMock !!\n"
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
);
}
@Override
void doSendEmailWithCredentials(
final DomainUser domainUser,
final Locale locale,
final String mailText) {
log.info("Email recipient=[{}], email text=\n{}", domainUser.getEmail(), mailText);
}
}