2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.svnfm.simulator.controllers;
23 import static org.mockito.Mockito.when;
24 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
25 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
26 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.svnfm.simulator.controller.SvnfmController;
35 import org.onap.svnfm.simulator.repository.VnfmCacheRepository;
36 import org.onap.svnfm.simulator.services.SvnfmService;
37 import org.onap.vnfm.v1.model.CreateVnfRequest;
38 import org.onap.vnfm.v1.model.InlineResponse201;
39 import org.springframework.http.MediaType;
40 import org.springframework.test.web.servlet.MockMvc;
41 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
42 import com.fasterxml.jackson.databind.ObjectMapper;
44 @RunWith(MockitoJUnitRunner.class)
45 public class TestSvnfmController {
48 private SvnfmController svnfmController;
50 private MockMvc mockMvc;
53 private SvnfmService svnfmService;
56 private VnfmCacheRepository vnfmCacheRepository;
60 MockitoAnnotations.initMocks(this);
61 this.mockMvc = MockMvcBuilders.standaloneSetup(svnfmController).build();
65 public void createVnfInstanceTest() throws Exception {
66 final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
68 createVnfRequest.setVnfdId("123456798");
69 createVnfRequest.setVnfInstanceName("createVnfInstanceTest");
70 createVnfRequest.setVnfInstanceDescription("createVnfInstanceTest");
72 when(vnfmCacheRepository.createVnf(createVnfRequest)).thenReturn(new InlineResponse201());
74 svnfmService.createVnf(createVnfRequest);
76 final String body = (new ObjectMapper()).valueToTree(createVnfRequest).toString();
78 .perform(post("/svnfm/vnf_instances").content(body).contentType(MediaType.APPLICATION_JSON)
79 .accept(MediaType.APPLICATION_JSON))
80 .andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON));