1 package org.onap.aai.sparky.synchronizer.task;
3 import org.junit.BeforeClass;
4 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
5 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryRestConfig;
6 import org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
7 import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
9 public class PerformActiveInventoryRetrievalTest {
11 private PerformActiveInventoryRetrieval sut;
14 public static void initBeforeClass() throws Exception {
16 * Mock aai.properties values which are used by repairSelfLink(), which is used both to build
17 * this test's expected URI and also used by PerformActiveInventoryRetrieval.get() which is the
20 ActiveInventoryRestConfig aaiRestConfig = new ActiveInventoryRestConfig(null);
21 ActiveInventoryConfig.getConfig().setAaiRestConfig(aaiRestConfig);
22 ActiveInventoryConfig.getConfig().getAaiRestConfig().setHost("localhost");
23 ActiveInventoryConfig.getConfig().getAaiRestConfig().setPort("8443");
24 ActiveInventoryConfig.getConfig().getAaiRestConfig()
25 .setAuthenticationMode(RestAuthenticationMode.SSL_CERT);
30 * @Test public void testGet_relativeURI() throws Exception { String uriToProcess =
31 * "/my/relative/uri"; // URI to perform test with
33 * Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
34 * "https://localhost:8443/my/relative/uri" String expectedURI =
35 * ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
37 * // Set up PerformActiveInventoryRetrieval dependencies ActiveInventoryDataProvider aaiProvider
38 * = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder()); NetworkTransaction
39 * txn = new NetworkTransaction(); txn.setLink(uriToProcess);
41 * sut = new PerformActiveInventoryRetrieval(txn, aaiProvider); sut.setContextMap(new
44 * // Call method under test which should add the missing scheme/host/port to the relative path
45 * given in this test sut.get();
47 * assertEquals(expectedURI, txn.getOperationResult().getRequestLink()); }
49 * @Test public void testGet_relativeURIWithSchemaAndAuthority() throws Exception { String
50 * uriToProcess = "https://localhost:8443/my/relative/uri"; // URI to perform test with
52 * Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
53 * "https://localhost:8443/my/relative/uri" String expectedURI =
54 * ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
56 * // Set up PerformActiveInventoryRetrieval dependencies ActiveInventoryDataProvider aaiProvider
57 * = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder()); NetworkTransaction
58 * txn = new NetworkTransaction(); txn.setLink(uriToProcess);
60 * sut = new PerformActiveInventoryRetrieval(txn, aaiProvider); sut.setContextMap(new
63 * // Call method under test which shouldn't change the absolute path given in this test
66 * assertEquals(expectedURI, txn.getOperationResult().getRequestLink()); }
68 * @Test public void testGet_emptyURI() throws Exception { String uriToProcess = ""; // URI to
71 * Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
72 * "https://localhost:8443" String expectedURI =
73 * ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
75 * // Set up PerformActiveInventoryRetrieval dependencies ActiveInventoryDataProvider aaiProvider
76 * = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder()); NetworkTransaction
77 * txn = new NetworkTransaction(); txn.setLink(uriToProcess);
79 * sut = new PerformActiveInventoryRetrieval(txn, aaiProvider); sut.setContextMap(new
82 * // Call method under test which should add the missing scheme/host/port to the empty URI given
83 * in this test sut.get();
85 * assertEquals(expectedURI, txn.getOperationResult().getRequestLink()); }