diff options
3 files changed, 124 insertions, 132 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java index ab7534c6..e41ec80d 100755 --- a/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/AlarmController.java @@ -150,47 +150,6 @@ public class AlarmController }
}
- @RequestMapping(value = { "/alarm/genCsv/{eventId}" } , method = RequestMethod.GET , produces = "application/json")
- public String generateCsvFile(HttpServletResponse response, @PathVariable String[] eventId) throws JsonProcessingException {
- logger.info("transfer generateCsvFile Apis, " +
- "Parameter all follows : [eventId : {}]",eventId);
- String csvFile = "csvFiles/vnf_alarm_"+new SimpleDateFormat("yy-MM-ddHH:mm:ss").format(new Date())+".csv";
- List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryId(eventId);
- List<String[]> csvData = new ArrayList<>();
- try{
- alarmsHeaders.forEach(ala ->{
- List<AlarmsInformation> information = alarmsInformationService.queryAlarmsInformation(new AlarmsInformation(ala.getEventId()),1,100).getList();
- String names = "";
- String values = "";
- if (0 < information.size() && null != information){
- for (AlarmsInformation a : information){
- names += a.getName()+",";
- values += a.getValue()+",";
- }
- names = names.substring(0,names.lastIndexOf(','));
- values = values.substring(0,values.lastIndexOf(','));
- }
- csvData.add(new String[]{
- ala.getVersion(),ala.getEventName(),ala.getDomain(),ala.getEventId(),ala.getEventType(),
- ala.getNfcNamingCode(),ala.getNfNamingCode(),ala.getSourceId(),ala.getSourceName(),
- ala.getReportingEntityId(),ala.getReportingEntityName(),ala.getPriority(),ala.getStartEpochMicrosec(),
- ala.getLastEpochMicroSec(),ala.getSequence(),ala.getFaultFieldsVersion(),ala.getEventServrity(),
- ala.getEventSourceType(),ala.getEventCategory(),ala.getAlarmCondition(),ala.getSpecificProblem(),
- ala.getVfStatus(),ala.getAlarmInterfaceA(),ala.getStatus(),DateUtils.dateToString(ala.getCreateTime()),
- DateUtils.dateToString(ala.getUpdateTime()),names,values
- });
- });
- CSVUtils.writeCsv(AlarmCSVHeaders,csvData,csvFile);
- }catch (Exception e){
- logger.error(e.getMessage());
- }
- if (ResponseUtil.responseDownload(csvFile,response)){
- return omAlarm.writeValueAsString("success");
- }else{
- return omAlarm.writeValueAsString("failed");
- }
- }
-
@RequestMapping(value = {"/alarm/sourceId"},method = RequestMethod.GET)
public String getSourceId(){
List<String> sourceIds = new ArrayList<>();
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java index ead47ef3..ed1c9f35 100755 --- a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java @@ -15,46 +15,74 @@ */ package org.onap.usecaseui.server.controller; -import com.fasterxml.jackson.core.JsonProcessingException; import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.Before; +import org.junit.After; import org.onap.usecaseui.server.bean.AlarmsHeader; import org.onap.usecaseui.server.bean.AlarmsInformation; import org.onap.usecaseui.server.service.AlarmsHeaderService; import org.onap.usecaseui.server.service.AlarmsInformationService; -import org.onap.usecaseui.server.util.CSVUtils; -import org.onap.usecaseui.server.util.DateUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -@RunWith(SpringRunner.class) -@SpringBootTest +import org.onap.usecaseui.server.util.Page; + +import java.util.*; + +import mockit.Mock; +import mockit.MockUp; + public class AlarmControllerTest { - @Autowired - AlarmController alarmController; + AlarmController controller = null; + + @Before + public void before() throws Exception { + controller = new AlarmController(); + + new MockUp<AlarmsHeaderService>() { + @Mock + public Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader, int currentPage, int pageSize) { + return new Page<AlarmsHeader>(); + } + @Mock + public List<AlarmsHeader> queryId(String[] id) { + AlarmsHeader ah = new AlarmsHeader(); + return Arrays.asList(ah); + } + }; + new MockUp<AlarmsInformationService>() { + @Mock + public Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage, int pageSize) { + return new Page<AlarmsInformation>(); + } + @Mock + public List<Map<String,String>> queryDateBetween(String sourceId, String startTime, String endTime) { + Map<String,String> map = new HashMap<String,String>(); + return Arrays.asList(map); + } + }; + } - @Test - public void getDataNotParam() throws JsonProcessingException { - System.out.println(alarmController.getAlarmData(null,null,null,null,null,null,1,100)); - } + @After + public void after() throws Exception { + } - @Test - public void getDataCarryParam() throws JsonProcessingException { - System.out.println(alarmController.getAlarmData("110","a","drop","down","1506331166000","2",1,100)); - } + @Test + public void testIndex() throws Exception { + controller.index(); + } - @Test - public void csvFile() throws JsonProcessingException { - System.out.println(alarmController.generateCsvFile(null,new String[]{"110"})); - } + @Test + public void testGetAlarmData() throws Exception { + controller.getAlarmData("sourceId", "sourceName", "priority", "startTime", "endTime", "vfStatus", 1, 10); + controller.getAlarmData(null, null, null, null, null, null, 1, 10); + } + @Test + public void testGetSourceId() throws Exception { + controller.getSourceId(); + } + @Test + public void testGenDiagram() throws Exception { + controller.genDiagram("sourceId", "startTime", "endTime"); + } } diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java index 65ef8708..3d95d193 100755 --- a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java @@ -1,4 +1,4 @@ -/* + /* * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,78 +15,83 @@ */ package org.onap.usecaseui.server.controller; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Arrays; +import java.util.List; +import java.util.Date; + +import org.junit.After; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.onap.usecaseui.server.bean.PerformanceHeader; import org.onap.usecaseui.server.bean.PerformanceInformation; import org.onap.usecaseui.server.service.PerformanceHeaderService; import org.onap.usecaseui.server.service.PerformanceInformationService; -import org.onap.usecaseui.server.util.CSVUtils; -import org.onap.usecaseui.server.util.DateUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +import org.onap.usecaseui.server.util.Page; -import javax.annotation.Resource; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; +import mockit.Mock; +import mockit.MockUp; -@RunWith(SpringRunner.class) -@SpringBootTest public class PerformanceControllerTest { - @Autowired - private PerformanceController performanceController; - - @Test - public void getPerformanceData() throws JsonProcessingException { - System.out.println(performanceController.getPerformanceData(null,1,100,null,null,null,null,null)); - } - - @Test - public void generateCsvFile() throws JsonProcessingException { - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","fre","2017-09-28 10:00:00")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","fre","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","null","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","null","null","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"null","null","null","null","null")); - System.out.println(performanceController.getPerformanceData(null,1,100,"110","fxc","efw","null","asdasdasda")); + PerformanceController controller = null; + @Before + public void before() throws Exception { + controller = new PerformanceController(); - } + new MockUp<PerformanceHeaderService>() { + @Mock + public Page<PerformanceHeader> queryPerformanceHeader(PerformanceHeader performanceHeder, int currentPage, int pageSize) { + return new Page<PerformanceHeader>(); + } + @Mock + public List<PerformanceHeader> queryId(String[] id) { + PerformanceHeader ph = new PerformanceHeader(); + return Arrays.asList(ph); + } + @Mock + public List<String> queryAllSourceId() { + String str = "abc"; + return Arrays.asList(str); + } + }; + new MockUp<PerformanceInformationService>() { + @Mock + public Page<PerformanceInformation> queryPerformanceInformation(PerformanceInformation performanceInformation, int currentPage, int pageSize) { + return new Page<PerformanceInformation>(); + } + @Mock + public int queryDataBetweenSum(String eventId, String name, Date startDate, Date endDate) { + return 1; + } + @Mock + public List<PerformanceInformation> queryDateBetween(String resourceId, String name, String startTime, String endTime) { + PerformanceInformation pi = new PerformanceInformation(); + return Arrays.asList(pi); + } + }; + } - @Test - public void generateDiaCsvFile() throws JsonProcessingException { - Map<String,String> p = new HashMap<>(); - p.put("eventId","110"); - p.put("name","110"); - p.put("value","110"); - p.put("createTime","110"); - p.put("updateTime","110"); - //System.out.println(performanceController.generateDiaCsvFile(null,p)); - } + @After + public void after() throws Exception { + } - @Test - public void generateDiagram(){ - try { - System.out.println(performanceController.generateDiagram("hour","110")); - System.out.println(performanceController.generateDiagram("day","110")); - System.out.println(performanceController.generateDiagram("month","110")); - System.out.println(performanceController.generateDiagram("year","110")); - } catch (ParseException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - } + @Test + public void testGenerateDiagram() throws Exception { + controller.generateDiagram("hour", "eventId"); + controller.generateDiagram("day", "eventId"); + controller.generateDiagram("month", "eventId"); + controller.generateDiagram("year", "eventId"); + controller.generateDiagram("sourceId", "startTime", "endTime", "nameParent", "nameChild"); + } + @Test + public void testGetSourceIds() throws Exception { + controller.getSourceIds(); + } -} + @Test + public void testGetNames() throws Exception { + controller.getNames("sourceId"); + } +}
\ No newline at end of file |