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.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
28 import java.io.ByteArrayOutputStream;
29 import java.io.PrintStream;
32 import org.onap.aaf.cadi.LocatorException;
33 import org.onap.aaf.cadi.PropAccess;
34 import org.onap.aaf.cadi.Locator.Item;
35 import org.onap.aaf.cadi.locator.DNSLocator;
37 public class JU_DNSLocator {
39 private PropAccess access;
43 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
47 public void test() throws LocatorException {
52 dl = new DNSLocator(access, "https", "localhost", "8100-8101");
56 assertThat(uri.toString(), is("https://localhost:8100"));
58 assertThat(uri.toString(), is("https://localhost:8100"));
60 assertThat(dl.hasItems(), is(true));
61 for (item = dl.first(); item != null; item = dl.next(item)) {
64 assertThat(dl.hasItems(), is(false));
66 // This doesn't actually do anything besides increase coverage
71 public void constructorTest() throws LocatorException {
73 new DNSLocator(access, "https", "localhost", "8100");
74 new DNSLocator(access, "https", "localhost", "8100-8101");
76 new DNSLocator(access, "http:localhost");
77 new DNSLocator(access, "https:localhost");
78 new DNSLocator(access, "https:localhost:8100");
79 new DNSLocator(access, "https:localhost:[8100]");
80 new DNSLocator(access, "https:localhost:[8100-8101]");
81 new DNSLocator(access, "https:localhost:8000/");
85 public void refreshTest() throws LocatorException {
86 DNSLocator dl = new DNSLocator(access, "https", "bogushost", "8100-8101");
87 assertThat(dl.refresh(), is(false));
90 @Test(expected = LocatorException.class)
91 public void throws1Test() throws LocatorException {
92 new DNSLocator(access, null);
95 @Test(expected = LocatorException.class)
96 public void throws2Test() throws LocatorException {
97 new DNSLocator(access, "ftp:invalid");
100 @Test(expected = LocatorException.class)
101 public void throws3Test() throws LocatorException {
102 new DNSLocator(access, "https:localhost:[8100");
105 @Test(expected = LocatorException.class)
106 public void throws4Test() throws LocatorException {
107 new DNSLocator(access, "https:localhost:[]");
110 @Test(expected = LocatorException.class)
111 public void throws5Test() throws LocatorException {
112 new DNSLocator(access, "https:localhost:[8100-]");
115 @Test(expected = LocatorException.class)
116 public void throws6Test() throws LocatorException {
117 new DNSLocator(access, "https:localhost:[-8101]");
120 @Test(expected = LocatorException.class)
121 public void throws7Test() throws LocatorException {
122 new DNSLocator(access, "https:localhost:/");