Added one typeless Policy in MockPolicyAgent 78/3578/3
authorPatrikBuhr <patrik.buhr@est.tech>
Tue, 5 May 2020 07:11:52 +0000 (09:11 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Wed, 6 May 2020 07:45:44 +0000 (09:45 +0200)
For enabling manual testing of typeless policies in the Controlpanel

Change-Id: I51a7c4cefeb7f621e27879f3ce4b3f4659c56bd4
Issue-ID: NONRTRIC-210
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java
policy-agent/src/test/java/org/oransc/policyagent/MockPolicyAgent.java

index 26d5152..750b074 100644 (file)
@@ -196,8 +196,8 @@ public class AsyncRestClient {
             .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) //
             .secure(c -> c.sslContext(sslContext)) //
             .doOnConnected(connection -> {
-                connection.addHandler(new ReadTimeoutHandler(30));
-                connection.addHandler(new WriteTimeoutHandler(30));
+                connection.addHandlerLast(new ReadTimeoutHandler(30));
+                connection.addHandlerLast(new WriteTimeoutHandler(30));
             });
         HttpClient httpClient = HttpClient.from(tcpClient);
         ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
index cdf614c..7bdd796 100644 (file)
@@ -31,10 +31,13 @@ import java.nio.file.Files;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.oransc.policyagent.configuration.ApplicationConfig;
+import org.oransc.policyagent.repository.ImmutablePolicy;
 import org.oransc.policyagent.repository.ImmutablePolicyType;
 import org.oransc.policyagent.repository.Policies;
+import org.oransc.policyagent.repository.Policy;
 import org.oransc.policyagent.repository.PolicyType;
 import org.oransc.policyagent.repository.PolicyTypes;
+import org.oransc.policyagent.repository.Ric;
 import org.oransc.policyagent.repository.Rics;
 import org.oransc.policyagent.utils.MockA1ClientFactory;
 import org.slf4j.Logger;
@@ -55,6 +58,12 @@ public class MockPolicyAgent {
     @Autowired
     Rics rics;
 
+    @Autowired
+    Policies policies;
+
+    @Autowired
+    PolicyTypes policyTypes;
+
     static class MockApplicationConfig extends ApplicationConfig {
         @Override
         public String getLocalConfigurationFilePath() {
@@ -101,10 +110,7 @@ public class MockPolicyAgent {
         }
 
         private static File[] getResourceFolderFiles(String folder) {
-            ClassLoader loader = Thread.currentThread().getContextClassLoader();
-            URL url = loader.getResource(folder);
-            String path = url.getPath();
-            return new File(path).listFiles();
+            return getFile(folder).listFiles();
         }
 
         private static String readFile(File file) throws IOException {
@@ -127,11 +133,19 @@ public class MockPolicyAgent {
         }
     }
 
+    private static File getFile(String path) {
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        URL url = loader.getResource(path);
+        return new File(url.getPath());
+    }
+
     @LocalServerPort
     private int port;
 
-    private void keepServerAlive() throws InterruptedException {
+    private void keepServerAlive() throws InterruptedException, IOException {
         logger.info("Keeping server alive!");
+        Thread.sleep(1000);
+        loadInstances();
         synchronized (this) {
             this.wait();
         }
@@ -143,6 +157,23 @@ public class MockPolicyAgent {
         return title;
     }
 
+    private void loadInstances() throws IOException {
+        PolicyType unnamedPolicyType = policyTypes.get("");
+        Ric ric = rics.get("ric1");
+        File jsonFile = getFile("test_application_configuration.json");
+        String json = new String(Files.readAllBytes(jsonFile.toPath()));
+
+        Policy policy = ImmutablePolicy.builder() //
+            .id("typelessPolicy") //
+            .json(json) //
+            .ownerServiceName("MockPolicyAgent") //
+            .ric(ric) //
+            .type(unnamedPolicyType) //
+            .lastModified("now") //
+            .build();
+        this.policies.put(policy);
+    }
+
     @Test
     @SuppressWarnings("squid:S2699") // Tests should include assertions. This test is only for keeping the server
                                      // alive,