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