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