|
37 | 37 | import org.opensearch.Version;
|
38 | 38 | import org.opensearch.action.admin.cluster.node.info.PluginsAndModules;
|
39 | 39 | import org.opensearch.common.io.stream.BytesStreamOutput;
|
| 40 | +import org.opensearch.common.xcontent.json.JsonXContent; |
40 | 41 | import org.opensearch.core.common.io.stream.ByteBufferStreamInput;
|
| 42 | +import org.opensearch.core.xcontent.ToXContent; |
| 43 | +import org.opensearch.core.xcontent.XContentBuilder; |
41 | 44 | import org.opensearch.semver.SemverRange;
|
42 | 45 | import org.opensearch.test.OpenSearchTestCase;
|
43 | 46 |
|
@@ -367,6 +370,31 @@ public void testSerialize() throws Exception {
|
367 | 370 | assertThat(info2.toString(), equalTo(info.toString()));
|
368 | 371 | }
|
369 | 372 |
|
| 373 | + public void testToXContent() throws Exception { |
| 374 | + PluginInfo info = new PluginInfo( |
| 375 | + "fake", |
| 376 | + "foo", |
| 377 | + "dummy", |
| 378 | + Version.CURRENT, |
| 379 | + "1.8", |
| 380 | + "dummyClass", |
| 381 | + "folder", |
| 382 | + Collections.emptyList(), |
| 383 | + false |
| 384 | + ); |
| 385 | + XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint(); |
| 386 | + String prettyPrint = info.toXContent(builder, ToXContent.EMPTY_PARAMS).prettyPrint().toString(); |
| 387 | + assertTrue(prettyPrint.contains("\"name\" : \"fake\"")); |
| 388 | + assertTrue(prettyPrint.contains("\"version\" : \"dummy\"")); |
| 389 | + assertTrue(prettyPrint.contains("\"opensearch_version\" : \"" + Version.CURRENT)); |
| 390 | + assertTrue(prettyPrint.contains("\"java_version\" : \"1.8\"")); |
| 391 | + assertTrue(prettyPrint.contains("\"description\" : \"foo\"")); |
| 392 | + assertTrue(prettyPrint.contains("\"classname\" : \"dummyClass\"")); |
| 393 | + assertTrue(prettyPrint.contains("\"custom_foldername\" : \"folder\"")); |
| 394 | + assertTrue(prettyPrint.contains("\"extended_plugins\" : [ ]")); |
| 395 | + assertTrue(prettyPrint.contains("\"has_native_controller\" : false")); |
| 396 | + } |
| 397 | + |
370 | 398 | public void testPluginListSorted() {
|
371 | 399 | List<PluginInfo> plugins = new ArrayList<>();
|
372 | 400 | plugins.add(new PluginInfo("c", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass", Collections.emptyList(), randomBoolean()));
|
|
0 commit comments