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=77213e6aa5d59806fb6f265e2799447abaf7ea32;hb=3ca1b28f07f5a46fbeca439677a98245e50b69ea;hp=dfc7142a3c8051533d4db386a81888bb2eb4d7f6;hpb=98adb75e5e627d28ecdf659f4c8ed640ce53ed5e;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 dfc7142a..77213e6a 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 @@ -7,9 +7,9 @@ * 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. @@ -21,23 +21,28 @@ 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.InetAddress; import java.net.URI; +import java.net.UnknownHostException; +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]); @@ -50,7 +55,7 @@ public class JU_DNSLocator { URI uri; dl = new DNSLocator(access, "https", "localhost", "8100-8101"); - + item = dl.best(); uri = dl.get(item); assertThat(uri.toString(), is("https://localhost:8100")); @@ -63,30 +68,47 @@ public class JU_DNSLocator { } assertThat(dl.hasItems(), is(false)); - // This doesn't actually do anything besides increase coverage + // 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, "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)); + DNSLocator dl = new DNSLocator(access, "https", "bogushost", "8100-8101", + // Note: Lambda would be nice but need JDK 1.7 still + // PowerMock couldn't do InetAddress + new DNSLocator.DNSLookup() { + @Override + public InetAddress[] getAllByName(String host) throws UnknownHostException { + return new InetAddress[0]; + } + } + ); + assertThat(dl.refresh(), is(true)); } - + @Test(expected = LocatorException.class) public void throws1Test() throws LocatorException { new DNSLocator(access, null);