X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Faaf%2Fv2_0%2Ftest%2FJU_AbsAAFLocator.java;h=5f5858ce05f9158c27998690292feee27f68e94b;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=e9c74cbfe148503e995fbab69031f8d68d218ebe;hpb=ceda6e8bc270202bcb24340b86617110289c902e;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java index e9c74cbf..5f5858ce 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java @@ -21,18 +21,23 @@ package org.onap.aaf.cadi.aaf.v2_0.test; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; -import org.junit.*; -import org.mockito.*; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.net.URI; import java.net.URISyntaxException; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.Locator.Item; import org.onap.aaf.cadi.LocatorException; @@ -44,150 +49,127 @@ import org.onap.aaf.misc.env.impl.BasicTrans; public class JU_AbsAAFLocator { - @Mock private LocatorCreator locatorCreatorMock; - - private PropAccess access; - private URI uri; - - private static final String uriString = "example.com"; - - @Before - public void setup() throws URISyntaxException { - MockitoAnnotations.initMocks(this); - - access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); - access.setProperty(Config.CADI_LATITUDE, "38.62"); // St Louis approx lat - access.setProperty(Config.CADI_LONGITUDE, "90.19"); // St Louis approx lon - - uri = new URI(uriString); - } + @Mock private LocatorCreator locatorCreatorMock; - @AfterClass - public static void tearDownAfterClass() throws Exception { - AbsAAFLocator.setCreator(null); - } - - @Test - public void test() throws LocatorException { - AAFLocatorStub loc; - - // Test with http - loc = new AAFLocatorStub(access, "httpname"); - assertThat(loc.getName(), is("httpname")); - assertThat(loc.getVersion(), is(Config.AAF_DEFAULT_VERSION)); - assertThat(loc.toString(), is("AAFLocator for " + "httpname" + " on " + loc.getURI())); - - loc = new AAFLocatorStub(access, "name"); - assertThat(loc.getName(), is("name")); - assertThat(loc.getVersion(), is(Config.AAF_DEFAULT_VERSION)); - loc = new AAFLocatorStub(access, "name:v2.0"); - assertThat(loc.getName(), is("name")); - assertThat(loc.getVersion(), is("v2.0")); - } - - @Test - public void createTest() throws LocatorException { - AbsAAFLocator.setCreator(locatorCreatorMock); - - assertThat(AbsAAFLocator.create("nonsense"), is(nullValue())); - assertThat(AbsAAFLocator.create("nonsense/locate"), is(nullValue())); - assertThat(AbsAAFLocator.create("nonsense/locate/"), is(nullValue())); - assertThat(AbsAAFLocator.create("nonsense/locate//"), is(nullValue())); - assertThat(AbsAAFLocator.create("nonsense/locate/name:v2.0"), is(nullValue())); - - assertThat(AbsAAFLocator.create("http/locate/name:v2.0"), is(nullValue())); - - doReturn(mock(AbsAAFLocator.class)).when(locatorCreatorMock).create(anyString(), anyString()); - assertThat(AbsAAFLocator.create("http/locate/name:v2.0/path"), is(not(nullValue()))); - - AbsAAFLocator.setCreator(null); - assertThat(AbsAAFLocator.create("http/locate/name:v2.0"), is(nullValue())); - - assertThat(AbsAAFLocator.create("http"), is(not(nullValue()))); - - AbsAAFLocator.setCreator(locatorCreatorMock); - assertThat(AbsAAFLocator.create("first", "second"), is(not(nullValue()))); - } - - @Test - public void nameFromLocatorURITest() throws LocatorException, URISyntaxException { - AAFLocatorStub loc = new AAFLocatorStub(access, "name:v2.0"); - assertThat(loc.getNameFromURI(new URI("example.com")), is("example.com")); - assertThat(loc.getNameFromURI(new URI("example.com/extra/stuff")), is("example.com/extra/stuff")); - assertThat(loc.getNameFromURI(new URI("example.com/locate/stuff")), is("stuff")); // n' stuff - } - - @Test - public void setSelfTest() throws LocatorException { - AbsAAFLocator.setCreatorSelf("host", 8000); - AbsAAFLocator.setCreator(null); - AbsAAFLocator.setCreatorSelf("host", 8000); - (new AAFLocatorStub(access, "name:v2.0")).setSelf("host", 8000); // oof - } - - @Test - public void coverage() throws LocatorException { - AAFLocatorStub loc = new AAFLocatorStub(access, "name:v2.0"); - assertThat(loc.get(null), is(nullValue())); - - try { - loc.get(mock(Item.class)); - fail("Should've thrown an exception"); - } catch (Exception e) { - } - - try { - loc.invalidate(mock(Item.class)); - fail("Should've thrown an exception"); - } catch (Exception e) { - } - - try { - loc.best(); - fail("Should've thrown an exception"); - } catch (Exception e) { - } - - assertThat(loc.first(), is(nullValue())); - - assertThat(loc.hasItems(), is(false)); - assertThat(loc.next(null), is(nullValue())); - - try { - loc.next(mock(Item.class)); - fail("Should've thrown an exception"); - } catch (Exception e) { - } - - loc.destroy(); - - - assertThat(loc.exposeGetURI(uri), is(uri)); - - assertThat(loc.setPathInfo("pathInfo"), is(not(nullValue()))); - assertThat(loc.setQuery("query"), is(not(nullValue()))); - assertThat(loc.setFragment("fragment"), is(not(nullValue()))); - - assertThat(loc.exposeGetURI(uri), is(not(uri))); - } - - - @Test(expected = LocatorException.class) - public void throwsTest() throws LocatorException { - @SuppressWarnings("unused") - AAFLocatorStub loc = new AAFLocatorStub(new PropAccess(), "name"); - } - - private class AAFLocatorStub extends AbsAAFLocator { - public AAFLocatorStub(Access access, String name) throws LocatorException { - super(access, name, 10000L); - } - @Override public boolean refresh() { return false; } - @Override protected URI getURI() { return uri; } - public String getName() { return name; } - public String getVersion() { return version; } - public String getNameFromURI(URI uri) { return nameFromLocatorURI(uri); } - public URI exposeGetURI(URI uri) throws LocatorException { return super.getURI(uri); } - } + private PropAccess access; + private URI uri; + + private static final String uriString = "example.com"; + + @Before + public void setup() throws URISyntaxException { + MockitoAnnotations.initMocks(this); + + access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); + access.setProperty(Config.CADI_LATITUDE, "38.62"); // St Louis approx lat + access.setProperty(Config.CADI_LONGITUDE, "90.19"); // St Louis approx lon + + uri = new URI(uriString); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + AbsAAFLocator.setCreator(null); + } + + @Test + public void test() throws LocatorException { + AAFLocatorStub loc; + + // Test with http + loc = new AAFLocatorStub(access, "httpname"); + assertThat(loc.getName(), is("httpname")); + assertThat(loc.getVersion(), is(Config.AAF_DEFAULT_API_VERSION)); + assertThat(loc.toString(), is("AAFLocator for " + "httpname" + " on " + loc.getURI())); + + loc = new AAFLocatorStub(access, "name"); + assertThat(loc.getName(), is("name")); + assertThat(loc.getVersion(), is(Config.AAF_DEFAULT_API_VERSION)); + loc = new AAFLocatorStub(access, "name:v2.0"); + assertThat(loc.getName(), is("name")); + assertThat(loc.getVersion(), is("v2.0")); + } + + + @Test + public void nameFromLocatorURITest() throws LocatorException, URISyntaxException { + AAFLocatorStub loc = new AAFLocatorStub(access, "name:v2.0"); + assertThat(loc.getNameFromURI(new URI("example.com")), is("example.com")); + assertThat(loc.getNameFromURI(new URI("example.com/extra/stuff")), is("extra")); + assertThat(loc.getNameFromURI(new URI("example.com/locate/stuff")), is("stuff")); // n' stuff + } + + @Test + public void setSelfTest() throws LocatorException { + AbsAAFLocator.setCreatorSelf("host", 8000); + AbsAAFLocator.setCreator(null); + AbsAAFLocator.setCreatorSelf("host", 8000); + (new AAFLocatorStub(access, "name:v2.0")).setSelf("host", 8000); // oof + } + + @Test + public void coverage() throws LocatorException { + AAFLocatorStub loc = new AAFLocatorStub(access, "name:v2.0"); + assertThat(loc.get(null), is(nullValue())); + + try { + loc.get(mock(Item.class)); + fail("Should've thrown an exception"); + } catch (Exception e) { + } + + try { + loc.invalidate(mock(Item.class)); + fail("Should've thrown an exception"); + } catch (Exception e) { + } + + try { + loc.best(); + fail("Should've thrown an exception"); + } catch (Exception e) { + } + + assertThat(loc.first(), is(nullValue())); + + assertThat(loc.hasItems(), is(false)); + assertThat(loc.next(null), is(nullValue())); + + try { + loc.next(mock(Item.class)); + fail("Should've thrown an exception"); + } catch (Exception e) { + } + + loc.destroy(); + + + assertThat(loc.exposeGetURI(uri), is(uri)); + + assertThat(loc.setPathInfo("pathInfo"), is(not(nullValue()))); + assertThat(loc.setQuery("query"), is(not(nullValue()))); + assertThat(loc.setFragment("fragment"), is(not(nullValue()))); + + assertThat(loc.exposeGetURI(uri), is(not(uri))); + } + + + @Test(expected = LocatorException.class) + public void throwsTest() throws LocatorException { + @SuppressWarnings("unused") + AAFLocatorStub loc = new AAFLocatorStub(new PropAccess(), "name"); + } + + private class AAFLocatorStub extends AbsAAFLocator { + public AAFLocatorStub(Access access, String name) throws LocatorException { + super(access, name, 10000L); + } + @Override public boolean refresh() { return false; } + @Override protected URI getURI() { return uri; } + public String getName() { return name; } + public String getVersion() { return version; } + public String getNameFromURI(URI uri) { return nameFromLocatorURI(uri); } + public URI exposeGetURI(URI uri) throws LocatorException { return super.getURI(uri); } + } }