use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method addDocumentFromInputStreamIsSuccessful.
@Test
public void addDocumentFromInputStreamIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(createDocResp));
String myDocumentJson = "{\"field\":\"value\"}";
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
builder.file(documentStream);
builder.filename("test_file");
builder.metadata(myMetadata.toString());
DocumentAccepted response = discoveryService.addDocument(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(DOCS1_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(createDocResp, response);
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method createTrainingExampleIsSuccessful.
@Test
public void createTrainingExampleIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(createTrainingExampleResp));
CreateTrainingExampleOptions.Builder builder = new CreateTrainingExampleOptions.Builder(environmentId, collectionId, queryId);
builder.documentId(documentId);
builder.relevance(0);
TrainingExample response = discoveryService.createTrainingExample(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING2_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(createTrainingExampleResp, response);
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method federatedQueryNoticesIsSuccessful.
@Test
public void federatedQueryNoticesIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(queryNoticesResp));
FederatedQueryNoticesOptions.Builder builder = new FederatedQueryNoticesOptions.Builder(environmentId, new ArrayList<>(Arrays.asList(collectionId)));
QueryNoticesResponse response = discoveryService.federatedQueryNotices(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(Q4_PATH, request.getPath());
assertEquals(GET, request.getMethod());
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method addDocumentFromInputStreamWithFileNameAndMediaTypeIsSuccessful.
@Test
public void addDocumentFromInputStreamWithFileNameAndMediaTypeIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(createDocResp));
String fileName = "MyFileName";
String myDocumentJson = "{\"field\":\"value\"}";
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
builder.filename("test_file");
builder.metadata(myMetadata.toString());
DocumentAccepted response = discoveryService.addDocument(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(DOCS1_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(createDocResp, response);
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifier method createClassifier.
/**
* Create classifier.
*
* Sends data to create and train a classifier and returns information about the new classifier.
*
* @param createClassifierOptions the {@link CreateClassifierOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Classifier}
*/
public ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions) {
Validator.notNull(createClassifierOptions, "createClassifierOptions cannot be null");
String[] pathSegments = { "v1/classifiers" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
RequestBody trainingMetadataBody = RequestUtils.inputStreamBody(createClassifierOptions.metadata(), "application/json");
multipartBuilder.addFormDataPart("training_metadata", createClassifierOptions.metadataFilename(), trainingMetadataBody);
RequestBody trainingDataBody = RequestUtils.inputStreamBody(createClassifierOptions.trainingData(), "text/csv");
multipartBuilder.addFormDataPart("training_data", createClassifierOptions.trainingDataFilename(), trainingDataBody);
builder.body(multipartBuilder.build());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class));
}
Aggregations