Improve coverage of cadi-aaf
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / cm / test / JU_PlaceArtifactScripts.java
diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/cm/test/JU_PlaceArtifactScripts.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/cm/test/JU_PlaceArtifactScripts.java
new file mode 100644 (file)
index 0000000..0ed29e1
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.cadi.cm.test;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.mockito.Mockito.*;
+
+import java.io.File;
+
+import org.junit.*;
+import org.mockito.*;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.cm.PlaceArtifactScripts;
+import org.onap.aaf.misc.env.Trans;
+
+import certman.v1_0.Artifacts.Artifact;
+import certman.v1_0.CertInfo;
+
+public class JU_PlaceArtifactScripts {
+
+       @Mock private Trans transMock;
+       @Mock private CertInfo certInfoMock;
+       @Mock private Artifact artiMock;
+
+       private static final String dirName = "src/test/resources/artifacts";
+       private static final String nsName = "org.onap.test";
+       private static final String luggagePassword = "12345";  // That's the stupidest combination I've ever heard in my life
+       private static final String notification = "A notification";
+       private static final String osUser = "user";  // That's the stupidest combination I've ever heard in my life
+
+       @Before
+       public void setup() {
+               MockitoAnnotations.initMocks(this);
+
+               when(artiMock.getDir()).thenReturn(dirName);
+               when(artiMock.getNs()).thenReturn(nsName);
+               when(artiMock.getNotification()).thenReturn(notification);
+               when(artiMock.getOsUser()).thenReturn(osUser);
+
+               when(certInfoMock.getChallenge()).thenReturn(luggagePassword);
+       }
+
+       @AfterClass
+       public static void tearDownOnce() {
+               cleanup();
+               PlaceArtifactScripts.clear();
+       }
+
+       @Test
+       public void test() throws CadiException {
+               PlaceArtifactScripts placer = new PlaceArtifactScripts();
+               placer.place(transMock, certInfoMock, artiMock, "machine");
+
+               assertThat(new File(dirName + '/' + nsName + ".crontab.sh").exists(), is(true));
+               assertThat(new File(dirName + '/' + nsName + ".check.sh").exists(), is(true));
+
+               //coverage
+               when(artiMock.getNotification()).thenReturn("mailto: " + notification);
+               placer.place(transMock, certInfoMock, artiMock, "machine");
+       }
+
+       private static void cleanup() {
+               File dir = new File(dirName);
+               if (dir.exists()) {
+                       for (File f : dir.listFiles()) {
+                               f.delete();
+                       }
+                       dir.delete();
+               }
+       }
+
+}