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====================================================
22 package org.onap.aaf.cadi.locator.test;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.junit.Assert.assertThat;
26 import static org.junit.Assert.fail;
28 import java.io.ByteArrayOutputStream;
29 import java.io.PrintStream;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.aaf.cadi.Access.Level;
35 import org.onap.aaf.cadi.Locator.Item;
36 import org.onap.aaf.cadi.LocatorException;
37 import org.onap.aaf.cadi.PropAccess;
38 import org.onap.aaf.cadi.locator.DNSLocator;
40 public class JU_DNSLocator {
42 private PropAccess access;
46 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
50 public void test() throws LocatorException {
55 dl = new DNSLocator(access, "https", "localhost", "8100-8101");
59 assertThat(uri.toString(), is("https://localhost:8100"));
61 assertThat(uri.toString(), is("https://localhost:8100"));
63 assertThat(dl.hasItems(), is(true));
64 for (item = dl.first(); item != null; item = dl.next(item)) {
67 assertThat(dl.hasItems(), is(false));
69 // This doesn't actually do anything besides increase coverage
74 public void constructorTest() throws LocatorException {
76 new DNSLocator(access, "https", "localhost", "8100");
77 new DNSLocator(access, "https", "localhost", "8100-8101");
79 new DNSLocator(access, "http://localhost");
80 new DNSLocator(access, "https://localhost");
81 new DNSLocator(access, "https://localhost:8100");
82 new DNSLocator(access, "https://localhost:[8100]");
83 new DNSLocator(access, "https://localhost:[8100-8101]");
84 new DNSLocator(access, "https://localhost:8000/");
85 new DNSLocator(access, "https://aaf-locatexx.onapxxx:8095/locate");
87 new DNSLocator(access, "https:localhost:8000");
88 fail("Invalid URL should not pass");
89 } catch (LocatorException e) {
90 access.log(Level.DEBUG, "Valid Exception");
96 public void refreshTest() throws LocatorException {
97 DNSLocator dl = new DNSLocator(access, "https", "bogushost", "8100-8101");
98 assertThat(dl.refresh(), is(false));
101 @Test(expected = LocatorException.class)
102 public void throws1Test() throws LocatorException {
103 new DNSLocator(access, null);
106 @Test(expected = LocatorException.class)
107 public void throws2Test() throws LocatorException {
108 new DNSLocator(access, "ftp:invalid");
111 @Test(expected = LocatorException.class)
112 public void throws3Test() throws LocatorException {
113 new DNSLocator(access, "https:localhost:[8100");
116 @Test(expected = LocatorException.class)
117 public void throws4Test() throws LocatorException {
118 new DNSLocator(access, "https:localhost:[]");
121 @Test(expected = LocatorException.class)
122 public void throws5Test() throws LocatorException {
123 new DNSLocator(access, "https:localhost:[8100-]");
126 @Test(expected = LocatorException.class)
127 public void throws6Test() throws LocatorException {
128 new DNSLocator(access, "https:localhost:[-8101]");
131 @Test(expected = LocatorException.class)
132 public void throws7Test() throws LocatorException {
133 new DNSLocator(access, "https:localhost:/");