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;
35 import org.onap.aaf.cadi.configure.PlaceArtifactOnStream;
36 import org.onap.aaf.misc.env.LogTarget;
37 import org.onap.aaf.misc.env.Trans;
39 import certman.v1_0.Artifacts.Artifact;
40 import certman.v1_0.CertInfo;
42 public class JU_PlaceArtifactOnStream {
44 @Mock private Trans transMock;
45 @Mock private CertInfo certInfoMock;
46 @Mock private Artifact artiMock;
48 private static final String luggagePassword = "12345"; // That's the stupidest combination I've ever heard in my life
49 private static final String privateKeyString = "I'm a private key!";
51 private ByteArrayOutputStream outStream;
53 private List<String> certs;
57 MockitoAnnotations.initMocks(this);
59 certs = new ArrayList<>();
63 when(certInfoMock.getChallenge()).thenReturn(luggagePassword);
64 when(certInfoMock.getCerts()).thenReturn(certs);
65 when(certInfoMock.getPrivatekey()).thenReturn(privateKeyString);
67 outStream = new ByteArrayOutputStream();
72 PlaceArtifactOnStream placer = new PlaceArtifactOnStream(new PrintStream(outStream));
73 placer.place(transMock, certInfoMock, artiMock, "machine");
75 String[] output = outStream.toString().split(System.lineSeparator(), 0);
78 "Challenge: " + luggagePassword,
86 assertThat(output.length, is(expected.length));
87 for (int i = 0; i < output.length; i++) {
88 assertThat(output[i], is(expected[i]));
92 when(certInfoMock.getNotes()).thenReturn("");
93 placer.place(transMock, certInfoMock, artiMock, "machine");
95 when(certInfoMock.getNotes()).thenReturn("Some Notes");
96 when(transMock.info()).thenReturn(mock(LogTarget.class));
97 placer.place(transMock, certInfoMock, artiMock, "machine");