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