Improve code coverage for aaf cadi modules
[aaf/cadi.git] / aaf / src / test / java / com / onap / aaf / cadi / aaf / AAFPermissionTest.java
diff --git a/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFPermissionTest.java b/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFPermissionTest.java
new file mode 100644 (file)
index 0000000..d0b2bde
--- /dev/null
@@ -0,0 +1,80 @@
+/*******************************************************************************\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 com.onap.aaf.cadi.aaf;\r
+\r
+import static org.hamcrest.CoreMatchers.is;\r
+import static org.junit.Assert.*;\r
+import static org.mockito.Mockito.when;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.onap.aaf.cadi.aaf.AAFPermission;\r
+import org.onap.aaf.cadi.lur.LocalPermission;\r
+\r
+public class AAFPermissionTest {\r
+\r
+       private static final String INSTANCE = "*";\r
+       private static final String ACTION = "*";\r
+       private static final String TYPE = "Auth";\r
+       private static final String KEY =TYPE + '|' + INSTANCE + '|' + ACTION;\r
+       \r
+       private String STRINGVALUE =\r
+       "AAFPermission:\n\tType: " + TYPE + \r
+       "\n\tInstance: " + INSTANCE +\r
+       "\n\tAction: " + ACTION +\r
+       "\n\tKey: " + KEY;\r
+\r
+       @Mock\r
+       private LocalPermission localPermission;\r
+       \r
+       @Mock\r
+       private LocalPermission localPermission2;\r
+\r
+       @Before\r
+       public void setup() {\r
+               MockitoAnnotations.initMocks(this);\r
+               when(localPermission.getKey()).thenReturn(TYPE);\r
+               when(localPermission2.getKey()).thenReturn(TYPE+" Default");\r
+       }\r
+       \r
+       @Test\r
+       public void test() {\r
+               AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION);\r
+               \r
+               assertTrue("This should Match",permission.match(permission));\r
+               \r
+               assertTrue("This should Match", permission.match(localPermission));\r
+               \r
+               assertFalse("This should Not Match", permission.match(localPermission2));\r
+               \r
+               assertThat(permission.getKey(), is(KEY));\r
+               \r
+               assertThat(permission.permType(), is("AAF"));\r
+               \r
+               assertThat(permission.toString(), is(STRINGVALUE));\r
+               \r
+       }\r
+\r
+}\r