aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorguochuyicmri <guochuyi@chinamobile.com>2019-03-13 16:15:30 +0800
committerguochuyicmri <guochuyi@chinamobile.com>2019-03-13 16:15:40 +0800
commitc946ee87d556ed36df4d7cb028399869815574db (patch)
tree4d23b5974f45fb7bf4f942fb4d880ad528811bf1 /server
parent9810f110a7a04aa5f214bc49403de1640de2321f (diff)
Increase UT coverages for UUI server
Change-Id: Ib089e131088f4289900f188d3464c07bf030e748 Issue-ID: USECASEUI-238 Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java3
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java55
-rwxr-xr-xserver/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java5
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java10
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java31
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/util/DmaapSubscriberTest.java68
6 files changed, 99 insertions, 73 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
index 61aa70f2..daa4737d 100644
--- a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
+++ b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
@@ -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
index b3bd5965..00000000
--- a/server/src/main/java/org/onap/usecaseui/server/bo/PerformanceBo.java
+++ /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;
- }
-}
diff --git a/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java b/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
index bb78503e..1a3953de 100755
--- a/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
+++ b/server/src/main/java/org/onap/usecaseui/server/hibernate/HibernateConfiguration.java
@@ -21,12 +21,13 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
-import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
-@org.springframework.context.annotation.Configuration
+@Configuration
public class HibernateConfiguration
{
@Autowired
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
index 78b58b61..15ec0fe4 100644
--- a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
+++ b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java
@@ -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);
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java b/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java
index 5aa22344..450e362b 100644
--- a/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java
+++ b/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java
@@ -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
index 00000000..67153f73
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/util/DmaapSubscriberTest.java
@@ -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);
+ }
+}