summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/sdnc/src
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-impl/sdnc/src')
-rw-r--r--models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java57
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java2
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java141
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java3
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java7
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java2
6 files changed, 67 insertions, 145 deletions
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
index 864ddf506..3679625ec 100644
--- a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
+++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
@@ -22,17 +22,14 @@
package org.onap.policy.sdnc;
-
import com.google.gson.JsonSyntaxException;
import java.util.HashMap;
import java.util.Map;
-import org.drools.core.WorkingMemory;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
-import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.rest.RestManager;
import org.onap.policy.rest.RestManager.Pair;
import org.onap.policy.sdnc.util.Serialization;
@@ -46,31 +43,41 @@ public final class SdncManager implements Runnable {
private String username;
private String password;
private SdncRequest sdncRequest;
- private WorkingMemory workingMem;
+ private SdncCallback callback;
private static final Logger logger = LoggerFactory.getLogger(SdncManager.class);
// The REST manager used for processing REST calls for this Sdnc manager
private RestManager restManager;
+ public interface SdncCallback {
+ public void onCallback(SdncResponse response);
+ }
+
/**
* Constructor.
*
- * @param wm Drools working memory
+ * @param cb Callback method
* @param request request
*/
- public SdncManager(WorkingMemory wm, SdncRequest request) {
- if (wm == null || request == null) {
+ public SdncManager(SdncCallback cb, SdncRequest request, String url,
+ String user, String password) {
+ if (cb == null || request == null) {
throw new IllegalArgumentException(
- "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null"
+ "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null"
);
}
- workingMem = wm;
- sdncRequest = request;
+ this.callback = cb;
+ this.sdncRequest = request;
+ if (url == null) {
+ throw new IllegalArgumentException(
+ "the \"url\" parameter on the SdncManager constructor may not be null"
+ );
+ }
+ this.sdncUrlBase = url;
+ this.username = user;
+ this.password = password;
restManager = new RestManager();
-
- setSdncParams(getPeManagerEnvProperty("sdnc.url"), getPeManagerEnvProperty("sdnc.username"),
- getPeManagerEnvProperty("sdnc.password"));
}
/**
@@ -108,12 +115,12 @@ public final class SdncManager implements Runnable {
sdncRequestJson);
} catch (Exception e) {
logger.info(e.getMessage(), e);
- workingMem.insert(responseError);
+ this.callback.onCallback(responseError);
return;
}
if (httpDetails == null) {
- workingMem.insert(responseError);
+ this.callback.onCallback(responseError);
return;
}
@@ -132,7 +139,7 @@ public final class SdncManager implements Runnable {
);
}
- workingMem.insert(response);
+ this.callback.onCallback(response);
} catch (JsonSyntaxException e) {
logger.info("Failed to deserialize into SdncResponse {}", e.getLocalizedMessage(), e);
} catch (Exception e) {
@@ -147,22 +154,4 @@ public final class SdncManager implements Runnable {
protected void setRestManager(final RestManager restManager) {
this.restManager = restManager;
}
-
- /**
- * This method reads and validates environmental properties coming from the policy engine. Null properties cause
- * an {@link IllegalArgumentException} runtime exception to be thrown
- * @param enginePropertyName name of the parameter to retrieve
- * @return the property value
- */
-
- private String getPeManagerEnvProperty(String enginePropertyName) {
- String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName);
- if (enginePropertyValue == null) {
- throw new IllegalArgumentException(
- "The value of policy engine manager environment property \""
- + enginePropertyName + "\" may not be null"
- );
- }
- return enginePropertyValue;
- }
}
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
index 53be3382b..1c18d9c8f 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
@@ -19,8 +19,6 @@
package org.onap.policy.sdnc;
-import java.util.LinkedList;
-
import org.junit.Test;
import org.onap.policy.sdnc.util.Serialization;
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
index ca6df0d0b..2a1cc6984 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
@@ -25,34 +25,24 @@ package org.onap.policy.sdnc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.endsWith;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.startsWith;
-
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.util.ArrayList;
-import java.util.List;
import java.util.UUID;
-
-import org.drools.core.WorkingMemory;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.rest.RestManager;
import org.onap.policy.rest.RestManager.Pair;
+import org.onap.policy.sdnc.SdncManager.SdncCallback;
import org.onap.policy.sdnc.util.Serialization;
-public class SdncManagerTest {
- private static WorkingMemory mockedWorkingMemory;
-
+public class SdncManagerTest implements SdncCallback {
private RestManager mockedRestManager;
private Pair<Integer, String> httpResponsePutOk;
@@ -65,7 +55,6 @@ public class SdncManagerTest {
@BeforeClass
public static void beforeTestSdncManager() {
- mockedWorkingMemory = mock(WorkingMemory.class);
}
/**
@@ -74,13 +63,13 @@ public class SdncManagerTest {
@Before
public void setupMockedRest() {
mockedRestManager = mock(RestManager.class);
-
+
httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
httpResponseErr = mockedRestManager.new Pair<>(200, null);
}
-
+
/**
* Create the request and response before.
*/
@@ -92,7 +81,7 @@ public class SdncManagerTest {
SdncHealRequestHeaderInfo additionalParams = new SdncHealRequestHeaderInfo();
additionalParams.setSvcAction("Go Home");
additionalParams.setSvcRequestId("My Request");
-
+
SdncHealRequest healRequest = new SdncHealRequest();
healRequest.setRequestHeaderInfo(additionalParams);
healRequest.setServiceInfo(serviceInfo);
@@ -112,87 +101,48 @@ public class SdncManagerTest {
response.setRequestId(request.getRequestId().toString());
response.setResponseOutput(responseDescriptor);
}
-
- /**
- * After Test clean up.
- */
- @After
- public void afterTestSdncManager() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().remove("sdnc.password");
- PolicyEngine.manager.getEnvironment().remove("sdnc.username");
- PolicyEngine.manager.getEnvironment().remove("sdnc.url");
- }
@Test
public void testSdncInitiation() throws InterruptedException {
try {
- new SdncManager(null, null);
+ new SdncManager(null, null, null, null, null);
fail("test should throw an exception here");
}
catch (IllegalArgumentException e) {
assertEquals(
- "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null",
+ "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null",
e.getMessage()
);
}
-
- try {
- new SdncManager(mockedWorkingMemory, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals(
- "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null",
- e.getMessage()
- );
- }
-
- try {
- new SdncManager(mockedWorkingMemory, request);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals(
- "The value of policy engine manager environment property \"sdnc.url\" may not be null",
- e.getMessage()
- );
- }
-
- PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
+
try {
- new SdncManager(mockedWorkingMemory, request);
+ new SdncManager(this, null, null, null, null);
fail("test should throw an exception here");
}
catch (IllegalArgumentException e) {
assertEquals(
- "The value of policy engine manager environment property \"sdnc.username\" may not be null",
+ "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null",
e.getMessage()
);
}
-
- PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
+
try {
- new SdncManager(mockedWorkingMemory, request);
+ new SdncManager(this, request, null, null, null);
fail("test should throw an exception here");
}
catch (IllegalArgumentException e) {
assertEquals(
- "The value of policy engine manager environment property \"sdnc.password\" may not be null",
+ "the \"url\" parameter on the SdncManager constructor may not be null",
e.getMessage()
);
}
-
- PolicyEngine.manager.getEnvironment().put("sdnc.password", "Toto");
- new SdncManager(mockedWorkingMemory, request);
+
+ new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Toto");
}
@Test
public void testSdncExecutionException() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("sdnc.password", "Exception");
-
- SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+ SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Exception");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
@@ -200,85 +150,76 @@ public class SdncManagerTest {
when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Exception"), anyMap(), anyString(), anyString()))
.thenThrow(new RuntimeException("OzException"));
-
+
managerThread.join(100);
}
-
+
@Test
public void testSdncExecutionNull() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("sdnc.password", "Null");
-
- SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+ SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Null");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
-
+
when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
.thenReturn(null);
-
+
managerThread.join(100);
}
@Test
public void testSdncExecutionError0() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("sdnc.password", "Error0");
-
- SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+ SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Error0");
manager.setRestManager(mockedRestManager);
-
+
Thread managerThread = new Thread(manager);
managerThread.start();
-
+
when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseErr);
-
+
managerThread.join(100);
}
@Test
public void testSdncExecutionBadResponse() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("sdnc.password", "BadResponse");
-
- SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+ SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "BadResponse");
manager.setRestManager(mockedRestManager);
-
+
Thread managerThread = new Thread(manager);
managerThread.start();
-
+
when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseBadResponse);
-
+
managerThread.join(100);
}
-
+
@Test
public void testSdncExecutionOk() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("sdnc.password", "OK");
-
- SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+ SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "OOK");
manager.setRestManager(mockedRestManager);
-
+
Thread managerThread = new Thread(manager);
managerThread.start();
when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponsePutOk);
-
+
when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap()))
.thenReturn(httpResponseGetOk);
-
+
managerThread.join(100);
}
+
+ @Override
+ public void onCallback(SdncResponse response) {
+ //
+ // Nothing really to do
+ //
+ }
}
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java
index 09591639f..a397bdcab 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java
@@ -25,9 +25,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.ArrayList;
-import java.util.List;
-
import org.junit.Test;
public class SdncResponseDescriptorTest {
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java
index 18c64aa0b..b36a72810 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-
import org.junit.Test;
public class SdncResponseTest {
@@ -35,15 +34,15 @@ public class SdncResponseTest {
SdncResponse response = new SdncResponse();
assertNotNull(response);
assertNotEquals(0, response.hashCode());
-
+
String requestId = "Get Home";
response.setRequestId(requestId);
assertEquals(requestId, response.getRequestId());
-
+
SdncResponseOutput responseDescriptor = new SdncResponseOutput();
response.setResponseOutput(responseDescriptor);
assertEquals(responseDescriptor, response.getResponseOutput());
-
+
assertNotEquals(0, response.hashCode());
}
}
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java
index 5ac910a17..9dfb3742e 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java
@@ -21,8 +21,6 @@
package org.onap.policy.sdnc.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;