2  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  17 package org.onap.usecaseui.server.service.impl;
 
  19 import org.hibernate.Query;
 
  20 import org.hibernate.Session;
 
  21 import org.hibernate.Transaction;
 
  22 import org.junit.Test; 
 
  23 import org.junit.Before; 
 
  24 import org.junit.After;
 
  25 import org.junit.runner.RunWith;
 
  26 import org.onap.usecaseui.server.UsecaseuiServerApplication;
 
  27 import org.onap.usecaseui.server.bean.PerformanceInformation;
 
  28 import org.onap.usecaseui.server.service.PerformanceInformationService;
 
  29 import org.onap.usecaseui.server.util.DateUtils;
 
  30 import org.springframework.boot.test.context.SpringBootTest;
 
  31 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
  32 import org.springframework.test.context.web.WebAppConfiguration;
 
  34 import javax.annotation.Resource;
 
  36 import java.text.SimpleDateFormat;
 
  37 import java.util.Date;
 
  40 import org.hibernate.Query;
 
  41 import org.hibernate.Session;
 
  42 import org.hibernate.SessionFactory;
 
  43 import org.hibernate.Transaction;
 
  48 import static org.mockito.Mockito.mock;
 
  51 * PerformanceInformationServiceImpl Tester. 
 
  53 * @author <Authors name> 
 
  54 * @since <pre> 8, 2018</pre>
 
  57 public class PerformanceInformationServiceImplTest {
 
  58     /*@Resource(name = "PerformanceInformationService")
 
  59     PerformanceInformationService performanceInformationService;*/
 
  60     PerformanceInformationServiceImpl service;
 
  62 public void before() throws Exception {
 
  63     service = mock(PerformanceInformationServiceImpl.class);
 
  67 public void after() throws Exception { 
 
  70 private Session session;
 
  71 private Transaction transaction;
 
  76 public void mockupUtil(){
 
  77          MockUp<Query> mockUpQuery = new MockUp<Query>() {
 
  79                 MockUp<Session> mockedSession = new MockUp<Session>() {
 
  81          public Query createQuery(String sql) {
 
  82              return mockUpQuery.getMockInstance();
 
  85                         public Transaction beginTransaction() {
 
  89                 new MockUp<SessionFactory>() {
 
  91                         public Session openSession() {
 
  92                                 return mockedSession.getMockInstance();
 
  95                 new MockUp<Transaction>() {
 
  97                         public void commit() {
 
 100      new MockUp<AlarmsInformationServiceImpl>() {
 
 102          private Session getSession() {
 
 103              return mockedSession.getMockInstance();
 
 109 * Method: savePerformanceInformation(PerformanceInformation performanceInformation) 
 
 113 public void testSavePerformanceInformation() throws Exception { 
 
 114 //TODO: Test goes here...
 
 116     PerformanceInformation a = new PerformanceInformation();
 
 119     a.setName("SGS.UeUnreachable");
 
 121     a.setCreateTime(DateUtils.now());
 
 122     a.setUpdateTime(DateUtils.now());
 
 124     service.savePerformanceInformation(a);
 
 130 * Method: updatePerformanceInformation(PerformanceInformation performanceInformation) 
 
 134 public void testUpdatePerformanceInformation() throws Exception { 
 
 135 //TODO: Test goes here...
 
 137     PerformanceInformation a = new PerformanceInformation();
 
 141     a.setUpdateTime(DateUtils.now());
 
 142     a.setCreateTime(DateUtils.now());
 
 144     service.updatePerformanceInformation(a);
 
 149 * Method: getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) 
 
 153 public void testGetAllCount() throws Exception { 
 
 154 //TODO: Test goes here...
 
 156     PerformanceInformation performanceInformation = new PerformanceInformation();
 
 157     performanceInformation.setName("vnf_a_3");
 
 160     service.getAllCount(performanceInformation,0,12);
 
 166 * Method: queryPerformanceInformation(PerformanceInformation performanceInformation, int currentPage, int pageSize) 
 
 170 public void testQueryPerformanceInformation() throws Exception { 
 
 171 //TODO: Test goes here...
 
 172     PerformanceInformation a = new PerformanceInformation();
 
 173     // a.setEventId("2202");
 
 175     service.queryPerformanceInformation(a, 1, 100);
 
 176            // .getList().forEach(al -> System.out.println(al.getValue()));
 
 181 * Method: queryId(String[] id) 
 
 185 public void testQueryId() throws Exception { 
 
 186 //TODO: Test goes here...
 
 188     service.queryId(new String[]{"2202"});
 
 189           //  .forEach(ai -> System.out.println(ai.getCreateTime()));
 
 194 * Method: queryDateBetween(String eventId, Date startDate, Date endDate) 
 
 198 public void testQueryDateBetweenForEventIdStartDateEndDate() throws Exception { 
 
 199 //TODO: Test goes here...
 
 200     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 
 201     String star = "2017-11-15 06:30:00";
 
 202     String end="2017-11-15 14:45:10";
 
 203     Date stard = sdf.parse(star);
 
 204     Date endd = sdf.parse(end);
 
 206     service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd);
 
 211 * Method: queryDateBetween(String resourceId, String name, String startTime, String endTime) 
 
 215 public void testQueryDateBetweenForResourceIdNameStartTimeEndTime() throws Exception { 
 
 216 //TODO: Test goes here...
 
 217     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 
 218     String star = "2017-11-15 06:30:00";
 
 219     String end="2017-11-15 14:45:10";
 
 220     Date stard = sdf.parse(star);
 
 221     Date endd = sdf.parse(end);
 
 223     service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd);
 
 229 * Method: queryMaxValueByBetweenDate(String sourceId, String name, String startTime, String endTime) 
 
 233 public void testQueryMaxValueByBetweenDate() throws Exception { 
 
 234 //TODO: Test goes here...
 
 236     service.queryDateBetween("2202", DateUtils.stringToDate("2017-10-15 01:00:00"), DateUtils.stringToDate("2017-10-15 02:00:00")).forEach(p -> System.out.println(p));