Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 085bc32

Browse files
committed
Merge pull request #829 from couchbase/feature/issue_249_router_accept
Fixed #249 - request non json attachment with Header 'Accept: applica…
2 parents 44616f7 + 7e67605 commit 085bc32

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/androidTest/java/com/couchbase/lite/RouterTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,46 @@ public void testDocWithAttachment() throws IOException {
134134
//https://github.com/couchbase/couchbase-lite-android-core/issues/12
135135
//content_type becomes null for attachments in responses, should be as set in Content-Type
136136
String contentTypeField = (String) attachmentResult.get("content_type");
137-
;
138137
assertTrue(attachmentResult.containsKey("content_type"));
139138
assertNotNull(contentTypeField);
140139

140+
// no Accept
141141
URLConnection conn = sendRequest("GET", "/db/docWithAttachment/inline.txt", null, null);
142142
String contentType = conn.getHeaderField("Content-Type");
143143
assertNotNull(contentType);
144144
assertTrue(contentType.contains("text/plain"));
145-
146145
StringWriter writer = new StringWriter();
147146
InputStream is = conn.getInputStream();
148147
IOUtils.copy(is, writer, "UTF-8");
149148
is.close();
150149
String responseString = writer.toString();
151150
assertTrue(responseString.contains(inlineTextString));
151+
writer.close();
152+
153+
// With Accept: text/plain
154+
Map<String, String> headers = new HashMap<>();
155+
headers.put("Accept", "text/plain");
156+
conn = sendRequest("GET", "/db/docWithAttachment/inline.txt", headers, null);
157+
contentType = conn.getHeaderField("Content-Type");
158+
assertNotNull(contentType);
159+
assertTrue(contentType.contains("text/plain"));
160+
writer = new StringWriter();
161+
is = conn.getInputStream();
162+
IOUtils.copy(is, writer, "UTF-8");
163+
is.close();
164+
responseString = writer.toString();
165+
assertTrue(responseString.contains(inlineTextString));
166+
writer.close();
167+
168+
// With Accept: application/json
169+
headers.put("Accept", "application/json");
170+
conn = sendRequest("GET", "/db/docWithAttachment/inline.txt", headers, null);
171+
assertEquals(Status.NOT_ACCEPTABLE, conn.getResponseCode());
172+
is = conn.getInputStream();
173+
Map<String, Object> body = Manager.getObjectMapper().readValue(is, Map.class);
174+
is.close();
175+
assertEquals(406, body.get("status"));
176+
assertEquals("not_acceptable", body.get("error"));
152177
}
153178

154179
private Map<String, Object> valueMapWithRev(String revId) {

0 commit comments

Comments
 (0)