Fix simulator topics for lower case
[policy/models.git] / models-sim / policy-models-simulators / src / test / java / org / onap / policy / models / simulators / MainTest.java
index f5598e2..73eb69f 100644 (file)
@@ -2,7 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,7 +31,9 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import jakarta.ws.rs.core.Response;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -38,7 +41,6 @@ import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
-import javax.ws.rs.core.Response;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -52,6 +54,7 @@ import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.common.utils.security.SelfSignedKeyStore;
 
 public class MainTest {
     private static final String PARAMETER_FILE = "simParameters.json";
@@ -64,7 +67,7 @@ public class MainTest {
      * Saves system properties.
      */
     @BeforeClass
-    public static void setUpBeforeClass() {
+    public static void setUpBeforeClass() throws IOException, InterruptedException {
         savedValues = new HashMap<>();
 
         for (String prop : List.of(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
@@ -75,11 +78,14 @@ public class MainTest {
             savedValues.put(prop, System.getProperty(prop));
         }
 
-        System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
-        System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME, "kstest");
+        System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, new SelfSignedKeyStore().getKeystoreName());
+        System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
+                        SelfSignedKeyStore.KEYSTORE_PASSWORD);
 
-        System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
-        System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME, "kstest");
+        System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME,
+                        "src/main/resources/ssl/policy-truststore");
+        System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
+                        SelfSignedKeyStore.KEYSTORE_PASSWORD);
     }
 
     /**
@@ -114,7 +120,7 @@ public class MainTest {
     }
 
     /**
-     * Verifies that all of the simulators are brought up and that HTTPS works with at
+     * Verifies that all the simulators are brought up and that HTTPS works with at
      * least one of them.
      */
     @Test
@@ -145,11 +151,11 @@ public class MainTest {
                         .allowSelfSignedCerts(true).basePath("aai").build();
         HttpClient client = HttpClientFactoryInstance.getClientFactory().build(params);
 
-        Response response = client.get("/v8/network/generic-vnfs/generic-vnf/my-vnf");
+        Response response = client.get("/v21/network/pnfs/pnf/demo-pnf");
         assertEquals(200, response.getStatus());
 
         String result = response.readEntity(String.class);
-        assertThat(result).contains("USUCP0PCOIL0110UJZZ01-vsrx");
+        assertThat(result).contains("model-123456");
     }
 
     /**
@@ -218,7 +224,7 @@ public class MainTest {
             }
         };
 
-        // run in another thread so we don't interrupt this thread
+        // run in another thread, so we don't interrupt this thread
         LinkedBlockingQueue<RuntimeException> queue = new LinkedBlockingQueue<>();
         Thread thread = new Thread(() -> {
             try {
@@ -242,7 +248,8 @@ public class MainTest {
      */
     @Test
     public void testBuildTopicServerInvalidProvider() {
-        assertThatThrownBy(() -> new Main("invalidTopicServer.json").start());
+        assertThatThrownBy(() -> new Main("invalidTopicServer.json").start())
+                        .hasCauseInstanceOf(IllegalArgumentException.class);
     }
 
     /**
@@ -250,7 +257,8 @@ public class MainTest {
      */
     @Test
     public void testBuildTopicServerNoSink() {
-        assertThatThrownBy(() -> new Main("missingSink.json").start());
+        assertThatThrownBy(() -> new Main("missingSink.json").start())
+                        .hasCauseInstanceOf(IllegalArgumentException.class);
     }
 
     /**
@@ -258,6 +266,7 @@ public class MainTest {
      */
     @Test
     public void testBuildTopicServerNoSource() {
-        assertThatThrownBy(() -> new Main("missingSource.json").start());
+        assertThatThrownBy(() -> new Main("missingSource.json").start())
+                        .hasCauseInstanceOf(IllegalArgumentException.class);
     }
 }