Search in sources :

Example 6 with ListRecommendationsPagedResponse

use of com.google.cloud.recommender.v1beta1.RecommenderClient.ListRecommendationsPagedResponse in project java-recommender by googleapis.

the class RecommenderClientTest method listRecommendationsTest2.

@Test
public void listRecommendationsTest2() throws Exception {
    Recommendation responsesElement = Recommendation.newBuilder().build();
    ListRecommendationsResponse expectedResponse = ListRecommendationsResponse.newBuilder().setNextPageToken("").addAllRecommendations(Arrays.asList(responsesElement)).build();
    mockRecommender.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListRecommendationsPagedResponse pagedListResponse = client.listRecommendations(parent);
    List<Recommendation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getRecommendationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockRecommender.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListRecommendationsRequest actualRequest = ((ListRecommendationsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListRecommendationsPagedResponse(com.google.cloud.recommender.v1.RecommenderClient.ListRecommendationsPagedResponse) Test(org.junit.Test)

Example 7 with ListRecommendationsPagedResponse

use of com.google.cloud.recommender.v1beta1.RecommenderClient.ListRecommendationsPagedResponse in project java-recommender by googleapis.

the class RecommenderClientTest method listRecommendationsTest.

@Test
public void listRecommendationsTest() throws Exception {
    Recommendation responsesElement = Recommendation.newBuilder().build();
    ListRecommendationsResponse expectedResponse = ListRecommendationsResponse.newBuilder().setNextPageToken("").addAllRecommendations(Arrays.asList(responsesElement)).build();
    mockRecommender.addResponse(expectedResponse);
    RecommenderName parent = RecommenderName.ofProjectLocationRecommenderName("[PROJECT]", "[LOCATION]", "[RECOMMENDER]");
    ListRecommendationsPagedResponse pagedListResponse = client.listRecommendations(parent);
    List<Recommendation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getRecommendationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockRecommender.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListRecommendationsRequest actualRequest = ((ListRecommendationsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListRecommendationsPagedResponse(com.google.cloud.recommender.v1.RecommenderClient.ListRecommendationsPagedResponse) Test(org.junit.Test)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)6 Test (org.junit.Test)6 ListRecommendationsPagedResponse (com.google.cloud.recommender.v1.RecommenderClient.ListRecommendationsPagedResponse)4 ListRecommendationsPagedResponse (com.google.cloud.recommender.v1beta1.RecommenderClient.ListRecommendationsPagedResponse)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 PermissionDeniedException (com.google.api.gax.rpc.PermissionDeniedException)1 ListRecommendationsRequest (com.google.cloud.recommender.v1beta1.ListRecommendationsRequest)1 Recommendation (com.google.cloud.recommender.v1beta1.Recommendation)1 RecommenderClient (com.google.cloud.recommender.v1beta1.RecommenderClient)1