-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,911 changed files
with
118,301 additions
and
120,816 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
java-accessapproval/samples/snippets/src/main/java/accessapproval/Quickstart.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,48 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package accessapproval; | ||
|
||
// [START accessapproval_quickstart] | ||
import com.google.cloud.accessapproval.v1.AccessApprovalAdminClient; | ||
import com.google.cloud.accessapproval.v1.ApprovalRequest; | ||
import java.io.IOException; | ||
|
||
public class Quickstart { | ||
|
||
public void quickstart() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String projectId = "your-project-id"; | ||
quickstart(projectId); | ||
} | ||
|
||
public void quickstart(String projectId) throws IOException { | ||
try (AccessApprovalAdminClient client = AccessApprovalAdminClient.create()) { | ||
String parent = "projects/" + projectId; | ||
AccessApprovalAdminClient.ListApprovalRequestsPagedResponse response = | ||
client.listApprovalRequests(parent); | ||
int total = 0; | ||
for (ApprovalRequest request : response.iterateAll()) { | ||
System.out.println(request.getName()); | ||
total++; | ||
} | ||
if (total == 0) { | ||
System.out.println("No approval requests found"); | ||
} | ||
} | ||
} | ||
} | ||
// [END accessapproval_quickstart] |
45 changes: 45 additions & 0 deletions
45
java-accessapproval/samples/snippets/src/test/java/accessapproval/QuickstartIT.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,45 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package accessapproval; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.google.cloud.testing.junit4.StdOutCaptureRule; | ||
import com.google.common.base.Strings; | ||
import java.io.IOException; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class QuickstartIT { | ||
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); | ||
|
||
@Rule public StdOutCaptureRule stdOutCap = new StdOutCaptureRule(); | ||
|
||
@BeforeClass | ||
public static void beforeAll() throws Exception { | ||
Assert.assertFalse("missing GOOGLE_CLOUD_PROJECT", Strings.isNullOrEmpty(PROJECT_ID)); | ||
} | ||
|
||
@Test | ||
public void testQuickstart() throws IOException { | ||
Quickstart quickstart = new Quickstart(); | ||
quickstart.quickstart(PROJECT_ID); | ||
assertEquals("No approval requests found\n", stdOutCap.getCapturedOutputAsUtf8String()); | ||
} | ||
} |
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
Oops, something went wrong.