use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.
the class TestStandardResultCodec method testInit.
@Test
public void testInit() {
Assert.assertNotNull(standardResultCodec);
ProtobufField[] protobufFieldArray = new ProtobufField[5];
FieldElement rawType = null;
FieldType type = FieldType.STRING;
ProtobufField p = new ProtobufField(rawType, type);
protobufFieldArray[0] = p;
Type[] types = new Type[1];
types[0] = Integer.TYPE;
Mockito.when(schema.getSchemaType()).thenReturn(FORMAT_NAME_PROTOBUF);
Mockito.when(schema.getRootType()).thenReturn(Mockito.mock(ProtobufMessage.class));
Mockito.when(schema.getRootType().getFieldCount()).thenReturn(1);
Mockito.when(schema.getRootType().fields()).thenReturn(Arrays.asList(protobufFieldArray));
Assert.assertNull(standardResultCodec.reader);
Assert.assertNull(standardResultCodec.writer);
standardResultCodec.init(schema, types);
Assert.assertNotNull(standardResultCodec.reader);
Assert.assertNotNull(standardResultCodec.writer);
}
use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.
the class TestParamSerializer method testSerialize.
@Test
public void testSerialize() {
boolean status = true;
Assert.assertNotNull(paramSerializer);
String[] stringArray = new String[1];
stringArray[0] = "abc";
ProtobufGenerator obj = null;
try {
obj = new ProtobufGenerator(Mockito.mock(IOContext.class), 2, Mockito.mock(ObjectCodec.class), Mockito.mock(OutputStream.class));
} catch (IOException exce) {
}
Assert.assertNotNull(obj);
new MockUp<ProtobufGenerator>() {
@Mock
public void writeStartObject() throws IOException {
}
ProtobufSchema protobufSchema = new ProtobufSchema(null, null);
@Mock
public ProtobufSchema getSchema() {
return protobufSchema;
}
};
ProtobufMessage protobufMessage = new ProtobufMessage(null, null);
new MockUp<ProtobufSchema>() {
@Mock
public ProtobufMessage getRootType() {
return protobufMessage;
}
};
List<ProtobufField> listProtobufField = new ArrayList<ProtobufField>();
listProtobufField.add(Mockito.mock(ProtobufField.class));
new MockUp<ProtobufMessage>() {
@Mock
public Iterable<ProtobufField> fields() {
return listProtobufField;
}
};
new MockUp<JsonGenerator>() {
@Mock
public void writeObjectField(String fieldName, Object pojo) throws IOException {
}
};
new MockUp<ProtobufGenerator>() {
@Mock
public void writeEndObject() throws IOException {
}
};
try {
paramSerializer.serialize(stringArray, obj, Mockito.mock(SerializerProvider.class));
} catch (JsonProcessingException e) {
status = false;
} catch (IOException e) {
status = false;
}
Assert.assertTrue(status);
}
use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project java-chassis by ServiceComb.
the class ResultSerializer method serialize.
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
gen.writeStartObject();
ProtobufGenerator protobufGenerator = (ProtobufGenerator) gen;
ProtobufField field = protobufGenerator.getSchema().getRootType().firstField();
gen.writeObjectField(field.name, value);
gen.writeEndObject();
}
use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project incubator-servicecomb-java-chassis by apache.
the class TestResultFieldCodec method testInit.
@Test
public void testInit() {
Assert.assertNotNull(resultFieldCodec);
ProtobufField[] protobufFieldArray = new ProtobufField[5];
FieldElement rawType = null;
FieldType type = FieldType.STRING;
ProtobufField p = new ProtobufField(rawType, type);
protobufFieldArray[0] = p;
Type[] types = new Type[10];
types[0] = Integer.TYPE;
Mockito.when(schema.getRootType()).thenReturn(Mockito.mock(ProtobufMessage.class));
Mockito.when(schema.getRootType().getFieldCount()).thenReturn(1);
Mockito.when(schema.getRootType().fields()).thenReturn(Arrays.asList(protobufFieldArray));
Assert.assertNull(resultFieldCodec.reader);
Assert.assertNull(resultFieldCodec.writer);
resultFieldCodec.init(schema, types);
Assert.assertNotNull(resultFieldCodec.reader);
Assert.assertNotNull(resultFieldCodec.writer);
}
use of com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField in project incubator-servicecomb-java-chassis by apache.
the class TestStandardResultCodec method testInit.
@Test
public void testInit() {
Assert.assertNotNull(standardResultCodec);
ProtobufField[] protobufFieldArray = new ProtobufField[5];
FieldElement rawType = null;
FieldType type = FieldType.STRING;
ProtobufField p = new ProtobufField(rawType, type);
protobufFieldArray[0] = p;
Type[] types = new Type[1];
types[0] = Integer.TYPE;
Mockito.when(schema.getSchemaType()).thenReturn(FORMAT_NAME_PROTOBUF);
Mockito.when(schema.getRootType()).thenReturn(Mockito.mock(ProtobufMessage.class));
Mockito.when(schema.getRootType().getFieldCount()).thenReturn(1);
Mockito.when(schema.getRootType().fields()).thenReturn(Arrays.asList(protobufFieldArray));
Assert.assertNull(standardResultCodec.reader);
Assert.assertNull(standardResultCodec.writer);
standardResultCodec.init(schema, types);
Assert.assertNotNull(standardResultCodec.reader);
Assert.assertNotNull(standardResultCodec.writer);
}
Aggregations