2 * ============LICENSE_START====================================================
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
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====================================================
22 package org.onap.aaf.cadi.cm.test;
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
26 import static org.mockito.Mockito.*;
28 import java.io.ByteArrayOutputStream;
29 import java.io.PrintStream;
30 import java.util.ArrayList;
31 import java.util.List;
36 import org.onap.aaf.cadi.cm.PlaceArtifactOnStream;
37 import org.onap.aaf.misc.env.LogTarget;
38 import org.onap.aaf.misc.env.Trans;
40 import certman.v1_0.Artifacts.Artifact;
41 import certman.v1_0.CertInfo;
43 public class JU_PlaceArtifactOnStream {
45 @Mock private Trans transMock;
46 @Mock private CertInfo certInfoMock;
47 @Mock private Artifact artiMock;
49 private static final String luggagePassword = "12345"; // That's the stupidest combination I've ever heard in my life
50 private static final String privateKeyString = "I'm a private key!";
52 private ByteArrayOutputStream outStream;
54 private List<String> certs;
58 MockitoAnnotations.initMocks(this);
60 certs = new ArrayList<>();
64 when(certInfoMock.getChallenge()).thenReturn(luggagePassword);
65 when(certInfoMock.getCerts()).thenReturn(certs);
66 when(certInfoMock.getPrivatekey()).thenReturn(privateKeyString);
68 outStream = new ByteArrayOutputStream();
73 PlaceArtifactOnStream placer = new PlaceArtifactOnStream(new PrintStream(outStream));
74 placer.place(transMock, certInfoMock, artiMock, "machine");
76 String[] output = outStream.toString().split("\n", 0);
79 "Challenge: " + luggagePassword,
87 assertThat(output.length, is(expected.length));
88 for (int i = 0; i < output.length; i++) {
89 assertThat(output[i], is(expected[i]));
93 when(certInfoMock.getNotes()).thenReturn("");
94 placer.place(transMock, certInfoMock, artiMock, "machine");
96 when(certInfoMock.getNotes()).thenReturn("Some Notes");
97 when(transMock.info()).thenReturn(mock(LogTarget.class));
98 placer.place(transMock, certInfoMock, artiMock, "machine");