Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT PULL REQUEST NO REVIEW NEEDED #593

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.petclinic.bffapigateway.dtos.Visits;

/*
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
*/
*/

/*
@author Maciej Szarlinski
Copied from https://github.com/spring-petclinic/spring-petclinic-microservices
*/

/*
@Data
@NoArgsConstructor
Expand All @@ -33,5 +35,6 @@ public class VisitDetails {
private String description = null;

private Status status = null;
private String billId = null;
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class VisitResponseDTO {
private String vetEmail;
private String vetPhoneNumber;
private Status status;
private String billId;
private String customerId;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.petclinic.bffapigateway.dtos.Visits;

/*
import lombok.Value;
import java.util.ArrayList;
import java.util.List;
*/
*/

/*
* @author Maciej Szarlinski
* Copied from https://github.com/spring-petclinic/spring-petclinic-microservices
*/

/*
@Value
public class Visits {
private List<VisitDetails> items = new ArrayList<>();
}
*/

*/
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ <h3 style="margin: 0; display: inline-block;">Confirmed Visits</h3>
<!-- <td style="white-space: pre-line">{{$ctrl.getPractitionerName(v.practitionerId)}}</td>-->
<td class="border" style="white-space: pre-line">{{v.vetFirstName}} {{v.vetLastName}}</td>
<td class="border" style="white-space: pre-line">{{v.petName}}</td>
<td class="status-text" style="white-space: pre-line"></td>
<td><a href="http://localhost:8080/#!/bills/details/{{v.billId}}/owner/{{v.customerId}}">{{v.billId}}</a></td>
<td class="status-text border" style="white-space: pre-line">{{v.status}}</td>
<td class="border">
<a ng-class="{
Expand Down Expand Up @@ -234,7 +234,7 @@ <h3 style="margin: 0; display: inline-block;">Cancelled Visits</h3>
<!-- <td style="white-space: pre-line">{{$ctrl.getPractitionerName(v.practitionerId)}}</td>-->
<td class="border" style="white-space: pre-line">{{v.vetFirstName}} {{v.vetLastName}}</td>
<td class="border" style="white-space: pre-line">{{v.petName}}</td>
<td class="status-text" style="white-space: pre-line"></td>
<td><a href="http://localhost:8080/#!/bills/details/{{v.billId}}/owner/{{v.customerId}}">{{v.billId}}</a></td>
<td class="status-text border" style="white-space: pre-line">{{v.status}}</td>
<td class="border">
<a ng-class="{
Expand Down Expand Up @@ -295,7 +295,7 @@ <h3 style="margin: 0; display: inline-block;">Completed Visits</h3>
<!-- <td style="white-space: pre-line">{{$ctrl.getPractitionerName(v.practitionerId)}}</td>-->
<td class="border" style="white-space: pre-line">{{v.vetFirstName}} {{v.vetLastName}}</td>
<td class="border" style="white-space: pre-line">{{v.petName}}</td>
<td class="status-text" style="white-space: pre-line"></td>
<td><a href="http://localhost:8080/#!/bills/details/{{v.billId}}/owner/{{v.customerId}}">{{v.billId}}</a></td>
<td class="status-text border" style="white-space: pre-line">{{v.status}}</td>
<td class="border">
<a ng-class="{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.util.UriComponentsBuilder;
import org.webjars.NotFoundException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import javax.print.attribute.standard.Media;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
Expand Down Expand Up @@ -2648,82 +2646,10 @@ void getSingleVisit_Valid() {
.expectBody()
.jsonPath("$.visitId").isEqualTo(visitResponseDTO.getVisitId())
.jsonPath("$.petId").isEqualTo(visitResponseDTO.getPetId())
.jsonPath("$.visitDate").isEqualTo("2024-11-25 13:45")
.jsonPath("$.visitDate").isEqualTo("2022-11-25 13:45")
.jsonPath("$.description").isEqualTo(visitResponseDTO.getDescription())
.jsonPath("$.practitionerId").isEqualTo(visitResponseDTO.getPractitionerId());
}
@Test
void getVisitsByStatus_Valid() {
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
.visitId("73b5c112-5703-4fb7-b7bc-ac8186811ae1")
.visitDate(LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")))
.description("this is a dummy description")
.petId("2")
.petName("YourPetNameHere")
.petBirthDate(new Date())
.practitionerId("2")
.vetFirstName("VetFirstNameHere")
.vetLastName("VetLastNameHere")
.vetEmail("[email protected]")
.vetPhoneNumber("123-456-7890")
.status(Status.UPCOMING)
.build();

when(visitsServiceClient.getVisitsForStatus(visitResponseDTO.getStatus().toString())).thenReturn(Flux.just(visitResponseDTO));

client.get()
.uri("/api/gateway/visits/status/{status}", visitResponseDTO.getStatus())
.exchange()
.expectStatus().isOk()
.expectBodyList(VisitResponseDTO.class)
.consumeWith(response -> {
Assertions.assertTrue(response.getResponseBody().size() > 0);
VisitResponseDTO responseBody = response.getResponseBody().get(0);
// Asserting that the values match what's expected
Assertions.assertEquals(visitResponseDTO.getVisitId(), responseBody.getVisitId());
Assertions.assertEquals(visitResponseDTO.getPetId(), responseBody.getPetId());
Assertions.assertEquals(visitResponseDTO.getVisitDate(), responseBody.getVisitDate());
Assertions.assertEquals(visitResponseDTO.getDescription(), responseBody.getDescription());
Assertions.assertEquals(visitResponseDTO.getPractitionerId(), responseBody.getPractitionerId());
});
}

@Test
void getVisitsByPractitionerId_Valid() {
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder()
.visitId("73b5c112-5703-4fb7-b7bc-ac8186811ae1")
.visitDate(LocalDateTime.parse("2024-11-25 13:45", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")))
.description("this is a dummy description")
.petId("2")
.petName("YourPetNameHere")
.petBirthDate(new Date())
.practitionerId("2")
.vetFirstName("VetFirstNameHere")
.vetLastName("VetLastNameHere")
.vetEmail("[email protected]")
.vetPhoneNumber("123-456-7890")
.status(Status.UPCOMING)
.build();

when(visitsServiceClient.getVisitByPractitionerId(visitResponseDTO.getPractitionerId())).thenReturn(Flux.just(visitResponseDTO));

client.get()
.uri("/api/gateway/visits/vets/{practitionerId}", visitResponseDTO.getPractitionerId())
.exchange()
.expectStatus().isOk()
.expectBodyList(VisitResponseDTO.class)
.consumeWith(response -> {
Assertions.assertTrue(response.getResponseBody().size() > 0);
VisitResponseDTO responseBody = response.getResponseBody().get(0);

Assertions.assertEquals(visitResponseDTO.getVisitId(), responseBody.getVisitId());
Assertions.assertEquals(visitResponseDTO.getPetId(), responseBody.getPetId());
Assertions.assertEquals(visitResponseDTO.getVisitDate(), responseBody.getVisitDate());
Assertions.assertEquals(visitResponseDTO.getDescription(), responseBody.getDescription());
Assertions.assertEquals(visitResponseDTO.getPractitionerId(), responseBody.getPractitionerId());
});
}


// @Test
// void getSingleVisit_Invalid() {
Expand Down Expand Up @@ -3121,35 +3047,6 @@ void login_invalid() throws Exception {
}


@Test
@DisplayName("Should Logout with a Valid Session, Clearing Bearer Cookie, and Returning 204")
void logout_shouldClearBearerCookie() {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add(HttpHeaders.COOKIE, "Bearer=some.token.value; Path=/; HttpOnly; SameSite=Lax");
when(authServiceClient.logout(any(ServerHttpRequest.class), any(ServerHttpResponse.class)))
.thenReturn(Mono.just(ResponseEntity.noContent().build()));
client.post()
.uri("/api/gateway/users/logout")
.headers(httpHeaders -> httpHeaders.putAll(headers))
.exchange()
.expectStatus().isNoContent()
.expectHeader().doesNotExist(HttpHeaders.SET_COOKIE);
}

@Test
@DisplayName("Given Expired Session, Logout Should Return 401")
void logout_shouldReturnUnauthorizedForExpiredSession() {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
when(authServiceClient.logout(any(ServerHttpRequest.class), any(ServerHttpResponse.class)))
.thenReturn(Mono.just(ResponseEntity.status(HttpStatus.UNAUTHORIZED).build()));
client.post()
.uri("/api/gateway/users/logout")
.headers(httpHeaders -> httpHeaders.putAll(headers))
.exchange()
.expectStatus().isUnauthorized()
.expectHeader().doesNotExist(HttpHeaders.SET_COOKIE);
}


private InventoryResponseDTO buildInventoryDTO(){
return InventoryResponseDTO.builder()
Expand Down Expand Up @@ -3530,9 +3427,6 @@ void testAddProductToInventory_InvalidInventoryId_ShouldReturnNotFoundException(






private ProductResponseDTO buildProductDTO(){
return ProductResponseDTO.builder()
.id("1")
Expand All @@ -3555,11 +3449,6 @@ private VetResponseDTO buildVetResponseDTO() {
.phoneNumber("947-238-2847")
.resume("Just became a vet")
.workday(new HashSet<>())
.workHoursJson("{\n" +
" \"Monday\": [\"Hour_8_9\",\"Hour_9_10\",\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\"],\n" +
" \"Wednesday\": [\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\",\"Hour_18_19\",\"Hour_19_20\"],\n" +
" \"Thursday\": [\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\"]\n" +
" }")
.specialties(new HashSet<>())
.active(false)
.build();
Expand All @@ -3573,11 +3462,6 @@ private VetResponseDTO buildVetResponseDTO2() {
.phoneNumber("947-238-2847")
.resume("Just became a vet")
.workday(new HashSet<>())
.workHoursJson("{\n" +
" \"Monday\": [\"Hour_8_9\",\"Hour_9_10\",\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\"],\n" +
" \"Wednesday\": [\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\",\"Hour_18_19\",\"Hour_19_20\"],\n" +
" \"Thursday\": [\"Hour_10_11\",\"Hour_11_12\",\"Hour_12_13\",\"Hour_13_14\",\"Hour_14_15\",\"Hour_15_16\",\"Hour_16_17\",\"Hour_17_18\"]\n" +
" }")
.specialties(new HashSet<>())
.active(true)
.build();
Expand Down Expand Up @@ -3881,26 +3765,6 @@ public void getUserById_ValidUserId_ShouldReturnUser() {
assertEquals(userDetails.getEmail(), u.getEmail());
});
}

@Test
void deleteUserById_ValidUserId_ShouldDeleteUser() {
UserDetails userDetails = UserDetails.builder()
.userId("validUserId")
.username("validUsername")
.email("validEmail")
.build();

when(authServiceClient.deleteUser(anyString(), anyString()))
.thenReturn(Mono.empty());

client.delete()
.uri("/api/gateway/users/validUserId")
.cookie("Bearer", "validToken")
.exchange()
.expectStatus().isNoContent();
}


private EducationResponseDTO buildEducation(){
return EducationResponseDTO.builder()
.educationId("1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import com.petclinic.billing.businesslayer.BillService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDate;


@Service
@Component
public class DataSetupService implements CommandLineRunner {
private final BillService billService;
public DataSetupService(BillService billService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.validation.Valid;

@RestController
@RequestMapping("")
@Slf4j
public class BillResource {
private final BillService SERVICE;
Expand Down
5 changes: 3 additions & 2 deletions billing-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
server.port: 7004
server.error.include-message: always

logging:
level:
Expand All @@ -22,8 +23,8 @@ app:
host: localhost
port: 7002
customers-service:
host: customers-service-reactive
port: 8090
host: localhost
port: 7003
---
spring:
config:
Expand Down
37 changes: 22 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@ services:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/njs:/etc/nginx/njs

billing-service:
build: billing-service
ports:
- "7004:8080"
# hostname: billing
#mem_limit: 350m
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- mongo1
# mysql5:
# condition: service_healthy

visits-service-new:
build: visits-service-new
restart: always
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- billing-service
- mongo2
- mailer-service

Expand Down Expand Up @@ -46,6 +61,7 @@ services:
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- billing-service
- customers-service-reactive
- vet-service
- visits-service-new
Expand All @@ -63,16 +79,7 @@ services:
environment:
- SPRING_PROFILES_ACTIVE=docker

billing-service:
build: billing-service
hostname: billing
#mem_limit: 350m
environment:
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- mongo1
# mysql5:
# condition: service_healthy


mailer-service:
build: mailer-service
Expand Down Expand Up @@ -263,11 +270,11 @@ services:
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
# healthcheck:
# test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet
# retries: 5
# interval: 15s
# start_period: 30s
#healthcheck:
#test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet
#retries: 5
#interval: 15s
#start_period: 30s

mongo-express1:
image: mongo-express
Expand Down
Loading
Loading