Increase UT coverages for UUI server 88/82088/1
authorguochuyicmri <guochuyi@chinamobile.com>
Wed, 13 Mar 2019 08:15:30 +0000 (16:15 +0800)
committerguochuyicmri <guochuyi@chinamobile.com>
Wed, 13 Mar 2019 08:15:40 +0000 (16:15 +0800)
Change-Id: Ib089e131088f4289900f188d3464c07bf030e748
Issue-ID: USECASEUI-238
Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java [deleted file]
server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java
server/src/test/java/org/onap/usecaseui/server/util/DmaapSubscriberTest.java [new file with mode: 0644]

index 61aa70f..daa4737 100644 (file)
@@ -18,12 +18,15 @@ package org.onap.usecaseui.server;
 import org.onap.usecaseui.server.util.DmaapSubscriber;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.web.client.RestTemplate;
 
 @SpringBootApplication
+@EnableAutoConfiguration(exclude={JpaRepositoriesAutoConfiguration.class})
 @ComponentScan(basePackages = "org.onap.usecaseui.server")
 public class UsecaseuiServerApplication {
        
diff --git a/server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java b/server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java
deleted file mode 100755 (executable)
index b3bd596..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2017 CMCC, Inc. and others. 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.
- */
-package org.onap.usecaseui.server.bo;
-
-import org.onap.usecaseui.server.bean.PerformanceHeader;
-import org.onap.usecaseui.server.bean.PerformanceInformation;
-import org.onap.usecaseui.server.util.Page;
-
-import java.io.Serializable;
-import java.util.List;
-
-public class PerformanceBo implements Serializable {
-
-    private PerformanceHeader performanceHeader;
-
-    private List<PerformanceInformation> performanceInformation;
-
-
-    public PerformanceBo() {
-    }
-
-    public PerformanceBo(PerformanceHeader performanceHeader, List<PerformanceInformation> performanceInformation) {
-        this.performanceHeader = performanceHeader;
-        this.performanceInformation = performanceInformation;
-    }
-
-    public PerformanceHeader getPerformanceHeader() {
-        return performanceHeader;
-    }
-
-    public void setPerformanceHeader(PerformanceHeader performanceHeader) {
-        this.performanceHeader = performanceHeader;
-    }
-
-    public List<PerformanceInformation> getPerformanceInformation() {
-        return performanceInformation;
-    }
-
-    public void setPerformanceInformation(List<PerformanceInformation> performanceInformation) {
-        this.performanceInformation = performanceInformation;
-    }
-}
index bb78503..1a3953d 100755 (executable)
@@ -21,12 +21,13 @@ import javax.sql.DataSource;
 \r
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.context.annotation.Bean;\r
-import org.springframework.orm.hibernate4.LocalSessionFactoryBean;\r
+import org.springframework.context.annotation.Configuration;\r
+import org.springframework.orm.hibernate5.LocalSessionFactoryBean;\r
 import org.springframework.orm.jpa.JpaTransactionManager;\r
 import org.springframework.transaction.PlatformTransactionManager;\r
 \r
 \r
-@org.springframework.context.annotation.Configuration\r
+@Configuration\r
 public class HibernateConfiguration\r
 {\r
     @Autowired\r
index 78b58b6..15ec0fe 100644 (file)
@@ -102,14 +102,14 @@ public class DmaapSubscriber implements Runnable {
         }
     }
 
-    private List<String> getDMaaPData(String topic) {
+    public List<String> getDMaaPData(String topic) {
         Client client = ClientBuilder.newClient(new ClientConfig());
         WebTarget webTarget = client.target(url + "/" + topic + "/" + consumerGroup + "/" + consumer);
         Response response = webTarget.queryParam("timeout", timeout).request().get();
         return response.readEntity(List.class);
     }
 
-    private void initConfig() {
+    public void initConfig() {
         InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("dmaap.properties");
         Properties p = new Properties();
         try {
@@ -138,7 +138,7 @@ public class DmaapSubscriber implements Runnable {
         }
     }
 
-    private void alarmProcess(Map<String, Object> eventMap) {
+    public void alarmProcess(Map<String, Object> eventMap) {
         AlarmsHeader alarm_header = new AlarmsHeader();
         alarm_header.setId(UuiCommonUtil.getUUID());
         List<AlarmsInformation> alarm_informations = new ArrayList<>();
@@ -229,7 +229,7 @@ public class DmaapSubscriber implements Runnable {
     }
     }
 
-    private void performanceProcess(Map<String, Object> maps) {
+    public void performanceProcess(Map<String, Object> maps) {
         PerformanceHeader performance_header = new PerformanceHeader();
         performance_header.setId(UuiCommonUtil.getUUID());
         List<PerformanceInformation> performance_informations = new ArrayList<>();
@@ -302,7 +302,7 @@ public class DmaapSubscriber implements Runnable {
                 });
     }
     
-    private String getTime(String time){
+    public String getTime(String time){
        String result=time;
        if(time.length()>=13){
                result=time.substring(0, 13);
index 5aa2234..450e362 100644 (file)
@@ -62,16 +62,25 @@ public class RestfulServices {
     }
 
     public static RequestBody extractBody(HttpServletRequest request) throws IOException {
-        ServletInputStream inStream = null;
-        try {
-            inStream = request.getInputStream();
-            BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
-            logger.info("The request body content is: "+IOUtils.read(reader));
-            return RequestBody.create(MediaType.parse("application/json"), IOUtils.read(reader));
-        }finally {
-            if (inStream != null) {
-                inStream.close();
-            }
+        BufferedReader br = null;
+                StringBuilder sb = new StringBuilder("");
+                try {
+                        br = request.getReader();
+                String str;
+                while ((str = br.readLine()) != null)
+                {
+                    sb.append(str);
+                }
+                br.close();
+                logger.info("The request body content is: "+sb.toString());
+                return RequestBody.create(MediaType.parse("application/json"),sb.toString());
+               }catch(Exception e){
+                        logger.info("RestfulServices occur exection,this content is: "+e.getMessage());
+                        return RequestBody.create(MediaType.parse("application/json"),sb.toString());
+               }finally {
+               if (null != br) {
+                        br.close();
+               }
+               }
         }
-    }
 }
diff --git a/server/src/test/java/org/onap/usecaseui/server/util/DmaapSubscriberTest.java b/server/src/test/java/org/onap/usecaseui/server/util/DmaapSubscriberTest.java
new file mode 100644 (file)
index 0000000..67153f7
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 CMCC, Inc. and others. 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.
+ */
+
+package org.onap.usecaseui.server.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class DmaapSubscriberTest {
+       
+       DmaapSubscriber dmaap = new DmaapSubscriber();
+       private String topic="events/unauthenticated.SEC_FAULT_OUTPUT";
+       
+/*     @Test
+       public void subscribeTest(){
+               dmaap.subscribe(topic);
+       }
+       
+       @Test
+       public void getDMaaPDataTest(){
+               dmaap.getDMaaPData(topic);
+       }*/
+       
+       @Test
+       public void initConfigTest(){
+               dmaap.initConfig();
+       }
+       
+       @Test
+       public void alarmProcessTest() throws JsonParseException, JsonMappingException, IOException{
+               List<String> list = new ArrayList<>();
+               ObjectMapper objMapper = new ObjectMapper();
+               list.add("{\"event\":{\"commonEventHeader\":{\"sourceId\":\"vnf_test_3\",\"startEpochMicrosec\":1516784364869,\"eventId\":\"ab305d54-85b4-a31b-7db2-fb6b9e546015\",\"sequence\":0,\"domain\":\"fault\",\"lastEpochMicrosec\":1516784364869,\"eventName\":\"Fault_MultiCloud_VMFailureCleared\",\"sourceName\":\"vSBC\",\"priority\":\"High\",\"version\":3.0,\"reportingEntityName\":\"vnf_test_3_rname\"},\"faultFields\":{\"eventSeverity\":\"CRITICAL\",\"alarmCondition\":\"Guest_Os_Failure\",\"faultFieldsVersion\":2.0,\"specificProblem\":\"Fault_MultiCloud_VMFailure\",\"alarmInterfaceA\":\"aaaa\",\"alarmAdditionalInformation\":[{\"name\":\"objectType\",\"value\":\"VIM\"},{\"name\":\"eventTime\",\"value\":\"2017-10-31 09:51:15\"}],\"eventSourceType\":\"other\",\"vfStatus\":\"Active\"}}}");
+               Map<String, Object> eventMaps = (Map<String, Object>) objMapper.readValue(list.get(0), Map.class).get("event");
+               dmaap.alarmProcess(eventMaps);
+               
+       }
+       
+       @Test
+       public void performanceProcessTest() throws JsonParseException, JsonMappingException, IOException{
+               List<String> list = new ArrayList<>();
+               ObjectMapper objMapper = new ObjectMapper();
+               list.add("{\"VESversion\":\"v5\",\"event\":{\"commonEventHeader\":{\"startEpochMicrosec\":0,\"sourceId\":\"shentao_test_vnf5\",\"eventId\":\"uui_test_vnf5\",\"nfcNamingCode\":\"\",\"reportingEntityId\":\"uui_test_vnf5\",\"internalHeaderFields\":{\"collectorTimeStamp\":\"Thu, 03 22 2018 02:30:09 GMT\"},\"eventType\":\"applicationVnf\",\"priority\":\"Normal\",\"version\":1.1,\"reportingEntityName\":\"ZTE-CMBJ-BJ,SubNetwork=100001,ManagedElement=100040_40,MmeFunction=1,EpRpDynS6aMme=2\",\"sequence\":498594,\"domain\":\"measurementsForVfScaling\",\"lastEpochMicrosec\":10363234321004,\"eventName\":\"Mfvs_MMEEpRpDynS6aMme\",\"sourceName\":\"1101ZTHX1E6M2QI4FZVTOXU\",\"nfNamingCode\":\"\"},\"measurementsForVfScalingFields\":{\"measurementInterval\":15,\"measurementsForVfScalingVersion\":2.1,\"additionalMeasurements\":[{\"name\":\"MME\",\"arrayOfFields\":[{\"name\":\"MM.UpdateLocationAnsFail\",\"value\":\"0.1\"},{\"name\":\"MM.UpdateLocationAnsFail.1xxx\",\"value\":\"0.2\"},{\"name\":\"MM.UpdateLocationAnsFail.3xxx\",\"value\":\"0.3\"}]}]}}}");
+               Map<String, Object> eventMaps = (Map<String, Object>) objMapper.readValue(list.get(0), Map.class).get("event");
+               dmaap.performanceProcess(eventMaps);
+       }
+}