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