X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fclient%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fhttp%2Ftest%2FJU_HX509SS.java;h=fd102a959318b2d0a130838c95fb599d2ddd8ec5;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=b57f29e0b18569179cc3046dacc65701f585db2f;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/cadi/client/src/test/java/org/onap/aaf/cadi/http/test/JU_HX509SS.java b/cadi/client/src/test/java/org/onap/aaf/cadi/http/test/JU_HX509SS.java index b57f29e0..fd102a95 100644 --- a/cadi/client/src/test/java/org/onap/aaf/cadi/http/test/JU_HX509SS.java +++ b/cadi/client/src/test/java/org/onap/aaf/cadi/http/test/JU_HX509SS.java @@ -48,70 +48,70 @@ import org.onap.aaf.cadi.http.HX509SS; import org.onap.aaf.misc.env.APIException; public class JU_HX509SS { - - @Mock X509Certificate x509Mock; - @Mock X509KeyManager keyManagerMock; - @Mock PrivateKey privateKeyMock; - @Mock SecurityInfoC siMock; - @Mock HttpURLConnection hucMock; - @Mock HttpsURLConnection hucsMock; - - private final static String alias = "Some alias"; - private final static String algName = "Some algName"; - private final static byte[] publicKeyBytes = "a public key".getBytes(); - - private PropAccess access; - private SecurityInfoC si; - - @Before - public void setup() throws IOException, CadiException, CertificateEncodingException { - MockitoAnnotations.initMocks(this); - - when(x509Mock.getSigAlgName()).thenReturn(algName); - when(x509Mock.getEncoded()).thenReturn(publicKeyBytes); - - when(keyManagerMock.getCertificateChain(alias)).thenReturn(new X509Certificate[] {x509Mock}); - when(keyManagerMock.getPrivateKey(alias)).thenReturn(privateKeyMock); + + @Mock X509Certificate x509Mock; + @Mock X509KeyManager keyManagerMock; + @Mock PrivateKey privateKeyMock; + @Mock SecurityInfoC siMock; + @Mock HttpURLConnection hucMock; + @Mock HttpsURLConnection hucsMock; + + private final static String alias = "Some alias"; + private final static String algName = "Some algName"; + private final static byte[] publicKeyBytes = "a public key".getBytes(); + + private PropAccess access; + private SecurityInfoC si; + + @Before + public void setup() throws IOException, CadiException, CertificateEncodingException { + MockitoAnnotations.initMocks(this); + + when(x509Mock.getSigAlgName()).thenReturn(algName); + when(x509Mock.getEncoded()).thenReturn(publicKeyBytes); + + when(keyManagerMock.getCertificateChain(alias)).thenReturn(new X509Certificate[] {x509Mock}); + when(keyManagerMock.getPrivateKey(alias)).thenReturn(privateKeyMock); - when(siMock.getKeyManagers()).thenReturn(new X509KeyManager[] {keyManagerMock}); - - access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); - access.setProperty(Config.CADI_ALIAS, alias); - // si = SecurityInfoC.instance(access, HttpURLConnectionStub.class); - } + when(siMock.getKeyManagers()).thenReturn(new X509KeyManager[] {keyManagerMock}); + + access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); + access.setProperty(Config.CADI_ALIAS, alias); + // si = SecurityInfoC.instance(access, HttpURLConnectionStub.class); + } - @Test - public void test() throws APIException, CadiException { - HX509SS x509 = new HX509SS(alias, siMock); - assertThat(x509.getID(), is(alias)); - assertThat(x509.setLastResponse(0), is(0)); - assertThat(x509.setLastResponse(1), is(0)); - assertThat(x509.setLastResponse(2), is(0)); - - // coverage... - x509.setSecurity(hucMock); - x509.setSecurity(hucsMock); - } - - // TODO: Test the setSecurity method - Ian - // @Test - // public void test2() throws APIException, CadiException { - // HX509SS x509 = new HX509SS(si, false); - // x509.setSecurity(hucMock); - // x509.setSecurity(hucsMock); - // } - - @Test(expected = APIException.class) - public void throws1Test() throws APIException, CadiException { - @SuppressWarnings("unused") - HX509SS x509 = new HX509SS(siMock); - } + @Test + public void test() throws APIException, CadiException { + HX509SS x509 = new HX509SS(alias, siMock); + assertThat(x509.getID(), is(alias)); + assertThat(x509.setLastResponse(0), is(0)); + assertThat(x509.setLastResponse(1), is(0)); + assertThat(x509.setLastResponse(2), is(0)); + + // coverage... + x509.setSecurity(hucMock); + x509.setSecurity(hucsMock); + } + + // TODO: Test the setSecurity method - Ian + // @Test + // public void test2() throws APIException, CadiException { + // HX509SS x509 = new HX509SS(si, false); + // x509.setSecurity(hucMock); + // x509.setSecurity(hucsMock); + // } + + @Test(expected = APIException.class) + public void throws1Test() throws APIException, CadiException { + @SuppressWarnings("unused") + HX509SS x509 = new HX509SS(siMock); + } - @Test(expected = APIException.class) - public void throws3Test() throws APIException, CadiException { - when(keyManagerMock.getCertificateChain(alias)).thenReturn(new X509Certificate[0]); - @SuppressWarnings("unused") - HX509SS x509 = new HX509SS(alias, siMock); - } - + @Test(expected = APIException.class) + public void throws3Test() throws APIException, CadiException { + when(keyManagerMock.getCertificateChain(alias)).thenReturn(new X509Certificate[0]); + @SuppressWarnings("unused") + HX509SS x509 = new HX509SS(alias, siMock); + } + }