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