diff options
Diffstat (limited to 'common')
16 files changed, 82 insertions, 267 deletions
diff --git a/common/pom.xml b/common/pom.xml index b9fd64e04e..7d468fae3f 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -16,11 +16,11 @@ </dependency> <dependency> <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> + <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> - <artifactId>spring-aspects</artifactId> + <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> @@ -29,10 +29,10 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> + </dependency> <dependency> <groupId>com.jayway.jsonpath</groupId> - <artifactId>json-path</artifactId> + <artifactId>json-path</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> @@ -49,7 +49,7 @@ <dependency> <groupId>org.onap.aai.aai-common</groupId> <artifactId>aai-schema</artifactId> - <version>1.3.1</version> + <version>1.4.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.modelmapper</groupId> @@ -85,7 +85,7 @@ <artifactId>commons-lang3</artifactId> </exclusion> </exclusions> - </dependency> + </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-ext</artifactId> @@ -106,7 +106,7 @@ </dependency> <dependency> <groupId>org.springframework.security</groupId> - <artifactId>spring-security-web</artifactId> + <artifactId>spring-security-web</artifactId> </dependency> <dependency> <groupId>org.onap.logging-analytics</groupId> diff --git a/common/src/main/java/org/onap/so/client/HttpClient.java b/common/src/main/java/org/onap/so/client/HttpClient.java index 12f19ac607..6f13a86237 100644 --- a/common/src/main/java/org/onap/so/client/HttpClient.java +++ b/common/src/main/java/org/onap/so/client/HttpClient.java @@ -34,10 +34,10 @@ public class HttpClient extends RestClient { protected final Logger log = LoggerFactory.getLogger(HttpClient.class); private TargetEntity targetEntity; - public HttpClient(URL host, String contentType, TargetEntity targetEntity) { + + HttpClient(URL host, String contentType, TargetEntity targetEntity) { super(host, contentType); this.targetEntity = targetEntity; - } @Override @@ -47,7 +47,6 @@ public class HttpClient extends RestClient { @Override protected void initializeHeaderMap(Map<String, String> headerMap) { - } @Override diff --git a/common/src/main/java/org/onap/so/client/grm/GRMDefaultPropertiesImpl.java b/common/src/main/java/org/onap/so/client/HttpClientFactory.java index b38072e769..d02c18ff56 100644 --- a/common/src/main/java/org/onap/so/client/grm/GRMDefaultPropertiesImpl.java +++ b/common/src/main/java/org/onap/so/client/HttpClientFactory.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018 Nokia. * ================================================================================ * 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. @@ -17,47 +17,23 @@ * limitations under the License. * ============LICENSE_END========================================================= */ +package org.onap.so.client; -package org.onap.so.client.grm; - -import java.net.MalformedURLException; import java.net.URL; - import javax.ws.rs.core.MediaType; +import org.onap.so.utils.TargetEntity; -public class GRMDefaultPropertiesImpl implements GRMProperties { - - public GRMDefaultPropertiesImpl() { - } - - @Override - public URL getEndpoint() throws MalformedURLException { - return new URL("http://localhost:47389"); - } - - @Override - public String getSystemName() { - return "MSO"; - } - - @Override - public String getDefaultVersion() { - return "v1"; - } - - @Override - public String getUsername() { - return "gmruser"; - } +public class HttpClientFactory { - @Override - public String getPassword() { - return "cGFzc3dvcmQ="; - } + public HttpClient newJsonClient(URL host, TargetEntity targetEntity) { + return new HttpClient(host, MediaType.APPLICATION_JSON, targetEntity); + } - @Override - public String getContentType() { - return MediaType.APPLICATION_JSON; - } + public HttpClient newXmlClient(URL host, TargetEntity targetEntity) { + return new HttpClient(host, MediaType.APPLICATION_XML, targetEntity); + } + public HttpClient newTextXmlClient(URL host, TargetEntity targetEntity) { + return new HttpClient(host, MediaType.TEXT_XML, targetEntity); + } } 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 ac4a8d1a7c..8369eba859 100644 --- a/common/src/main/java/org/onap/so/client/RestClientSSL.java +++ b/common/src/main/java/org/onap/so/client/RestClientSSL.java @@ -22,6 +22,7 @@ package org.onap.so.client; import java.io.FileInputStream; import java.net.URI; +import java.nio.file.Paths; import java.security.KeyStore; import java.security.NoSuchAlgorithmException; import java.util.Optional; @@ -72,7 +73,7 @@ public abstract class RestClientSSL extends RestClient { private KeyStore getKeyStore() { KeyStore ks = null; char[] password = System.getProperty(RestClientSSL.SSL_KEY_STORE_PASSWORD_KEY).toCharArray(); - try(FileInputStream fis = new FileInputStream(System.getProperty(RestClientSSL.SSL_KEY_STORE_KEY))) { + try(FileInputStream fis = new FileInputStream(Paths.get(System.getProperty(RestClientSSL.SSL_KEY_STORE_KEY)).normalize().toString())) { ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(fis, password); diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java index 51d09006db..f003dc0628 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java @@ -25,6 +25,7 @@ import java.util.Map; import org.onap.aai.annotations.Metadata; import org.onap.aai.domain.yang.AllottedResource; +import org.onap.aai.domain.yang.AggregateRoute; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.Collection; import org.onap.aai.domain.yang.Complex; @@ -113,6 +114,7 @@ public enum AAIObjectType implements GraphInventoryObjectType { SP_PARTNER(AAINamespaceConstants.BUSINESS, SpPartner.class), DEVICE(AAINamespaceConstants.NETWORK, Device.class), EXT_AAI_NETWORK(AAINamespaceConstants.NETWORK, ExtAaiNetwork.class), + AGGREGATE_ROUTE(AAINamespaceConstants.NETWORK, AggregateRoute.class), UNKNOWN("", ""); private final String uriTemplate; diff --git a/common/src/main/java/org/onap/so/client/grm/GRMClient.java b/common/src/main/java/org/onap/so/client/grm/GRMClient.java index 84e25b9ce4..653e1cc7b3 100644 --- a/common/src/main/java/org/onap/so/client/grm/GRMClient.java +++ b/common/src/main/java/org/onap/so/client/grm/GRMClient.java @@ -53,7 +53,7 @@ public class GRMClient { } } - protected ServiceEndPointLookupRequest buildServiceEndPointlookupRequest(String name, int majorVersion, String env) { + public ServiceEndPointLookupRequest buildServiceEndPointlookupRequest(String name, int majorVersion, String env) { VersionLookup version = new VersionLookup(); version.setMajor(majorVersion); diff --git a/common/src/main/java/org/onap/so/client/grm/GRMProperties.java b/common/src/main/java/org/onap/so/client/grm/GRMProperties.java index da9f215aac..1206896bf9 100644 --- a/common/src/main/java/org/onap/so/client/grm/GRMProperties.java +++ b/common/src/main/java/org/onap/so/client/grm/GRMProperties.java @@ -24,7 +24,7 @@ import org.onap.so.client.RestProperties; public interface GRMProperties extends RestProperties { public String getDefaultVersion(); - public String getUsername(); - public String getPassword(); + public String getAuth(); + public String getKey(); public String getContentType(); } diff --git a/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java b/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java index ce16ccaaaa..0bb55e627a 100644 --- a/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java +++ b/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java @@ -32,13 +32,11 @@ import org.onap.so.utils.TargetEntity; public class GRMRestClient extends RestClient { - private final String username; - private final String password; + private final GRMProperties properties; - public GRMRestClient(RestProperties props, URI path, String username, String password) { - super(props, Optional.of(path)); - this.username = username; - this.password = password; + public GRMRestClient(GRMProperties props, URI path) { + super(props, Optional.of(path)); + this.properties = props; } @Override @@ -48,7 +46,12 @@ public class GRMRestClient extends RestClient { @Override protected void initializeHeaderMap(Map<String, String> headerMap) { - headerMap.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(new String(username + ":" + password).getBytes())); + String auth = properties.getAuth(); + String key = properties.getKey(); + + if (auth != null && !auth.isEmpty() && key != null && !key.isEmpty()) { + addBasicAuthHeader(auth, key); + } } } diff --git a/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java b/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java index 3045cb35f4..0c95a66979 100644 --- a/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java +++ b/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java @@ -21,7 +21,6 @@ package org.onap.so.client.grm; import java.net.URI; -import java.util.Base64; import javax.ws.rs.core.UriBuilder; @@ -34,11 +33,8 @@ public class GRMRestInvoker { public GRMRestInvoker(GRMAction action) { GRMProperties props = GRMPropertiesLoader.getInstance().getImpl(); - if (props == null) { - props = new GRMDefaultPropertiesImpl(); - } this.properties = props; - this.client = new GRMRestClient(this.properties, this.createURI(action), this.properties.getUsername(), this.decode(this.properties.getPassword())); + this.client = new GRMRestClient(properties, this.createURI(action)); } private URI createURI(GRMAction action) { @@ -49,15 +45,6 @@ public class GRMRestInvoker { .build(); } - private String decode(String cred) { - try { - return new String(Base64.getDecoder().decode(cred.getBytes())); - } - catch(IllegalArgumentException iae) { - return cred; - } - } - private RestClient getClient() { return this.client; } diff --git a/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java b/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java index 6f415af8b0..8154b9137d 100644 --- a/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java +++ b/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java @@ -154,6 +154,6 @@ public class SDNOHealthCheckDmaapConsumer extends DmaapConsumer { @Override public int getMaximumElapsedTime() { - return 300000; + return 600000; } } diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/InstanceReferences.java b/common/src/main/java/org/onap/so/serviceinstancebeans/InstanceReferences.java index 69d21c41ac..72374e0580 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/InstanceReferences.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/InstanceReferences.java @@ -39,6 +39,8 @@ public class InstanceReferences { protected String networkInstanceId; protected String networkInstanceName; protected String requestorId; + protected String instanceGroupId; + protected String instanceGroupName; public String getServiceInstanceId() { @@ -109,6 +111,18 @@ public class InstanceReferences { public void setRequestorId(String requestorId) { this.requestorId = requestorId; } + public String getInstanceGroupId() { + return instanceGroupId; + } + public void setInstanceGroupId(String instanceGroupId) { + this.instanceGroupId = instanceGroupId; + } + public String getInstanceGroupName() { + return instanceGroupName; + } + public void setInstanceGroupName(String instanceGroupName) { + this.instanceGroupName = instanceGroupName; + } @Override public String toString() { return new ToStringBuilder(this).append("serviceInstanceId", serviceInstanceId) @@ -118,6 +132,7 @@ public class InstanceReferences { .append("volumeGroupInstanceId", volumeGroupInstanceId) .append("volumeGroupInstanceName", volumeGroupInstanceName) .append("networkInstanceId", networkInstanceId).append("networkInstanceName", networkInstanceName) - .append("requestorId", requestorId).toString(); + .append("requestorId", requestorId).append("instanceGroupId", instanceGroupId) + .append("instanceGroupName", instanceGroupName).toString(); } } diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java index 527aa037ed..8adce38ada 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java @@ -31,6 +31,7 @@ public class RequestStatus { protected String statusMessage; protected Integer percentProgress; protected String finishTime; + protected String timeStamp; public String getRequestState() { @@ -57,9 +58,15 @@ public class RequestStatus { public void setFinishTime(String finishTime) { this.finishTime = finishTime; } + public String getTimeStamp() { + return timeStamp; + } + public void setTimeStamp(String timeStamp) { + this.timeStamp = timeStamp; + } @Override public String toString() { return new ToStringBuilder(this).append("requestState", requestState).append("statusMessage", statusMessage) - .append("percentProgress", percentProgress).append("finishTime", finishTime).toString(); + .append("percentProgress", percentProgress).append("finishTime", finishTime).append("timeStamp", timeStamp).toString(); } } diff --git a/common/src/test/java/org/onap/so/client/HttpClientTest.java b/common/src/test/java/org/onap/so/client/HttpClientTest.java index 221005cb7c..75ce5f322f 100644 --- a/common/src/test/java/org/onap/so/client/HttpClientTest.java +++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java @@ -30,22 +30,21 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.net.MalformedURLException; import java.net.URL; - import org.junit.Rule; import org.junit.Test; import org.onap.so.utils.TargetEntity; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - public class HttpClientTest{ + private final HttpClientFactory httpClientFactory = new HttpClientFactory(); @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicHttpsPort()); - @Test(expected = Test.None.class) + @Test public void testPost_success() throws MalformedURLException{ stubFor(post(urlEqualTo("/services/sdnc/post")) @@ -54,7 +53,7 @@ public class HttpClientTest{ .withBody(""))); URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); - HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN); + HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN); client.addBasicAuthHeader("97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF", "123"); client.addAdditionalHeader("Accept", "application/json"); @@ -64,7 +63,7 @@ public class HttpClientTest{ verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post"))); } - @Test(expected = Test.None.class) + @Test public void testPost_nullHeader() throws MalformedURLException{ stubFor(post(urlEqualTo("/services/sdnc/post")) @@ -73,7 +72,7 @@ public class HttpClientTest{ .withBody(""))); URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); - HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN); + HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN); client.addAdditionalHeader("Accept", "application/json"); client.addAdditionalHeader("id", null); @@ -84,7 +83,7 @@ public class HttpClientTest{ .withHeader("Accept", equalTo("application/json"))); } - @Test(expected = Test.None.class) + @Test public void testPost_nullBasicAuth() throws MalformedURLException{ stubFor(post(urlEqualTo("/services/sdnc/post")) @@ -93,7 +92,7 @@ public class HttpClientTest{ .withBody(""))); URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); - HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN); + HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN); client.addBasicAuthHeader("", "12345"); client.addAdditionalHeader("Accept", "application/json"); 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 6fca4a1820..06196fd73e 100644 --- a/common/src/test/java/org/onap/so/client/RestClientTest.java +++ b/common/src/test/java/org/onap/so/client/RestClientTest.java @@ -47,11 +47,12 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class RestClientTest { - + + private final HttpClientFactory httpClientFactory = new HttpClientFactory(); @Mock private RestProperties props; - - + + @Test public void retries() throws Exception { RestClient spy = buildSpy(); @@ -82,7 +83,8 @@ public class RestClientTest { } private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException { - RestClient client = new HttpClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), "application/json", TargetEntity.BPMN); + RestClient client = httpClientFactory + .newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), TargetEntity.BPMN); return spy(client); } diff --git a/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java b/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java index e1afa82e1e..c0633c1cca 100644 --- a/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java +++ b/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java @@ -45,7 +45,7 @@ public class DmaapPublisherTest { @Override public Optional<String> getHost() { - return Optional.of("http://localhost:8080"); + return Optional.of("http://test"); } }; diff --git a/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java b/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java deleted file mode 100644 index 388e89a438..0000000000 --- a/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.client.grm; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; -import static com.github.tomakehurst.wiremock.client.WireMock.matching; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.client.WireMock.verify; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.io.File; -import java.nio.file.Files; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - - -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.onap.so.client.grm.beans.ServiceEndPoint; -import org.onap.so.client.grm.beans.ServiceEndPointList; -import org.onap.so.client.grm.beans.ServiceEndPointLookupRequest; -import org.onap.so.client.grm.beans.ServiceEndPointRequest; -import org.onap.so.client.grm.exceptions.GRMClientCallFailed; -import org.onap.so.utils.TestAppender; -import org.slf4j.MDC; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -import ch.qos.logback.classic.spi.ILoggingEvent; - -public class GRMClientTest { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(47389)); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String uuidRegex = "(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-5][0-9a-f]{3}-?[089ab][0-9a-f]{3}-?[0-9a-f]{12}$"; - - @BeforeClass - public static void setUp() throws Exception { - System.setProperty("mso.config.path", "src/test/resources"); - } - - @Test - public void testFind() throws Exception { - TestAppender.events.clear(); - String endpoints = getFileContentsAsString("__files/grm/endpoints.json"); - wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody(endpoints))); - - MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, "/test"); - GRMClient client = new GRMClient(); - ServiceEndPointList sel = client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); - List<ServiceEndPoint> list = sel.getServiceEndPointList(); - assertEquals(3, list.size()); - - boolean foundInvoke = false; - boolean foundInvokeReturn = false; - for(ILoggingEvent logEvent : TestAppender.events) - if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") && - logEvent.getMarker().getName().equals("INVOKE") - ){ - Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - assertEquals("GRM",mdc.get("TargetEntity")); - assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - foundInvoke=true; - }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") && - logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("INVOKE_RETURN")){ - Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - assertEquals("200",mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); - assertEquals("COMPLETED",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - foundInvokeReturn=true; - } - - if(!foundInvoke) - fail("INVOKE Marker not found"); - - if(!foundInvokeReturn) - fail("INVOKE RETURN Marker not found"); - - verify(postRequestedFor(urlEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) - .withHeader(ONAPLogConstants.Headers.INVOCATION_ID.toString(), matching(uuidRegex)) - .withHeader(ONAPLogConstants.Headers.REQUEST_ID.toString(), matching(uuidRegex)) - .withHeader(ONAPLogConstants.Headers.PARTNER_NAME.toString(), equalTo("SO"))); - TestAppender.events.clear(); - } - - @Test - public void testFindFail() throws Exception { - - wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) - .willReturn(aResponse() - .withStatus(400) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody(""))); - - GRMClient client = new GRMClient(); - thrown.expect(GRMClientCallFailed.class); - client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); - } - - @Test - public void testAddFail() throws Exception { - wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")) - .willReturn(aResponse() - .withStatus(404) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody("test"))); - ServiceEndPointRequest request = new ServiceEndPointRequest(); - GRMClient client = new GRMClient(); - thrown.expect(GRMClientCallFailed.class); - client.addServiceEndPoint(request); - } - - @Test - public void testBuildServiceEndPointLookupRequest() { - GRMClient client = new GRMClient(); - ServiceEndPointLookupRequest request = client.buildServiceEndPointlookupRequest("TEST.ECOMP_PSL.Inventory", 1, "DEV"); - assertEquals("TEST.ECOMP_PSL.Inventory", request.getServiceEndPoint().getName()); - assertEquals(Integer.valueOf(1), Integer.valueOf(request.getServiceEndPoint().getVersion().getMajor())); - assertEquals("DEV", request.getEnv()); - - } - - protected String getFileContentsAsString(String fileName) { - String content = ""; - try { - ClassLoader classLoader = this.getClass().getClassLoader(); - File file = new File(classLoader.getResource(fileName).getFile()); - content = new String(Files.readAllBytes(file.toPath())); - } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); - } - return content; - } -} |