public static LocationName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "LocationName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("location")); }
public static List<LocationName> parseList(List<String> formattedStrings) { List<LocationName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }
public static String format(String project, String location) { return newBuilder().setProject(project).setLocation(location).build().toString(); }
@Test @SuppressWarnings("all") public void listJobsTest() { String nextPageToken = ""; Job jobsElement = Job.newBuilder().build(); List<Job> jobs = Arrays.asList(jobsElement); ListJobsResponse expectedResponse = ListJobsResponse.newBuilder().setNextPageToken(nextPageToken).addAllJobs(jobs).build(); mockCloudScheduler.addResponse(expectedResponse); LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); ListJobsPagedResponse pagedListResponse = client.listJobs(parent); List<Job> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getJobsList().get(0), resources.get(0)); List<GeneratedMessageV3> actualRequests = mockCloudScheduler.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListJobsRequest actualRequest = (ListJobsRequest) actualRequests.get(0); Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
public static List<String> toStringList(List<LocationName> values) { List<String> list = new ArrayList<String>(values.size()); for (LocationName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public LocationName build() { return new LocationName(this); } }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
public static LocationName of(String project, String location) { return newBuilder().setProject(project).setLocation(location).build(); }
@Test @SuppressWarnings("all") public void createJobTest() { JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); String description = "description-1724546052"; String schedule = "schedule-697920873"; String timeZone = "timeZone36848094"; Job expectedResponse = Job.newBuilder() .setName(name.toString()) .setDescription(description) .setSchedule(schedule) .setTimeZone(timeZone) .build(); mockCloudScheduler.addResponse(expectedResponse); LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); Job job = Job.newBuilder().build(); Job actualResponse = client.createJob(parent, job); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockCloudScheduler.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateJobRequest actualRequest = (CreateJobRequest) actualRequests.get(0); Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); Assert.assertEquals(job, actualRequest.getJob()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * Lists jobs. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); * for (Job element : cloudSchedulerClient.listJobs(parent).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. * <p>The location name. For example: `projects/PROJECT_ID/locations/LOCATION_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListJobsPagedResponse listJobs(LocationName parent) { ListJobsRequest request = ListJobsRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); return listJobs(request); }
.setParent(parent == null ? null : parent.toString()) .setJob(job) .build();
@Test @SuppressWarnings("all") public void listJobsExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); client.listJobs(parent); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void createJobExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); Job job = Job.newBuilder().build(); client.createJob(parent, job); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }