013ecd7261d30b97077af2860a0a35709bb75c71
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / openo / nfvo / jujuvnfmadapter / service / process / VnfResourceMgrTest.java
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.jujuvnfmadapter.service.process;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.openo.baseservice.remoteservice.exception.ServiceException;
29 import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant;
30 import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo;
31 import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample;
32 import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample.Criteria;
33 import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample.Criterion;
34 import org.openo.nfvo.jujuvnfmadapter.service.mapper.JujuVnfmInfoMapper;
35
36 import mockit.Expectations;
37 import mockit.Mock;
38 import mockit.MockUp;
39 import mockit.Mocked;
40 import mockit.integration.junit4.JMockit;
41 import net.sf.json.JSONObject;
42 import static mockit.Deencapsulation.*;
43
44
45 @RunWith(JMockit.class)
46
47 public class VnfResourceMgrTest {
48     VnfResourceMgr vnfMgr;
49     JujuVnfmInfoMapper jujuVnfmInfoMapper;
50     JujuVnfmInfoExample jujuexample = new JujuVnfmInfoExample();
51     Criteria criteria = jujuexample.createCriteria();
52
53     @Before
54     public void setUp() {
55         vnfMgr = new VnfResourceMgr();
56         vnfMgr.setJujuVnfmInfoMapper(jujuVnfmInfoMapper);
57         vnfMgr.getJujuVnfmInfoMapper();
58     }
59
60     @Test
61     public void grantVnfResourceTest() throws ServiceException {
62
63         String vnfId = "1";
64         new Expectations(vnfMgr) {
65             {
66                 invoke(vnfMgr, "findByVnfId", "1");
67                 JujuVnfmInfo info = new JujuVnfmInfo();
68                 info.setId("1");
69                 info.setAppName("Test");
70                 info.setJobId("1");
71                 info.setVnfId(vnfId);
72                 returns(info);
73             }
74         };
75         JSONObject compute = new JSONObject();
76         JSONObject res = vnfMgr.grantVnfResource(compute, vnfId);
77         assertEquals(res.get("retCode"), -1);
78     }
79
80 }