682606c0ffac014095179684e1c6ca96e19448f3
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / cm / test / JU_PlaceArtifactScripts.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
22 package org.onap.aaf.cadi.cm.test;
23
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
26 import static org.mockito.Mockito.*;
27
28 import java.io.File;
29
30 import org.junit.*;
31 import org.mockito.*;
32 import org.onap.aaf.cadi.CadiException;
33 import org.onap.aaf.cadi.configure.PlaceArtifactScripts;
34 import org.onap.aaf.misc.env.Trans;
35
36 import certman.v1_0.Artifacts.Artifact;
37 import certman.v1_0.CertInfo;
38
39 public class JU_PlaceArtifactScripts {
40
41         @Mock private Trans transMock;
42         @Mock private CertInfo certInfoMock;
43         @Mock private Artifact artiMock;
44
45         private static final String dirName = "src/test/resources/artifacts";
46         private static final String nsName = "org.onap.test";
47         private static final String luggagePassword = "12345";  // That's the stupidest combination I've ever heard in my life
48         private static final String notification = "A notification";
49         private static final String osUser = "user";  // That's the stupidest combination I've ever heard in my life
50
51         @Before
52         public void setup() {
53                 MockitoAnnotations.initMocks(this);
54
55                 when(artiMock.getDir()).thenReturn(dirName);
56                 when(artiMock.getNs()).thenReturn(nsName);
57                 when(artiMock.getNotification()).thenReturn(notification);
58                 when(artiMock.getOsUser()).thenReturn(osUser);
59
60                 when(certInfoMock.getChallenge()).thenReturn(luggagePassword);
61         }
62
63         @AfterClass
64         public static void tearDownOnce() {
65                 cleanup();
66                 PlaceArtifactScripts.clear();
67         }
68
69         @Test
70         public void test() throws CadiException {
71                 PlaceArtifactScripts placer = new PlaceArtifactScripts();
72                 placer.place(transMock, certInfoMock, artiMock, "machine");
73
74                 assertThat(new File(dirName + '/' + nsName + ".crontab.sh").exists(), is(true));
75                 assertThat(new File(dirName + '/' + nsName + ".check.sh").exists(), is(true));
76
77                 //coverage
78                 when(artiMock.getNotification()).thenReturn("mailto: " + notification);
79                 placer.place(transMock, certInfoMock, artiMock, "machine");
80         }
81
82         private static void cleanup() {
83                 File dir = new File(dirName);
84                 if (dir.exists()) {
85                         for (File f : dir.listFiles()) {
86                                 f.delete();
87                         }
88                         dir.delete();
89                 }
90         }
91
92 }