@@ -34,38 +34,78 @@ public static void closeClient() throws IOException {
3434 }
3535
3636 @ Test
37- public void whenPutCourse_thenCorrect () throws IOException {
37+ public void whenUpdateNonExistentCourse_thenReceiveNotFoundResponse () throws IOException {
3838 HttpPut httpPut = new HttpPut (BASE_URL + "3" );
39- InputStream resourceStream = this .getClass ().getClassLoader ().getResourceAsStream ("course.xml" );
39+ InputStream resourceStream = this .getClass ().getClassLoader ().getResourceAsStream ("non_existent_course.xml" );
40+ httpPut .setEntity (new InputStreamEntity (resourceStream ));
41+ httpPut .setHeader ("Content-Type" , "text/xml" );
42+
43+ HttpResponse response = client .execute (httpPut );
44+ assertEquals (404 , response .getStatusLine ().getStatusCode ());
45+ }
46+
47+ @ Test
48+ public void whenUpdateUnchangedCourse_thenReceiveNotModifiedResponse () throws IOException {
49+ HttpPut httpPut = new HttpPut (BASE_URL + "1" );
50+ InputStream resourceStream = this .getClass ().getClassLoader ().getResourceAsStream ("unchanged_course.xml" );
51+ httpPut .setEntity (new InputStreamEntity (resourceStream ));
52+ httpPut .setHeader ("Content-Type" , "text/xml" );
53+
54+ HttpResponse response = client .execute (httpPut );
55+ assertEquals (304 , response .getStatusLine ().getStatusCode ());
56+ }
57+
58+ @ Test
59+ public void whenUpdateValidCourse_thenReceiveOKResponse () throws IOException {
60+ HttpPut httpPut = new HttpPut (BASE_URL + "2" );
61+ InputStream resourceStream = this .getClass ().getClassLoader ().getResourceAsStream ("changed_course.xml" );
4062 httpPut .setEntity (new InputStreamEntity (resourceStream ));
4163 httpPut .setHeader ("Content-Type" , "text/xml" );
4264
4365 HttpResponse response = client .execute (httpPut );
4466 assertEquals (200 , response .getStatusLine ().getStatusCode ());
4567
46- Course course = getCourse (3 );
47- assertEquals (3 , course .getId ());
68+ Course course = getCourse (2 );
69+ assertEquals (2 , course .getId ());
4870 assertEquals ("Apache CXF Support for RESTful" , course .getName ());
4971 }
72+
73+ @ Test
74+ public void whenCreateConflictStudent_thenReceiveConflictResponse () throws IOException {
75+ HttpPost httpPost = new HttpPost (BASE_URL + "1/students" );
76+ InputStream resourceStream = this .getClass ().getClassLoader ().getResourceAsStream ("conflict_student.xml" );
77+ httpPost .setEntity (new InputStreamEntity (resourceStream ));
78+ httpPost .setHeader ("Content-Type" , "text/xml" );
79+
80+ HttpResponse response = client .execute (httpPost );
81+ assertEquals (409 , response .getStatusLine ().getStatusCode ());
82+ }
5083
5184 @ Test
52- public void whenPostStudent_thenCorrect () throws IOException {
85+ public void whenCreateValidStudent_thenReceiveOKResponse () throws IOException {
5386 HttpPost httpPost = new HttpPost (BASE_URL + "2/students" );
54- InputStream resourceStream = this .getClass ().getClassLoader ().getResourceAsStream ("student .xml" );
87+ InputStream resourceStream = this .getClass ().getClassLoader ().getResourceAsStream ("created_student .xml" );
5588 httpPost .setEntity (new InputStreamEntity (resourceStream ));
5689 httpPost .setHeader ("Content-Type" , "text/xml" );
5790
5891 HttpResponse response = client .execute (httpPost );
5992 assertEquals (200 , response .getStatusLine ().getStatusCode ());
6093
61- Student student = getStudent (2 , 0 );
94+ Student student = getStudent (2 , 3 );
6295 assertEquals (3 , student .getId ());
6396 assertEquals ("Student C" , student .getName ());
6497 }
6598
6699 @ Test
67- public void whenDeleteStudent_thenCorrect () throws IOException {
68- HttpDelete httpDelete = new HttpDelete (BASE_URL + "1/students/0" );
100+ public void whenDeleteInvalidStudent_thenReceiveNotFoundResponse () throws IOException {
101+ HttpDelete httpDelete = new HttpDelete (BASE_URL + "1/students/3" );
102+ HttpResponse response = client .execute (httpDelete );
103+ assertEquals (404 , response .getStatusLine ().getStatusCode ());
104+ }
105+
106+ @ Test
107+ public void whenDeleteValidStudent_thenReceiveOKResponse () throws IOException {
108+ HttpDelete httpDelete = new HttpDelete (BASE_URL + "1/students/1" );
69109 HttpResponse response = client .execute (httpDelete );
70110 assertEquals (200 , response .getStatusLine ().getStatusCode ());
71111
0 commit comments