Distributing Blueprint to DCAE Dashboard Issue-ID: DCAEGEN2-2385>
[dcaegen2/platform.git] / mod2 / catalog-service / src / test / java / org / onap / dcaegen2 / platform / mod / web / BlueprintDistributionControllerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  org.onap.dcae
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
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.dcaegen2.platform.mod.web;
22
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;
30
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;
45
46 @ExtendWith(SpringExtension.class)
47 @WebMvcTest(BlueprintDistributionController.class)
48 public class BlueprintDistributionControllerTest {
49
50     @Autowired
51     MockMvc mockMvc;
52
53     @MockBean
54     private BlueprintDistributionService mockBlueprintDistributionService;
55
56     @BeforeEach
57     void setup() {
58     }
59
60
61     @Test
62     void test_distributeBlueprintById_shouldReturn201AndResponseBody() throws Exception {
63
64         ResponseEntity mockResponseEntity = new ResponseEntity<>(new SuccessResponse("Success"), HttpStatus.OK);
65
66         when(mockBlueprintDistributionService
67             .distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV)).thenReturn(mockResponseEntity);
68
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());
72
73         verify(mockBlueprintDistributionService, times(1)).distributeBlueprint(BP_DISTRIBUTION_MODEL_ID,BP_DISTRIBUTION_ENV);
74     }
75
76 }