use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2022-feb-spring-data by bankin.
the class _02Main method main.
public static void main(String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("CodeFirstEx");
EntityManager entityManager = factory.createEntityManager();
entityManager.getTransaction().begin();
Product product = new Product("product", 123, BigDecimal.TEN);
Customer customer = new Customer("customer", "customer", "asd");
StoreLocation location = new StoreLocation("location");
Sale sale = new Sale(product, customer, location);
entityManager.persist(product);
entityManager.persist(customer);
entityManager.persist(location);
entityManager.persist(sale);
entityManager.getTransaction().commit();
entityManager.close();
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project C-DAC-Notes by shreeshailaya.
the class SaveProduct method main.
public static void main(String[] args) {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
Metadata metadata = new MetadataSources(registry).getMetadataBuilder().build();
SessionFactory sf = metadata.getSessionFactoryBuilder().build();
System.out.println("session factory created");
Session session = sf.openSession();
Category category = new Category("Computer");
Product pc = new Product("DELL PC", "Quad-core PC", 1200, category);
Product laptop = new Product("MacBook", "Apple High-end laptop", 2100, category);
Product phone = new Product("iPhone 5", "Apple Best-selling smartphone", 499, category);
Product tablet = new Product("iPad 3", "Apple Best-selling tablet", 1099, category);
Set<Product> products = new HashSet<Product>();
products.add(pc);
products.add(laptop);
products.add(phone);
products.add(tablet);
category.setProducts(products);
Transaction tr = session.beginTransaction();
session.save(category);
tr.commit();
System.out.println(" saved");
session.close();
sf.close();
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method getFakeProductPositions.
private List<ProductPosition> getFakeProductPositions() {
List<Product> fakeProducts = getFakeProducts();
Warehouse fakeWarehouse = getFakeWarehouse1();
Date d1 = new Date();
cal.setTime(d1);
cal.add(Calendar.DATE, -10);
d1.setTime(cal.getTime().getTime());
Date d2 = new Date();
cal.setTime(d2);
cal.add(Calendar.DATE, -1);
d2.setTime(cal.getTime().getTime());
Date d3 = new Date();
cal.setTime(d3);
cal.add(Calendar.DATE, -40);
d3.setTime(cal.getTime().getTime());
ProductPosition ps1 = new ProductPosition(1L, fakeProducts.get(0), fakeWarehouse, "AAA", 5, 3, d1, new BigDecimal(10000.0), "ИП ИВАНОВ", true, d1);
ps1.setId(1L);
ProductPosition ps2 = new ProductPosition(1L, fakeProducts.get(0), fakeWarehouse, "AAA", 5, 3, d2, new BigDecimal(10000.0), "ИП ИВАНОВ", true, d2);
ps2.setId(2L);
ProductPosition ps3 = new ProductPosition(2L, fakeProducts.get(1), fakeWarehouse, "AAA", 5, 3, d1, new BigDecimal(10000.0), "ИП ПЕТРОВ", true, d1);
ps3.setId(3L);
ProductPosition ps4 = new ProductPosition(2L, fakeProducts.get(1), fakeWarehouse, "AAA", 10, 8, d2, new BigDecimal(10000.0), "ИП ПЕТРОВ", true, d2);
ps4.setId(4L);
ProductPosition ps5 = new ProductPosition(3L, fakeProducts.get(2), fakeWarehouse, "AAA", 20, 20, d3, new BigDecimal(10000.0), "ИП ФЕДОРОВ", true, d3);
ps5.setId(5L);
ProductPosition ps6 = new ProductPosition(3L, fakeProducts.get(2), fakeWarehouse, "AAA", 15, 15, d1, new BigDecimal(10000.0), "ИП ФЕДОРОВ", true, d1);
ps6.setId(6L);
return new ArrayList<>(Arrays.asList(ps1, ps2, ps3, ps4, ps5, ps6));
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method countOrderCostSuccessfulTest.
@Test
public void countOrderCostSuccessfulTest() {
WarehouseInfoDTO fakeWarehouseInfoDTO = getFakeWarehouseInfoDTO();
List<Product> fakeProducts = getFakeProducts();
List<ProductPosition> fakePositions = getFakeProductPositions();
Mockito.when(courierRepo.countWorkingCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 100);
Mockito.when(courierRepo.countDeliveringCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 100);
Mockito.when(warehouseService.getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class))).thenReturn(fakeWarehouseInfoDTO);
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(1L, 1L)).thenReturn(Arrays.asList(fakePositions.get(0), fakePositions.get(1)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(2L, 1L)).thenReturn(Arrays.asList(fakePositions.get(2), fakePositions.get(3)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(3L, 1L)).thenReturn(Arrays.asList(fakePositions.get(4), fakePositions.get(5)));
Mockito.when(productRepo.findById(1l)).thenReturn(Optional.of(fakeProducts.get(0)));
Mockito.when(productRepo.findById(2l)).thenReturn(Optional.of(fakeProducts.get(1)));
Mockito.when(productRepo.findById(3l)).thenReturn(Optional.of(fakeProducts.get(2)));
HashMap<Long, Integer> fakeHashMap = new HashMap<>();
fakeHashMap.put(1L, 2);
fakeHashMap.put(2L, 3);
fakeHashMap.put(3L, 5);
Double[] res = orderService.countOrderCost(getFakeCoordsDTO(), fakeHashMap, 1L);
Assertions.assertEquals(res[0], 760.0);
Assertions.assertEquals(res[1], 20.0);
Assertions.assertEquals(res[2], 2.0);
Mockito.verify(courierRepo, Mockito.times(1)).countWorkingCouriersByWarehouse(1L);
Mockito.verify(courierRepo, Mockito.times(1)).countDeliveringCouriersByWarehouse(1L);
Mockito.verify(productPositionRepo, Mockito.times(3)).findByProductIdAndWarehouseIdWithLock(Mockito.any(Long.class), Mockito.eq(1L));
Mockito.verify(warehouseService, Mockito.times(1)).getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class));
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method searchProductsSuccess.
@Test
public void searchProductsSuccess() {
Pageable pageable = PageRequest.of(0, 2);
Page<Product> productPage = ProductUtils.createPageWithMilkProducts(pageable);
String requestSearchPhrase = "Milk taste";
String perfectPhrase = "Milk:* & taste:*";
Long warehouseId = 4L;
Point geo = makeGeo();
WarehouseInfoDTO warehouseInfoDTO = new WarehouseInfoDTO(warehouseId, null, null, null, null, false);
when(warehouseServiceMock.getNearestWarehouse(geo)).thenReturn(warehouseInfoDTO);
when(productRepoMock.searchProducts(perfectPhrase, warehouseId, pageable)).thenReturn(productPage);
SearchProductDTO searchDTO = createSearchProductDTO(requestSearchPhrase);
List<ProductDTO> resultList = productService.searchProducts(searchDTO, pageable);
List<ProductDTO> perfectList = ProductUtils.createProductDTOListFromPage(productPage);
verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
verify(productRepoMock, times(1)).searchProducts(perfectPhrase, warehouseId, pageable);
assertEquals(resultList, perfectList);
}
Aggregations