2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright 2019 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.vid.controller;
25 import static org.mockito.BDDMockito.given;
26 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
27 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
28 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
30 import org.apache.log4j.BasicConfigurator;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.vid.services.RoleGeneratorService;
37 import org.springframework.http.MediaType;
38 import org.springframework.test.web.servlet.MockMvc;
39 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
41 @RunWith(MockitoJUnitRunner.class)
42 public class RoleGeneratorControllerTest {
44 private static final String PATH = "/generateRoleScript/{firstRun}";
46 private static final String FIRST_JSON = "{key1: val1}";
47 private static final String SECOND_JSON = "{key2: val2}";
49 private RoleGeneratorController roleGeneratorController;
50 private MockMvc mockMvc;
53 private RoleGeneratorService service;
57 roleGeneratorController = new RoleGeneratorController(service);
58 BasicConfigurator.configure();
59 mockMvc = MockMvcBuilders.standaloneSetup(roleGeneratorController).build();
61 given(service.generateRoleScript(true)).willReturn(FIRST_JSON);
62 given(service.generateRoleScript(false)).willReturn(SECOND_JSON);
66 public void generateRoleScript_shouldReturnJson_whenFirstRun() throws Exception {
67 mockMvc.perform(get(PATH, "true")
68 .contentType(MediaType.APPLICATION_JSON))
69 .andExpect(status().isOk())
70 .andExpect(content().json(FIRST_JSON));
74 public void generateRoleScript_shouldReturnJson_whenNoFirstRun() throws Exception {
75 mockMvc.perform(get(PATH, "false")
76 .contentType(MediaType.APPLICATION_JSON))
77 .andExpect(status().isOk())
78 .andExpect(content().json(SECOND_JSON));