diff options
Diffstat (limited to 'components/slice-analysis-ms/src/test/java/org/onap/slice')
3 files changed, 15 insertions, 28 deletions
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java index b19b4801..95da3667 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java @@ -22,6 +22,7 @@ package org.onap.slice.analysis.ms.restclients; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; import java.util.Collections; import java.util.HashMap; @@ -31,49 +32,39 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; +import org.onap.slice.analysis.ms.service.SnssaiSamplesProcessorTest; import org.onap.slice.analysis.ms.utils.BeanUtil; -import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; -@RunWith(PowerMockRunner.class) -@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) -@PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ BeanUtil.class }) -@SpringBootTest(classes = RestClient.class) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RestClientTest.class) public class RestClientTest { - @Mock RestTemplate restTemplate; - @InjectMocks RestClient restclient; - - @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) + @SuppressWarnings({ "static-access"}) @Test public void sendGetRequestTest() { - - PowerMockito.mockStatic(BeanUtil.class); - PowerMockito.when(BeanUtil.getBean(Mockito.any())).thenReturn(restTemplate); - ParameterizedTypeReference<Map<String,Integer>> responseType = null; + ParameterizedTypeReference<Map<String,Integer>> responseType = null; HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); @@ -82,7 +73,7 @@ public class RestClientTest { responsemap.put("dLThptPerSlice", 1); responsemap.put("uLThptPerSlice", 2); String requestUrl=""; - PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.GET,requestEntity,responseType)).thenReturn(ResponseEntity.ok(responsemap)); + when(restTemplate.exchange(requestUrl, HttpMethod.GET,requestEntity,responseType)).thenReturn(ResponseEntity.ok(responsemap)); ResponseEntity<Map<String,Integer>> resp = restclient.sendGetRequest(headers, requestUrl, responseType); assertEquals(resp.getBody(),responsemap); } @@ -90,15 +81,13 @@ public class RestClientTest { @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) @Test public void sendPostRequestTest() { - PowerMockito.mockStatic(BeanUtil.class); - PowerMockito.when(BeanUtil.getBean(RestTemplate.class)).thenReturn(restTemplate); ParameterizedTypeReference<String> responseType = null; HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); String requestUrl = "Url"; String requestBody = null; HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); - PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.OK)); + when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.OK)); ResponseEntity<String> resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); assertEquals(resp.getStatusCode(), HttpStatus.OK); } @@ -111,7 +100,7 @@ public class RestClientTest { headers.setContentType(MediaType.APPLICATION_JSON); String requestUrl = "Url"; String requestBody = null; HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); - PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.NOT_FOUND)); + when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.NOT_FOUND)); ResponseEntity<String> resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); assertEquals(resp.getStatusCode(), HttpStatus.NOT_FOUND); } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java index e9c134f7..05e60171 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java @@ -70,7 +70,6 @@ public class AverageCalculatorTest { catch (IOException e) { e.printStackTrace(); } - assertEquals(output, averageCalculator.findAverageOfSamples(input)); } @@ -113,5 +112,4 @@ public class AverageCalculatorTest { assertEquals(new MeasurementObject("cell1", result), averageCalculator.findSum(new MeasurementObject("cell1", existingMap), new MeasurementObject("cell1", currentMap))); } -} - +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java index b8316dfe..e8cc2145 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java @@ -130,7 +130,7 @@ public class SnssaiSamplesProcessorTest { @Test public void calculatePercentageChangeTest() { - Map<String, Map<String, Integer>> ricConfiguration = null; + Map<String, Map<String, Object>> ricConfiguration = null; Map<String, Map<String, Integer>> exp = new HashMap<>(); Map<String, Integer> ric1 = new HashMap<>(); Map<String, Integer> ric2 = new HashMap<>(); @@ -140,7 +140,7 @@ public class SnssaiSamplesProcessorTest { exp.put("1", ric1); exp.put("2", ric2); try { - ricConfiguration = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricConfiguration.json"))), new TypeReference<Map<String, Map<String, Integer>>>(){}); + ricConfiguration = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricConfiguration.json"))), new TypeReference<Map<String, Map<String, Object>>>(){}); } catch (IOException e) { e.printStackTrace(); |