use of com.google.cloud.vision.v1.Product in project java-retail by googleapis.
the class CrudProductTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException, ExecutionException {
String projectId = ServiceOptions.getDefaultProjectId();
String generatedProductId = UUID.randomUUID().toString();
String branchName = String.format("projects/%s/locations/global/catalogs/default_catalog/branches/0", projectId);
String productName = String.format("%s/products/%s", branchName, generatedProductId);
bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
Product createdProduct = createProduct(generatedProductId, branchName);
getProduct(productName);
updateProduct(createdProduct, productName);
deleteProduct(productName);
}
use of com.google.cloud.vision.v1.Product in project java-retail by googleapis.
the class GetProductTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException, ExecutionException {
String generatedProductId = UUID.randomUUID().toString();
bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
Product createdProduct = createProduct(generatedProductId);
Product product = getProduct(createdProduct.getName());
deleteProduct(product.getName());
}
use of com.google.cloud.vision.v1.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.vision.v1.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.vision.v1.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);
}
Aggregations