use logging interceptor in SDC client
[vid.git] / vid-app-common / src / test / java / org / onap / vid / asdc / rest / SdcRestClientITTest.java
index 2ef3374..3a76a33 100644 (file)
@@ -2,14 +2,14 @@
  * ============LICENSE_START=======================================================
  * VID
  * ================================================================================
- * Copyright (C) 2018 Nokia Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 - 2019 Nokia 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.
 
 package org.onap.vid.asdc.rest;
 
+import static com.xebialabs.restito.semantics.Action.ok;
+import static com.xebialabs.restito.semantics.Action.stringContent;
+import static org.apache.http.client.config.RequestConfig.custom;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalToIgnoringCase;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.hamcrest.collection.IsMapContaining.hasKey;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.onap.vid.client.SyncRestClientInterface.HEADERS.X_ECOMP_INSTANCE_ID;
+
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.xebialabs.restito.semantics.Call;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.GeneralSecurityException;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.UUID;
+import javax.net.ssl.SSLContext;
 import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.socket.ConnectionSocketFactory;
@@ -38,27 +58,7 @@ import org.onap.vid.asdc.AsdcCatalogException;
 import org.onap.vid.asdc.beans.Service;
 import org.onap.vid.client.SyncRestClient;
 import org.onap.vid.testUtils.StubServerUtil;
-
-import javax.net.ssl.SSLContext;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.security.GeneralSecurityException;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.UUID;
-
-import static com.xebialabs.restito.semantics.Action.ok;
-import static com.xebialabs.restito.semantics.Action.stringContent;
-import static org.apache.http.client.config.RequestConfig.custom;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasItems;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.matchesPattern;
-import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.junit.Assert.assertTrue;
-import static org.onap.vid.client.SyncRestClientInterface.HEADERS.X_ECOMP_INSTANCE_ID;
-import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
+import org.onap.vid.utils.Logging;
 
 
 public class SdcRestClientITTest {
@@ -71,9 +71,9 @@ public class SdcRestClientITTest {
     public static void setUpClass() throws GeneralSecurityException {
         stubServer = new StubServerUtil();
         stubServer.runSecuredServer();
-        SyncRestClient syncRestClient = new SyncRestClient(createNaiveHttpClient());
+        SyncRestClient syncRestClient = new SyncRestClient(createNaiveHttpClient(), mock(Logging.class));
         String serverUrl = stubServer.constructTargetUrl("https", "");
-        sdcRestClient = new SdcRestClient(serverUrl, "", syncRestClient);
+        sdcRestClient = new SdcRestClient(serverUrl, "", syncRestClient, mock(Logging.class));
     }
 
     @AfterClass
@@ -87,7 +87,7 @@ public class SdcRestClientITTest {
         String expectedEndpoint = String.format("/sdc/v1/catalog/services/%s/toscaModel", uuid);
 
         stubServer.prepareGetCall(
-                expectedEndpoint, stringContent("sampleFileContent"), "sampleFileContent", ok(), "application/octet-stream");
+                expectedEndpoint, stringContent("sampleFileContent"), ok(), "application/octet-stream");
 
 
         Path serviceToscaModel = sdcRestClient.getServiceToscaModel(uuid);
@@ -124,15 +124,20 @@ public class SdcRestClientITTest {
 
         assertTrue(first.isPresent());
 
-        assertThat(first.get().getHeaders().keySet(), hasItems(X_ECOMP_INSTANCE_ID.toLowerCase(), REQUEST_ID_HEADER_KEY.toLowerCase()));
-        assertThat(first.get().getHeaders().get(REQUEST_ID_HEADER_KEY.toLowerCase()).get(0), matchesPattern(UUID_REGEX));
+        assertThat(first.get().getHeaders(), hasKey(equalToIgnoringCase(X_ECOMP_INSTANCE_ID)));
     }
 
     private Service getExpectedService(String stringId) {
-        return new Service(stringId, stringId,
-                "sampleCategory", "sampleVersion",
-                "sampleName", "sampleDistStatus",
-                "sampleToscaUrl", Service.LifecycleState.CERTIFIED, Collections.emptyList(), Collections.emptyList());
+        return new Service.ServiceBuilder().setUuid(stringId)
+                .setInvariantUUID(stringId)
+                .setCategory("sampleCategory")
+                .setVersion("sampleVersion")
+                .setName( "sampleName")
+                .setDistributionStatus("sampleDistStatus")
+                .setToscaModelURL("sampleToscaUrl")
+                .setLifecycleState(Service.LifecycleState.CERTIFIED)
+                .setArtifacts(Collections.emptyList())
+                .setResources(Collections.emptyList()).build();
     }