import org.onap.aaf.misc.env.APIException;
public class JU_HMangr {
-
- @Mock Locator<URI> locMock;
- @Mock SecuritySetter<HttpURLConnection> ssMock;
- @Mock Retryable<Void> retryableMock;
- @Mock Retryable<Integer> goodRetry;
- @Mock Locator.Item itemMock;
- @Mock Rcli<Object> clientMock;
-
- private PropAccess access;
- private URI uri;
- private final static String uriString = "http://example.com";
-
- @Before
- public void setup() throws URISyntaxException {
- MockitoAnnotations.initMocks(this);
-
- access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
- uri = new URI(uriString);
- }
-
- @Test
- public void sameTest() throws LocatorException, APIException, CadiException, ConnectException {
- HMangr hman = new HMangr(access, locMock);
- when(retryableMock.item()).thenReturn(itemMock);
- when(locMock.get(itemMock)).thenReturn(uri);
- assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
-
- //coverage...
- when(retryableMock.lastClient()).thenReturn(clientMock);
- assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
-
- CadiException cadiException;
-
- ConnectException connectException = new ConnectException();
- cadiException = new CadiException(connectException);
- doThrow(cadiException).when(retryableMock).code(clientMock);
- when(locMock.hasItems()).thenReturn(true).thenReturn(false);
- assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
-
- SocketException socketException = new SocketException();
- cadiException = new CadiException(socketException);
- doThrow(cadiException).when(retryableMock).code(clientMock);
- when(locMock.hasItems()).thenReturn(true).thenReturn(false);
- assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
-
- doThrow(connectException).when(retryableMock).code(clientMock);
- assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
-
- }
-
- @Test(expected = LocatorException.class)
- public void throwsLocatorException1Test() throws LocatorException {
- @SuppressWarnings("unused")
- HMangr hman = new HMangr(access, null);
- }
-
- @Test(expected = LocatorException.class)
- public void throwsLocatorException2Test() throws LocatorException, APIException, CadiException {
- HMangr hman = new HMangr(access, locMock);
- hman.same(ssMock, retryableMock);
- }
-
- @Test(expected = LocatorException.class)
- public void throwsLocatorException3Test() throws LocatorException, APIException, CadiException {
- HMangr hman = new HMangr(access, locMock);
- when(locMock.best()).thenReturn(itemMock);
- when(locMock.hasItems()).thenReturn(true).thenReturn(false);
- hman.same(ssMock, retryableMock);
- }
-
- @SuppressWarnings("unchecked")
- @Test(expected = CadiException.class)
- public void throwsCadiException1Test() throws LocatorException, APIException, CadiException, ConnectException {
- HMangr hman = new HMangr(access, locMock);
- when(retryableMock.item()).thenReturn(itemMock);
- when(locMock.get(itemMock)).thenReturn(uri);
- when(retryableMock.lastClient()).thenReturn(clientMock);
- when(retryableMock.code(clientMock)).thenThrow(CadiException.class);
- hman.same(ssMock, retryableMock);
- }
-
- @Test(expected = CadiException.class)
- public void throwsCadiException2Test() throws LocatorException, APIException, CadiException, ConnectException {
- HMangr hman = new HMangr(access, locMock);
- when(retryableMock.item()).thenReturn(itemMock);
- when(locMock.get(itemMock)).thenReturn(uri);
- when(retryableMock.lastClient()).thenReturn(clientMock);
-
- ConnectException connectException = new ConnectException();
- CadiException cadiException = new CadiException(connectException);
- doThrow(cadiException).when(retryableMock).code(clientMock);
- hman.same(ssMock, retryableMock);
- }
-
- @Test(expected = CadiException.class)
- public void throwsCadiException3Test() throws LocatorException, APIException, CadiException, ConnectException {
- HMangr hman = new HMangr(access, locMock);
- when(retryableMock.item()).thenReturn(itemMock);
- when(locMock.get(itemMock)).thenReturn(uri);
- when(retryableMock.lastClient()).thenReturn(clientMock);
-
- SocketException socketException = new SocketException();
- CadiException cadiException = new CadiException(socketException);
- doThrow(cadiException).when(retryableMock).code(clientMock);
- hman.same(ssMock, retryableMock);
- }
-
- @Test(expected = CadiException.class)
- public void throwsCadiException4Test() throws LocatorException, APIException, CadiException, ConnectException {
- HMangr hman = new HMangr(access, locMock);
- when(retryableMock.item()).thenReturn(itemMock);
- when(locMock.get(itemMock)).thenReturn(uri);
- when(retryableMock.lastClient()).thenReturn(clientMock);
-
- Exception e = new Exception();
- CadiException cadiException = new CadiException(e);
- doThrow(cadiException).when(retryableMock).code(clientMock);
- hman.same(ssMock, retryableMock);
- }
-
- @Test
- public void allTest() throws LocatorException, CadiException, APIException {
- HManagerStub hman = new HManagerStub(access, locMock);
- assertThat(hman.best(ssMock, retryableMock), is(nullValue()));
- assertThat(hman.all(ssMock, retryableMock), is(nullValue()));
- assertThat(hman.all(ssMock, retryableMock, true), is(nullValue()));
- }
-
- @Test
- public void oneOfTest() throws LocatorException, CadiException, APIException, ConnectException {
- HMangr hman = new HMangr(access, locMock);
- assertThat(hman.oneOf(ssMock, retryableMock, false, "host"), is(nullValue()));
-
- try {
- hman.oneOf(ssMock, retryableMock, true, "host");
- fail("Should've thrown an exception");
- } catch (LocatorException e) {
- }
-
- when(locMock.first()).thenReturn(itemMock);
- when(locMock.get(itemMock)).thenReturn(uri);
-
- // Branching coverage...
- assertThat(hman.oneOf(ssMock, retryableMock, false, null), is(nullValue()));
- assertThat(hman.oneOf(ssMock, retryableMock, false, "host"), is(nullValue()));
-
- assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
-
- CadiException cadiException;
-
- cadiException = new CadiException(new ConnectException());
- doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
- assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
-
- cadiException = new CadiException(new SSLHandshakeException(null));
- doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
- assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
-
- cadiException = new CadiException(new SocketException());
- doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
- try {
- hman.oneOf(ssMock, retryableMock, false, uriString.substring(7));
- fail("Should've thrown an exception");
- } catch (CadiException e) {
- }
-
- cadiException = new CadiException(new SocketException("java.net.SocketException: Connection reset"));
- doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
- try {
- hman.oneOf(ssMock, retryableMock, false, uriString.substring(7));
- fail("Should've thrown an exception");
- } catch (CadiException e) {
- }
-
- cadiException = new CadiException();
- doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
- try {
- hman.oneOf(ssMock, retryableMock, false, uriString.substring(7));
- fail("Should've thrown an exception");
- } catch (CadiException e) {
- }
-
- doThrow(new ConnectException()).when(retryableMock).code((Rcli<?>) any());
- assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
-
- when(goodRetry.code((Rcli<?>) any())).thenReturn(5);
- assertThat(hman.oneOf(ssMock, goodRetry, false, uriString.substring(7)), is(5));
- }
-
- @Test
- public void coverageTest() throws LocatorException {
- HMangr hman = new HMangr(access, locMock);
- hman.readTimeout(5);
- assertThat(hman.readTimeout(), is(5));
- hman.connectionTimeout(5);
- assertThat(hman.connectionTimeout(), is(5));
- hman.apiVersion("v1.0");
- assertThat(hman.apiVersion(), is("v1.0"));
- hman.close();
-
- }
-
- private class HManagerStub extends HMangr {
- public HManagerStub(Access access, Locator<URI> loc) throws LocatorException { super(access, loc); }
- @Override public<RET> RET same(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) {
- return null;
- }
- @Override public<RET> RET oneOf(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable, boolean notify, String host) {
- return null;
- }
- }
-
+
+ @Mock Locator<URI> locMock;
+ @Mock SecuritySetter<HttpURLConnection> ssMock;
+ @Mock Retryable<Void> retryableMock;
+ @Mock Retryable<Integer> goodRetry;
+ @Mock Locator.Item itemMock;
+ @Mock Rcli<Object> clientMock;
+
+ private PropAccess access;
+ private URI uri;
+ private final static String uriString = "http://example.com";
+
+ @Before
+ public void setup() throws URISyntaxException {
+ MockitoAnnotations.initMocks(this);
+
+ access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
+ uri = new URI(uriString);
+ }
+
+ @Test
+ public void sameTest() throws LocatorException, APIException, CadiException, ConnectException {
+ HMangr hman = new HMangr(access, locMock);
+ when(retryableMock.item()).thenReturn(itemMock);
+ when(locMock.get(itemMock)).thenReturn(uri);
+ assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
+
+ //coverage...
+ when(retryableMock.lastClient()).thenReturn(clientMock);
+ assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
+
+ CadiException cadiException;
+
+ ConnectException connectException = new ConnectException();
+ cadiException = new CadiException(connectException);
+ doThrow(cadiException).when(retryableMock).code(clientMock);
+ when(locMock.hasItems()).thenReturn(true).thenReturn(false);
+ assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
+
+ SocketException socketException = new SocketException();
+ cadiException = new CadiException(socketException);
+ doThrow(cadiException).when(retryableMock).code(clientMock);
+ when(locMock.hasItems()).thenReturn(true).thenReturn(false);
+ assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
+
+ doThrow(connectException).when(retryableMock).code(clientMock);
+ assertThat(hman.same(ssMock, retryableMock), is(nullValue()));
+
+ }
+
+ @Test(expected = LocatorException.class)
+ public void throwsLocatorException1Test() throws LocatorException {
+ @SuppressWarnings("unused")
+ HMangr hman = new HMangr(access, null);
+ }
+
+ @Test(expected = LocatorException.class)
+ public void throwsLocatorException2Test() throws LocatorException, APIException, CadiException {
+ HMangr hman = new HMangr(access, locMock);
+ hman.same(ssMock, retryableMock);
+ }
+
+ @Test(expected = LocatorException.class)
+ public void throwsLocatorException3Test() throws LocatorException, APIException, CadiException {
+ HMangr hman = new HMangr(access, locMock);
+ when(locMock.best()).thenReturn(itemMock);
+ when(locMock.hasItems()).thenReturn(true).thenReturn(false);
+ hman.same(ssMock, retryableMock);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(expected = CadiException.class)
+ public void throwsCadiException1Test() throws LocatorException, APIException, CadiException, ConnectException {
+ HMangr hman = new HMangr(access, locMock);
+ when(retryableMock.item()).thenReturn(itemMock);
+ when(locMock.get(itemMock)).thenReturn(uri);
+ when(retryableMock.lastClient()).thenReturn(clientMock);
+ when(retryableMock.code(clientMock)).thenThrow(CadiException.class);
+ hman.same(ssMock, retryableMock);
+ }
+
+ @Test(expected = CadiException.class)
+ public void throwsCadiException2Test() throws LocatorException, APIException, CadiException, ConnectException {
+ HMangr hman = new HMangr(access, locMock);
+ when(retryableMock.item()).thenReturn(itemMock);
+ when(locMock.get(itemMock)).thenReturn(uri);
+ when(retryableMock.lastClient()).thenReturn(clientMock);
+
+ ConnectException connectException = new ConnectException();
+ CadiException cadiException = new CadiException(connectException);
+ doThrow(cadiException).when(retryableMock).code(clientMock);
+ hman.same(ssMock, retryableMock);
+ }
+
+ @Test(expected = CadiException.class)
+ public void throwsCadiException3Test() throws LocatorException, APIException, CadiException, ConnectException {
+ HMangr hman = new HMangr(access, locMock);
+ when(retryableMock.item()).thenReturn(itemMock);
+ when(locMock.get(itemMock)).thenReturn(uri);
+ when(retryableMock.lastClient()).thenReturn(clientMock);
+
+ SocketException socketException = new SocketException();
+ CadiException cadiException = new CadiException(socketException);
+ doThrow(cadiException).when(retryableMock).code(clientMock);
+ hman.same(ssMock, retryableMock);
+ }
+
+ @Test(expected = CadiException.class)
+ public void throwsCadiException4Test() throws LocatorException, APIException, CadiException, ConnectException {
+ HMangr hman = new HMangr(access, locMock);
+ when(retryableMock.item()).thenReturn(itemMock);
+ when(locMock.get(itemMock)).thenReturn(uri);
+ when(retryableMock.lastClient()).thenReturn(clientMock);
+
+ Exception e = new Exception();
+ CadiException cadiException = new CadiException(e);
+ doThrow(cadiException).when(retryableMock).code(clientMock);
+ hman.same(ssMock, retryableMock);
+ }
+
+ @Test
+ public void allTest() throws LocatorException, CadiException, APIException {
+ HManagerStub hman = new HManagerStub(access, locMock);
+ assertThat(hman.best(ssMock, retryableMock), is(nullValue()));
+ assertThat(hman.all(ssMock, retryableMock), is(nullValue()));
+ assertThat(hman.all(ssMock, retryableMock, true), is(nullValue()));
+ }
+
+ @Test
+ public void oneOfTest() throws LocatorException, CadiException, APIException, ConnectException {
+ HMangr hman = new HMangr(access, locMock);
+ assertThat(hman.oneOf(ssMock, retryableMock, false, "host"), is(nullValue()));
+
+ try {
+ hman.oneOf(ssMock, retryableMock, true, "host");
+ fail("Should've thrown an exception");
+ } catch (LocatorException e) {
+ }
+
+ when(locMock.first()).thenReturn(itemMock);
+ when(locMock.get(itemMock)).thenReturn(uri);
+
+ // Branching coverage...
+ assertThat(hman.oneOf(ssMock, retryableMock, false, null), is(nullValue()));
+ assertThat(hman.oneOf(ssMock, retryableMock, false, "host"), is(nullValue()));
+
+ assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
+
+ CadiException cadiException;
+
+ cadiException = new CadiException(new ConnectException());
+ doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
+ assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
+
+ cadiException = new CadiException(new SSLHandshakeException(null));
+ doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
+ assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
+
+ cadiException = new CadiException(new SocketException());
+ doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
+ try {
+ hman.oneOf(ssMock, retryableMock, false, uriString.substring(7));
+ fail("Should've thrown an exception");
+ } catch (CadiException e) {
+ }
+
+ cadiException = new CadiException(new SocketException("java.net.SocketException: Connection reset"));
+ doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
+ try {
+ hman.oneOf(ssMock, retryableMock, false, uriString.substring(7));
+ fail("Should've thrown an exception");
+ } catch (CadiException e) {
+ }
+
+ cadiException = new CadiException();
+ doThrow(cadiException).when(retryableMock).code((Rcli<?>) any());
+ try {
+ hman.oneOf(ssMock, retryableMock, false, uriString.substring(7));
+ fail("Should've thrown an exception");
+ } catch (CadiException e) {
+ }
+
+ doThrow(new ConnectException()).when(retryableMock).code((Rcli<?>) any());
+ assertThat(hman.oneOf(ssMock, retryableMock, false, uriString.substring(7)), is(nullValue()));
+
+ when(goodRetry.code((Rcli<?>) any())).thenReturn(5);
+ assertThat(hman.oneOf(ssMock, goodRetry, false, uriString.substring(7)), is(5));
+ }
+
+ @Test
+ public void coverageTest() throws LocatorException {
+ HMangr hman = new HMangr(access, locMock);
+ hman.readTimeout(5);
+ assertThat(hman.readTimeout(), is(5));
+ hman.connectionTimeout(5);
+ assertThat(hman.connectionTimeout(), is(5));
+ hman.apiVersion("v1.0");
+ assertThat(hman.apiVersion(), is("v1.0"));
+ hman.close();
+
+ }
+
+ private class HManagerStub extends HMangr {
+ public HManagerStub(Access access, Locator<URI> loc) throws LocatorException { super(access, loc); }
+ @Override public<RET> RET same(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) {
+ return null;
+ }
+ @Override public<RET> RET oneOf(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable, boolean notify, String host) {
+ return null;
+ }
+ }
+
}
\ No newline at end of file