Merge "Install tools/libs from doc hub image"
[aaf/authz.git] / cadi / client / src / test / java / org / onap / aaf / cadi / locator / test / JU_DNSLocator.java
index d9f75ff..a80e52f 100644 (file)
 
 package org.onap.aaf.cadi.locator.test;
 
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
 import java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
 
-import org.junit.AfterClass;
-import org.junit.Test;
+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 {
-
-       @AfterClass
-       public static void tearDownAfterClass() throws Exception {
+       
+       private PropAccess access;
+       
+       @Before
+       public void setup() {
+               access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
        }
 
        @Test
-       public void test() {
-               // TODO: Actually test this class - Ian
+       public void test() throws LocatorException {
+               DNSLocator dl;
+               Item item;
+               URI uri;
+
+               dl = new DNSLocator(access, "https", "localhost", "8100-8101");
                
-               DNSLocator dl = new DNSLocator(new PropAccess(), "https", "aaf.it.att.com","8150-8152");
-               try {
-                       Item item = dl.best();
-                       URI uri = dl.get(item);
-                       URL url = uri.toURL();
-                       URLConnection conn = url.openConnection();
-                       conn.connect();
-               } catch (Exception e) {
+               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:/");
        }
 
 }