aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/pom.xml32
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/ActDeActNssi.java5
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java2
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/CustomerInfo.java45
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/NssInstance.java (renamed from common/src/main/java/org/onap/so/beans/nsmf/NSSI.java)40
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java4
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/OperationType.java59
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/OrchestrationStatusEnum.java36
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java26
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/ResponseDescriptor.java1
-rw-r--r--common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java6
-rw-r--r--common/src/main/java/org/onap/so/client/AddCacheHeaders.java28
-rw-r--r--common/src/main/java/org/onap/so/client/CacheFactory.java25
-rw-r--r--common/src/main/java/org/onap/so/client/CacheProperties.java13
-rw-r--r--common/src/main/java/org/onap/so/client/RestClient.java20
-rw-r--r--common/src/main/java/org/onap/so/client/RestClientSSL.java2
-rw-r--r--common/src/main/java/org/onap/so/client/RestProperties.java17
-rw-r--r--common/src/main/java/org/onap/so/security/SoCadiFilter.java2
-rw-r--r--common/src/test/java/org/onap/so/client/RestClientTest.java63
-rw-r--r--common/src/test/resources/logback-test.xml91
20 files changed, 418 insertions, 99 deletions
diff --git a/common/pom.xml b/common/pom.xml
index 74e51805ad..08f797d7e5 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -135,8 +135,11 @@
</dependency>
<dependency>
<groupId>org.onap.aaf.authz</groupId>
+ <artifactId>aaf-cadi-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.aaf.authz</groupId>
<artifactId>aaf-cadi-aaf</artifactId>
- <version>${aaf.cadi.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
@@ -149,6 +152,21 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>org.onap.aaf.authz</groupId>
+ <artifactId>aaf-auth-client</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.aaf.authz</groupId>
+ <artifactId>aaf-misc-env</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.aaf.authz</groupId>
+ <artifactId>aaf-misc-rosetta</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
@@ -293,6 +311,16 @@
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
+ <dependency>
+ <groupId>javax.cache</groupId>
+ <artifactId>cache-api</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <version>3.8.1</version>
+ </dependency>
</dependencies>
<dependencyManagement>
<dependencies>
@@ -366,4 +394,4 @@
</plugin>
</plugins>
</build>
-</project> \ No newline at end of file
+</project>
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/ActDeActNssi.java b/common/src/main/java/org/onap/so/beans/nsmf/ActDeActNssi.java
index ed82500210..b14cf7e94d 100644
--- a/common/src/main/java/org/onap/so/beans/nsmf/ActDeActNssi.java
+++ b/common/src/main/java/org/onap/so/beans/nsmf/ActDeActNssi.java
@@ -20,16 +20,19 @@
package org.onap.so.beans.nsmf;
+import java.io.Serializable;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
-public class ActDeActNssi {
+public class ActDeActNssi implements Serializable {
public final static String ACT_URL = "/api/rest/provMns/v1/NSS/%s" + "/activation";
public final static String DE_ACT_URL = "/api/rest/provMns/v1/NSS/%s" + "/deactivation";
+ private static final long serialVersionUID = 7597630091910711349L;
+
private String nsiId;
private String nssiId;
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java
index 5edeb7e74f..3d0f70805c 100644
--- a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java
+++ b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java
@@ -32,7 +32,7 @@ import java.util.List;
@ToString
public class AnSliceProfile implements Serializable {
/*
- * Reference 3GPP TS 28.541 V16.5.0, Section 6.3.4.
+ * Reference 3GPP TS 28.541 V16.5.0.
*/
private static final long serialVersionUID = -3057342171549542794L;
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/CustomerInfo.java b/common/src/main/java/org/onap/so/beans/nsmf/CustomerInfo.java
new file mode 100644
index 0000000000..6381d5b6e2
--- /dev/null
+++ b/common/src/main/java/org/onap/so/beans/nsmf/CustomerInfo.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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 org.onap.so.beans.nsmf;
+
+import lombok.Builder;
+import lombok.Data;
+import java.io.Serializable;
+
+@Data
+@Builder
+public class CustomerInfo implements Serializable {
+ private static final long serialVersionUID = -8749985097619384358L;
+
+ private String globalSubscriberId;
+
+ private String serviceInstanceId;
+
+ private String subscriptionServiceType;
+
+ private String operationId;
+
+ private OperationType operationType;
+
+ private String nsiId;
+
+ private String snssai;
+
+}
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/NSSI.java b/common/src/main/java/org/onap/so/beans/nsmf/NssInstance.java
index a57458f2cf..396e8fce45 100644
--- a/common/src/main/java/org/onap/so/beans/nsmf/NSSI.java
+++ b/common/src/main/java/org/onap/so/beans/nsmf/NssInstance.java
@@ -20,7 +20,15 @@
package org.onap.so.beans.nsmf;
-public class NSSI {
+import lombok.Builder;
+import lombok.Data;
+import java.io.Serializable;
+
+@Data
+@Builder
+public class NssInstance implements Serializable {
+
+ private static final long serialVersionUID = -153484249182203537L;
private String nssiId;
@@ -28,33 +36,11 @@ public class NSSI {
private String modelVersionId;
- public NSSI(String nssiId, String modelInvariantId, String modelVersionId) {
- this.nssiId = nssiId;
- this.modelInvariantId = modelInvariantId;
- this.modelVersionId = modelVersionId;
- }
-
- public String getNssiId() {
- return nssiId;
- }
-
- public void setNssiId(String nssiId) {
- this.nssiId = nssiId;
- }
-
- public String getModelInvariantId() {
- return modelInvariantId;
- }
+ private NetworkType networkType;
- public void setModelInvariantId(String modelInvariantId) {
- this.modelInvariantId = modelInvariantId;
- }
+ private OperationType operationType;
- public String getModelVersionId() {
- return modelVersionId;
- }
+ private String snssai;
- public void setModelVersionId(String modelVersionId) {
- this.modelVersionId = modelVersionId;
- }
+ private String serviceType;
}
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java b/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java
index 3292730f29..356c1cb4de 100644
--- a/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java
+++ b/common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java
@@ -37,7 +37,7 @@ public class NssmfRequest implements Serializable {
private String globalSubscriberId;
- private String serviceInstanceId;
+ private String serviceInstanceID;
private String subscriptionServiceType;
@@ -54,7 +54,7 @@ public class NssmfRequest implements Serializable {
this.subscriptionServiceType = serviceInfo.getSubscriptionServiceType();
this.networkType = networkType;
this.additionalProperties = additionalProperties;
- this.serviceInstanceId = serviceInfo.getNssiId();
+ this.serviceInstanceID = serviceInfo.getNssiId();
this.name = serviceInfo.getNssiName();
}
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/OperationType.java b/common/src/main/java/org/onap/so/beans/nsmf/OperationType.java
new file mode 100644
index 0000000000..1ee56b5ca0
--- /dev/null
+++ b/common/src/main/java/org/onap/so/beans/nsmf/OperationType.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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 org.onap.so.beans.nsmf;
+
+import lombok.Getter;
+import lombok.ToString;
+
+@Getter
+@ToString
+public enum OperationType {
+ /**
+ * allocate
+ */
+ ALLOCATE("allocate"),
+
+ DEALLOCATE("deallocate"),
+
+ CREATE("create"),
+
+ TERMINATE("terminate"),
+
+ ACTIVATE("activation"),
+
+ DEACTIVATE("deactivation");
+
+ private String type;
+
+
+ OperationType(String type) {
+ this.type = type;
+ }
+
+ public static OperationType getOperationType(String value) {
+ for (OperationType operationType : OperationType.values()) {
+ if (operationType.type.equalsIgnoreCase(value)) {
+ return operationType;
+ }
+ }
+ return null;
+ }
+}
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/OrchestrationStatusEnum.java b/common/src/main/java/org/onap/so/beans/nsmf/OrchestrationStatusEnum.java
new file mode 100644
index 0000000000..572a312265
--- /dev/null
+++ b/common/src/main/java/org/onap/so/beans/nsmf/OrchestrationStatusEnum.java
@@ -0,0 +1,36 @@
+package org.onap.so.beans.nsmf;
+
+import lombok.Getter;
+import lombok.ToString;
+
+@Getter
+@ToString
+public enum OrchestrationStatusEnum {
+ /**
+ * activated
+ */
+ ACTIVATED("activated"),
+
+ /**
+ * deactivated
+ */
+ DEACTIVATED("deactivated"),
+
+ ;
+
+ private String value;
+
+
+ OrchestrationStatusEnum(String value) {
+ this.value = value;
+ }
+
+ public static OrchestrationStatusEnum getStatus(String value) {
+ for (OrchestrationStatusEnum orchestrationStatus : OrchestrationStatusEnum.values()) {
+ if (orchestrationStatus.value.equalsIgnoreCase(value)) {
+ return orchestrationStatus;
+ }
+ }
+ return null;
+ }
+}
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java b/common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java
index 7485b387d8..6b30af9339 100644
--- a/common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java
+++ b/common/src/main/java/org/onap/so/beans/nsmf/QuerySubnetCapability.java
@@ -2,19 +2,19 @@
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
- * Copyright (C) 2020 Wipro Limited.
- * ================================================================================
- * 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.
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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=========================================================
*/
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/ResponseDescriptor.java b/common/src/main/java/org/onap/so/beans/nsmf/ResponseDescriptor.java
index 17ef210c4e..ab9399eec9 100644
--- a/common/src/main/java/org/onap/so/beans/nsmf/ResponseDescriptor.java
+++ b/common/src/main/java/org/onap/so/beans/nsmf/ResponseDescriptor.java
@@ -49,5 +49,4 @@ public class ResponseDescriptor implements Serializable {
private String nssiId;
- private String endPointId;
}
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java b/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java
index f9848fca31..5146685058 100644
--- a/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java
+++ b/common/src/main/java/org/onap/so/beans/nsmf/ServiceInfo.java
@@ -20,11 +20,17 @@
package org.onap.so.beans.nsmf;
import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Data;
+import lombok.NoArgsConstructor;
import java.io.Serializable;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
public class ServiceInfo implements Serializable {
private static final long serialVersionUID = 7895110339097615695L;
diff --git a/common/src/main/java/org/onap/so/client/AddCacheHeaders.java b/common/src/main/java/org/onap/so/client/AddCacheHeaders.java
new file mode 100644
index 0000000000..1a41be1233
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/AddCacheHeaders.java
@@ -0,0 +1,28 @@
+package org.onap.so.client;
+
+import java.io.IOException;
+import java.util.Collections;
+import javax.annotation.Priority;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Priority(1)
+public class AddCacheHeaders implements ClientResponseFilter {
+
+ private final CacheProperties props;
+
+ public AddCacheHeaders(CacheProperties props) {
+ this.props = props;
+ }
+
+ public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException {
+ if (request.getMethod().equalsIgnoreCase("GET")) {
+ response.getHeaders().putIfAbsent("Cache-Control",
+ Collections.singletonList("public, max-age=" + (props.getMaxAge() / 1000)));
+ }
+
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/CacheFactory.java b/common/src/main/java/org/onap/so/client/CacheFactory.java
new file mode 100644
index 0000000000..6bc4858463
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/CacheFactory.java
@@ -0,0 +1,25 @@
+package org.onap.so.client;
+
+
+import java.util.concurrent.TimeUnit;
+import javax.cache.configuration.Factory;
+import javax.cache.expiry.Duration;
+import javax.cache.expiry.ExpiryPolicy;
+import javax.cache.expiry.TouchedExpiryPolicy;
+
+public class CacheFactory implements Factory<ExpiryPolicy> {
+
+ private static final long serialVersionUID = 8948728679233836929L;
+
+ private final CacheProperties props;
+
+ public CacheFactory(CacheProperties props) {
+ this.props = props;
+ }
+
+ @Override
+ public ExpiryPolicy create() {
+ return TouchedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, props.getMaxAge())).create();
+ }
+
+}
diff --git a/common/src/main/java/org/onap/so/client/CacheProperties.java b/common/src/main/java/org/onap/so/client/CacheProperties.java
new file mode 100644
index 0000000000..4fb2a87a5b
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/CacheProperties.java
@@ -0,0 +1,13 @@
+package org.onap.so.client;
+
+public interface CacheProperties {
+
+
+ default Long getMaxAge() {
+ return 60000L;
+ }
+
+ default String getCacheName() {
+ return "default-http-cache";
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/RestClient.java b/common/src/main/java/org/onap/so/client/RestClient.java
index ece1333f83..be0a0f3f9e 100644
--- a/common/src/main/java/org/onap/so/client/RestClient.java
+++ b/common/src/main/java/org/onap/so/client/RestClient.java
@@ -34,10 +34,12 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.ResponseProcessingException;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
@@ -186,8 +188,20 @@ public abstract class RestClient {
return APPLICATION_MERGE_PATCH_JSON;
}
+ protected ClientBuilder getClientBuilder() {
+ ClientBuilder builder = ClientBuilder.newBuilder();
+ if (props.isCachingEnabled()) {
+ enableCaching(builder);
+ }
+ return builder.readTimeout(props.getReadTimeout(), TimeUnit.MILLISECONDS);
+ }
+
+ protected ClientBuilder enableCaching(ClientBuilder builder) {
+ return builder;
+ }
+
protected Client getClient() {
- return ClientBuilder.newBuilder().build();
+ return getClientBuilder().build();
}
protected abstract ONAPComponentsList getTargetEntity();
@@ -201,7 +215,6 @@ public abstract class RestClient {
metricLogClientFilter = new SOMetricLogClientFilter();
mdcSetup.setTargetEntity(getTargetEntity());
client.register(metricLogClientFilter);
-
if (!path.isPresent()) {
webTarget = client.target(host.toString());
} else {
@@ -225,6 +238,9 @@ public abstract class RestClient {
result.add(e -> {
return e.getCause() instanceof ConnectException;
});
+ result.add(e -> {
+ return e.getCause() instanceof ResponseProcessingException;
+ });
return result;
}
diff --git a/common/src/main/java/org/onap/so/client/RestClientSSL.java b/common/src/main/java/org/onap/so/client/RestClientSSL.java
index 1e8953892e..c6252e4652 100644
--- a/common/src/main/java/org/onap/so/client/RestClientSSL.java
+++ b/common/src/main/java/org/onap/so/client/RestClientSSL.java
@@ -56,7 +56,7 @@ public abstract class RestClientSSL extends RestClient {
}
}
// Use default SSL context
- client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()).build();
+ client = getClientBuilder().sslContext(SSLContext.getDefault()).build();
logger.info("RestClientSSL using default SSL context!");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
diff --git a/common/src/main/java/org/onap/so/client/RestProperties.java b/common/src/main/java/org/onap/so/client/RestProperties.java
index 9e4e99cb4e..a7a0ef614c 100644
--- a/common/src/main/java/org/onap/so/client/RestProperties.java
+++ b/common/src/main/java/org/onap/so/client/RestProperties.java
@@ -40,4 +40,21 @@ public interface RestProperties {
public default boolean mapNotFoundToEmpty() {
return false;
}
+
+ /**
+ * Time in milliseconds
+ *
+ * @return
+ */
+ public default Long getReadTimeout() {
+ return Long.valueOf(60000);
+ }
+
+ public default boolean isCachingEnabled() {
+ return false;
+ }
+
+ public default CacheProperties getCacheProperties() {
+ return new CacheProperties() {};
+ }
}
diff --git a/common/src/main/java/org/onap/so/security/SoCadiFilter.java b/common/src/main/java/org/onap/so/security/SoCadiFilter.java
index 2763d6ee15..06d0795d86 100644
--- a/common/src/main/java/org/onap/so/security/SoCadiFilter.java
+++ b/common/src/main/java/org/onap/so/security/SoCadiFilter.java
@@ -22,6 +22,7 @@
*/
package org.onap.so.security;
+import javax.annotation.Priority;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import org.onap.aaf.cadi.config.Config;
@@ -34,6 +35,7 @@ import org.springframework.stereotype.Component;
@Component
@Profile("!test & aaf")
+@Priority(0)
public class SoCadiFilter extends CadiFilter {
protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class);
diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java
index cd00a9e4de..d40576b69f 100644
--- a/common/src/test/java/org/onap/so/client/RestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/RestClientTest.java
@@ -21,6 +21,8 @@
package org.onap.so.client;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
@@ -28,7 +30,13 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Optional;
import javax.ws.rs.NotFoundException;
+import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriBuilderException;
@@ -37,21 +45,26 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
-import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.logging.filter.base.ONAPComponents;
+import org.onap.logging.filter.base.ONAPComponentsList;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
@RunWith(MockitoJUnitRunner.class)
public class RestClientTest {
private final HttpClientFactory httpClientFactory = new HttpClientFactory();
- @Mock
- private RestProperties props;
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(
+ WireMockConfiguration.options().dynamicPort().extensions(new ResponseTemplateTransformer(false)));
+
@Test
public void retries() throws Exception {
RestClient spy = buildSpy();
@@ -80,6 +93,50 @@ public class RestClientTest {
}
+ @Test
+ public void timeoutTest() throws URISyntaxException {
+ wireMockRule.stubFor(get("/chunked/delayed")
+ .willReturn(aResponse().withStatus(200).withBody("Hello world!").withChunkedDribbleDelay(2, 300)));
+
+
+ RestProperties props = new RestProperties() {
+
+ @Override
+ public URL getEndpoint() throws MalformedURLException {
+ return new URL(String.format("http://localhost:%s", wireMockRule.port()));
+ }
+
+ @Override
+ public String getSystemName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Long getReadTimeout() {
+ return Long.valueOf(100);
+ }
+ };
+ RestClient client = new RestClient(props, Optional.of(new URI("/chunked/delayed"))) {
+
+ @Override
+ protected void initializeHeaderMap(Map<String, String> headerMap) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected ONAPComponentsList getTargetEntity() {
+ return ONAPComponents.EXTERNAL;
+ }
+
+ };
+
+ thrown.expect(ProcessingException.class);
+ client.get();
+
+ }
+
private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException {
RestClient client = httpClientFactory.newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(),
ONAPComponents.BPMN);
diff --git a/common/src/test/resources/logback-test.xml b/common/src/test/resources/logback-test.xml
index b52e6be022..3c5f259817 100644
--- a/common/src/test/resources/logback-test.xml
+++ b/common/src/test/resources/logback-test.xml
@@ -19,61 +19,60 @@
-->
<configuration>
- <property name="p_tim" value="%d{&quot;yyyy-MM-dd'T'HH:mm:ss.SSSXXX&quot;, UTC}"/>
- <property name="p_lvl" value="%level"/>
- <property name="p_log" value="%logger"/>
- <property name="p_mdc" value="%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}"/>
- <property name="p_msg" value="%replace(%replace(%msg){'\t', '\\\\t'}){'\n','\\\\n'}"/>
- <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}"/>
- <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/>
- <property name="p_thr" value="%thread"/>
- <property name="pattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/>
+ <property name="p_tim" value="%d{&quot;yyyy-MM-dd'T'HH:mm:ss.SSSXXX&quot;, UTC}" />
+ <property name="p_lvl" value="%level" />
+ <property name="p_log" value="%logger" />
+ <property name="p_mdc" value="%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}" />
+ <property name="p_msg" value="%replace(%replace(%msg){'\t', '\\\\t'}){'\n','\\\\n'}" />
+ <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}" />
+ <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}" />
+ <property name="p_thr" value="%thread" />
+ <property name="pattern"
+ value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n" />
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>${pattern}</pattern>
- </encoder>
- </appender>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>${pattern}</pattern>
+ </encoder>
+ </appender>
- <appender name="test"
- class="org.onap.so.utils.TestAppender" />
+ <appender name="test" class="org.onap.so.utils.TestAppender" />
- <logger name="com.att.ecomp.audit" level="info" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
+ <logger name="com.att.ecomp.audit" level="info" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
- <logger name="com.att.eelf.metrics" level="info" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
+ <logger name="com.att.eelf.metrics" level="info" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
- <logger name="com.att.eelf.error" level="WARN" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
+ <logger name="com.att.eelf.error" level="WARN" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
- <logger name="org.onap" level="${so.log.level:-DEBUG}" additivity="false">
- <appender-ref ref="STDOUT" />
- <appender-ref ref="test" />
- </logger>
-
- <logger name="org.flywaydb" level="DEBUG" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-
+ <logger name="org.onap" level="${so.log.level:-DEBUG}" additivity="false">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="test" />
+ </logger>
- <logger name="ch.vorburger" level="WARN" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-
- <logger name="org.reflections" level="ERROR" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-
+ <logger name="org.flywaydb" level="DEBUG" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
- <root level="WARN">
- <appender-ref ref="STDOUT" />
- <appender-ref ref="test" />
- </root>
+
+ <logger name="ch.vorburger" level="WARN" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.reflections" level="ERROR" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <root level="WARN">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="test" />
+ </root>
</configuration> \ No newline at end of file