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

chore: Add HttpJson CRUD Showcase tests #1589

Merged
merged 16 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion showcase/gapic-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<artifactId>fmt-maven-plugin</artifactId>
<version>2.9</version>
<configuration>
<filesNamePattern>(IT.*\.java)|(.*Test.java)</filesNamePattern>
<filesNamePattern>(IT.*\.java)|(.*Test.java)|(TestClientInitializer.java)</filesNamePattern>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we are explicitly specifying the files in the fmt plugin, because we want to exclude some files? @mpeddada1

</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.FieldMask;
import com.google.showcase.v1beta1.CreateUserRequest;
import com.google.showcase.v1beta1.DeleteUserRequest;
import com.google.showcase.v1beta1.EchoSettings;
import com.google.showcase.v1beta1.IdentityClient;
import com.google.showcase.v1beta1.IdentitySettings;
import com.google.showcase.v1beta1.ListUsersRequest;
import com.google.showcase.v1beta1.ListUsersResponse;
import com.google.showcase.v1beta1.UpdateUserRequest;
import com.google.showcase.v1beta1.User;
import java.io.IOException;
import java.security.GeneralSecurityException;
import com.google.showcase.v1beta1.it.util.TestClientInitializer;
import java.util.Arrays;
import java.util.List;
import org.junit.After;
Expand All @@ -49,22 +44,15 @@ public class ITCrud {
.setAge(25)
.build();

private IdentityClient grpcClient;
private IdentityClient httpJsonClient;

@Before
public void setup() throws GeneralSecurityException, IOException {
public void setup() throws Exception {
// Create gRPC IdentityClient
grpcClient = TestClientInitializer.createGrpcIdentityClient();
// Create HttpJson IdentityClient
IdentitySettings httpJsonIdentitySettings =
IdentitySettings.newHttpJsonBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultHttpJsonTransportProviderBuilder()
.setHttpTransport(
new NetHttpTransport.Builder().doNotValidateCertificate().build())
.setEndpoint("http://localhost:7469")
.build())
.build();
httpJsonClient = IdentityClient.create(httpJsonIdentitySettings);
httpJsonClient = TestClientInitializer.createHttpJsonIdentityClient();

// Ensure an empty state before each run
cleanupData(httpJsonClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,61 @@
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.showcase.v1beta1.EchoClient;
import com.google.showcase.v1beta1.EchoSettings;
import com.google.showcase.v1beta1.IdentityClient;
import com.google.showcase.v1beta1.IdentitySettings;
import io.grpc.ManagedChannelBuilder;

public class TestClientInitializer {

public static EchoClient createGrpcEchoClient() throws Exception {
EchoSettings grpcEchoSettings =
EchoSettings.newBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultGrpcTransportProviderBuilder()
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.build())
public static EchoClient createGrpcEchoClient() throws Exception {
EchoSettings grpcEchoSettings =
EchoSettings.newBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultGrpcTransportProviderBuilder()
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.build())
.build();
return EchoClient.create(grpcEchoSettings);
}

.build();
return EchoClient.create(grpcEchoSettings);
}
public static EchoClient createHttpJsonEchoClient() throws Exception {
EchoSettings httpJsonEchoSettings =
EchoSettings.newHttpJsonBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultHttpJsonTransportProviderBuilder()
.setHttpTransport(
new NetHttpTransport.Builder().doNotValidateCertificate().build())
.setEndpoint("http://localhost:7469")
.build())
.build();
return EchoClient.create(httpJsonEchoSettings);
}

public static EchoClient createHttpJsonEchoClient() throws Exception{
EchoSettings httpJsonEchoSettings =
EchoSettings.newHttpJsonBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultHttpJsonTransportProviderBuilder()
.setHttpTransport(
new NetHttpTransport.Builder().doNotValidateCertificate().build())
.setEndpoint("http://localhost:7469")
.build())
.build();
return EchoClient.create(httpJsonEchoSettings);
}
public static IdentityClient createGrpcIdentityClient() throws Exception {
IdentitySettings grpcIdentitySettings =
IdentitySettings.newHttpJsonBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
IdentitySettings.defaultGrpcTransportProviderBuilder()
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.build())
.build();
return IdentityClient.create(grpcIdentitySettings);
}

public static IdentityClient createHttpJsonIdentityClient() throws Exception {
IdentitySettings httpjsonIdentitySettings =
IdentitySettings.newHttpJsonBuilder()
.setCredentialsProvider(NoCredentialsProvider.create())
.setTransportChannelProvider(
EchoSettings.defaultHttpJsonTransportProviderBuilder()
.setHttpTransport(
new NetHttpTransport.Builder().doNotValidateCertificate().build())
.setEndpoint("http://localhost:7469")
.build())
.build();
return IdentityClient.create(httpjsonIdentitySettings);
}
}