79bbf18de07477380f1cd45d4d2128def4bc6b4e
[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 package org.onap.usecaseui.server.service.impl;
17
18 import org.junit.Test;
19 import org.junit.Before;
20 import org.junit.After;
21 import org.onap.usecaseui.server.bean.PerformanceInformation;
22 import org.onap.usecaseui.server.service.impl.PerformanceInformationServiceImpl;
23 import org.onap.usecaseui.server.util.DateUtils;
24
25 import java.util.*;
26 import java.io.*;
27 import org.hibernate.Query;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30 import org.hibernate.Transaction;
31
32 import mockit.Mock;
33 import mockit.MockUp;
34
35 /** 
36 * PerformanceInformationServiceImpl Tester. 
37
38 * @author <Authors name> 
39 * @since <pre>8, 2018</pre>
40 * @version 1.0 
41 */
42 public class PerformanceInformationServiceImplTest {
43         PerformanceInformationServiceImpl performanceInformationServiceImpl = null;
44         private static final long serialVersionUID = 1L;
45
46         @Before
47         public void before() throws Exception {
48                 performanceInformationServiceImpl = new PerformanceInformationServiceImpl();
49
50                 MockUp<Transaction> mockUpTransaction = new MockUp<Transaction>() {
51                         @Mock
52                         public void commit() {
53                         }
54                 };
55                 MockUp<Query> mockUpQuery = new MockUp<Query>() {
56                 };
57                 new MockUp<Query>() {
58                         @Mock
59                         public Query setString(String name, String value) {
60                                 return mockUpQuery.getMockInstance();
61                         }
62                         @Mock
63                         public Query setDate(String name, Date value) {
64                                 return mockUpQuery.getMockInstance();
65                         }
66                         @Mock
67                         public Query setInteger(String name, int value) {
68                                 return mockUpQuery.getMockInstance();
69                         }
70                         @Mock
71                         public int executeUpdate() {
72                                 return 0;
73                         }
74                         @Mock
75                         public Query setMaxResults(int value) {
76                                 return mockUpQuery.getMockInstance();
77                         }
78                         @Mock
79                         public Query setFirstResult(int firstResult) {
80                                 return mockUpQuery.getMockInstance();
81                         }
82                         @Mock
83                         public Query setParameterList(String name, Object[] values) {
84                                 return mockUpQuery.getMockInstance();
85                         }
86                         @Mock
87                         public List<PerformanceInformation> list() {
88                                 PerformanceInformation pi = new PerformanceInformation();
89                                 return Arrays.asList(pi);
90                         }
91                         @Mock
92                         public Object uniqueResult() {
93                                 return "0";
94                         }
95                 };
96                 MockUp<Session> mockedSession = new MockUp<Session>() {
97                         @Mock
98                         public Query createQuery(String sql) {
99                                 return mockUpQuery.getMockInstance();
100                         }
101                         @Mock
102                         public Transaction beginTransaction() {
103                                 return mockUpTransaction.getMockInstance();
104                         }
105                         @Mock
106                         public Transaction getTransaction() {
107                                 return mockUpTransaction.getMockInstance();
108                         }
109                         @Mock
110                         public Serializable save(Object object) {
111                                 return (Serializable) serialVersionUID;
112                         }
113                         @Mock
114                         public void flush() {
115                         }
116                         @Mock
117                         public void update(Object object) {
118                         }
119                 };
120                 new MockUp<SessionFactory>() {
121                         @Mock
122                         public Session openSession() {
123                                 return mockedSession.getMockInstance();
124                         }
125                 };
126                 new MockUp<PerformanceInformationServiceImpl>() {
127                         @Mock
128                         private Session getSession() {
129                                 return mockedSession.getMockInstance();
130                         }
131                 };
132         }
133
134         @After
135         public void after() throws Exception {
136         }
137
138         @Test
139         public void testSavePerformanceInformation() throws Exception {
140                 try {
141                         PerformanceInformation pi = null;
142                         performanceInformationServiceImpl.savePerformanceInformation(pi);
143                 } catch (Exception e) {
144                         e.printStackTrace();
145                 }
146         }
147
148         @Test
149         public void testUpdatePerformanceInformation() throws Exception {
150                 try {
151                         PerformanceInformation pi = null;
152                         performanceInformationServiceImpl.updatePerformanceInformation(pi);
153                 } catch (Exception e) {
154                         e.printStackTrace();
155                 }
156         }
157
158         @Test
159         public void testQueryId() throws Exception {
160                 try {
161                         String[] id = {"1", "2", "3"};
162                         performanceInformationServiceImpl.queryId(id);
163                 } catch (Exception e) {
164                         e.printStackTrace();
165                 }
166         }
167
168         @Test
169         public void testQueryDateBetween() throws Exception {
170                 try {
171                         performanceInformationServiceImpl.queryDateBetween("eventId", DateUtils.now(), DateUtils.now());
172                         performanceInformationServiceImpl.queryDateBetween("resourceId", "name", "startTime", "endTime");
173                 } catch (Exception e) {
174                         e.printStackTrace();
175                 }
176         }
177
178         @Test
179         public void testQueryDataBetweenSum() throws Exception {
180                 try {
181                         performanceInformationServiceImpl.queryDataBetweenSum("eventId", "name", DateUtils.now(), DateUtils.now());
182                 } catch (Exception e) {
183                         e.printStackTrace();
184                 }
185         }
186         
187         @Test
188         public void testQueryMaxValueByBetweenDate() throws Exception {
189                 try {
190                         performanceInformationServiceImpl.queryMaxValueByBetweenDate("", "","","");
191                         performanceInformationServiceImpl.queryMaxValueByBetweenDate("eventId", "name","1527151520000","1527151620000");
192                 } catch (Exception e) {
193                         e.printStackTrace();
194                 }
195         }
196         
197         @Test
198         public void testGetAllPerformanceInformationByHeaderId() throws Exception {
199                 try {
200                         performanceInformationServiceImpl.getAllPerformanceInformationByHeaderId("0a573f09d50f46adaae0c10e741fea4d");
201                 } catch (Exception e) {
202                         e.printStackTrace();
203                 }
204         }
205 }