2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2021 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 static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26 import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_ENV;
27 import static org.onap.dcaegen2.platform.mod.objectmothers.BlueprintDistributionObjectMother.BP_DISTRIBUTION_MODEL_ID;
28 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
29 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.junit.jupiter.api.extension.ExtendWith;
34 import org.onap.dcaegen2.platform.mod.model.restapi.SuccessResponse;
35 import org.onap.dcaegen2.platform.mod.web.controller.BlueprintDistributionController;
36 import org.onap.dcaegen2.platform.mod.web.service.blueprintdistributionservice.BlueprintDistributionService;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
39 import org.springframework.boot.test.mock.mockito.MockBean;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.MediaType;
42 import org.springframework.http.ResponseEntity;
43 import org.springframework.test.context.junit.jupiter.SpringExtension;
44 import org.springframework.test.web.servlet.MockMvc;
46 @ExtendWith(SpringExtension.class)
47 @WebMvcTest(BlueprintDistributionController.class)
48 public class BlueprintDistributionControllerTest {
54 private BlueprintDistributionService mockBlueprintDistributionService;
62 void test_distributeBlueprintById_shouldReturn201AndResponseBody() throws Exception {
64 ResponseEntity mockResponseEntity = new ResponseEntity<>(new SuccessResponse("Success"), HttpStatus.OK);
66 when(mockBlueprintDistributionService
67 .distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV)).thenReturn(mockResponseEntity);
69 mockMvc.perform(post("/api/deployment-artifact/" + BP_DISTRIBUTION_MODEL_ID + "/distribute")
70 .param("env",BP_DISTRIBUTION_ENV).contentType(MediaType.APPLICATION_JSON))
71 .andExpect(status().isOk());
73 verify(mockBlueprintDistributionService, times(1)).distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV);