1 /*============LICENSE_START=======================================================
2 * aaf-certservice-client
3 * ================================================================================
4 * Copyright (C) 2020 Nokia. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.onap.aaf.certservice.client.certification.conversion;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
27 import java.security.PrivateKey;
28 import java.util.List;
29 import org.junit.jupiter.api.Test;
30 import org.onap.aaf.certservice.client.api.ExitableException;
31 import org.onap.aaf.certservice.client.certification.PrivateKeyToPemEncoder;
32 import org.onap.aaf.certservice.client.certification.writer.CertFileWriter;
34 class PemArtifactsCreatorTest {
35 private final String KEYSTORE_PEM = "keystore.pem";
36 private final String TRUSTSTORE_PEM = "truststore.pem";
37 private final String KEY_PEM = "key.pem";
38 private final String KEY = "my private key";
39 private CertFileWriter certFileWriter = mock(CertFileWriter.class);
40 private PrivateKey privateKey = mock(PrivateKey.class);
41 private PrivateKeyToPemEncoder pkEncoder = mock(PrivateKeyToPemEncoder.class);
44 void pemArtifactsCreatorShouldCallRequiredMethods() throws ExitableException {
46 final PemArtifactsCreator creator = new PemArtifactsCreator(certFileWriter, pkEncoder);
49 when(pkEncoder.encodePrivateKeyToPem(privateKey)).thenReturn(KEY);
50 creator.create(List.of("one", "two"), List.of("three", "four"), privateKey);
53 verify(certFileWriter, times(1)).saveData("one\ntwo".getBytes(), KEYSTORE_PEM);
54 verify(certFileWriter, times(1)).saveData("three\nfour".getBytes(), TRUSTSTORE_PEM);
55 verify(certFileWriter, times(1)).saveData(KEY.getBytes(), KEY_PEM);