@Test public void getByteArrayPrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder() .setBinaryResult(ByteString.copyFrom("SomeBinary".getBytes())).build(); assertArrayEquals("SomeBinary".getBytes(Charset.forName("UTF-8")), (byte[]) protobufSerializationService.decode(encodedValue)); }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue value = 2;</code> */ public Builder mergeValue(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue value) { if (valueBuilder_ == null) { if (value_ != null) { value_ = org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.newBuilder(value_).mergeFrom(value).buildPartial(); } else { value_ = value; } onChanged(); } else { valueBuilder_.mergeFrom(value); } return this; } /**
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue key = 1;</code> */ public Builder mergeKey(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue value) { if (keyBuilder_ == null) { if (key_ != null) { key_ = org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.newBuilder(key_).mergeFrom(value).buildPartial(); } else { key_ = value; } onChanged(); } else { keyBuilder_.mergeFrom(value); } return this; } /**
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue result = 1;</code> */ public Builder mergeResult(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue value) { if (resultBuilder_ == null) { if (result_ != null) { result_ = org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.newBuilder(result_).mergeFrom(value).buildPartial(); } else { result_ = value; } onChanged(); } else { resultBuilder_.mergeFrom(value); } return this; } /**
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue oldValue = 1;</code> */ public Builder mergeOldValue(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue value) { if (oldValueBuilder_ == null) { if (oldValue_ != null) { oldValue_ = org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.newBuilder(oldValue_).mergeFrom(value).buildPartial(); } else { oldValue_ = value; } onChanged(); } else { oldValueBuilder_.mergeFrom(value); } return this; } /**
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue arguments = 3;</code> */ public Builder mergeArguments(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue value) { if (argumentsBuilder_ == null) { if (arguments_ != null) { arguments_ = org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.newBuilder(arguments_).mergeFrom(value).buildPartial(); } else { arguments_ = value; } onChanged(); } else { argumentsBuilder_.mergeFrom(value); } return this; } /**
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue arguments = 3;</code> */ public Builder mergeArguments(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue value) { if (argumentsBuilder_ == null) { if (arguments_ != null) { arguments_ = org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.newBuilder(arguments_).mergeFrom(value).buildPartial(); } else { arguments_ = value; } onChanged(); } else { argumentsBuilder_.mergeFrom(value); } return this; } /**
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue key = 1;</code> */ public Builder mergeKey(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue value) { if (keyBuilder_ == null) { if (key_ != null) { key_ = org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValue.newBuilder(key_).mergeFrom(value).buildPartial(); } else { key_ = value; } onChanged(); } else { keyBuilder_.mergeFrom(value); } return this; } /**
@Test(expected = DecodingException.class) public void processThrowsExceptionWhenUnableToDecode() throws Exception { String exceptionText = "unsupported type!"; Exception exception = new DecodingException(exceptionText); ProtobufSerializationService serializationServiceStub = mock(ProtobufSerializationService.class); when(serializationServiceStub.decode(any())).thenThrow(exception); BasicTypes.EncodedValue encodedKey = BasicTypes.EncodedValue.newBuilder() .setJsonObjectResult("{\"someKey\":\"someValue\"}").build(); PutRequestOperationHandler operationHandler = new PutRequestOperationHandler(); BasicTypes.EncodedValue testValue = serializationService.encode(TEST_VALUE); BasicTypes.Entry testEntry = ProtobufUtilities.createEntry(encodedKey, testValue); RegionAPI.PutRequest putRequest = ProtobufRequestUtilities.createPutRequest(TEST_REGION, testEntry).getPutRequest(); operationHandler.process(serializationServiceStub, putRequest, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); }
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
@Test(expected = DecodingException.class) public void processThrowsExceptionWhenUnableToDecodeRequest() throws Exception { Exception exception = new DecodingException("error finding codec for type"); ProtobufSerializationService serializationServiceStub = mock(ProtobufSerializationService.class); when(serializationServiceStub.decode(any())).thenThrow(exception); BasicTypes.EncodedValue encodedKey = BasicTypes.EncodedValue.newBuilder() .setJsonObjectResult("{\"someKey\":\"someValue\"}").build(); RegionAPI.GetRequest getRequest = ProtobufRequestUtilities.createGetRequest(TEST_REGION, encodedKey).getGetRequest(); operationHandler.process(serializationServiceStub, getRequest, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); }
@Test(expected = DecodingException.class) public void processThrowsExceptionWhenUnableToDecodeRequest() throws Exception { Exception exception = new DecodingException("error finding codec for type"); ProtobufSerializationService serializationServiceStub = mock(ProtobufSerializationService.class); when(serializationServiceStub.decode(any())).thenThrow(exception); BasicTypes.EncodedValue encodedKey = BasicTypes.EncodedValue.newBuilder() .setJsonObjectResult("{\"someKey\":\"someValue\"}").build(); RegionAPI.RemoveRequest removeRequest = ProtobufRequestUtilities.createRemoveRequest(TEST_REGION, encodedKey).getRemoveRequest();; operationHandler.process(serializationServiceStub, removeRequest, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); }
@Test public void getStringPrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder().setStringResult("SomeString").build(); assertEquals("SomeString", protobufSerializationService.decode(encodedValue)); }
@Test public void getFloatPrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder().setFloatResult(1).build(); assertEquals(1f, protobufSerializationService.decode(encodedValue)); }
@Test public void getBytePrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder().setByteResult(1).build(); assertEquals((byte) 1, protobufSerializationService.decode(encodedValue)); }
@Test public void getLongPrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder().setLongResult(1).build(); assertEquals(1l, protobufSerializationService.decode(encodedValue)); }
@Test public void getBooleanPrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder().setBooleanResult(true).build(); assertEquals(true, protobufSerializationService.decode(encodedValue)); }
@Test public void getShortPrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder().setShortResult(1).build(); assertEquals((short) 1, protobufSerializationService.decode(encodedValue)); }
@Test public void getDoublePrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder().setDoubleResult(1.0).build(); assertEquals(1.0, protobufSerializationService.decode(encodedValue)); }
@Test public void getIntPrimitiveFromEncodedValue() throws Exception { BasicTypes.EncodedValue.Builder builder = BasicTypes.EncodedValue.newBuilder(); BasicTypes.EncodedValue encodedValue = builder.setIntResult(1).build(); assertEquals(1, protobufSerializationService.decode(encodedValue)); }