embulk-input-zendesk 0.2.14 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -3
  3. data/.travis.yml +5 -44
  4. data/CHANGELOG.md +3 -0
  5. data/README.md +5 -5
  6. data/build.gradle +123 -0
  7. data/classpath/commons-codec-1.10.jar +0 -0
  8. data/classpath/commons-logging-1.2.jar +0 -0
  9. data/classpath/embulk-input-zendesk-0.3.0.jar +0 -0
  10. data/classpath/httpclient-4.5.6.jar +0 -0
  11. data/classpath/httpcore-4.4.10.jar +0 -0
  12. data/config/checkstyle/checkstyle.xml +128 -0
  13. data/config/checkstyle/default.xml +108 -0
  14. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  15. data/gradle/wrapper/gradle-wrapper.properties +5 -0
  16. data/gradlew +172 -0
  17. data/gradlew.bat +84 -0
  18. data/lib/embulk/guess/zendesk.rb +21 -0
  19. data/lib/embulk/input/zendesk.rb +3 -9
  20. data/src/main/java/org/embulk/input/zendesk/ZendeskInputPlugin.java +471 -0
  21. data/src/main/java/org/embulk/input/zendesk/clients/ZendeskRestClient.java +268 -0
  22. data/src/main/java/org/embulk/input/zendesk/models/AuthenticationMethod.java +23 -0
  23. data/src/main/java/org/embulk/input/zendesk/models/Target.java +46 -0
  24. data/src/main/java/org/embulk/input/zendesk/models/ZendeskException.java +25 -0
  25. data/src/main/java/org/embulk/input/zendesk/services/ZendeskSupportAPIService.java +109 -0
  26. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskConstants.java +61 -0
  27. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskDateUtils.java +51 -0
  28. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskUtils.java +150 -0
  29. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskValidatorUtils.java +92 -0
  30. data/src/test/java/org/embulk/input/zendesk/TestZendeskInputPlugin.java +232 -0
  31. data/src/test/java/org/embulk/input/zendesk/clients/TestZendeskRestClient.java +351 -0
  32. data/src/test/java/org/embulk/input/zendesk/services/TestZendeskSupportAPIService.java +172 -0
  33. data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskDateUtils.java +36 -0
  34. data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskUtil.java +160 -0
  35. data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskValidatorUtils.java +138 -0
  36. data/src/test/java/org/embulk/input/zendesk/utils/ZendeskPluginTestRuntime.java +133 -0
  37. data/src/test/java/org/embulk/input/zendesk/utils/ZendeskTestHelper.java +63 -0
  38. data/src/test/resources/config/base.yml +14 -0
  39. data/src/test/resources/config/base_validator.yml +48 -0
  40. data/src/test/resources/config/incremental.yml +54 -0
  41. data/src/test/resources/config/non-incremental.yml +39 -0
  42. data/src/test/resources/config/util.yml +18 -0
  43. data/src/test/resources/data/client.json +293 -0
  44. data/src/test/resources/data/error_data.json +187 -0
  45. data/src/test/resources/data/expected/ticket_column.json +148 -0
  46. data/src/test/resources/data/expected/ticket_column_with_related_objects.json +152 -0
  47. data/src/test/resources/data/expected/ticket_fields_column.json +92 -0
  48. data/src/test/resources/data/expected/ticket_metrics_column.json +98 -0
  49. data/src/test/resources/data/ticket_fields.json +225 -0
  50. data/src/test/resources/data/ticket_metrics.json +397 -0
  51. data/src/test/resources/data/ticket_with_related_objects.json +67 -0
  52. data/src/test/resources/data/tickets.json +232 -0
  53. data/src/test/resources/data/tickets_continue.json +52 -0
  54. data/src/test/resources/data/util.json +19 -0
  55. data/src/test/resources/data/util_page.json +227 -0
  56. metadata +65 -221
  57. data/.ruby-version +0 -1
  58. data/.travis.yml.erb +0 -43
  59. data/Gemfile +0 -2
  60. data/Rakefile +0 -21
  61. data/embulk-input-zendesk.gemspec +0 -29
  62. data/gemfiles/embulk-0.8.0-latest +0 -4
  63. data/gemfiles/embulk-0.8.1 +0 -4
  64. data/gemfiles/embulk-latest +0 -4
  65. data/gemfiles/template.erb +0 -4
  66. data/lib/embulk/input/zendesk/client.rb +0 -434
  67. data/lib/embulk/input/zendesk/plugin.rb +0 -199
  68. data/test/capture_io.rb +0 -45
  69. data/test/embulk/input/zendesk/test_client.rb +0 -722
  70. data/test/embulk/input/zendesk/test_plugin.rb +0 -628
  71. data/test/fixture_helper.rb +0 -11
  72. data/test/fixtures/invalid_app_marketplace_lack_one_property.yml +0 -13
  73. data/test/fixtures/invalid_app_marketplace_lack_two_property.yml +0 -12
  74. data/test/fixtures/invalid_lack_username.yml +0 -9
  75. data/test/fixtures/invalid_unknown_auth.yml +0 -9
  76. data/test/fixtures/tickets.json +0 -44
  77. data/test/fixtures/valid_app_marketplace.yml +0 -14
  78. data/test/fixtures/valid_auth_basic.yml +0 -11
  79. data/test/fixtures/valid_auth_oauth.yml +0 -10
  80. data/test/fixtures/valid_auth_token.yml +0 -11
  81. data/test/override_assert_raise.rb +0 -21
  82. data/test/run-test.rb +0 -26
@@ -0,0 +1,36 @@
1
+ package org.embulk.input.zendesk.utils;
2
+
3
+ import org.embulk.spi.DataException;
4
+ import org.junit.Assert;
5
+ import org.junit.Test;
6
+ import static org.junit.Assert.assertThrows;
7
+
8
+ public class TestZendeskDateUtils
9
+ {
10
+ @Test
11
+ public void isoToEpochSecondShouldReturnCorrectValue()
12
+ {
13
+ long expectedValue = 1550645445;
14
+
15
+ long value = ZendeskDateUtils.isoToEpochSecond("2019-02-20T06:50:45Z");
16
+ Assert.assertEquals(expectedValue, value);
17
+
18
+ value = ZendeskDateUtils.isoToEpochSecond("2019-02-20 06:50:45 +0000");
19
+ Assert.assertEquals(expectedValue, value);
20
+
21
+ value = ZendeskDateUtils.isoToEpochSecond("2019-02-20T06:50:45.000Z");
22
+ Assert.assertEquals(expectedValue, value);
23
+
24
+ value = ZendeskDateUtils.isoToEpochSecond("2019-02-20T06:50:45+00:00");
25
+ Assert.assertEquals(expectedValue, value);
26
+ }
27
+
28
+ @Test
29
+ public void isoToEpochSecondShouldThrowException()
30
+ {
31
+ assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-02asdasdasd-20T06:50:45Z"));
32
+ assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-002-20T06:50:45Z"));
33
+ assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-02-200T06:50:45.000Z"));
34
+ assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-02-20T24:01:00Z"));
35
+ }
36
+ }
@@ -0,0 +1,160 @@
1
+ package org.embulk.input.zendesk.utils;
2
+
3
+ import com.fasterxml.jackson.databind.JsonNode;
4
+ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
5
+ import org.embulk.EmbulkTestRuntime;
6
+ import org.embulk.input.zendesk.ZendeskInputPlugin.PluginTask;
7
+ import org.embulk.input.zendesk.models.Target;
8
+ import org.embulk.input.zendesk.services.ZendeskSupportAPIService;
9
+ import org.embulk.spi.Column;
10
+ import org.embulk.spi.PageBuilder;
11
+ import org.embulk.spi.Schema;
12
+ import org.embulk.spi.json.JsonParser;
13
+ import org.embulk.spi.time.Timestamp;
14
+ import org.embulk.spi.time.TimestampParser;
15
+
16
+ import org.junit.Assert;
17
+ import org.junit.BeforeClass;
18
+ import org.junit.Rule;
19
+ import org.junit.Test;
20
+ import org.mockito.Mockito;
21
+ import org.msgpack.value.Value;
22
+
23
+ import static org.junit.Assert.assertEquals;
24
+ import static org.mockito.ArgumentMatchers.anyBoolean;
25
+ import static org.mockito.ArgumentMatchers.anyInt;
26
+ import static org.mockito.ArgumentMatchers.anyLong;
27
+ import static org.mockito.ArgumentMatchers.anyString;
28
+
29
+ import static org.mockito.Mockito.mock;
30
+ import static org.mockito.Mockito.times;
31
+ import static org.mockito.Mockito.verify;
32
+ import static org.mockito.Mockito.when;
33
+
34
+ public class TestZendeskUtil
35
+ {
36
+ @Rule
37
+ @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
38
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
39
+
40
+ private static Schema schema;
41
+ private static Column booleanColumn;
42
+ private static Column longColumn;
43
+ private static Column doubleColumn;
44
+ private static Column stringColumn;
45
+ private static Column dateColumn;
46
+ private static Column jsonColumn;
47
+
48
+ private static ZendeskSupportAPIService zendeskSupportAPIService;
49
+
50
+ @BeforeClass
51
+ public static void setUp()
52
+ {
53
+ zendeskSupportAPIService = mock(ZendeskSupportAPIService.class);
54
+ PluginTask pluginTask = ZendeskTestHelper.getConfigSource("util.yml").loadConfig(PluginTask.class);
55
+ schema = pluginTask.getColumns().toSchema();
56
+ booleanColumn = schema.getColumn(0);
57
+ longColumn = schema.getColumn(1);
58
+ doubleColumn = schema.getColumn(2);
59
+ stringColumn = schema.getColumn(3);
60
+ dateColumn = schema.getColumn(4);
61
+ jsonColumn = schema.getColumn(5);
62
+ }
63
+
64
+ @Test
65
+ public void testIsSupportIncrementalShouldReturnTrue()
66
+ {
67
+ boolean result = ZendeskUtils.isSupportAPIIncremental(Target.TICKETS);
68
+ Assert.assertTrue(result);
69
+
70
+ result = ZendeskUtils.isSupportAPIIncremental(Target.USERS);
71
+ Assert.assertTrue(result);
72
+
73
+ result = ZendeskUtils.isSupportAPIIncremental(Target.ORGANIZATIONS);
74
+ Assert.assertTrue(result);
75
+
76
+ result = ZendeskUtils.isSupportAPIIncremental(Target.TICKET_EVENTS);
77
+ Assert.assertTrue(result);
78
+
79
+ result = ZendeskUtils.isSupportAPIIncremental(Target.TICKET_METRICS);
80
+ Assert.assertTrue(result);
81
+ }
82
+
83
+ @Test
84
+ public void testNumberToSplitWithHintingInTaskWithNonIncrementalTarget()
85
+ {
86
+ JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util_page.json");
87
+ when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
88
+ int number = ZendeskUtils.numberToSplitWithHintingInTask(2101);
89
+ assertEquals(22, number);
90
+
91
+ number = ZendeskUtils.numberToSplitWithHintingInTask(2100);
92
+ assertEquals(21, number);
93
+
94
+ number = ZendeskUtils.numberToSplitWithHintingInTask(2099);
95
+ assertEquals(21, number);
96
+ }
97
+
98
+ @Test
99
+ public void testAddRecordAllRight()
100
+ {
101
+ String name = "allRight";
102
+ JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util.json").get(name);
103
+ PageBuilder mock = Mockito.mock(PageBuilder.class);
104
+
105
+ Boolean boolValue = Boolean.TRUE;
106
+ long longValue = 1;
107
+ double doubleValue = 1;
108
+ String stringValue = "string";
109
+ Timestamp dateValue = TimestampParser.of("%Y-%m-%dT%H:%M:%S%z", "UTC").parse("2019-01-01T00:00:00Z");
110
+ Value jsonValue = new JsonParser().parse("{}");
111
+
112
+ ZendeskUtils.addRecord(dataJson, schema, mock);
113
+
114
+ verify(mock, times(1)).setBoolean(booleanColumn, boolValue);
115
+ verify(mock, times(1)).setLong(longColumn, longValue);
116
+ verify(mock, times(1)).setDouble(doubleColumn, doubleValue);
117
+ verify(mock, times(1)).setString(stringColumn, stringValue);
118
+ verify(mock, times(1)).setTimestamp(dateColumn, dateValue);
119
+ verify(mock, times(1)).setJson(jsonColumn, jsonValue);
120
+ }
121
+
122
+ @Test
123
+ public void testAddRecordAllWrong()
124
+ {
125
+ String name = "allWrong";
126
+ JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util.json").get(name);
127
+ PageBuilder mock = Mockito.mock(PageBuilder.class);
128
+
129
+ Value jsonValue = new JsonParser().parse("{}");
130
+
131
+ ZendeskUtils.addRecord(dataJson, schema, mock);
132
+
133
+ verify(mock, times(1)).setNull(booleanColumn);
134
+ verify(mock, times(1)).setNull(longColumn);
135
+ verify(mock, times(1)).setNull(doubleColumn);
136
+ verify(mock, times(1)).setNull(stringColumn);
137
+ verify(mock, times(1)).setNull(dateColumn);
138
+ verify(mock, times(1)).setJson(jsonColumn, jsonValue);
139
+ }
140
+
141
+ @Test
142
+ public void testAddRecordAllMissing()
143
+ {
144
+ String name = "allMissing";
145
+ JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util.json").get(name);
146
+ PageBuilder mock = Mockito.mock(PageBuilder.class);
147
+
148
+ ZendeskUtils.addRecord(dataJson, schema, mock);
149
+
150
+ verify(mock, times(6)).setNull(Mockito.any(Column.class));
151
+ }
152
+
153
+ @Test
154
+ public void testConvertBase64()
155
+ {
156
+ String expectedResult = "YWhrc2RqZmhramFzZGhma2phaGRma2phaGRramZoYWtqZGY=";
157
+ String encode = ZendeskUtils.convertBase64("ahksdjfhkjasdhfkjahdfkjahdkjfhakjdf");
158
+ assertEquals(expectedResult, encode);
159
+ }
160
+ }
@@ -0,0 +1,138 @@
1
+ package org.embulk.input.zendesk.utils;
2
+
3
+ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4
+ import org.embulk.config.ConfigSource;
5
+
6
+ import org.embulk.input.zendesk.ZendeskInputPlugin;
7
+ import org.embulk.input.zendesk.services.ZendeskSupportAPIService;
8
+
9
+ import org.embulk.spi.InputPlugin;
10
+ import org.embulk.test.TestingEmbulk;
11
+
12
+ import org.junit.Before;
13
+ import org.junit.Rule;
14
+ import org.junit.Test;
15
+ import org.junit.rules.ExpectedException;
16
+ import org.junit.rules.RuleChain;
17
+ import org.junit.rules.TestRule;
18
+
19
+ import static org.junit.Assert.assertEquals;
20
+ import static org.junit.Assert.fail;
21
+
22
+ import static org.mockito.Mockito.mock;
23
+
24
+ import java.util.Collections;
25
+
26
+ public class TestZendeskValidatorUtils
27
+ {
28
+ private final ExpectedException thrown = ExpectedException.none();
29
+ private final TestingEmbulk embulk = TestingEmbulk.builder()
30
+ .registerPlugin(InputPlugin.class, "zendesk", ZendeskInputPlugin.class)
31
+ .build();
32
+ public ZendeskPluginTestRuntime runtime = new ZendeskPluginTestRuntime();
33
+ ConfigSource configSource;
34
+
35
+ @Rule
36
+ @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
37
+ public TestRule chain = RuleChain.outerRule(embulk).around(runtime).around(thrown);
38
+
39
+ private ZendeskSupportAPIService zendeskSupportAPIService = mock(ZendeskSupportAPIService.class);
40
+
41
+ @Before
42
+ public void prepare()
43
+ {
44
+ configSource = getBaseConfigSource();
45
+ }
46
+
47
+ @Test
48
+ public void validateHostShouldThrowException()
49
+ {
50
+ configSource.set("login_url", "dummyhost");
51
+ final ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
52
+ assertValidation(task, "Login URL, 'dummyhost', is unmatched expectation. It should be followed this format: https://abc.zendesk.com/");
53
+ }
54
+
55
+ @Test
56
+ public void validateCredentialOauthShouldThrowException()
57
+ {
58
+ configSource.set("auth_method", "oauth");
59
+ configSource.remove("access_token");
60
+ final ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
61
+ assertValidation(task, "access_token is required for authentication method 'oauth'");
62
+ }
63
+
64
+ @Test
65
+ public void validateCredentialBasicShouldThrowException()
66
+ {
67
+ configSource.set("auth_method", "basic");
68
+ configSource.remove("username");
69
+ ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
70
+ assertValidation(task, "username and password are required for authentication method 'basic'");
71
+
72
+ configSource.set("username", "");
73
+ configSource.remove("password");
74
+ task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
75
+ assertValidation(task, "username and password are required for authentication method 'basic'");
76
+ }
77
+
78
+ @Test
79
+ public void validateCredentialTokenShouldThrowException()
80
+ {
81
+ configSource.set("auth_method", "token");
82
+ configSource.remove("token");
83
+ ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
84
+ assertValidation(task, "username and token are required for authentication method 'token'");
85
+
86
+ configSource.set("token", "");
87
+ configSource.remove("username");
88
+ task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
89
+ assertValidation(task, "username and token are required for authentication method 'token'");
90
+ }
91
+
92
+ @Test
93
+ public void validateAppMarketPlaceShouldThrowException()
94
+ {
95
+ configSource.remove("app_marketplace_integration_name");
96
+ ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
97
+ assertValidation(task, "All of app_marketplace_integration_name, app_marketplace_org_id, " +
98
+ "app_marketplace_app_id " +
99
+ "are required to fill out for Apps Marketplace API header");
100
+ }
101
+
102
+ @Test
103
+ public void validateInclude()
104
+ {
105
+ configSource.set("target", "ticket_fields");
106
+ configSource.set("includes", Collections.singletonList("organizations"));
107
+ final ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
108
+ ZendeskValidatorUtils.validateInputTask(task, zendeskSupportAPIService);
109
+ }
110
+
111
+ @Test
112
+ public void validateIncremental()
113
+ {
114
+ configSource.set("target", "ticket_fields");
115
+ configSource.set("incremental", true);
116
+ configSource.set("dedup", false);
117
+ configSource.set("start_time", "");
118
+
119
+ final ZendeskInputPlugin.PluginTask task = configSource.loadConfig(ZendeskInputPlugin.PluginTask.class);
120
+ ZendeskValidatorUtils.validateInputTask(task, zendeskSupportAPIService);
121
+ }
122
+
123
+ private static ConfigSource getBaseConfigSource()
124
+ {
125
+ return ZendeskTestHelper.getConfigSource("base_validator.yml");
126
+ }
127
+
128
+ private void assertValidation(final ZendeskInputPlugin.PluginTask task, final String message)
129
+ {
130
+ try {
131
+ ZendeskValidatorUtils.validateInputTask(task, zendeskSupportAPIService);
132
+ fail("Should not reach here");
133
+ }
134
+ catch (final Exception e) {
135
+ assertEquals(message, e.getMessage());
136
+ }
137
+ }
138
+ }
@@ -0,0 +1,133 @@
1
+ package org.embulk.input.zendesk.utils;
2
+
3
+ import com.fasterxml.jackson.databind.ObjectMapper;
4
+ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
5
+ import com.fasterxml.jackson.databind.node.ObjectNode;
6
+ import com.google.inject.Binder;
7
+ import com.google.inject.Injector;
8
+ import com.google.inject.Module;
9
+ import org.embulk.GuiceBinder;
10
+ import org.embulk.RandomManager;
11
+ import org.embulk.TestPluginSourceModule;
12
+ import org.embulk.TestUtilityModule;
13
+ import org.embulk.config.ConfigSource;
14
+ import org.embulk.config.DataSourceImpl;
15
+ import org.embulk.config.ModelManager;
16
+ import org.embulk.exec.ExecModule;
17
+ import org.embulk.exec.ExtensionServiceLoaderModule;
18
+ import org.embulk.exec.SystemConfigModule;
19
+ import org.embulk.jruby.JRubyScriptingModule;
20
+ import org.embulk.plugin.BuiltinPluginSourceModule;
21
+ import org.embulk.plugin.PluginClassLoaderFactory;
22
+ import org.embulk.plugin.PluginClassLoaderModule;
23
+ import org.embulk.spi.BufferAllocator;
24
+ import org.embulk.spi.Exec;
25
+ import org.embulk.spi.ExecAction;
26
+ import org.embulk.spi.ExecSession;
27
+ import org.junit.runner.Description;
28
+ import org.junit.runners.model.Statement;
29
+
30
+ import java.util.Random;
31
+
32
+ /**
33
+ * This is a clone from {@link org.embulk.EmbulkTestRuntime}, since there is no easy way to extend it.
34
+ * The only modification is on the provided systemConfig, enable tests to run `embulk/guess/zendesk.rb`
35
+ */
36
+ public class ZendeskPluginTestRuntime extends GuiceBinder
37
+ {
38
+ public static class TestRuntimeModule implements Module
39
+ {
40
+ @Override
41
+ public void configure(Binder binder)
42
+ {
43
+ ConfigSource systemConfig = getSystemConfig();
44
+ new SystemConfigModule(systemConfig).configure(binder);
45
+ new ExecModule().configure(binder);
46
+ new ExtensionServiceLoaderModule(systemConfig).configure(binder);
47
+ new BuiltinPluginSourceModule().configure(binder);
48
+ new JRubyScriptingModule(systemConfig).configure(binder);
49
+ new PluginClassLoaderModule(systemConfig).configure(binder);
50
+ new TestUtilityModule().configure(binder);
51
+ new TestPluginSourceModule().configure(binder);
52
+ }
53
+ }
54
+
55
+ private ExecSession exec;
56
+
57
+ public ZendeskPluginTestRuntime()
58
+ {
59
+ super(new TestRuntimeModule());
60
+ Injector injector = getInjector();
61
+ ConfigSource execConfig = new DataSourceImpl(injector.getInstance(ModelManager.class));
62
+ this.exec = ExecSession.builder(injector).fromExecConfig(execConfig).build();
63
+ }
64
+
65
+ public ExecSession getExec()
66
+ {
67
+ return exec;
68
+ }
69
+
70
+ public BufferAllocator getBufferAllocator()
71
+ {
72
+ return getInstance(BufferAllocator.class);
73
+ }
74
+
75
+ public ModelManager getModelManager()
76
+ {
77
+ return getInstance(ModelManager.class);
78
+ }
79
+
80
+ public Random getRandom()
81
+ {
82
+ return getInstance(RandomManager.class).getRandom();
83
+ }
84
+
85
+ public PluginClassLoaderFactory getPluginClassLoaderFactory()
86
+ {
87
+ return getInstance(PluginClassLoaderFactory.class);
88
+ }
89
+
90
+ @Override
91
+ public Statement apply(Statement base, Description description)
92
+ {
93
+ final Statement superStatement = ZendeskPluginTestRuntime.super.apply(base, description);
94
+ return new Statement() {
95
+ public void evaluate() throws Throwable
96
+ {
97
+ try {
98
+ Exec.doWith(exec, (ExecAction<Void>) () -> {
99
+ try {
100
+ superStatement.evaluate();
101
+ }
102
+ catch (Throwable ex) {
103
+ throw new RuntimeExecutionException(ex);
104
+ }
105
+ return null;
106
+ });
107
+ }
108
+ catch (RuntimeException ex) {
109
+ throw ex.getCause();
110
+ }
111
+ finally {
112
+ exec.cleanup();
113
+ }
114
+ }
115
+ };
116
+ }
117
+
118
+ private static class RuntimeExecutionException extends RuntimeException
119
+ {
120
+ public RuntimeExecutionException(Throwable cause)
121
+ {
122
+ super(cause);
123
+ }
124
+ }
125
+
126
+ private static ConfigSource getSystemConfig()
127
+ {
128
+ ObjectNode configNode = JsonNodeFactory.instance.objectNode();
129
+ configNode.set("jruby_load_path", JsonNodeFactory.instance.arrayNode().add("lib"));
130
+
131
+ return new DataSourceImpl(new ModelManager(null, new ObjectMapper()), configNode);
132
+ }
133
+ }