Remove Tabs, per Jococo
[aaf/authz.git] / auth / auth-certman / src / test / java / org / onap / aaf / auth / cm / data / JU_CertRespTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21 package org.onap.aaf.auth.cm.data;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Mockito.when;
26 import static org.mockito.MockitoAnnotations.initMocks;
27
28 import java.io.IOException;
29 import java.security.GeneralSecurityException;
30 import java.security.KeyPair;
31 import java.security.PrivateKey;
32 import java.security.PublicKey;
33 import java.security.cert.X509Certificate;
34
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Answers;
38 import org.mockito.Mock;
39 import org.onap.aaf.auth.cm.ca.CA;
40 import org.onap.aaf.auth.cm.cert.CSRMeta;
41 import org.onap.aaf.cadi.configure.CertException;
42 import org.onap.aaf.misc.env.Trans;
43
44 public class JU_CertRespTest {
45
46     @Mock
47     CSRMeta csrMeta;
48
49     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
50     Trans trans;
51
52     @Mock
53     X509Certificate x509;
54
55     @Mock
56     CA ca;
57
58     @Before
59     public void setUp() throws Exception {
60         initMocks(this);
61         CertDrop drop = new CertDrop();
62         CertRenew renew = new CertRenew();
63
64         PublicKey publicKey = new PublicKey() {
65
66             @Override
67             public String getFormat() {
68                 // TODO Auto-generated method stub
69                 return null;
70             }
71
72             @Override
73             public byte[] getEncoded() {
74                 // TODO Auto-generated method stub
75                 return null;
76             }
77
78             @Override
79             public String getAlgorithm() {
80                 // TODO Auto-generated method stub
81                 return null;
82             }
83         };
84         PrivateKey privateKey = new PrivateKey() {
85
86             @Override
87             public String getFormat() {
88                 // TODO Auto-generated method stub
89                 return null;
90             }
91
92             @Override
93             public byte[] getEncoded() {
94                 // TODO Auto-generated method stub
95                 return "privatekey".getBytes();
96             }
97
98             @Override
99             public String getAlgorithm() {
100                 // TODO Auto-generated method stub
101                 return null;
102             }
103         };
104         KeyPair keypair = new KeyPair(publicKey, privateKey);
105
106         when(csrMeta.keypair(trans)).thenReturn(keypair);
107         when(csrMeta.challenge()).thenReturn("challenge");
108         when(x509.getSubjectDN()).thenReturn(null);
109         when(x509.getEncoded()).thenReturn("x509Certificate".getBytes());
110
111     }
112
113     @Test
114     public void testCertResp() throws IOException, GeneralSecurityException, CertException {
115         CertResp resp = new CertResp("CERT");
116
117         assertEquals("CERT", resp.asCertString());
118         assertEquals("", resp.challenge());
119
120         String[] trustChain = { "trustChain" };
121         String[] notes = { "notes" };
122
123         String[] caIssureDNs = { "caIssuer" };
124         String[] trustedCAs = { "trustedCAs" };
125
126         when(ca.getCaIssuerDNs()).thenReturn(caIssureDNs);
127         when(ca.getEnv()).thenReturn("Env");
128         when(ca.getTrustedCAs()).thenReturn(trustedCAs);
129
130         resp = new CertResp(trans, ca, x509, csrMeta, trustChain, notes);
131
132         assertNotNull(resp.privateString());
133         assertEquals("challenge", resp.challenge());
134         assertEquals("notes", resp.notes()[0]);
135         assertEquals("trustChain", resp.trustChain()[0]);
136         assertEquals("caIssuer", resp.caIssuerDNs()[0]);
137         assertEquals("trustedCAs", resp.trustCAs()[0]);
138         assertEquals("Env", resp.env());
139     }
140 }