3aac705b5bd0aced105229c63a84882b53e60e2f
[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.HostDaoImpl;
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.mapper.HostMapper;
26 import org.onap.vfc.nfvo.res.service.mapper.NetworkMapper;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
28
29 import mockit.Expectations;
30 import mockit.Mock;
31 import mockit.MockUp;
32 import mockit.Mocked;
33
34 public class HostDaoImplTest {
35     @Mocked
36     HostMapper mapper;
37     @Test
38     public void testdeleteHost() throws ServiceException {
39
40         new MockUp<AbstractDao>() {
41
42             @Mock
43              public <T> T getMapperManager(Class<T> type) {
44                 return (T) mapper;
45
46             }
47         };
48         HostDaoImpl impl = new HostDaoImpl();
49         assertEquals(0, impl.deleteHost("123"));
50     }
51
52     @Test
53     public void testdeleteHostByVimId() throws ServiceException {
54
55         new MockUp<AbstractDao>() {
56
57             @Mock
58              public <T> T getMapperManager(Class<T> type) {
59                 return (T) mapper;
60
61             }
62         };
63         HostDaoImpl impl = new HostDaoImpl();
64         assertEquals(0, impl.deleteHostByVimId("123"));
65     }
66
67     @Test
68     public void testaddHost() throws ServiceException {
69
70         new MockUp<AbstractDao>() {
71
72             @Mock
73              public <T> T getMapperManager(Class<T> type) {
74                 return (T) mapper;
75
76             }
77         };
78         HostDaoImpl impl = new HostDaoImpl();
79         HostEntity hostEntity =new HostEntity();
80         hostEntity.setId("1");
81         assertEquals(0, impl.addHost(hostEntity));
82
83     }
84
85     @Test
86     public void testaddHostSelective() throws ServiceException {
87
88         new MockUp<AbstractDao>() {
89
90             @Mock
91              public <T> T getMapperManager(Class<T> type) {
92                 return (T) mapper;
93
94             }
95         };
96         HostDaoImpl impl = new HostDaoImpl();
97         HostEntity hostEntity =new HostEntity();
98         hostEntity.setId("1");
99         assertEquals(0, impl.addHostSelective(hostEntity));
100
101     }
102
103     @Test
104     public void testupdateHostSelective() throws ServiceException {
105
106         new MockUp<AbstractDao>() {
107
108             @Mock
109              public <T> T getMapperManager(Class<T> type) {
110                 return (T) mapper;
111
112             }
113         };
114         HostDaoImpl impl = new HostDaoImpl();
115         HostEntity hostEntity =new HostEntity();
116         hostEntity.setId("1");
117         assertEquals(0, impl.updateHostSelective(hostEntity));
118
119     }
120
121     @Test
122     public void testupdateHost() 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         HostDaoImpl impl = new HostDaoImpl();
133         HostEntity hostEntity =new HostEntity();
134         hostEntity.setId("1");
135         assertEquals(0, impl.updateHost(hostEntity));
136
137     }
138
139     @Test
140     public void testupdateHostByVimId() throws ServiceException {
141
142         new MockUp<AbstractDao>() {
143
144             @Mock
145              public <T> T getMapperManager(Class<T> type) {
146                 return (T) mapper;
147
148             }
149         };
150         HostDaoImpl impl = new HostDaoImpl();
151         HostEntity hostEntity =new HostEntity();
152         hostEntity.setId("1");
153         assertEquals(0, impl.updateHostByVimId(hostEntity));
154
155     }
156
157 }