-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathClientServerUtilityTest.java
More file actions
115 lines (98 loc) · 4.61 KB
/
ClientServerUtilityTest.java
File metadata and controls
115 lines (98 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package client;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class ClientServerUtilityTest {
String mockData = "ENTS/1.0 Request\r\nfileName\r\nintegrityValue\r\n";
ClientServerUtility clientServerUtilityObj;
/*
* Create new ClientServerUtility object before every test method
*/
@Before
public void setUp() throws Exception {
clientServerUtilityObj = new ClientServerUtility();
}
@Test
public void testConstructedObject() {
//Testing if the above constructed object is not null
assertNotNull(clientServerUtilityObj);
}// end of testConstructedObject()
/*
* messageInBytesShouldReturnMessageInBytes()
* This test checks if the message is converted to bytes.
*/
@Test
public void messageInBytesShouldReturnMessageInBytes() {
assertArrayEquals(mockData.getBytes(), clientServerUtilityObj.messageInBytes(mockData));
}//end of messageInBytesShouldReturnMessageInBytes()
/*
* The next 5 methods tests isFileNameSyntaxCorrect() method.
*/
/*
* isFileNameSyntaxCorrectShouldReturnTrue()
* This test checks if the name of the requested file has the correct syntax
*/
@Test
public void isFileNameSyntaxCorrectShouldReturnTrue() {
String fileName = "directors_message.txt";
assertTrue(clientServerUtilityObj.isFileNameSyntaxCorrect(fileName, "request"));
}// end of isFileNameSyntaxCorrectShouldReturnTrue()
/*
* fileNameWithoutExtensionShouldThrowException()
* This test checks if the name of the requested file has the correct syntax.
* The file name has no extension. Hence it should throw an exception.
*/
@Test (expected = IllegalArgumentException.class)
public void fileNameWithoutExtensionShouldThrowException() {
String fileName = "directors_message";
assertFalse(clientServerUtilityObj.isFileNameSyntaxCorrect(fileName, "request"));
}// end of fileNameWithoutExtensionShouldThrowException()
/*
* fileNameWithSpecialCharacterShouldThrowException()
* This test checks if the name of the requested file has the correct syntax.
* The file name has special characters. Hence it should throw an exception.
*/
@Test (expected = IllegalArgumentException.class)
public void fileNameWithSpecialCharacterShouldThrowException() {
String fileName = "$$$$directors_message@@@@@.txt";
assertFalse(clientServerUtilityObj.isFileNameSyntaxCorrect(fileName, "request"));
}//end of fileNameWithSpecialCharacterShouldThrowException()
/*
* fileNameDoesNotStartWithAlphabetsShouldThrowException()
* This test checks if the name of the requested file has the correct syntax.
* The file name does not start with alphabets. Hence it should throw an exception.
*/
@Test (expected = IllegalArgumentException.class)
public void fileNameDoesNotStartWithAlphabetsShouldThrowException() {
String fileName = "1234directors_message.txt";
assertFalse(clientServerUtilityObj.isFileNameSyntaxCorrect(fileName, "request"));
}// end of fileNameDoesNotStartWithAlphabetsShouldThrowException()
/*
* extensionHasSpecialCharactersShouldThrowException()
* This test checks if the name of the requested file has the correct syntax.
* The extension should be alphanumeric, but here it contains special characters. Hence it should throw an exception.
*/
@Test (expected = IllegalArgumentException.class)
public void extensionHasSpecialCharactersShouldThrowException() {
String fileName = "directors_message.@@@txt";
assertFalse(clientServerUtilityObj.isFileNameSyntaxCorrect(fileName, "request"));
}// end of extensionHasSpecialCharactersShouldThrowException()
/*
* getIntegrityCheckValueShouldReturnIntegrityValueAsString()
* This test checks if the returned integrity value matches the expected integrity value for the gives message.
*/
@Test
public void getIntegrityCheckValueShouldReturnIntegrityValueAsString() {
String mockDataWithoutIntegrityValue = "ENTS/1.0 Request\r\nfileName\r\n"; //We calculate integrity value for a message without the integrity field.
assertEquals("11482", clientServerUtilityObj.getIntegrityCheckValue(mockDataWithoutIntegrityValue));
}//end of getIntegrityCheckValueShouldReturnIntegrityValueAsString()
/*
* isIntegrityValueOfMessageCorrectShouldReturnTrue()
* This test checks if the integrity value of the "request" is correct.
*/
@Test
public void isIntegrityValueOfRequestMessageCorrectShouldReturnTrue() {
String mockDataWithIntegrityValue = "ENTS/1.0 Request\r\nfileName\r\n11482\r\n";
assertTrue(clientServerUtilityObj.isIntegrityValueOfMessageCorrect(mockDataWithIntegrityValue, "request"));
}//end of isIntegrityValueOfRequestMessageCorrectShouldReturnTrue()
}//end of test class ClientServerUtilityTest