Guest User

Untitled

a guest
Dec 11th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.85 KB | None | 0 0
  1. /**
  2. * Test method for
  3. * {@link br.edu.ufpb.threadControl.messengerConcurrent.controller.Facade#addPurchase(br.edu.ufpb.threadControl.messengerConcurrent.entity.Purchase)}
  4. * .
  5. */
  6.  
  7. @Test
  8. public void testAddPurchaseProduct() {
  9.  
  10. /*------------Starting operations of the customer------------*/
  11.  
  12. List<Customer> currentObjectsListCustomer = null;
  13.  
  14. Customer customerAuxOne = null;
  15. Customer customerAuxTwo = null;
  16. Customer customerAuxThree = null;
  17.  
  18. Customer customer1 = new Customer("Diego", "07278910112", "3422-1010",
  19. "diego.sousa@dce.ufpb.br", "S3cr3t", 18, 11, 1988);
  20. Customer customer2 = new Customer("Ayla", "07278910113", "3422-1011",
  21. "ayla@dce.ufpb.br", "S3cr3t2", 19, 12, 1989);
  22. Customer customer3 = new Customer("Kawe", "07278910114", "3422-1012",
  23. "kawe.ramon@dce.ufpb.br", "S3cr3t3", 20, 01, 1990);
  24.  
  25. // Add Customer
  26. threadControl.prepare(getAddCustomerFinishedState(3));
  27. facade.addCustomer(customer1);
  28. facade.addCustomer(customer2);
  29. facade.addCustomer(customer3);
  30. threadControl.waitUntilStateIsReached();
  31.  
  32. // Getting the list of customers
  33. threadControl.prepare(getListOfCustomerFinishedState(1));
  34. threadControl.proceed();
  35.  
  36. facade.getListOfCustomer(copyListOfAllCustomer);
  37.  
  38. try {
  39. currentObjectsListCustomer = copyListOfAllCustomer.take();
  40. } catch (InterruptedException e) {
  41. e.printStackTrace();
  42. }
  43.  
  44. threadControl.waitUntilStateIsReached();
  45.  
  46. assertEquals(3, currentObjectsListCustomer.size());
  47. assertTrue(currentObjectsListCustomer.contains(customer1));
  48. assertTrue(currentObjectsListCustomer.contains(customer2));
  49. assertTrue(currentObjectsListCustomer.contains(customer3));
  50.  
  51. // getting customer by CPF
  52. threadControl.prepare(getSearchCustomerByCpfFinishedState(1));
  53. threadControl.proceed();
  54.  
  55. facade.searchCustomerByCpf("07278910112", takerClientList);
  56.  
  57. try {
  58. customerAuxOne = takerClientList.take();
  59. } catch (InterruptedException e) {
  60. e.printStackTrace();
  61. }
  62.  
  63. threadControl.waitUntilStateIsReached();
  64.  
  65. assertEquals("Diego".toUpperCase(), customerAuxOne.getName());
  66. assertFalse(customerAuxOne.getLogin() == "ayla@dce.ufpb.br");
  67.  
  68. // getting customer by CPF
  69. threadControl.prepare(getSearchCustomerByCpfFinishedState(2));
  70. threadControl.proceed();
  71.  
  72. facade.searchCustomerByCpf("07278910113", takerClientList);
  73.  
  74. try {
  75. customerAuxTwo = takerClientList.take();
  76.  
  77. } catch (InterruptedException e) {
  78. e.printStackTrace();
  79. }
  80.  
  81. threadControl.waitUntilStateIsReached();
  82.  
  83. assertEquals("S3cr3t2", customerAuxTwo.getPassword());
  84. assertEquals("3422-1011", customerAuxTwo.getPhone());
  85. assertEquals("Ayla".toUpperCase(), customerAuxTwo.getName());
  86. assertFalse(customerAuxTwo.getLogin() == "diego.sousa@dce.ufpb.br");
  87.  
  88. // getting customer by CPF
  89. threadControl.prepare(getSearchCustomerByCpfFinishedState(3));
  90. threadControl.proceed();
  91.  
  92. facade.searchCustomerByCpf("07278910114", takerClientList);
  93.  
  94. try {
  95. customerAuxThree = takerClientList.take();
  96. } catch (InterruptedException e) {
  97. e.printStackTrace();
  98. }
  99.  
  100. threadControl.waitUntilStateIsReached();
  101.  
  102. assertEquals("S3cr3t3", customerAuxThree.getPassword());
  103. assertEquals("3422-1012", customerAuxThree.getPhone());
  104. assertEquals("Kawe".toUpperCase(), customerAuxThree.getName());
  105. assertFalse(customerAuxThree.getLogin() == "ayla@dce.ufpb.br");
  106.  
  107. assertTrue(currentObjectsListCustomer.contains(customerAuxOne));
  108. assertTrue(currentObjectsListCustomer.contains(customerAuxTwo));
  109. assertTrue(currentObjectsListCustomer.contains(customerAuxThree));
  110. assertEquals(3, currentObjectsListCustomer.size());
  111.  
  112. /*----------------End of customer operations-------------------*/
  113.  
  114. /*------------Starting operations of the product---------------*/
  115.  
  116. // Add Products
  117. List<Product> currentObjectsListProduct = null;
  118.  
  119. Product productAuxOne = null;
  120. Product productAuxTwo = null;
  121. Product productAuxThree = null;
  122.  
  123. Product product1 = new Product("IPod", 1200.00, 100);
  124. Product product2 = new Product("IPhone", 2200.00, 200);
  125. Product product3 = new Product("IPad", 3200.00, 300);
  126.  
  127. threadControl.prepare(getAddProductFinishedState(3));
  128. threadControl.proceed();
  129.  
  130. facade.addProduct(product1);
  131. facade.addProduct(product2);
  132. facade.addProduct(product3);
  133.  
  134. threadControl.waitUntilStateIsReached();
  135.  
  136. // Getting the List of Products
  137. threadControl.prepare(getListOfProductFinishedState(1));
  138. threadControl.proceed();
  139.  
  140. facade.getListOfProduct(copyListOfAllProduct);
  141.  
  142. try {
  143. currentObjectsListProduct = copyListOfAllProduct.take();
  144. } catch (InterruptedException e) {
  145. e.printStackTrace();
  146. }
  147.  
  148. threadControl.waitUntilStateIsReached();
  149.  
  150. assertEquals(3, currentObjectsListProduct.size());
  151. assertTrue(currentObjectsListProduct.contains(product1));
  152. assertTrue(currentObjectsListProduct.contains(product2));
  153. assertTrue(currentObjectsListProduct.contains(product3));
  154.  
  155. threadControl.prepare(getSearchProductByNameFinishedState(1));
  156. threadControl.proceed();
  157.  
  158. // Searching by product name
  159. facade.searchProductByName("IPod", takerProductList);
  160.  
  161. try {
  162. productAuxOne = takerProductList.take();
  163. } catch (InterruptedException e) {
  164. e.printStackTrace();
  165. }
  166.  
  167. threadControl.waitUntilStateIsReached();
  168.  
  169. assertTrue(currentObjectsListProduct.contains(productAuxOne));
  170. assertEquals("IPod".toUpperCase(), productAuxOne.getName());
  171. assertFalse(productAuxOne.getPrice() == 3200);
  172.  
  173. // Searching by product name
  174. threadControl.prepare(getSearchProductByNameFinishedState(2));
  175. threadControl.proceed();
  176.  
  177. facade.searchProductByName("IPad", takerProductList);
  178.  
  179. try {
  180. productAuxTwo = takerProductList.take();
  181. } catch (InterruptedException e) {
  182. e.printStackTrace();
  183. }
  184.  
  185. threadControl.waitUntilStateIsReached();
  186.  
  187. assertTrue(currentObjectsListProduct.contains(productAuxTwo));
  188. assertEquals("IPad".toUpperCase(), productAuxTwo.getName());
  189. assertFalse(productAuxTwo.getPrice() == 1200);
  190.  
  191. // Searching by product name
  192. threadControl.prepare(getSearchProductByNameFinishedState(3));
  193. threadControl.proceed();
  194.  
  195. facade.searchProductByName("IPhone", takerProductList);
  196.  
  197. try {
  198. productAuxThree = takerProductList.take();
  199. } catch (InterruptedException e) {
  200. e.printStackTrace();
  201. }
  202.  
  203. threadControl.waitUntilStateIsReached();
  204.  
  205. assertTrue(currentObjectsListProduct.contains(productAuxThree));
  206. assertEquals("IPhone".toUpperCase(), productAuxThree.getName());
  207. assertFalse(productAuxThree.getPrice() == 1200);
  208.  
  209. assertTrue(currentObjectsListProduct.contains(productAuxOne));
  210. assertTrue(currentObjectsListProduct.contains(productAuxTwo));
  211. assertTrue(currentObjectsListProduct.contains(productAuxThree));
  212. assertEquals(3, currentObjectsListProduct.size());
  213.  
  214. /*-----------------End of Product operations-------------------*/
  215.  
  216. /*------------Starting operations of the Promotions---------------*/
  217.  
  218. List<Promotion> currentObjectsListPromotion = null;
  219. Promotion promotionAuxOne = null;
  220. Promotion promotionAuxTwo = null;
  221. Promotion promotionAuxThree = null;
  222.  
  223. List<Product> listProduct = new ArrayList<Product>();
  224. listProduct.add(productAuxOne);
  225. listProduct.add(productAuxThree);
  226.  
  227. List<Product> listProductTwo = new ArrayList<Product>();
  228. listProductTwo.add(productAuxTwo);
  229. listProductTwo.add(productAuxThree);
  230.  
  231. Promotion promotion1 = new Promotion("Promoção Apple", listProductTwo,
  232. 5000, 30);
  233. Promotion promotion2 = new Promotion("Promotion Apple Combo",
  234. listProduct, 3000, 30);
  235.  
  236. threadControl.prepare(getAddPromotionFinishedState(2));
  237. threadControl.proceed();
  238.  
  239. facade.addPromotion(promotion1);
  240. facade.addPromotion(promotion2);
  241.  
  242. threadControl.waitUntilStateIsReached();
  243.  
  244. // Getting the list of Promotions
  245. threadControl.prepare(getListOfPromotionFinishedState(1));
  246. threadControl.proceed();
  247.  
  248. facade.getListOfPromotion(copyListOfAllPromotion);
  249.  
  250. try {
  251. currentObjectsListPromotion = copyListOfAllPromotion.take();
  252. } catch (InterruptedException e) {
  253. e.printStackTrace();
  254. }
  255.  
  256. threadControl.waitUntilStateIsReached();
  257.  
  258. assertTrue(currentObjectsListPromotion.contains(promotion1));
  259. assertTrue(currentObjectsListPromotion.contains(promotion2));
  260. assertEquals(2, currentObjectsListPromotion.size());
  261.  
  262. // getting promotions by Name
  263. threadControl.prepare(getSearchPromotionByNameFinishedState(1));
  264. threadControl.proceed();
  265.  
  266. facade.searchPromotionByName("Promoção Apple", takerPromotionList);
  267.  
  268. try {
  269. promotionAuxOne = takerPromotionList.take();
  270. } catch (InterruptedException e) {
  271. e.printStackTrace();
  272. }
  273.  
  274. threadControl.waitUntilStateIsReached();
  275.  
  276. assertEquals("Promoção Apple".toUpperCase(), promotionAuxOne.getName());
  277. assertEquals(listProductTwo, promotionAuxOne.getListProducts());
  278.  
  279. // getting promotions by Name
  280. threadControl.prepare(getSearchPromotionByNameFinishedState(2));
  281. threadControl.proceed();
  282.  
  283. facade.searchPromotionByName("Promotion Apple Combo",
  284. takerPromotionList);
  285.  
  286. try {
  287. promotionAuxTwo = takerPromotionList.take();
  288. } catch (InterruptedException e) {
  289. e.printStackTrace();
  290. }
  291.  
  292. threadControl.waitUntilStateIsReached();
  293.  
  294. assertEquals("Promotion Apple Combo".toUpperCase(),
  295. promotionAuxTwo.getName());
  296. assertEquals(listProduct, promotionAuxTwo.getListProducts());
  297.  
  298. assertTrue(currentObjectsListPromotion.contains(promotionAuxOne));
  299. assertTrue(currentObjectsListPromotion.contains(promotionAuxTwo));
  300. assertFalse(currentObjectsListPromotion.contains(promotionAuxThree));
  301. assertEquals(2, currentObjectsListPromotion.size());
  302.  
  303. /*-----------------End of Promotion operations-----------------*/
  304.  
  305. /*------------Starting operations of the Purchases-------------*/
  306.  
  307. // Creating list of Products
  308. List<Purchase> listPurchase = null;
  309. Map<Product, Integer> listProductAux = new HashMap<Product, Integer>();
  310. listProductAux.put(productAuxOne, 5);
  311.  
  312. // Creating list of Promotions
  313. Map<Promotion, Integer> listPromotionAux = new HashMap<Promotion, Integer>();
  314. listPromotionAux.put(promotionAuxOne, 5);
  315. listPromotionAux.put(promotionAuxTwo, 10);
  316.  
  317. Purchase purchaseOne = new Purchase(customerAuxOne, listProductAux,
  318. null);
  319. Purchase purchaseTwo = new Purchase(customerAuxTwo, null,
  320. listPromotionAux);
  321. Purchase purchaseThree = new Purchase(customerAuxThree, listProductAux,
  322. listPromotionAux);
  323.  
  324. // Adding Purchases
  325. threadControl.prepare(getAddPurchaseFinishedState(3));
  326. threadControl.proceed();
  327.  
  328. facade.addPurchase(purchaseOne);
  329. facade.addPurchase(purchaseTwo);
  330. facade.addPurchase(purchaseThree);
  331.  
  332. threadControl.waitUntilStateIsReached();
  333.  
  334. // Getting the list of Purchases
  335. threadControl.prepare(getListOfPurchaseFinishedState(1));
  336. threadControl.proceed();
  337. facade.getListOfPurchase(copyListOfAllPurchase);
  338.  
  339. try {
  340. listPurchase = copyListOfAllPurchase.take();
  341. } catch (InterruptedException e) {
  342. e.printStackTrace();
  343. }
  344.  
  345. threadControl.waitUntilStateIsReached();
  346.  
  347. assertEquals(3, listPurchase.size());
  348. assertTrue(listPurchase.contains(purchaseOne));
  349. assertTrue(listPurchase.contains(purchaseTwo));
  350. assertTrue(listPurchase.contains(purchaseThree));
  351.  
  352. threadControl.proceed();
  353.  
  354. }
Add Comment
Please, Sign In to add comment