com.google.common.truth.extensions.proto.ProtoTruth Java Examples
The following examples show how to use
com.google.common.truth.extensions.proto.ProtoTruth.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryResponseToProtoTest.java From rejoiner with Apache License 2.0 | 6 votes |
@Test public void getReferenceNameShouldReturnCorrectValueForMessages() { ProtoTruth.assertThat( QueryResponseToProto.buildMessage( TestProto.Proto1.getDefaultInstance(), ImmutableMap.of( "id", "abc", "intField", 123, "testProto", ImmutableMap.of("innerId", "abc_inner", "enums", ImmutableList.of("FOO"))))) .isEqualTo( Proto1.newBuilder() .setId("abc") .setIntField(123) .setTestProto( Proto2.newBuilder() .setInnerId("abc_inner") .addEnumsValue(Proto2.TestEnum.FOO_VALUE)) .build()); }
Example #2
Source File: GqlInputConverterTest.java From rejoiner with Apache License 2.0 | 6 votes |
@Test public void inputConverterShouldFillProtoBuf() { GqlInputConverter inputConverter = GqlInputConverter.newBuilder().add(TestProto.getDescriptor().getFile()).build(); Message protoBuf = inputConverter.createProtoBuf( Proto1.getDescriptor(), Proto1.newBuilder(), ImmutableMap.of( "id", "id", "intField", 123, "testProto", ImmutableMap.of("innerId", "1"))); ProtoTruth.assertThat(protoBuf) .isEqualTo( Proto1.newBuilder() .setId("id") .setIntField(123) .setTestProto(Proto2.newBuilder().setInnerId("1").build()) .build()); }
Example #3
Source File: HyperLogLogPlusPlusTest.java From zetasketch with Apache License 2.0 | 5 votes |
@Test public void serializeToBytes() throws Exception { HyperLogLogPlusPlus<Integer> aggregator = hllBuilder.buildForIntegers(); aggregator.add(1); aggregator.add(2); aggregator.add(3); AggregatorStateProto actual = AggregatorStateProto.parseFrom(aggregator.serializeToByteArray(), EXTENSIONS); // Don't worry about the exact value for data, the golden tests cover that. ProtoTruth.assertThat( ValueType.forStandardType(DefaultOpsType.Id.UINT32) .copyToBuilder( AggregatorStateProto.newBuilder() .setType(AggregatorType.HYPERLOGLOG_PLUS_UNIQUE) .setEncodingVersion(2) .setNumValues(3) .setExtension( HllplusUnique.hyperloglogplusUniqueState, HyperLogLogPlusUniqueStateProto.newBuilder() .setPrecisionOrNumBuckets(15) .setSparsePrecisionOrNumBuckets(25) .setSparseSize(3) .setData(ByteString.EMPTY) .build())) .build()) .ignoringFieldDescriptors( HyperLogLogPlusUniqueStateProto.getDescriptor().findFieldByName("sparse_data")) .ignoringFieldAbsence() .isEqualTo(actual); assertTrue(actual.getExtension(HllplusUnique.hyperloglogplusUniqueState).hasSparseData()); }
Example #4
Source File: HyperLogLogPlusPlusTest.java From zetasketch with Apache License 2.0 | 5 votes |
@Test public void serializeToByteString() throws Exception { HyperLogLogPlusPlus<Integer> aggregator = hllBuilder.buildForIntegers(); aggregator.add(1); aggregator.add(2); aggregator.add(3); AggregatorStateProto actual = AggregatorStateProto.parseFrom(aggregator.serializeToByteString(), EXTENSIONS); // Don't worry about the exact value for data, the golden tests cover that. ProtoTruth.assertThat( ValueType.forStandardType(DefaultOpsType.Id.UINT32) .copyToBuilder( AggregatorStateProto.newBuilder() .setType(AggregatorType.HYPERLOGLOG_PLUS_UNIQUE) .setEncodingVersion(2) .setNumValues(3) .setExtension( HllplusUnique.hyperloglogplusUniqueState, HyperLogLogPlusUniqueStateProto.newBuilder() .setPrecisionOrNumBuckets(15) .setSparsePrecisionOrNumBuckets(25) .setSparseSize(3) .setData(ByteString.EMPTY) .build())) .build()) .ignoringFieldDescriptors( HyperLogLogPlusUniqueStateProto.getDescriptor().findFieldByName("sparse_data")) .ignoringFieldAbsence() .isEqualTo(actual); assertTrue(actual.getExtension(HllplusUnique.hyperloglogplusUniqueState).hasSparseData()); }
Example #5
Source File: HyperLogLogPlusPlusTest.java From zetasketch with Apache License 2.0 | 5 votes |
@Test public void serializeToProto() { HyperLogLogPlusPlus<Integer> aggregator = hllBuilder.buildForIntegers(); aggregator.add(1); aggregator.add(2); aggregator.add(3); AggregatorStateProto actual = aggregator.serializeToProto(); // Don't worry about the exact value for data, the golden tests cover that. ProtoTruth.assertThat( ValueType.forStandardType(DefaultOpsType.Id.UINT32) .copyToBuilder( AggregatorStateProto.newBuilder() .setType(AggregatorType.HYPERLOGLOG_PLUS_UNIQUE) .setEncodingVersion(2) .setNumValues(3) .setExtension( HllplusUnique.hyperloglogplusUniqueState, HyperLogLogPlusUniqueStateProto.newBuilder() .setPrecisionOrNumBuckets(15) .setSparsePrecisionOrNumBuckets(25) .setSparseSize(3) .setData(ByteString.EMPTY) .build())) .build()) .ignoringFieldDescriptors( HyperLogLogPlusUniqueStateProto.getDescriptor().findFieldByName("sparse_data")) .ignoringFieldAbsence() .isEqualTo(actual); assertTrue(actual.getExtension(HllplusUnique.hyperloglogplusUniqueState).hasSparseData()); }
Example #6
Source File: ExecutionResultToProtoAsyncTest.java From rejoiner with Apache License 2.0 | 5 votes |
@Test public void toProtoExecutionResultShouldReturnData() throws ExecutionException, InterruptedException { CompletableFuture<ProtoExecutionResult<Proto1>> executionResultCompletableFuture = ExecutionResultToProtoAsync.toProtoExecutionResult( Proto1.getDefaultInstance(), CompletableFuture.completedFuture( ExecutionResultImpl.newExecutionResult() .data( ImmutableMap.of( "id", "abc", "intField", 123, "testProto", ImmutableMap.of( "innerId", "abc_inner", "enums", ImmutableList.of("FOO")))) .build())); ProtoTruth.assertThat(executionResultCompletableFuture.get().message()) .isEqualTo( Proto1.newBuilder() .setId("abc") .setIntField(123) .setTestProto( Proto2.newBuilder() .setInnerId("abc_inner") .addEnumsValue(Proto2.TestEnum.FOO_VALUE)) .build()); Truth.assertThat(executionResultCompletableFuture.get().errors()).isEmpty(); }
Example #7
Source File: ProtobufExt.java From titus-control-plane with Apache License 2.0 | 5 votes |
/** * Deep comparison between two protobuf {@link Message entities}, including nested entities. The two messages *must* * be of the same type (i.e.: {@code getDescriptorForType()} must return the same {@code Descriptor} for both). * * @return an @{@link Optional} {@link String} report of the differences, {@link Optional#empty()} if none are found. * @throws IllegalArgumentException when both messages are not of the same type * @throws NullPointerException when any of the messages are <tt>null</tt> */ public static <T extends Message> Optional<String> diffReport(T one, T other) { ErrorCollector collector = new ErrorCollector(); new TestVerb(collector) .about(ProtoTruth.protos()) .that(other) .named(one.getDescriptorForType().getName()) .reportingMismatchesOnly() .isEqualTo(one); return collector.getFailure(); }
Example #8
Source File: ExecutionResultToProtoAsyncTest.java From rejoiner with Apache License 2.0 | 4 votes |
@Test public void toProtoExecutionResultShouldReturnDataAndError() throws ExecutionException, InterruptedException { ExceptionWhileDataFetching exceptionWhileDataFetching = new ExceptionWhileDataFetching( ExecutionPath.rootPath(), new RuntimeException("hello world"), new SourceLocation(10, 20)); CompletableFuture<ProtoExecutionResult<Proto1>> executionResultCompletableFuture = ExecutionResultToProtoAsync.toProtoExecutionResult( Proto1.getDefaultInstance(), CompletableFuture.completedFuture( ExecutionResultImpl.newExecutionResult() .data( ImmutableMap.of( "id", "abc", "intField", 123, "testProto", ImmutableMap.of( "innerId", "abc_inner", "enums", ImmutableList.of("FOO")))) .addError(exceptionWhileDataFetching) .build())); ProtoTruth.assertThat(executionResultCompletableFuture.get().message()) .isEqualTo( Proto1.newBuilder() .setId("abc") .setIntField(123) .setTestProto( Proto2.newBuilder() .setInnerId("abc_inner") .addEnumsValue(Proto2.TestEnum.FOO_VALUE)) .build()); ProtoTruth.assertThat(executionResultCompletableFuture.get().errors()) .containsExactly( GraphqlError.newBuilder() .setMessage("Exception while fetching data () : hello world") .addLocations( com.google.api.graphql.SourceLocation.newBuilder().setLine(10).setColumn(20)) .setType(ErrorType.DATA_FETCHING_EXCEPTION) .build()); }