1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Wipro Limited.
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=========================================================
20 *******************************************************************************/
22 package org.onap.dcaegen2.services.sonhms.restclient;
24 import static org.junit.Assert.assertEquals;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Matchers;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.dcaegen2.services.sonhms.Configuration;
36 import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException;
37 import org.onap.dcaegen2.services.sonhms.model.AnrInput;
38 import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate;
39 import org.powermock.api.mockito.PowerMockito;
40 import org.powermock.core.classloader.annotations.PrepareForTest;
41 import org.powermock.modules.junit4.PowerMockRunner;
42 import org.powermock.modules.junit4.PowerMockRunnerDelegate;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.core.ParameterizedTypeReference;
45 import org.springframework.http.ResponseEntity;
46 import org.springframework.test.context.junit4.SpringRunner;
48 @RunWith(PowerMockRunner.class)
49 @PowerMockRunnerDelegate(SpringRunner.class)
50 @PrepareForTest({ SonHandlerRestTemplate.class,Configuration.class })
51 @SpringBootTest(classes = OofRestClientTest.class)
52 public class OofRestClientTest {
53 Configuration configuration = Configuration.getInstance();
57 MockitoAnnotations.initMocks(this);
61 public void queryOofTest() {
62 configuration.setBufferTime(60);
63 configuration.setCallbackUrl("/callbackUrl");
64 List<String> list = new ArrayList<String>();
66 configuration.setDmaapServers(list);
67 configuration.setCg("cg");
68 configuration.setCid("cid");
69 configuration.setMaximumClusters(5);
70 configuration.setMinCollision(5);
71 configuration.setMinConfusion(5);
72 configuration.setNumSolutions(1);
73 configuration.setOofService("oofService");
74 configuration.setPciOptimizer("pci");
75 configuration.setPollingInterval(30);
76 configuration.setPollingTimeout(100);
77 configuration.setConfigDbService("sdnrService");
78 configuration.setSourceId("sourceId");
79 String responseBody="{\n" +
80 " \"transactionId\": \"xxx-xxx-xxxx\",\n" +
81 " \"requestId\": \"yyy-yyy-yyyy\",\n" +
82 " \"requestStatus\": \"accepted\",\n" +
83 " \"statusMessage\": \"\"\n" +
85 List<String> cellIdList=new ArrayList<String>();
86 cellIdList.add("EXP001");
87 List<String> optimizers=new ArrayList<String>();
88 optimizers.add("pci");
89 List<AnrInput> anrInputList = new ArrayList<>();
91 PowerMockito.mockStatic(SonHandlerRestTemplate.class);
92 PowerMockito.mockStatic(Configuration.class);
93 PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
94 PowerMockito.when(SonHandlerRestTemplate.sendPostRequestToOof(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any()))
95 .thenReturn(ResponseEntity.ok(responseBody));
100 String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers, anrInputList);
101 assertEquals(ResponseEntity.ok(responseBody).getBody(), result);
104 } catch (OofNotFoundException e) {
105 // TODO Auto-generated catch block
108 PowerMockito.when(SonHandlerRestTemplate.sendPostRequestToOof(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any()))
112 OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers, new ArrayList<>());
114 } catch (OofNotFoundException e) {
115 // TODO Auto-generated catch block