12
12
import net .apnic .rdap .conformance .responsetest .NotStatusCode ;
13
13
import net .apnic .rdap .conformance .Utils ;
14
14
15
+ import org .apache .http .Header ;
15
16
import org .apache .http .HttpResponse ;
16
17
import org .apache .http .HttpRequest ;
17
18
24
25
final public class Link implements Test {
25
26
private String url ;
26
27
private Result proto ;
28
+ private String expectedContentType ;
27
29
private Context context = null ;
28
30
private HttpResponse httpResponse = null ;
29
31
private Throwable throwable = null ;
@@ -34,11 +36,14 @@ final public class Link implements Test {
34
36
*
35
37
* @param argUrl a {@link java.lang.String} object.
36
38
* @param argProto a {@link net.apnic.rdap.conformance.Result} object.
39
+ * @param argExpectedContentType a {@link java.lang.String} object.
37
40
*/
38
41
public Link (final String argUrl ,
39
- final Result argProto ) {
42
+ final Result argProto ,
43
+ final String argExpectedContentType ) {
40
44
url = argUrl ;
41
45
proto = argProto ;
46
+ expectedContentType = argExpectedContentType ;
42
47
}
43
48
44
49
/** {@inheritDoc} */
@@ -81,9 +86,19 @@ public boolean run() {
81
86
context .addResult (r );
82
87
ResponseTest sc = new NotStatusCode (0 );
83
88
boolean scres = sc .run (context , proto , httpResponse );
84
- if (!scres ) {
85
- return false ;
89
+
90
+ if (expectedContentType != null ) {
91
+ Header contentType =
92
+ httpResponse .getFirstHeader ("Content-Type" );
93
+ boolean res = contentType .getValue ().equals (expectedContentType );
94
+
95
+ Result r2 = new Result (proto );
96
+ r2 .setCode ("response" );
97
+ r2 .setStatus (res ? Status .Success : Status .Warning );
98
+ r2 .setInfo ("link content type matches received content type" );
99
+ context .addResult (r2 );
86
100
}
87
- return true ;
101
+
102
+ return scres ;
88
103
}
89
104
}
0 commit comments