Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions client/client-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<!--Modules-->
<modules>
<module>sample-client-elasticsearch-product</module>
<module>sample-client-graphql-book</module>
<module>sample-client-reactive-football</module>
<module>sample-client-reactive-weather</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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>
<parent>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>client-samples</artifactId>
<version>0.4.10-SNAPSHOT</version>
</parent>

<artifactId>sample-client-elasticsearch-product</artifactId>

<dependencies>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-client-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-client-test</artifactId>
</dependency>
</dependencies>

</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.americanexpress.sample.client.elasticsearch.product.client;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import io.americanexpress.sample.client.elasticsearch.product.model.Product;
import io.americanexpress.synapse.client.elasticsearch.client.BaseCreateElasticSearchDocumentSearchClient;
import org.springframework.stereotype.Component;
import static io.americanexpress.sample.client.elasticsearch.product.config.ProductElasticSearchConfig.INDEX_NAME;

/**
* {@code CreateProductElasticSearchDocumentClient} creates a document in ElasticSearch.
*
* @author sshre31
*/
@Component
public class CreateProductElasticSearchDocumentClient extends BaseCreateElasticSearchDocumentSearchClient<Product> {

/**
* Create an instance of CreateProductElasticSearchDocumentClient with the specified parameters.
*
* @param elasticsearchClient elasticsearchClient
*/
public CreateProductElasticSearchDocumentClient(ElasticsearchClient elasticsearchClient) {
super(elasticsearchClient, INDEX_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.americanexpress.sample.client.elasticsearch.product.client;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import io.americanexpress.sample.client.elasticsearch.product.model.Product;
import io.americanexpress.synapse.client.elasticsearch.client.BaseDeleteElasticSearchDocumentSearchClient;
import org.springframework.stereotype.Component;
import static io.americanexpress.sample.client.elasticsearch.product.config.ProductElasticSearchConfig.INDEX_NAME;

/**
* {@code DeleteProductElasticSearchDocumentClient} deletes a document from ElasticSearch.
*
* @author sshre31
*/
@Component
public class DeleteProductElasticSearchDocumentClient extends BaseDeleteElasticSearchDocumentSearchClient<Product> {

/**
* Create an instance of BaseDeleteElasticSearchDocumentSearchClient with the specified parameters.
*
* @param elasticsearchClient elasticsearchClient
*/
public DeleteProductElasticSearchDocumentClient(ElasticsearchClient elasticsearchClient) {
super(elasticsearchClient, INDEX_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.americanexpress.sample.client.elasticsearch.product.client;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import io.americanexpress.sample.client.elasticsearch.product.model.Product;
import io.americanexpress.synapse.client.elasticsearch.client.BaseReadElasticSearchDocumentSearchClient;
import org.springframework.stereotype.Component;
import static io.americanexpress.sample.client.elasticsearch.product.config.ProductElasticSearchConfig.INDEX_NAME;

/**
* {@code ReadProductElasticSearchDocumentClient} reads a document from ElasticSearch.
*
* @author sshre31
*/
@Component
public class ReadProductElasticSearchDocumentClient extends BaseReadElasticSearchDocumentSearchClient<Product> {

/**
* Create an instance of BaseReadElasticSearchDocumentSearchClient with the specified parameters.
*
* @param elasticsearchClient elasticsearchClient
*/
public ReadProductElasticSearchDocumentClient(ElasticsearchClient elasticsearchClient) {
super(elasticsearchClient, INDEX_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.americanexpress.sample.client.elasticsearch.product.client;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import io.americanexpress.sample.client.elasticsearch.product.model.Product;
import io.americanexpress.synapse.client.elasticsearch.client.BaseUpdateElasticSearchDocumentSearchClient;
import org.springframework.stereotype.Component;
import static io.americanexpress.sample.client.elasticsearch.product.config.ProductElasticSearchConfig.INDEX_NAME;

/**
* {@code UpdateProductElasticSearchDocumentClient}
*
* @author sshre31
*/
@Component
public class UpdateProductElasticSearchDocumentClient extends BaseUpdateElasticSearchDocumentSearchClient<Product> {

/**
* Create an instance of BaseUpdateElasticSearchDocumentSearchClient with the specified parameters.
*
* @param elasticsearchClient elasticsearchClient
*/
public UpdateProductElasticSearchDocumentClient(ElasticsearchClient elasticsearchClient) {
super(elasticsearchClient, INDEX_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.americanexpress.sample.client.elasticsearch.product.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.americanexpress.synapse.client.elasticsearch.config.BaseElasticSearchClientConfig;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
* {@code ProductElasticSearchConfig} specifies the configuration for the ElasticSearch client.
*
* @author sshre31
*/
@ComponentScan("io.americanexpress.sample.client.elasticsearch.product")
@Configuration
public class ProductElasticSearchConfig extends BaseElasticSearchClientConfig {

/**
* Index name.
*/
public static final String INDEX_NAME = "products";

/**
* Constructor taking in objectMapper & metricInterceptor.
*
* @param defaultObjectMapper the default object mapper
*/
public ProductElasticSearchConfig(ObjectMapper defaultObjectMapper, Environment environment) {
super(defaultObjectMapper, environment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.americanexpress.sample.client.elasticsearch.product.model;

import io.americanexpress.synapse.client.elasticsearch.model.BaseElasticSearchData;

/**
* {@code Product} represents a product.
*
* @author sshre31
*/
public class Product extends BaseElasticSearchData {

/**
* Name of the product.
*/
private String name;

/**
* Description of the product.
*/
private String description;

/**
* Get the name.
*
* @return the name
*/
public String getName() {
return name;
}

/**
* Set the name.
*
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

/**
* Get the description.
*
* @return description
*/
public String getDescription() {
return description;
}

/**
* Set the description.
*
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.americanexpress.sample.client.elasticsearch.client;

import io.americanexpress.sample.client.elasticsearch.config.ProductElasticSearchConfigTest;
import io.americanexpress.sample.client.elasticsearch.product.client.CreateProductElasticSearchDocumentClient;
import io.americanexpress.sample.client.elasticsearch.product.model.Product;
import io.americanexpress.synapse.framework.exception.ApplicationClientException;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* {@code CreateProductElasticSearchDocumentIT} tests the {@link CreateProductElasticSearchDocumentClient} class.
*
* @author sshre31
*/
@ContextConfiguration(classes = ProductElasticSearchConfigTest.class)
@ExtendWith(SpringExtension.class)
class CreateProductElasticSearchDocumentIT {

@Autowired
CreateProductElasticSearchDocumentClient createProductElasticSearchDocument;

@Test
void save_providedValidProduct_expectedSuccess() {
var product = new Product();
product.setId(UUID.randomUUID().toString());
product.setName("Ice Cream");
product.setDescription("Fudge Ice Cream.");
assertDoesNotThrow(() -> createProductElasticSearchDocument.save(product));
}

@Test
void read_providedValidProduct_expectedException() {
var product = new Product();
product.setName("Ice Cream");
product.setDescription("Fudge Ice Cream.");
assertThrows(ApplicationClientException.class, () -> createProductElasticSearchDocument.save(product));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.americanexpress.sample.client.elasticsearch.client;

import io.americanexpress.sample.client.elasticsearch.config.ProductElasticSearchConfigTest;
import io.americanexpress.sample.client.elasticsearch.product.client.ReadProductElasticSearchDocumentClient;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* {@code ReadProductElasticSearchDocumentIT}
*
* @author sshre31
*/
@ContextConfiguration(classes = ProductElasticSearchConfigTest.class)
@ExtendWith(SpringExtension.class)
class ReadProductElasticSearchDocumentIT {


@Autowired
ReadProductElasticSearchDocumentClient readProductElasticSearchDocumentClient;

@Test
void findById_providedValidId_expectedSuccess() throws IOException {
var product = readProductElasticSearchDocumentClient.findById("{id}");
assertNotNull(product);
}

@Test
void findAll_providedValidRequest_expectedSuccess() throws IOException {
var allProducts = readProductElasticSearchDocumentClient.findAll();
assertNotNull(allProducts);
}

@Test
void searchByKey_providedValidKeyword_expectedSuccess() throws IOException {
var products = readProductElasticSearchDocumentClient.searchByKey("name", "Ice Cream");
assertNotNull(products);
}

@Test
void doesExists_providedValidId_expectedSuccess() throws IOException {
var products = readProductElasticSearchDocumentClient.doesExists("{id}");
assertTrue(products);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.americanexpress.sample.client.elasticsearch.config;

import io.americanexpress.sample.client.elasticsearch.product.config.ProductElasticSearchConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
* {@code ProductElasticSearchConfigTest}
*
* @author sshre31
*/
@Configuration
@Import(ProductElasticSearchConfig.class)
public class ProductElasticSearchConfigTest {

}
1 change: 1 addition & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<!--Modules-->
<modules>
<module>client-samples</module>
<module>synapse-client-elasticsearch</module>
<module>synapse-client-graphql</module>
<module>synapse-client-rest</module>
<module>synapse-client-soap</module>
Expand Down
5 changes: 5 additions & 0 deletions client/synapse-client-elasticsearch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# synapse-client-rest

## Description

## Usage
Loading