X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fclient%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Flocator%2Ftest%2FJU_DNSLocator.java;h=b786cf6801e8f0aa0244e23582eeb5b9d42f8f5c;hb=c5aaaeeb8a4c008fa4a576c55da4c3bf703acdac;hp=a80e52f70f9aced2d1638e250904eaa66503461e;hpb=1f761f3591242a4ef2b6c7630342e9ecd402574f;p=aaf%2Fauthz.git diff --git a/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java b/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java index a80e52f7..b786cf68 100644 --- a/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java +++ b/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java @@ -21,105 +21,116 @@ package org.onap.aaf.cadi.locator.test; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; -import org.junit.*; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.net.URI; +import org.junit.Before; +import org.junit.Test; +import org.onap.aaf.cadi.Access.Level; +import org.onap.aaf.cadi.Locator.Item; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.Locator.Item; import org.onap.aaf.cadi.locator.DNSLocator; public class JU_DNSLocator { - - private PropAccess access; - - @Before - public void setup() { - access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); - } - - @Test - public void test() throws LocatorException { - DNSLocator dl; - Item item; - URI uri; - - dl = new DNSLocator(access, "https", "localhost", "8100-8101"); - - item = dl.best(); - uri = dl.get(item); - assertThat(uri.toString(), is("https://127.0.0.1:8100")); - item = dl.best(); - assertThat(uri.toString(), is("https://127.0.0.1:8100")); - - assertThat(dl.hasItems(), is(true)); - for (item = dl.first(); item != null; item = dl.next(item)) { - dl.invalidate(item); - } - assertThat(dl.hasItems(), is(false)); - - // This doesn't actually do anything besides increase coverage - dl.destroy(); - } - - @Test - public void constructorTest() throws LocatorException { - // For coverage - new DNSLocator(access, "https", "localhost", "8100"); - new DNSLocator(access, "https", "localhost", "8100-8101"); - - new DNSLocator(access, "http:localhost"); - new DNSLocator(access, "https:localhost"); - new DNSLocator(access, "https:localhost:8100"); - new DNSLocator(access, "https:localhost:[8100]"); - new DNSLocator(access, "https:localhost:[8100-8101]"); - new DNSLocator(access, "https:localhost:8000/"); - } - - @Test - public void refreshTest() throws LocatorException { - DNSLocator dl = new DNSLocator(access, "https", "bogushost", "8100-8101"); - assertThat(dl.refresh(), is(false)); - } - - @Test(expected = LocatorException.class) - public void throws1Test() throws LocatorException { - new DNSLocator(access, null); - } - - @Test(expected = LocatorException.class) - public void throws2Test() throws LocatorException { - new DNSLocator(access, "ftp:invalid"); - } - - @Test(expected = LocatorException.class) - public void throws3Test() throws LocatorException { - new DNSLocator(access, "https:localhost:[8100"); - } - - @Test(expected = LocatorException.class) - public void throws4Test() throws LocatorException { - new DNSLocator(access, "https:localhost:[]"); - } - - @Test(expected = LocatorException.class) - public void throws5Test() throws LocatorException { - new DNSLocator(access, "https:localhost:[8100-]"); - } - - @Test(expected = LocatorException.class) - public void throws6Test() throws LocatorException { - new DNSLocator(access, "https:localhost:[-8101]"); - } - - @Test(expected = LocatorException.class) - public void throws7Test() throws LocatorException { - new DNSLocator(access, "https:localhost:/"); - } + + private PropAccess access; + + @Before + public void setup() { + access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); + } + + @Test + public void test() throws LocatorException { + DNSLocator dl; + Item item; + URI uri; + + dl = new DNSLocator(access, "https", "localhost", "8100-8101"); + + item = dl.best(); + uri = dl.get(item); + assertThat(uri.toString(), is("https://localhost:8100")); + item = dl.best(); + assertThat(uri.toString(), is("https://localhost:8100")); + + assertThat(dl.hasItems(), is(true)); + for (item = dl.first(); item != null; item = dl.next(item)) { + dl.invalidate(item); + } + assertThat(dl.hasItems(), is(false)); + + // This doesn't actually do anything besides increase coverage + dl.destroy(); + } + + @Test + public void constructorTest() throws LocatorException { + // For coverage + new DNSLocator(access, "https", "localhost", "8100"); + new DNSLocator(access, "https", "localhost", "8100-8101"); + + new DNSLocator(access, "http://localhost"); + new DNSLocator(access, "https://localhost"); + new DNSLocator(access, "https://localhost:8100"); + new DNSLocator(access, "https://localhost:[8100]"); + new DNSLocator(access, "https://localhost:[8100-8101]"); + new DNSLocator(access, "https://localhost:8000/"); + new DNSLocator(access, "https://aaf-locatexx.onapxxx:8095/locate"); + try { + new DNSLocator(access, "https:localhost:8000"); + fail("Invalid URL should not pass"); + } catch (LocatorException e) { + access.log(Level.DEBUG, "Valid Exception"); + + } + } + + @Test + public void refreshTest() throws LocatorException { + DNSLocator dl = new DNSLocator(access, "https", "bogushost", "8100-8101"); + assertThat(dl.refresh(), is(false)); + } + + @Test(expected = LocatorException.class) + public void throws1Test() throws LocatorException { + new DNSLocator(access, null); + } + + @Test(expected = LocatorException.class) + public void throws2Test() throws LocatorException { + new DNSLocator(access, "ftp:invalid"); + } + + @Test(expected = LocatorException.class) + public void throws3Test() throws LocatorException { + new DNSLocator(access, "https:localhost:[8100"); + } + + @Test(expected = LocatorException.class) + public void throws4Test() throws LocatorException { + new DNSLocator(access, "https:localhost:[]"); + } + + @Test(expected = LocatorException.class) + public void throws5Test() throws LocatorException { + new DNSLocator(access, "https:localhost:[8100-]"); + } + + @Test(expected = LocatorException.class) + public void throws6Test() throws LocatorException { + new DNSLocator(access, "https:localhost:[-8101]"); + } + + @Test(expected = LocatorException.class) + public void throws7Test() throws LocatorException { + new DNSLocator(access, "https:localhost:/"); + } }