* ============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.
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;
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;
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";
* 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,
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);
}
/**
}
}
- @Test
- public void testConstructor() throws Exception {
- assertThatIllegalArgumentException().isThrownBy(() -> new Main("invalidSimParameters.json"))
- .withMessage("invalid simulator parameters");
- }
-
/**
- * 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
Main.main(new String[] {PARAMETER_FILE});
// don't need to wait long, because buildXxx() does the wait for us
- for (int port = 6666; port <= 6670; ++port) {
+ for (int port : new int[] {6666, 6667, 6668, 6669, 6670, 6680}) {
assertTrue("simulator on port " + port, NetworkUtil.isTcpPortOpen(HOST, port, 1, 100));
}
checkAai();
}
+ @Test
+ public void testMainMinimalParameters() {
+ Main.main(new String[] {"minParameters.json"});
+ assertNotNull(Main.getInstance());
+ assertTrue(Main.getInstance().isAlive());
+ }
+
private void checkAai() throws HttpClientConfigException {
BusTopicParams params = BusTopicParams.builder().clientName("client").hostname(HOST).port(6666).useHttps(true)
.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");
}
/**
}
};
- // 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 {
assertThat(ex.getCause()).hasMessageStartingWith("interrupted while building");
}
- /**
- * Tests buildTopicServer() when the provider class is invalid.
- */
- @Test
- public void testBuildTopicServerInvalidProvider() {
- assertThatThrownBy(() -> new Main("invalidTopicServer.json").start());
- }
- /**
- * Tests buildTopicServer() when the sink is missing.
- */
- @Test
- public void testBuildTopicServerNoSink() {
- assertThatThrownBy(() -> new Main("missingSink.json").start());
- }
-
- /**
- * Tests buildTopicServer() when the sink is missing.
- */
- @Test
- public void testBuildTopicServerNoSource() {
- assertThatThrownBy(() -> new Main("missingSource.json").start());
- }
}