HTDS Integration and Testing CSC 505 - Advanced Topics in Software Engineering Spring 2014 May 1, 2014 Version 2.0 Prepared by Qutaiba Albluwi, Younghun Chae, Tripti Garg, Zach Oliveira
HTDS Integration and Testing
CSC 505 - Advanced Topics in Software Engineering
Spring 2014
May 1, 2014
Version 2.0
Prepared by
Qutaiba Albluwi, Younghun Chae, Tripti Garg, Zach Oliveira
HTDS Testing and Integration
2
Document Status Sheet
Document Title Software Design Document
Author(s) Q. Albluwi, Y. Chae, T. Garg, Z. Oliveira
Version 2.0
Document Status Proposed
Version Submission
Date
Changes
1.0 04-10-2014 The document includes only the testing plans
2.0 04-24-2014 The document is restructured such that the testing plan is
presented in v1.0 appears in Section 1 and 2.
Sections 3, 4 and 5 are added
HTDS Testing and Integration
3
Table of Contents 1. Testing Model and Documentation ..................................................................................................... 5
1.1 Testing Model .................................................................................................................................. 5
1.2. Relationship to other documents ..................................................................................................... 5
2. Testing Plan ......................................................................................................................................... 5
2.1 Module Testing Plan ......................................................................................................................... 5
2.2 Integration Testing Plan ................................................................................................................... 5
2.3 Use Case Testing Inventory ............................................................................................................... 6
2.4 Expected Use Case Testing Results .................................................................................................... 7
2.5 Testing Schedule .............................................................................................................................. 9
3. Data Sets .............................................................................................................................................. 9
3.1 Data Generation ............................................................................................................................... 9
3.2 Sample Data Sets ............................................................................................................................ 10
3.3.1 Data Set 1: RhodeIsland.txt ................................................................................................... 10
3.3.2 Data Set 2: Massachusetts.txt ................................................................................................ 10
3.3.3 Data Set 3: Germany.txt ......................................................................................................... 11
3.3.4 Data Set 4: France.txt ............................................................................................................ 11
3.3.5 Data Set 5: Russia.txt ............................................................................................................ 11
3.3 Random HTDS Data Structure ......................................................................................................... 12
4. Testing Results .................................................................................................................................. 12
4.1 Unit Testing ................................................................................................................................... 12
4.1.1 Results of Unit Testing Using AlertTest Module ..................................................................... 12
4.1.2 Results of Unit Testing Using DBConnectorTest Module........................................................ 14
4.2 Integration Testing ........................................................................................................................ 14
5. Appendices ........................................................................................................................................ 16
5.1 Python Random Phone Number Generator ...................................................................................... 16
5.2 RandomHTDS Testing Module ........................................................................................................ 16
5.3 AlertTest JUnit Module ................................................................................................................... 19
5.4 DBConnectorTest JUnit Module ...................................................................................................... 24
HTDS Testing and Integration
4
Table of Figures Figure 1: Relationship of the “Testing and Integration” Document to other documents ............................. 6
Figure 2: Sample from Data Set 1: RhodeIsland.txt ............................................................................... 10
Figure 3: Sample from Data Set 2: Massachusetts.txt ............................................................................ 10
Figure 4: Sample from Data Set 3: Germany.txt ..................................................................................... 11
Figure 5: Sample Data Set 4: France.txt ................................................................................................ 11
Figure 6: Sample Data Set 5: Russia.txt ................................................................................................ 12
Figure 7: AlertTest JUnit Results ............................................................................................................ 13
Figure 8: AlertTest Error Reporting ........................................................................................................ 13
Figure 9: DBConnector JUnit Results ..................................................................................................... 14
Figure 10: Python Script for Random Phone Number Generator ............................................................ 16
Table of Tables Table 1: Use Case & Test Case Inventory ............................................................................................... 7
Table 2: Expected Use Case Testing Results .......................................................................................... 9
Table 3: Testing Schedule ....................................................................................................................... 9
Table 4: Random HTDS Data Structures ............................................................................................... 12
Table 5: Integration Testing Results ....................................................................................................... 15
HTDS Testing and Integration
5
1. Testing Model and Documentation
1.1 Testing Model For the testing of the HTDS system, a black-box testing technique will be used. A large portion
of the HTDS system consists of communication with the database. It is of no concern how the
data is retrieved from the database, as long the user can receive the information they wish to
retrieve, the test will be successful. Similarly, as long as information can be successfully
uploaded to the database, the test will be successful. Since we are only concerned with the
input/output of the HTDS system, the black-box testing technique will be sufficient.
The testing of the HTDS system will also use a top-down approach. The HTDS system has a
GUI interface that the user interacts with. If a problem arises during testing, it will be as a result
of the user interacting with the interface. In debugging the problem, our team will need to track
the problem from the “highest” part of the structure that handles the most click, and work our
way down until we find the problem, possibly down to the lowest level of
1.2. Relationship to other documents We present the relationship of the test plan to the other documents produced during the
development, such as Software Requirements, Software Design, and Implementation Guide.
This shows that how the testing scenarios are related to each document.
1. The use cases are developed from the use cases in the Software Requirements
Specification document. It refers to the section 3.3 in the Software Requirements
Specification document.
2. Integration tests are developed from the Software Design document. It refers to the
section 1 and 2 in the Software Design document.
3. Unit tests are generated from the Implementation Guide document. It refers to the section
2 in the Implementation Guide document.
A visualization of the relationships to the other documents can be seen in the diagram below.
2. Testing Plan
2.1 Module Testing Plan The module testing cases will be designed to test the validity of the program’s correctness. The
module testing cases will be performed on the components as they are developed. Tests will be
executed using test code in the form of JUnit which provides a good test framework for Java
Language. The JUnit will test each class that has been implemented at each building time.
2.2 Integration Testing Plan Integration test will be performed on both the components as well as the integrated system that
involves the Local PCs and Remote database. Since the components will be developed from the
top-down, the test strategy will mostly align to the order of top-down integration test approach.
HTDS Testing and Integration
6
However, as the integration begins to include GUI level functionality, the tests being run will
utilize significantly more manual testing and less automated testing.
Figure 1: Relationship of the “Testing and Integration” Document to other documents
2.3 Use Case Testing Inventory Considering the scope of the project and the time limitations, the following use cases will be
tested:
Use Case ID Description Test Case
UC-1 Login to HTDS TC-1, TC-2
UC-2 Select a Task TC-3, TC-4, TC-5
UC-3 View Alerts TC-6, TC-7, TC-8, TC-9, TC-10
UC-4 Upload Input Files TC-11, TC-12
UC-5 Analyze Data TC-13, TC-14
UC-6 Add User TC-15, TC-16
UC-7 Configure Alert Database (ADB) TC-17
UC-8 Update User TC-18, TC-19, TC-20
UC-9 Logout TC-21
HTDS Testing and Integration
7
UC-10 Create Profile TC-22, TC-23
UC-11 View Data TC-24, TC-25, TC-26, TC-27, TC-28, TC-29, TC-30
Table 1: Use Case & Test Case Inventory
2.4 Expected Use Case Testing Results The table below provides the description and expected result of each test case executed to fully
test the functionality in the use cases.
Test
Case
Use
Case ID
Description Expected Result
TC-1 UC-1 Agent enters a valid user name
and password
User is granted the access to the system
TC-2 UC-1 Agent enters an invalid user
name and password
User is not granted the access to the system.
An error message displays informing agent that
username password is invalid.
TC-3 UC-2 Agent clicks view alerts View alerts screen displays
TC-4 UC-2 Agent clicks upload files The HTDS Uploader screen displays
TC-5 UC-2 Agent clicks analyze files Analyze files screen displays
TC-6 UC-3 Agent clicks on view all alerts
All the alerts present in the database are
displayed to the agent
TC-7 UC-3 Agent clicks on alerts by date Agent is able to select a date, only the alerts
specified for that date are displayed. No other
alerts are displayed.
TC-8 UC-3 Agent clicks on alerts by user Agent is able to select a user. Only the alerts
for the selected user display.
TC-9 UC-3 Agent clicks on alerts by phone
number
Agent is able to select a phone number. Only
the alerts for the selected phone number
display.
TC-10 UC-3 Agent clicks on alerts by victim
name
Agent is able to select a victim name. Only the
alerts for the selected victim name display.
TC-11 UC-4 Agent clicks browse button Agent is able to browse a file and select it. The
selected file displays with its location.
HTDS Testing and Integration
8
TC-12 UC-4 Agent clicks upload button Success: File is uploaded successfully in ADB.
A message with Success displays.
Failure: File is not uploaded in ADB. A error
message displays.
TC-13 UC-5 Agent clicks the analyzer button
and selects data from ADB
Analyze Data screen displays and agent is able
to see selected data from ADB
TC-14 UC-5 Agent stores alerts in ADB Success: Alerts stored in ADB. A success
message displays.
Failure: Alerts are not stored in ADB. A error
message displays.
TC-15 UC-6 Administrator clicks
configuration button
Configuration screens displays.
TC-16 UC-6 Administrator selects add user
and enters username,
password, privileges
If user is added successfully in database, the
message with success will be displayed.
Otherwise error message will be displayed. If
same username already exists in database, the
message to choose another username will be
displayed.
TC-17
UC-7
Administrator selects Alert
Database Configuration on
configuration screen and
updates location for storing
ADB
Success: If location is updated. Messages with
success will displays.
Failure: Message with system error will display.
TC-18
UC-8
Administrator selects Update
User from configuration screen
Screen with select option displays.
TC-19
UC-8 Administrator selects Update
User Password and enters new
password for the user
Success: If new password is changed, a
message with success wills displays.
Failure: Error message will displays.
TC-20
UC-8
Administrator selects Update
User Profile and enters
parameter for the user
Success: If information is updated, a message
with success wills displays.
Failure: Error message will displays.
TC-21
UC-9
User clicks logout button
Message with logout will displays and only
HTDS login screen will displays. User will not
be able to access any other UI screen except
login screen.
TC-22
UC-10
Administrator selects Create
Profile on Configuration screen
Screen with select option displays.
TC-23
UC-10 Administrator selects Create
User Profile and enters data
Success: Message with success displays.
Failure: a) Mandatory field is empty. b) Same
user profile already exists in database. Error
HTDS Testing and Integration
9
message will displays.
TC-24
UC-11 Agent selects View Data. View Data screen displays.
TC-25
UC-11 Agent clicks on view all data. All the data present in the database are
displayed to the agent
TC-26
UC-11 Agent clicks on data by File Agent is able to select a file, only the data for
selected. No other data are displayed.
TC-27
UC-11 Agent clicks on data by user Agent is able to select a user. Only the data for
the selected user display.
TC-28
UC-11 Agent clicks on data by phone
number
Agent is able to select a phone number. Only
the data for the selected phone number
display.
TC-29
UC-11 Agent clicks on data by victim
name
Agent is able to select a victim name. Only the
data for the selected victim name display.
TC-30
UC-11 Agent clicks on View Data
entry.
Agent is able to select a record ID for data.
Only data for the selected record ID displays.
Table 2: Expected Use Case Testing Results
2.5 Testing Schedule
Date Activity
April 10th-April 24th Module Testing*
April 24th- May 1st Integration Testing*
May 1st-May 8th Finalizing and Prototyping
*Integration occurs throughout Table 3: Testing Schedule
3. Data Sets
3.1 Data Generation Online random/fake name generators were used to generate large lists of female names. These
names are concatenated with randomly generated phone numbers into sample input files.
These input files are has identical features to the input files that users are expected to use in
real environment. The size of data list, name list format and phone number format were
designed differently to mimic realistic scenarios.
Two methods were used to generate phone numbers. Online random/fake phone number
generators were used to generate lists to be incorporated into the large data sets. For the
HTDS Testing and Integration
10
smaller data sets, an in-house Python script (see Appendix 1) was developed to generate data
sets with high phone number repetitions. The frequencies of phone numbers vary from one input
file to another.
3.2 Sample Data Sets
3.3.1 Data Set 1: RhodeIsland.txt
File Name: RhodeIslands.txt
Number of Entries 5,000
Fixed Code 401 xxx xxxx
Name Generator http://random-name-generator.info/
Phone Generator Python Script
Figure 2: Sample from Data Set 1: RhodeIsland.txt
3.3.2 Data Set 2: Massachusetts.txt
File Name: Massachusetts.txt
Number of Entries 2,000
Fixed Code 617-345 xxxx
Name Generator http://listofrandomnames.com
Phone Generator Python Script
Figure 3: Sample from Data Set 2: Massachusetts.txt
HTDS Testing and Integration
11
3.3.3 Data Set 3: Germany.txt
File Name: German.txt
Number of Entries 45,000
Fixed Code No
Name Generator http://www.fakenamegenerator.com/order.php
Phone Generator http://www.fakenamegenerator.com/order.php
Figure 4: Sample from Data Set 3: Germany.txt
3.3.4 Data Set 4: France.txt
File Name: france.txt
Number of Entries 98,000
Fixed Code No
Name Generator http://www.fakenamegenerator.com/order.php
Phone Generator http://www.fakenamegenerator.com/order.php
Figure 5: Sample Data Set 4: France.txt
3.3.5 Data Set 5: Russia.txt
File Name: Russia.txt
Number of Entries
1,000
Fixed Code 499-555-66xx
Name Generator http://www.atlantagamer.org/iGM/RandomNames/
Phone Generator Python Script
HTDS Testing and Integration
12
Figure 6: Sample Data Set 5: Russia.txt
3.3 Random HTDS Data Structure A module was developed to generate random HTDS data structures to be used in the testing
procedures. A copy of the module is available at (5.2 RandomHTDS Testing Module), while a
summary of the main methods is presented in the following table:
Name Type Object Type Random Generator Method
ID Generic Int RandomHTDS.randomID( ) Date Generic Date RandomHTDS.randomDate ( ) Phone Generic String RandomHTDS.randomPhone( ) String Generic String RandomHTDS.randomString( ) String [ ] Generic String [ ] RandomHTDS.randomStringArray(int: Size) filename Generic String RandomHTDS.randomFileName ( ) Color HTDS String RandomHTDS.randomColor( ) Permissions HTDS Boolean [ ] RandomHTDS.randomPermissions ( ) User HTDS User RandomHTDS.randomUser( ) UserProfile HTDS UserProfile RandomHTDS.randomUserProfile( ) Alert HTDS Alert RandomHTDS.randomAlert( ) AlertProfile HTDS AlertProfile RandomHTDS.randomAlertProfile ( ) AlertLog HTDS AlertLog RandomHTDS.randomAlertLog ( ) Data HTDS Data RandomHTDS.randomData ( ) DataLog HTDS DataLog RandomHTDS.randomDataLog ( )
Table 4: Random HTDS Data Structures
4. Testing Results
4.1 Unit Testing Two modules were written using JUnit to perform the unit testing for the HTDS modules. The
AlertTest module, tests the data structures, while the DBConnectorTest module tests the
DBConnector along with the other modules. Both modules are presented in the Appendix.
4.1.1 Results of Unit Testing Using AlertTest Module The following figure shows that the all testing methods has passed the JUnit test procedures.
HTDS Testing and Integration
13
Figure 7: AlertTest JUnit Results
The following figure shows that Errors were caught successfully with clear traceability of the
class and the method that threw the error exception.
Figure 8: AlertTest Error Reporting
HTDS Testing and Integration
14
4.1.2 Results of Unit Testing Using DBConnectorTest Module
Figure 9: DBConnector JUnit Results
4.2 Integration Testing The following Table shows the results of the Integration testing. Each Test case provided in
Section 2.4 is presented along with the testing results.
Test
Case
Use
Case ID Description Testing Result
TC-1 UC-1 Agent enters a valid user name and password Successful
TC-2 UC-1 Agent enters an invalid user name and password Successful
TC-3 UC-2 Agent clicks view alerts Successful
TC-4 UC-2 Agent clicks upload files Successful
TC-5 UC-2 Agent clicks analyze files Successful
TC-6 UC-3 Agent clicks on view all alerts Successful
TC-7 UC-3 Agent clicks on alerts by date Successful
TC-8 UC-3 Agent clicks on alerts by user Successful
TC-9 UC-3 Agent clicks on alerts by phone number Successful
HTDS Testing and Integration
15
TC-10 UC-3 Agent clicks on alerts by victim name Successful
TC-11 UC-4 Agent clicks browse button Successful
TC-12 UC-4 Agent clicks upload button Successful
TC-13 UC-5 Agent clicks the analyzer button and selects data from
ADB Successful
TC-14 UC-5 Agent stores alerts in ADB Successful
TC-15 UC-6 Administrator clicks configuration button Successful
TC-16 UC-6 Admin selects “Add User” and enters username,
password, privileges Successful
TC-17
UC-7
Administrator selects Alert Database Configuration on
configuration screen and updates location for storing
ADB
Not Implemented
TC-18
UC-8
Administrator selects Update User from configuration
screen Successful
TC-19
UC-8 Administrator selects Update User Password and
enters new password for the user Successful
TC-20 UC-8 Admin performs Update User Profile Successful
TC-21 UC-9 User clicks logout button Not Implemented
TC-22 UC-10 Admin selects Create Profile on Configuration screen Successful
TC-23 UC-10 Admin selects Create User Profile and enters data Successful
TC-24 UC-11 Agent selects View Data. Successful
TC-25 UC-11 Agent clicks on view all data. Successful
TC-26 UC-11 Agent clicks on data by File Successful
TC-27 UC-11 Agent clicks on data by user Successful
TC-28 UC-11 Agent clicks on data by phone number Successful
TC-29 UC-11 Agent clicks on data by victim name Successful
TC-30 UC-11 Agent clicks on View Data entry. Successful
Table 5: Integration Testing Results
HTDS Testing and Integration
16
5. Appendices
5.1 Python Random Phone Number Generator # CSC 505 - Spring 2014 # HTDS Project # Random Phone number generator import random numList = ['0','1','2','3','4','5','6','7','8','9'] #random phone numbers including random area code # PN = phone number def generateRandomPN(size,filename): outFile = open(filename,"w") for i in range(size): phoneNum = generateAreaCode()+generateCode(3) + generateCode(4)+'\n' outFile.write(phoneNum) outFile.close() # random phone numbers with same area code def generateRandomPN_FixedAreaCode(size, filename, areacode): outFile = open(filename, "w") for i in range(size): phoneNum = areacode + generateCode(3) + generateCode(4)+'\n' outFile.write(phoneNum) outFile.close() # random phone numbers with fixed area code and fixed 6 digits def generateRandomPN_FixedDigits(size, filename, fixeddigits): outFile = open(filename, "w") for i in range(size): phoneNum = fixeddigits + generateCode(10-len(fixeddigits))+'\n' outFile.write(phoneNum) outFile.close() def generateAreaCode(): firstDigit = numList[random.randint(1,9)] # first digit can't be a '0' secondDigit = numList[random.randint(0,9)] thirdDigit = numList[random.randint(0,9)] return firstDigit+secondDigit+thirdDigit def generateCode(numOfDigits): code = '' for i in range(numOfDigits): code = code + numList[random.randint(0,9)] return code
Figure 10: Python Script for Random Phone Number Generator
5.2 RandomHTDS Testing Module
package HTDSTesting;
HTDS Testing and Integration
17
import htds.Alert; import htds.AlertLog; import htds.AlertProfile; import htds.AlertProfileLog; import htds.User; import htds.UserProfile; import htds.Data; import htds.DataLog; import java.sql.Date; import java.util.Arrays; import java.util.Random; /** * This class generates random data structures for testing purposes * The following structures are supported: * 1- Random ID number 2- Random Phone number 3- Random Color * 4- Random Date 5- Random String 6- Random String Array * 7- Random Alert 8- Random AlertLog 9- Random User * 10- Random UserProfile 11- Random Permissions 12- Random Data * 13- Random DataLog 14- Random File name 15- Random AlertProfile */ public class RandomHTDS { /** * Generates a random integer between 0 and Integer.MAX_VALUE; * @return random positive integer */ public static int randomID(){ return 0 + (int)(Math.random()*Integer.MAX_VALUE);} /** * Generates a phone number as a string of only digits with no additional formatting * @return a string representing a phone number */ public static String randomPhone(){ int randDigit; String phone = ""; for (int i=0;i<9;i++){ randDigit = 0 + (int)(Math.random()*9); phone = phone + Integer.toString(randDigit); } return phone;} /** * Returns one of the following strings representing colors * "Red", "Orange", "Yellow", "Blue", "Green" * @return a string representing one of the 5-scale colors */ public static String randomColor(){ int randIndex = 0 + (int)(Math.random()*4); return AlertProfile.getColors()[randIndex];} /** * return a random object of type Date * @return random Date object */ public static Date randomDate(){ return new Date(randomID());} /** * Generates a character ['a' to 'z'] at random * @return one character at random */ public static char randomCharacter(){ Random r = new Random(); char c = (char)(r.nextInt(26) + 'a'); return c;} /** * This method generates a random String, containing only characters * String length is between 3 to 8 characters chosen randomly
HTDS Testing and Integration
18
* @return random string */ public static String randomString(){ String name = ""; int StringLength = (3 + (int)(Math.random()*8)); for (int i = 0; i<= StringLength;i++) name = name + Character.toString(randomCharacter()); return name;} /** * @param size: number of desired strings * @return an Array of Strings */ public static String[] randomStringArray(int size){ String[] randomStringArray = new String[size]; for (int i=0;i<size;i++) randomStringArray[i] = randomString(); return randomStringArray;} /** * generate an array of integers of size 4, representing thresholds * @return int[] */ public static int[] randomThresholds(){ int[] randomThresholdsArray = new int[5]; randomThresholdsArray[4] = 1 + (int)(Math.random()*3); randomThresholdsArray[3] = 4 + (int)(Math.random()*5); randomThresholdsArray[2] = 5 + (int)(Math.random()*7); randomThresholdsArray[1] = 7 + (int)(Math.random()*9); randomThresholdsArray[0] = 9 + (int)(Math.random()*12); return randomThresholdsArray;} /** * generate an object of type AlertLog * @return: a random object of type AlertLog */ public static AlertLog randomAlertLog(){ return new AlertLog(randomID(), randomID(), randomID(), randomDate(), randomID());} /** * Generates a random Object of type Alert * @return an object of type Alert with random properties */ public static Alert randomAlert(){ return new Alert(randomID(), randomColor(), randomPhone(), randomAlertLog(), randomStringArray(5));} /** * @return an object of type AlertProfileLog with random properties * This function should be used for testing purposes only */ public static AlertProfileLog randomAlertProfileLog(){ return new AlertProfileLog(randomID(), randomID(), "RandomProfile", randomDate());} /** * Generates a random AlertProfile * @return an object of type AlertProfile */ public static AlertProfile randomAlertProfile(){ return new AlertProfile(randomID(),randomThresholds(), "Random", randomAlertProfileLog());} /**
HTDS Testing and Integration
19
* Generates a random UserProfile object * @ return an object of type UserProfile */ public static UserProfile randomUserProfile(){ return new UserProfile(randomID(), "randomProfile", randomPermissions()); } /** * Generates a random permission matrix for a UserProfile * @return an object of type boolean[] */ public static boolean[] randomPermissions(){ boolean [] permissions = new boolean[4]; for (int i=0;i<4;i++) if(randomID()%2 == 0) permissions[i] = true; else permissions[i] = false; return permissions;} /** * Generates a random User * @ return an object of type User */ public static User randomUser(){ return new User(randomID(), randomString(), randomString(), randomString(), randomUserProfile());} /** * Generates a random Data * @return: an object of type Data */ public static Data randomData(){ return new Data(randomID(), randomString(), randomPhone(), randomID());} /** * Generates random filename with extension .txt * return a String * @return */ public static String randomFileName(){ return randomString() + ".txt";} /** * Generates a random DataLog * @return an object of type DataLog */ public static DataLog randomDataLog(){ return new DataLog(randomID(), randomID(), randomFileName(), randomDate());} }
5.3 AlertTest JUnit Module
package HTDSTesting; import htds.Alert; import htds.AlertLog; import htds.AlertProfile; import htds.AlertProfileLog; import htds.Data; import htds.DataLog; import htds.User; import htds.UserProfile; import java.sql.Date; import static org.junit.Assert.*;
HTDS Testing and Integration
20
import org.junit.Test; /** * The AlertTest class is used for unit testing of testing of the HTDS data structures. * The following calsses are tested * 1- Alert 2- AlertLog 3- AlertProfile 4- AlertProfileLog * 5- User 6- UserProfile 7- Data 8- DataLog */ public class AlertTest { //--------------------------------------------------------------------------- /** * Tests the AlertProfileLog class */ @Test public void testAletProfileLogClass(){ //Test Constructors AlertProfileLog log1 = new AlertProfileLog(RandomHTDS.randomID(), RandomHTDS.randomID(), "RandomProfile",RandomHTDS.randomDate()); assertNotNull(log1); AlertProfileLog log2 = RandomHTDS.randomAlertProfileLog(); assertNotNull(log2); AlertProfileLog log3 = new AlertProfileLog(log2); assertNotNull(log3); assertEquals(log3.getID(), log2.getID()); assertEquals(log3.getDescription(), log2.getDescription()); assertEquals(log3.getDate(), log2.getDate()); assertEquals(log3.getUserID(), log2.getUserID()); //Test setting invalid values AlertProfileLog log4 = new AlertProfileLog(-6, RandomHTDS.randomID(), "RandomProfile",RandomHTDS.randomDate()); assertEquals(-1, log4.getID()); AlertProfileLog log5 = new AlertProfileLog(RandomHTDS.randomID(), -3, "RandomProfile",RandomHTDS.randomDate()); assertEquals(-1, log5.getUserID()); AlertProfileLog log7 = new AlertProfileLog(RandomHTDS.randomID(), RandomHTDS.randomID(), "RandomProfile",null); assertNull(log7.getDate()); //Test getters Date date = RandomHTDS.randomDate(); AlertProfileLog log6 = new AlertProfileLog(5, 6, "ProfileTest", date ); assertEquals(5, log6.getID()); assertEquals(6, log6.getUserID()); assertEquals("ProfileTest", log6.getDescription()); assertEquals(date, log6.getDate()); } //-------------------------------------------------------------------------- /** * Tests the AlertProfile Class */ @Test public void testAletProfileClass(){ AlertProfile profile1 = new AlertProfile(RandomHTDS.randomID(),
HTDS Testing and Integration
21
RandomHTDS.randomThresholds(),"RandomProfile",RandomHTDS.randomAlertProfileLog()); assertNotNull(profile1); AlertProfile profile2 = new AlertProfile(profile1); assertNotNull(profile2); AlertProfile profile3 = new AlertProfile(-8, RandomHTDS.randomThresholds(), "RandomProfile",RandomHTDS.randomAlertProfileLog()); assertEquals(-1, profile3 .getID()); int[] wrongThresholds = new int[]{1,2,3}; AlertProfile profile4 = new AlertProfile(RandomHTDS.randomID(),wrongThresholds, "RandomProfile",RandomHTDS.randomAlertProfileLog()); assertNull(profile4.getThresholds()); AlertProfileLog log1 = RandomHTDS.randomAlertProfileLog(); int logID = log1.getID(); int[] thresholds = new int[]{20,15,10,5,1}; AlertProfile profile5 = new AlertProfile(20,thresholds, "RandomProfile", log1); assertEquals(20, profile5.getID()); assertEquals(thresholds, profile5.getThresholds()); assertEquals("RandomProfile", profile5.getDescription()); assertEquals(logID, profile5.getAlertProfileLog().getID()); } //--------------------------------------------------------------------------- /** * Tests the AlertLog Class */ @Test public void testAlertLogClass(){ //test constructors AlertLog log1 = new AlertLog(RandomHTDS.randomID(), RandomHTDS.randomID(), RandomHTDS.randomID(),RandomHTDS.randomDate(), RandomHTDS.randomID()); assertNotNull(log1); AlertLog log2 = new AlertLog(RandomHTDS.randomID(), RandomHTDS.randomID(), RandomHTDS.randomID(),RandomHTDS.randomDate(), RandomHTDS.randomAlertProfile()); assertNotNull(log2); AlertLog log3 = new AlertLog(log2); assertNotNull(log3); AlertLog log4 = new AlertLog(RandomHTDS.randomID(), RandomHTDS.randomUser(), RandomHTDS.randomDataLog(),RandomHTDS.randomDate(), RandomHTDS.randomAlertProfile()); assertNotNull(log4); int invalidID = -10; AlertLog log5 = new AlertLog(invalidID, invalidID,invalidID, null,invalidID); assertEquals(-1,log5.getID()); assertEquals(-1,log5.getUserID()); assertEquals(-1,log5.getAlertProfileID()); assertNull(log5.getDate()); assertEquals(-1, log5.getDataLogID()); } //--------------------------------------------------------------------------- /**
HTDS Testing and Integration
22
* Tests the Alert class */ @Test public void testAlertClass(){ Alert alert1 = new Alert(RandomHTDS.randomID(),RandomHTDS.randomColor(), RandomHTDS.randomPhone(), RandomHTDS.randomAlertLog(), RandomHTDS.randomStringArray(5)); assertNotNull(alert1); Alert alert2 = new Alert(alert1); assertNotNull(alert2); assertEquals(alert2.getID(), alert1.getID()); assertEquals(alert2.getAlertLogID(), alert1.getAlertLogID()); assertEquals(alert2.getColor(), alert1.getColor()); assertEquals(alert2.getFrequency(), alert1.getFrequency()); assertEquals(alert2.getSPN(), alert1.getSPN()); assertEquals(alert2.getVictimNames().toString(), alert1.getVictimNames().toString()); Alert alert3 = new Alert("Red", "5556666", new String[]{"HHH", "JJJ"}); assertNotNull(alert3); String[] invalidVictimNames = new String[]{}; Alert alert4 = new Alert(-15,"Brown","5556666", null, invalidVictimNames); assertEquals(-1,alert4.getID()); assertEquals("", alert4.getColor()); assertNull(alert4.getAlertLog()); assertEquals(invalidVictimNames.toString(),alert4.getVictimNames().toString()); assertEquals("5556666", alert4.getSPN()); } @Test public void testUserProfileClass(){ UserProfile profile1 = new UserProfile(); assertNotNull(profile1); UserProfile profile2 = new UserProfile(RandomHTDS.randomID()); assertNotNull(profile2); UserProfile profile3 = new UserProfile(RandomHTDS.randomID(), RandomHTDS.randomString(), RandomHTDS.randomPermissions()); assertNotNull(profile3); UserProfile profile4 = new UserProfile(profile3); assertNotNull(profile4); assertEquals(profile3.getID(), profile4.getID()); assertEquals(profile3.getProfileName(), profile4.getProfileName()); assertEquals(profile3.getPermissions()[0], profile4.getPermissions()[0]); assertEquals(profile3.getPermissions()[1], profile4.getPermissions()[1]); assertEquals(profile3.getPermissions()[2], profile4.getPermissions()[2]); assertEquals(profile3.getPermissions()[3], profile4.getPermissions()[3]); boolean[] wrongPermissions = new boolean[]{true,true,true}; UserProfile profile5 = new UserProfile(); profile5.setPermissions(wrongPermissions); assertEquals(false, profile5.getPermissions()[0]); assertEquals(false, profile5.getPermissions()[1]);
HTDS Testing and Integration
23
assertEquals(false, profile5.getPermissions()[2]); assertEquals(false, profile5.getPermissions()[3]); UserProfile profile6 = new UserProfile(300, "Testing", new boolean[]{true, false, true, false}); assertEquals(300, profile6.getID()); assertEquals("Testing", profile6.getProfileName()); assertEquals(true, profile6.getPermissions()[0]); assertEquals(false, profile6.getPermissions()[1]); assertEquals(true, profile6.getPermissions()[2]); assertEquals(false, profile6.getPermissions()[3]); UserProfile profile7 = new UserProfile(-20); assertEquals(-1, profile7.getID()); } @Test public void testUserClass(){ User user1 = new User(RandomHTDS.randomID(), RandomHTDS.randomString(), RandomHTDS.randomString(), RandomHTDS.randomString(), RandomHTDS.randomUserProfile()); assertNotNull(user1); } @Test public void testDataClass(){ Data data1 = new Data(); assertNotNull(data1); Data data2 = new Data(RandomHTDS.randomID(), RandomHTDS.randomString(), RandomHTDS.randomPhone(), RandomHTDS.randomID()); assertNotNull(data2); Data data3 = new Data(data2); assertNotNull(data3); assertEquals(data3.getID(), data2.getID()); assertEquals(data3.getDataLogID(), data2.getDataLogID()); assertEquals(data3.getName(), data2.getName()); assertEquals(data3.getPhone(), data2.getPhone()); Data data4 = new Data(-9, "RandomName", "53?27--2342/23", -40); assertEquals(-1, data4.getID()); assertEquals("RandomName", data4.getName()); assertEquals("5327234223", data4.getPhone()); assertEquals(-1, data4.getDataLogID()); } @Test public void testDataLogClass(){ DataLog log1 = new DataLog(RandomHTDS.randomID(), RandomHTDS.randomID(), RandomHTDS.randomFileName(), RandomHTDS.randomDate()); assertNotNull(log1); DataLog log2 = new DataLog(RandomHTDS.randomID(), RandomHTDS.randomUser(), RandomHTDS.randomFileName(), RandomHTDS.randomDate()); assertNotNull(log2); DataLog log3 = new DataLog(log2);
HTDS Testing and Integration
24
assertNotNull(log3); assertEquals(log3.getID(), log2.getID()); assertEquals(log3.getDate(), log2.getDate()); assertEquals(log3.getFileName(), log2.getFileName()); assertEquals(log3.getUserID(), log2.getUserID()); } //--------------------------------------------------------------------------- /** * Main function to executes all testing methods in AlertTest class * @param args: to be left blank */ public static void main(String [ ] args){ AlertTest test = new AlertTest(); test.testAletProfileLogClass(); test.testAletProfileClass(); test.testAlertLogClass(); test.testAlertClass(); test.testDataClass(); test.testDataLogClass(); test.testUserClass(); test.testUserProfileClass(); } }
5.4 DBConnectorTest JUnit Module package HTDSTesting; import static org.junit.Assert.*; import htds.Alert; import htds.AlertLog; import htds.AlertProfile; import htds.Data; import htds.UserProfile; import htds.DBConnector; import htds.User; import java.sql.Date; import org.junit.Test; /** * The DBConnectorTest class is used for testing the functionalities of the DBConnector */ public class DBConnectorTest { DBConnector dbConnector = new DBConnector(); @Test public void testLogin(){ User user = dbConnector.login("agent", "htds2014"); assertNotNull(user); } @Test public void testAddUser(){ boolean[] permission = {true, true, true, true}; UserProfile up = new UserProfile(1, "admin", permission ); User user = new User(1, "unitTest", "unitTest", "unitTest", up); assertTrue(dbConnector.addUser(user)); } @Test public void testDeleteUser(){ User user = new User(1, "unitTest", "unitTest", "unitTest", new UserProfile()); assertTrue(dbConnector.removeUser(user));
HTDS Testing and Integration
25
} @Test public void testUploadFile(){ dbConnector.login("agent", "htds2014"); String filename = "C:\\Users\\Zachary\\Documents\\CSC 505\\RhodeIsland.txt"; assertTrue(dbConnector.uploadFile(filename)); } @Test public void testGetAnalysis(){ assertNotNull(dbConnector.getAnalysis(1)); } @Test public void testUploadAlert(){ @SuppressWarnings("deprecation") AlertLog al = new AlertLog(2, 2, 1, new Date(114,9,2), 1); Alert[] alerts = new Alert[2]; alerts[0] = new Alert(1, "Red", "333585677", al, new String[]{"b"}); alerts[1] = new Alert(2, "Blue", "250452456", al, new String[]{"a"}); assertTrue(dbConnector.uploadAlert(alerts)); } @Test public void testCreateUserProfile(){ UserProfile userProfile = new UserProfile(); boolean[] permissions = {false, false, false, false}; userProfile.setProfileName("UnitTest"); userProfile.setPermissions(permissions); assertTrue(dbConnector.createUserProfile(userProfile)); } @Test public void testCreateAlertProfile(){ dbConnector.login("agent", "htds2014"); int[] th = {50, 40, 30, 20, 10}; AlertProfile alertProfile = new AlertProfile(0, th, "UnitTest", null); assertTrue(dbConnector.createAlertProfile(alertProfile)); } @Test public void testUpdateUserPassword(){ UserProfile profile = new UserProfile(); User user = new User(1, "Administrator", "", "", profile); String password = "htds2014"; assertTrue(dbConnector.updateUserPassword(user, password)); } @Test public void testUpdateUserProfile(){ UserProfile emptyProfile = new UserProfile(); User user = new User(1, "administrator", "Administrator", "", emptyProfile); UserProfile userProfile1 = new UserProfile(1); UserProfile userProfile2 = new UserProfile(2); }
HTDS Testing and Integration
26
@Test public void testGetData(){ Data[] test1 = dbConnector.getData(); assertNotNull(test1); Data data = new Data(); data.setPhone("578229221"); Data[] test2 = dbConnector.getData(data); assertNotNull(test2); int dataLogID = 2; Data[] test3 = dbConnector.getData(dataLogID); assertNotNull(test3); UserProfile userProfile = null; User user = new User(0, "admin", "admin", "password", userProfile); Data[] test4 = dbConnector.getData(user); assertNotNull(test4); Data[] test5 = dbConnector.getData("Genevre Lalonde", DBConnector.VICTIM_NAME); assertNotNull(test5); Data[] test6 = dbConnector.getData("56135060", DBConnector.PHONE_NUMBER); assertNotNull(test6); } @Test public void testGetAlerts(){ Alert[] test1 = dbConnector.getAlerts(); assertNotNull(test1); @SuppressWarnings("deprecation") Alert[] test2 = dbConnector.getAlerts(new Date(114,3,22), new Date(114,3,24)); assertNotNull(test2); UserProfile userProfile = null; User user = new User(0, "agent", "agent", "password", userProfile); Alert[] test3 = dbConnector.getAlerts(user); assertNotNull(test3); int alertProfileID = 1; Alert[] test4 = dbConnector.getAlerts(alertProfileID); assertNotNull(test4); Alert[] test5 = dbConnector.getAlerts("Jeanette Grignon", DBConnector.VICTIM_NAME); assertNotNull(test5); Alert[] test6 = dbConnector.getAlerts("250452456", DBConnector.PHONE_NUMBER); assertNotNull(test6); Alert[] test7 = dbConnector.getAlerts("Red", DBConnector.COLOR); assertNotNull(test7); } }