1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.authz.cm.cert;
\r
25 import static org.junit.Assert.*;
\r
26 import static org.mockito.Mockito.mock;
\r
27 import static org.mockito.Mockito.when;
\r
29 import java.io.File;
\r
30 import java.io.FileNotFoundException;
\r
31 import java.io.IOException;
\r
32 import java.security.Key;
\r
33 import java.security.PrivateKey;
\r
34 import java.security.PublicKey;
\r
36 import org.bouncycastle.operator.OperatorCreationException;
\r
37 import org.bouncycastle.pkcs.PKCS10CertificationRequest;
\r
38 import org.junit.BeforeClass;
\r
39 import org.junit.Rule;
\r
40 import org.junit.Test;
\r
41 import org.junit.rules.ExpectedException;
\r
42 import org.junit.runner.RunWith;
\r
43 import org.mockito.Mock;
\r
44 import org.mockito.Mockito;
\r
45 import org.mockito.runners.MockitoJUnitRunner;
\r
46 import org.onap.aaf.authz.cm.cert.BCFactory;
\r
48 import org.onap.aaf.cadi.cm.CertException;
\r
49 import org.onap.aaf.inno.env.TimeTaken;
\r
50 import org.onap.aaf.inno.env.Trans;
\r
52 @RunWith(MockitoJUnitRunner.class)
\r
53 public class JU_BCFactory {
\r
55 private static BCFactory bcFactory = new BCFactory();
\r
57 private static BCFactory bcFact;
\r
59 private static PrivateKey pk;
\r
62 private static Trans trans;
\r
65 private static PKCS10CertificationRequest req;
\r
68 public static void setUp() throws IOException {
\r
70 trans = mock(Trans.class);
\r
71 req = mock(PKCS10CertificationRequest.class);
\r
72 when(req.getEncoded()).thenReturn(new byte[1]);
\r
73 when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken(null, 0) {
\r
76 public void output(StringBuilder sb) {
\r
77 // TODO Auto-generated method stub
\r
81 bcFact = mock(BCFactory.class);
\r
85 public void toStrin() throws OperatorCreationException, IOException, CertException {
\r
86 assertNotNull(bcFactory.toString(trans, req));
\r
90 public void toStrinMoc() throws OperatorCreationException, IOException, CertException {
\r
91 assertNotNull(bcFact.toString(trans, req));
\r
95 public ExpectedException thrown= ExpectedException.none();
\r
98 public void toCSR() {
\r
100 assertNotNull(bcFactory.toCSR(trans, new File("/random/path")));
\r
101 thrown.expect(FileNotFoundException.class);
\r
102 } catch (IOException e) {
\r
104 e.printStackTrace();
\r
110 class XYZKey implements Key, PublicKey, PrivateKey {
\r
114 rotValue = 1200213;
\r
116 public String getAlgorithm() {
\r
120 public String getFormat() {
\r
121 return "XYZ Special Format";
\r
124 public byte[] getEncoded() {
\r
125 byte b[] = new byte[4];
\r
126 b[3] = (byte) ((rotValue << 24) & 0xff);
\r
127 b[2] = (byte) ((rotValue << 16) & 0xff);
\r
128 b[1] = (byte) ((rotValue << 8) & 0xff);
\r
129 b[0] = (byte) ((rotValue << 0) & 0xff);
\r