fb0f29caeb19a265027b2b8184537dab82c71f4c
[usecase-ui/server.git] /
1 /*
2  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.usecaseui.server.service.impl;
18
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;
33
34 import javax.annotation.Resource;
35
36 import java.text.SimpleDateFormat;
37 import java.util.Date;
38
39
40 import org.hibernate.Query;
41 import org.hibernate.Session;
42 import org.hibernate.SessionFactory;
43 import org.hibernate.Transaction;
44
45 import mockit.Mock;
46 import mockit.MockUp;
47
48 import static org.mockito.Mockito.mock;
49
50 /** 
51 * PerformanceInformationServiceImpl Tester. 
52
53 * @author <Authors name> 
54 * @since <pre> 8, 2018</pre>
55 * @version 1.0 
56 */
57 public class PerformanceInformationServiceImplTest {
58     /*@Resource(name = "PerformanceInformationService")
59     PerformanceInformationService performanceInformationService;*/
60     PerformanceInformationServiceImpl service;
61 @Before
62 public void before() throws Exception {
63     service = mock(PerformanceInformationServiceImpl.class);
64
65
66 @After
67 public void after() throws Exception { 
68
69
70 private Session session;
71 private Transaction transaction;
72 private Query query;
73 /**
74  * mockupUtil 
75  */
76 public void mockupUtil(){
77          MockUp<Query> mockUpQuery = new MockUp<Query>() {
78      };
79                 MockUp<Session> mockedSession = new MockUp<Session>() {
80          @Mock
81          public Query createQuery(String sql) {
82              return mockUpQuery.getMockInstance();
83          }
84                         @Mock
85                         public Transaction beginTransaction() {
86                                 return transaction;
87                         }
88                 };
89                 new MockUp<SessionFactory>() {
90                         @Mock
91                         public Session openSession() {
92                                 return mockedSession.getMockInstance();
93                         }
94                 };
95                 new MockUp<Transaction>() {
96                         @Mock
97                         public void commit() {
98                         }
99                 };
100      new MockUp<AlarmsInformationServiceImpl>() {
101          @Mock
102          private Session getSession() {
103              return mockedSession.getMockInstance();
104          }
105      };
106 }
107 /** 
108
109 * Method: savePerformanceInformation(PerformanceInformation performanceInformation) 
110
111 */ 
112 @Test
113 public void testSavePerformanceInformation() throws Exception { 
114 //TODO: Test goes here...
115
116     PerformanceInformation a = new PerformanceInformation();
117
118     a.setEventId("123");
119     a.setName("SGS.UeUnreachable");
120     a.setValue("40");
121     a.setCreateTime(DateUtils.now());
122     a.setUpdateTime(DateUtils.now());
123     mockupUtil();
124     service.savePerformanceInformation(a);
125
126
127
128 /** 
129
130 * Method: updatePerformanceInformation(PerformanceInformation performanceInformation) 
131
132 */ 
133 @Test
134 public void testUpdatePerformanceInformation() throws Exception { 
135 //TODO: Test goes here...
136
137     PerformanceInformation a = new PerformanceInformation();
138     a.setEventId("110");
139     a.setName("efw");
140     a.setValue("fko11");
141     a.setUpdateTime(DateUtils.now());
142     a.setCreateTime(DateUtils.now());
143     mockupUtil();
144     service.updatePerformanceInformation(a);
145
146
147 /** 
148
149 * Method: getAllCount(PerformanceInformation performanceInformation, int currentPage, int pageSize) 
150
151 */ 
152 @Test
153 public void testGetAllCount() throws Exception { 
154 //TODO: Test goes here...
155
156     PerformanceInformation performanceInformation = new PerformanceInformation();
157     performanceInformation.setName("vnf_a_3");
158
159     mockupUtil();
160     service.getAllCount(performanceInformation,0,12);
161
162
163
164 /** 
165
166 * Method: queryPerformanceInformation(PerformanceInformation performanceInformation, int currentPage, int pageSize) 
167
168 */ 
169 @Test
170 public void testQueryPerformanceInformation() throws Exception { 
171 //TODO: Test goes here...
172     PerformanceInformation a = new PerformanceInformation();
173     // a.setEventId("2202");
174     mockupUtil();
175     service.queryPerformanceInformation(a, 1, 100);
176            // .getList().forEach(al -> System.out.println(al.getValue()));
177
178
179 /** 
180
181 * Method: queryId(String[] id) 
182
183 */ 
184 @Test
185 public void testQueryId() throws Exception { 
186 //TODO: Test goes here...
187         mockupUtil();
188     service.queryId(new String[]{"2202"});
189           //  .forEach(ai -> System.out.println(ai.getCreateTime()));
190
191
192 /** 
193
194 * Method: queryDateBetween(String eventId, Date startDate, Date endDate) 
195
196 */ 
197 @Test
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);
205    // mockupUtil();
206     service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd);
207
208
209 /** 
210
211 * Method: queryDateBetween(String resourceId, String name, String startTime, String endTime) 
212
213 */ 
214 @Test
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);
222     mockupUtil();
223     service.queryDateBetween("1101ZTHX1MMEGJM1W1",stard,endd);
224
225
226
227 /** 
228
229 * Method: queryMaxValueByBetweenDate(String sourceId, String name, String startTime, String endTime) 
230
231 */ 
232 @Test
233 public void testQueryMaxValueByBetweenDate() throws Exception { 
234 //TODO: Test goes here...
235         mockupUtil();
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));
237
238
239
240
241