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.onap.usecaseui.server.bean.PerformanceInformation;
22 import org.onap.usecaseui.server.service.impl.PerformanceInformationServiceImpl;
23 import org.onap.usecaseui.server.util.DateUtils;
27 import org.hibernate.Query;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30 import org.hibernate.Transaction;
36 * PerformanceInformationServiceImpl Tester.
38 * @author <Authors name>
39 * @since <pre>8, 2018</pre>
42 public class PerformanceInformationServiceImplTest {
43 PerformanceInformationServiceImpl performanceInformationServiceImpl = null;
44 private static final long serialVersionUID = 1L;
47 public void before() throws Exception {
48 performanceInformationServiceImpl = new PerformanceInformationServiceImpl();
50 MockUp<Transaction> mockUpTransaction = new MockUp<Transaction>() {
52 public void commit() {
55 MockUp<Query> mockUpQuery = new MockUp<Query>() {
59 public Query setString(String name, String value) {
60 return mockUpQuery.getMockInstance();
63 public Query setDate(String name, Date value) {
64 return mockUpQuery.getMockInstance();
67 public Query setInteger(String name, int value) {
68 return mockUpQuery.getMockInstance();
71 public int executeUpdate() {
75 public Query setMaxResults(int value) {
76 return mockUpQuery.getMockInstance();
79 public Query setFirstResult(int firstResult) {
80 return mockUpQuery.getMockInstance();
83 public Query setParameterList(String name, Object[] values) {
84 return mockUpQuery.getMockInstance();
87 public List<PerformanceInformation> list() {
88 PerformanceInformation pi = new PerformanceInformation();
89 return Arrays.asList(pi);
92 public Object uniqueResult() {
96 MockUp<Session> mockedSession = new MockUp<Session>() {
98 public Query createQuery(String sql) {
99 return mockUpQuery.getMockInstance();
102 public Transaction beginTransaction() {
103 return mockUpTransaction.getMockInstance();
106 public Transaction getTransaction() {
107 return mockUpTransaction.getMockInstance();
110 public Serializable save(Object object) {
111 return (Serializable) serialVersionUID;
114 public void flush() {
117 public void update(Object object) {
120 new MockUp<SessionFactory>() {
122 public Session openSession() {
123 return mockedSession.getMockInstance();
126 new MockUp<PerformanceInformationServiceImpl>() {
128 private Session getSession() {
129 return mockedSession.getMockInstance();
135 public void after() throws Exception {
139 public void testSavePerformanceInformation() throws Exception {
141 PerformanceInformation pi = null;
142 performanceInformationServiceImpl.savePerformanceInformation(pi);
143 } catch (Exception e) {
149 public void testUpdatePerformanceInformation() throws Exception {
151 PerformanceInformation pi = null;
152 performanceInformationServiceImpl.updatePerformanceInformation(pi);
153 } catch (Exception e) {
159 public void testQueryId() throws Exception {
161 String[] id = {"1", "2", "3"};
162 performanceInformationServiceImpl.queryId(id);
163 } catch (Exception e) {
169 public void testQueryDateBetween() throws Exception {
171 performanceInformationServiceImpl.queryDateBetween("eventId", DateUtils.now(), DateUtils.now());
172 performanceInformationServiceImpl.queryDateBetween("resourceId", "name", "startTime", "endTime");
173 } catch (Exception e) {
179 public void testQueryDataBetweenSum() throws Exception {
181 performanceInformationServiceImpl.queryDataBetweenSum("eventId", "name", DateUtils.now(), DateUtils.now());
182 } catch (Exception e) {
188 public void testQueryMaxValueByBetweenDate() throws Exception {
190 performanceInformationServiceImpl.queryMaxValueByBetweenDate("", "","","");
191 performanceInformationServiceImpl.queryMaxValueByBetweenDate("eventId", "name","1527151520000","1527151620000");
192 } catch (Exception e) {
198 public void testGetAllPerformanceInformationByHeaderId() throws Exception {
200 performanceInformationServiceImpl.getAllPerformanceInformationByHeaderId("0a573f09d50f46adaae0c10e741fea4d");
201 } catch (Exception e) {