fix new openssl, data, etc
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / config / test / JU_RegistrationPropHolder.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  */
20
21 package org.onap.aaf.cadi.config.test;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.net.UnknownHostException;
26
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;
33
34 public class JU_RegistrationPropHolder {
35
36         @Test
37         public void testBlank() {
38                 PropAccess pa = new PropAccess();
39                 RegistrationPropHolder rph;
40                 int ju_port = 20;
41                 try {
42                         ////////////////
43                         // Check Required Properties
44                         ////////////////
45                         try {
46                                 rph = new RegistrationPropHolder(pa,20);
47                         } catch (CadiException e) {
48                                 Assert.assertEquals(
49                                                 "\ncadi_latitude must be defined." + 
50                                                 "\ncadi_longitude must be defined.",e.getMessage());
51                         }
52                         
53                         try {
54                                 pa.setProperty(Config.CADI_LATITUDE, "32.7");
55                                 rph = new RegistrationPropHolder(pa,20);
56                         } catch (CadiException e) {
57                                 Assert.assertEquals(
58                                                 "\ncadi_longitude must be defined.",e.getMessage());
59                         }
60                         
61                         pa.setProperty(Config.CADI_LONGITUDE, "-72.0");
62                         rph = new RegistrationPropHolder(pa,ju_port);
63                         
64                         ////////////////
65                         // Validate Default Properties
66                         ////////////////
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));
73                         }
74
75                         String ns = "myns";
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));
83                         }
84
85                         String ns2 = "onap";
86                         pa.setProperty(Config.AAF_LOCATOR_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_hostname);
91                                 assertEquals(ju_port,rph.getEntryPort(dot_le));
92                                 assertEquals(rph.hostname,rph.getEntryFQDN("",dot_le));
93                         }
94
95                         ////////////////
96                         // Validate Public Host and Port settings
97                         ////////////////
98                         String public_hostname = "com.public.hostname";
99                         int public_port = 999;
100                         pa.setProperty(Config.AAF_LOCATOR_PUBLIC_HOSTNAME, 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_hostname);
104                         assertEquals(public_port,pubRPH.getEntryPort(""));
105
106
107                         final String url = "https://aaf.osaaf.org:8095/org.osaaf.aaf.service:2.1";
108                         String name="theName";
109                         assertEquals(url,rph.replacements(url, name, ""));
110                         
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(curl, name, ""));
115                         
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(curl, name, ""));
120                         
121                         curl = url.replace(root_ns, "%AAF_NS");
122                         pa.setProperty(Config.AAF_ROOT_NS,root_ns);
123                         assertEquals(url,rph.replacements(curl, name, ""));
124                         
125                         final String fqdn = "%C.%CNS.%NS.%N";
126                         String target = "myns.theName";
127                         assertEquals(target,rph.replacements(fqdn, name, ""));
128
129                         pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+".hello", "mycontns");
130                         target = "mycontns.org.osaaf.aaf.theName";
131                         assertEquals(target,rph.replacements(fqdn, name, ".hello"));
132                         
133                         pa.setProperty(Config.AAF_LOCATOR_CONTAINER+".hello","helloC");
134                         target = "helloC.mycontns.org.osaaf.aaf.theName";
135                         assertEquals(target,rph.replacements(fqdn, name, ".hello"));
136                         
137                         pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS,"c_ns");
138                         target = "c_ns.myns.theName";
139                         assertEquals(target,rph.replacements(fqdn, name, ""));
140
141
142                 } catch (UnknownHostException | CadiException e) {
143                         e.printStackTrace();
144                         Assert.fail();
145                 }
146         }
147         
148
149 }