Skip to content

Commit

Permalink
chore+refacto(jpa) add mapstruct + fix jpa repo to have a spring cont…
Browse files Browse the repository at this point in the history
…ext ok
  • Loading branch information
mpumd committed Oct 9, 2024
1 parent 7110e9a commit 283a341
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 12 deletions.
39 changes: 36 additions & 3 deletions infra-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

<springdoc-openapi-starter.version>2.6.0</springdoc-openapi-starter.version>
<spring-boot.version>3.3.4</spring-boot.version>

<mapstruct.version>1.6.2</mapstruct.version>
</properties>

<dependencyManagement>
Expand All @@ -48,20 +50,26 @@
<!-- infra -->
<dependency>
<groupId>com.mpumd.poc</groupId>
<artifactId>sb-in</artifactId>
<artifactId>sb-application</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mpumd.poc</groupId>
<artifactId>sb-out</artifactId>
<artifactId>sb-in</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mpumd.poc</groupId>
<artifactId>sb-application</artifactId>
<artifactId>sb-out</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>

<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
Expand Down Expand Up @@ -119,4 +127,29 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.mpumd.poc.person.sb.application;

import com.mpumd.poc.person.application.PersonApplicationService;
import com.mpumd.poc.person.context.PersonPersistanceRepository;
import com.mpumd.poc.person.context.command.PersonRegistrationCommand;
import lombok.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PersonAppSvc extends com.mpumd.poc.person.application.PersonApplicationService {
public PersonAppSvc(@NonNull PersonPersistanceRepository personPersistanceRepository) {
public class PersonAppSvc extends PersonApplicationService {

public PersonAppSvc(PersonPersistanceRepository personPersistanceRepository) {
super(personPersistanceRepository);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mpumd.poc.person.sb.application;

import com.mpumd.poc.person.application.PersonApplicationService;
import com.mpumd.poc.person.context.PersonPersistanceRepository;
import com.mpumd.poc.person.context.command.PersonRegistrationCommand;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doNothing;

@ExtendWith(MockitoExtension.class)
class PersonAppSvcTest {

@Mock
PersonPersistanceRepository persistanceRepository;

@InjectMocks
@Spy
PersonAppSvc personAppSvc;

@Mock
PersonRegistrationCommand cmd;

@Test
void shouldCallSuperRegister() {
var captor = ArgumentCaptor.forClass(PersonRegistrationCommand.class);
doNothing().when((PersonApplicationService)personAppSvc).register(captor.capture());

personAppSvc.register(cmd);

assertEquals(captor.getValue(), cmd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- changeset mpumd:1

CREATE TABLE IF NOT EXISTS PERSON (
id VARCHAR(36) NOT NULL UNIQUE,
id UUID NOT NULL UNIQUE,
first_name VARCHAR(255),
last_name VARCHAR(255),
gender VARCHAR(255),
Expand Down
5 changes: 5 additions & 0 deletions infra-spring/sb-out/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<artifactId>context-person</artifactId>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mpumd.poc.person.sb.jpa;

// optional at this moment
//@EnableJpaRepositories(basePackages = "com.mpumd.poc.person.sb.jpa")
//@EntityScan("com.mpumd.poc.person.sb.jpa.entity")
public class JpaConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import com.mpumd.poc.person.context.PersonPersistanceRepository;
import com.mpumd.poc.person.context.aggregat.Person;
import com.mpumd.poc.person.context.query.PersonSearchQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

//interface PersonSpringRepo extends CrudRepository<PersonEntity, Long> {
//}

@Repository
@RequiredArgsConstructor
public class PersonJpaAdapter implements PersonPersistanceRepository {

private final PersonSpringRepo personSpringRepo;

@Override
public boolean isExist(PersonSearchQuery person) {
return false;
}

@Override
public void push(Person person) {

// personSpringRepo.save(perso);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mpumd.poc.person.sb.jpa;

import com.mpumd.poc.person.sb.jpa.entity.PersonEntity;
import org.springframework.data.repository.CrudRepository;

import java.util.UUID;

public interface PersonSpringRepo extends CrudRepository<PersonEntity, UUID> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import lombok.Data;

import java.time.ZonedDateTime;
import java.util.UUID;

@Data
@Table(name = "PERSON")
@Entity
public class PersonEntity {
@Id
@Column(name = "id", length = 36, unique = true)
private final String id;
private final UUID id;

@Column(name = "first_name")
private final String firstName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mpumd.poc.person.sb.jpa;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DataJpaTest
@Disabled
class PersonJpaAdapterIT {

@Test
void shouldPushInDB() {
}
}

0 comments on commit 283a341

Please sign in to comment.