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 ******************************************************************************/
23 package org.onap.aaf.auth.cm.cert;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
30 import java.io.FileNotFoundException;
31 import java.io.IOException;
32 import java.security.Key;
33 import java.security.PrivateKey;
34 import java.security.PublicKey;
36 import org.bouncycastle.operator.OperatorCreationException;
37 import org.bouncycastle.pkcs.PKCS10CertificationRequest;
38 import org.junit.BeforeClass;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.junit.rules.ExpectedException;
42 import org.junit.runner.RunWith;
43 import org.mockito.Mockito;
44 import org.mockito.runners.MockitoJUnitRunner;
45 import org.onap.aaf.cadi.configure.CertException;
46 import org.onap.aaf.misc.env.TimeTaken;
47 import org.onap.aaf.misc.env.Trans;
49 @RunWith(MockitoJUnitRunner.class)
50 public class JU_BCFactory {
52 private static BCFactory bcFactory = new BCFactory();
54 private static BCFactory bcFact;
56 private static PrivateKey pk;
59 private static Trans trans;
62 private static PKCS10CertificationRequest req;
65 public static void setUp() throws IOException {
67 trans = mock(Trans.class);
68 req = mock(PKCS10CertificationRequest.class);
69 when(req.getEncoded()).thenReturn(new byte[1]);
70 when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken(null, 0) {
73 public void output(StringBuilder sb) {
74 // TODO Auto-generated method stub
78 bcFact = mock(BCFactory.class);
82 public void toStrin() throws OperatorCreationException, IOException, CertException {
83 assertNotNull(bcFactory.toString(req));
87 public void toStrinMoc() throws OperatorCreationException, IOException, CertException {
88 assertNotNull(bcFact.toString(req));
92 public ExpectedException thrown= ExpectedException.none();
97 assertNotNull(bcFactory.toCSR(trans, new File("/random/path")));
98 thrown.expect(FileNotFoundException.class);
99 } 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);