public void testStartDiscussionInitiationSave() throws Exception { TenantId tenantId = new TenantId("T12345"); Product product = new Product( tenantId, new ProductId("679890"), new ProductOwnerId(tenantId, "thepm"), "My Product", "My product, which is my product.", DiscussionAvailability.NOT_REQUESTED); product.startDiscussionInitiation("ABCDEFGHIJ"); LevelDBUnitOfWork.start(this.database); productRepository.save(product); LevelDBUnitOfWork.current().commit(); Product savedProduct = productRepository.productOfDiscussionInitiationId(product.tenantId(), "ABCDEFGHIJ"); assertNotNull(savedProduct); assertEquals(product.tenantId(), savedProduct.tenantId()); assertEquals(product.productId(), savedProduct.productId()); assertEquals(product.productOwnerId(), savedProduct.productOwnerId()); assertEquals("My Product", savedProduct.name()); assertEquals("My product, which is my product.", savedProduct.description()); assertEquals(DiscussionAvailability.NOT_REQUESTED, savedProduct.discussion().availability()); }
public void testSave() throws Exception { TenantId tenantId = new TenantId("T12345"); Product product = new Product( tenantId, new ProductId("679890"), new ProductOwnerId(tenantId, "thepm"), "My Product", "My product, which is my product.", DiscussionAvailability.NOT_REQUESTED); LevelDBUnitOfWork.start(this.database); productRepository.save(product); LevelDBUnitOfWork.current().commit(); Product savedProduct = productRepository.productOfId(product.tenantId(), product.productId()); assertNotNull(savedProduct); assertEquals(product.tenantId(), savedProduct.tenantId()); assertEquals(product.productId(), savedProduct.productId()); assertEquals(product.productOwnerId(), savedProduct.productOwnerId()); assertEquals("My Product", savedProduct.name()); assertEquals("My product, which is my product.", savedProduct.description()); assertEquals(DiscussionAvailability.NOT_REQUESTED, savedProduct.discussion().availability()); Collection<Product> savedProducts = productRepository.allProductsOfTenant(product.tenantId()); assertFalse(savedProducts.isEmpty()); assertEquals(1, savedProducts.size()); }
public void testConcurrentTransactions() throws Exception { final List<Integer> orderOfCommits = new ArrayList<Integer>(); final TenantId tenantId = new TenantId("T12345"); Product product1 = new Product( tenantId, new ProductId("679890"), new ProductOwnerId(tenantId, "thepm"), "My Product 1", "My product 1, which is my product.", DiscussionAvailability.NOT_REQUESTED); LevelDBUnitOfWork.start(database); productRepository.save(product1); new Thread() { @Override public void run() { Product product2 = new Product( tenantId, new ProductId("09876"), new ProductOwnerId(tenantId, "thepm"), "My Product 2", "My product 2, which is my product.", DiscussionAvailability.NOT_REQUESTED); LevelDBUnitOfWork.start(database); productRepository.save(product2); LevelDBUnitOfWork.current().commit(); orderOfCommits.add(2); } }.start(); Thread.sleep(250L); LevelDBUnitOfWork.current().commit(); orderOfCommits.add(1); for (int idx = 0; idx < orderOfCommits.size(); ++idx) { assertEquals(idx + 1, orderOfCommits.get(idx).intValue()); } Thread.sleep(250L); Collection<Product> savedProducts = productRepository.allProductsOfTenant(product1.tenantId()); assertFalse(savedProducts.isEmpty()); assertEquals(2, savedProducts.size()); }
public void testRemove() throws Exception { TenantId tenantId = new TenantId("T12345"); Product product1 = new Product( tenantId, new ProductId("679890"), new ProductOwnerId(tenantId, "thepm"), "My Product 1", "My product 1, which is my product.", DiscussionAvailability.NOT_REQUESTED); Product product2 = new Product( tenantId, new ProductId("09876"), new ProductOwnerId(tenantId, "thepm"), "My Product 2", "My product 2, which is my product.", DiscussionAvailability.NOT_REQUESTED); LevelDBUnitOfWork.start(this.database); productRepository.save(product1); productRepository.save(product2); LevelDBUnitOfWork.current().commit(); LevelDBUnitOfWork.start(this.database); productRepository.remove(product1); LevelDBUnitOfWork.current().commit(); Collection<Product> savedProducts = productRepository.allProductsOfTenant(tenantId); assertFalse(savedProducts.isEmpty()); assertEquals(1, savedProducts.size()); assertEquals(product2.productId(), savedProducts.iterator().next().productId()); LevelDBUnitOfWork.start(this.database); productRepository.remove(product2); LevelDBUnitOfWork.current().commit(); savedProducts = productRepository.allProductsOfTenant(tenantId); assertTrue(savedProducts.isEmpty()); }