2  * ============LICENSE_START=======================================================
 
   3  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 
   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.
 
  16  * ============LICENSE_END=========================================================
 
  18 package org.onap.dcae.runtime.web.controllers;
 
  20 import org.onap.dcae.runtime.core.Edge;
 
  21 import org.onap.dcae.runtime.core.FlowGraph;
 
  22 import org.onap.dcae.runtime.core.Node;
 
  23 import org.onap.dcae.runtime.web.TestUtils;
 
  24 import org.onap.dcae.runtime.web.models.GraphRequest;
 
  25 import org.onap.dcae.runtime.web.service.GraphServiceImpl;
 
  26 import org.junit.Before;
 
  27 import org.junit.Test;
 
  28 import org.junit.runner.RunWith;
 
  29 import org.springframework.beans.factory.annotation.Autowired;
 
  30 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
 
  31 import org.springframework.boot.test.mock.mockito.MockBean;
 
  32 import org.springframework.http.MediaType;
 
  33 import org.springframework.test.context.junit4.SpringRunner;
 
  34 import org.springframework.test.web.servlet.MockMvc;
 
  36 import static org.mockito.Mockito.when;
 
  37 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
 
  38 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
 
  39 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
 
  40 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
  42 @RunWith(SpringRunner.class)
 
  44 public class TestFlowGraphController {
 
  47     private MockMvc mockMvc;
 
  50     private GraphServiceImpl graphService;
 
  52     private GraphRequest graphRequest;
 
  55     public void setUp() throws Exception{
 
  56         graphRequest = new GraphRequest();
 
  57         graphRequest.setId("1234");
 
  58         graphRequest.setName("nifi-main");
 
  59         graphRequest.setDescription("mock graph");
 
  63     public void testInitializeGraph() throws Exception{
 
  64         graphRequest.setMain(true);
 
  65         mockMvc.perform(post("/api/graph/main")
 
  66                         .contentType(MediaType.APPLICATION_JSON)
 
  67                         .content(TestUtils.convertObjectToJsonBytes(graphRequest)))
 
  68                         .andExpect(status().isCreated());
 
  72     public void testGetMainGraph() throws Exception{
 
  73         FlowGraph<Node, Edge> flowGraph = new FlowGraph<>("1234","nifi-main",true,"demo");
 
  74         when(this.graphService.getMainGraph()).thenReturn(flowGraph);
 
  75         mockMvc.perform(get("/api/graph/main"))
 
  76                 .andExpect(status().isOk())
 
  77                 .andExpect(jsonPath("id").value("1234"))
 
  78                 .andExpect(jsonPath("name").value("nifi-main"));
 
  82 //    public void testMainGraphNotFound() throws Exception{
 
  83 //        when(this.graphService.getMainGraph()).thenReturn(null);
 
  84 //        mockMvc.perform(get("/api/graph/main"))
 
  85 //                .andExpect(status().isNotFound());
 
  89 //    public void testConflictIfMainGraphExists() throws Exception{
 
  90 //        when(this.graphService.initializeMainGraph(graphRequest)).thenThrow(new MainGraphAlreadyExistException(""));
 
  91 //        mockMvc.perform(post("/api/graph/main")
 
  92 //                .contentType(MediaType.APPLICATION_JSON)
 
  93 //                .content(TestUtils.convertObjectToJsonBytes(graphRequest)))
 
  94 //                .andExpect(status().isConflict());