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 com.att.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
47 import com.att.cadi.cm.CertException;
\r
48 import com.att.inno.env.TimeTaken;
\r
49 import com.att.inno.env.Trans;
\r
51 @RunWith(MockitoJUnitRunner.class)
\r
52 public class JU_BCFactory {
\r
54 private static BCFactory bcFactory = new BCFactory();
\r
56 private static BCFactory bcFact;
\r
58 private static PrivateKey pk;
\r
61 private static Trans trans;
\r
64 private static PKCS10CertificationRequest req;
\r
67 public static void setUp() throws IOException {
\r
69 trans = mock(Trans.class);
\r
70 req = mock(PKCS10CertificationRequest.class);
\r
71 when(req.getEncoded()).thenReturn(new byte[1]);
\r
72 when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken(null, 0) {
\r
75 public void output(StringBuilder sb) {
\r
76 // TODO Auto-generated method stub
\r
80 bcFact = mock(BCFactory.class);
\r
84 public void toStrin() throws OperatorCreationException, IOException, CertException {
\r
85 assertNotNull(bcFactory.toString(trans, req));
\r
89 public void toStrinMoc() throws OperatorCreationException, IOException, CertException {
\r
90 assertNotNull(bcFact.toString(trans, req));
\r
94 public ExpectedException thrown= ExpectedException.none();
\r
97 public void toCSR() {
\r
99 assertNotNull(bcFactory.toCSR(trans, new File("/random/path")));
\r
100 thrown.expect(FileNotFoundException.class);
\r
101 } catch (IOException e) {
\r
103 e.printStackTrace();
\r
109 class XYZKey implements Key, PublicKey, PrivateKey {
\r
113 rotValue = 1200213;
\r
115 public String getAlgorithm() {
\r
119 public String getFormat() {
\r
120 return "XYZ Special Format";
\r
123 public byte[] getEncoded() {
\r
124 byte b[] = new byte[4];
\r
125 b[3] = (byte) ((rotValue << 24) & 0xff);
\r
126 b[2] = (byte) ((rotValue << 16) & 0xff);
\r
127 b[1] = (byte) ((rotValue << 8) & 0xff);
\r
128 b[0] = (byte) ((rotValue << 0) & 0xff);
\r