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.mockito.internal.configuration.DefaultInjectionEngine;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.PropAccess;
33 import org.onap.aaf.cadi.config.Config;
34 import org.onap.aaf.cadi.register.RegistrationCreator;
36 import junit.framework.Assert;
37 import locate.v1_0.MgmtEndpoint;
39 public class JU_RegistrationCreator {
41 private static final String DOT_OOM = ".oom";
45 PropAccess pa = new PropAccess();
46 pa.setProperty(Config.CADI_LATITUDE, "32.7");
47 pa.setProperty(Config.CADI_LONGITUDE, "-72.0");
48 pa.setProperty(Config.AAF_LOCATOR_NAME, "");
51 String hostname = Inet4Address.getLocalHost().getHostName();
53 RegistrationCreator rc = new RegistrationCreator(pa);
55 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
56 assertEquals(hostname,me.getHostname());
57 assertEquals(port,me.getPort());
58 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
59 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
60 assertEquals(2,me.getMajor());
61 assertEquals(1,me.getMinor());
62 assertEquals(0,me.getPatch());
63 assertEquals(0,me.getPkg());
64 assertEquals(entry,me.getName());
65 assertEquals("https",me.getProtocol());
66 assertEquals(0,me.getSpecialPorts().size());
69 String protocol = "http";
70 pa.setProperty(Config.AAF_LOCATOR_PROTOCOL, protocol);
71 rc = new RegistrationCreator(pa);
72 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
73 assertEquals(hostname,me.getHostname());
74 assertEquals(port,me.getPort());
75 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
76 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
77 assertEquals(2,me.getMajor());
78 assertEquals(1,me.getMinor());
79 assertEquals(0,me.getPatch());
80 assertEquals(0,me.getPkg());
81 assertEquals("",me.getName());
82 assertEquals(protocol,me.getProtocol());
83 assertEquals(0,me.getSpecialPorts().size());
86 pa.setProperty(Config.AAF_LOCATOR_ENTRIES, "service");
87 rc = new RegistrationCreator(pa);
88 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
89 switch(me.getName()) {
91 assertEquals(hostname,me.getHostname());
92 assertEquals(port,me.getPort());
95 assertEquals(hostname,me.getHostname());
96 assertEquals(port,me.getPort());
99 fail("unknown Locator Entry");
101 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
102 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
103 assertEquals(2,me.getMajor());
104 assertEquals(1,me.getMinor());
105 assertEquals(0,me.getPatch());
106 assertEquals(0,me.getPkg());
107 assertEquals(protocol,me.getProtocol());
108 assertEquals(0,me.getSpecialPorts().size());
112 pa.setProperty(Config.AAF_LOCATOR_ENTRIES, entry);
113 rc = new RegistrationCreator(pa);
114 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
115 switch(me.getName()) {
117 assertEquals(hostname,me.getHostname());
118 assertEquals(port,me.getPort());
121 assertEquals(hostname,me.getHostname());
122 assertEquals(port,me.getPort());
125 fail("unknown Locator Entry");
127 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
128 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
129 assertEquals(2,me.getMajor());
130 assertEquals(1,me.getMinor());
131 assertEquals(0,me.getPatch());
132 assertEquals(0,me.getPkg());
133 assertEquals(protocol,me.getProtocol());
134 assertEquals(0,me.getSpecialPorts().size());
137 pa.setProperty(Config.AAF_LOCATOR_CONTAINER, "oom");
138 pa.setProperty(Config.AAF_ROOT_NS, Config.AAF_ROOT_NS_DEF);
139 pa.setProperty(Config.AAF_LOCATOR_NAME,"%NS.%N");
140 pa.setProperty(Config.AAF_LOCATOR_NAME+DOT_OOM,"%CNS.%NS.%N");
141 pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+DOT_OOM, "onap");
142 String k8s_public_hostname="k8s.public.com";
143 int public_port = 30001;
145 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_FQDN,k8s_public_hostname);
146 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_PORT+DOT_OOM,Integer.toString(public_port));
147 pa.setProperty(Config.AAF_LOCATOR_APP_NS, Config.AAF_ROOT_NS_DEF);
148 rc = new RegistrationCreator(pa);
149 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
150 switch(me.getName()) {
151 case "org.osaaf.aaf.service":
152 assertEquals(k8s_public_hostname,me.getHostname());
153 assertEquals(public_port,me.getPort());
155 case "onap.org.osaaf.aaf.service":
156 assertEquals(hostname,me.getHostname());
157 assertEquals(port,me.getPort());
160 fail("unknown Entry Name, " + me.getName());
162 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
163 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
164 assertEquals(2,me.getMajor());
165 assertEquals(1,me.getMinor());
166 assertEquals(0,me.getPatch());
167 assertEquals(0,me.getPkg());
168 assertEquals(protocol,me.getProtocol());
169 assertEquals(0,me.getSpecialPorts().size());
173 } catch (CadiException | UnknownHostException e) {
174 Assert.fail(e.getMessage());