use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class BulkInsertTest method bulkInsertProductsWithAtomic.
@Test
public void bulkInsertProductsWithAtomic() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
String productId1 = UUID.randomUUID().toString();
String productId2 = UUID.randomUUID().toString();
ProductsInput product1 = ProductsInput.builder().id(productId1).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
ProductsInput product2 = ProductsInput.builder().id(productId2).name("Non-Legs").price("1000.99").created(now()).description("Non-legs.").build();
bulkInsertProductsWithAtomic(client, Arrays.asList(product1, product2));
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());
}
use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class BulkInsertTest method bulkInsertMoreProductsThanSelectionsUsingBulkAndOrderWithAtomic.
@Test
@DisplayName("Should execute multiple mutations including bulk with more elements than selections with atomic directive")
public void bulkInsertMoreProductsThanSelectionsUsingBulkAndOrderWithAtomic() {
String productName = "Shiny Legs";
String description = "Normal legs but shiny.";
List<ProductsInput> productsInputs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
productsInputs.add(ProductsInput.builder().id(UUID.randomUUID().toString()).name(productName).price("3199.99").created(now()).description(description).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(productsInputs).orderValue(order).build();
bulkInsertProductsAndOrdersWithAtomic(client, mutation);
for (ProductsInput product : productsInputs) {
GetProductsWithFilterQuery.Value product1Result = getProduct(client, (String) product.id());
assertThat(product1Result.getId()).hasValue(product.id());
assertThat(product1Result.getName()).hasValue(product.name());
assertThat(product1Result.getPrice()).hasValue(product.price());
assertThat(product1Result.getCreated()).hasValue(product.created());
assertThat(product1Result.getDescription()).hasValue(product.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 insertProducts.
@Test
public void insertProducts() {
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();
InsertProductsMutation.InsertProducts result = insertProduct(client, input);
assertThat(result.getApplied()).hasValue(true);
assertThat(result.getValue()).hasValueSatisfying(product -> {
assertThat(product.getId()).hasValue(productId);
assertThat(product.getName()).hasValue(input.name());
assertThat(product.getPrice()).hasValue(input.price());
assertThat(product.getCreated()).hasValue(input.created());
assertThat(product.getDescription()).hasValue(input.description());
});
GetProductsWithFilterQuery.Value product = getProduct(client, productId);
assertThat(product.getId()).hasValue(productId);
assertThat(product.getName()).hasValue(input.name());
assertThat(product.getPrice()).hasValue(input.price());
assertThat(product.getCreated()).hasValue(input.created());
assertThat(product.getDescription()).hasValue(input.description());
}
use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class ApolloTest method updateProducts.
@Test
public void updateProducts() {
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 input = ProductsInput.builder().id(productId).name(insertInput.name()).price(insertInput.price()).created(insertInput.created()).description("Normal legs but shiny. Now available in different colors").build();
UpdateProductsMutation mutation = UpdateProductsMutation.builder().value(input).build();
UpdateProductsMutation.Data result = getObservable(client.mutate(mutation));
assertThat(result.getUpdateProducts()).hasValueSatisfying(updateProducts -> {
assertThat(updateProducts.getApplied()).hasValue(true);
assertThat(updateProducts.getValue()).hasValueSatisfying(product -> {
assertThat(product.getId()).hasValue(productId);
assertThat(product.getName()).hasValue(input.name());
assertThat(product.getPrice()).hasValue(input.price());
assertThat(product.getCreated()).hasValue(input.created());
assertThat(product.getDescription()).hasValue(input.description());
});
});
GetProductsWithFilterQuery.Value product = getProduct(client, productId);
assertThat(product.getId()).hasValue(productId);
assertThat(product.getName()).hasValue(input.name());
assertThat(product.getPrice()).hasValue(input.price());
assertThat(product.getCreated()).hasValue(input.created());
assertThat(product.getDescription()).hasValue(input.description());
}
use of com.example.graphql.client.betterbotz.type.ProductsInput in project stargate by stargate.
the class BulkInsertTest method bulkInsertProducts.
@Test
public void bulkInsertProducts() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
String productId1 = UUID.randomUUID().toString();
String productId2 = UUID.randomUUID().toString();
ProductsInput product1 = ProductsInput.builder().id(productId1).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
ProductsInput product2 = ProductsInput.builder().id(productId2).name("Non-Legs").price("1000.99").created(now()).description("Non-legs.").build();
List<BulkInsertProductsMutation.BulkInsertProduct> bulkInsertedProducts = bulkInsertProducts(client, Arrays.asList(product1, product2));
BulkInsertProductsMutation.BulkInsertProduct firstInsertedProduct = bulkInsertedProducts.get(0);
BulkInsertProductsMutation.BulkInsertProduct secondInsertedProduct = bulkInsertedProducts.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());
}
Aggregations