Update project structure to org.onap.aaf
[aaf/authz.git] / authz-certman / src / test / java / org / onap / aaf / authz / cm / cert / JU_BCFactory.java
diff --git a/authz-certman/src/test/java/org/onap/aaf/authz/cm/cert/JU_BCFactory.java b/authz-certman/src/test/java/org/onap/aaf/authz/cm/cert/JU_BCFactory.java
new file mode 100644 (file)
index 0000000..3435d49
--- /dev/null
@@ -0,0 +1,132 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ *  *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ *  * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.authz.cm.cert;\r
+\r
+import static org.junit.Assert.*;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.security.Key;\r
+import java.security.PrivateKey;\r
+import java.security.PublicKey;\r
+\r
+import org.bouncycastle.operator.OperatorCreationException;\r
+import org.bouncycastle.pkcs.PKCS10CertificationRequest;\r
+import org.junit.BeforeClass;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.onap.aaf.authz.cm.cert.BCFactory;\r
+\r
+import org.onap.aaf.cadi.cm.CertException;\r
+import org.onap.aaf.inno.env.TimeTaken;\r
+import org.onap.aaf.inno.env.Trans;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class JU_BCFactory {\r
+       \r
+       private static BCFactory bcFactory = new BCFactory();\r
+       \r
+       private static BCFactory bcFact;\r
+       \r
+       private static PrivateKey pk;\r
+       \r
+       \r
+       private static Trans trans;\r
+       \r
+       \r
+       private static PKCS10CertificationRequest req;\r
+       \r
+       @BeforeClass\r
+       public static void setUp() throws IOException {\r
+               pk = new XYZKey();\r
+               trans = mock(Trans.class);\r
+               req = mock(PKCS10CertificationRequest.class);\r
+               when(req.getEncoded()).thenReturn(new byte[1]);\r
+               when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken(null, 0) {\r
+                       \r
+                       @Override\r
+                       public void output(StringBuilder sb) {\r
+                               // TODO Auto-generated method stub\r
+                               \r
+                       }\r
+               });\r
+               bcFact = mock(BCFactory.class);\r
+       }\r
+       \r
+       @Test\r
+       public void toStrin() throws OperatorCreationException, IOException, CertException {\r
+               assertNotNull(bcFactory.toString(trans, req));\r
+       }\r
+       \r
+       @Test\r
+       public void toStrinMoc() throws OperatorCreationException, IOException, CertException {\r
+               assertNotNull(bcFact.toString(trans, req));\r
+       }\r
+       \r
+       @Rule\r
+    public ExpectedException thrown= ExpectedException.none();\r
+       \r
+       @Test\r
+       public void toCSR()  {\r
+               try {\r
+                       assertNotNull(bcFactory.toCSR(trans, new File("/random/path")));\r
+                       thrown.expect(FileNotFoundException.class);\r
+               } catch (IOException e) {\r
+                       \r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+       \r
+}\r
+\r
+class XYZKey implements Key, PublicKey, PrivateKey {\r
+       \r
+       int rotValue;\r
+       public XYZKey() {\r
+               rotValue = 1200213;\r
+       }\r
+       public String getAlgorithm() {\r
+               return "XYZ";\r
+       }\r
+\r
+       public String getFormat() {\r
+               return "XYZ Special Format";\r
+       }\r
+\r
+       public byte[] getEncoded() {\r
+               byte b[] = new byte[4];\r
+               b[3] = (byte) ((rotValue << 24) & 0xff);\r
+               b[2] = (byte) ((rotValue << 16) & 0xff);\r
+               b[1] = (byte) ((rotValue << 8) & 0xff);\r
+               b[0] = (byte) ((rotValue << 0) & 0xff);\r
+               return b;\r
+       }\r
+}\r