use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class BulkInsertTest method insertOrderAndBulkInsertNProductsWithAtomic.
@Test
@DisplayName("Should execute normal insert and multiple bulk mutations with atomic directive")
public void insertOrderAndBulkInsertNProductsWithAtomic() {
String productId1 = UUID.randomUUID().toString();
String productId2 = UUID.randomUUID().toString();
String productName = "Shiny Legs";
String description = "Normal legs but shiny.";
ProductsInput product1 = ProductsInput.builder().id(productId1).name(productName).price("3199.99").created(now()).description(description).build();
ProductsInput product2 = ProductsInput.builder().id(productId2).name("Non-Legs").price("1000.99").created(now()).description("Non-legs.").build();
String customerName = "c1";
OrdersInput order = OrdersInput.builder().prodName(productName).customerName(customerName).price("3199.99").description(description).build();
ApolloClient client = getApolloClient("/graphql/" + keyspace);
InsertOrdersAndBulkInsertProductsWithAtomicMutation mutation = InsertOrdersAndBulkInsertProductsWithAtomicMutation.builder().values(Arrays.asList(product1, product2)).orderValue(order).build();
insertOrdersAndBulkInsertProductsWthAtomic(client, mutation);
GetProductsWithFilterQuery.Value product1Result = getProduct(client, productId1);
assertThat(product1Result.getId()).hasValue(productId1);
assertThat(product1Result.getName()).hasValue(product1.name());
assertThat(product1Result.getPrice()).hasValue(product1.price());
assertThat(product1Result.getCreated()).hasValue(product1.created());
assertThat(product1Result.getDescription()).hasValue(product1.description());
GetProductsWithFilterQuery.Value product2Result = getProduct(client, productId2);
assertThat(product2Result.getId()).hasValue(productId2);
assertThat(product2Result.getName()).hasValue(product2.name());
assertThat(product2Result.getPrice()).hasValue(product2.price());
assertThat(product2Result.getCreated()).hasValue(product2.created());
assertThat(product2Result.getDescription()).hasValue(product2.description());
assertThat(session.execute(SimpleStatement.newInstance("SELECT * FROM \"Orders\" WHERE \"prodName\" = ?", productName)).one()).isNotNull().extracting(r -> r.getString("\"customerName\""), r -> r.getString("description")).containsExactly(customerName, description);
}
use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class BulkInsertTest method bulkInsertNProductsUsingBulkAndOrderWithAtomic.
@Test
@DisplayName("Should execute multiple mutations including bulk with atomic directive")
public void bulkInsertNProductsUsingBulkAndOrderWithAtomic() {
String productId1 = UUID.randomUUID().toString();
String productId2 = UUID.randomUUID().toString();
String productName = "Shiny Legs";
String description = "Normal legs but shiny.";
ProductsInput product1 = ProductsInput.builder().id(productId1).name(productName).price("3199.99").created(now()).description(description).build();
ProductsInput product2 = ProductsInput.builder().id(productId2).name("Non-Legs").price("1000.99").created(now()).description("Non-legs.").build();
String customerName = "c1";
OrdersInput order = OrdersInput.builder().prodName(productName).customerName(customerName).price("3199.99").description(description).build();
ApolloClient client = getApolloClient("/graphql/" + keyspace);
BulkInsertProductsAndOrdersWithAtomicMutation mutation = BulkInsertProductsAndOrdersWithAtomicMutation.builder().values(Arrays.asList(product1, product2)).orderValue(order).build();
List<BulkInsertProductsAndOrdersWithAtomicMutation.Product> result = bulkInsertProductsAndOrdersWithAtomic(client, mutation).getProducts().get();
BulkInsertProductsAndOrdersWithAtomicMutation.Product firstInsertedProduct = result.get(0);
BulkInsertProductsAndOrdersWithAtomicMutation.Product secondInsertedProduct = result.get(1);
assertThat(firstInsertedProduct.getApplied().get()).isTrue();
assertThat(firstInsertedProduct.getValue()).hasValueSatisfying(value -> {
assertThat(value.getId()).hasValue(productId1);
});
assertThat(secondInsertedProduct.getApplied().get()).isTrue();
assertThat(secondInsertedProduct.getValue()).hasValueSatisfying(value -> {
assertThat(value.getId()).hasValue(productId2);
});
// retrieve from db
GetProductsWithFilterQuery.Value product1Result = getProduct(client, productId1);
assertThat(product1Result.getId()).hasValue(productId1);
assertThat(product1Result.getName()).hasValue(product1.name());
assertThat(product1Result.getPrice()).hasValue(product1.price());
assertThat(product1Result.getCreated()).hasValue(product1.created());
assertThat(product1Result.getDescription()).hasValue(product1.description());
GetProductsWithFilterQuery.Value product2Result = getProduct(client, productId2);
assertThat(product2Result.getId()).hasValue(productId2);
assertThat(product2Result.getName()).hasValue(product2.name());
assertThat(product2Result.getPrice()).hasValue(product2.price());
assertThat(product2Result.getCreated()).hasValue(product2.created());
assertThat(product2Result.getDescription()).hasValue(product2.description());
assertThat(session.execute(SimpleStatement.newInstance("SELECT * FROM \"Orders\" WHERE \"prodName\" = ?", productName)).one()).isNotNull().extracting(r -> r.getString("\"customerName\""), r -> r.getString("description")).containsExactly(customerName, description);
}
use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class ApolloTest method deleteProducts.
@Test
public void deleteProducts() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
String productId = UUID.randomUUID().toString();
ProductsInput insertInput = ProductsInput.builder().id(productId).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
insertProduct(client, insertInput);
DeleteProductsMutation mutation = DeleteProductsMutation.builder().value(ProductsInput.builder().id(productId).build()).build();
DeleteProductsMutation.Data result = getObservable(client.mutate(mutation));
assertThat(result.getDeleteProducts()).hasValueSatisfying(deleteProducts -> {
assertThat(deleteProducts.getApplied()).hasValue(true);
assertThat(deleteProducts.getValue()).hasValueSatisfying(product -> {
assertThat(product.getId()).hasValue(productId);
assertThat(product.getName()).isEmpty();
assertThat(product.getPrice()).isEmpty();
assertThat(product.getCreated()).isEmpty();
assertThat(product.getDescription()).isEmpty();
});
});
List<Value> remainingProductValues = getProductValues(client, productId);
assertThat(remainingProductValues).isEmpty();
}
use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class ApolloTest method updateProductsMissingIfExistsTrue.
@Test
public void updateProductsMissingIfExistsTrue() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
String productId = UUID.randomUUID().toString();
ProductsInput input = ProductsInput.builder().id(productId).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
UpdateProductsMutation mutation = UpdateProductsMutation.builder().value(input).ifExists(true).build();
UpdateProductsMutation.Data result = getObservable(client.mutate(mutation));
assertThat(result.getUpdateProducts()).hasValueSatisfying(products -> {
assertThat(products.getApplied()).hasValue(false);
assertThat(products.getValue()).hasValueSatisfying(value -> {
assertThat(value.getId()).isEmpty();
assertThat(value.getName()).isEmpty();
assertThat(value.getPrice()).isEmpty();
assertThat(value.getCreated()).isEmpty();
assertThat(value.getDescription()).isEmpty();
});
});
}
use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class ApolloTest method deleteProductsIfExistsTrue.
@Test
public void deleteProductsIfExistsTrue() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
String productId = UUID.randomUUID().toString();
ProductsInput insertInput = ProductsInput.builder().id(productId).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
insertProduct(client, insertInput);
ProductsInput deleteInput = ProductsInput.builder().id(productId).name(insertInput.name()).price(insertInput.price()).created(insertInput.created()).build();
DeleteProductsMutation mutation = DeleteProductsMutation.builder().value(deleteInput).ifExists(true).build();
DeleteProductsMutation.Data result = getObservable(client.mutate(mutation));
assertThat(result.getDeleteProducts()).hasValueSatisfying(deleteProducts -> {
assertThat(deleteProducts.getApplied()).hasValue(true);
});
}
Aggregations