1 package org.onap.aai.sparky.synchronizer.task;
3 import org.junit.BeforeClass;
4 import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
7 * TODO-> RestClientBuilder is no longer being use neither is RestAuthenticationMode class
8 * need to be rewritten to use ONAP RestAuthenticationMode
11 public class PerformActiveInventoryRetrievalTest {
13 private PerformActiveInventoryRetrieval sut;
16 public static void initBeforeClass() throws Exception {
17 /* Mock aai.properties values which are used by repairSelfLink(), which is used both to build this
18 * test's expected URI and also used by PerformActiveInventoryRetrieval.get() which is the method under test
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().setAuthenticationMode(RestAuthenticationMode.SSL_CERT);
29 public void testGet_relativeURI() throws Exception {
30 String uriToProcess = "/my/relative/uri"; // URI to perform test with
32 Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
33 "https://localhost:8443/my/relative/uri"
34 String expectedURI = ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
36 // Set up PerformActiveInventoryRetrieval dependencies
37 ActiveInventoryDataProvider aaiProvider = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder());
38 NetworkTransaction txn = new NetworkTransaction();
39 txn.setLink(uriToProcess);
41 sut = new PerformActiveInventoryRetrieval(txn, aaiProvider);
42 sut.setContextMap(new HashMap<>());
44 // Call method under test which should add the missing scheme/host/port to the relative path given in this test
47 assertEquals(expectedURI, txn.getOperationResult().getRequestLink());
51 public void testGet_relativeURIWithSchemaAndAuthority() throws Exception {
52 String uriToProcess = "https://localhost:8443/my/relative/uri"; // URI to perform test with
54 Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
55 "https://localhost:8443/my/relative/uri"
56 String expectedURI = ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
58 // Set up PerformActiveInventoryRetrieval dependencies
59 ActiveInventoryDataProvider aaiProvider = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder());
60 NetworkTransaction txn = new NetworkTransaction();
61 txn.setLink(uriToProcess);
63 sut = new PerformActiveInventoryRetrieval(txn, aaiProvider);
64 sut.setContextMap(new HashMap<>());
66 // Call method under test which shouldn't change the absolute path given in this test
69 assertEquals(expectedURI, txn.getOperationResult().getRequestLink());
73 public void testGet_emptyURI() throws Exception {
74 String uriToProcess = ""; // URI to perform test with
76 Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
77 "https://localhost:8443"
78 String expectedURI = ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
80 // Set up PerformActiveInventoryRetrieval dependencies
81 ActiveInventoryDataProvider aaiProvider = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder());
82 NetworkTransaction txn = new NetworkTransaction();
83 txn.setLink(uriToProcess);
85 sut = new PerformActiveInventoryRetrieval(txn, aaiProvider);
86 sut.setContextMap(new HashMap<>());
88 // Call method under test which should add the missing scheme/host/port to the empty URI given in this test
91 assertEquals(expectedURI, txn.getOperationResult().getRequestLink());