use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.
the class EndpointServiceClientTest method listEndpointsTest.
@Test
public void listEndpointsTest() throws Exception {
Endpoint responsesElement = Endpoint.newBuilder().build();
ListEndpointsResponse expectedResponse = ListEndpointsResponse.newBuilder().setNextPageToken("").addAllEndpoints(Arrays.asList(responsesElement)).build();
mockEndpointService.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListEndpointsPagedResponse pagedListResponse = client.listEndpoints(parent);
List<Endpoint> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getEndpointsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockEndpointService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListEndpointsRequest actualRequest = ((ListEndpointsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.
the class JobServiceClientTest method listCustomJobsTest.
@Test
public void listCustomJobsTest() throws Exception {
CustomJob responsesElement = CustomJob.newBuilder().build();
ListCustomJobsResponse expectedResponse = ListCustomJobsResponse.newBuilder().setNextPageToken("").addAllCustomJobs(Arrays.asList(responsesElement)).build();
mockJobService.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListCustomJobsPagedResponse pagedListResponse = client.listCustomJobs(parent);
List<CustomJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getCustomJobsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockJobService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListCustomJobsRequest actualRequest = ((ListCustomJobsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.
the class FeaturestoreServiceClientTest method searchFeaturesTest.
@Test
public void searchFeaturesTest() throws Exception {
Feature responsesElement = Feature.newBuilder().build();
SearchFeaturesResponse expectedResponse = SearchFeaturesResponse.newBuilder().setNextPageToken("").addAllFeatures(Arrays.asList(responsesElement)).build();
mockFeaturestoreService.addResponse(expectedResponse);
LocationName location = LocationName.of("[PROJECT]", "[LOCATION]");
SearchFeaturesPagedResponse pagedListResponse = client.searchFeatures(location);
List<Feature> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getFeaturesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockFeaturestoreService.getRequests();
Assert.assertEquals(1, actualRequests.size());
SearchFeaturesRequest actualRequest = ((SearchFeaturesRequest) actualRequests.get(0));
Assert.assertEquals(location.toString(), actualRequest.getLocation());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.aiplatform.v1beta1.LocationName in project google-cloud-java by googleapis.
the class TranslateSnippetsBeta method translateTextWithGlossary.
// [END translate_get_glossary_beta]
/**
* Translates a given text using a glossary.
*
* @param projectId - Id of the project.
* @param location - location name.
* @param name - Glossary name.
* @param text - Text to be translated. e.g. "Hello World!"
* @param sourceLanguageCode - Language code of text. e.g. "en"
* @param targetLanguageCode - Language code for translation. e.g. "sr"
*/
// [START translate_translate_text_with_glossary_beta]
static TranslateTextResponse translateTextWithGlossary(String projectId, String location, String name, String text, String sourceLanguageCode, String targetLanguageCode) {
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
TranslateTextGlossaryConfig translateTextGlossaryConfig = TranslateTextGlossaryConfig.newBuilder().setGlossary(glossaryName.toString()).build();
TranslateTextRequest translateTextRequest = TranslateTextRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setSourceLanguageCode(sourceLanguageCode).setTargetLanguageCode(targetLanguageCode).addContents(text).setGlossaryConfig(translateTextGlossaryConfig).build();
// Call the API
TranslateTextResponse response = translationServiceClient.translateText(translateTextRequest);
System.out.format("Translated text: %s", response.getGlossaryTranslationsList().get(0).getTranslatedText());
return response;
} catch (Exception e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.aiplatform.v1beta1.LocationName in project google-cloud-java by googleapis.
the class TranslateSnippetsBeta method detectLanguageOfText.
// [END translate_list_language_names_beta]
/**
* Detects the language of a given text.
*
* @param projectId - Id of the project.
* @param location - location name.
* @param text - Text for detection
*/
// [START translate_detect_language_beta]
static DetectLanguageResponse detectLanguageOfText(String projectId, String location, String text) {
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
DetectLanguageRequest detectLanguageRequest = DetectLanguageRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setContent(text).build();
// Call the API
DetectLanguageResponse response = translationServiceClient.detectLanguage(detectLanguageRequest);
System.out.format("Detected Language Code: %s", response.getLanguages(0).getLanguageCode());
return response;
} catch (Exception e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
Aggregations