BAEL-71323 re-org modules
This commit is contained in:
@@ -2,4 +2,3 @@
|
||||
|
||||
This module contains articles about design patterns.
|
||||
|
||||
- [Coupling in Java](https://www.baeldung.com/java-coupling-classes-tight-loose)
|
||||
|
||||
2
patterns-modules/coupling/README.md
Normal file
2
patterns-modules/coupling/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
- [Coupling in Java](https://www.baeldung.com/java-coupling-classes-tight-loose)
|
||||
@@ -12,10 +12,6 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>wire-tap</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?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>
|
||||
<artifactId>wire-tap</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>enterprise-patterns</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,50 +0,0 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>hexagonal-architecture</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>hexagonal-architecture</name>
|
||||
<description>Project for hexagonal architecture in java</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class HexArchApplicationDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HexArchApplicationDemo.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.config;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.services.EmployeeService;
|
||||
import com.baeldung.pattern.hexagonal.domain.services.EmployeeServiceImpl;
|
||||
import com.baeldung.pattern.hexagonal.persistence.EmployeeRepository;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class AppConfig {
|
||||
@Bean
|
||||
public EmployeeService getEmployeeService(EmployeeRepository employeeRepository) {
|
||||
return new EmployeeServiceImpl(employeeRepository);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.config;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.persistence.MongoRepoEx;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableMongoRepositories(basePackageClasses = MongoRepoEx.class)
|
||||
public class MongoConfig {
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.controller;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.model.Employee;
|
||||
import com.baeldung.pattern.hexagonal.domain.services.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/employees")
|
||||
public class EmployeeController {
|
||||
@Autowired
|
||||
EmployeeService employeeService;
|
||||
|
||||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public Employee addEmployee(@RequestBody Employee employee) {
|
||||
return employeeService.addEmployee(employee);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/{employeeId}")
|
||||
public Employee getEmployee(@PathVariable("employeeId") String employeeId) {
|
||||
return employeeService.getEmployee(employeeId);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.domain.model;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Employee {
|
||||
@Id
|
||||
private String empId;
|
||||
private String empName;
|
||||
private String empJobTitle;
|
||||
|
||||
public String getEmpId() {
|
||||
return empId;
|
||||
}
|
||||
|
||||
public void setEmpId(String empId) {
|
||||
this.empId = empId;
|
||||
}
|
||||
|
||||
public String getEmpName() {
|
||||
return empName;
|
||||
}
|
||||
|
||||
public void setEmpName(String empName) {
|
||||
this.empName = empName;
|
||||
}
|
||||
|
||||
public String getEmpJobTitle() {
|
||||
return empJobTitle;
|
||||
}
|
||||
|
||||
public void setEmpJobTitle(String empJobTitle) {
|
||||
this.empJobTitle = empJobTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Employee employee = (Employee) o;
|
||||
return empId.equals(employee.empId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(empId);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.domain.services;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.model.Employee;
|
||||
|
||||
public interface EmployeeService {
|
||||
|
||||
Employee addEmployee(Employee employee);
|
||||
|
||||
Employee getEmployee(String employeeId);
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.domain.services;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.model.Employee;
|
||||
import com.baeldung.pattern.hexagonal.persistence.EmployeeRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Autowired
|
||||
public EmployeeServiceImpl(EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Employee addEmployee(Employee employee) {
|
||||
return employeeRepository.add(employee);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Employee getEmployee(String employeeId) {
|
||||
Optional<Employee> employee = employeeRepository.findById(employeeId);
|
||||
|
||||
if (employee.isPresent()) {
|
||||
return employee.get();
|
||||
} else {
|
||||
// throw
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.persistence;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.model.Employee;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface EmployeeRepository {
|
||||
|
||||
Employee add(Employee employee);
|
||||
|
||||
Optional<Employee> findById(String id);
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.persistence;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.model.Employee;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public class MongoDBRepository implements EmployeeRepository {
|
||||
|
||||
@Autowired
|
||||
MongoRepoEx mongoRepository;
|
||||
|
||||
@Override
|
||||
public Employee add(Employee employee) {
|
||||
return mongoRepository.insert(employee);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Employee> findById(String id) {
|
||||
return mongoRepository.findById(id);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.persistence;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.model.Employee;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface MongoRepoEx extends MongoRepository<Employee, String> {
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.baeldung.pattern.hexagonal.domain.services;
|
||||
|
||||
import com.baeldung.pattern.hexagonal.domain.model.Employee;
|
||||
import com.baeldung.pattern.hexagonal.persistence.EmployeeRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class EmployeeServiceImplUnitTest {
|
||||
|
||||
private EmployeeRepository employeeRepository;
|
||||
private EmployeeService testService;
|
||||
private Employee testModel;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
employeeRepository = mock(EmployeeRepository.class);
|
||||
|
||||
testService = new EmployeeServiceImpl(employeeRepository);
|
||||
testModel = new Employee();
|
||||
testModel.setEmpId("2000");
|
||||
testModel.setEmpName("Test user 1");
|
||||
testModel.setEmpJobTitle("Software engineer");
|
||||
}
|
||||
|
||||
@Test
|
||||
void addEmployee() {
|
||||
when(employeeRepository.add(any(Employee.class))).thenReturn(testModel);
|
||||
|
||||
Employee testResponse = testService.addEmployee(testModel);
|
||||
assertEquals(testModel, testResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getEmployee() {
|
||||
when(employeeRepository.findById("2000")).thenReturn(Optional.of(testModel));
|
||||
|
||||
Employee testResponse = testService.getEmployee("2000");
|
||||
assertEquals(testModel, testResponse);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@
|
||||
<module>dip</module>
|
||||
<module>cqrs-es</module>
|
||||
<module>front-controller</module>
|
||||
<module>hexagonal-architecture</module>
|
||||
<module>intercepting-filter</module>
|
||||
<module>solid</module>
|
||||
<module>clean-architecture</module>
|
||||
|
||||
Reference in New Issue
Block a user