forked from eclipse-rdf4j/rdf4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue eclipse-rdf4j#80: Allow a null RDFFormat to upload.
Allow a null RDFFormat to upload, and pass it through as an untyped entity. Signed-off-by: Joseph Walton <joe@kafsemo.org>
- Loading branch information
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
core/http/client/src/test/java/org/eclipse/rdf4j/http/client/SesameSessionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Eclipse RDF4J contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.http.client; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.HttpVersion; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.client.protocol.HttpClientContext; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.message.BasicStatusLine; | ||
import org.eclipse.rdf4j.http.protocol.UnauthorizedException; | ||
import org.eclipse.rdf4j.repository.RepositoryException; | ||
import org.eclipse.rdf4j.rio.RDFFormat; | ||
import org.eclipse.rdf4j.rio.RDFParseException; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
|
||
public class SesameSessionTest { | ||
|
||
@Rule | ||
public MockitoRule wireMocks = MockitoJUnit.rule(); | ||
|
||
@Mock | ||
HttpClient client; | ||
|
||
@Mock | ||
ExecutorService executorService; | ||
|
||
@InjectMocks | ||
SesameSession session; | ||
|
||
@Test | ||
public void passingNullForDataFormatSendsAnUntypedEntity() | ||
throws UnauthorizedException, RDFParseException, RepositoryException, IOException | ||
{ | ||
session.setQueryURL("http://localhost/"); | ||
|
||
HttpResponse response = mock(HttpResponse.class); | ||
|
||
when(response.getEntity()).thenReturn(new StringEntity("")); | ||
when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "Ok")); | ||
|
||
ArgumentCaptor<HttpUriRequest> captor = ArgumentCaptor.forClass(HttpUriRequest.class); | ||
|
||
when(client.execute(Mockito.<HttpUriRequest> any(), Mockito.<HttpClientContext> any())).thenReturn( | ||
response); | ||
|
||
InputStream contents = new ByteArrayInputStream(new byte[0]); | ||
String baseURI = "http://localhost/"; | ||
RDFFormat dataFormat = null; | ||
boolean overwrite = true; | ||
boolean preserveNodeIds = true; | ||
|
||
session.upload(contents, baseURI, dataFormat, overwrite, preserveNodeIds); | ||
|
||
verify(client).execute(captor.capture(), Mockito.<HttpClientContext> any()); | ||
|
||
assertThat(captor.getValue(), org.hamcrest.Matchers.instanceOf(HttpPut.class)); | ||
HttpPut put = (HttpPut)captor.getValue(); | ||
assertThat(put.getEntity().getContentType(), Matchers.nullValue()); | ||
} | ||
} |