18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2021, 2022 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2021, 2023 , Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2020, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opengrok .web .api .v1 .controller ;
32
32
import org .glassfish .jersey .test .spi .TestContainerException ;
33
33
import org .glassfish .jersey .test .spi .TestContainerFactory ;
34
34
import org .junit .jupiter .api .Test ;
35
+ import org .opengrok .indexer .Info ;
35
36
import org .opengrok .indexer .configuration .Configuration ;
36
37
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
37
38
import org .opengrok .indexer .util .IOUtils ;
@@ -70,7 +71,7 @@ protected TestContainerFactory getTestContainerFactory() throws TestContainerExc
70
71
71
72
/**
72
73
* This method tests include files reload by testing it for one specific file out of the whole set.
73
- * @throws IOException
74
+ * @throws IOException on error
74
75
*/
75
76
@ Test
76
77
public void testIncludeReload () throws IOException {
@@ -98,10 +99,11 @@ public void testIncludeReload() throws IOException {
98
99
}
99
100
100
101
// Reload the contents via API call.
101
- Response r = target ("system" )
102
+ try ( Response r = target ("system" )
102
103
.path ("includes" ).path ("reload" )
103
- .request ().put (Entity .text ("" ));
104
- assertEquals (Response .Status .NO_CONTENT .getStatusCode (), r .getStatus ());
104
+ .request ().put (Entity .text ("" ))) {
105
+ assertEquals (Response .Status .NO_CONTENT .getStatusCode (), r .getStatus ());
106
+ }
105
107
106
108
// Check that the content was reloaded.
107
109
String after = env .getIncludeFiles ().getFooterIncludeFileContent (false );
@@ -117,20 +119,20 @@ public void testDtagsEftarReload() throws IOException {
117
119
// The output file will be located in a directory under data root so create it first.
118
120
Path dataRoot = Files .createTempDirectory ("api_dtags_test" );
119
121
env .setDataRoot (dataRoot .toString ());
120
- Paths .get (dataRoot .toString (), "index" ).toFile ().mkdir ();
122
+ assertTrue ( Paths .get (dataRoot .toString (), "index" ).toFile ().mkdir () );
121
123
122
124
// Create path descriptions string.
123
- StringBuilder sb = new StringBuilder ();
124
125
PathDescription [] descriptions = {
125
126
new PathDescription ("/path1" , "foo foo" ),
126
127
new PathDescription ("/path2" , "bar bar" )
127
128
};
128
129
129
130
// Reload the contents via API call.
130
- Response r = target ("system" )
131
+ try ( Response r = target ("system" )
131
132
.path ("pathdesc" )
132
- .request ().post (Entity .json (descriptions ));
133
- assertEquals (Response .Status .NO_CONTENT .getStatusCode (), r .getStatus ());
133
+ .request ().post (Entity .json (descriptions ))) {
134
+ assertEquals (Response .Status .NO_CONTENT .getStatusCode (), r .getStatus ());
135
+ }
134
136
135
137
// Check
136
138
Path eftarPath = env .getDtagsEftarPath ();
@@ -166,4 +168,26 @@ public void testIndexTime() throws IOException, ParseException {
166
168
// Cleanup
167
169
IOUtils .removeRecursive (dataRoot );
168
170
}
171
+
172
+ @ Test
173
+ void testVersion () {
174
+ Response r = target ("system" )
175
+ .path ("version" )
176
+ .request ().get ();
177
+ String result = r .readEntity (String .class );
178
+
179
+ assertEquals (Response .Status .OK .getStatusCode (), r .getStatus ());
180
+ assertEquals (String .format ("%s (%s)" , Info .getVersion (), Info .getRevision ()), result );
181
+ }
182
+
183
+ @ Test
184
+ void testPing () {
185
+ Response r = target ("system" )
186
+ .path ("ping" )
187
+ .request ().get ();
188
+ String result = r .readEntity (String .class );
189
+
190
+ assertEquals (Response .Status .OK .getStatusCode (), r .getStatus ());
191
+ assertTrue (result .isEmpty ());
192
+ }
169
193
}
0 commit comments