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.*;
29 import java.util.ArrayList;
30 import java.util.List;
34 import org.onap.aaf.cadi.CadiException;
35 import org.onap.aaf.cadi.configure.PlaceArtifactInFiles;
36 import org.onap.aaf.misc.env.Trans;
38 import certman.v1_0.Artifacts.Artifact;
39 import certman.v1_0.CertInfo;
41 public class JU_PlaceArtifactInFiles {
43 @Mock private Trans transMock;
44 @Mock private CertInfo certInfoMock;
45 @Mock private Artifact artiMock;
47 private static final String dirName = "src/test/resources/artifacts";
48 private static final String nsName = "org.onap.test";
49 private static final String luggagePassword = "12345"; // That's the stupidest combination I've ever heard in my life
51 private List<String> certs;
55 MockitoAnnotations.initMocks(this);
57 certs = new ArrayList<>();
61 when(certInfoMock.getChallenge()).thenReturn(luggagePassword);
62 when(certInfoMock.getCerts()).thenReturn(certs);
64 when(artiMock.getDir()).thenReturn(dirName);
65 when(artiMock.getNs()).thenReturn(nsName);
69 public static void tearDownOnce() {
71 PlaceArtifactInFiles.clear();
75 public void test() throws CadiException {
76 PlaceArtifactInFiles placer = new PlaceArtifactInFiles();
77 placer.place(transMock, certInfoMock, artiMock, "machine");
78 assertThat(placer._place(transMock, certInfoMock, artiMock), is(true));
79 assertThat(new File(dirName + '/' + nsName + ".crt").exists(), is(true));
80 assertThat(new File(dirName + '/' + nsName + ".key").exists(), is(true));
82 when(certInfoMock.getCerts()).thenReturn(null);
84 placer._place(transMock, certInfoMock, artiMock);
85 fail("Should've thrown an exception");
86 } catch (Exception e) {
90 private static void cleanup() {
91 File dir = new File(dirName);
93 for (File f : dir.listFiles()) {