d0fd3fede0d25b560d1d3a98a24df764fadb42af
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
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.openo.nfvo.resmanagement.service.dao.impl;
17
18 import static org.junit.Assert.*;
19
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.junit.Test;
25 import org.openo.baseservice.remoteservice.exception.ServiceException;
26 import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
27 import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper;
28 import mockit.Expectations;
29 import mockit.Mock;
30 import mockit.MockUp;
31 import mockit.Mocked;
32
33 public class NetworkDaoImplTest {
34     @Mocked
35     NetworkMapper mapper;
36     @Test
37     public void testdeleteNetwork() throws ServiceException {
38
39          new Expectations() {{
40              mapper.deleteNetwork("123");
41            }};
42
43         new MockUp<AbstractDao>() {
44
45             @Mock
46              public <T> T getMapperManager(Class<T> type) {
47                 return (T) mapper;
48
49             }
50         };
51         NetworkDaoImpl impl = new NetworkDaoImpl();
52         assertEquals(0, impl.deleteNetwork("123"));
53
54     }
55     @Test
56     public void testdeleteNetworkByVimId() throws ServiceException {
57             new MockUp<AbstractDao>() {
58
59             @Mock
60              public <T> T getMapperManager(Class<T> type) {
61                 return (T) mapper;
62
63             }
64         };
65         NetworkDaoImpl impl = new NetworkDaoImpl();
66         assertEquals(0, impl.deleteNetworkByVimId("123"));
67
68     }
69     @Test
70     public void testaddNetwork() throws ServiceException {
71             new MockUp<AbstractDao>() {
72
73             @Mock
74              public <T> T getMapperManager(Class<T> type) {
75                 return (T) mapper;
76
77             }
78         };
79         NetworkDaoImpl impl = new NetworkDaoImpl();
80         NetworkEntity networkEntity =new NetworkEntity();
81         networkEntity.setId("1");
82         assertEquals(0, impl.addNetwork(networkEntity));
83
84     }
85
86     @Test
87     public void testaddNetworkSelective() throws ServiceException {
88
89             new MockUp<AbstractDao>() {
90
91             @Mock
92              public <T> T getMapperManager(Class<T> type) {
93                 return (T) mapper;
94
95             }
96         };
97         NetworkDaoImpl impl = new NetworkDaoImpl();
98         NetworkEntity networkEntity =new NetworkEntity();
99         networkEntity.setId("1");
100         assertEquals(0, impl.addNetworkSelective(networkEntity));
101     }
102     @Test
103     public void testupdateNetworkSelective() throws ServiceException {
104
105             new MockUp<AbstractDao>() {
106
107             @Mock
108              public <T> T getMapperManager(Class<T> type) {
109                 return (T) mapper;
110
111             }
112         };
113         NetworkDaoImpl impl = new NetworkDaoImpl();
114         NetworkEntity networkEntity =new NetworkEntity();
115         networkEntity.setId("1");
116         assertEquals(0, impl.updateNetworkSelective(networkEntity));
117     }
118     @Test
119     public void testupdateNetwork() throws ServiceException {
120
121             new MockUp<AbstractDao>() {
122
123             @Mock
124              public <T> T getMapperManager(Class<T> type) {
125                 return (T) mapper;
126
127             }
128         };
129         NetworkDaoImpl impl = new NetworkDaoImpl();
130         NetworkEntity networkEntity =new NetworkEntity();
131         networkEntity.setId("1");
132         assertEquals(0, impl.updateNetwork(networkEntity));
133
134     }
135     @Test
136     public void testupdateNetworkByVimId() throws ServiceException {
137
138             new MockUp<AbstractDao>() {
139
140             @Mock
141              public <T> T getMapperManager(Class<T> type) {
142                 return (T) mapper;
143
144             }
145         };
146         NetworkDaoImpl impl = new NetworkDaoImpl();
147         NetworkEntity networkEntity =new NetworkEntity();
148         networkEntity.setId("1");
149         assertEquals(0, impl.updateNetworkByVimId(networkEntity));
150
151     }
152 }