[POLICY-52] pdp-d: PolicyEngine junits 97/6297/2
authorJorge Hernandez <jh1730@att.com>
Thu, 27 Jul 2017 15:46:21 +0000 (10:46 -0500)
committerJorge Hernandez <jh1730@att.com>
Thu, 27 Jul 2017 15:49:55 +0000 (10:49 -0500)
Change-Id: I8c85d75d7eddd7c959ed4cfb7167b58d9c7c9854
Signed-off-by: Jorge Hernandez <jh1730@att.com>
policy-endpoints/src/test/resources/logback-test.xml
policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java
policy-management/src/test/java/org/openecomp/policy/drools/system/test/PolicyEngineTest.java [new file with mode: 0644]
policy-management/src/test/resources/logback-test.xml [new file with mode: 0644]

index bc813ef..607a60d 100644 (file)
@@ -7,8 +7,10 @@
             </Pattern>
         </encoder>
     </appender>
+    
+    <logger name="org.openecomp.policy.drools.http.server.test" level="INFO"/>
 
-    <root level="info">
+    <root level="warn">
         <appender-ref ref="STDOUT"/>
     </root>
 
index 633d237..02479ec 100644 (file)
@@ -696,7 +696,7 @@ class PolicyEngineManager implements PolicyEngine {
                
                for (HttpServletServer httpServer: this.httpServers) {
                        try {
-                               if (!httpServer.start())
+                               if (!httpServer.waitedStart(5 * 1000L))
                                        success = false;
                        } catch (Exception e) {
                                logger.error("{}: cannot start http-server {} because of {}", this, 
diff --git a/policy-management/src/test/java/org/openecomp/policy/drools/system/test/PolicyEngineTest.java b/policy-management/src/test/java/org/openecomp/policy/drools/system/test/PolicyEngineTest.java
new file mode 100644 (file)
index 0000000..15a2776
--- /dev/null
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-management
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.policy.drools.system.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openecomp.policy.drools.http.client.HttpClient;
+import org.openecomp.policy.drools.http.server.HttpServletServer;
+import org.openecomp.policy.drools.system.PolicyController;
+import org.openecomp.policy.drools.system.PolicyEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * PolicyEngine unit tests
+ */
+public class PolicyEngineTest {
+       private static Logger logger = LoggerFactory.getLogger(PolicyEngineTest.class);
+       
+       @BeforeClass
+       public static void startUp() {
+               logger.info("----- TEST: startUp() ---------");
+               
+               Properties engineProperties = new Properties();
+               engineProperties.put("http.server.services", "CONFIG");
+               engineProperties.put("http.server.services.CONFIG.host", "0.0.0.0");
+               engineProperties.put("http.server.services.CONFIG.port", "9696");
+               engineProperties.put("http.server.services.CONFIG.restPackages", "org.openecomp.policy.drools.server.restful");
+               
+               assertFalse(PolicyEngine.manager.isAlive());
+               
+               PolicyEngine.manager.configure(engineProperties);               
+               assertFalse(PolicyEngine.manager.isAlive());
+               
+               PolicyEngine.manager.start();
+               assertTrue(PolicyEngine.manager.isAlive());
+               assertFalse(PolicyEngine.manager.isLocked());
+               assertTrue(HttpServletServer.factory.get(9696).isAlive());
+       }
+       
+       @AfterClass
+       public static void tearDown() { 
+               logger.info("----- TEST: tearDown() ---------");
+               
+               PolicyEngine.manager.stop();
+               assertFalse(PolicyEngine.manager.isAlive());
+       }
+       
+       @Test
+       public void addController() throws Exception {
+               logger.info("----- TEST: addController() ---------");
+               
+               Properties controllerProperties = new Properties();
+               controllerProperties.put("controller.name", "unnamed");
+               
+               PolicyEngine.manager.createPolicyController("unnamed", controllerProperties);
+               assertTrue(PolicyController.factory.inventory().size() == 1);
+               
+               HttpClient client = HttpClient.factory.build("telemetry", false, false, 
+                                                     "localhost", 9696, "policy/pdp", 
+                                                      null, null, false);
+               Response response = client.get("engine");
+               Object body = HttpClient.getBody(response, Object.class);
+               logger.info("policy-engine: {}", body);
+               
+               assertTrue(response.getStatus() == 200);
+               
+               PolicyController testController = PolicyController.factory.get("unnamed");
+               assertFalse(testController.getDrools().isAlive());
+               assertFalse(testController.getDrools().isLocked());
+       }
+
+}
diff --git a/policy-management/src/test/resources/logback-test.xml b/policy-management/src/test/resources/logback-test.xml
new file mode 100644 (file)
index 0000000..e48b9a1
--- /dev/null
@@ -0,0 +1,17 @@
+<configuration>
+
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <Pattern>
+                %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
+            </Pattern>
+        </encoder>
+    </appender>
+    
+    <logger name="org.openecomp.policy.drools.system.test" level="INFO"/>
+
+    <root level="warn">
+        <appender-ref ref="STDOUT"/>
+    </root>
+
+</configuration>
\ No newline at end of file