X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=PolicyEngineAPI%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fstd%2FStdPolicyEngineTest.java;h=90e00c2c3bc33ffd5373391ce1ad503968394773;hb=2ae7194f9b915e42bba68537eec9426baa5ae456;hp=1218f1914e0b3fa490daf4e25cb65c387dec64dc;hpb=bffca61e5b75c556c7a0a1bda4e537146d4ec2ae;p=policy%2Fengine.git diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java index 1218f1914..90e00c2c3 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/StdPolicyEngineTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,8 +24,8 @@ package org.onap.policy.std; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -72,7 +74,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.api.ConfigRequestParameters; import org.onap.policy.api.DecisionRequestParameters; import org.onap.policy.api.DecisionResponse; @@ -102,13 +103,14 @@ import org.onap.policy.api.PushPolicyParameters; import org.onap.policy.models.APIDictionaryResponse; import org.onap.policy.models.APIPolicyConfigResponse; import org.onap.policy.std.utils.PolicyConfigConstants; +import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestClientException; -@RunWith(MockitoJUnitRunner.class) +@RunWith(PowerMockRunner.class) public class StdPolicyEngineTest { private static final String ONAP_NAME_VAL = "ONAP_NAME"; @@ -140,17 +142,20 @@ public class StdPolicyEngineTest { assertEquals("TEST", StdPolicyEngine.getEnvironment()); assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL()); assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType()); - assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList()); + assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), + policyEngine.getNotificationURLList()); } - + @Test public void testStdPolicyEngineWithPropertiesInitialize_noException() throws Exception { - final StdPolicyEngine policyEngine = new StdPolicyEngine(getDefaultProperties(), (String) null); + final StdPolicyEngine policyEngine = + new StdPolicyEngine(getDefaultProperties(), (String) null); policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS); assertEquals("TEST", StdPolicyEngine.getEnvironment()); assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL()); assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType()); - assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList()); + assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), + policyEngine.getNotificationURLList()); } @Test @@ -173,7 +178,8 @@ public class StdPolicyEngineTest { } @Test - public void testStdPolicyEngineInitializeWithSingleNotificationType_noException() throws Exception { + public void testStdPolicyEngineInitializeWithSingleNotificationType_noException() + throws Exception { final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE); final Properties properties = new Properties(); @@ -192,28 +198,32 @@ public class StdPolicyEngineTest { } @Test(expected = PolicyEngineException.class) - public void testStdPolicyEngineInitialize_InvalidPropertyFile_Exception() throws PolicyEngineException { + public void testStdPolicyEngineInitialize_InvalidPropertyFile_Exception() + throws PolicyEngineException { new StdPolicyEngine("Invalid.properties", (String) null); } @Test(expected = PolicyEngineException.class) - public void testStdPolicyEngineInitialize_InvalidPropertyFileWithExt_Exception() throws Exception { + public void testStdPolicyEngineInitialize_InvalidPropertyFileWithExt_Exception() + throws Exception { final File emptyFile = temporaryFolder.newFile("EmptyFile.txt"); new StdPolicyEngine(emptyFile.toString(), (String) null); } @Test(expected = PolicyEngineException.class) public void testStdPolicyEngineInitialize_NullArguments_Exception() throws Exception { - new StdPolicyEngine((String)null, (String) null); + new StdPolicyEngine((String) null, (String) null); } @Test(expected = PolicyEngineException.class) - public void testStdPolicyEngineWithPropertiesInitialize_NullArguments_Exception() throws Exception { - new StdPolicyEngine((Properties)null, (String) null); + public void testStdPolicyEngineWithPropertiesInitialize_NullArguments_Exception() + throws Exception { + new StdPolicyEngine((Properties) null, (String) null); } @Test(expected = PolicyEngineException.class) - public void testStdPolicyEngineInitialize_PropertyFileMissingMandatoryProperties_Exception() throws Exception { + public void testStdPolicyEngineInitialize_PropertyFileMissingMandatoryProperties_Exception() + throws Exception { final File file = temporaryFolder.newFile(INVALID_CONFIG_PROPERTY_FILE); final Properties properties = new Properties(); properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE); @@ -227,7 +237,8 @@ public class StdPolicyEngineTest { final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE); final Properties properties = new Properties(); - properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE + PolicyConfigConstants.SEMICOLLON + PDP_PROP_VALUE_1); + properties.setProperty(PDP_URL_PROP_NAME, + PDP_PROP_VALUE + PolicyConfigConstants.SEMICOLLON + PDP_PROP_VALUE_1); properties.setProperty(CLIENT_ID_PROP_NAME, "test"); properties.setProperty(CLIENT_KEY_PROP_NAME, "test"); properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP); @@ -242,7 +253,8 @@ public class StdPolicyEngineTest { StdPolicyEngine.rotatePDPList(); assertEquals("https://localhost:8091/pdp/", StdPolicyEngine.getPDPURL()); assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType()); - assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList()); + assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), + policyEngine.getNotificationURLList()); } @Test(expected = PolicyEngineException.class) @@ -285,7 +297,8 @@ public class StdPolicyEngineTest { @Test public void testStdPolicyEngineSendEvent_noException() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doReturn(new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED)).when(spyPolicyEngine) + doReturn(new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED)) + .when(spyPolicyEngine) .callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any()); final Collection actualPolicyResponses = @@ -296,7 +309,8 @@ public class StdPolicyEngineTest { } @Test(expected = PolicyEventException.class) - public void testStdPolicyEngineSendEvent_NullEventRequestParameters_Exception() throws Exception { + public void testStdPolicyEngineSendEvent_NullEventRequestParameters_Exception() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); spyPolicyEngine.sendEvent((EventRequestParameters) null); } @@ -305,8 +319,8 @@ public class StdPolicyEngineTest { public void testStdPolicyEngineSendEvent_EventRequestParameters_CallPDPThrow401Exception_Exception() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - Mockito.doThrow(new RuntimeException(new RestClientException("Error 401"))).when(spyPolicyEngine) - .callNewPDP(any(), any(), any(), any()); + Mockito.doThrow(new RuntimeException(new RestClientException("Error 401"))) + .when(spyPolicyEngine).callNewPDP(any(), any(), any(), any()); spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID); } @@ -317,29 +331,34 @@ public class StdPolicyEngineTest { final ResponseEntity stubbedResponse = new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), + any(), any(), any()); final EventRequestParameters eventRequestParameters = new EventRequestParameters(); eventRequestParameters.setEventAttributes(Collections.emptyMap()); eventRequestParameters.setRequestID(REQUEST_UUID); - final Collection actualPolicyResponses = spyPolicyEngine.sendEvent(eventRequestParameters); + final Collection actualPolicyResponses = + spyPolicyEngine.sendEvent(eventRequestParameters); assertEquals(1, actualPolicyResponses.size()); } @Test - public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigJSON_noException() throws Exception { + public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigJSON_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); final ResponseEntity stubbedResponse = new ResponseEntity<>( - getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION), HttpStatus.ACCEPTED); + getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION), + HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final Collection actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters()); + final Collection actualPolicyResponses = + spyPolicyEngine.getConfig(new ConfigRequestParameters()); assertEquals(1, actualPolicyResponses.size()); @@ -349,16 +368,18 @@ public class StdPolicyEngineTest { } @Test - public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigOther_noException() throws Exception { + public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigOther_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = - new ResponseEntity<>(getAPIPolicyConfigResponse(PolicyType.OTHER, COMMENTS), HttpStatus.ACCEPTED); + final ResponseEntity stubbedResponse = new ResponseEntity<>( + getAPIPolicyConfigResponse(PolicyType.OTHER, COMMENTS), HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final Collection actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters()); + final Collection actualPolicyResponses = + spyPolicyEngine.getConfig(new ConfigRequestParameters()); assertEquals(1, actualPolicyResponses.size()); @@ -368,16 +389,18 @@ public class StdPolicyEngineTest { } @Test - public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigXML_noException() throws Exception { + public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigXML_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); final ResponseEntity stubbedResponse = new ResponseEntity<>( getAPIPolicyConfigResponse(PolicyType.XML, XML_CONFIGURATION), HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final Collection actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters()); + final Collection actualPolicyResponses = + spyPolicyEngine.getConfig(new ConfigRequestParameters()); assertEquals(1, actualPolicyResponses.size()); @@ -391,13 +414,14 @@ public class StdPolicyEngineTest { throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = - new ResponseEntity<>(getAPIPolicyConfigResponse(PolicyType.PROPERTIES, COMMENTS), HttpStatus.ACCEPTED); + final ResponseEntity stubbedResponse = new ResponseEntity<>( + getAPIPolicyConfigResponse(PolicyType.PROPERTIES, COMMENTS), HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final Collection actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters()); + final Collection actualPolicyResponses = + spyPolicyEngine.getConfig(new ConfigRequestParameters()); assertEquals(1, actualPolicyResponses.size()); @@ -410,8 +434,8 @@ public class StdPolicyEngineTest { public void testStdPolicyEngineSendEvent_ConfigRequestParameters_CallPDPThrow404Exception_Exception() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(new RuntimeException(new RestClientException("Error 404"))).when(spyPolicyEngine).callNewPDP(any(), - any(), any(), any()); + doThrow(new RuntimeException(new RestClientException("Error 404"))).when(spyPolicyEngine) + .callNewPDP(any(), any(), any(), any()); spyPolicyEngine.getConfig(new ConfigRequestParameters()); } @@ -426,10 +450,11 @@ public class StdPolicyEngineTest { final ResponseEntity stubbedResponse = new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final Collection actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters()); + final Collection actualResponse = + spyPolicyEngine.listConfig(new ConfigRequestParameters()); assertEquals(1, actualResponse.size()); assertNotNull(actualResponse.iterator().next()); @@ -440,28 +465,32 @@ public class StdPolicyEngineTest { throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final APIPolicyConfigResponse[] apiPolicyConfigResponse = - getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION, PolicyConfigConstants.PE300); + final APIPolicyConfigResponse[] apiPolicyConfigResponse = getAPIPolicyConfigResponse( + PolicyType.JSON, JSON_CONFIGURATION, PolicyConfigConstants.PE300); final ResponseEntity stubbedResponse = new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final Collection actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters()); + final Collection actualResponse = + spyPolicyEngine.listConfig(new ConfigRequestParameters()); assertEquals(1, actualResponse.size()); } @Test - public void testStdPolicyEngineListConfig_ConfigRequestParametersWithTestProperty_noException() throws Exception { + public void testStdPolicyEngineListConfig_ConfigRequestParametersWithTestProperty_noException() + throws Exception { final Properties defaultProperties = getDefaultProperties(); defaultProperties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "test"); - final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine("test" + CONFIG_PROPERTIES_FILE, defaultProperties); + final StdPolicyEngine spyPolicyEngine = + getSpyPolicyEngine("test" + CONFIG_PROPERTIES_FILE, defaultProperties); - final Collection actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters()); + final Collection actualResponse = + spyPolicyEngine.listConfig(new ConfigRequestParameters()); assertEquals(1, actualResponse.size()); @@ -475,8 +504,8 @@ public class StdPolicyEngineTest { final ResponseEntity stubbedResponse = new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); final DecisionResponse actualResponse = spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID); @@ -485,7 +514,8 @@ public class StdPolicyEngineTest { } @Test(expected = PolicyDecisionException.class) - public void testStdPolicyEngineGetDecision_PolicyDecision_CallPDPThrow400Exception_Exception() throws Exception { + public void testStdPolicyEngineGetDecision_PolicyDecision_CallPDPThrow400Exception_Exception() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); doThrow(new RuntimeException(new RestClientException("Error 400"))).when(spyPolicyEngine) .callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST), any(), any()); @@ -493,15 +523,16 @@ public class StdPolicyEngineTest { } @Test - public void testStdPolicyEnginGetDecision_DecisionRequestParameters_noException() throws Exception { + public void testStdPolicyEnginGetDecision_DecisionRequestParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); final ResponseEntity stubbedResponse = new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); final DecisionRequestParameters requestParameters = new DecisionRequestParameters(); requestParameters.setOnapName(ONAP_NAME_VAL); @@ -514,22 +545,26 @@ public class StdPolicyEngineTest { } @Test(expected = PolicyDecisionException.class) - public void ttestStdPolicyEnginGetDecision_NullDecisionRequestParameters_Exception() throws Exception { + public void ttestStdPolicyEnginGetDecision_NullDecisionRequestParameters_Exception() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); spyPolicyEngine.getDecision((DecisionRequestParameters) null); } @Test - public void testStdPolicyEnginGetMetrics_MetricsRequestParameters_noException() throws Exception { + public void testStdPolicyEnginGetMetrics_MetricsRequestParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Metrics", HttpStatus.ACCEPTED); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Metrics", HttpStatus.ACCEPTED); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME), + eq(HttpMethod.GET), any(), any()); - final MetricsResponse actualResponse = spyPolicyEngine.getMetrics(new MetricsRequestParameters()); + final MetricsResponse actualResponse = + spyPolicyEngine.getMetrics(new MetricsRequestParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.ACCEPTED.value(), actualResponse.getResponseCode()); @@ -539,10 +574,12 @@ public class StdPolicyEngineTest { public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowHttpException_ResponseWithHttpCode() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))).when(spyPolicyEngine) + doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))) + .when(spyPolicyEngine) .callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), any(), any()); - final MetricsResponse actualResponse = spyPolicyEngine.getMetrics(new MetricsRequestParameters()); + final MetricsResponse actualResponse = + spyPolicyEngine.getMetrics(new MetricsRequestParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode()); @@ -552,8 +589,8 @@ public class StdPolicyEngineTest { public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowPolicyException_Exception() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME), - eq(HttpMethod.GET), any(), any()); + doThrow(PolicyException.class).when(spyPolicyEngine) + .callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), any(), any()); spyPolicyEngine.getMetrics(new MetricsRequestParameters()); @@ -564,12 +601,14 @@ public class StdPolicyEngineTest { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), + eq(HttpMethod.PUT), any(), any()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.pushPolicy(new PushPolicyParameters()); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.pushPolicy(new PushPolicyParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode()); @@ -579,10 +618,12 @@ public class StdPolicyEngineTest { public void testStdPolicyEnginePushPolicy_PushPolicyParametersThrowsHttpClientErrorException_ResponseWithHttpCode() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))).when(spyPolicyEngine) + doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))) + .when(spyPolicyEngine) .callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.pushPolicy(new PushPolicyParameters()); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.pushPolicy(new PushPolicyParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode()); @@ -592,41 +633,46 @@ public class StdPolicyEngineTest { @Test(expected = PolicyException.class) public void testStdPolicyEnginePushPolicy_PushPolicyParameters_Exception() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), - eq(HttpMethod.PUT), any(), any()); + doThrow(PolicyException.class).when(spyPolicyEngine) + .callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any()); spyPolicyEngine.pushPolicy(new PushPolicyParameters()); } @Test - public void testStdPolicyEnginDeletePolicy_DeletePolicyParameters_noException() throws Exception { + public void testStdPolicyEnginDeletePolicy_DeletePolicyParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(DELETE_POLICY_RESOURCE_NAME), eq(HttpMethod.DELETE), any(), any()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.deletePolicy(new DeletePolicyParameters()); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.deletePolicy(new DeletePolicyParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode()); } @Test - public void testStdPolicyEnginGetDictionaryItem_DictionaryParameters_noException() throws Exception { + public void testStdPolicyEnginGetDictionaryItem_DictionaryParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); final ResponseEntity stubbedResponse = new ResponseEntity<>(getAPIDictionaryResponse(), HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), - eq(HttpMethod.POST), any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP( + eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any()); - final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); + final DictionaryResponse actualResponse = + spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); assertNotNull(actualResponse); } @@ -635,11 +681,13 @@ public class StdPolicyEngineTest { public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp400ExceptionThrown_ResponseWithHttpCode() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Error 400"))) - .when(spyPolicyEngine) - .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any()); + doThrow(new RuntimeException( + new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Error 400"))) + .when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); + final DictionaryResponse actualResponse = + spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.BAD_REQUEST.value(), actualResponse.getResponseCode()); @@ -650,11 +698,13 @@ public class StdPolicyEngineTest { public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp401ExceptionThrown_ResponseWithHttpCode() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.UNAUTHORIZED, "Error 401"))) - .when(spyPolicyEngine) - .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any()); + doThrow(new RuntimeException( + new HttpClientErrorException(HttpStatus.UNAUTHORIZED, "Error 401"))) + .when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); + final DictionaryResponse actualResponse = + spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.UNAUTHORIZED.value(), actualResponse.getResponseCode()); @@ -665,11 +715,13 @@ public class StdPolicyEngineTest { public void testStdPolicyGetDictionaryItem_DictionaryParametersWithRunTimeExceptionThrown_ResponseWithHttpCode() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error"))) - .when(spyPolicyEngine) - .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any()); + doThrow(new RuntimeException( + new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error"))) + .when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), + eq(HttpMethod.POST), any(), any()); - final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); + final DictionaryResponse actualResponse = + spyPolicyEngine.getDictionaryItem(new DictionaryParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), actualResponse.getResponseCode()); @@ -677,50 +729,59 @@ public class StdPolicyEngineTest { } @Test - public void testStdPolicyEnginCreateDictionaryItem_DictionaryParameters_noException() throws Exception { + public void testStdPolicyEnginCreateDictionaryItem_DictionaryParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_DICTIONARY_ITEM_RESOURCE_NAME), - eq(HttpMethod.PUT), any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP( + eq(CREATE_DICTIONARY_ITEM_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.createDictionaryItem(new DictionaryParameters()); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.createDictionaryItem(new DictionaryParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode()); } @Test - public void testStdPolicyEnginUpdateDictionaryItem_DictionaryParameters_noException() throws Exception { + public void testStdPolicyEnginUpdateDictionaryItem_DictionaryParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_DICTIONARY_ITEM_RESOURCE_NAME), - eq(HttpMethod.PUT), any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP( + eq(UPDATE_DICTIONARY_ITEM_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.updateDictionaryItem(new DictionaryParameters()); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.updateDictionaryItem(new DictionaryParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode()); } @Test - public void testStdPolicyEnginPolicyEngineImport_ImportParameters_noException() throws Exception { + public void testStdPolicyEnginPolicyEngineImport_ImportParameters_noException() + throws Exception { final File emptyfile = temporaryFolder.newFile("emptyFile.txt"); final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(POLICY_ENGINE_IMPORT_RESOURCE_NAME), - eq(HttpMethod.POST), any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP( + eq(POLICY_ENGINE_IMPORT_RESOURCE_NAME), eq(HttpMethod.POST), any(), any()); final ImportParameters importParameters = new ImportParameters(); importParameters.setFilePath(emptyfile.toString()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.policyEngineImport(importParameters); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.policyEngineImport(importParameters); assertNotNull(actualResponse); assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode()); @@ -730,12 +791,14 @@ public class StdPolicyEngineTest { public void testStdPolicyEnginCreatePolicy_PolicyParameters_noException() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_POLICY_RESOURCE_NAME), + eq(HttpMethod.PUT), any(), any()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.createPolicy(new PolicyParameters()); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.createPolicy(new PolicyParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode()); @@ -745,12 +808,14 @@ public class StdPolicyEngineTest { public void testStdPolicyEnginUpdatePolicy_PolicyParameters_noException() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), + eq(HttpMethod.PUT), any(), any()); - final PolicyChangeResponse actualResponse = spyPolicyEngine.updatePolicy(new PolicyParameters()); + final PolicyChangeResponse actualResponse = + spyPolicyEngine.updatePolicy(new PolicyParameters()); assertNotNull(actualResponse); assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode()); @@ -781,53 +846,60 @@ public class StdPolicyEngineTest { public void testStdPolicyEnginPushPolicy_PolicyParameters_noException() throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), + eq(HttpMethod.PUT), any(), any()); - final String actualResponse = - spyPolicyEngine.pushPolicy("POLICY_SCOPE", ONAP_NAME_VAL, "POLICY_TYPE", "POLICY_GROUP", REQUEST_UUID); + final String actualResponse = spyPolicyEngine.pushPolicy("POLICY_SCOPE", ONAP_NAME_VAL, + "POLICY_TYPE", "POLICY_GROUP", REQUEST_UUID); assertNotNull(actualResponse); } @Test - public void testStdPolicyEnginCreateUpdateConfigPolicy_PolicyParameters_noException() throws Exception { + public void testStdPolicyEnginCreateUpdateConfigPolicy_PolicyParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), + eq(HttpMethod.PUT), any(), any()); - final String actualResponse = spyPolicyEngine.createUpdateConfigPolicy("POLICY_NAME", ONAP_NAME_VAL, - ONAP_NAME_VAL, "CONFIG_NAME", Collections.emptyMap(), PolicyType.JSON.toString().toUpperCase(), "", - "POLICY_SCOPE", REQUEST_UUID, "", "", "", new Date().toString(), true); + final String actualResponse = spyPolicyEngine.createUpdateConfigPolicy("POLICY_NAME", + ONAP_NAME_VAL, ONAP_NAME_VAL, "CONFIG_NAME", Collections.emptyMap(), + PolicyType.JSON.toString().toUpperCase(), "", "POLICY_SCOPE", REQUEST_UUID, "", "", + "", new Date().toString(), true); assertNotNull(actualResponse); } @Test(expected = PolicyException.class) - public void testStdPolicyEnginCreateUpdateConfigPolicy_NullPolicyName_Exception() throws Exception { + public void testStdPolicyEnginCreateUpdateConfigPolicy_NullPolicyName_Exception() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - spyPolicyEngine.createUpdateConfigPolicy(null, null, null, null, null, null, null, null, null, null, null, null, - null, true); + spyPolicyEngine.createUpdateConfigPolicy(null, null, null, null, null, null, null, null, + null, null, null, null, null, true); } @Test - public void testStdPolicyEnginCreateUpdateConfigFirewallPolicy_PolicyParameters_noException() throws Exception { + public void testStdPolicyEnginCreateUpdateConfigFirewallPolicy_PolicyParameters_noException() + throws Exception { final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine(); - final ResponseEntity stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK); + final ResponseEntity stubbedResponse = + new ResponseEntity<>("Successful", HttpStatus.OK); - doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), - any(), any()); + doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), + eq(HttpMethod.PUT), any(), any()); - final String actualResponse = - spyPolicyEngine.createUpdateConfigFirewallPolicy("POLICY_NAME", getJsonObject(JSON_CONFIGURATION), - "POLICY_SCOPE", REQUEST_UUID, "", "", "", new Date().toString(), true); + final String actualResponse = spyPolicyEngine.createUpdateConfigFirewallPolicy( + "POLICY_NAME", getJsonObject(JSON_CONFIGURATION), "POLICY_SCOPE", REQUEST_UUID, "", + "", "", new Date().toString(), true); assertNotNull(actualResponse); } @@ -848,7 +920,8 @@ public class StdPolicyEngineTest { creatPropertyFile(file, properties); - final StdPolicyEngine spyPolicyEngine = spy(new StdPolicyEngine(file.toString(), (String) null)); + final StdPolicyEngine spyPolicyEngine = + spy(new StdPolicyEngine(file.toString(), (String) null)); spyPolicyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS); return spyPolicyEngine; } @@ -889,7 +962,8 @@ public class StdPolicyEngineTest { return new StdPolicyResponse[] {response}; } - private void creatPropertyFile(final File file, final Properties properties) throws IOException { + private void creatPropertyFile(final File file, final Properties properties) + throws IOException { try (final BufferedWriter bufferedWriter = Files.newBufferedWriter(file.toPath());) { properties.store(bufferedWriter, COMMENTS); }