diff options
author | Smokowski, Steve (ss835w) <ss835w@us.att.com> | 2019-05-02 09:42:55 -0400 |
---|---|---|
committer | Smokowski, Steve (ss835w) <ss835w@us.att.com> | 2019-05-07 10:02:17 -0400 |
commit | 3f9a0c3183480d150089c0d5a6e507c877f7d121 (patch) | |
tree | b3db04cbe2cef23f81503177a50edc5360ffa486 /openstack-client | |
parent | e153f0adfbed711ce1e215748594a4d04fd1edaf (diff) |
Enhance Openstack Client
Update Openstack Client to support additional fields
Updat all formatting issues
Issue-ID: SO-1844
Change-Id: I1369e0c18cc25274db8df7e12855a020b8da38da
Signed-off-by: Smokowski, Steve (ss835w) <ss835w@us.att.com>
Diffstat (limited to 'openstack-client')
13 files changed, 239 insertions, 243 deletions
diff --git a/openstack-client/pom.xml b/openstack-client/pom.xml index 8e4b6b0..302f176 100644 --- a/openstack-client/pom.xml +++ b/openstack-client/pom.xml @@ -1,53 +1,53 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onap.so.libs</groupId> - <artifactId>openstack-java-sdk</artifactId> - <version>1.4.0-SNAPSHOT</version> - </parent> - <groupId>org.onap.so.libs.openstack-java-sdk</groupId> - <artifactId>openstack-client</artifactId> - <name>OpenStack Client</name> - <description>OpenStack Client</description> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.so.libs</groupId> + <artifactId>openstack-java-sdk</artifactId> + <version>1.4.0-SNAPSHOT</version> + </parent> + <groupId>org.onap.so.libs.openstack-java-sdk</groupId> + <artifactId>openstack-client</artifactId> + <name>OpenStack Client</name> + <description>OpenStack Client</description> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-mockito</artifactId> - <scope>test</scope> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <scope>test</scope> + </dependency> + </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>3.0.2</version> - <executions> - <execution> - <id>test-jar</id> - <goals> - <goal>test-jar</goal> - </goals> - <configuration> - <skip>false</skip> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.0.2</version> + <executions> + <execution> + <id>test-jar</id> + <goals> + <goal>test-jar</goal> + </goals> + <configuration> + <skip>false</skip> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java index 53d2595..bcb7d51 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java @@ -1,40 +1,39 @@ -/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-
-package com.woorea.openstack.base.client;
-
-/**
- * A common abstract parent of all Openstack Exception types, allowing
- * calling classes the choice to catch all error exceptions together.
- */
-public abstract class OpenStackBaseException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- /*
- * Implement only the basic constructors
- */
- public OpenStackBaseException () {}
-
- public OpenStackBaseException(String message) {
- super(message);
- }
-
- public OpenStackBaseException(String message, Throwable cause) {
- super(message, cause);
- }
-}
\ No newline at end of file +/*- + * ============LICENSE_START======================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package com.woorea.openstack.base.client; + +/** + * A common abstract parent of all Openstack Exception types, allowing calling classes the choice to catch all error + * exceptions together. + */ +public abstract class OpenStackBaseException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /* + * Implement only the basic constructors + */ + public OpenStackBaseException() {} + + public OpenStackBaseException(String message) { + super(message); + } + + public OpenStackBaseException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java index a111975..8c61b30 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java @@ -70,23 +70,24 @@ public class OpenStackClient { try { return connector.request(request); } catch (OpenStackResponseException e) { - if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED - || tokenProvider == null) { + if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED || tokenProvider == null) { throw e; } authException = e; tokenProvider.expireToken(); } } - if(null == authException){ - authException = new OpenStackResponseException("Unknown issue",500); + if (null == authException) { + authException = new OpenStackResponseException("Unknown issue", 500); } throw authException; } public <T> T execute(OpenStackRequest<T> request) { - OpenStackResponse response = request(request); - return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null; + OpenStackResponse response = request(request); + return (request.returnType() != null && request.returnType() != Void.class) + ? response.getEntity(request.returnType()) + : null; } public void property(String property, String value) { @@ -105,4 +106,4 @@ public class OpenStackClient { return new OpenStackRequest<>(this, HttpMethod.GET, path, null, returnType); } -}
\ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java index 0e29335..30d6722 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java @@ -18,9 +18,8 @@ package com.woorea.openstack.base.client; /** - * Custom RuntimeException to report connection errors to Openstack endpoints. - * Must be a RuntimeException to conform with OpenstackClient interface, which - * does not declare specific Exceptions. + * Custom RuntimeException to report connection errors to Openstack endpoints. Must be a RuntimeException to conform + * with OpenstackClient interface, which does not declare specific Exceptions. */ public class OpenStackConnectException extends OpenStackBaseException { @@ -33,4 +32,4 @@ public class OpenStackConnectException extends OpenStackBaseException { public OpenStackConnectException(String message, Throwable cause) { super(message, cause); } -}
\ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java index 07b6f70..d896837 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java @@ -25,137 +25,137 @@ import java.util.Map; public class OpenStackRequest<R> { - private OpenStackClient client; + private OpenStackClient client; - private String endpoint; - - private HttpMethod method; + private String endpoint; + + private HttpMethod method; - private StringBuilder path = new StringBuilder(); + private StringBuilder path = new StringBuilder(); - private Map<String, List<Object>> headers = new HashMap<>(); + private Map<String, List<Object>> headers = new HashMap<>(); - private Entity<?> entity; + private Entity<?> entity; - private Class<R> returnType; + private Class<R> returnType; - public OpenStackRequest() { - - } - - public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity, - Class<R> returnType) { - this.client = client; - this.method = method; - this.path = new StringBuilder(path); - this.entity = entity; - this.returnType = returnType; - header("Accept", "application/json"); - } - - public OpenStackRequest<R> endpoint(String endpoint) { - this.endpoint = endpoint; - return this; - } - - public String endpoint() { - return endpoint; - } - - public OpenStackRequest<R> method(HttpMethod method) { - this.method = method; - return this; - } - - public HttpMethod method() { - return method; - } - - public OpenStackRequest<R> path(String path) { - this.path.append(path); - return this; - } - - public String path() { - return path.toString(); - } - - public OpenStackRequest<R> header(String name, Object value) { - if (value != null) { - headers.put(name, Arrays.asList(value)); - } - return this; - } - - public Map<String, List<Object>> headers() { - return headers; - } - - public <T> Entity<T> entity(T entity, String contentType) { - return new Entity<>(entity, contentType); - } - - public Entity<?> entity() { - return entity; - } - - public <T> Entity<T> json(T entity) { - return entity(entity, "application/json"); - } - - public void returnType(Class<R> returnType) { - this.returnType = returnType; - } - - public Class<R> returnType() { - return returnType; - } - - public R execute() { - return client.execute(this); - } - - public OpenStackResponse request() { - return client.request(this); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method + ", path=" + path + ", headers=" - + headers + ", entity=" + entity + ", returnType=" + returnType + "]"; - } - - private Map<String, List<Object>> queryParams = new LinkedHashMap<>(); - - public Map<String, List<Object>> queryParams() { - return queryParams; - } - - public OpenStackRequest<R> queryParam(String key, Object value) { - if (value != null) { - if (queryParams.containsKey(key)) { - List<Object> values = queryParams.get(key); - values.add(value); - } else { - List<Object> values = new ArrayList<>(); - values.add(value); - queryParams.put(key, values); - } - } - return this; - } - - protected static String buildPath(String... elements) { - StringBuilder stringBuilder = new StringBuilder(); - for (String element : elements) { - stringBuilder.append(element); - } - - return stringBuilder.toString(); - } + public OpenStackRequest() { + + } + + public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity, + Class<R> returnType) { + this.client = client; + this.method = method; + this.path = new StringBuilder(path); + this.entity = entity; + this.returnType = returnType; + header("Accept", "application/json"); + } + + public OpenStackRequest<R> endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + public String endpoint() { + return endpoint; + } + + public OpenStackRequest<R> method(HttpMethod method) { + this.method = method; + return this; + } + + public HttpMethod method() { + return method; + } + + public OpenStackRequest<R> path(String path) { + this.path.append(path); + return this; + } + + public String path() { + return path.toString(); + } + + public OpenStackRequest<R> header(String name, Object value) { + if (value != null) { + headers.put(name, Arrays.asList(value)); + } + return this; + } + + public Map<String, List<Object>> headers() { + return headers; + } + + public <T> Entity<T> entity(T entity, String contentType) { + return new Entity<>(entity, contentType); + } + + public Entity<?> entity() { + return entity; + } + + public <T> Entity<T> json(T entity) { + return entity(entity, "application/json"); + } + + public void returnType(Class<R> returnType) { + this.returnType = returnType; + } + + public Class<R> returnType() { + return returnType; + } + + public R execute() { + return client.execute(this); + } + + public OpenStackResponse request() { + return client.request(this); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method + ", path=" + path + ", headers=" + + headers + ", entity=" + entity + ", returnType=" + returnType + "]"; + } + + private Map<String, List<Object>> queryParams = new LinkedHashMap<>(); + + public Map<String, List<Object>> queryParams() { + return queryParams; + } + + public OpenStackRequest<R> queryParam(String key, Object value) { + if (value != null) { + if (queryParams.containsKey(key)) { + List<Object> values = queryParams.get(key); + values.add(value); + } else { + List<Object> values = new ArrayList<>(); + values.add(value); + queryParams.put(key, values); + } + } + return this; + } + + protected static String buildPath(String... elements) { + StringBuilder stringBuilder = new StringBuilder(); + for (String element : elements) { + stringBuilder.append(element); + } + + return stringBuilder.toString(); + } } diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java index 0add524..dfc1d13 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java @@ -32,7 +32,7 @@ public interface OpenStackResponse { public InputStream getInputStream(); public String header(String name); - + public Map<String, String> headers(); - + } diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java index e8b1e87..1d7f29b 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java @@ -56,4 +56,4 @@ public class OpenStackResponseException extends OpenStackBaseException { return response; } -}
\ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java index 73204e9..aa552ad 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java @@ -18,7 +18,7 @@ package com.woorea.openstack.base.client; public class OpenStackResponseStatus { - private OpenStackResponseStatus(){ + private OpenStackResponseStatus() { } @@ -28,4 +28,4 @@ public class OpenStackResponseStatus { public static final int CONFLICT = 409; -}
\ No newline at end of file +} diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java index a7dd2e5..74b92a1 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java @@ -30,7 +30,6 @@ public class OpenStackSimpleTokenProvider implements OpenStackTokenProvider { } @Override - public void expireToken() { - } + public void expireToken() {} } diff --git a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java index 618adb5..edef0a9 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java +++ b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java @@ -14,4 +14,4 @@ * ============LICENSE_END========================================================= */ -package com.woorea.openstack.common.session;
\ No newline at end of file +package com.woorea.openstack.common.session; diff --git a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java index 618adb5..edef0a9 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java +++ b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java @@ -14,4 +14,4 @@ * ============LICENSE_END========================================================= */ -package com.woorea.openstack.common.session;
\ No newline at end of file +package com.woorea.openstack.common.session; diff --git a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java index 8ff2634..29580ba 100644 --- a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java +++ b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java @@ -63,9 +63,9 @@ public class OpenStackClientMockUtils { return this; } - public <T extends OpenStackRequest> OpenStackClientMockUtils mockRequestThrow(T request, String message, int status) { - Mockito.when(connector.request(Mockito.eq(request))) - .thenThrow(new OpenStackResponseException(message, status)); + public <T extends OpenStackRequest> OpenStackClientMockUtils mockRequestThrow(T request, String message, + int status) { + Mockito.when(connector.request(Mockito.eq(request))).thenThrow(new OpenStackResponseException(message, status)); return this; } diff --git a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java index 9a83903..e4a4098 100644 --- a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java +++ b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java @@ -43,11 +43,9 @@ public class OpenStackClientTest { } private OpenStackClientConnector mockClientConnector() { - return OpenStackClientMockUtils.getInstance() - .mockRequestResponse(Entity.class, Entity.json(SUCCESS)) + return OpenStackClientMockUtils.getInstance().mockRequestResponse(Entity.class, Entity.json(SUCCESS)) .mockRequestThrow(notAuthorizedRequest, "Not Authorized", OpenStackResponseStatus.NOT_AUTHORIZED) - .mockRequestThrow(conflictRequest, "Conflict", OpenStackResponseStatus.CONFLICT) - .getConnector(); + .mockRequestThrow(conflictRequest, "Conflict", OpenStackResponseStatus.CONFLICT).getConnector(); } @@ -69,4 +67,4 @@ public class OpenStackClientTest { public void executeConflict() { client.execute(conflictRequest); } -}
\ No newline at end of file +} |