|
| 1 | +import com.authzed.api.v1.ExperimentalServiceGrpc; |
| 2 | +import com.authzed.api.v1.PermissionsServiceGrpc; |
| 3 | +import com.authzed.api.v1.SchemaServiceGrpc; |
| 4 | +import com.authzed.grpcutil.BearerToken; |
| 5 | +import io.grpc.ManagedChannel; |
| 6 | +import io.grpc.ManagedChannelBuilder; |
| 7 | + |
| 8 | +import java.util.Random; |
| 9 | + |
| 10 | +public class TestClient { |
| 11 | + private static final String tokenPrefix = "tc_test_token"; |
| 12 | + |
| 13 | + public SchemaServiceGrpc.SchemaServiceBlockingStub schemaService; |
| 14 | + public PermissionsServiceGrpc.PermissionsServiceBlockingStub permissionsService; |
| 15 | + public PermissionsServiceGrpc.PermissionsServiceStub asyncPermissionsService; |
| 16 | + public ExperimentalServiceGrpc.ExperimentalServiceBlockingStub experimentalService; |
| 17 | + public TestClient() { |
| 18 | + ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:50051").usePlaintext().build(); |
| 19 | + String token = generateToken(); |
| 20 | + schemaService = SchemaServiceGrpc.newBlockingStub(channel) |
| 21 | + .withCallCredentials(new BearerToken(token)); |
| 22 | + permissionsService = PermissionsServiceGrpc.newBlockingStub(channel) |
| 23 | + .withCallCredentials(new BearerToken(token)); |
| 24 | + asyncPermissionsService = PermissionsServiceGrpc.newStub(channel) |
| 25 | + .withCallCredentials(new BearerToken(token)); |
| 26 | + experimentalService = ExperimentalServiceGrpc.newBlockingStub(channel) |
| 27 | + .withCallCredentials(new BearerToken(token)); |
| 28 | + } |
| 29 | + public String generateToken() { |
| 30 | + Random random = new Random(); |
| 31 | + return tokenPrefix + random.nextInt(1000); |
| 32 | + } |
| 33 | +} |
0 commit comments