2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.platform.mod.web;
23 import org.onap.dcaegen2.platform.mod.model.specification.DeploymentType;
24 import org.onap.dcaegen2.platform.mod.model.restapi.SpecificationRequest;
25 import org.onap.dcaegen2.platform.mod.model.specification.Specification;
26 import org.onap.dcaegen2.platform.mod.web.controller.SpecificationController;
27 import org.onap.dcaegen2.platform.mod.web.service.specification.SpecificationService;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
33 import org.springframework.boot.test.mock.mockito.MockBean;
34 import org.springframework.http.MediaType;
35 import org.springframework.test.context.junit.jupiter.SpringExtension;
36 import org.springframework.test.web.servlet.MockMvc;
38 import static org.onap.dcaegen2.platform.mod.objectmothers.BaseMsObjectMother.asJsonString;
39 import static org.onap.dcaegen2.platform.mod.objectmothers.MsInstanceObjectMother.MS_INSTANCE_ID;
40 import static org.onap.dcaegen2.platform.mod.objectmothers.SpecificationObjectMother.getMockSpecification;
41 import static org.onap.dcaegen2.platform.mod.objectmothers.SpecificationObjectMother.getSpecificationRequest;
42 import static org.hamcrest.Matchers.notNullValue;
43 import static org.mockito.Mockito.*;
44 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
45 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
46 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
48 @ExtendWith(SpringExtension.class)
49 @WebMvcTest(SpecificationController.class)
50 public class SpecificationControllerTest {
56 private SpecificationService mockSpecificationService;
63 void test_addSpecification_returnsSpecification() throws Exception {
65 SpecificationRequest specificationRequest = getSpecificationRequest();
66 Specification specification = getMockSpecification(DeploymentType.DOCKER);
68 when(mockSpecificationService.createSpecification(MS_INSTANCE_ID, specificationRequest)).thenReturn(specification);
71 mockMvc.perform(post("/api/specification/" + MS_INSTANCE_ID)
72 .contentType(MediaType.APPLICATION_JSON)
73 .content(asJsonString(specificationRequest)).accept(MediaType.APPLICATION_JSON))
74 .andExpect(jsonPath("$.id", notNullValue()))
75 .andExpect(status().isCreated());
76 verify(mockSpecificationService, times(1)).createSpecification(MS_INSTANCE_ID, specificationRequest);