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_fqdn);
71 assertEquals(ju_port,rph.getEntryPort(dot_le));
72 assertEquals(rph.hostname,rph.getEntryFQDN("",dot_le));
76 pa.setProperty(Config.AAF_LOCATOR_APP_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_fqdn);
81 assertEquals(ju_port,rph.getEntryPort(dot_le));
82 assertEquals(rph.hostname,rph.getEntryFQDN("",dot_le));
86 pa.setProperty(Config.AAF_LOCATOR_APP_NS+".helm", ns2);
87 for(String dot_le : new String[] {"",".helm"}) {
88 assertEquals(rph.hostname,rph.default_fqdn);
89 assertEquals("",rph.lcontainer);
90 assertEquals(rph.hostname,rph.public_fqdn);
91 assertEquals(ju_port,rph.getEntryPort(dot_le));
92 assertEquals(rph.hostname,rph.getEntryFQDN("",dot_le));
96 // Validate Public Host and Port settings
98 String public_hostname = "com.public.hostname";
99 int public_port = 999;
100 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_FQDN, public_hostname);
101 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_PORT,Integer.toString(public_port));
102 RegistrationPropHolder pubRPH = new RegistrationPropHolder(pa,ju_port);
103 assertEquals(public_hostname,pubRPH.public_fqdn);
104 assertEquals(public_port,pubRPH.getEntryPort(""));
107 final String url = "https://aaf.osaaf.org:8095/org.osaaf.aaf.service:2.1";
108 String name="theName";
109 assertEquals(url,rph.replacements(getClass().getSimpleName(),url, name, ""));
111 String alu = "aaf.osaaf.org:8095";
112 String curl = url.replace(alu, Config.AAF_LOCATE_URL_TAG);
113 pa.setProperty(Config.AAF_LOCATE_URL,"https://"+alu);
114 assertEquals(url.replace("8095","8095/locate"),rph.replacements(getClass().getSimpleName(),curl, name, ""));
116 String root_ns = "org.osaaf.aaf";
117 curl = url.replace(root_ns, "AAF_NS");
118 pa.setProperty(Config.AAF_ROOT_NS,root_ns);
119 assertEquals(url,rph.replacements(getClass().getSimpleName(),curl, name, ""));
121 curl = url.replace(root_ns, "%AAF_NS");
122 pa.setProperty(Config.AAF_ROOT_NS,root_ns);
123 assertEquals(url,rph.replacements(getClass().getSimpleName(),curl, name, ""));
125 final String fqdn = "%C.%CNS.%NS.%N";
126 String target = "myns.theName";
127 assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, ""));
129 pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+".hello", "mycontns");
130 target = "mycontns.myns.theName";
131 assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, ".hello"));
133 pa.setProperty(Config.AAF_LOCATOR_CONTAINER+".hello","helloC");
134 target = "helloC.mycontns.myns.theName";
135 assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, ".hello"));
137 pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS,"c_ns");
138 target = "c_ns.myns.theName";
139 assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, ""));
142 } catch (UnknownHostException | CadiException e) {