Search in sources :

Example 11 with Key

use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method migrateKeyTest.

@Test
public void migrateKeyTest() throws Exception {
    Key expectedResponse = Key.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setTestingOptions(TestingOptions.newBuilder().build()).build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    MigrateKeyRequest request = MigrateKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
    Key actualResponse = client.migrateKey(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    MigrateKeyRequest actualRequest = ((MigrateKeyRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) MigrateKeyRequest(com.google.recaptchaenterprise.v1.MigrateKeyRequest) HashMap(java.util.HashMap) Key(com.google.recaptchaenterprise.v1.Key) Test(org.junit.Test)

Example 12 with Key

use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method getMetricsTest2.

@Test
public void getMetricsTest2() throws Exception {
    Metrics expectedResponse = Metrics.newBuilder().setName(MetricsName.of("[PROJECT]", "[KEY]").toString()).setStartTime(Timestamp.newBuilder().build()).addAllScoreMetrics(new ArrayList<ScoreMetrics>()).addAllChallengeMetrics(new ArrayList<ChallengeMetrics>()).build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    String name = "name3373707";
    Metrics actualResponse = client.getMetrics(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetMetricsRequest actualRequest = ((GetMetricsRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ChallengeMetrics(com.google.recaptchaenterprise.v1.ChallengeMetrics) ScoreMetrics(com.google.recaptchaenterprise.v1.ScoreMetrics) Metrics(com.google.recaptchaenterprise.v1.Metrics) ScoreMetrics(com.google.recaptchaenterprise.v1.ScoreMetrics) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetMetricsRequest(com.google.recaptchaenterprise.v1.GetMetricsRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 13 with Key

use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method getMetricsTest.

@Test
public void getMetricsTest() throws Exception {
    Metrics expectedResponse = Metrics.newBuilder().setName(MetricsName.of("[PROJECT]", "[KEY]").toString()).setStartTime(Timestamp.newBuilder().build()).addAllScoreMetrics(new ArrayList<ScoreMetrics>()).addAllChallengeMetrics(new ArrayList<ChallengeMetrics>()).build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    MetricsName name = MetricsName.of("[PROJECT]", "[KEY]");
    Metrics actualResponse = client.getMetrics(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetMetricsRequest actualRequest = ((GetMetricsRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ChallengeMetrics(com.google.recaptchaenterprise.v1.ChallengeMetrics) ScoreMetrics(com.google.recaptchaenterprise.v1.ScoreMetrics) Metrics(com.google.recaptchaenterprise.v1.Metrics) ScoreMetrics(com.google.recaptchaenterprise.v1.ScoreMetrics) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetMetricsRequest(com.google.recaptchaenterprise.v1.GetMetricsRequest) MetricsName(com.google.recaptchaenterprise.v1.MetricsName) Test(org.junit.Test)

Example 14 with Key

use of com.google.recaptchaenterprise.v1.Key in project grpc-gcp-java by GoogleCloudPlatform.

the class DataStoreChecksumClient method simpleLookup.

private static void simpleLookup(DatastoreBlockingStub stub, String projectId) {
    PathElement pathElement = PathElement.newBuilder().setKind("Person").setName("weiranf").build();
    Key key = Key.newBuilder().addPath(pathElement).build();
    LookupRequest lookupRequest = LookupRequest.newBuilder().setProjectId(projectId).addKeys(key).build();
    LookupResponse lookupResponse = stub.lookup(lookupRequest);
    if (lookupResponse.getFoundCount() > 0) {
        System.out.println("ENTITY FOUND:");
        Entity entity = lookupResponse.getFound(0).getEntity();
        Map<String, Value> map = entity.getPropertiesMap();
        for (Map.Entry<String, Value> entry : map.entrySet()) {
            System.out.printf("%s => %s\n", entry.getKey(), entry.getValue().getStringValue());
        }
    } else {
        System.out.println("NO ENTITY FOUND!");
    }
}
Also used : Entity(com.google.datastore.v1.Entity) PathElement(com.google.datastore.v1.Key.PathElement) Value(com.google.datastore.v1.Value) LookupResponse(com.google.datastore.v1.LookupResponse) Map(java.util.Map) Key(com.google.datastore.v1.Key) LookupRequest(com.google.datastore.v1.LookupRequest)

Example 15 with Key

use of com.google.recaptchaenterprise.v1.Key in project beam by apache.

the class DataStoreReadWriteIT method testWriteRead_viaCoreBeamIO.

@Test
public void testWriteRead_viaCoreBeamIO() {
    String projectId = options.getProject();
    Key ancestor = makeKey(KIND, UUID.randomUUID().toString()).build();
    Key itemKey = makeKey(ancestor, KIND, UUID.randomUUID().toString()).setPartitionId(PartitionId.newBuilder().setProjectId(projectId).build()).build();
    Row testWriteRow = Row.withSchema(SOURCE_SCHEMA).addValues(itemKey.toByteArray(), "4000").build();
    writePipeline.apply(Create.of(testWriteRow).withRowSchema(SOURCE_SCHEMA)).apply(RowToEntity.create("__key__", KIND)).apply(DatastoreIO.v1().write().withProjectId(projectId));
    writePipeline.run().waitUntilFinish();
    Query.Builder query = Query.newBuilder();
    query.addKindBuilder().setName(KIND);
    query.setFilter(makeFilter("__key__", Operator.EQUAL, makeValue(itemKey)));
    DatastoreV1.Read read = DatastoreIO.v1().read().withProjectId(projectId).withQuery(query.build());
    PCollection<Row> rowsRead = readPipeline.apply(read).apply(EntityToRow.create(SOURCE_SCHEMA, "__key__"));
    PAssert.that(rowsRead).containsInAnyOrder(testWriteRow);
    readPipeline.run().waitUntilFinish();
}
Also used : Query(com.google.datastore.v1.Query) DatastoreV1(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1) ByteString(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.ByteString) Row(org.apache.beam.sdk.values.Row) EntityToRow(org.apache.beam.sdk.io.gcp.datastore.EntityToRow) Key(com.google.datastore.v1.Key) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)27 Key (com.google.datastore.v1.Key)17 AbstractMessage (com.google.protobuf.AbstractMessage)12 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)11 Key (com.google.recaptchaenterprise.v1.Key)10 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)8 Entity (com.google.datastore.v1.Entity)7 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)7 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)7 Mutation (com.google.datastore.v1.Mutation)5 ArrayList (java.util.ArrayList)5 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 GetKeyRequest (com.google.recaptchaenterprise.v1.GetKeyRequest)4 Key (com.google.recaptchaenterprise.v1beta1.Key)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 HashMap (java.util.HashMap)4 Query (com.google.datastore.v1.Query)3 DeleteKeyRequest (com.google.recaptchaenterprise.v1.DeleteKeyRequest)3 GetMetricsRequest (com.google.recaptchaenterprise.v1.GetMetricsRequest)3 Metrics (com.google.recaptchaenterprise.v1.Metrics)3