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.
16 package org.onap.usecaseui.server.service.impl;
18 import org.junit.Test;
19 import org.junit.Before;
20 import org.junit.After;
21 import org.junit.runner.RunWith;
22 import org.onap.usecaseui.server.UsecaseuiServerApplication;
23 import org.onap.usecaseui.server.bean.PerformanceInformation;
24 import org.onap.usecaseui.server.service.impl.PerformanceInformationServiceImpl;
25 import org.onap.usecaseui.server.util.DateUtils;
26 import org.onap.usecaseui.server.util.Page;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.boot.test.context.SpringBootTest;
29 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30 import org.springframework.test.context.web.WebAppConfiguration;
32 import java.sql.Timestamp;
33 import java.text.SimpleDateFormat;
36 import org.hibernate.Query;
37 import org.hibernate.Session;
38 import org.hibernate.SessionFactory;
39 import org.hibernate.Transaction;
45 * PerformanceInformationServiceImpl Tester.
47 * @author <Authors name>
48 * @since <pre>8, 2018</pre>
51 public class PerformanceInformationServiceImplTest {
52 PerformanceInformationServiceImpl performanceInformationServiceImpl = null;
53 private static final long serialVersionUID = 1L;
56 public void before() throws Exception {
57 performanceInformationServiceImpl = new PerformanceInformationServiceImpl();
59 MockUp<Transaction> mockUpTransaction = new MockUp<Transaction>() {
61 public void commit() {
64 MockUp<Query> mockUpQuery = new MockUp<Query>() {
68 public Query setString(String name, String value) {
69 return mockUpQuery.getMockInstance();
72 public Query setDate(String name, Date value) {
73 return mockUpQuery.getMockInstance();
76 public Query setInteger(String name, int value) {
77 return mockUpQuery.getMockInstance();
80 public int executeUpdate() {
84 public Query setMaxResults(int value) {
85 return mockUpQuery.getMockInstance();
88 public Query setFirstResult(int firstResult) {
89 return mockUpQuery.getMockInstance();
92 public Query setParameterList(String name, Object[] values) {
93 return mockUpQuery.getMockInstance();
96 public List<PerformanceInformation> list() {
97 PerformanceInformation pi = new PerformanceInformation();
98 return Arrays.asList(pi);
101 public Object uniqueResult() {
105 MockUp<Session> mockedSession = new MockUp<Session>() {
107 public Query createQuery(String sql) {
108 return mockUpQuery.getMockInstance();
111 public Transaction beginTransaction() {
112 return mockUpTransaction.getMockInstance();
115 public Transaction getTransaction() {
116 return mockUpTransaction.getMockInstance();
119 public Serializable save(Object object) {
120 return (Serializable) serialVersionUID;
123 public void flush() {
126 public void update(Object object) {
129 new MockUp<SessionFactory>() {
131 public Session openSession() {
132 return mockedSession.getMockInstance();
135 new MockUp<PerformanceInformationServiceImpl>() {
137 private Session getSession() {
138 return mockedSession.getMockInstance();
144 public void after() throws Exception {
148 public void testSavePerformanceInformation() throws Exception {
149 PerformanceInformation pi = null;
150 performanceInformationServiceImpl.savePerformanceInformation(pi);
154 public void testUpdatePerformanceInformation() throws Exception {
155 PerformanceInformation pi = null;
156 performanceInformationServiceImpl.updatePerformanceInformation(pi);
160 public void testGetAllCount() throws Exception {
161 new MockUp<Query>() {
163 public Object uniqueResult() {
167 PerformanceInformation pi = new PerformanceInformation();
171 pi.setCreateTime(DateUtils.now());
172 pi.setUpdateTime(DateUtils.now());
173 performanceInformationServiceImpl.getAllCount(pi, 1, 1);
177 public void testQueryPerformanceInformation() throws Exception {
178 PerformanceInformation pi = new PerformanceInformation();
182 pi.setCreateTime(DateUtils.now());
183 pi.setUpdateTime(DateUtils.now());
184 performanceInformationServiceImpl.queryPerformanceInformation(pi, 1, 1);
188 public void testQueryId() throws Exception {
189 String[] id = {"1", "2", "3"};
190 performanceInformationServiceImpl.queryId(id);
194 public void testQueryDateBetween() throws Exception {
195 performanceInformationServiceImpl.queryDateBetween("eventId", DateUtils.now(), DateUtils.now());
196 performanceInformationServiceImpl.queryDateBetween("resourceId", "name", "startTime", "endTime");
200 public void testQueryDataBetweenSum() throws Exception {
201 performanceInformationServiceImpl.queryDataBetweenSum("eventId", "name", DateUtils.now(), DateUtils.now());
204 @Test(expected = Exception.class)
205 public void testSavePerformanceInformationException() throws Exception {
206 new MockUp<PerformanceInformationServiceImpl>() {
208 private Session getSession() throws Exception {
209 throw new Exception();
212 PerformanceInformation pi = new PerformanceInformation();
213 performanceInformationServiceImpl.savePerformanceInformation(pi);
216 @Test(expected = Exception.class)
217 public void testUpdatePerformanceInformationException() throws Exception {
218 new MockUp<PerformanceInformationServiceImpl>() {
220 private Session getSession() throws Exception {
221 throw new Exception();
224 PerformanceInformation pi = new PerformanceInformation();
225 performanceInformationServiceImpl.updatePerformanceInformation(pi);
228 @Test(expected = Exception.class)
229 public void testGetAllCountException() throws Exception {
230 new MockUp<PerformanceInformationServiceImpl>() {
232 private Session getSession() throws Exception {
233 throw new Exception();
236 PerformanceInformation pi = new PerformanceInformation();
237 performanceInformationServiceImpl.getAllCount(pi, 1, 1);
240 @Test(expected = Exception.class)
241 public void testQueryPerformanceInformationException() throws Exception {
242 new MockUp<PerformanceInformationServiceImpl>() {
244 private Session getSession() throws Exception {
245 throw new Exception();
248 PerformanceInformation pi = new PerformanceInformation();
249 performanceInformationServiceImpl.queryPerformanceInformation(pi, 1, 1);
252 @Test(expected = Exception.class)
253 public void testQueryIdException() throws Exception {
254 new MockUp<PerformanceInformationServiceImpl>() {
256 private Session getSession() throws Exception {
257 throw new Exception();
260 String[] id = {"1", "2", "3"};
261 performanceInformationServiceImpl.queryId(id);
264 @Test(expected = Exception.class)
265 public void testQueryDateBetweenException() throws Exception {
266 new MockUp<PerformanceInformationServiceImpl>() {
268 private Session getSession() throws Exception {
269 throw new Exception();
272 performanceInformationServiceImpl.queryDateBetween("eventId", DateUtils.now(), DateUtils.now());
273 performanceInformationServiceImpl.queryDateBetween("resourceId", "name", "startTime", "endTime");
276 @Test(expected = Exception.class)
277 public void testQueryDataBetweenSumException() throws Exception {
278 new MockUp<PerformanceInformationServiceImpl>() {
280 private Session getSession() throws Exception {
281 throw new Exception();
284 performanceInformationServiceImpl.queryDataBetweenSum("eventId", "name", DateUtils.now(), DateUtils.now());