Skip to content

Commit

Permalink
Add view endpoint and test
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok committed Mar 4, 2024
1 parent ef94861 commit 72f4cf3
Show file tree
Hide file tree
Showing 28 changed files with 392 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import smecalculus.bezmen.construction.SepulkaClientBeans;
import smecalculus.bezmen.core.SepulkaMessageDm;
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationRequest;
import smecalculus.bezmen.core.SepulkaMessageDmEg;
import smecalculus.bezmen.core.SepulkaService;
Expand Down Expand Up @@ -44,4 +45,24 @@ void shouldRegisterSepulka() {
.ignoringExpectedNullFields()
.isEqualTo(expectedResponse);
}

@Test
void shouldViewSepulka() {
// given
var externalId = UUID.randomUUID().toString();
// and
var request = SepulkaMessageEmEg.viewRequest(externalId);
// and
when(serviceMock.view(any(SepulkaMessageDm.ViewRequest.class)))
.thenReturn(SepulkaMessageDmEg.viewResponse(externalId).build());
// and
var expectedResponse = SepulkaMessageEmEg.viewResponse(externalId);
// when
var actualResponse = externalClient.view(request);
// then
assertThat(actualResponse)
.usingRecursiveComparison()
.ignoringExpectedNullFields()
.isEqualTo(expectedResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import static java.util.UUID.randomUUID;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.core.SepulkaMessageDm.PreviewRequest;
import smecalculus.bezmen.core.SepulkaMessageDm.PreviewResponse;
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationRequest;
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationResponse;
import smecalculus.bezmen.core.SepulkaMessageDm.ViewRequest;
import smecalculus.bezmen.core.SepulkaMessageDm.ViewResponse;
import smecalculus.bezmen.storage.SepulkaDao;

@RequiredArgsConstructor
Expand All @@ -37,7 +35,7 @@ public RegistrationResponse register(RegistrationRequest request) {
}

@Override
public List<PreviewResponse> view(PreviewRequest request) {
return Collections.emptyList();
public ViewResponse view(ViewRequest request) {
return new ViewResponse(request.externalId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import smecalculus.bezmen.core.SepulkaService;
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationRequest;
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationResponse;
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewRequest;
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewResponse;
import smecalculus.bezmen.validation.EdgeValidator;

@RequiredArgsConstructor
Expand All @@ -26,4 +28,12 @@ public RegistrationResponse register(RegistrationRequest requestEdge) {
var response = service.register(request);
return mapper.toEdge(response);
}

@Override
public ViewResponse view(ViewRequest requestEdge) {
validator.validate(requestEdge);
var request = mapper.toDomain(requestEdge);
var response = service.view(request);
return mapper.toEdge(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smecalculus.bezmen.messaging.SepulkaClient;
import smecalculus.bezmen.messaging.SepulkaMessageEm;
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationRequest;
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationResponse;
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewResponse;

@RestController
@RequestMapping("sepulkas")
Expand All @@ -21,8 +25,16 @@ public class SepulkaController {
private SepulkaClient client;

@PostMapping
ResponseEntity<RegistrationResponse> register(@RequestBody RegistrationRequest requestEdge) {
var responseEdge = client.register(requestEdge);
return ResponseEntity.status(HttpStatus.CREATED).body(responseEdge);
ResponseEntity<RegistrationResponse> register(@RequestBody RegistrationRequest request) {
var response = client.register(request);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

@GetMapping("/{externalId}")
ResponseEntity<ViewResponse> view(@PathVariable("externalId") String externalId) {
var request = new SepulkaMessageEm.ViewRequest();
request.setExternalId(externalId);
var response = client.view(request);
return ResponseEntity.status(HttpStatus.OK).body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.UUID
@ExtendWith(SpringExtension::class)
@ContextConfiguration(classes = [SepulkaClientBeans::class])
abstract class SepulkaClientIT {

@Autowired
private lateinit var externalClient: SepulkaClient

Expand All @@ -42,4 +43,24 @@ abstract class SepulkaClientIT {
.ignoringExpectedNullFields()
.isEqualTo(expectedResponse)
}

@Test
fun shouldViewSepulka() {
// given
val externalId = UUID.randomUUID().toString()
// and
val request = SepulkaMessageEmEg.viewRequest(externalId)
// and
whenever(serviceMock.view(any(SepulkaMessageDm.ViewRequest::class.java)))
.thenReturn(SepulkaMessageDmEg.viewResponse(externalId).build())
// and
val expectedResponse = SepulkaMessageEmEg.viewResponse(externalId)
// when
val actualResponse = externalClient.view(request)
// then
assertThat(actualResponse)
.usingRecursiveComparison()
.ignoringExpectedNullFields()
.isEqualTo(expectedResponse)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package smecalculus.bezmen.core

import smecalculus.bezmen.core.SepulkaMessageDm.PreviewRequest
import smecalculus.bezmen.core.SepulkaMessageDm.PreviewResponse
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationRequest
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationResponse
import smecalculus.bezmen.core.SepulkaMessageDm.ViewRequest
import smecalculus.bezmen.core.SepulkaMessageDm.ViewResponse
import smecalculus.bezmen.storage.SepulkaDao
import java.time.LocalDateTime
import java.util.UUID
Expand All @@ -25,7 +25,7 @@ class SepulkaServiceImpl(
return converter.toMessage(sepulkaSaved).build()
}

override fun view(request: PreviewRequest): List<PreviewResponse> {
return listOf()
override fun view(request: ViewRequest): ViewResponse {
return ViewResponse(request.externalId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package smecalculus.bezmen.messaging
import smecalculus.bezmen.core.SepulkaService
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationRequest
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationResponse
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewRequest
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewResponse
import smecalculus.bezmen.validation.EdgeValidator

class SepulkaClientImpl(
Expand All @@ -16,4 +18,11 @@ class SepulkaClientImpl(
val response = service.register(request)
return mapper.toEdge(response)
}

override fun view(requestEdge: ViewRequest): ViewResponse {
validator.validate(requestEdge)
val request = mapper.toDomain(requestEdge)
val response = service.view(request)
return mapper.toEdge(response)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package smecalculus.bezmen.messaging.springmvc

import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import smecalculus.bezmen.messaging.SepulkaClient
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationRequest
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationResponse
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewRequest
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewResponse

@RestController
@RequestMapping("sepulkas")
Expand All @@ -17,9 +21,19 @@ class SepulkaController(
) {
@PostMapping
fun register(
@RequestBody requestEdge: RegistrationRequest,
@RequestBody request: RegistrationRequest,
): ResponseEntity<RegistrationResponse> {
val responseEdge = client.register(requestEdge)
return ResponseEntity.status(HttpStatus.CREATED).body(responseEdge)
val response = client.register(request)
return ResponseEntity.status(HttpStatus.CREATED).body(response)
}

@GetMapping("/{externalId}")
fun register(
@PathVariable("externalId") externalId: String,
): ResponseEntity<ViewResponse> {
val request = ViewRequest()
request.externalId = externalId
val response = client.view(request)
return ResponseEntity.status(HttpStatus.OK).body(response)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationRequest;
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationResponse;
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewRequest;
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewResponse;

/**
* Port: client side
*/
public interface SepulkaClient {
RegistrationResponse register(RegistrationRequest request);

ViewResponse view(ViewRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,23 @@ public static class RegistrationRequest {

@Data
public static class RegistrationResponse {
String externalId;
}

@Data
public static class SearchResponse {
String externalId;
}

@Data
public static class ViewRequest {
@NotNull
@Size(min = 1, max = 64)
String externalId;
}

@Data
public static class ViewResponse {
String externalId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.UUID;
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationRequest;
import smecalculus.bezmen.messaging.SepulkaMessageEm.RegistrationResponse;
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewRequest;
import smecalculus.bezmen.messaging.SepulkaMessageEm.ViewResponse;

public abstract class SepulkaMessageEmEg {
public static RegistrationRequest registrationRequest() {
Expand All @@ -28,4 +30,28 @@ public static RegistrationResponse registrationResponse(String externalId) {
responseEdge.setExternalId(externalId);
return responseEdge;
}

public static ViewRequest viewRequest() {
var requestEdge = new ViewRequest();
requestEdge.setExternalId(UUID.randomUUID().toString());
return requestEdge;
}

public static ViewRequest viewRequest(String id) {
var requestEdge = viewRequest();
requestEdge.setExternalId(id);
return requestEdge;
}

public static ViewResponse viewResponse() {
var responseEdge = new ViewResponse();
responseEdge.setExternalId(UUID.randomUUID().toString());
return responseEdge;
}

public static ViewResponse viewResponse(String externalId) {
var responseEdge = viewResponse();
responseEdge.setExternalId(externalId);
return responseEdge;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public record RegistrationRequest(@NonNull String externalId) {}
public record RegistrationResponse(@NonNull String externalId) {}

@Builder
public record PreviewRequest(@NonNull String externalId) {}
public record ViewRequest(@NonNull String externalId) {}

@Builder
public record PreviewResponse(@NonNull String externalId) {}
public record ViewResponse(@NonNull String externalId) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.UUID;
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationResponse;
import smecalculus.bezmen.core.SepulkaMessageDm.ViewResponse;

public class SepulkaMessageDmEg {
public static RegistrationResponse.Builder registrationResponse() {
Expand All @@ -11,4 +12,12 @@ public static RegistrationResponse.Builder registrationResponse() {
public static RegistrationResponse.Builder registrationResponse(String externalId) {
return registrationResponse().externalId(externalId);
}

public static ViewResponse.Builder viewResponse() {
return ViewResponse.builder().externalId(UUID.randomUUID().toString());
}

public static ViewResponse.Builder viewResponse(String externalId) {
return viewResponse().externalId(externalId);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package smecalculus.bezmen.core;

import java.util.List;
import smecalculus.bezmen.core.SepulkaMessageDm.PreviewRequest;
import smecalculus.bezmen.core.SepulkaMessageDm.PreviewResponse;
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationRequest;
import smecalculus.bezmen.core.SepulkaMessageDm.RegistrationResponse;
import smecalculus.bezmen.core.SepulkaMessageDm.ViewRequest;
import smecalculus.bezmen.core.SepulkaMessageDm.ViewResponse;

public interface SepulkaService {
RegistrationResponse register(RegistrationRequest request);

List<PreviewResponse> view(PreviewRequest request);
ViewResponse view(ViewRequest request);
}
7 changes: 6 additions & 1 deletion lib/essentials/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
<packaging>jar</packaging>

<dependencies>
<!--ABSTRACTION-->
<!--CORE-->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>abstraction</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>testing</artifactId>
<scope>test</scope>
</dependency>
<!--SERDE-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Loading

0 comments on commit 72f4cf3

Please sign in to comment.