embulk-filter-protobuf 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ package org.embulk.filter.protobuf;
2
+
3
+ import org.embulk.EmbulkTestRuntime;
4
+ import org.embulk.config.ConfigException;
5
+ import org.embulk.config.ConfigLoader;
6
+ import org.embulk.config.ConfigSource;
7
+ import org.embulk.filter.protobuf.ProtobufFilterPlugin.PluginTask;
8
+ import org.embulk.spi.Exec;
9
+ import org.embulk.spi.Schema;
10
+ import org.embulk.spi.SchemaConfigException;
11
+ import org.embulk.spi.type.Types;
12
+
13
+ import org.junit.Before;
14
+ import org.junit.Rule;
15
+ import org.junit.Test;
16
+ import org.junit.rules.ExpectedException;
17
+
18
+ import java.io.File;
19
+
20
+ public class TestProtobufFilterPlugin
21
+ {
22
+ @Rule
23
+ public EmbulkTestRuntime runtime;
24
+
25
+ @Rule
26
+ public ExpectedException thrown;
27
+
28
+ private String protobufJarPath;
29
+ private ProtobufFilterPlugin plugin;
30
+ private Schema defaultInputSchema;
31
+
32
+ public TestProtobufFilterPlugin()
33
+ {
34
+ this.runtime = new EmbulkTestRuntime();
35
+ this.thrown = ExpectedException.none();
36
+
37
+ String pluginBasePath = new File(".").getAbsoluteFile().getParent();
38
+ this.protobufJarPath = String.format(
39
+ "%s/example/AddressBookProtosProto3Syntax.jar",
40
+ pluginBasePath);
41
+ }
42
+
43
+ @Before
44
+ public void createResources()
45
+ {
46
+ this.plugin = new ProtobufFilterPlugin();
47
+ Schema defaultInputSchema = Schema.builder()
48
+ .add("to serialize", Types.STRING)
49
+ .build();
50
+ }
51
+
52
+ public static PluginTask taskFromYamlString(String... lines)
53
+ {
54
+ StringBuilder builder = new StringBuilder();
55
+ for (String line : lines) {
56
+ builder.append(line).append("\n");
57
+ }
58
+ String yamlString = builder.toString();
59
+
60
+ ConfigLoader loader = new ConfigLoader(Exec.getModelManager());
61
+ ConfigSource config = loader.fromYamlString(yamlString);
62
+ return config.loadConfig(PluginTask.class);
63
+ }
64
+
65
+ @Test
66
+ public void testValidate_bothTrue()
67
+ {
68
+ // 'serialize: true' and 'deserilize: true'
69
+ // TODO: expect ConfigException,
70
+ // but somehow get java.util.concurrent.ExecutionException
71
+ //thrown.expect(ConfigException.class);
72
+ thrown.expectMessage("Specify either 'serialize: true' or 'deserialize: true'.");
73
+ PluginTask task = taskFromYamlString(
74
+ "type: protobuf",
75
+ "serialize: true",
76
+ "deserialize: true",
77
+ "encoding: Base64",
78
+ "protobuf_jar_path: " + protobufJarPath,
79
+ "columns:",
80
+ " - {name: to serialize, message: com.example.tutorial.AddressBookProtos$Person}"
81
+ );
82
+ plugin.validate(task, defaultInputSchema);
83
+ }
84
+
85
+ @Test
86
+ public void testValidate_bothFalse()
87
+ {
88
+ // 'serialize: false' and 'deserilize: false'
89
+ //thrown.expect(ConfigException.class);
90
+ thrown.expectMessage("Specify either 'serialize: true' or 'deserialize: true'.");
91
+ PluginTask task = taskFromYamlString(
92
+ "type: protobuf",
93
+ "encoding: Base64",
94
+ "protobuf_jar_path: " + protobufJarPath,
95
+ "columns:",
96
+ " - {name: to serialize, message: com.example.tutorial.AddressBookProtos$Person}"
97
+ );
98
+ plugin.validate(task, defaultInputSchema);
99
+ }
100
+
101
+ @Test
102
+ public void testValidate_encoding()
103
+ {
104
+ //thrown.expect(ConfigException.class);
105
+ thrown.expectMessage("Specify 'encoding: Base64'.");
106
+ PluginTask task = taskFromYamlString(
107
+ "type: protobuf",
108
+ "serialize: true",
109
+ "encoding: Base1",
110
+ "protobuf_jar_path: " + protobufJarPath,
111
+ "columns:",
112
+ " - {name: to serialize, message: com.example.tutorial.AddressBookProtos$Person}"
113
+ );
114
+ plugin.validate(task, defaultInputSchema);
115
+ }
116
+
117
+ @Test
118
+ public void testValidate_protobufJarPathDoesNotExist()
119
+ {
120
+ //thrown.expect(ConfigException.class);
121
+ thrown.expectMessage("The jar file does not exist.");
122
+ PluginTask task = taskFromYamlString(
123
+ "type: protobuf",
124
+ "serialize: true",
125
+ "encoding: Base64",
126
+ "protobuf_jar_path: ./A.jar",
127
+ "columns:",
128
+ " - {name: to serialize, message: com.example.tutorial.AddressBookProtos$Person}"
129
+ );
130
+ plugin.validate(task, defaultInputSchema);
131
+ }
132
+
133
+ @Test
134
+ public void testValidate_inputColumnDoesNotExist()
135
+ {
136
+ String colName = "to serialize";
137
+ //thrown.expect(SchemaConfigException.class);
138
+ thrown.expectMessage(String.format(
139
+ "Column '%s' is not found", colName));
140
+ PluginTask task = taskFromYamlString(
141
+ "type: protobuf",
142
+ "serialize: true",
143
+ "encoding: Base64",
144
+ "protobuf_jar_path: " + protobufJarPath,
145
+ "columns:",
146
+ " - {name: " + colName + ", message: com.example.tutorial.AddressBookProtos$Person}"
147
+ );
148
+ Schema customInputSchema = Schema.builder()
149
+ .add("to deserialize", Types.STRING)
150
+ .build();
151
+ plugin.validate(task, customInputSchema);
152
+ }
153
+
154
+ @Test
155
+ public void testValidate_invalidTypeOfInputColumn()
156
+ {
157
+ //thrown.expect(ConfigException.class);
158
+ thrown.expectMessage("Type of input columns must be string.");
159
+ PluginTask task = taskFromYamlString(
160
+ "type: protobuf",
161
+ "serialize: true",
162
+ "encoding: Base64",
163
+ "protobuf_jar_path: " + protobufJarPath,
164
+ "columns:",
165
+ " - {name: to serialize, message: com.example.tutorial.AddressBookProtos$Person}"
166
+ );
167
+ Schema customInputSchema = Schema.builder()
168
+ .add("to serialize", Types.BOOLEAN)
169
+ .build();
170
+ plugin.validate(task, customInputSchema);
171
+ }
172
+ }
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-filter-protobuf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke NISHIOKA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: An Embulk filter plugin for interconversion between Protocol Buffer message and JSON.
42
+ email:
43
+ - yusuke.nishioka.0713@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - LICENSE.txt
50
+ - README.md
51
+ - build.gradle
52
+ - config/checkstyle/checkstyle.xml
53
+ - config/checkstyle/default.xml
54
+ - example/GenerateTestData.java
55
+ - example/addressbook_proto2_syntax.proto
56
+ - example/addressbook_proto3_syntax.proto
57
+ - example/example_deserialize.csv
58
+ - example/example_deserialize.yml
59
+ - example/example_serialize.json
60
+ - example/example_serialize.yml
61
+ - example/generate_jar_from_proto
62
+ - example/generate_test_data
63
+ - gradle/wrapper/gradle-wrapper.jar
64
+ - gradle/wrapper/gradle-wrapper.properties
65
+ - gradlew
66
+ - gradlew.bat
67
+ - lib/embulk/filter/protobuf.rb
68
+ - src/main/java/org/embulk/filter/protobuf/ColumnVisitorImpl.java
69
+ - src/main/java/org/embulk/filter/protobuf/ProtobufFilterPlugin.java
70
+ - src/test/java/org/embulk/filter/protobuf/TestColumnVisitorImpl.java
71
+ - src/test/java/org/embulk/filter/protobuf/TestProtobufFilterPlugin.java
72
+ - classpath/embulk-filter-protobuf-0.1.0.jar
73
+ - classpath/gson-2.7.jar
74
+ - classpath/protobuf-java-3.1.0.jar
75
+ - classpath/protobuf-java-util-3.1.0.jar
76
+ homepage: https://github.com/ysk24ok/embulk-filter-protobuf
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.1.9
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Protobuf filter plugin for Embulk
100
+ test_files: []