Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.33 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package fitness.application;
  7.  
  8. import java.time.LocalDate;
  9. import java.util.ArrayList;
  10. import java.util.Arrays;
  11. import org.junit.After;
  12. import org.junit.AfterClass;
  13. import org.junit.Assert;
  14. import org.junit.Before;
  15. import org.junit.BeforeClass;
  16. import org.junit.Test;
  17. import static org.junit.Assert.*;
  18.  
  19. /**
  20. *
  21. * @author Simon Read, Simon William and James Tan
  22. */
  23. public class DatabaseControllerTest {
  24.  
  25. public DatabaseControllerTest() {
  26. }
  27.  
  28. @BeforeClass
  29. public static void setUpClass() {
  30. }
  31.  
  32. @AfterClass
  33. public static void tearDownClass() {
  34. }
  35.  
  36. @Before
  37. public void setUp() {
  38. }
  39.  
  40. @After
  41. public void tearDown() {
  42. }
  43.  
  44. /**
  45. * Test of getUserDashboard method, of class DatabaseController.
  46. */
  47. @Test
  48. public void testGetUserDashboard() {
  49. DatabaseController instance = new DatabaseController();
  50. System.out.println("getUserDashboard");
  51.  
  52. instance.userId = 8888;
  53.  
  54. ArrayList<ArrayList> expResult = new ArrayList<ArrayList>();
  55. ArrayList<String> goals = new ArrayList<String>();
  56. ArrayList<String> daily = new ArrayList<String>();
  57. goals.add("7");
  58. goals.add("60");
  59. goals.add("7000");
  60. goals.add("7");
  61. goals.add("7");
  62. daily.add("3");
  63. daily.add("0");
  64. daily.add("0");
  65. daily.add("2");
  66. daily.add("0");
  67.  
  68. expResult.add(goals);
  69. expResult.add(daily);
  70.  
  71. instance.date = LocalDate.parse("2017-05-03");
  72. instance.previousWeek = LocalDate.parse("2017-05-03").minusDays(7);
  73. instance.previousMonth = LocalDate.parse("2017-05-03").minusMonths(1);
  74. ArrayList<ArrayList> result = instance.getUserDashboard();
  75.  
  76. instance.closeDatabase();
  77. assertEquals(expResult, result);
  78.  
  79. }
  80.  
  81. /**
  82. * Test of addPractitioner method, of class DatabaseController.
  83. */
  84. @Test
  85. public void testAddPractitioner() {
  86. System.out.println("addPractitioner");
  87. DatabaseController instance = new DatabaseController();
  88.  
  89. int practitionerId = 07;
  90. String password = "jkl";
  91. String fName = "Bunsen";
  92. String lName = "Beaker";
  93.  
  94. String[] expResult = new String[4];
  95. expResult[0] = practitionerId + "";
  96. expResult[1] = password + "";
  97. expResult[2] = fName + "";
  98. expResult[3] = lName + "";
  99.  
  100. instance.addPractitioner(practitionerId, password, fName, lName);
  101. String[] result = instance.getUser(07);
  102.  
  103. instance.closeDatabase();
  104. Assert.assertArrayEquals(expResult, result);
  105.  
  106. }
  107. // this is bad
  108. /**
  109. * Test of addClient method, of class DatabaseController.
  110. */
  111. @Test
  112. public void testAddClient() {
  113. DatabaseController instance = new DatabaseController();
  114. System.out.println("addClient");
  115.  
  116. String password = "cookies";
  117. String fName = "Paul";
  118. String lName = "Dell'Orso";
  119. int age = 60;
  120. int pracID = 56;
  121.  
  122. String[] expResult = new String[6];
  123. expResult[0] = 1001 + "";
  124. expResult[1] = password + "";
  125. expResult[2] = fName + "";
  126. expResult[3] = lName + "";
  127. expResult[4] = age + "";
  128. expResult[5] = pracID + "";
  129.  
  130. instance.setUserId(pracID);
  131.  
  132. instance.addClient(password, fName, lName, age);
  133. String[] result = instance.getUser(1001);
  134. instance.removeUser(1001);
  135. instance.closeDatabase();
  136.  
  137.  
  138. Assert.assertArrayEquals(expResult, result);
  139. }
  140.  
  141. /**
  142. * This test case test the user if client Test of getUser method, of class
  143. * DatabaseController.
  144. */
  145. @Test
  146. public void testGetUser() {
  147. System.out.println("getUser");
  148. int user = 8888;
  149. DatabaseController instance = new DatabaseController();
  150. int expResult = 6;
  151. String[] collection = instance.getUser(user);
  152. int result = collection.length;
  153. assertEquals(expResult, result);
  154.  
  155. instance.closeDatabase();
  156. }
  157.  
  158. /**
  159. * This test case test the user if practitioner Test of getUser method, of
  160. * class DatabaseController.
  161. */
  162. @Test
  163. public void testGetUserPrac() {
  164. System.out.println("getUser");
  165. int user = 12;
  166. DatabaseController instance = new DatabaseController();
  167. int expResult = 4;
  168. String[] collection = instance.getUser(user);
  169. int result = collection.length;
  170. assertEquals(expResult, result);
  171.  
  172. instance.closeDatabase();
  173. }
  174. //
  175.  
  176. /**
  177. * Test of setUserId method, of class DatabaseController.
  178. */
  179. @Test
  180. public void testSetUserId() {
  181. System.out.println("setUserId");
  182. int userId = 8888;
  183. int expResult = userId;
  184. DatabaseController instance = new DatabaseController();
  185. instance.setUserId(userId);
  186.  
  187. int result = instance.getUserId();
  188.  
  189. assertEquals(expResult, result);
  190. instance.closeDatabase();
  191.  
  192. }
  193.  
  194. /**
  195. * Test of getUserId method, of class DatabaseController.
  196. */
  197. @Test
  198. public void testGetUserId() {
  199. System.out.println("getUserId");
  200. DatabaseController instance = new DatabaseController();
  201. int expResult = 8888;
  202. int userId = 8888;
  203. instance.setUserId(userId);
  204. int result = instance.getUserId();
  205.  
  206. assertEquals(expResult, result);
  207. instance.closeDatabase();
  208. }
  209.  
  210. /**
  211. * Test of getCurrentUser method, of class DatabaseController.
  212. */
  213. @Test
  214. public void testGetCurrentUser() {
  215. System.out.println("getCurrentUser");
  216. DatabaseController instance = new DatabaseController();
  217. int expResult = 6;
  218. instance.userId = 8888;
  219. String[] collection = instance.getCurrentUser();
  220. int result = collection.length;
  221. assertEquals(expResult, result);
  222. instance.closeDatabase();
  223. }
  224.  
  225. /**
  226. * Test of getClients method, of class DatabaseController.
  227. */
  228. @Test
  229. public void testGetClients() {
  230. System.out.println("getClients");
  231. DatabaseController instance = new DatabaseController();
  232. instance.userId = 12;
  233. int expResult = 4;
  234. ArrayList collection = instance.getClients();
  235. int result = collection.size();
  236.  
  237. assertEquals(expResult, result);
  238. instance.closeDatabase();
  239. }
  240.  
  241. /**
  242. * Test of getPassword method, of class DatabaseController.
  243. */
  244. @Test
  245. public void testGetPassword() {
  246. System.out.println("getPassword");
  247. int userID = 8888;
  248. DatabaseController instance = new DatabaseController();
  249. String expResult = "qwe123";
  250. String result = instance.getPassword(userID);
  251. assertEquals(expResult, result);
  252.  
  253. instance.closeDatabase();
  254. }
  255.  
  256. /** this is full of bads
  257. * Test of removeUser method, of class DatabaseController.
  258. */
  259. @Test
  260. public void testRemoveUser() {
  261. System.out.println("removeUser");
  262. int userId = 9876;
  263. DatabaseController instance = new DatabaseController();
  264. instance.userId = 9876;
  265. boolean result = false;
  266. boolean expResult = true;
  267. instance.removeUser(userId);
  268. String[] testUsers = instance.getUser(userId);
  269. if (testUsers == null) {
  270. //pass
  271. result = true;
  272. }
  273.  
  274. assertEquals(expResult, result);
  275.  
  276. instance.closeDatabase();
  277. }
  278.  
  279. /**
  280. * Test of updatePassword method, of class DatabaseController.
  281. */
  282. @Test
  283. public void testUpdatePassword() {
  284. System.out.println("updatePassword");
  285. int userId = 3333;
  286. String newPassword = "doughnuts";
  287. DatabaseController instance = new DatabaseController();
  288. instance.updatePassword(userId, newPassword);
  289. String result = instance.getPassword(userId);
  290. String expResult = newPassword;
  291.  
  292. assertEquals(expResult, result);
  293.  
  294. instance.closeDatabase();
  295. }
  296.  
  297. /**
  298. * Test of getQuery method, of class DatabaseController.
  299. */
  300. @Test
  301. public void testGetQuery() {
  302.  
  303. System.out.println("getQuery");
  304. String query = "strength";
  305. DatabaseController instance = new DatabaseController();
  306. instance.userId = 8888;
  307. boolean expResult = true;
  308. boolean resultSize = false;
  309. ArrayList<String[]> result = instance.getQuery(query);
  310. int arrSize = result.size();
  311. if (arrSize > 1) {
  312. resultSize = true;
  313. }
  314. instance.closeDatabase();
  315.  
  316. assertEquals(expResult, resultSize);
  317.  
  318. }
  319.  
  320. /**
  321. * Test of addStengthEntry method, of class DatabaseController.
  322. */
  323. @Test
  324. public void testAddStrengthEntry() {
  325. System.out.println("addStengthEntry");
  326.  
  327. DatabaseController instance = new DatabaseController();
  328. instance.userId = 8888;
  329. int programId = 3888;
  330. String exerciseName = "Biceps Curl";
  331. String entryDate = "2017-05-04";
  332. double weight = 5.2;
  333. int reps = 12;
  334.  
  335. ArrayList<String[]> strengthEntryBefore = new ArrayList<String[]>();
  336. ArrayList<String[]> strengthEntryAfter = new ArrayList<String[]>();
  337. ArrayList<String> strengthEntryValues = new ArrayList<String>();
  338.  
  339. strengthEntryValues.add(Integer.toString(programId));
  340. strengthEntryValues.add(exerciseName);
  341. strengthEntryValues.add(entryDate);
  342. strengthEntryValues.add(Double.toString(weight));
  343. strengthEntryValues.add(Integer.toString(reps));
  344.  
  345. strengthEntryBefore = instance.getQuery("strength");
  346.  
  347. instance.addStengthEntry(strengthEntryValues);
  348.  
  349. strengthEntryAfter = instance.getQuery("strength");
  350.  
  351. String sqlQuery = "DELETE FROM strengthEntry WHERE entryDate IS '2017-05-04'";
  352. instance.removeQuery(sqlQuery);
  353. instance.closeDatabase();
  354. assertEquals(strengthEntryBefore.size(), strengthEntryAfter.size() - 1);
  355. }
  356.  
  357. /**
  358. * Test of addAerobicEntry method, of class DatabaseController.
  359. */
  360. @Test
  361. public void testAddAerobicEntry() {
  362. System.out.println("addAerobicEntry");
  363.  
  364. DatabaseController instance = new DatabaseController();
  365. instance.userId = 8888;
  366. int programId = 3889;
  367. String day = "Saturday";
  368. int week = 1;
  369. int minutes = 45;
  370. String entryDate = "2017-05-03";
  371.  
  372. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  373. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  374. ArrayList<String> aerobicEntryValues = new ArrayList<String>();
  375.  
  376. aerobicEntryValues.add(Integer.toString(programId));
  377. aerobicEntryValues.add(day);
  378. aerobicEntryValues.add(Integer.toString(week));
  379. aerobicEntryValues.add(Integer.toString(minutes));
  380. aerobicEntryValues.add(entryDate);
  381.  
  382. arrEntryBefore = instance.getQuery("aerobic");
  383. instance.addAerobicEntry(aerobicEntryValues);
  384. arrEntryAfter = instance.getQuery("aerobic");
  385.  
  386. String sqlQuery = "DELETE FROM aerobicEntry WHERE entryDate IS '2017-05-03'";
  387. instance.removeQuery(sqlQuery);
  388. instance.closeDatabase();
  389. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  390. }
  391.  
  392. /**
  393. * Test of addPedometerEntry method, of class DatabaseController.
  394. */
  395. @Test
  396. public void testAddPedometerEntry() {
  397. System.out.println("addPedometerEntry");
  398. DatabaseController instance = new DatabaseController();
  399. instance.userId = 8888;
  400. int programId = 3889;
  401. String day = "Saturday";
  402. int week = 1;
  403. int steps = 45;
  404. String entryDate = "2017-05-03";
  405.  
  406. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  407. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  408. ArrayList<String> pedometerEntryValues = new ArrayList<String>();
  409. pedometerEntryValues.add(Integer.toString(programId));
  410. pedometerEntryValues.add(day);
  411. pedometerEntryValues.add(Integer.toString(week));
  412. pedometerEntryValues.add(Integer.toString(steps));
  413. pedometerEntryValues.add(entryDate);
  414.  
  415. arrEntryBefore = instance.getQuery("pedometer");
  416. instance.addPedometerEntry(pedometerEntryValues);
  417. arrEntryAfter = instance.getQuery("pedometer");
  418.  
  419. String sqlQuery = "DELETE FROM pedometerEntry WHERE entryDate IS '2017-05-03'";
  420. instance.removeQuery(sqlQuery);
  421. instance.closeDatabase();
  422. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  423. }
  424.  
  425. /**
  426. * Test of addBalanceEntry method, of class DatabaseController.
  427. */
  428. @Test
  429. public void testAddBalanceEntry() {
  430. System.out.println("addBalanceEntry");
  431. DatabaseController instance = new DatabaseController();
  432. instance.userId = 8888;
  433.  
  434. int programId = 3891;
  435. int leftLegTime = 80;
  436. int rightLegTime = 80;
  437. String entryDate = "2017-05-03";
  438.  
  439. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  440. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  441. ArrayList<String> balanceEntryValues = new ArrayList<String>();
  442.  
  443. balanceEntryValues.add(Integer.toString(programId));
  444. balanceEntryValues.add(Integer.toString(leftLegTime));
  445. balanceEntryValues.add(Integer.toString(rightLegTime));
  446. balanceEntryValues.add(entryDate);
  447.  
  448. arrEntryBefore = instance.getQuery("balance");
  449. instance.addBalanceEntry(balanceEntryValues);
  450. arrEntryAfter = instance.getQuery("balance");
  451.  
  452. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  453. String sqlQuery = "DELETE FROM balanceEntry WHERE entryDate IS '2017-05-03'";
  454. instance.removeQuery(sqlQuery);
  455. instance.closeDatabase();
  456. }
  457.  
  458. /**
  459. * Test of addFlexibilityEntry method, of class DatabaseController.
  460. */
  461. @Test
  462. public void testAddFlexibilityEntry() {
  463. System.out.println("addFlexibilityEntry");
  464. DatabaseController instance = new DatabaseController();
  465. instance.userId = 8888;
  466.  
  467. int programId = 3892;
  468. String entryDate = "2017-05-03";
  469. Boolean[] stretches = new Boolean[19];
  470.  
  471. for (int i = 0; i < stretches.length; i++) {
  472. stretches[i] = true;
  473. }
  474.  
  475. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  476. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  477. ArrayList<String> balanceEntryValues = new ArrayList<String>();
  478. balanceEntryValues.add(Integer.toString(programId));
  479. balanceEntryValues.add(entryDate);
  480. for (int j = 0; j < stretches.length; j++) {
  481. balanceEntryValues.add(Boolean.toString(stretches[j]));
  482. }
  483.  
  484. arrEntryBefore = instance.getQuery("flexibility");
  485. instance.addFlexibilityEntry(balanceEntryValues);
  486. arrEntryAfter = instance.getQuery("flexibility");
  487.  
  488. String sqlQuery = "DELETE FROM flexibilityEntry WHERE entryDate IS '2017-05-03'";
  489. instance.removeQuery(sqlQuery);
  490.  
  491. instance.closeDatabase();
  492.  
  493. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  494.  
  495. }
  496.  
  497. /**
  498. * Test of addCondition method, of class DatabaseController.
  499. */
  500. @Test
  501. public void testAddCondition() {
  502. System.out.println("addCondition");
  503. DatabaseController instance = new DatabaseController();
  504. instance.userId = 8888;
  505. instance.newUserId = 8888;
  506. int userId = 8888;
  507. double weight = 142.42;
  508. int height = 180;
  509. Boolean[] conditions = new Boolean[10];
  510. for (int i = 0; i < conditions.length; i++) {
  511. conditions[i] = true;
  512. }
  513. String medicationType = "Gatorade";
  514. String otherProblem = "Kung Fu Elbow";
  515.  
  516. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  517. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  518.  
  519. arrEntryBefore = instance.getQuery("condition");
  520.  
  521. instance.addCondition(weight, height, conditions, medicationType, otherProblem);
  522.  
  523. arrEntryAfter = instance.getQuery("condition");
  524.  
  525. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  526. String sqlQuery = "DELETE FROM condition WHERE medicationType IS 'Gatorade'";
  527.  
  528. instance.removeQuery(sqlQuery);
  529. instance.closeDatabase();
  530.  
  531.  
  532. }
  533.  
  534. /**
  535. * Test of removeQuery method, of class DatabaseController.
  536. */
  537. @Test
  538. public void testRemoveQuery() {
  539. System.out.println("removeQuery");
  540. DatabaseController instance = new DatabaseController();
  541.  
  542. instance.userId = 8888;
  543. int programId = 3889;
  544. String day = "Saturday";
  545. int week = 1;
  546. int steps = 45;
  547. String entryDate = "2017-05-03";
  548.  
  549. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  550. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  551. ArrayList<String> pedometerEntryValues = new ArrayList<String>();
  552. pedometerEntryValues.add(Integer.toString(programId));
  553. pedometerEntryValues.add(day);
  554. pedometerEntryValues.add(Integer.toString(week));
  555. pedometerEntryValues.add(Integer.toString(steps));
  556. pedometerEntryValues.add(entryDate);
  557. //add it to remove
  558. arrEntryBefore = instance.getQuery("pedometer");
  559. instance.addPedometerEntry(pedometerEntryValues);
  560. //remove querry
  561. String sqlQuery = "DELETE FROM pedometerEntry WHERE entryDate IS '2017-05-03'";
  562. instance.removeQuery(sqlQuery);
  563. //get querry after removed
  564. arrEntryAfter = instance.getQuery("pedometer");
  565.  
  566. instance.closeDatabase();
  567. assertEquals(arrEntryBefore.size(), arrEntryAfter.size());
  568.  
  569. }
  570.  
  571. /**
  572. * Test of findUserGoals method, of class DatabaseController.
  573. */
  574. @Test
  575. public void testFindUserGoals() {
  576. System.out.println("findUserGoals");
  577. DatabaseController instance = new DatabaseController();
  578. instance.userId = 3456;
  579.  
  580. int[] expResult = {1, 0, 0, 0, 1};
  581. int[] result = instance.findUserGoals(3456);
  582.  
  583. assertArrayEquals(expResult, result);
  584. instance.closeDatabase();
  585. }
  586.  
  587. /**
  588. * Test of getProgramId method, of class DatabaseController.
  589. */
  590. @Test
  591. public void testGetProgramId() {
  592. System.out.println("getProgramId");
  593. DatabaseController instance = new DatabaseController();
  594. instance.userId = 8888;
  595.  
  596. String s = "strength";
  597. int expResult = 3888;
  598. int result = instance.getProgramId(s,8888);
  599.  
  600. assertEquals(expResult, result);
  601.  
  602. instance.closeDatabase();
  603. }
  604.  
  605. /**
  606. * Test of getExerciseList method, of class DatabaseController.
  607. */
  608. @Test
  609. public void testGetExerciseList() {
  610. System.out.println("getExerciseList");
  611. DatabaseController instance = new DatabaseController();
  612. ArrayList<String> expResult = new ArrayList<String>();
  613. expResult.add("Seated Lateral Raise");
  614. expResult.add("Biceps Curl");
  615. expResult.add("Shoulder Shrugs");
  616. expResult.add("One Arm Triceps");
  617. expResult.add("One Arm Row");
  618. expResult.add("Chest Press");
  619. expResult.add("Abdominal Crunch");
  620. expResult.add("Leg Extension");
  621. expResult.add("Bulgarian Squat");
  622. expResult.add("Calf Raise");
  623. expResult.add("Hamstring Curl");
  624. expResult.add("Glute Extension");
  625. expResult.add("Deadlift");
  626. expResult.add("Squat");
  627. ArrayList<String> result = instance.getExerciseList();
  628. assertEquals(expResult, result);
  629.  
  630. instance.closeDatabase();
  631. }
  632.  
  633.  
  634.  
  635.  
  636. /**
  637. * Test of generateId method, of class DatabaseController.
  638. */
  639. @Test
  640. public void testGenerateId() {
  641. System.out.println("generateId");
  642. String s = "client";
  643. DatabaseController instance = new DatabaseController();
  644.  
  645. int expResult = 1001;
  646. int result = instance.generateId(s);
  647. assertEquals(expResult, result);
  648.  
  649. instance.closeDatabase();
  650. }
  651.  
  652. /**
  653. * Test of setClientId method, of class DatabaseController.
  654. */
  655. @Test
  656. public void testSetClientId() {
  657. System.out.println("setClientId");
  658. int id = 8888;
  659. DatabaseController instance = new DatabaseController();
  660. instance.userId =8888;
  661. instance.setClientId(id);
  662.  
  663. }
  664.  
  665. /**
  666. * Test of getClientId method, of class DatabaseController.
  667. */
  668. @Test
  669. public void testGetClientId() {
  670. System.out.println("getClientId");
  671. DatabaseController instance = new DatabaseController();
  672. int expResult = 0;
  673. int result = instance.getClientId();
  674. assertEquals(expResult, result);
  675.  
  676. }
  677. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement