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");
50 String hostname = Inet4Address.getLocalHost().getHostName();
52 RegistrationCreator rc = new RegistrationCreator(pa);
54 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
55 assertEquals(hostname,me.getHostname());
56 assertEquals(port,me.getPort());
57 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
58 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
59 assertEquals(2,me.getMajor());
60 assertEquals(1,me.getMinor());
61 assertEquals(0,me.getPatch());
62 assertEquals(0,me.getPkg());
63 assertEquals(entry,me.getName());
64 assertEquals(null,me.getProtocol());
65 assertEquals(0,me.getSpecialPorts().size());
68 String protocol = "http";
69 pa.setProperty(Config.AAF_LOCATOR_PROTOCOL, protocol);
70 rc = new RegistrationCreator(pa);
71 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
72 assertEquals(hostname,me.getHostname());
73 assertEquals(port,me.getPort());
74 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
75 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
76 assertEquals(2,me.getMajor());
77 assertEquals(1,me.getMinor());
78 assertEquals(0,me.getPatch());
79 assertEquals(0,me.getPkg());
80 assertEquals("",me.getName());
81 assertEquals(protocol,me.getProtocol());
82 assertEquals(0,me.getSpecialPorts().size());
85 pa.setProperty(Config.AAF_LOCATOR_ENTRIES, "service");
86 rc = new RegistrationCreator(pa);
87 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
88 switch(me.getName()) {
90 assertEquals(hostname,me.getHostname());
91 assertEquals(port,me.getPort());
94 assertEquals(hostname,me.getHostname());
95 assertEquals(port,me.getPort());
98 fail("unknown Locator Entry");
100 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
101 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
102 assertEquals(2,me.getMajor());
103 assertEquals(1,me.getMinor());
104 assertEquals(0,me.getPatch());
105 assertEquals(0,me.getPkg());
106 assertEquals(protocol,me.getProtocol());
107 assertEquals(0,me.getSpecialPorts().size());
111 pa.setProperty(Config.AAF_LOCATOR_ENTRIES, entry);
112 rc = new RegistrationCreator(pa);
113 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
114 switch(me.getName()) {
116 assertEquals(hostname,me.getHostname());
117 assertEquals(port,me.getPort());
120 assertEquals(hostname,me.getHostname());
121 assertEquals(port,me.getPort());
124 fail("unknown Locator Entry");
126 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
127 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
128 assertEquals(2,me.getMajor());
129 assertEquals(1,me.getMinor());
130 assertEquals(0,me.getPatch());
131 assertEquals(0,me.getPkg());
132 assertEquals(protocol,me.getProtocol());
133 assertEquals(0,me.getSpecialPorts().size());
136 pa.setProperty(Config.AAF_LOCATOR_CONTAINER, "oom");
137 pa.setProperty(Config.AAF_ROOT_NS, Config.AAF_ROOT_NS_DEF);
138 pa.setProperty(Config.AAF_LOCATOR_NAME,"%NS.%N");
139 pa.setProperty(Config.AAF_LOCATOR_NAME+DOT_OOM,"%CNS.%NS.%N");
140 pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+DOT_OOM, "onap");
141 String k8s_public_hostname="k8s.public.com";
142 int public_port = 30001;
144 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_FQDN,k8s_public_hostname);
145 pa.setProperty(Config.AAF_LOCATOR_PUBLIC_PORT+DOT_OOM,Integer.toString(public_port));
146 pa.setProperty(Config.AAF_LOCATOR_APP_NS, Config.AAF_ROOT_NS_DEF);
147 rc = new RegistrationCreator(pa);
148 for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
149 switch(me.getName()) {
150 case "org.osaaf.aaf.service":
151 assertEquals(k8s_public_hostname,me.getHostname());
152 assertEquals(public_port,me.getPort());
154 case "onap.org.osaaf.aaf.service":
155 assertEquals(hostname,me.getHostname());
156 assertEquals(port,me.getPort());
159 fail("unknown Entry Name, " + me.getName());
161 assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
162 assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
163 assertEquals(2,me.getMajor());
164 assertEquals(1,me.getMinor());
165 assertEquals(0,me.getPatch());
166 assertEquals(0,me.getPkg());
167 assertEquals(protocol,me.getProtocol());
168 assertEquals(0,me.getSpecialPorts().size());
172 } catch (CadiException | UnknownHostException e) {
173 Assert.fail(e.getMessage());