use of com.google.cloud.retail.v2.Product in project java-retail by googleapis.
the class ImportProductsBigQueryTableTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException, ExecutionException {
String projectId = ServiceOptions.getDefaultProjectId();
String branchName = String.format("projects/%s/locations/global/catalogs/default_catalog/branches/0", projectId);
String datasetId = "products";
String tableId = "products";
String dataSchema = "product";
ReconciliationMode reconciliationMode = ReconciliationMode.INCREMENTAL;
bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
ProductsCreateBigqueryTable.main();
ImportProductsRequest importBigQueryRequest = getImportProductsBigQueryRequest(reconciliationMode, projectId, datasetId, tableId, dataSchema, branchName);
waitForOperationCompletion(importBigQueryRequest);
}
use of com.google.cloud.retail.v2.Product in project cuba by cuba-platform.
the class DataManagerTransactionalUsageTest method test.
@Test
public void test() {
SaleProcessor processor = AppBeans.get("test_SaleProcessor");
Id<OrderLine, UUID> orderLineId = processor.sell("abc", 10);
Product product1 = dataManager.load(Product.class).query("select p from sales1$Product p where p.name = :name").parameter("name", "abc").one();
assertEquals(90, (int) product1.getQuantity());
// change Product in OrderLIne
Product product2 = dataManager.create(Product.class);
product2.setName("def");
product2.setQuantity(100);
dataManager.commit(product2);
OrderLine orderLine = dataManager.load(orderLineId).view("with-product").one();
orderLine.setProduct(product2);
dataManager.commit(orderLine);
Product changedProduct1 = dataManager.load(Id.of(product1)).one();
assertEquals(100, (int) changedProduct1.getQuantity());
Product changedProduct2 = dataManager.load(Id.of(product2)).one();
assertEquals(90, (int) changedProduct2.getQuantity());
// remove OrderLine
OrderLine orderLineToRemove = dataManager.load(orderLineId).view("with-product").one();
dataManager.remove(orderLineToRemove);
Product product21 = dataManager.load(Id.of(product2)).one();
assertEquals(100, (int) product21.getQuantity());
}
use of com.google.cloud.retail.v2.Product in project cuba by cuba-platform.
the class TransactionalActionUsageTest method testOnSuccessAction.
@Test
public void testOnSuccessAction() {
EntitySet entities = transactionalActionFactory.getTransactionalAction().withCommitContext(() -> {
CommitContext cc = new CommitContext();
Product p = metadata.create(Product.class);
p.setName("test");
p.setQuantity(100);
cc.addInstanceToCommit(p);
return cc;
}).onSuccess(es -> {
es.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).forEach(e -> ((Product) e).setName("newName"));
}).perform();
Product product = (Product) entities.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).findFirst().orElse(null);
assertNotNull(product);
assertEquals("newName", product.getName());
Product productFromDb = transactionalDataManager.load(Id.of(product)).one();
assertNotNull(productFromDb);
assertEquals("test", productFromDb.getName());
}
use of com.google.cloud.retail.v2.Product in project cuba by cuba-platform.
the class TransactionalActionUsageTest method testOnFailAction.
@Test
public void testOnFailAction() {
EntitySet entities = transactionalActionFactory.getTransactionalAction().withCommitContext(() -> {
CommitContext cc = new CommitContext();
Product p = metadata.create(Product.class);
p.setName("test");
p.setQuantity(100);
p.setId(null);
cc.addInstanceToCommit(p);
return cc;
}).onFail((cc, t) -> {
messageFromOnFailAction = "[testOnFailAction] commit failed";
}).perform();
assertNull(entities);
assertEquals("[testOnFailAction] commit failed", messageFromOnFailAction);
}
use of com.google.cloud.retail.v2.Product in project cuba by cuba-platform.
the class TransactionalActionUsageTest method testAllActions.
@Test
public void testAllActions() {
EntitySet entities = transactionalDataManager.commitAction(() -> {
CommitContext cc = new CommitContext();
Product p = transactionalDataManager.create(Product.class);
p.setName("allActionsTest");
p.setQuantity(100);
cc.addInstanceToCommit(p);
return cc;
}).onSuccess(es -> {
es.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).forEach(e -> ((Product) e).setName("onSuccessName"));
}).onFail((cc, t) -> {
messageFromOnFailAction = "[testAllActions] commit failed";
}).afterCompletion(cc -> {
messageFromAfterCommitAction = "[testAllActions] transaction ended";
}).perform();
Product product = (Product) entities.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).findFirst().orElse(null);
assertNotNull(product);
assertEquals("onSuccessName", product.getName());
Product productFromDb = transactionalDataManager.load(Id.of(product)).one();
assertNotNull(productFromDb);
assertEquals("allActionsTest", productFromDb.getName());
assertNotEquals("[testAllActions] commit failed", messageFromOnFailAction);
assertEquals("[testAllActions] transaction ended", messageFromAfterCommitAction);
}
Aggregations