2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.sparky.synchronizer.task;
24 import org.junit.BeforeClass;
25 import org.onap.aai.sparky.sync.task.PerformActiveInventoryRetrieval;
28 * TODO-> RestClientBuilder is no longer being use neither is RestAuthenticationMode class
29 * need to be rewritten to use ONAP RestAuthenticationMode
32 public class PerformActiveInventoryRetrievalTest {
34 private PerformActiveInventoryRetrieval sut;
37 public static void initBeforeClass() throws Exception {
38 /* Mock aai.properties values which are used by repairSelfLink(), which is used both to build this
39 * test's expected URI and also used by PerformActiveInventoryRetrieval.get() which is the method under test
41 ActiveInventoryRestConfig aaiRestConfig = new ActiveInventoryRestConfig(null);
42 ActiveInventoryConfig.getConfig().setAaiRestConfig(aaiRestConfig);
43 ActiveInventoryConfig.getConfig().getAaiRestConfig().setHost("localhost");
44 ActiveInventoryConfig.getConfig().getAaiRestConfig().setPort("8443");
45 ActiveInventoryConfig.getConfig().getAaiRestConfig().setAuthenticationMode(RestAuthenticationMode.SSL_CERT);
50 public void testGet_relativeURI() throws Exception {
51 String uriToProcess = "/my/relative/uri"; // URI to perform test with
53 Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
54 "https://localhost:8443/my/relative/uri"
55 String expectedURI = ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
57 // Set up PerformActiveInventoryRetrieval dependencies
58 ActiveInventoryDataProvider aaiProvider = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder());
59 NetworkTransaction txn = new NetworkTransaction();
60 txn.setLink(uriToProcess);
62 sut = new PerformActiveInventoryRetrieval(txn, aaiProvider);
63 sut.setContextMap(new HashMap<>());
65 // Call method under test which should add the missing scheme/host/port to the relative path given in this test
68 assertEquals(expectedURI, txn.getOperationResult().getRequestLink());
72 public void testGet_relativeURIWithSchemaAndAuthority() throws Exception {
73 String uriToProcess = "https://localhost:8443/my/relative/uri"; // URI to perform test with
75 Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
76 "https://localhost:8443/my/relative/uri"
77 String expectedURI = ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
79 // Set up PerformActiveInventoryRetrieval dependencies
80 ActiveInventoryDataProvider aaiProvider = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder());
81 NetworkTransaction txn = new NetworkTransaction();
82 txn.setLink(uriToProcess);
84 sut = new PerformActiveInventoryRetrieval(txn, aaiProvider);
85 sut.setContextMap(new HashMap<>());
87 // Call method under test which shouldn't change the absolute path given in this test
90 assertEquals(expectedURI, txn.getOperationResult().getRequestLink());
94 public void testGet_emptyURI() throws Exception {
95 String uriToProcess = ""; // URI to perform test with
97 Use uriToProcess + repairSelfLink() method to build the URI that we expect to see:
98 "https://localhost:8443"
99 String expectedURI = ActiveInventoryConfig.getConfig().repairSelfLink(uriToProcess);
101 // Set up PerformActiveInventoryRetrieval dependencies
102 ActiveInventoryDataProvider aaiProvider = new ActiveInventoryAdapter(new OxmModelLoader(), new RestClientBuilder());
103 NetworkTransaction txn = new NetworkTransaction();
104 txn.setLink(uriToProcess);
106 sut = new PerformActiveInventoryRetrieval(txn, aaiProvider);
107 sut.setContextMap(new HashMap<>());
109 // Call method under test which should add the missing scheme/host/port to the empty URI given in this test
112 assertEquals(expectedURI, txn.getOperationResult().getRequestLink());