nbi ko when can't reach onap 91/49291/1
authorromaingimbert <romain.gimbert@orange.com>
Mon, 28 May 2018 07:41:05 +0000 (09:41 +0200)
committerromaingimbert <romain.gimbert@orange.com>
Mon, 28 May 2018 07:41:05 +0000 (09:41 +0200)
- fix infinite loop
- change test

Change-Id: I286e7ed9ea4b46ceb9af4d18d40adbf55de62e92
Issue-ID: EXTAPI-94
Signed-off-by: romaingimbert <romain.gimbert@orange.com>
src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java
src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java
src/test/java/org/onap/nbi/apis/ApiTestWithoutOnap.java [new file with mode: 0644]

index a09587c..a7e3356 100644 (file)
  */
 package org.onap.nbi.apis.serviceorder;
 
+import java.net.URI;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import org.onap.nbi.OnapComponentsUrlPaths;
 import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo;
 import org.onap.nbi.exceptions.BackendFunctionalException;
@@ -22,17 +27,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.ResourceAccessException;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.util.UriComponentsBuilder;
 
-import java.net.URI;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
 @Service
 public class MultiClient {
 
@@ -179,7 +183,7 @@ public class MultiClient {
                         + response.getBody().toString());
             }
             return response;
-        } catch (BackendFunctionalException e) {
+        } catch (BackendFunctionalException|ResourceAccessException e) {
             LOGGER.error("error on calling " + callUrl + " ," + e);
             return null;
         }
@@ -209,7 +213,7 @@ public class MultiClient {
             }
             return response;
 
-        } catch (BackendFunctionalException e) {
+        } catch (BackendFunctionalException|ResourceAccessException e) {
             LOGGER.error("error on calling " + callURL + " ," + e);
             return null;
         }
index e0daa23..3dba422 100644 (file)
@@ -24,8 +24,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.ResourceAccessException;
 import org.springframework.web.client.RestTemplate;
 
 @Service
@@ -68,7 +73,7 @@ public class SoClient {
             logResponsePost(url, response);
             return response;
 
-        } catch (BackendFunctionalException e) {
+        } catch (BackendFunctionalException|ResourceAccessException e) {
             LOGGER.error(ERROR_ON_CALLING + url + " ," + e);
             return null;
         }
@@ -90,7 +95,7 @@ public class SoClient {
             logResponsePost(url, response);
             return response;
 
-        } catch (BackendFunctionalException e) {
+        } catch (BackendFunctionalException|ResourceAccessException e) {
             LOGGER.error(ERROR_ON_CALLING + url + " ," + e);
             return null;
         }
@@ -118,7 +123,7 @@ public class SoClient {
             logResponseGet(url, response);
             return response.getBody();
 
-        } catch (BackendFunctionalException e) {
+        } catch (BackendFunctionalException|ResourceAccessException e) {
             LOGGER.error(ERROR_ON_CALLING + url + " ," + e);
             return null;
         }
diff --git a/src/test/java/org/onap/nbi/apis/ApiTestWithoutOnap.java b/src/test/java/org/onap/nbi/apis/ApiTestWithoutOnap.java
new file mode 100644 (file)
index 0000000..c37c441
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ *     Copyright (c) 2018 Orange
+ *
+ *     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.
+ */
+package org.onap.nbi.apis;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.nbi.apis.assertions.ServiceOrderAssertions;
+import org.onap.nbi.apis.serviceorder.model.ActionType;
+import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
+import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
+import org.onap.nbi.apis.serviceorder.model.StateType;
+import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
+import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository;
+import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
+import org.onap.nbi.apis.serviceorder.workflow.SOTaskProcessor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.embedded.LocalServerPort;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public class ApiTestWithoutOnap {
+
+
+    @Autowired
+    ServiceOrderRepository serviceOrderRepository;
+
+    @Autowired
+    ExecutionTaskRepository executionTaskRepository;
+
+    @Autowired
+    SOTaskProcessor SoTaskProcessor;
+
+    @After
+    public void tearsDownUpPort() throws Exception {
+        executionTaskRepository.deleteAll();
+        serviceOrderRepository.deleteAll();
+    }
+
+
+    public ExecutionTask getExecutionTask(String orderItemId) {
+        for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
+            if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
+                return executionTask;
+            }
+
+        }
+        return null;
+    }
+
+
+
+    @Test
+    public void testExecutionTaskWithoutOnap() throws Exception {
+
+        ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+            executionTaskRepository, ActionType.ADD);
+
+        SoTaskProcessor.processOrderItem(executionTaskA);
+        ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+        assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+        for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+                assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+        }
+
+        assertThat(executionTaskRepository.count()).isEqualTo(0);
+    }
+
+
+
+
+
+
+}