Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable java-notification integration test #8742

Merged
merged 16 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ fi

function setup_cloud() {
gcloud config set project "$GOOGLE_CLOUD_PROJECT"
time (
terraform -version &&
source ./.cloud/helpers/init.sh "$1" &&
source ./.cloud/helpers/plan.sh "$1" &&
source ./.cloud/helpers/apply.sh &&
source ./.cloud/helpers/populate-env.sh
)

terraform -version &&
source ./.cloud/helpers/init.sh "$1" &&
source ./.cloud/helpers/plan.sh "$1" &&
source ./.cloud/helpers/apply.sh &&
source ./.cloud/helpers/populate-env.sh

destroy() {
arguments=$?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.rpc.FailedPreconditionException;
import com.google.cloud.ServiceOptions;
import com.google.cloud.notification.Notification;
import com.google.cloud.notification.NotificationImpl.DefaultNotificationFactory;
Expand All @@ -33,9 +34,8 @@
import com.google.iam.v1.Binding;
import com.google.iam.v1.Policy;
import com.google.pubsub.v1.ProjectTopicName;
import io.grpc.StatusRuntimeException;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand All @@ -45,14 +45,12 @@
import java.util.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

public class ITSystemTest {

private static RemoteStorageHelper remoteStorageHelper;
private static TopicAdminClient topicAdminClient;
private static Notification notificationService;
private static Storage storageService;
Expand All @@ -69,9 +67,8 @@ public class ITSystemTest {
@Rule public Timeout globalTimeout = Timeout.seconds(300);

@BeforeClass
public static void beforeClass()
throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
remoteStorageHelper = RemoteStorageHelper.create();
public static void beforeClass() throws IOException {
RemoteStorageHelper remoteStorageHelper = RemoteStorageHelper.create();
topicAdminClient = TopicAdminClient.create();
storageService = remoteStorageHelper.getOptions().getService();
notificationService = new DefaultNotificationFactory().create(storageService);
Expand All @@ -95,7 +92,6 @@ private String formatForTest(String resourceName) {
return resourceName + "-" + NAME_SUFFIX;
}

@Ignore
@Test
public void testNotifications() {
// Use Pubsub to create a Topic.
Expand All @@ -109,9 +105,15 @@ public void testNotifications() {
.setRole("roles/pubsub.publisher")
.addMembers(STORAGE_SERVICE_AGENT)
.build();
Policy newPolicy =
topicAdminClient.setIamPolicy(
topic.toString(), policy.toBuilder().addBindings(binding).build());
Policy modifiedPolicy = policy.toBuilder().addBindings(binding).build();
Policy newPolicy;
try {
newPolicy = topicAdminClient.setIamPolicy(topic.toString(), modifiedPolicy);
} catch (StatusRuntimeException | FailedPreconditionException ex) {
System.out.println(
"Failed setIamPolicy request for " + topic.toString() + " : " + modifiedPolicy);
throw ex;
}
assertTrue(newPolicy.getBindingsList().contains(binding));

String permissionName = "pubsub.topics.get";
Expand Down