4edcdf324501b82d8cf7dfe8b32abb6916f7ed8d
[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 org.junit.Test;
21 import org.openo.baseservice.remoteservice.exception.ServiceException;
22 import org.openo.nfvo.resmanagement.service.entity.HostEntity;
23 import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
24 import org.openo.nfvo.resmanagement.service.entity.PortEntity;
25 import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper;
26 import org.openo.nfvo.resmanagement.service.mapper.PortMapper;
27
28 import mockit.Expectations;
29 import mockit.Mock;
30 import mockit.MockUp;
31 import mockit.Mocked;
32
33 public class PortDaoImplTest {
34     @Mocked
35     PortMapper mapper;
36
37
38     @Test
39     public void testdeletePort() throws ServiceException {
40
41          new Expectations() {{
42              mapper.deletePort("123");
43            }};
44
45         new MockUp<AbstractDao>() {
46
47             @Mock
48              public <T> T getMapperManager(Class<T> type) {
49                 return (T) mapper;
50
51             }
52         };
53         PortDaoImpl impl = new PortDaoImpl();
54         assertEquals(0, impl.deletePort("123"));
55
56
57     }
58     @Test
59     public void testdeletePortByVimId() 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         PortDaoImpl impl = new PortDaoImpl();
69         assertEquals(0, impl.deletePortByVimId("123"));
70
71     }
72
73     @Test
74     public void testaddPort() throws ServiceException {
75             new MockUp<AbstractDao>() {
76
77             @Mock
78              public <T> T getMapperManager(Class<T> type) {
79                 return (T) mapper;
80
81             }
82         };
83         PortDaoImpl impl = new PortDaoImpl();
84         PortEntity portEntity =new PortEntity();
85         portEntity.setId("1");
86         assertEquals(0, impl.addPort(portEntity));
87
88     }
89
90     @Test
91     public void testaddPortSelective() throws ServiceException {
92
93         new MockUp<AbstractDao>() {
94
95             @Mock
96              public <T> T getMapperManager(Class<T> type) {
97                 return (T) mapper;
98
99             }
100         };
101         PortDaoImpl impl = new PortDaoImpl();
102         PortEntity portEntity =new PortEntity();
103         portEntity.setId("1");
104         assertEquals(0, impl.addPortSelective(portEntity));
105
106     }
107
108     @Test
109     public void testupdatePortSelective() throws ServiceException {
110
111             new MockUp<AbstractDao>() {
112
113             @Mock
114              public <T> T getMapperManager(Class<T> type) {
115                 return (T) mapper;
116
117             }
118         };
119         PortDaoImpl impl = new PortDaoImpl();
120         PortEntity portEntity =new PortEntity();
121         portEntity.setId("1");
122         assertEquals(0, impl.updatePortSelective(portEntity));
123     }
124     @Test
125     public void testupdatePort() throws ServiceException {
126
127             new MockUp<AbstractDao>() {
128
129             @Mock
130              public <T> T getMapperManager(Class<T> type) {
131                 return (T) mapper;
132
133             }
134         };
135         PortDaoImpl impl = new PortDaoImpl();
136         PortEntity portEntity =new PortEntity();
137         portEntity.setId("1");
138         assertEquals(0, impl.updatePort(portEntity));
139
140     }
141     @Test
142     public void testupdatePortByVimId() throws ServiceException {
143
144             new MockUp<AbstractDao>() {
145
146             @Mock
147              public <T> T getMapperManager(Class<T> type) {
148                 return (T) mapper;
149
150             }
151         };
152         PortDaoImpl impl = new PortDaoImpl();
153         PortEntity portEntity =new PortEntity();
154         portEntity.setId("1");
155         assertEquals(0, impl.updatePortByVimId(portEntity));
156
157     }
158 }