Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.43 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("1");
  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.  
  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] = 1000 + "";
  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. instance.addClient(password, fName, lName, age);
  132. String[] result = instance.getUser(1000);
  133. instance.removeUser(1000);
  134. instance.closeDatabase();
  135.  
  136. Assert.assertArrayEquals(expResult, result);
  137. }
  138.  
  139. /**
  140. * This test case test the user if client Test of getUser method, of class
  141. * DatabaseController.
  142. */
  143. @Test
  144. public void testGetUser() {
  145. System.out.println("getUser");
  146. int user = 8888;
  147. DatabaseController instance = new DatabaseController();
  148. int expResult = 6;
  149. String[] collection = instance.getUser(user);
  150. int result = collection.length;
  151. assertEquals(expResult, result);
  152.  
  153. instance.closeDatabase();
  154. }
  155.  
  156. /**
  157. * This test case test the user if practitioner Test of getUser method, of
  158. * class DatabaseController.
  159. */
  160. @Test
  161. public void testGetUserPrac() {
  162. System.out.println("getUser");
  163. int user = 12;
  164. DatabaseController instance = new DatabaseController();
  165. int expResult = 4;
  166. String[] collection = instance.getUser(user);
  167. int result = collection.length;
  168. assertEquals(expResult, result);
  169.  
  170. instance.closeDatabase();
  171. }
  172. //
  173.  
  174. /**
  175. * Test of setUserId method, of class DatabaseController.
  176. */
  177. @Test
  178. public void testSetUserId() {
  179. System.out.println("setUserId");
  180. int userId = 8888;
  181. int expResult = userId;
  182. DatabaseController instance = new DatabaseController();
  183. instance.setUserId(userId);
  184.  
  185. int result = instance.getUserId();
  186.  
  187. assertEquals(expResult, result);
  188. instance.closeDatabase();
  189.  
  190. }
  191.  
  192. /**
  193. * Test of getUserId method, of class DatabaseController.
  194. */
  195. @Test
  196. public void testGetUserId() {
  197. System.out.println("getUserId");
  198. DatabaseController instance = new DatabaseController();
  199. int expResult = 8888;
  200. int userId = 8888;
  201. instance.setUserId(userId);
  202. int result = instance.getUserId();
  203.  
  204. assertEquals(expResult, result);
  205. instance.closeDatabase();
  206. }
  207.  
  208. /**
  209. * Test of getCurrentUser method, of class DatabaseController.
  210. */
  211. @Test
  212. public void testGetCurrentUser() {
  213. System.out.println("getCurrentUser");
  214. DatabaseController instance = new DatabaseController();
  215. int expResult = 6;
  216. instance.userId = 8888;
  217. String[] collection = instance.getCurrentUser();
  218. int result = collection.length;
  219. assertEquals(expResult, result);
  220. instance.closeDatabase();
  221. }
  222.  
  223. /**
  224. * Test of getClients method, of class DatabaseController.
  225. */
  226. @Test
  227. public void testGetClients() {
  228. System.out.println("getClients");
  229. DatabaseController instance = new DatabaseController();
  230. instance.userId = 12;
  231. int expResult = 3;
  232. ArrayList collection = instance.getClients();
  233. int result = collection.size();
  234.  
  235. assertEquals(expResult, result);
  236. instance.closeDatabase();
  237. }
  238.  
  239. /**
  240. * Test of getPassword method, of class DatabaseController.
  241. */
  242. @Test
  243. public void testGetPassword() {
  244. System.out.println("getPassword");
  245. int userID = 8888;
  246. DatabaseController instance = new DatabaseController();
  247. String expResult = "qwe123";
  248. String result = instance.getPassword(userID);
  249. assertEquals(expResult, result);
  250.  
  251. instance.closeDatabase();
  252. }
  253.  
  254. /**
  255. * this is full of bads Test of removeUser method, of class
  256. * DatabaseController.
  257. */
  258. @Test
  259. public void testRemoveUser() {
  260. System.out.println("removeUser");
  261. int userId = 9876;
  262. DatabaseController instance = new DatabaseController();
  263. instance.userId = 9876;
  264. boolean result = false;
  265. boolean expResult = true;
  266. instance.removeUser(userId);
  267. String[] testUsers = instance.getUser(userId);
  268. if (testUsers == null) {
  269. //pass
  270. result = true;
  271. }
  272.  
  273. assertEquals(expResult, result);
  274.  
  275. instance.closeDatabase();
  276. }
  277.  
  278. /**
  279. * Test of updatePassword method, of class DatabaseController.
  280. */
  281. @Test
  282. public void testUpdatePassword() {
  283. System.out.println("updatePassword");
  284. int userId = 3333;
  285. String newPassword = "doughnuts";
  286. DatabaseController instance = new DatabaseController();
  287. instance.updatePassword(userId, newPassword);
  288. String result = instance.getPassword(userId);
  289. String expResult = newPassword;
  290.  
  291. assertEquals(expResult, result);
  292.  
  293. instance.closeDatabase();
  294. }
  295.  
  296. /**
  297. * Test of getQuery method, of class DatabaseController.
  298. */
  299. @Test
  300. public void testGetQuery() {
  301.  
  302. System.out.println("getQuery");
  303. String query = "strength";
  304. DatabaseController instance = new DatabaseController();
  305. instance.userId = 8888;
  306. boolean expResult = true;
  307. boolean resultSize = false;
  308. ArrayList<String[]> result = instance.getQuery(query);
  309. int arrSize = result.size();
  310. if (arrSize > 1) {
  311. resultSize = true;
  312. }
  313. instance.closeDatabase();
  314.  
  315. assertEquals(expResult, resultSize);
  316.  
  317. }
  318.  
  319. /**
  320. * Test of addStengthEntry method, of class DatabaseController.
  321. */
  322. @Test
  323. public void testAddStrengthEntry() {
  324. System.out.println("addStengthEntry");
  325.  
  326. DatabaseController instance = new DatabaseController();
  327. instance.userId = 8888;
  328. int programId = 3888;
  329. String exerciseName = "Biceps Curl";
  330. String entryDate = "2017-05-04";
  331. double weight = 5.2;
  332. int reps = 12;
  333.  
  334. ArrayList<String[]> strengthEntryBefore = new ArrayList<String[]>();
  335. ArrayList<String[]> strengthEntryAfter = new ArrayList<String[]>();
  336. ArrayList<String> strengthEntryValues = new ArrayList<String>();
  337.  
  338. strengthEntryValues.add(Integer.toString(programId));
  339. strengthEntryValues.add(exerciseName);
  340. strengthEntryValues.add(entryDate);
  341. strengthEntryValues.add(Double.toString(weight));
  342. strengthEntryValues.add(Integer.toString(reps));
  343.  
  344. strengthEntryBefore = instance.getQuery("strength");
  345.  
  346. instance.addStengthEntry(strengthEntryValues);
  347.  
  348. strengthEntryAfter = instance.getQuery("strength");
  349.  
  350. String sqlQuery = "DELETE FROM strengthEntry WHERE entryDate IS '2017-05-04'";
  351. instance.removeQuery(sqlQuery);
  352. instance.closeDatabase();
  353. assertEquals(strengthEntryBefore.size(), strengthEntryAfter.size() - 1);
  354. }
  355.  
  356. /**
  357. * Test of addAerobicEntry method, of class DatabaseController.
  358. */
  359. @Test
  360. public void testAddAerobicEntry() {
  361. System.out.println("addAerobicEntry");
  362.  
  363. DatabaseController instance = new DatabaseController();
  364. instance.userId = 8888;
  365. int programId = 3889;
  366. String day = "Saturday";
  367. int minutes = 45;
  368. String entryDate = "2017-05-03";
  369.  
  370. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  371. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  372. ArrayList<String> aerobicEntryValues = new ArrayList<String>();
  373.  
  374. aerobicEntryValues.add(Integer.toString(programId));
  375. aerobicEntryValues.add(day);
  376. aerobicEntryValues.add(Integer.toString(minutes));
  377. aerobicEntryValues.add(entryDate);
  378.  
  379. arrEntryBefore = instance.getQuery("aerobic");
  380. instance.addAerobicEntry(aerobicEntryValues);
  381. arrEntryAfter = instance.getQuery("aerobic");
  382.  
  383. String sqlQuery = "DELETE FROM aerobicEntry WHERE entryDate IS '2017-05-03'";
  384. instance.removeQuery(sqlQuery);
  385. instance.closeDatabase();
  386. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  387. }
  388.  
  389. /**
  390. * Test of addPedometerEntry method, of class DatabaseController.
  391. */
  392. @Test
  393. public void testAddPedometerEntry() {
  394. System.out.println("addPedometerEntry");
  395. DatabaseController instance = new DatabaseController();
  396. instance.userId = 8888;
  397. int programId = 3889;
  398. String day = "Saturday";
  399. int steps = 45;
  400. String entryDate = "2017-05-03";
  401.  
  402. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  403. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  404. ArrayList<String> pedometerEntryValues = new ArrayList<String>();
  405. pedometerEntryValues.add(Integer.toString(programId));
  406. pedometerEntryValues.add(day);
  407. pedometerEntryValues.add(Integer.toString(steps));
  408. pedometerEntryValues.add(entryDate);
  409.  
  410. arrEntryBefore = instance.getQuery("pedometer");
  411. instance.addPedometerEntry(pedometerEntryValues);
  412. arrEntryAfter = instance.getQuery("pedometer");
  413.  
  414. String sqlQuery = "DELETE FROM pedometerEntry WHERE steps IS 45";
  415. instance.removeQuery(sqlQuery);
  416.  
  417. instance.closeDatabase();
  418.  
  419. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  420. }
  421.  
  422. /**
  423. * Test of addBalanceEntry method, of class DatabaseController.
  424. */
  425. @Test
  426. public void testAddBalanceEntry() {
  427. System.out.println("addBalanceEntry");
  428. DatabaseController instance = new DatabaseController();
  429. instance.userId = 8888;
  430.  
  431. int programId = 3891;
  432. int leftLegTime = 80;
  433. int rightLegTime = 80;
  434. String entryDate = "2017-05-03";
  435.  
  436. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  437. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  438. ArrayList<String> balanceEntryValues = new ArrayList<String>();
  439.  
  440. balanceEntryValues.add(Integer.toString(programId));
  441. balanceEntryValues.add(Integer.toString(leftLegTime));
  442. balanceEntryValues.add(Integer.toString(rightLegTime));
  443. balanceEntryValues.add(entryDate);
  444.  
  445. arrEntryBefore = instance.getQuery("balance");
  446. instance.addBalanceEntry(balanceEntryValues);
  447. arrEntryAfter = instance.getQuery("balance");
  448.  
  449. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  450. String sqlQuery = "DELETE FROM balanceEntry WHERE entryDate IS '2017-05-03'";
  451. instance.removeQuery(sqlQuery);
  452. instance.closeDatabase();
  453. }
  454.  
  455. /**
  456. * Test of addFlexibilityEntry method, of class DatabaseController.
  457. */
  458. @Test
  459. public void testAddFlexibilityEntry() {
  460. System.out.println("addFlexibilityEntry");
  461. DatabaseController instance = new DatabaseController();
  462. instance.userId = 8888;
  463.  
  464. int programId = 3892;
  465. String entryDate = "2017-05-03";
  466. Boolean[] stretches = new Boolean[19];
  467.  
  468. for (int i = 0; i < stretches.length; i++) {
  469. stretches[i] = true;
  470. }
  471.  
  472. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  473. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  474. ArrayList<String> balanceEntryValues = new ArrayList<String>();
  475. balanceEntryValues.add(Integer.toString(programId));
  476. balanceEntryValues.add(entryDate);
  477. for (int j = 0; j < stretches.length; j++) {
  478. balanceEntryValues.add(Boolean.toString(stretches[j]));
  479. }
  480.  
  481. arrEntryBefore = instance.getQuery("flexibility");
  482. instance.addFlexibilityEntry(balanceEntryValues);
  483. arrEntryAfter = instance.getQuery("flexibility");
  484.  
  485. String sqlQuery = "DELETE FROM flexibilityEntry WHERE entryDate IS '2017-05-03'";
  486. instance.removeQuery(sqlQuery);
  487.  
  488. instance.closeDatabase();
  489.  
  490. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  491.  
  492. }
  493.  
  494. /**
  495. * Test of addCondition method, of class DatabaseController.
  496. */
  497. @Test
  498. public void testAddCondition() {
  499. System.out.println("addCondition");
  500. DatabaseController instance = new DatabaseController();
  501. instance.userId = 8888;
  502. instance.newUserId = 8888;
  503. int userId = 8888;
  504. double weight = 142.42;
  505. int height = 180;
  506. Boolean[] conditions = new Boolean[10];
  507. for (int i = 0; i < conditions.length; i++) {
  508. conditions[i] = true;
  509. }
  510. String medicationType = "Gatorade";
  511. String otherProblem = "Kung Fu Elbow";
  512.  
  513. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  514. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  515.  
  516. arrEntryBefore = instance.getQuery("condition");
  517.  
  518. instance.addCondition(weight, height, conditions, medicationType, otherProblem);
  519.  
  520. arrEntryAfter = instance.getQuery("condition");
  521.  
  522. assertEquals(arrEntryBefore.size(), arrEntryAfter.size() - 1);
  523. String sqlQuery = "DELETE FROM condition WHERE medicationType IS 'Gatorade'";
  524.  
  525. instance.removeQuery(sqlQuery);
  526. instance.closeDatabase();
  527.  
  528. }
  529.  
  530. /**
  531. * Test of removeQuery method, of class DatabaseController.
  532. */
  533. @Test
  534. public void testRemoveQuery() {
  535. System.out.println("removeQuery");
  536. DatabaseController instance = new DatabaseController();
  537.  
  538. instance.userId = 8888;
  539. int programId = 3889;
  540. String day = "Saturday";
  541. int steps = 45;
  542. String entryDate = "2017-05-03";
  543.  
  544. ArrayList<String[]> arrEntryBefore = new ArrayList<String[]>();
  545. ArrayList<String[]> arrEntryAfter = new ArrayList<String[]>();
  546. ArrayList<String> pedometerEntryValues = new ArrayList<String>();
  547. pedometerEntryValues.add(Integer.toString(programId));
  548. pedometerEntryValues.add(day);
  549. pedometerEntryValues.add(Integer.toString(steps));
  550. pedometerEntryValues.add(entryDate);
  551. //add it to remove
  552. arrEntryBefore = instance.getQuery("pedometer");
  553. instance.addPedometerEntry(pedometerEntryValues);
  554. //remove querry
  555. String sqlQuery = "DELETE FROM pedometerEntry WHERE entryDate IS '2017-05-03'";
  556. instance.removeQuery(sqlQuery);
  557. //get querry after removed
  558. arrEntryAfter = instance.getQuery("pedometer");
  559.  
  560. instance.closeDatabase();
  561. assertEquals(arrEntryBefore.size(), arrEntryAfter.size());
  562.  
  563. }
  564.  
  565. /**
  566. * Test of findUserGoals method, of class DatabaseController.
  567. */
  568. @Test
  569. public void testFindUserGoals() {
  570. System.out.println("findUserGoals");
  571. DatabaseController instance = new DatabaseController();
  572. instance.userId = 3456;
  573.  
  574. int[] expResult = {1, 0, 0, 0, 1};
  575. int[] result = instance.findUserGoals(3456);
  576.  
  577. assertArrayEquals(expResult, result);
  578. instance.closeDatabase();
  579. }
  580.  
  581. /**
  582. * Test of getProgramId method, of class DatabaseController.
  583. */
  584. @Test
  585. public void testGetProgramId() {
  586. System.out.println("getProgramId");
  587. DatabaseController instance = new DatabaseController();
  588. instance.userId = 8888;
  589.  
  590. String s = "strength";
  591. int expResult = 3888;
  592. int result = instance.getProgramId(s, 8888);
  593.  
  594. assertEquals(expResult, result);
  595.  
  596. instance.closeDatabase();
  597. }
  598.  
  599. /**
  600. * Test of getExerciseList method, of class DatabaseController.
  601. */
  602. @Test
  603. public void testGetExerciseList() {
  604. System.out.println("getExerciseList");
  605. DatabaseController instance = new DatabaseController();
  606. ArrayList<String> expResult = new ArrayList<String>();
  607. expResult.add("Seated Lateral Raise");
  608. expResult.add("Biceps Curl");
  609. expResult.add("Shoulder Shrugs");
  610. expResult.add("One Arm Triceps");
  611. expResult.add("One Arm Row");
  612. expResult.add("Chest Press");
  613. expResult.add("Abdominal Crunch");
  614. expResult.add("Leg Extension");
  615. expResult.add("Bulgarian Squat");
  616. expResult.add("Calf Raise");
  617. expResult.add("Hamstring Curl");
  618. expResult.add("Glute Extension");
  619. expResult.add("Deadlift");
  620. expResult.add("Squat");
  621. ArrayList<String> result = instance.getExerciseList();
  622. assertEquals(expResult, result);
  623.  
  624. instance.closeDatabase();
  625. }
  626.  
  627. /**
  628. * Test of generateId method, of class DatabaseController.
  629. */
  630. @Test
  631. public void testGenerateId() {
  632. System.out.println("generateId");
  633. String s = "client";
  634. DatabaseController instance = new DatabaseController();
  635.  
  636. int expResult = 1000;
  637. int result = instance.generateId(s);
  638. assertEquals(expResult, result);
  639.  
  640. instance.closeDatabase();
  641. }
  642.  
  643. /**
  644. * Test of setClientId method, of class DatabaseController.
  645. */
  646. @Test
  647. public void testSetClientId() {
  648. System.out.println("setClientId");
  649. int id = 8888;
  650. int expResult = id;
  651. DatabaseController instance = new DatabaseController();
  652. instance.userId = 8888;
  653. instance.setClientId(id);
  654. int result = instance.getClientId();
  655. assertEquals(expResult, result);
  656. instance.closeDatabase();
  657. }
  658.  
  659. /**
  660. * Test of getClientId method, of class DatabaseController.
  661. */
  662. @Test
  663. public void testGetClientId() {
  664. System.out.println("getClientId");
  665. DatabaseController instance = new DatabaseController();
  666. int id = 8888;
  667. int expResult = id;
  668. instance.setClientId(id);
  669. int result = instance.getClientId();
  670. assertEquals(expResult, result);
  671. instance.closeDatabase();
  672.  
  673. }
  674.  
  675. /**
  676. * Test of getClientProgramsFromDb(FromDb method, of class
  677. * DatabaseController.
  678. */
  679. @Test
  680. public void testgetClientProgramsFromDb() {
  681. System.out.println("getClientProgramsFromDb");
  682. int id = 1111;
  683. DatabaseController instance = new DatabaseController();
  684. int[] expResult = {1, 1, 0, 0, 0};
  685. int[] result = instance.getClientProgramsFromDb(id);
  686.  
  687. instance.closeDatabase();
  688.  
  689. assertArrayEquals(expResult, result);
  690.  
  691. }
  692.  
  693. /**
  694. * Test of getClientProgramsFromDb method, of class DatabaseController.
  695. */
  696. @Test
  697. public void testGetClientPrograms() {
  698. System.out.println("getClientPrograms");
  699. int id = 1111;
  700. String s = "existing";
  701. DatabaseController instance = new DatabaseController();
  702. String[] expResult = {"Strength", "Aerobic"};
  703. String[] result = instance.getClientPrograms(id, s);
  704.  
  705. instance.closeDatabase();
  706.  
  707. assertArrayEquals(expResult, result);
  708.  
  709. }
  710.  
  711. /**
  712. * Test of getGoalId method, of class DatabaseController.
  713. */
  714. @Test
  715. public void testGetGoalId() {
  716. System.out.println("getGoalId");
  717. String exercise = "strength";
  718. int pid = 3888;
  719. int id = 8888;
  720. DatabaseController instance = new DatabaseController();
  721. instance.userId = id;
  722. int expResult = 5888;
  723.  
  724. int result = instance.getGoalId(exercise, pid);
  725. instance.closeDatabase();
  726. assertEquals(expResult, result);
  727.  
  728. }
  729.  
  730. /**
  731. * Test of getProgramDateRange method, of class DatabaseController.
  732. */
  733. @Test
  734. public void testGetProgramDateRange() {
  735. System.out.println("getProgramDateRange");
  736. String programName = "strength";
  737. DatabaseController instance = new DatabaseController();
  738. int id = 8888;
  739. instance.userId = id;
  740. ArrayList<String> expResult = new ArrayList<String>();
  741. String[] strArr = {"2017-04-29", "2017-04-30", "2017-05-01", "2017-05-02", "2017-05-03",
  742. "2017-05-04", "2017-05-05", "2017-05-06", "2017-05-07", "2017-05-08",
  743. "2017-05-09", "2017-05-10", "2017-05-11", "2017-05-12", "2017-05-13",
  744. "2017-05-14", "2017-05-15", "2017-05-16", "2017-05-17", "2017-05-18",
  745. "2017-05-19", "2017-05-20", "2017-05-21", "2017-05-22", "2017-05-23",
  746. "2017-05-24", "2017-05-25", "2017-05-26", "2017-05-27", "2017-05-28",
  747. "2017-05-29", "2017-05-30", "2017-05-31", "2017-06-01", "2017-06-02"};
  748.  
  749. for (int i = 0; i < strArr.length; i++) {
  750. expResult.add(strArr[i]);
  751. }
  752. ArrayList<String> result = instance.getProgramDateRange(programName);
  753.  
  754. instance.closeDatabase();
  755. assertEquals(expResult, result);
  756.  
  757. }
  758.  
  759. /**
  760. * Test of addProgram method, of class DatabaseController.
  761. */
  762. @Test
  763. public void testAddProgram() {
  764. System.out.println("addProgram");
  765. int id = 1111;
  766. int type = 3;
  767. String dateStart = "2017-04-28";
  768. String dateFinish = "2017-06-01";
  769. String program = "pedometer";
  770.  
  771. ArrayList<String> programArr = new ArrayList<String>();
  772. programArr.add(Integer.toString(id));
  773. programArr.add(Integer.toString(type));
  774. programArr.add(dateStart);
  775. programArr.add(dateFinish);
  776. for (int i = 0; i < 7; i++) {
  777. programArr.add("true");
  778. }
  779. DatabaseController instance = new DatabaseController();
  780. instance.userId = 12;
  781. instance.addProgram(programArr);
  782. int expResult = 3111;
  783. int result = instance.getProgramId(program, 1111);
  784.  
  785. //remove querry
  786. String sqlQuery = "DELETE FROM program WHERE dateStart IS '2017-04-28'";
  787. instance.removeQuery(sqlQuery);
  788.  
  789. instance.closeDatabase();
  790. assertEquals(expResult, result);
  791.  
  792. }
  793.  
  794. /**
  795. * Test of generateProgramId method, of class DatabaseController.
  796. */
  797. @Test
  798. public void testGenerateProgramId() {
  799. System.out.println("generateProgramId");
  800. int user = 1111;
  801. DatabaseController instance = new DatabaseController();
  802. instance.userId =12;
  803.  
  804. int expResult = 3111;
  805. int result = instance.generateProgramId(user);
  806.  
  807.  
  808. instance.closeDatabase();
  809. assertEquals(expResult, result);
  810.  
  811. }
  812.  
  813. /**
  814. * Test of addGoalEntry method, of class DatabaseController.
  815. */
  816. @Test
  817. public void testAddGoalEntry() {
  818. System.out.println("addGoalEntry");
  819. DatabaseController instance = new DatabaseController();
  820. instance.setClientId(1111);
  821. String exercise = "strength";
  822. int programID = 3006;
  823. ArrayList<String> goalEntry = new ArrayList<String>();
  824. String excerName = "arms";
  825. int startWeight = 05;
  826. int endWeight = 05;
  827. int exceriseStartReps = 05;
  828. int exceriseGoalsReps =05;
  829.  
  830. goalEntry.add(excerName);
  831. goalEntry.add(Integer.toString(startWeight));
  832. goalEntry.add(Integer.toString(endWeight));
  833. goalEntry.add(Integer.toString(exceriseStartReps));
  834. goalEntry.add(Integer.toString(exceriseGoalsReps));
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841. instance.addGoalEntry(exercise, goalEntry);
  842.  
  843. int expResult = 4006;
  844.  
  845. int result = instance.getGoalId(exercise, programID);
  846. System.out.println("resultzzzz" + result);
  847. String sqlQuery = "DELETE FROM strengthGoal WHERE goalId IS 4006";
  848. instance.removeQuery(sqlQuery);
  849. String sqlQueryTwo = "DELETE FROM myGoals WHERE goalId IS 4006";
  850. instance.removeQuery(sqlQueryTwo);
  851.  
  852. instance.closeDatabase();
  853. assertEquals(expResult, result);
  854.  
  855. }
  856.  
  857. /**
  858. * Test of getStrengthExercise method, of class DatabaseController.
  859. */
  860. @Test
  861. public void testGetStrengthExercise() {
  862. System.out.println("getStrengthExercise");
  863. String exercise = "Arms";
  864. DatabaseController instance = new DatabaseController();
  865. ArrayList expResult = null;
  866. ArrayList result = instance.getStrengthExercise(exercise);
  867.  
  868.  
  869. instance.closeDatabase();
  870. assertEquals(expResult, result);
  871. }
  872. //
  873. // /**
  874. // * Test of getStrengthDays method, of class DatabaseController.
  875. // */
  876. // @Test
  877. // public void testGetStrengthDays() {
  878. // System.out.println("getStrengthDays");
  879. // String exercise = "";
  880. // DatabaseController instance = new DatabaseController();
  881. // boolean[] expResult = null;
  882. // boolean[] result = instance.getStrengthDays(exercise);
  883. // assertArrayEquals(expResult, result);
  884. // // TODO review the generated test code and remove the default call to fail.
  885. // fail("The test case is a prototype.");
  886. // }
  887. //
  888. // /**
  889. // * Test of editStrengthEntry method, of class DatabaseController.
  890. // */
  891. // @Test
  892. // public void testEditStrengthEntry() {
  893. // System.out.println("editStrengthEntry");
  894. // DatabaseController instance = new DatabaseController();
  895. // instance.editStrengthEntry();
  896. // // TODO review the generated test code and remove the default call to fail.
  897. // fail("The test case is a prototype.");
  898. // }
  899. //
  900. // /**
  901. // * Test of editAerobicEntry method, of class DatabaseController.
  902. // */
  903. // @Test
  904. // public void testEditAerobicEntry() {
  905. // System.out.println("editAerobicEntry");
  906. // DatabaseController instance = new DatabaseController();
  907. // instance.editAerobicEntry();
  908. // // TODO review the generated test code and remove the default call to fail.
  909. // fail("The test case is a prototype.");
  910. // }
  911. //
  912. // /**
  913. // * Test of editPedometerEntry method, of class DatabaseController.
  914. // */
  915. // @Test
  916. // public void testEditPedometerEntry() {
  917. // System.out.println("editPedometerEntry");
  918. // DatabaseController instance = new DatabaseController();
  919. // instance.editPedometerEntry();
  920. // // TODO review the generated test code and remove the default call to fail.
  921. // fail("The test case is a prototype.");
  922. // }
  923. //
  924. // /**
  925. // * Test of editBalanceEntry method, of class DatabaseController.
  926. // */
  927. // @Test
  928. // public void testEditBalanceEntry() {
  929. // System.out.println("editBalanceEntry");
  930. // DatabaseController instance = new DatabaseController();
  931. // instance.editBalanceEntry();
  932. // // TODO review the generated test code and remove the default call to fail.
  933. // fail("The test case is a prototype.");
  934. // }
  935. //
  936. // /**
  937. // * Test of editFlexibilityEntry method, of class DatabaseController.
  938. // */
  939. // @Test
  940. // public void testEditFlexibilityEntry() {
  941. // System.out.println("editFlexibilityEntry");
  942. // DatabaseController instance = new DatabaseController();
  943. // instance.editFlexibilityEntry();
  944. // // TODO review the generated test code and remove the default call to fail.
  945. // fail("The test case is a prototype.");
  946. // }
  947. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement