summaryrefslogtreecommitdiffstats
path: root/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java
blob: af344d2fab79153701cb725f8f4eaaa84cd9f166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
 * ============LICENSE_START====================================================
 * org.onap.aaf
 * ===========================================================================
 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
 * ===========================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END====================================================
 */

package org.onap.aaf.cadi.register.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.net.Inet4Address;
import java.net.UnknownHostException;

import org.junit.Test;
import org.mockito.internal.configuration.DefaultInjectionEngine;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.PropAccess;
import org.onap.aaf.cadi.config.Config;
import org.onap.aaf.cadi.register.RegistrationCreator;

import junit.framework.Assert;
import locate.v1_0.MgmtEndpoint;

public class JU_RegistrationCreator {

	private static final String DOT_OOM = ".oom";

	@Test
	public void test() {
		PropAccess pa = new PropAccess();
		pa.setProperty(Config.CADI_LATITUDE, "32.7");
		pa.setProperty(Config.CADI_LONGITUDE, "-72.0");
		pa.setProperty(Config.AAF_LOCATOR_NAME, "");
		
		try {
			String hostname = Inet4Address.getLocalHost().getHostName();
			String entry = "";
			RegistrationCreator rc = new RegistrationCreator(pa);
			int port = 999;
			for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
				assertEquals(hostname,me.getHostname());
				assertEquals(port,me.getPort());
				assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
				assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
				assertEquals(2,me.getMajor());
				assertEquals(1,me.getMinor());
				assertEquals(0,me.getPatch());
				assertEquals(0,me.getPkg());
				assertEquals(entry,me.getName());
				assertEquals(null,me.getProtocol());
				assertEquals(0,me.getSpecialPorts().size());
			}

			String protocol = "http";
			pa.setProperty(Config.AAF_LOCATOR_PROTOCOL, protocol);
			rc = new RegistrationCreator(pa);
			for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
				assertEquals(hostname,me.getHostname());
				assertEquals(port,me.getPort());
				assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
				assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
				assertEquals(2,me.getMajor());
				assertEquals(1,me.getMinor());
				assertEquals(0,me.getPatch());
				assertEquals(0,me.getPkg());
				assertEquals("",me.getName());
				assertEquals(protocol,me.getProtocol());
				assertEquals(0,me.getSpecialPorts().size());
			}
			
			pa.setProperty(Config.AAF_LOCATOR_ENTRIES, "service");
			rc = new RegistrationCreator(pa);
			for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
				switch(me.getName()) {
					case "":
						assertEquals(hostname,me.getHostname());
						assertEquals(port,me.getPort());
						break;
					case "service":
						assertEquals(hostname,me.getHostname());
						assertEquals(port,me.getPort());
						break;
					default:
						fail("unknown Locator Entry");
				}
				assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
				assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
				assertEquals(2,me.getMajor());
				assertEquals(1,me.getMinor());
				assertEquals(0,me.getPatch());
				assertEquals(0,me.getPkg());
				assertEquals(protocol,me.getProtocol());
				assertEquals(0,me.getSpecialPorts().size());
			}

			entry = "service";
			pa.setProperty(Config.AAF_LOCATOR_ENTRIES, entry);
			rc = new RegistrationCreator(pa);
			for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
				switch(me.getName()) {
					case "":
						assertEquals(hostname,me.getHostname());
						assertEquals(port,me.getPort());
						break;
					case "service":
						assertEquals(hostname,me.getHostname());
						assertEquals(port,me.getPort());
						break;
					default:
						fail("unknown Locator Entry");
				}
				assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
				assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
				assertEquals(2,me.getMajor());
				assertEquals(1,me.getMinor());
				assertEquals(0,me.getPatch());
				assertEquals(0,me.getPkg());
				assertEquals(protocol,me.getProtocol());
				assertEquals(0,me.getSpecialPorts().size());
			}

			pa.setProperty(Config.AAF_LOCATOR_CONTAINER, "oom");
			pa.setProperty(Config.AAF_ROOT_NS, Config.AAF_ROOT_NS_DEF);
			pa.setProperty(Config.AAF_LOCATOR_NAME,"%NS.%N");
			pa.setProperty(Config.AAF_LOCATOR_NAME+DOT_OOM,"%CNS.%NS.%N");
			pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+DOT_OOM, "onap");
			String k8s_public_hostname="k8s.public.com";
			int public_port = 30001;
			
			pa.setProperty(Config.AAF_LOCATOR_PUBLIC_FQDN,k8s_public_hostname);
			pa.setProperty(Config.AAF_LOCATOR_PUBLIC_PORT+DOT_OOM,Integer.toString(public_port));
			pa.setProperty(Config.AAF_LOCATOR_APP_NS, Config.AAF_ROOT_NS_DEF);
			rc = new RegistrationCreator(pa);
			for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) {
				switch(me.getName()) {
					case "org.osaaf.aaf.service":
						assertEquals(k8s_public_hostname,me.getHostname());
						assertEquals(public_port,me.getPort());
						break;
					case "onap.org.osaaf.aaf.service":
						assertEquals(hostname,me.getHostname());
						assertEquals(port,me.getPort());
						break;
					default:
						fail("unknown Entry Name, " + me.getName());
				}
				assertEquals(pa.getProperty(Config.CADI_LATITUDE),Float.toString(me.getLatitude()));
				assertEquals(pa.getProperty(Config.CADI_LONGITUDE),Float.toString(me.getLongitude()));
				assertEquals(2,me.getMajor());
				assertEquals(1,me.getMinor());
				assertEquals(0,me.getPatch());
				assertEquals(0,me.getPkg());
				assertEquals(protocol,me.getProtocol());
				assertEquals(0,me.getSpecialPorts().size());
			}


		} catch (CadiException | UnknownHostException e) {
			Assert.fail(e.getMessage());
		}
		

	}

}