Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Test method for
- * {@link br.edu.ufpb.threadControl.messengerConcurrent.controller.Facade#addPurchase(br.edu.ufpb.threadControl.messengerConcurrent.entity.Purchase)}
- * .
- */
- @Test
- public void testAddPurchaseProduct() {
- /*------------Starting operations of the customer------------*/
- List<Customer> currentObjectsListCustomer = null;
- Customer customerAuxOne = null;
- Customer customerAuxTwo = null;
- Customer customerAuxThree = null;
- Customer customer1 = new Customer("Diego", "07278910112", "3422-1010",
- "diego.sousa@dce.ufpb.br", "S3cr3t", 18, 11, 1988);
- Customer customer2 = new Customer("Ayla", "07278910113", "3422-1011",
- "ayla@dce.ufpb.br", "S3cr3t2", 19, 12, 1989);
- Customer customer3 = new Customer("Kawe", "07278910114", "3422-1012",
- "kawe.ramon@dce.ufpb.br", "S3cr3t3", 20, 01, 1990);
- // Add Customer
- threadControl.prepare(getAddCustomerFinishedState(3));
- facade.addCustomer(customer1);
- facade.addCustomer(customer2);
- facade.addCustomer(customer3);
- threadControl.waitUntilStateIsReached();
- // Getting the list of customers
- threadControl.prepare(getListOfCustomerFinishedState(1));
- threadControl.proceed();
- facade.getListOfCustomer(copyListOfAllCustomer);
- try {
- currentObjectsListCustomer = copyListOfAllCustomer.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals(3, currentObjectsListCustomer.size());
- assertTrue(currentObjectsListCustomer.contains(customer1));
- assertTrue(currentObjectsListCustomer.contains(customer2));
- assertTrue(currentObjectsListCustomer.contains(customer3));
- // getting customer by CPF
- threadControl.prepare(getSearchCustomerByCpfFinishedState(1));
- threadControl.proceed();
- facade.searchCustomerByCpf("07278910112", takerClientList);
- try {
- customerAuxOne = takerClientList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals("Diego".toUpperCase(), customerAuxOne.getName());
- assertFalse(customerAuxOne.getLogin() == "ayla@dce.ufpb.br");
- // getting customer by CPF
- threadControl.prepare(getSearchCustomerByCpfFinishedState(2));
- threadControl.proceed();
- facade.searchCustomerByCpf("07278910113", takerClientList);
- try {
- customerAuxTwo = takerClientList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals("S3cr3t2", customerAuxTwo.getPassword());
- assertEquals("3422-1011", customerAuxTwo.getPhone());
- assertEquals("Ayla".toUpperCase(), customerAuxTwo.getName());
- assertFalse(customerAuxTwo.getLogin() == "diego.sousa@dce.ufpb.br");
- // getting customer by CPF
- threadControl.prepare(getSearchCustomerByCpfFinishedState(3));
- threadControl.proceed();
- facade.searchCustomerByCpf("07278910114", takerClientList);
- try {
- customerAuxThree = takerClientList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals("S3cr3t3", customerAuxThree.getPassword());
- assertEquals("3422-1012", customerAuxThree.getPhone());
- assertEquals("Kawe".toUpperCase(), customerAuxThree.getName());
- assertFalse(customerAuxThree.getLogin() == "ayla@dce.ufpb.br");
- assertTrue(currentObjectsListCustomer.contains(customerAuxOne));
- assertTrue(currentObjectsListCustomer.contains(customerAuxTwo));
- assertTrue(currentObjectsListCustomer.contains(customerAuxThree));
- assertEquals(3, currentObjectsListCustomer.size());
- /*----------------End of customer operations-------------------*/
- /*------------Starting operations of the product---------------*/
- // Add Products
- List<Product> currentObjectsListProduct = null;
- Product productAuxOne = null;
- Product productAuxTwo = null;
- Product productAuxThree = null;
- Product product1 = new Product("IPod", 1200.00, 100);
- Product product2 = new Product("IPhone", 2200.00, 200);
- Product product3 = new Product("IPad", 3200.00, 300);
- threadControl.prepare(getAddProductFinishedState(3));
- threadControl.proceed();
- facade.addProduct(product1);
- facade.addProduct(product2);
- facade.addProduct(product3);
- threadControl.waitUntilStateIsReached();
- // Getting the List of Products
- threadControl.prepare(getListOfProductFinishedState(1));
- threadControl.proceed();
- facade.getListOfProduct(copyListOfAllProduct);
- try {
- currentObjectsListProduct = copyListOfAllProduct.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals(3, currentObjectsListProduct.size());
- assertTrue(currentObjectsListProduct.contains(product1));
- assertTrue(currentObjectsListProduct.contains(product2));
- assertTrue(currentObjectsListProduct.contains(product3));
- threadControl.prepare(getSearchProductByNameFinishedState(1));
- threadControl.proceed();
- // Searching by product name
- facade.searchProductByName("IPod", takerProductList);
- try {
- productAuxOne = takerProductList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertTrue(currentObjectsListProduct.contains(productAuxOne));
- assertEquals("IPod".toUpperCase(), productAuxOne.getName());
- assertFalse(productAuxOne.getPrice() == 3200);
- // Searching by product name
- threadControl.prepare(getSearchProductByNameFinishedState(2));
- threadControl.proceed();
- facade.searchProductByName("IPad", takerProductList);
- try {
- productAuxTwo = takerProductList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertTrue(currentObjectsListProduct.contains(productAuxTwo));
- assertEquals("IPad".toUpperCase(), productAuxTwo.getName());
- assertFalse(productAuxTwo.getPrice() == 1200);
- // Searching by product name
- threadControl.prepare(getSearchProductByNameFinishedState(3));
- threadControl.proceed();
- facade.searchProductByName("IPhone", takerProductList);
- try {
- productAuxThree = takerProductList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertTrue(currentObjectsListProduct.contains(productAuxThree));
- assertEquals("IPhone".toUpperCase(), productAuxThree.getName());
- assertFalse(productAuxThree.getPrice() == 1200);
- assertTrue(currentObjectsListProduct.contains(productAuxOne));
- assertTrue(currentObjectsListProduct.contains(productAuxTwo));
- assertTrue(currentObjectsListProduct.contains(productAuxThree));
- assertEquals(3, currentObjectsListProduct.size());
- /*-----------------End of Product operations-------------------*/
- /*------------Starting operations of the Promotions---------------*/
- List<Promotion> currentObjectsListPromotion = null;
- Promotion promotionAuxOne = null;
- Promotion promotionAuxTwo = null;
- Promotion promotionAuxThree = null;
- List<Product> listProduct = new ArrayList<Product>();
- listProduct.add(productAuxOne);
- listProduct.add(productAuxThree);
- List<Product> listProductTwo = new ArrayList<Product>();
- listProductTwo.add(productAuxTwo);
- listProductTwo.add(productAuxThree);
- Promotion promotion1 = new Promotion("Promoção Apple", listProductTwo,
- 5000, 30);
- Promotion promotion2 = new Promotion("Promotion Apple Combo",
- listProduct, 3000, 30);
- threadControl.prepare(getAddPromotionFinishedState(2));
- threadControl.proceed();
- facade.addPromotion(promotion1);
- facade.addPromotion(promotion2);
- threadControl.waitUntilStateIsReached();
- // Getting the list of Promotions
- threadControl.prepare(getListOfPromotionFinishedState(1));
- threadControl.proceed();
- facade.getListOfPromotion(copyListOfAllPromotion);
- try {
- currentObjectsListPromotion = copyListOfAllPromotion.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertTrue(currentObjectsListPromotion.contains(promotion1));
- assertTrue(currentObjectsListPromotion.contains(promotion2));
- assertEquals(2, currentObjectsListPromotion.size());
- // getting promotions by Name
- threadControl.prepare(getSearchPromotionByNameFinishedState(1));
- threadControl.proceed();
- facade.searchPromotionByName("Promoção Apple", takerPromotionList);
- try {
- promotionAuxOne = takerPromotionList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals("Promoção Apple".toUpperCase(), promotionAuxOne.getName());
- assertEquals(listProductTwo, promotionAuxOne.getListProducts());
- // getting promotions by Name
- threadControl.prepare(getSearchPromotionByNameFinishedState(2));
- threadControl.proceed();
- facade.searchPromotionByName("Promotion Apple Combo",
- takerPromotionList);
- try {
- promotionAuxTwo = takerPromotionList.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals("Promotion Apple Combo".toUpperCase(),
- promotionAuxTwo.getName());
- assertEquals(listProduct, promotionAuxTwo.getListProducts());
- assertTrue(currentObjectsListPromotion.contains(promotionAuxOne));
- assertTrue(currentObjectsListPromotion.contains(promotionAuxTwo));
- assertFalse(currentObjectsListPromotion.contains(promotionAuxThree));
- assertEquals(2, currentObjectsListPromotion.size());
- /*-----------------End of Promotion operations-----------------*/
- /*------------Starting operations of the Purchases-------------*/
- // Creating list of Products
- List<Purchase> listPurchase = null;
- Map<Product, Integer> listProductAux = new HashMap<Product, Integer>();
- listProductAux.put(productAuxOne, 5);
- // Creating list of Promotions
- Map<Promotion, Integer> listPromotionAux = new HashMap<Promotion, Integer>();
- listPromotionAux.put(promotionAuxOne, 5);
- listPromotionAux.put(promotionAuxTwo, 10);
- Purchase purchaseOne = new Purchase(customerAuxOne, listProductAux,
- null);
- Purchase purchaseTwo = new Purchase(customerAuxTwo, null,
- listPromotionAux);
- Purchase purchaseThree = new Purchase(customerAuxThree, listProductAux,
- listPromotionAux);
- // Adding Purchases
- threadControl.prepare(getAddPurchaseFinishedState(3));
- threadControl.proceed();
- facade.addPurchase(purchaseOne);
- facade.addPurchase(purchaseTwo);
- facade.addPurchase(purchaseThree);
- threadControl.waitUntilStateIsReached();
- // Getting the list of Purchases
- threadControl.prepare(getListOfPurchaseFinishedState(1));
- threadControl.proceed();
- facade.getListOfPurchase(copyListOfAllPurchase);
- try {
- listPurchase = copyListOfAllPurchase.take();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- threadControl.waitUntilStateIsReached();
- assertEquals(3, listPurchase.size());
- assertTrue(listPurchase.contains(purchaseOne));
- assertTrue(listPurchase.contains(purchaseTwo));
- assertTrue(listPurchase.contains(purchaseThree));
- threadControl.proceed();
- }
Add Comment
Please, Sign In to add comment