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.register.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.fail;
26 import java.net.Inet4Address;
27 import java.net.UnknownHostException;
29 import org.junit.Test;
30 import org.onap.aaf.cadi.CadiException;
31 import org.onap.aaf.cadi.PropAccess;
32 import org.onap.aaf.cadi.config.Config;
33 import org.onap.aaf.cadi.register.RegistrationCreator;
35 import junit.framework.Assert;
36 import locate.v1_0.MgmtEndpoint;
38 public class JU_RegistrationCreator {
40 private static final String DOT_OOM = ".oom";
44 PropAccess pa = new PropAccess();
45 pa.setProperty(Config.CADI_LATITUDE, "32.7");
46 pa.setProperty(Config.CADI_LONGITUDE, "-72.0");
49 String hostname = Inet4Address.getLocalHost().getHostName();
51 RegistrationCreator rc = new RegistrationCreator(pa);
53 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
54 assertEquals(hostname,me.getHostname());
55 assertEquals(port,me.getPort());
56 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
57 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
58 assertEquals(2,me.getMajor());
59 assertEquals(1,me.getMinor());
60 assertEquals(0,me.getPatch());
61 assertEquals(0,me.getPkg());
62 assertEquals(entry,me.getName());
63 assertEquals(null,me.getProtocol());
64 assertEquals(0,me.getSpecialPorts().size());
67 String protocol = "http";
68 pa.setProperty(Config.AAF_LOCATOR_PROTOCOL, protocol);
69 rc = new RegistrationCreator(pa);
70 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
71 assertEquals(hostname,me.getHostname());
72 assertEquals(port,me.getPort());
73 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
74 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
75 assertEquals(2,me.getMajor());
76 assertEquals(1,me.getMinor());
77 assertEquals(0,me.getPatch());
78 assertEquals(0,me.getPkg());
79 assertEquals("",me.getName());
80 assertEquals(protocol,me.getProtocol());
81 assertEquals(0,me.getSpecialPorts().size());
84 pa.setProperty(Config.AAF_LOCATOR_ENTRIES, "service");
85 rc = new RegistrationCreator(pa);
86 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
87 switch(me.getName()) {
89 assertEquals(hostname,me.getHostname());
90 assertEquals(port,me.getPort());
93 assertEquals(hostname,me.getHostname());
94 assertEquals(port,me.getPort());
97 fail("unknown Locator Entry");
99 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
100 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
101 assertEquals(2,me.getMajor());
102 assertEquals(1,me.getMinor());
103 assertEquals(0,me.getPatch());
104 assertEquals(0,me.getPkg());
105 assertEquals(protocol,me.getProtocol());
106 assertEquals(0,me.getSpecialPorts().size());
110 pa.setProperty(Config.AAF_LOCATOR_ENTRIES, entry);
111 rc = new RegistrationCreator(pa);
112 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
113 switch(me.getName()) {
115 assertEquals(hostname,me.getHostname());
116 assertEquals(port,me.getPort());
119 assertEquals(hostname,me.getHostname());
120 assertEquals(port,me.getPort());
123 fail("unknown Locator Entry");
125 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
126 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
127 assertEquals(2,me.getMajor());
128 assertEquals(1,me.getMinor());
129 assertEquals(0,me.getPatch());
130 assertEquals(0,me.getPkg());
131 assertEquals(protocol,me.getProtocol());
132 assertEquals(0,me.getSpecialPorts().size());
135 pa.setProperty(Config.AAF_LOCATOR_CONTAINER, "oom");
136 pa.setProperty(Config.AAF_ROOT_NS, Config.AAF_ROOT_NS_DEF);
137 pa.setProperty(Config.AAF_LOCATOR_NAME,"%NS.%N");
138 pa.setProperty(Config.AAF_LOCATOR_NAME+DOT_OOM,"%CNS.%NS.%N");
139 pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+DOT_OOM, "onap");
140 String k8s_public_hostname="k8s.public.com";
141 int public_port = 30001;
143 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_HOSTNAME,k8s_public_hostname);
144 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_PORT+DOT_OOM,Integer.toString(public_port));
145 rc = new RegistrationCreator(pa);
146 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
147 switch(me.getName()) {
148 case "org.osaaf.aaf.service":
149 assertEquals(k8s_public_hostname,me.getHostname());
150 assertEquals(public_port,me.getPort());
152 case "onap.org.osaaf.aaf.service":
153 assertEquals(hostname,me.getHostname());
154 assertEquals(port,me.getPort());
157 fail("unknown Entry Name, " + me.getName());
159 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
160 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
161 assertEquals(2,me.getMajor());
162 assertEquals(1,me.getMinor());
163 assertEquals(0,me.getPatch());
164 assertEquals(0,me.getPkg());
165 assertEquals(protocol,me.getProtocol());
166 assertEquals(0,me.getSpecialPorts().size());
170 } catch (CadiException | UnknownHostException e) {
171 Assert.fail(e.getMessage());