ProtobufUtils { public static Descriptors.Descriptor buildDescriptor(String filePath, String messageName) { Descriptors.FileDescriptor fileDescriptor = parseFileDescriptor(filePath); Descriptors.Descriptor result = null; for (Descriptors.Descriptor descriptor : fileDescriptor.getMessageTypes()) { if (descriptor.getName().equals(messageName)) { result = descriptor; } } if (null == result) { throw new RuntimeException("Unable to locate Message '" + messageName + "' in Descriptor"); } return result; }  static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema); static StructType buildSchema(Descriptors.Descriptor descriptor); static Descriptors.Descriptor buildDescriptor(String filePath, String messageName); static Descriptors.Descriptor buildDescriptor(String filePath); static boolean isGzipped(InputStream inputStream);  }
@Test public void buildDescriptorSingleNoDefinedName() { Descriptors.Descriptor descriptor = ProtobufUtils.buildDescriptor( ProtobufUtils.class.getResource(SINGLE_EXAMPLE).getPath()); Assert.assertThat(descriptor.getName(), is("SingleExample")); Assert.assertThat(descriptor.getFields().size(), is(24)); Assert.assertThat(descriptor.getEnumTypes().size(), is(1)); Assert.assertThat(descriptor.getNestedTypes().size(), is(2)); }
@Test public void buildDescriptorSingleDefinedName() { Descriptors.Descriptor descriptor = ProtobufUtils.buildDescriptor( ProtobufUtils.class.getResource(SINGLE_EXAMPLE).getPath(), "SingleExample"); Assert.assertThat(descriptor.getName(), is("SingleExample")); Assert.assertThat(descriptor.getFields().size(), is(24)); Assert.assertThat(descriptor.getEnumTypes().size(), is(1)); Assert.assertThat(descriptor.getNestedTypes().size(), is(2)); }
@Test public void buildDescriptorMultipleNoDefinedName() { thrown.expect(RuntimeException.class); ProtobufUtils.buildDescriptor(ProtobufUtils.class.getResource(MULTIPLE_EXAMPLE).getPath()); }
@Test public void buildDescriptorMultipleInvalidName() { thrown.expect(RuntimeException.class); ProtobufUtils.buildDescriptor(ProtobufUtils.class.getResource(MULTIPLE_EXAMPLE).getPath(), "None"); }
@Test public void buildDescriptorMultipleDefinedName() { Descriptors.Descriptor descriptor = ProtobufUtils.buildDescriptor( ProtobufUtils.class.getResource(MULTIPLE_EXAMPLE).getPath(), "MultipleExample"); Assert.assertThat(descriptor.getName(), is("MultipleExample")); Assert.assertThat(descriptor.getFields().size(), is(1)); Assert.assertThat(descriptor.getFields().get(0).getType(), is(Descriptors.FieldDescriptor.Type.MESSAGE)); }