format all files
This commit is contained in:
@@ -21,98 +21,99 @@ import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/** Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */
|
||||
private static final String DEFAULT_DOWNLOAD_URL =
|
||||
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION
|
||||
+ "/maven-wrapper-"
|
||||
+ WRAPPER_VERSION
|
||||
+ ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use
|
||||
* instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
/** Path where the maven-wrapper.jar will be saved to. */
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '"
|
||||
+ outputFile.getParentFile().getAbsolutePath()
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(
|
||||
new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
}
|
||||
|
||||
8
adapter/addressvalidation/mvnw
vendored
8
adapter/addressvalidation/mvnw
vendored
@@ -316,7 +316,7 @@ export MAVEN_CMD_LINE_ARGS
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?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"
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
||||
@@ -3,25 +3,25 @@ package de.strasser.peter.hexagonal.addressvalidation;
|
||||
import de.strasser.peter.hexagonal.application.customer.domain.Address;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.AddressValidatorPort;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.commands.ValidateAddressCommand;
|
||||
import de.strasser.peter.hexagonal.common.Adapter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@Adapter
|
||||
class AddressValidator implements AddressValidatorPort {
|
||||
|
||||
@Override
|
||||
public Address validate(ValidateAddressCommand validateAddressCommand) throws InvalidAddressExc {
|
||||
// This could be some call to a 3rd party to validate this address.
|
||||
if (validateAddressCommand.getStreet().equalsIgnoreCase("parkring")) {
|
||||
log.info("Address is made up.");
|
||||
throw new InvalidAddressExc(validateAddressCommand);
|
||||
}
|
||||
|
||||
return new Address(
|
||||
validateAddressCommand.getStreet(),
|
||||
validateAddressCommand.getHouseNumber(),
|
||||
validateAddressCommand.getZipCode(),
|
||||
validateAddressCommand.getCountry());
|
||||
@Override
|
||||
public Address validate(ValidateAddressCommand validateAddressCommand) throws InvalidAddressExc {
|
||||
// This could be some call to a 3rd party to validate this address.
|
||||
if (validateAddressCommand.getStreet().equalsIgnoreCase("parkring")) {
|
||||
log.info("Address is made up.");
|
||||
throw new InvalidAddressExc(validateAddressCommand);
|
||||
}
|
||||
|
||||
return new Address(
|
||||
validateAddressCommand.getStreet(),
|
||||
validateAddressCommand.getHouseNumber(),
|
||||
validateAddressCommand.getZipCode(),
|
||||
validateAddressCommand.getCountry());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,98 +21,99 @@ import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/** Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */
|
||||
private static final String DEFAULT_DOWNLOAD_URL =
|
||||
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION
|
||||
+ "/maven-wrapper-"
|
||||
+ WRAPPER_VERSION
|
||||
+ ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use
|
||||
* instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
/** Path where the maven-wrapper.jar will be saved to. */
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '"
|
||||
+ outputFile.getParentFile().getAbsolutePath()
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(
|
||||
new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
}
|
||||
|
||||
8
adapter/persistence/mvnw
vendored
8
adapter/persistence/mvnw
vendored
@@ -316,7 +316,7 @@ export MAVEN_CMD_LINE_ARGS
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
|
||||
@@ -18,8 +18,7 @@ import java.util.List;
|
||||
@Slf4j
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerDao
|
||||
implements SaveCustomerPort, LoadCustomerPort, QueryAllCustomersCRUD {
|
||||
public class CustomerDao implements SaveCustomerPort, LoadCustomerPort, QueryAllCustomersCRUD {
|
||||
private final CustomerRepository customerRepository;
|
||||
private final CustomerMapper customerMapper;
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
public class MongoConfig {
|
||||
|
||||
@Bean
|
||||
public MongoClient mongoClient() {
|
||||
return MongoClients.create("mongodb://admin:changeme@localhost:27017");
|
||||
}
|
||||
@Bean
|
||||
public MongoClient mongoClient() {
|
||||
return MongoClients.create("mongodb://admin:changeme@localhost:27017");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,5 +7,4 @@ import org.springframework.stereotype.Repository;
|
||||
import java.math.BigInteger;
|
||||
|
||||
@Repository
|
||||
public interface CustomerRepository extends MongoRepository<CustomerEntity, BigInteger> {
|
||||
}
|
||||
public interface CustomerRepository extends MongoRepository<CustomerEntity, BigInteger> {}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.strasser.peter.hexagonal.persistence;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.domain.Customer;
|
||||
import de.strasser.peter.hexagonal.persistence.mapper.CustomerMapper;
|
||||
import de.strasser.peter.hexagonal.persistence.mapper.CustomerMapperImpl;
|
||||
import de.strasser.peter.hexagonal.persistence.repository.CustomerRepository;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -18,24 +17,21 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@DataMongoTest
|
||||
@Import({CustomerDao.class, CustomerMapperImpl.class})
|
||||
class CustomerDaoTest {
|
||||
@Autowired
|
||||
private CustomerDao customerDao;
|
||||
@Autowired private CustomerDao customerDao;
|
||||
|
||||
@Autowired
|
||||
private CustomerRepository customerRepository;
|
||||
@Autowired private CustomerRepository customerRepository;
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
this.customerRepository.deleteAll();
|
||||
}
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
this.customerRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(5)
|
||||
void should_ContainOneCustomer_When_CallingInsertMethod() {
|
||||
var customer = Customer.newCustomer("hans", "passwsord", LocalDate.of(1980, 1, 1));
|
||||
this.customerDao.upsert(customer);
|
||||
|
||||
assertEquals(this.customerRepository.findAll().size(), 1);
|
||||
}
|
||||
@Test
|
||||
@Timeout(5)
|
||||
void should_ContainOneCustomer_When_CallingInsertMethod() {
|
||||
var customer = Customer.newCustomer("hans", "passwsord", LocalDate.of(1980, 1, 1));
|
||||
this.customerDao.upsert(customer);
|
||||
|
||||
assertEquals(this.customerRepository.findAll().size(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package de.strasser.peter.hexagonal.persistence;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class PersistenceTestConfiguration {
|
||||
|
||||
|
||||
}
|
||||
public class PersistenceTestConfiguration {}
|
||||
|
||||
167
adapter/web/.mvn/wrapper/MavenWrapperDownloader.java
vendored
167
adapter/web/.mvn/wrapper/MavenWrapperDownloader.java
vendored
@@ -21,98 +21,99 @@ import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/** Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */
|
||||
private static final String DEFAULT_DOWNLOAD_URL =
|
||||
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION
|
||||
+ "/maven-wrapper-"
|
||||
+ WRAPPER_VERSION
|
||||
+ ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use
|
||||
* instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
/** Path where the maven-wrapper.jar will be saved to. */
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '"
|
||||
+ outputFile.getParentFile().getAbsolutePath()
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(
|
||||
new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
}
|
||||
|
||||
8
adapter/web/mvnw
vendored
8
adapter/web/mvnw
vendored
@@ -316,7 +316,7 @@ export MAVEN_CMD_LINE_ARGS
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
|
||||
@@ -2,14 +2,19 @@ package de.strasser.peter.hexagonal.web;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.port.in.AddAddressUseCase;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.in.commands.AddAddressCommand;
|
||||
import de.strasser.peter.hexagonal.common.Adapter;
|
||||
import de.strasser.peter.hexagonal.web.dto.request.AddAddressRequest;
|
||||
import de.strasser.peter.hexagonal.web.mapper.AddAddressWebMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
@Adapter
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class AddAddressController {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.strasser.peter.hexagonal.web;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.port.in.QueryAllCustomersCRUD;
|
||||
import de.strasser.peter.hexagonal.common.Adapter;
|
||||
import de.strasser.peter.hexagonal.web.dto.response.CustomerResponse;
|
||||
import de.strasser.peter.hexagonal.web.mapper.CustomerWebMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Adapter
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerCRUDController {
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package de.strasser.peter.hexagonal.web;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.port.in.RegisterCustomerUseCase;
|
||||
import de.strasser.peter.hexagonal.web.mapper.RegisterCustomerWebMapper;
|
||||
import de.strasser.peter.hexagonal.common.Adapter;
|
||||
import de.strasser.peter.hexagonal.web.dto.request.RegisterCustomerRequest;
|
||||
import de.strasser.peter.hexagonal.web.mapper.RegisterCustomerWebMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Adapter
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class RegisterCustomerController {
|
||||
private final RegisterCustomerUseCase registerCustomerUseCase;
|
||||
private final RegisterCustomerWebMapper registerCustomerMapper;
|
||||
private final RegisterCustomerUseCase registerCustomerUseCase;
|
||||
private final RegisterCustomerWebMapper registerCustomerMapper;
|
||||
|
||||
@PostMapping("/v1/register")
|
||||
public void registerCustomer(@RequestBody RegisterCustomerRequest registerCustomerRequest) {
|
||||
registerCustomerUseCase.register(registerCustomerMapper.toCmd(registerCustomerRequest));
|
||||
}
|
||||
@PostMapping("/v1/register")
|
||||
public void registerCustomer(@RequestBody RegisterCustomerRequest registerCustomerRequest) {
|
||||
registerCustomerUseCase.register(registerCustomerMapper.toCmd(registerCustomerRequest));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,4 @@ package de.strasser.peter.hexagonal.web.config;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig {
|
||||
|
||||
}
|
||||
public class WebConfig {}
|
||||
|
||||
@@ -8,9 +8,9 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(force = true)
|
||||
public class AddAddressRequest {
|
||||
String type;
|
||||
String street;
|
||||
Integer houseNumber;
|
||||
Integer zipCode;
|
||||
String country;
|
||||
String type;
|
||||
String street;
|
||||
Integer houseNumber;
|
||||
Integer zipCode;
|
||||
String country;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.time.LocalDate;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(force = true)
|
||||
public class RegisterCustomerRequest {
|
||||
String name;
|
||||
LocalDate birthDay;
|
||||
String password;
|
||||
String name;
|
||||
LocalDate birthDay;
|
||||
String password;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ package de.strasser.peter.hexagonal.web.dto.response;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public enum AddressTypeResponse {
|
||||
@JsonProperty("default")
|
||||
DEFAULT,
|
||||
@JsonProperty("shipping")
|
||||
SHIPPING,
|
||||
@JsonProperty("billing")
|
||||
BILLING;
|
||||
@JsonProperty("default")
|
||||
DEFAULT,
|
||||
@JsonProperty("shipping")
|
||||
SHIPPING,
|
||||
@JsonProperty("billing")
|
||||
BILLING;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package de.strasser.peter.hexagonal.web.dto.response;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.domain.Address;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -14,32 +14,36 @@ import java.time.LocalDateTime;
|
||||
@ControllerAdvice
|
||||
public class ErrorHandling {
|
||||
|
||||
@ExceptionHandler(ConstraintViolationException.class)
|
||||
public ResponseEntity<ErrorResponse> constrainViolationException(HttpServletRequest req, ConstraintViolationException exc) {
|
||||
return ErrorResponse.createErrorResp(req, HttpStatus.BAD_REQUEST, exc);
|
||||
}
|
||||
@ExceptionHandler(ConstraintViolationException.class)
|
||||
public ResponseEntity<ErrorResponse> constrainViolationException(
|
||||
HttpServletRequest req, ConstraintViolationException exc) {
|
||||
return ErrorResponse.createErrorResp(req, HttpStatus.BAD_REQUEST, exc);
|
||||
}
|
||||
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public ResponseEntity<ErrorResponse> constrainViolationException(HttpServletRequest req, BusinessException exc) {
|
||||
return ErrorResponse.createErrorResp(req, HttpStatus.BAD_REQUEST, exc);
|
||||
}
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public ResponseEntity<ErrorResponse> constrainViolationException(
|
||||
HttpServletRequest req, BusinessException exc) {
|
||||
return ErrorResponse.createErrorResp(req, HttpStatus.BAD_REQUEST, exc);
|
||||
}
|
||||
|
||||
@Value
|
||||
public static class ErrorResponse {
|
||||
String timestamp;
|
||||
Integer status;
|
||||
String error;
|
||||
String message;
|
||||
String path;
|
||||
@Value
|
||||
public static class ErrorResponse {
|
||||
String timestamp;
|
||||
Integer status;
|
||||
String error;
|
||||
String message;
|
||||
String path;
|
||||
|
||||
public static ResponseEntity<ErrorResponse> createErrorResp(HttpServletRequest req, HttpStatus code, Exception e) {
|
||||
final ErrorResponse errResponse = new ErrorResponse(
|
||||
LocalDateTime.now().toString(),
|
||||
code.value(),
|
||||
e.getClass().getSimpleName(),
|
||||
e.getMessage(),
|
||||
req.getRequestURI());
|
||||
return ResponseEntity.status(code).body(errResponse);
|
||||
}
|
||||
public static ResponseEntity<ErrorResponse> createErrorResp(
|
||||
HttpServletRequest req, HttpStatus code, Exception e) {
|
||||
final ErrorResponse errResponse =
|
||||
new ErrorResponse(
|
||||
LocalDateTime.now().toString(),
|
||||
code.value(),
|
||||
e.getClass().getSimpleName(),
|
||||
e.getMessage(),
|
||||
req.getRequestURI());
|
||||
return ResponseEntity.status(code).body(errResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AddAddressWebMapper {
|
||||
AddAddressCommand toCmd(AddAddressRequest addAddressRequest);
|
||||
AddAddressCommand toCmd(AddAddressRequest addAddressRequest);
|
||||
}
|
||||
|
||||
@@ -11,5 +11,4 @@ public interface CustomerWebMapper {
|
||||
CustomerResponse toResponse(Customer customer);
|
||||
|
||||
List<CustomerResponse> toResponse(List<Customer> customer);
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper
|
||||
public interface RegisterCustomerWebMapper {
|
||||
@Mapping(source = "password", target = "clearPassword")
|
||||
RegisterCustomerCommand toCmd(RegisterCustomerRequest registerCustomerRequest);
|
||||
@Mapping(source = "password", target = "clearPassword")
|
||||
RegisterCustomerCommand toCmd(RegisterCustomerRequest registerCustomerRequest);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ class RegisterCustomerControllerTest {
|
||||
|
||||
@Test
|
||||
public void should_DenyRequest_When_SendingInvalidDateFormat() throws Exception {
|
||||
final String body = ReadStringResources.readStringFromResource("invalid_date_register_customer.json");
|
||||
final String body =
|
||||
ReadStringResources.readStringFromResource("invalid_date_register_customer.json");
|
||||
|
||||
mockMvc
|
||||
.perform(post("/v1/register").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package de.strasser.peter.hexagonal.web;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class WebTestConfiguration {
|
||||
|
||||
|
||||
}
|
||||
public class WebTestConfiguration {}
|
||||
|
||||
167
application/.mvn/wrapper/MavenWrapperDownloader.java
vendored
167
application/.mvn/wrapper/MavenWrapperDownloader.java
vendored
@@ -21,98 +21,99 @@ import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/** Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */
|
||||
private static final String DEFAULT_DOWNLOAD_URL =
|
||||
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION
|
||||
+ "/maven-wrapper-"
|
||||
+ WRAPPER_VERSION
|
||||
+ ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use
|
||||
* instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
/** Path where the maven-wrapper.jar will be saved to. */
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '"
|
||||
+ outputFile.getParentFile().getAbsolutePath()
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(
|
||||
new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
}
|
||||
|
||||
8
application/mvnw
vendored
8
application/mvnw
vendored
@@ -316,7 +316,7 @@ export MAVEN_CMD_LINE_ARGS
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.strasser.peter.hexagonal.application.customer.exception;
|
||||
|
||||
public class AddressTypeDoesNotExistsExc extends BusinessException {
|
||||
public AddressTypeDoesNotExistsExc(String type) {
|
||||
super(String.format("Adress of type '%s' does not exist!", type));
|
||||
}
|
||||
public AddressTypeDoesNotExistsExc(String type) {
|
||||
super(String.format("Adress of type '%s' does not exist!", type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.strasser.peter.hexagonal.application.customer.exception;
|
||||
|
||||
public abstract class BusinessException extends IllegalStateException {
|
||||
public BusinessException(String error) {
|
||||
super(error);
|
||||
}
|
||||
public BusinessException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package de.strasser.peter.hexagonal.application.customer.exception;
|
||||
|
||||
public class DefaultAdressRequiredToActivateExc extends BusinessException {
|
||||
|
||||
public DefaultAdressRequiredToActivateExc() {
|
||||
super("Customer needs to have at least a default adress to be able to be activated!");
|
||||
}
|
||||
public DefaultAdressRequiredToActivateExc() {
|
||||
super("Customer needs to have at least a default adress to be able to be activated!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package de.strasser.peter.hexagonal.application.customer.exception;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class TooYoungExc extends BusinessException {
|
||||
public TooYoungExc(int age) {
|
||||
super(MessageFormat.format("Customer is too young. Expected: > 18 yrs, Actual: {0}", age));
|
||||
}
|
||||
public TooYoungExc(int age) {
|
||||
super(MessageFormat.format("Customer is too young. Expected: > 18 yrs, Actual: {0}", age));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AddAddressMapper {
|
||||
ValidateAddressCommand toOutCmd(AddAddressCommand addAddressCommand);
|
||||
ValidateAddressCommand toOutCmd(AddAddressCommand addAddressCommand);
|
||||
}
|
||||
|
||||
@@ -9,5 +9,6 @@ import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
public interface AddAddressUseCase {
|
||||
void addAddresses(@Min(0) BigInteger customerId, @Valid @NotEmpty List<AddAddressCommand> addresses);
|
||||
void addAddresses(
|
||||
@Min(0) BigInteger customerId, @Valid @NotEmpty List<AddAddressCommand> addresses);
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ import de.strasser.peter.hexagonal.application.customer.port.in.commands.Registe
|
||||
import javax.validation.Valid;
|
||||
|
||||
public interface RegisterCustomerUseCase {
|
||||
void register(@Valid RegisterCustomerCommand registerCustomerCommand);
|
||||
void register(@Valid RegisterCustomerCommand registerCustomerCommand);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,12 @@ import javax.validation.constraints.NotEmpty;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(force = true)
|
||||
public class AddAddressCommand {
|
||||
@NotEmpty String type;
|
||||
@NotEmpty String street;
|
||||
Integer houseNumber;
|
||||
@Min(0)
|
||||
Integer zipCode;
|
||||
@NotEmpty String country;
|
||||
@NotEmpty String type;
|
||||
@NotEmpty String street;
|
||||
Integer houseNumber;
|
||||
|
||||
@Min(0)
|
||||
Integer zipCode;
|
||||
|
||||
@NotEmpty String country;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package de.strasser.peter.hexagonal.application.customer.port.in.commands;
|
||||
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.validator.SecurePassword;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -14,7 +13,7 @@ import java.time.LocalDate;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(force = true)
|
||||
public class RegisterCustomerCommand {
|
||||
@NotEmpty String name;
|
||||
@Past LocalDate birthDay;
|
||||
@SecurePassword String clearPassword;
|
||||
@NotEmpty String name;
|
||||
@Past LocalDate birthDay;
|
||||
@SecurePassword String clearPassword;
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ import de.strasser.peter.hexagonal.application.customer.domain.Address;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.commands.ValidateAddressCommand;
|
||||
|
||||
public interface AddressValidatorPort {
|
||||
Address validate(ValidateAddressCommand validateAddressCommand);
|
||||
Address validate(ValidateAddressCommand validateAddressCommand);
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ import de.strasser.peter.hexagonal.application.customer.domain.Customer;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public interface LoadCustomerPort {
|
||||
Customer findById(BigInteger id);
|
||||
Customer findById(BigInteger id);
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ package de.strasser.peter.hexagonal.application.customer.port.out;
|
||||
import de.strasser.peter.hexagonal.application.customer.domain.Customer;
|
||||
|
||||
public interface SaveCustomerPort {
|
||||
void upsert(Customer customer);
|
||||
void upsert(Customer customer);
|
||||
}
|
||||
|
||||
@@ -22,28 +22,30 @@ import java.util.Map;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
class AddressService implements AddAddressUseCase {
|
||||
private final SaveCustomerPort saveCustomerAdapter;
|
||||
private final AddressValidatorPort addressValidatorAdapter;
|
||||
private final LoadCustomerPort loadCustomerAdapter;
|
||||
private final AddAddressMapper addAddressMapper;
|
||||
private final SaveCustomerPort saveCustomerAdapter;
|
||||
private final AddressValidatorPort addressValidatorAdapter;
|
||||
private final LoadCustomerPort loadCustomerAdapter;
|
||||
private final AddAddressMapper addAddressMapper;
|
||||
|
||||
@Override
|
||||
public void addAddresses(@Min(0) BigInteger customerId, @Valid @NotEmpty List<AddAddressCommand> addAddressCmds) {
|
||||
final Customer customer = loadCustomerAdapter.findById(customerId);
|
||||
@Override
|
||||
public void addAddresses(
|
||||
@Min(0) BigInteger customerId, @Valid @NotEmpty List<AddAddressCommand> addAddressCmds) {
|
||||
final Customer customer = loadCustomerAdapter.findById(customerId);
|
||||
|
||||
final Map<Address.AddressType, Address> addresses = new HashMap<>();
|
||||
addAddressCmds.forEach(addAddressCommand -> validateAndAddToMap(addresses, addAddressCommand));
|
||||
final Map<Address.AddressType, Address> addresses = new HashMap<>();
|
||||
addAddressCmds.forEach(addAddressCommand -> validateAndAddToMap(addresses, addAddressCommand));
|
||||
|
||||
customer.addAddresses(addresses);
|
||||
customer.addAddresses(addresses);
|
||||
|
||||
saveCustomerAdapter.upsert(customer);
|
||||
}
|
||||
saveCustomerAdapter.upsert(customer);
|
||||
}
|
||||
|
||||
private void validateAndAddToMap(Map<Address.AddressType, Address> addresses, AddAddressCommand addAddressCommand) {
|
||||
final var addressType = Address.AddressType.fromString(addAddressCommand.getType());
|
||||
final var validateAddressCmd = addAddressMapper.toOutCmd(addAddressCommand);
|
||||
final var validatedAddress = addressValidatorAdapter.validate(validateAddressCmd);
|
||||
private void validateAndAddToMap(
|
||||
Map<Address.AddressType, Address> addresses, AddAddressCommand addAddressCommand) {
|
||||
final var addressType = Address.AddressType.fromString(addAddressCommand.getType());
|
||||
final var validateAddressCmd = addAddressMapper.toOutCmd(addAddressCommand);
|
||||
final var validatedAddress = addressValidatorAdapter.validate(validateAddressCmd);
|
||||
|
||||
addresses.put(addressType, validatedAddress);
|
||||
}
|
||||
addresses.put(addressType, validatedAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,18 @@ import javax.validation.Valid;
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
class RegisterCustomerService implements RegisterCustomerUseCase {
|
||||
private final SaveCustomerPort saveUser;
|
||||
private final SaveCustomerPort saveUser;
|
||||
|
||||
@Override
|
||||
public void register(@Valid RegisterCustomerCommand registerCmd) {
|
||||
var encryptedPw = this.superSecureHashingAlgorithm(registerCmd.getClearPassword());
|
||||
var newCustomer = Customer.newCustomer(registerCmd.getName(), encryptedPw, registerCmd.getBirthDay());
|
||||
@Override
|
||||
public void register(@Valid RegisterCustomerCommand registerCmd) {
|
||||
var encryptedPw = this.superSecureHashingAlgorithm(registerCmd.getClearPassword());
|
||||
var newCustomer =
|
||||
Customer.newCustomer(registerCmd.getName(), encryptedPw, registerCmd.getBirthDay());
|
||||
|
||||
saveUser.upsert(newCustomer);
|
||||
}
|
||||
saveUser.upsert(newCustomer);
|
||||
}
|
||||
|
||||
private String superSecureHashingAlgorithm(String s) {
|
||||
return new StringBuilder(s).reverse().toString();
|
||||
}
|
||||
private String superSecureHashingAlgorithm(String s) {
|
||||
return new StringBuilder(s).reverse().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package de.strasser.peter.hexagonal.application.customer.domain;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.exception.TooOldToDeactivateExc;
|
||||
import de.strasser.peter.hexagonal.application.customer.exception.TooYoungExc;
|
||||
import de.strasser.peter.hexagonal.application.customer.mapper.AddAddressMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collections;
|
||||
@@ -13,7 +11,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class CustomerTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void should_CreateNewCustomer() {
|
||||
final var customer = Customer.newCustomer("name", "pw", LocalDate.of(1980, 1, 1));
|
||||
@@ -57,10 +54,8 @@ class CustomerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_ThrowTooOldErr_When_DeactivatingOldCustomer(){
|
||||
public void should_ThrowTooOldErr_When_DeactivatingOldCustomer() {
|
||||
final Customer customer = Customer.newCustomer("name", "pw", LocalDate.of(1950, 1, 1));
|
||||
assertThrows(TooOldToDeactivateExc.class, customer::deactivate);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.strasser.peter.hexagonal.application.customer.service;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.domain.Address;
|
||||
import de.strasser.peter.hexagonal.application.customer.domain.Customer;
|
||||
import de.strasser.peter.hexagonal.application.customer.mapper.AddAddressMapper;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.in.commands.AddAddressCommand;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.AddressValidatorPort;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.LoadCustomerPort;
|
||||
@@ -12,7 +11,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package de.strasser.peter.hexagonal.application.customer.service;
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.mapper.AddAddressMapper;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.in.commands.RegisterCustomerCommand;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.AddressValidatorPort;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.LoadCustomerPort;
|
||||
@@ -21,48 +20,47 @@ import static org.mockito.BDDMockito.willDoNothing;
|
||||
@SpringBootTest
|
||||
class RegisterCustomerServiceTest {
|
||||
|
||||
@Autowired
|
||||
private RegisterCustomerService sut;
|
||||
@Autowired private RegisterCustomerService sut;
|
||||
|
||||
@MockBean
|
||||
private SaveCustomerPort saveCustomerAdapterMock;
|
||||
@MockBean
|
||||
private AddressValidatorPort addressValidatorAdapterMock;
|
||||
@MockBean
|
||||
private LoadCustomerPort loadCustomerAdapterMock;
|
||||
@MockBean private SaveCustomerPort saveCustomerAdapterMock;
|
||||
@MockBean private AddressValidatorPort addressValidatorAdapterMock;
|
||||
@MockBean private LoadCustomerPort loadCustomerAdapterMock;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
willDoNothing().given(saveCustomerAdapterMock).upsert(any());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
willDoNothing().given(saveCustomerAdapterMock).upsert(any());
|
||||
}
|
||||
@Test
|
||||
public void should_ThrowInvalidBirthDate_When_PassingDateInFuture() {
|
||||
RegisterCustomerCommand registerCustomerCommand =
|
||||
new RegisterCustomerCommand("Hans", LocalDate.now().plusDays(1), "secretPassword");
|
||||
|
||||
@Test
|
||||
public void should_ThrowInvalidBirthDate_When_PassingDateInFuture() {
|
||||
RegisterCustomerCommand registerCustomerCommand =
|
||||
new RegisterCustomerCommand("Hans", LocalDate.now().plusDays(1), "secretPassword");
|
||||
|
||||
assertThrows(ConstraintViolationException.class, () -> {
|
||||
sut.register(registerCustomerCommand);
|
||||
assertThrows(
|
||||
ConstraintViolationException.class,
|
||||
() -> {
|
||||
sut.register(registerCustomerCommand);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_ThrowInvalidPassword_When_PassingInsecurePassword() {
|
||||
LocalDate birthday = LocalDate.of(1980, 1, 1);
|
||||
RegisterCustomerCommand registerCustomerCommand =
|
||||
new RegisterCustomerCommand("Hans", birthday, "secretPassword");
|
||||
@Test
|
||||
public void should_ThrowInvalidPassword_When_PassingInsecurePassword() {
|
||||
LocalDate birthday = LocalDate.of(1980, 1, 1);
|
||||
RegisterCustomerCommand registerCustomerCommand =
|
||||
new RegisterCustomerCommand("Hans", birthday, "secretPassword");
|
||||
|
||||
assertThrows(ConstraintViolationException.class, () -> {
|
||||
sut.register(registerCustomerCommand);
|
||||
assertThrows(
|
||||
ConstraintViolationException.class,
|
||||
() -> {
|
||||
sut.register(registerCustomerCommand);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_SaveUser() {
|
||||
LocalDate birthday = LocalDate.of(1980, 1, 1);
|
||||
RegisterCustomerCommand registerCustomerCommand =
|
||||
new RegisterCustomerCommand("Hans", birthday, "Ha012!321+dw");
|
||||
sut.register(registerCustomerCommand);
|
||||
}
|
||||
@Test
|
||||
public void should_SaveUser() {
|
||||
LocalDate birthday = LocalDate.of(1980, 1, 1);
|
||||
RegisterCustomerCommand registerCustomerCommand =
|
||||
new RegisterCustomerCommand("Hans", birthday, "Ha012!321+dw");
|
||||
sut.register(registerCustomerCommand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?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"
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.strasser.peter.hexagonal.common;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Component
|
||||
public @interface Adapter {
|
||||
|
||||
/**
|
||||
* The value may indicate a suggestion for a logical component name, to be turned into a Spring
|
||||
* bean in case of an autodetected component.
|
||||
*
|
||||
* @return the suggested component name, if any (or empty String otherwise)
|
||||
*/
|
||||
@AliasFor(annotation = Component.class)
|
||||
String value() default "";
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.strasser.peter.hexagonal.common.validators;
|
||||
package de.strasser.peter.hexagonal.common;
|
||||
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.strasser.peter.hexagonal.common;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Component
|
||||
public @interface UseCase {
|
||||
|
||||
/**
|
||||
* The value may indicate a suggestion for a logical component name, to be turned into a Spring
|
||||
* bean in case of an autodetected component.
|
||||
*
|
||||
* @return the suggested component name, if any (or empty String otherwise)
|
||||
*/
|
||||
@AliasFor(annotation = Component.class)
|
||||
String value() default "";
|
||||
}
|
||||
167
config/.mvn/wrapper/MavenWrapperDownloader.java
vendored
167
config/.mvn/wrapper/MavenWrapperDownloader.java
vendored
@@ -21,98 +21,99 @@ import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/** Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */
|
||||
private static final String DEFAULT_DOWNLOAD_URL =
|
||||
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION
|
||||
+ "/maven-wrapper-"
|
||||
+ WRAPPER_VERSION
|
||||
+ ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to use
|
||||
* instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
/** Path where the maven-wrapper.jar will be saved to. */
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if (mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
if (mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if (!outputFile.getParentFile().exists()) {
|
||||
if (!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '"
|
||||
+ outputFile.getParentFile().getAbsolutePath()
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(
|
||||
new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
}
|
||||
|
||||
8
config/mvnw
vendored
8
config/mvnw
vendored
@@ -316,7 +316,7 @@ export MAVEN_CMD_LINE_ARGS
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
|
||||
@@ -48,6 +48,8 @@
|
||||
<groupId>de.strasser.peter.hexagonal</groupId>
|
||||
<artifactId>persistence</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class HexagonalApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HexagonalApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HexagonalApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package de.strasser.peter.hexagonal.config;
|
||||
|
||||
public class ArchitectureTest {}
|
||||
@@ -6,8 +6,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
@SpringBootTest
|
||||
class HexagonalApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextLoads() {}
|
||||
}
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -25,6 +25,7 @@
|
||||
<addressvalidation.version>0.0.1-SNAPSHOT</addressvalidation.version>
|
||||
<web.version>0.0.1-SNAPSHOT</web.version>
|
||||
<persistence.version>0.0.1-SNAPSHOT</persistence.version>
|
||||
<archunit.version>0.18.0</archunit.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -77,6 +78,13 @@
|
||||
<artifactId>persistence</artifactId>
|
||||
<version>${persistence.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tngtech.archunit</groupId>
|
||||
<artifactId>archunit</artifactId>
|
||||
<version>${archunit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user