16
16
import static java .util .Collections .emptySet ;
17
17
import static org .mockito .Mockito .mock ;
18
18
19
- import org .apache .logging .log4j .Level ;
20
- import org .apache .logging .log4j .LogManager ;
21
19
import org .junit .After ;
22
20
import org .junit .Before ;
23
21
import org .opensearch .Version ;
31
29
import org .opensearch .extensions .ExtensionsManager ;
32
30
import org .opensearch .indices .breaker .NoneCircuitBreakerService ;
33
31
import org .opensearch .rest .RestRequest ;
34
- import org .opensearch .test .MockLogAppender ;
35
32
import org .opensearch .test .OpenSearchTestCase ;
36
33
import org .opensearch .test .rest .FakeRestChannel ;
37
34
import org .opensearch .test .rest .FakeRestRequest ;
@@ -89,8 +86,12 @@ public void tearDown() throws Exception {
89
86
public void testRestInitializeExtensionActionResponse () throws Exception {
90
87
ExtensionsManager extensionsManager = mock (ExtensionsManager .class );
91
88
RestInitializeExtensionAction restInitializeExtensionAction = new RestInitializeExtensionAction (extensionsManager );
89
+ final String content =
90
+ "{\" name\" :\" ad-extension\" ,\" uniqueId\" :\" ad-extension\" ,\" hostAddress\" :\" 127.0.0.1\" ,\" port\" :\" 4532\" ,\" version\" :\" 1.0\" ,\" opensearchVersion\" :\" 3.0.0\" ,\" minimumCompatibleVersion\" :\" 3.0.0\" }" ;
91
+ RestRequest request = new FakeRestRequest .Builder (xContentRegistry ()).withContent (new BytesArray (content ), XContentType .JSON )
92
+ .withMethod (RestRequest .Method .POST )
93
+ .build ();
92
94
93
- RestRequest request = new FakeRestRequest .Builder (xContentRegistry ()).withMethod (RestRequest .Method .POST ).build ();
94
95
FakeRestChannel channel = new FakeRestChannel (request , false , 0 );
95
96
restInitializeExtensionAction .handleRequest (request , channel , null );
96
97
@@ -100,33 +101,6 @@ public void testRestInitializeExtensionActionResponse() throws Exception {
100
101
101
102
}
102
103
103
- public void testRestInitializeExtensionAction () throws Exception {
104
- ExtensionsManager extensionsManager = mock (ExtensionsManager .class );
105
- RestInitializeExtensionAction restInitializeExtensionAction = new RestInitializeExtensionAction (extensionsManager );
106
- final String content =
107
- "{\" name\" :\" ad-extension\" ,\" uniqueId\" :\" ad-extension\" ,\" hostAddress\" :\" 127.0.0.1\" ,\" port\" :\" 4532\" ,\" version\" :\" 1.0\" ,\" opensearchVersion\" :\" 3.0.0\" ,\" minimumCompatibleVersion\" :\" 3.0.0\" }" ;
108
- RestRequest request = new FakeRestRequest .Builder (xContentRegistry ()).withContent (new BytesArray (content ), XContentType .JSON )
109
- .withMethod (RestRequest .Method .POST )
110
- .build ();
111
-
112
- try (
113
- MockLogAppender mockLogAppender = MockLogAppender .createForLoggers (LogManager .getLogger (RestInitializeExtensionAction .class ))
114
- ) {
115
- mockLogAppender .addExpectation (
116
- new MockLogAppender .SeenEventExpectation (
117
- "Extension has been initialized" ,
118
- "org.opensearch.extensions.rest.RestInitializeExtensionAction" ,
119
- Level .INFO ,
120
- "Extension has been initialized"
121
- )
122
- );
123
- restInitializeExtensionAction .prepareRequest (request , null );
124
- mockLogAppender .assertAllExpectationsMatched ();
125
-
126
- }
127
-
128
- }
129
-
130
104
public void testRestInitializeExtensionActionFailure () throws Exception {
131
105
ExtensionsManager extensionsManager = new ExtensionsManager (Set .of ());
132
106
RestInitializeExtensionAction restInitializeExtensionAction = new RestInitializeExtensionAction (extensionsManager );
@@ -137,22 +111,11 @@ public void testRestInitializeExtensionActionFailure() throws Exception {
137
111
.withMethod (RestRequest .Method .POST )
138
112
.build ();
139
113
140
- try (
141
- MockLogAppender mockLogAppender = MockLogAppender .createForLoggers (LogManager .getLogger (RestInitializeExtensionAction .class ))
142
- ) {
143
- mockLogAppender .addExpectation (
144
- new MockLogAppender .SeenEventExpectation (
145
- "Required field is missing in the request" ,
146
- "org.opensearch.extensions.rest.RestInitializeExtensionAction" ,
147
- Level .ERROR ,
148
- "Required field [uniqueId] is missing in the request"
149
- )
150
- );
151
- restInitializeExtensionAction .prepareRequest (request , null );
152
- mockLogAppender .assertAllExpectationsMatched ();
153
-
154
- }
114
+ FakeRestChannel channel = new FakeRestChannel (request , false , 0 );
115
+ restInitializeExtensionAction .handleRequest (request , channel , null );
155
116
117
+ assertEquals (1 , channel .errors ().get ());
118
+ assertTrue (channel .capturedResponse ().content ().utf8ToString ().contains ("Required field [uniqueId] is missing in the request" ));
156
119
}
157
120
158
121
}
0 commit comments