2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.cadi.config.test;
23 import static org.junit.Assert.assertEquals;
25 import java.net.UnknownHostException;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.onap.aaf.cadi.CadiException;
30 import org.onap.aaf.cadi.PropAccess;
31 import org.onap.aaf.cadi.config.Config;
32 import org.onap.aaf.cadi.config.RegistrationPropHolder;
34 public class JU_RegistrationPropHolder {
37 public void testBlank() {
38 PropAccess pa = new PropAccess();
39 RegistrationPropHolder rph;
43 // Check Required Properties
46 rph = new RegistrationPropHolder(pa,20);
47 } catch (CadiException e) {
49 "\ncadi_latitude must be defined." +
50 "\ncadi_longitude must be defined.",e.getMessage());
54 pa.setProperty(Config.CADI_LATITUDE, "32.7");
55 rph = new RegistrationPropHolder(pa,20);
56 } catch (CadiException e) {
58 "\ncadi_longitude must be defined.",e.getMessage());
61 pa.setProperty(Config.CADI_LONGITUDE, "-72.0");
62 rph = new RegistrationPropHolder(pa,ju_port);
65 // Validate Default Properties
67 for(String dot_le : new String[] {"",".helm"}) {
68 assertEquals(rph.hostname,rph.default_fqdn);
69 assertEquals("",rph.lcontainer);
70 assertEquals(rph.hostname,rph.public_hostname);
71 assertEquals(ju_port,rph.getEntryPort(dot_le));
72 assertEquals(rph.hostname,rph.getEntryFQDN("",dot_le));
76 pa.setProperty(Config.AAF_LOCATOR_NS, ns);
77 for(String dot_le : new String[] {"",".helm"}) {
78 assertEquals(rph.hostname,rph.default_fqdn);
79 assertEquals("",rph.lcontainer);
80 assertEquals(rph.hostname,rph.public_hostname);
81 assertEquals(ju_port,rph.getEntryPort(dot_le));
82 assertEquals(rph.hostname,rph.getEntryFQDN("",dot_le));
86 pa.setProperty(Config.AAF_LOCATOR_NS+".helm", ns2);
87 for(String dot_le : new String[] {"",".helm"}) {
89 if(dot_le.isEmpty()) {
94 assertEquals(rph.hostname,rph.default_fqdn);
95 assertEquals("",rph.lcontainer);
96 assertEquals(rph.hostname,rph.public_hostname);
97 assertEquals(ju_port,rph.getEntryPort(dot_le));
98 assertEquals(rph.hostname,rph.getEntryFQDN("",dot_le));
102 // Validate Public Host and Port settings
104 String public_hostname = "com.public.hostname";
105 int public_port = 999;
106 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_HOSTNAME, public_hostname);
107 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_PORT,Integer.toString(public_port));
108 RegistrationPropHolder pubRPH = new RegistrationPropHolder(pa,ju_port);
109 assertEquals(public_hostname,pubRPH.public_hostname);
110 assertEquals(public_port,pubRPH.getEntryPort(""));
113 final String url = "https://aaf.osaaf.org:8095/org.osaaf.aaf.service:2.1";
114 String name="theName";
115 assertEquals(url,rph.replacements(url, name, ""));
117 String alu = "aaf.osaaf.org:8095";
118 String curl = url.replace(alu, Config.AAF_LOCATE_URL_TAG);
119 pa.setProperty(Config.AAF_LOCATE_URL,"https://"+alu);
120 assertEquals(url.replace("8095","8095/locate"),rph.replacements(curl, name, ""));
122 String root_ns = "org.osaaf.aaf";
123 curl = url.replace(root_ns, "AAF_NS");
124 pa.setProperty(Config.AAF_ROOT_NS,root_ns);
125 assertEquals(url,rph.replacements(curl, name, ""));
127 curl = url.replace(root_ns, "%AAF_NS");
128 pa.setProperty(Config.AAF_ROOT_NS,root_ns);
129 assertEquals(url,rph.replacements(curl, name, ""));
131 final String fqdn = "%C.%CNS.%NS.%N";
132 String target = "myns.theName";
133 assertEquals(target,rph.replacements(fqdn, name, ""));
135 pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+".hello", "mycontns");
136 target = "mycontns.org.osaaf.aaf.theName";
137 assertEquals(target,rph.replacements(fqdn, name, ".hello"));
139 pa.setProperty(Config.AAF_LOCATOR_CONTAINER+".hello","hello");
140 target = "hello.mycontns.org.osaaf.aaf.theName";
141 assertEquals(target,rph.replacements(fqdn, name, ".hello"));
143 pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS,"c_ns");
144 target = "c_ns.myns.theName";
145 assertEquals(target,rph.replacements(fqdn, name, ""));
148 } catch (UnknownHostException | CadiException e) {