Skip to content

Commit

Permalink
Merge branch 'release/4.9.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-taman committed May 4, 2020
2 parents 1b6b77c + 56ea01c commit f021aa3
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 85 deletions.
2 changes: 1 addition & 1 deletion store-base/store-build-chassis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RC1</version>
<version>2.3.0.M4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
9 changes: 7 additions & 2 deletions store-base/store-cloud-chassis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-build-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-build-chassis</relativePath>
<relativePath>../../store-build-chassis/pom.xml</relativePath>
</parent>

<artifactId>store-cloud-chassis</artifactId>
Expand Down Expand Up @@ -36,9 +36,14 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion store-base/store-service-chassis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-cloud-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-cloud-chassis</relativePath>
<relativePath>../../store-cloud-chassis/pom.xml</relativePath>
</parent>

<artifactId>store-service-chassis</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion store-cloud-infra/edge-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-cloud-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-cloud-chassis</relativePath>
<relativePath>../../store-base/store-cloud-chassis/pom.xml</relativePath>
</parent>

<groupId>com.siriusxi.cloud.infra</groupId>
Expand Down
2 changes: 1 addition & 1 deletion store-cloud-infra/eureka-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-cloud-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-cloud-chassis</relativePath>
<relativePath>../../store-base/store-cloud-chassis/pom.xml</relativePath>
</parent>

<groupId>com.siriusxi.cloud.infra</groupId>
Expand Down
2 changes: 1 addition & 1 deletion store-common/store-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-build-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-build-chassis</relativePath>
<relativePath>../../store-base/store-build-chassis/pom.xml</relativePath>
</parent>

<artifactId>store-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion store-common/store-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-build-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-build-chassis</relativePath>
<relativePath>../../store-base/store-build-chassis/pom.xml</relativePath>
</parent>

<artifactId>store-utils</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion store-services/product-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-service-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-service-chassis</relativePath>
<relativePath>../../store-base/store-service-chassis/pom.xml</relativePath>
</parent>

<artifactId>product-service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void duplicateError() {
sendCreateProductEvent(productId);
fail("Expected a MessagingException here!");
} catch (MessagingException me) {
if (me.getCause() instanceof InvalidInputException iie) {
assertEquals("Duplicate key, Product Id: " + productId, iie.getMessage());
if (me.getCause() instanceof InvalidInputException iie){
assertEquals("Duplicate key, Product Id: ".concat(String.valueOf(productId)), iie.getMessage());
} else {
fail("Expected a InvalidInputException as the root cause!");
}
Expand All @@ -102,20 +102,21 @@ public void deleteProduct() {

@Test
public void getProductInvalidParameterString() {

getAndVerifyProduct(BASE_URI + "/no-integer", BAD_REQUEST)
.jsonPath("$.path").isEqualTo(BASE_URI + "no-integer")
var uri = BASE_URI.concat("no-integer");
getAndVerifyProduct(uri, BAD_REQUEST)
.jsonPath("$.path").isEqualTo(uri)
.jsonPath("$.message").isEqualTo("Type mismatch.");
}

@Test
public void getProductNotFound() {

int productIdNotFound = 13;

getAndVerifyProduct(productIdNotFound, NOT_FOUND)
.jsonPath("$.path").isEqualTo(BASE_URI + productIdNotFound)
.jsonPath("$.path").isEqualTo(BASE_URI.concat(String.valueOf(productIdNotFound)))
.jsonPath("$.message")
.isEqualTo("No product found for productId: " + productIdNotFound);
.isEqualTo("No product found for productId: ".concat(String.valueOf(productIdNotFound)));
}

@Test
Expand All @@ -124,13 +125,13 @@ public void getProductInvalidParameterNegativeValue() {
int productIdInvalid = -1;

getAndVerifyProduct(productIdInvalid, UNPROCESSABLE_ENTITY)
.jsonPath("$.path").isEqualTo(BASE_URI + productIdInvalid)
.jsonPath("$.message").isEqualTo("Invalid productId: " + productIdInvalid);
.jsonPath("$.path").isEqualTo(BASE_URI.concat(String.valueOf(productIdInvalid)))
.jsonPath("$.message").isEqualTo("Invalid productId: ".concat(String.valueOf(productIdInvalid)));
}

private WebTestClient.BodyContentSpec getAndVerifyProduct(
int productId, HttpStatus expectedStatus) {
return getAndVerifyProduct(BASE_URI + productId, expectedStatus);
return getAndVerifyProduct(BASE_URI.concat(String.valueOf(productId)), expectedStatus);
}

private WebTestClient.BodyContentSpec getAndVerifyProduct(
Expand All @@ -146,7 +147,10 @@ private WebTestClient.BodyContentSpec getAndVerifyProduct(
}

private void sendCreateProductEvent(int productId) {
Product product = new Product(productId, "Name " + productId, productId, "SA");
var product = new Product(productId,
"Name ".concat(String.valueOf(productId)),
productId,
"SA");
Event<Integer, Product> event = new Event<>(CREATE, productId, product);
input.send(new GenericMessage<>(event));
}
Expand Down
2 changes: 1 addition & 1 deletion store-services/recommendation-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-service-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-service-chassis</relativePath>
<relativePath>../../store-base/store-service-chassis/pom.xml</relativePath>
</parent>

<artifactId>recommendation-service</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion store-services/review-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-service-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-service-chassis</relativePath>
<relativePath>../../store-base/store-service-chassis/pom.xml</relativePath>
</parent>

<artifactId>review-service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;

import static com.siriusxi.ms.store.api.event.Event.Type.CREATE;
import static com.siriusxi.ms.store.api.event.Event.Type.DELETE;
Expand Down
2 changes: 1 addition & 1 deletion store-services/store-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.siriusxi.ms.store</groupId>
<artifactId>store-service-chassis</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../store-base/store-service-chassis</relativePath>
<relativePath>../../store-base/store-service-chassis/pom.xml</relativePath>
</parent>

<artifactId>store-service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,64 @@
@Log4j2
class IsSameEvent extends TypeSafeMatcher<String> {

private final ObjectMapper mapper = new ObjectMapper();
private final ObjectMapper mapper = new ObjectMapper();

private Event expectedEvent;
private final Event expectedEvent;

private IsSameEvent(Event expectedEvent) {
this.expectedEvent = expectedEvent;
}

private IsSameEvent(Event expectedEvent) {
this.expectedEvent = expectedEvent;
}
public static Matcher<String> sameEventExceptCreatedAt(Event expectedEvent) {
return new IsSameEvent(expectedEvent);
}

@Override
protected boolean matchesSafely(String eventAsJson) {
@Override
protected boolean matchesSafely(String eventAsJson) {

if (expectedEvent == null) return false;
if (expectedEvent == null) return false;

log.trace("Convert the following json string to a map: {}", eventAsJson);
Map mapEvent = convertJsonStringToMap(eventAsJson);
mapEvent.remove("eventCreatedAt");
log.trace("Convert the following json string to a map: {}", eventAsJson);
Map mapEvent = convertJsonStringToMap(eventAsJson);
mapEvent.remove("eventCreatedAt");

Map mapExpectedEvent = getMapWithoutCreatedAt(expectedEvent);
Map mapExpectedEvent = getMapWithoutCreatedAt(expectedEvent);

log.trace("Got the map: {}", mapEvent);
log.trace("Compare to the expected map: {}", mapExpectedEvent);
return mapEvent.equals(mapExpectedEvent);
}
log.trace("Got the map: {}", mapEvent);
log.trace("Compare to the expected map: {}", mapExpectedEvent);
return mapEvent.equals(mapExpectedEvent);
}

@Override
public void describeTo(Description description) {
String expectedJson = convertObjectToJsonString(expectedEvent);
description.appendText("expected to look like " + expectedJson);
}
@Override
public void describeTo(Description description) {
String expectedJson = convertObjectToJsonString(expectedEvent);
description.appendText("expected to look like " + expectedJson);
}

public static Matcher<String> sameEventExceptCreatedAt(Event expectedEvent) {
return new IsSameEvent(expectedEvent);
}
private Map getMapWithoutCreatedAt(Event event) {
Map mapEvent = convertObjectToMap(event);
mapEvent.remove("eventCreatedAt");
return mapEvent;
}

private Map getMapWithoutCreatedAt(Event event) {
Map mapEvent = convertObjectToMap(event);
mapEvent.remove("eventCreatedAt");
return mapEvent;
}

private Map convertObjectToMap(Object object) {
JsonNode node = mapper.convertValue(object, JsonNode.class);
return mapper.convertValue(node, Map.class);
}
private Map convertObjectToMap(Object object) {
JsonNode node = mapper.convertValue(object, JsonNode.class);
return mapper.convertValue(node, Map.class);
}

private String convertObjectToJsonString(Object object) {
try {
return mapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
private String convertObjectToJsonString(Object object) {
try {
return mapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

private Map convertJsonStringToMap(String eventAsJson) {
try {
return mapper.readValue(eventAsJson, new TypeReference<HashMap>(){});
} catch (IOException e) {
throw new RuntimeException(e);
}
private Map convertJsonStringToMap(String eventAsJson) {
try {
return mapper.readValue(eventAsJson, new TypeReference<HashMap>() {});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import static org.springframework.http.HttpStatus.OK;

@SpringBootTest(
webEnvironment = RANDOM_PORT,
properties = {"eureka.client.enabled: false"})
webEnvironment = RANDOM_PORT,
properties = {"eureka.client.enabled: false"})
class MessagingTests {

public static final String BASE_URL = "/store/api/v1/products/";
Expand Down Expand Up @@ -67,8 +67,7 @@ public void createCompositeProduct1() {
new Event<>(
CREATE,
composite.productId(),
new Product(
composite.productId(), composite.name(), composite.weight(), null));
new Product(composite.productId(), composite.name(), composite.weight(), null));
assertThat(queueProducts, is(receivesPayloadThat(sameEventExceptCreatedAt(expectedEvent))));

// Assert none recommendations and review events
Expand Down Expand Up @@ -97,8 +96,7 @@ public void createCompositeProduct2() {
new Event<>(
CREATE,
composite.productId(),
new Product(
composite.productId(), composite.name(), composite.weight(), null));
new Product(composite.productId(), composite.name(), composite.weight(), null));
assertThat(queueProducts, receivesPayloadThat(sameEventExceptCreatedAt(expectedProductEvent)));

// Assert one create recommendation event queued up
Expand Down Expand Up @@ -176,13 +174,16 @@ private void postAndVerifyProduct(ProductAggregate compositeProduct) {
.uri(BASE_URL)
.body(Mono.just(compositeProduct), ProductAggregate.class)
.exchange()
.expectStatus().isEqualTo(OK);
.expectStatus()
.isEqualTo(OK);
}

private void deleteAndVerifyProduct(int productId) {
client.delete()
.uri(BASE_URL.concat(valueOf(productId)))
.exchange()
.expectStatus().isEqualTo(OK);
client
.delete()
.uri(BASE_URL.concat(valueOf(productId)))
.exchange()
.expectStatus()
.isEqualTo(OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import static org.springframework.http.MediaType.APPLICATION_JSON;

@SpringBootTest(
webEnvironment = RANDOM_PORT,
properties = {"eureka.client.enabled: false"})
webEnvironment = RANDOM_PORT,
properties = {"eureka.client.enabled: false"})
class StoreServiceApplicationTests {

public static final String BASE_URL = "/store/api/v1/products/";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.siriusxi.ms.store.pcs;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.SuiteDisplayName;
import org.junit.runner.RunWith;

//@RunWith(JUnitPlatform.class)
@SuiteDisplayName("Store Service Testing Suite")
@SelectClasses(value = {StoreServiceApplicationTests.class, MessagingTests.class})
public class StoreServiceTestingSuite {}
class StoreServiceTestingSuite {}

0 comments on commit f021aa3

Please sign in to comment.