11package org .openstack4j .api ;
22
3- import com .fasterxml .jackson .annotation .JsonInclude .*;
4- import com .fasterxml .jackson .databind .*;
5- import com .google .common .io .*;
6- import okhttp3 .mockwebserver .*;
7- import org .bouncycastle .util .io .*;
8- import org .openstack4j .api .OSClient .*;
9- import org .openstack4j .core .transport .internal .*;
10- import org .openstack4j .openstack .*;
11- import org .openstack4j .openstack .identity .v2 .domain .*;
3+ import com .fasterxml .jackson .annotation .JsonInclude .Include ;
4+ import com .fasterxml .jackson .databind .DeserializationFeature ;
5+ import com .fasterxml .jackson .databind .ObjectMapper ;
6+ import com .fasterxml .jackson .databind .SerializationFeature ;
7+ import com .google .common .io .ByteStreams ;
8+ import okhttp3 .mockwebserver .MockResponse ;
9+ import okhttp3 .mockwebserver .MockWebServer ;
10+ import okhttp3 .mockwebserver .RecordedRequest ;
11+ import org .bouncycastle .util .io .Streams ;
12+ import org .openstack4j .api .OSClient .OSClientV2 ;
13+ import org .openstack4j .api .OSClient .OSClientV3 ;
14+ import org .openstack4j .core .transport .internal .HttpExecutor ;
15+ import org .openstack4j .openstack .OSFactory ;
16+ import org .openstack4j .openstack .identity .v2 .domain .KeystoneAccess ;
1217import org .openstack4j .openstack .identity .v3 .domain .KeystoneToken ;
13- import org .slf4j .*;
14- import org .testng .annotations .*;
15-
16- import java .io .*;
17- import java .net .*;
18- import java .util .*;
18+ import org .slf4j .Logger ;
19+ import org .slf4j .LoggerFactory ;
20+ import org .testng .annotations .AfterClass ;
21+ import org .testng .annotations .BeforeClass ;
22+
23+ import java .io .IOException ;
24+ import java .io .InputStream ;
25+ import java .net .InetAddress ;
26+ import java .net .UnknownHostException ;
27+ import java .util .HashMap ;
28+ import java .util .Map ;
1929
2030/**
2131 * Base Test class which handles Mocking a Webserver to fullfill and test
2636public abstract class AbstractTest {
2737
2838 protected enum Service {
29- IDENTITY (5000 ),
39+ IDENTITY (5000 ),
3040 NETWORK (9696 ),
31- COMPUTE (8774 ),
32- BLOCK_STORAGE (8776 ),
33- METERING (8087 ),
34- TELEMETRY (8087 ),
35- SHARE (8786 ),
41+ COMPUTE (8774 ),
42+ BLOCK_STORAGE (8776 ),
43+ METERING (8087 ),
44+ TELEMETRY (8087 ),
45+ SHARE (8786 ),
3646 OBJECT_STORAGE (8800 ),
3747 BARBICAN (9311 ),
3848 MAGNUM (9511 ),
3949 ORCHESTRATION (8004 ),
4050 DATABASE (8779 ),
41- TACKER (9890 ),
51+ TACKER (9890 ),
4252 IMAGE (9292 ),
4353 ARTIFACT (9494 ),
4454 CLUSTERING (8778 ),
@@ -52,7 +62,7 @@ private Service(int port) {
5262 }
5363
5464 }
55-
65+
5666 private final Logger LOG = LoggerFactory .getLogger (getClass ().getName ());
5767
5868 protected static final String JSON_ACCESS = "/identity/v2/access.json" ;
@@ -100,7 +110,7 @@ protected void respondWith(String resource) throws IOException {
100110
101111 /**
102112 * Responds with specified status code and no body
103- *
113+ *
104114 * @param statusCode the status code to respond with
105115 */
106116 protected void respondWith (int statusCode ) {
@@ -109,8 +119,8 @@ protected void respondWith(int statusCode) {
109119
110120 /**
111121 * Responds with specified status code, no body and optional headers
112- *
113- * @param headers optional headers
122+ *
123+ * @param headers optional headers
114124 * @param statusCode the status code to respond with
115125 */
116126 protected void respondWith (Map <String , String > headers , int statusCode ) {
@@ -119,9 +129,9 @@ protected void respondWith(Map<String, String> headers, int statusCode) {
119129
120130 /**
121131 * Responds with specified status code and json body
122- *
132+ *
123133 * @param statusCode the status code to respond with
124- * @param jsonBody the json body
134+ * @param jsonBody the json body
125135 */
126136 protected void respondWith (int statusCode , String jsonBody ) {
127137 Map <String , String > headers = new HashMap <String , String >();
@@ -131,10 +141,10 @@ protected void respondWith(int statusCode, String jsonBody) {
131141
132142 /**
133143 * Responds with specified status code, body and optional headers
134- *
135- * @param headers optional headers
144+ *
145+ * @param headers optional headers
136146 * @param statusCode the status code to respond with
137- * @param body the response body
147+ * @param body the response body
138148 */
139149 protected void respondWith (Map <String , String > headers , int statusCode , String body ) {
140150 MockResponse r = new MockResponse ();
@@ -151,9 +161,9 @@ protected void respondWith(Map<String, String> headers, int statusCode, String b
151161 /**
152162 * Responds with given header, status code, body from json resource file.
153163 *
154- * @param headers the specified header
164+ * @param headers the specified header
155165 * @param statusCode the status code to respond with
156- * @param resource the json resource file
166+ * @param resource the json resource file
157167 * @throws IOException Signals that an I/O exception has occurred
158168 */
159169 protected void respondWithHeaderAndResource (Map <String , String > headers , int statusCode , String resource )
@@ -174,16 +184,16 @@ protected void respondWithCodeAndResource(int statusCode, String resource) throw
174184 * Callers should use this to verify the request was sent as intended.
175185 * This method will block until the request is available, possibly forever.
176186 * <br/>
177- * <b>Be aware that this method will catch all the previous requests made
187+ * <b>Be aware that this method will catch all the previous requests made
178188 * to the mock server, also from other previous tests!
179189 * Make sure to take all the requests made by methods in the same test class.</b>
180- *
190+ *
181191 * @return the head of the request queue
182192 */
183193 protected RecordedRequest takeRequest () throws InterruptedException {
184194 return server .takeRequest ();
185195 }
186-
196+
187197 protected String authURL (String path ) {
188198 return String .format ("http://%s:5000%s" , getHost (), path );
189199 }
@@ -201,7 +211,7 @@ protected void afterTest() {
201211 protected void associateClientV2 (OSClientV2 osv2 ) {
202212 this .osv2 = osv2 ;
203213 }
204-
214+
205215 protected void associateClientV3 (OSClientV3 osv3 ) {
206216 this .osv3 = osv3 ;
207217 }
0 commit comments