4deb71ee811280aa7fa5bfa1fa98e3c3d068172b
[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.NetworkEntity;
23 import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
24 import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper;
25 import org.openo.nfvo.resmanagement.service.mapper.SitesMapper;
26
27 import mockit.Expectations;
28 import mockit.Mock;
29 import mockit.MockUp;
30 import mockit.Mocked;
31
32 public class SitesDaoImplTest {
33     @Mocked
34     SitesMapper mapper;
35     @Test
36     public void testdeleteSite() throws ServiceException {
37
38          new Expectations() {{
39              mapper.deleteSite("123");
40            }};
41
42         new MockUp<AbstractDao>() {
43
44             @Mock
45              public <T> T getMapperManager(Class<T> type) {
46                 return (T) mapper;
47
48             }
49         };
50         SitesDaoImpl impl = new SitesDaoImpl();
51         assertEquals(0, impl.deleteSite("123"));
52     }
53     @Test
54     public void testaddSite() throws ServiceException {
55             new MockUp<AbstractDao>() {
56
57             @Mock
58              public <T> T getMapperManager(Class<T> type) {
59                 return (T) mapper;
60
61             }
62         };
63         SitesDaoImpl impl = new SitesDaoImpl();
64         SitesEntity sitesEntity =new SitesEntity();
65         sitesEntity.setId("1");
66         assertEquals(0, impl.addSite(sitesEntity));
67     }
68     @Test
69     public void testaddSiteSelective() throws ServiceException {
70
71             new MockUp<AbstractDao>() {
72
73             @Mock
74              public <T> T getMapperManager(Class<T> type) {
75                 return (T) mapper;
76
77             }
78         };
79         SitesDaoImpl impl = new SitesDaoImpl();
80         SitesEntity sitesEntity =new SitesEntity();
81         sitesEntity.setId("1");
82         assertEquals(0, impl.addSiteSelective(sitesEntity));
83     }
84     @Test
85     public void testupdateSiteSelective() throws ServiceException {
86
87             new MockUp<AbstractDao>() {
88
89             @Mock
90              public <T> T getMapperManager(Class<T> type) {
91                 return (T) mapper;
92
93             }
94         };
95         SitesDaoImpl impl = new SitesDaoImpl();
96         SitesEntity sitesEntity =new SitesEntity();
97         sitesEntity.setId("1");
98         assertEquals(0, impl.updateSiteSelective(sitesEntity));
99     }
100     @Test
101     public void testupdateNetwork() throws ServiceException {
102
103             new MockUp<AbstractDao>() {
104
105             @Mock
106              public <T> T getMapperManager(Class<T> type) {
107                 return (T) mapper;
108
109             }
110         };
111         SitesDaoImpl impl = new SitesDaoImpl();
112         SitesEntity sitesEntity =new SitesEntity();
113         sitesEntity.setId("1");
114         assertEquals(0, impl.updateSite(sitesEntity));
115     }
116     @Test
117     public void testupdateSiteByVimId() throws ServiceException {
118
119             new MockUp<AbstractDao>() {
120
121             @Mock
122              public <T> T getMapperManager(Class<T> type) {
123                 return (T) mapper;
124
125             }
126         };
127         SitesDaoImpl impl = new SitesDaoImpl();
128         SitesEntity sitesEntity =new SitesEntity();
129         sitesEntity.setId("1");
130         assertEquals(0, impl.updateSiteByVimId(sitesEntity));
131     }
132 }