Skip to content

Commit 0bcf292

Browse files
committed
[feature/nro-profile] Check link content type (fixes #31).
1 parent 5c2a5a7 commit 0bcf292

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/main/java/net/apnic/rdap/conformance/attributetest/Link.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ public boolean run(final Context context, final Result proto,
4949
Result nr2 = new Result(nr);
5050
nr2.addNode("value");
5151
context.submitTest(new net.apnic.rdap.conformance.test.common.Link(
52-
value, nr2
52+
value, nr2, null
5353
));
5454
}
5555

56+
String type = Utils.castToString(data.get("type"));
5657
String href = Utils.getStringAttribute(context, nr, "href",
5758
Status.Failure, data);
5859
if (href == null) {
@@ -61,7 +62,7 @@ public boolean run(final Context context, final Result proto,
6162
Result nr2 = new Result(nr);
6263
nr2.addNode("href");
6364
context.submitTest(new net.apnic.rdap.conformance.test.common.Link(
64-
href, nr2
65+
href, nr2, type
6566
));
6667
}
6768

src/main/java/net/apnic/rdap/conformance/test/common/Link.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.apnic.rdap.conformance.responsetest.NotStatusCode;
1313
import net.apnic.rdap.conformance.Utils;
1414

15+
import org.apache.http.Header;
1516
import org.apache.http.HttpResponse;
1617
import org.apache.http.HttpRequest;
1718

@@ -24,6 +25,7 @@
2425
final public class Link implements Test {
2526
private String url;
2627
private Result proto;
28+
private String expectedContentType;
2729
private Context context = null;
2830
private HttpResponse httpResponse = null;
2931
private Throwable throwable = null;
@@ -34,11 +36,14 @@ final public class Link implements Test {
3436
*
3537
* @param argUrl a {@link java.lang.String} object.
3638
* @param argProto a {@link net.apnic.rdap.conformance.Result} object.
39+
* @param argExpectedContentType a {@link java.lang.String} object.
3740
*/
3841
public Link(final String argUrl,
39-
final Result argProto) {
42+
final Result argProto,
43+
final String argExpectedContentType) {
4044
url = argUrl;
4145
proto = argProto;
46+
expectedContentType = argExpectedContentType;
4247
}
4348

4449
/** {@inheritDoc} */
@@ -81,9 +86,19 @@ public boolean run() {
8186
context.addResult(r);
8287
ResponseTest sc = new NotStatusCode(0);
8388
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);
86100
}
87-
return true;
101+
102+
return scres;
88103
}
89104
}

0 commit comments

Comments
 (0)