summaryrefslogtreecommitdiffstats
path: root/auth/auth-core/src/test
diff options
context:
space:
mode:
authorInstrumental <jcgmisc@stl.gathman.org>2018-03-26 13:51:48 -0700
committerInstrumental <jcgmisc@stl.gathman.org>2018-03-26 13:52:07 -0700
commit71037c39a37d3549dcfe31926832a657744fbe05 (patch)
tree78911b2b5e86e4e44228f7a27b3a8cd954b7f3e2 /auth/auth-core/src/test
parenta20accc73189d8e5454cd26049c0e6fae75da16f (diff)
AT&T 2.0.19 Code drop, stage 3
Issue-ID: AAF-197 Change-Id: I8b02cb073ccba318ccaf6ea0276446bdce88fb82 Signed-off-by: Instrumental <jcgmisc@stl.gathman.org>
Diffstat (limited to 'auth/auth-core/src/test')
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java66
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java174
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransFilter.java130
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransImpl.java169
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java121
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_NullTrans.java273
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java58
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_DataFile.java70
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_TextIndex.java76
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java48
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java64
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/CredCompare.java64
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/JU_RequestCheck.java42
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/MultiCompare.java69
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSAttribCompare.java93
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSCompare.java75
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/PermCompare.java66
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RoleCompare.java62
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RolePermCompare.java69
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RosettaCompare.java66
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/UserRoleCompare.java62
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch.java173
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch1.java164
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterRoute.java33
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java184
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CodeSetter.java73
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content.java661
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java130
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Pair.java47
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Route.java38
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_RouteReport.java40
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Routes.java72
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_TypedCode.java106
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Version.java70
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_JettyServiceStarter.java95
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/util/test/JU_Mask.java71
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java204
37 files changed, 4078 insertions, 0 deletions
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java
new file mode 100644
index 00000000..89e1aa94
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/common/test/JU_Define.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.common.test;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.misc.env.Env;
+import static org.junit.Assert.*;
+
+//import com.att.authz.common.Define;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+//TODO: Gabe [JUnit] class path/ class Define is missing, com.att.authz.common also missing
+public class JU_Define {
+ //Define define;
+ public static String ROOT_NS="NS.Not.Set";
+ public static String ROOT_COMPANY=ROOT_NS;
+
+ @Mock
+ Env envMock;
+
+
+// @Before
+// public void setUp(){
+// define = new Define();
+// }
+//
+// @Test
+// public void testSet() throws CadiException {
+// PowerMockito.when(envMock.getProperty(Config.AAF_ROOT_NS)).thenReturn("aaf_root_ns");
+// PowerMockito.when(envMock.getProperty(Config.AAF_ROOT_COMPANY)).thenReturn("aaf_root_company");
+// //PowerMockito.when(envMock.init().log()).thenReturn(null);
+// //PowerMockito.doNothing().doThrow(new CadiException()).when(envMock).init().log(Matchers.anyString());
+// //define.set(envMock);
+// }
+
+ @Test
+ public void netYetTested() {
+ fail("Tests not yet implemented");
+ }
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
new file mode 100644
index 00000000..1117fce7
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.env.test;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import org.onap.aaf.cadi.Access;
+import static org.mockito.Mockito.when;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.Access.Level;
+import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.misc.env.APIException;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import junit.framework.Assert;
+
+@RunWith(PowerMockRunner.class)
+public class JU_AuthzEnv {
+ private static final org.onap.aaf.cadi.Access.Level DEBUG = null;
+ AuthzEnv authzEnv;
+ enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
+
+ @Before
+ public void setUp(){
+ PropAccess access = null;
+ Properties props = null;
+ authzEnv = new AuthzEnv();
+ AuthzEnv authzEnv1 = new AuthzEnv("Test");
+ AuthzEnv authzEnv2 = new AuthzEnv(props);
+ AuthzEnv authzEnv3 = new AuthzEnv(access);
+ }
+
+ @Test
+ public void testTransRate() {
+ Long Result = authzEnv.transRate();
+ System.out.println("value of result " +Result); //Expected 300000
+ assertNotNull(Result);
+ }
+
+ @Test
+ public void checkNewTransNoAvg() {
+
+ Assert.assertNotNull(authzEnv.newTransNoAvg());
+ }
+
+ @Test
+ public void checkNewTrans() {
+ Assert.assertNotNull(authzEnv.newTrans());
+ }
+
+ @Test
+ public void checkPropAccess() {
+ Assert.assertNotNull(authzEnv.access());
+ }
+
+ @Test
+ public void checkgetProperties() { //TODO:[GABE]No setter for this, add?
+ Assert.assertNotNull(authzEnv.getProperties());
+ Assert.assertNotNull(authzEnv.getProperties("test"));
+ }
+
+ @Test(expected = APIException.class)
+ public void checkSetLog4JNames() throws APIException {//TODO: Find better way to test instead of just seeing if strings pass
+ authzEnv.setLog4JNames("path", "root","service","audit","init","trace");
+ authzEnv.setLog4JNames("path", "root",null,"audit","init","trace");
+ }
+
+ @Test
+ public void checkPropertyGetters(){
+ authzEnv.setProperty("key","value");
+ Assert.assertEquals(authzEnv.getProperty("key"), "value");
+ Assert.assertEquals(authzEnv.getProperty("key","value"), "value");
+ }
+
+ @Test
+ public void checkPropertySetters(){
+ Assert.assertEquals(authzEnv.getProperty("key","value"), authzEnv.setProperty("key","value"));
+ }
+
+ @Test(expected = IOException.class)
+ public void testDecryptException() throws IOException{
+ String encrypted = "enc:";
+ authzEnv.setProperty(Config.CADI_KEYFILE, "test");//TODO: Figure out setter for this
+ authzEnv.decrypt(encrypted, true);
+ authzEnv.decrypt("", false);
+ }
+
+ @Test
+ public void testDecrypt() throws IOException{
+ String encrypted = "encrypted";
+ String Result = authzEnv.decrypt(encrypted, true);
+ System.out.println("value of res " +Result);
+ assertEquals("encrypted",Result);
+ }
+
+ @Test
+ public void testClassLoader() {
+ ClassLoader cLoad = mock(ClassLoader.class);
+ cLoad = authzEnv.classLoader();
+ Assert.assertNotNull(cLoad);
+ }
+
+ @Test
+ public void testLoad() throws IOException {
+ InputStream is = mock(InputStream.class);
+ authzEnv.load(is);
+ }
+
+ @Test
+ public void testLog() {
+ Access.Level lvl = Access.Level.DEBUG;
+ Object msgs = null;
+ authzEnv.log(lvl, msgs);
+ }
+
+ @Test
+ public void testLog1() {
+ Exception e = new Exception();
+ Object msgs = null;
+ authzEnv.log(e, msgs);
+ }
+
+ @Test
+ public void testPrintf() {
+ Access.Level lvl = Access.Level.DEBUG;
+ Object msgs = null;
+ authzEnv.printf(lvl, "Test", msgs);
+ }
+
+ @Test
+ public void testWillLog() {
+ Access.Level lvl = Access.Level.DEBUG;
+ Access.Level lvl1 = Access.Level.AUDIT;
+ boolean test = authzEnv.willLog(lvl);
+ Assert.assertFalse(test);
+ test = authzEnv.willLog(lvl1);
+ Assert.assertTrue(test);
+
+ }
+
+ @Test
+ public void testSetLogLevel() {
+ Access.Level lvl = Access.Level.DEBUG;
+ authzEnv.setLogLevel(lvl);
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransFilter.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransFilter.java
new file mode 100644
index 00000000..f874e9d0
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransFilter.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.env.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.*;
+import org.mockito.Mock;
+import java.security.Principal;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransFilter;
+import org.onap.aaf.auth.env.AuthzTransImpl;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.Connector;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.TrustChecker;
+import org.onap.aaf.cadi.principal.TaggedPrincipal;
+import org.onap.aaf.misc.env.LogTarget;
+import org.onap.aaf.misc.env.Slot;
+import org.onap.aaf.misc.env.Trans.Metric;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class JU_AuthzTransFilter {
+AuthzTransFilter authzTransFilter;
+AuthzEnv authzEnvMock = mock(AuthzEnv.class);
+Connector connectorMock = mock(Connector.class);
+TrustChecker trustCheckerMock = mock(TrustChecker.class);
+AuthzTrans authzTransMock = mock(AuthzTrans.class);
+Object additionalTafLurs = mock(Object.class);
+
+ @Before
+ public void setUp() throws CadiException{
+ when(authzEnvMock.access()).thenReturn(new PropAccess());
+ //when(authzEnvMock.newTrans()).thenReturn(new AuthzTransImpl(authzEnvMock));
+ authzTransFilter = new AuthzTransFilter(authzEnvMock, connectorMock, trustCheckerMock, additionalTafLurs);
+
+
+ }
+
+/* @Test
+ public void testTallyHo(){
+ PowerMockito.when(authzTransMock.info().isLoggable()).thenReturn(true);
+ //TODO: Gabe [JUnit] Not visible for junit
+ //if(trans.info().isLoggable())
+ //authzTransFilter.tallyHo(authzTransMock);
+
+ }*/
+
+ /*@Test
+ public void testProtected() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Method newTransMethod = AuthzTransFilter.class.getDeclaredMethod("newTrans");
+ newTransMethod.setAccessible(true);
+
+ newTransMethod.invoke(authzTransFilter);
+ }*/
+
+ @Test
+ public void testAuthenticated() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, CadiException {
+ Principal p = mock(Principal.class);
+ AuthzTransFilter aTF = new AuthzTransFilter(authzEnvMock, connectorMock, trustCheckerMock, null);
+ Class c = aTF.getClass();
+ Class[] cArg = new Class[2];
+ cArg[0] = AuthzTrans.class;
+ cArg[1] = Principal.class; //Steps to test a protected method
+ Method authenticatedMethod = c.getDeclaredMethod("authenticated", cArg);
+ authenticatedMethod.setAccessible(true);
+ authenticatedMethod.invoke(aTF,authzTransMock, null);
+ }
+
+ @Test
+ public void testTallyHo() throws CadiException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Slot specialLogSlot = authzEnvMock.slot("SPECIAL_LOG_SLOT");
+ LogTarget lt = mock(LogTarget.class);
+ AuthzTransFilter aTF = new AuthzTransFilter(authzEnvMock, connectorMock, trustCheckerMock, additionalTafLurs);
+ TaggedPrincipal tPrin = mock(TaggedPrincipal.class);
+ Metric met = new Metric();
+ met.total = 199.33F;
+ met.entries = 15;
+ met.buckets = new float[] {199.33F,99.33F};
+ Class c = aTF.getClass();
+ Class[] cArg = new Class[1];
+ cArg[0] = AuthzTrans.class; //Steps to test a protected method
+ Method tallyHoMethod = c.getDeclaredMethod("tallyHo", cArg);
+ StringBuilder sb = new StringBuilder("AuditTrail\n");
+ when(authzTransMock.auditTrail(((LogTarget)any()), anyInt(),(StringBuilder)any(),anyInt(),anyInt())).thenReturn(met);
+ tallyHoMethod.setAccessible(true);
+ when(authzTransMock.get(specialLogSlot, false)).thenReturn(false);
+ when(authzTransMock.warn()).thenReturn(lt);
+ when(authzTransMock.info()).thenReturn(lt);
+ tallyHoMethod.invoke(aTF,authzTransMock);
+ when(authzTransMock.getUserPrincipal()).thenReturn(tPrin);
+ tallyHoMethod.invoke(aTF,authzTransMock);
+
+ }
+
+
+
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransImpl.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransImpl.java
new file mode 100644
index 00000000..c646e52e
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransImpl.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.env.test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.security.Principal;
+import java.util.Date;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTransImpl;
+import org.onap.aaf.auth.env.AuthzTrans.REQD_TYPE;
+import org.onap.aaf.auth.org.Organization;
+import org.onap.aaf.auth.org.OrganizationFactory;
+import org.onap.aaf.cadi.Lur;
+import org.onap.aaf.cadi.Permission;
+import org.onap.aaf.misc.env.Env;
+import org.onap.aaf.misc.env.LogTarget;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import junit.framework.Assert;
+
+@RunWith(PowerMockRunner.class)
+public class JU_AuthzTransImpl {
+
+ AuthzTransImpl authzTransImpl;
+ @Mock
+ AuthzEnv authzEnvMock;
+ AuthzTransImpl trans1;
+
+ private Organization org=null;
+ private AuthzTransImpl mockAuthzTransImpl;
+ private static HttpServletRequest req;
+ private static HttpServletResponse res;
+ private Lur lur1 = mock(Lur.class);
+
+ @Before
+ public void setUp(){
+ authzTransImpl = new AuthzTransImpl(authzEnvMock);
+ req = mock(HttpServletRequest.class);
+ authzTransImpl.set(req);
+ when(req.getParameter("request")).thenReturn("NotNull");
+ authzTransImpl.set(req);
+ when(req.getParameter("request")).thenReturn("");
+ authzTransImpl.set(req);
+ }
+
+ @Test
+ public void testOrg() {
+ Organization result=null;
+ result = authzTransImpl.org();
+ OrganizationFactory test = mock(OrganizationFactory.class);
+ //result = OrganizationFactory.obtain(authzTransImpl.env(), authzTransImpl.user());
+ authzTransImpl.org();
+ //when(test).thenReturn(null);
+ //assertTrue(true);
+ }
+
+ @Mock
+ LogTarget logTargetMock;
+
+ @Test
+ public void testLogAuditTrail(){
+
+ when(logTargetMock.isLoggable()).thenReturn(false);
+ authzTransImpl.logAuditTrail(logTargetMock);
+ when(logTargetMock.isLoggable()).thenReturn(true);
+ Env delegate = mock(Env.class);
+ //when(logTargetMock.isLoggable()).thenReturn(true);//TODO: Figure this out
+ //authzTransImpl.logAuditTrail(logTargetMock);
+ }
+
+// @Test //TODO:Fix this AAF-111
+// public void testSetUser() {
+// Principal user = mock(Principal.class);
+// authzTransImpl.setUser(user);
+// Principal user1 = authzTransImpl.getUserPrincipal();
+// String username = user1.getName();
+// Assert.assertNotNull(user1);
+// }
+
+// @Test //TODO:Fix this AAF-111
+// public void testUser() {
+// Assert.assertEquals("n/a", authzTransImpl.user());
+// Principal user = mock(Principal.class); //Unsure how to modify name
+// when(user.toString()).thenReturn("name");
+// when(user.getName()).thenReturn("name");
+// authzTransImpl.setUser(user);
+// Assert.assertEquals("name", authzTransImpl.user());
+// }
+//
+ @Test
+ public void testRequested() {
+ REQD_TYPE user = REQD_TYPE.move;
+ REQD_TYPE user1 = REQD_TYPE.future;
+ HttpServletRequest req = mock(HttpServletRequest.class);
+ String p = user1.name();
+ boolean boolUser = authzTransImpl.requested(user);
+ Assert.assertEquals(false, boolUser);
+ Assert.assertNotNull(p);
+ authzTransImpl.requested(user,true);
+ when(authzTransImpl.requested(user)).thenReturn(null);
+ Assert.assertEquals(true, authzTransImpl.requested(user));
+ /* String p1 = req.getParameter(user1.name()); //unable to access private method call in all instances
+ when(req.getParameter(user1.name())).thenReturn("test");
+ authzTransImpl.requested(user,false);
+ */
+
+
+ }
+
+ @Test
+ public void testFish() {
+ mockAuthzTransImpl = mock(AuthzTransImpl.class);
+ Permission p = mock(Permission.class);
+ authzTransImpl.fish(p);
+ String str = "Test";
+ lur1.createPerm(str);
+ when(p.match(p)).thenReturn(true);
+ authzTransImpl.setLur(lur1);
+ authzTransImpl.fish(p);
+ }
+
+ @Test
+ public void testSetVariables() { //TODO: refactor this better
+ Assert.assertNull(authzTransImpl.agent());
+ Assert.assertNull(authzTransImpl.ip());
+ Assert.assertNull(authzTransImpl.path());
+ Assert.assertNotNull(authzTransImpl.port());
+ Assert.assertNull(authzTransImpl.meth());
+ Assert.assertNull(authzTransImpl.getUserPrincipal());
+ Assert.assertNotNull(authzTransImpl.user());
+ }
+
+ @Test
+ public void testNow() {
+ Date date = new Date();
+ Assert.assertEquals(date,authzTransImpl.now());
+ when(authzTransImpl.now()).thenReturn(null);
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java
new file mode 100644
index 00000000..b29e716a
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzTransOnlyFilter.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.env.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import static org.mockito.Mockito.*;
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.servlet.ServletRequest;
+
+import org.onap.aaf.cadi.principal.TaggedPrincipal;
+import org.onap.aaf.misc.env.Env;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransFilter;
+import org.onap.aaf.auth.env.AuthzTransOnlyFilter;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.Connector;
+import org.onap.aaf.cadi.TrustChecker;
+import org.onap.aaf.misc.env.LogTarget;
+import org.onap.aaf.misc.env.Slot;
+import org.onap.aaf.misc.env.Trans;
+import org.onap.aaf.misc.env.Trans.Metric;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_AuthzTransOnlyFilter {
+ AuthzTransFilter authzTransFilter;
+ AuthzEnv authzEnvMock = mock(AuthzEnv.class);
+ Connector connectorMock = mock(Connector.class);
+ TrustChecker trustCheckerMock = mock(TrustChecker.class);
+ AuthzTrans authzTransMock = mock(AuthzTrans.class);
+ Object additionalTafLurs = mock(Object.class);
+ ServletRequest servletRequestMock = mock(ServletRequest.class);
+ AuthzTransOnlyFilter authzTransOnlyFilter;
+
+ @Before
+ public void setUp(){
+ authzTransOnlyFilter = new AuthzTransOnlyFilter(authzEnvMock);
+ }
+
+ /*@Test
+ public void testProtected() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Method newTransMethod = AuthzTransFilter.class.getDeclaredMethod("newTrans");
+ newTransMethod.setAccessible(true);
+
+ newTransMethod.invoke(authzTransFilter);
+ }*/
+
+ @Test
+ public void testStart() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ AuthzTransOnlyFilter aTF = new AuthzTransOnlyFilter(authzEnvMock);
+ Class c = aTF.getClass();
+ Class[] cArg = new Class[2];
+ cArg[0] = AuthzTrans.class;
+ cArg[1] = ServletRequest.class; //Steps to test a protected method
+ Method startMethod = c.getDeclaredMethod("start", cArg);
+ startMethod.setAccessible(true);
+ //startMethod.invoke(aTF, authzTransMock, servletRequestMock);
+ }
+
+ @Test
+ public void testAuthenticated() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, CadiException {
+ TaggedPrincipal p = mock(TaggedPrincipal.class);
+ AuthzTransOnlyFilter aTF = new AuthzTransOnlyFilter(authzEnvMock);
+ Class c = aTF.getClass();
+ Class[] cArg = new Class[2];
+ cArg[0] = AuthzTrans.class;
+ cArg[1] = TaggedPrincipal.class; //Steps to test a protected method
+ Method authenticatedMethod = c.getDeclaredMethod("authenticated", cArg);
+ authenticatedMethod.setAccessible(true);
+ authenticatedMethod.invoke(aTF,authzTransMock, null);
+ }
+
+ @Test
+ public void testTallyHo() throws CadiException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ AuthzTransOnlyFilter aTF = new AuthzTransOnlyFilter(authzEnvMock);
+ LogTarget log = mock(LogTarget.class);
+ Metric met = new Metric();
+ met.total = 199.33F;
+ met.entries = 15;
+ met.buckets = new float[] {199.33F,99.33F};
+ Class c = aTF.getClass();
+ Class[] cArg = new Class[1];
+ cArg[0] = AuthzTrans.class; //Steps to test a protected method
+ StringBuilder sb = new StringBuilder("AuditTrail\n");
+ when(authzTransMock.auditTrail(anyInt(),(StringBuilder)any(),anyInt(),anyInt())).thenReturn(met);
+ when(authzTransMock.info()).thenReturn(log);
+ doNothing().when(log).log((StringBuilder)any());
+ Method tallyHoMethod = c.getDeclaredMethod("tallyHo", cArg);
+ tallyHoMethod.setAccessible(true);
+ tallyHoMethod.invoke(aTF,authzTransMock);
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_NullTrans.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_NullTrans.java
new file mode 100644
index 00000000..e82aa163
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_NullTrans.java
@@ -0,0 +1,273 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.env.test;
+
+import static org.junit.Assert.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.NullTrans;
+import org.onap.aaf.auth.env.AuthzTrans.REQD_TYPE;
+import org.onap.aaf.auth.org.Organization;
+import org.onap.aaf.cadi.Permission;
+import org.onap.aaf.misc.env.Decryptor;
+import org.onap.aaf.misc.env.Encryptor;
+import org.onap.aaf.misc.env.LogTarget;
+import org.onap.aaf.misc.env.Slot;
+import org.onap.aaf.misc.env.TimeTaken;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.security.Principal;
+import java.util.Date;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_NullTrans {
+ NullTrans nullTrans;
+
+ @Before
+ public void setUp(){
+ nullTrans = new NullTrans();
+ }
+
+ @Test
+ public void testAuditTrail() {
+ Assert.assertNull(nullTrans.auditTrail(0, null, 0));
+ }
+
+ @Test
+ public void testSingleton() {
+ AuthzTrans single = nullTrans.singleton();
+ Assert.assertTrue(single instanceof AuthzTrans);
+ }
+
+ @Test
+ public void testCheckpoints() {
+ nullTrans.checkpoint("Test");
+ nullTrans.checkpoint(null, 0);
+ }
+
+ @Test
+ public void testFatal() {
+ LogTarget log = nullTrans.fatal();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testError() {
+ LogTarget log = nullTrans.error();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testAudit() {
+ LogTarget log = nullTrans.audit();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testInit() {
+ LogTarget log = nullTrans.init();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testWarn() {
+ LogTarget log = nullTrans.warn();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testInfo() {
+ LogTarget log = nullTrans.info();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testDebug() {
+ LogTarget log = nullTrans.debug();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testTrace() {
+ LogTarget log = nullTrans.trace();
+ Assert.assertEquals(LogTarget.NULL, log);
+ }
+
+ @Test
+ public void testStart() {
+ TimeTaken test = nullTrans.start("test", 1);
+ StringBuilder sb = new StringBuilder();
+ test.output(sb);
+ StringBuilder sb1 = new StringBuilder();
+ sb1.append(test);
+ String s = sb.toString();
+ String s1 = sb1.toString();
+ s1 = s1.trim();
+ Assert.assertEquals(s,s1);
+ }
+
+ @Test
+ public void testSetProperty() {
+ String tag = "tag";
+ String value = "value";
+ nullTrans.setProperty(tag, value);
+ String expected = nullTrans.getProperty(tag, value);
+ Assert.assertEquals(expected, value);
+ String expectedTag = nullTrans.getProperty(tag);
+ Assert.assertEquals(expectedTag, tag);
+ }
+
+ @Test
+ public void testDecryptor() {
+ Decryptor decry = nullTrans.decryptor();
+ Assert.assertNull(decry);
+ }
+
+ @Test
+ public void testEncryptor() {
+ Encryptor encry = nullTrans.encryptor();
+ Assert.assertNull(encry);
+ }
+
+ @Test
+ public void testSet() {
+ HttpServletRequest req = mock(HttpServletRequest.class);
+ AuthzTrans set = nullTrans.set(req);
+ Assert.assertNull(set);
+ }
+
+ @Test
+ public void testUser() {
+ String user = nullTrans.user();
+ Assert.assertNull(user);
+ }
+
+ @Test
+ public void testGetUserPrincipal() {
+ Principal principal = nullTrans.getUserPrincipal();
+ Assert.assertNull(principal);
+ }
+
+ @Test
+ public void testIp() {
+ String ip = nullTrans.ip();
+ Assert.assertNull(ip);
+ }
+
+ @Test
+ public void testMeth() {
+ String meth = nullTrans.meth();
+ Assert.assertNull(meth);
+ }
+
+ @Test
+ public void testPort() {
+ int port = nullTrans.port();
+ Assert.assertEquals(port,0);
+ }
+
+ @Test
+ public void testPath() {
+ String path = nullTrans.path();
+ Assert.assertNull(path);
+ }
+
+ @Test
+ public void testPut() {
+ nullTrans.put(null, nullTrans);
+ }
+
+ @Test
+ public void testSetUser() {
+ Principal principal = mock(Principal.class);
+ //nullTrans.setUser(principal);
+ }
+
+ @Test
+ public void testSlot() {
+ Slot slot = nullTrans.slot(null);
+ Assert.assertNull(slot);
+ }
+
+ @Test
+ public void testEnv() {
+ AuthzEnv env = nullTrans.env();
+ Assert.assertNull(env);
+ }
+
+ @Test
+ public void testAgent() {
+ String agent = nullTrans.agent();
+ Assert.assertNull(agent);
+ }
+
+ @Test
+ public void testSetLur() {
+ nullTrans.setLur(null);
+ }
+
+ @Test
+ public void testFish() {
+ Permission perm = mock(Permission.class);
+ Boolean fish = nullTrans.fish(perm);
+ Assert.assertFalse(fish);
+ }
+
+ @Test
+ public void testOrg() {
+ Organization org = nullTrans.org();
+ Assert.assertEquals(Organization.NULL, org);
+ }
+
+ @Test
+ public void testLogAuditTrail() {
+ LogTarget lt = mock(LogTarget.class);
+ nullTrans.logAuditTrail(lt);
+ }
+
+ @Test
+ public void testRequested() {
+ Boolean reqd = nullTrans.requested(null);
+ Assert.assertFalse(reqd);
+ nullTrans.requested(null, true);
+ }
+
+ @Test
+ public void testNow() {
+ Date date = new Date();
+ Assert.assertEquals(date,nullTrans.now());
+ //when(nullTrans.now()).thenReturn(null);
+ }
+
+
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java
new file mode 100644
index 00000000..fc812a2c
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/test/JU_Result.java
@@ -0,0 +1,58 @@
+/**
+ * ============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.auth.layer.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.aaf.auth.layer.Result;
+
+public class JU_Result {
+ Result result;
+// @Mock
+// RV value;
+ int status=0;
+ String details = "details";
+ String[] variables;
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Before
+ public void setUp(){
+ //TODO: Gabe [JUnit] Not visible for junit
+ //result = new Result(result, status, details, variables);
+ }
+
+// @Test
+// public void testPartialContent() {
+// Result Res = result.partialContent(true);
+// System.out.println("Res" +Res);
+// assertEquals(details,Res.toString());
+//
+// }
+
+ @Test
+ public void netYetTested() {
+ fail("Tests not yet implemented");
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_DataFile.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_DataFile.java
new file mode 100644
index 00000000..a7ea2953
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_DataFile.java
@@ -0,0 +1,70 @@
+/**
+ * ============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.auth.local.test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import static org.junit.Assert.*;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.onap.aaf.auth.local.DataFile;
+import org.onap.aaf.auth.local.DataFile.Token;
+import org.onap.aaf.auth.local.DataFile.Token.Field;
+
+public class JU_DataFile {
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ @Test
+ public void netYetTested() {
+ fail("Tests not yet implemented");
+ }
+
+// @Test
+// public void test() throws Exception {
+// File file = new File("../authz-batch/data/v1.dat");
+// DataFile df = new DataFile(file,"r");
+// int count = 0;
+// List<String> list = new ArrayList<String>();
+// try {
+// df.open();
+// Token tok = df.new Token(1024000);
+// Field fld = tok.new Field('|');
+//
+// while(tok.nextLine()) {
+// ++count;
+// fld.reset();
+// list.add(fld.at(0));
+// }
+//// Collections.sort(list);
+// for(String s: list) {
+// System.out.println(s);
+//
+// }
+// } finally {
+// System.out.printf("%15s:%12d\n","Total",count);
+// }
+// }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_TextIndex.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_TextIndex.java
new file mode 100644
index 00000000..613d2a80
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_TextIndex.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.local.test;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.local.DataFile;
+import org.onap.aaf.auth.local.TextIndex;
+import org.onap.aaf.misc.env.TimeTaken;
+import org.onap.aaf.misc.env.Trans;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_TextIndex {
+ TextIndex textIndex;
+ Trans trans;
+ DataFile datefile;
+ @Mock
+ File file;
+
+ @Before
+ public void setUp() throws IOException{ //TODO: AAF-111 fix once actual input is known.
+ char character = 'a';
+ String filePath = "test/output_key";
+ File keyfile = new File(filePath);
+ FileOutputStream is = new FileOutputStream(keyfile);
+ OutputStreamWriter osw = new OutputStreamWriter(is);
+ Writer w = new BufferedWriter(osw);
+ w.write("asdfasdfasdf");
+ w.close();
+ datefile = new DataFile(keyfile, "test");
+ trans = mock(Trans.class);
+ textIndex = new TextIndex(keyfile);
+ //textIndex.create(trans, datefile, 20, character, 2, 2);
+ keyfile.delete();
+ }
+
+ @Test
+ public void testOpen() throws IOException {
+ //textIndex.open();
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java
new file mode 100644
index 00000000..01b8256f
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationException.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.org.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.aaf.auth.org.OrganizationException;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class JU_OrganizationException {
+
+ OrganizationException organizationException;
+
+ @Before
+ public void setUp(){
+ organizationException = new OrganizationException();
+ }
+
+
+ @Test
+ public void test() {
+ assertTrue(true);
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java
new file mode 100644
index 00000000..2136e786
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/org/test/JU_OrganizationFactory.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.org.test;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import static org.mockito.Mockito.mock;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.org.OrganizationException;
+import org.onap.aaf.auth.org.OrganizationFactory;
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.env.impl.BasicEnv;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class JU_OrganizationFactory {
+ private static final String ORG_SLOT = null;
+ OrganizationFactory organizationFactory;
+ BasicEnv bEnv;
+ @Mock
+ AuthzEnv authzEnvMock;
+ String orgClass="orgclass";
+ String orgNS="orgns";
+ @Before
+ public void setUp(){
+ organizationFactory = new OrganizationFactory();
+ bEnv = new BasicEnv();
+ }
+
+ @SuppressWarnings("static-access")
+ @Test(expected = APIException.class)
+ public void testInit() throws OrganizationException {
+ organizationFactory.init(bEnv);
+ }
+
+// @SuppressWarnings("static-access") TODO:Fix this AAF-111
+// @Test(expected = OrganizationException.class)
+// public void testObtain() throws OrganizationException{
+// PowerMockito.when(authzEnvMock.getProperty("Organization."+orgNS)).thenReturn("notnull");
+// organizationFactory.obtain(authzEnvMock, orgNS);
+// }
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/CredCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/CredCompare.java
new file mode 100644
index 00000000..cac26a88
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/CredCompare.java
@@ -0,0 +1,64 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.*;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.CredRequest;
+
+public class CredCompare extends RosettaCompare<CredRequest> {
+ public CredCompare() {
+ super(CredRequest.class);
+ }
+
+ public static CredRequest create() {
+ CredRequest rr = new CredRequest();
+ String in = instance();
+ rr.setId("m888"+ in + "@ns.att.com");
+ rr.setPassword("Bogus0"+in);
+ rr.setType(200);
+ GregorianCalendar gc = new GregorianCalendar();
+ rr.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ rr.setEnd(Chrono.timeStamp(gc));
+ return rr;
+ }
+
+ @Override
+ public void compare(CredRequest t1, CredRequest t2) {
+ assertEquals(t1.getId(),t2.getId());
+ assertEquals(t1.getPassword(),t2.getPassword());
+ assertEquals(t1.getType(),t2.getType());
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+
+
+ @Override
+ public CredRequest newOne() {
+ return create();
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/JU_RequestCheck.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/JU_RequestCheck.java
new file mode 100644
index 00000000..38bd51fc
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/JU_RequestCheck.java
@@ -0,0 +1,42 @@
+/**
+ * ============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.auth.request.test;
+
+import org.junit.Test;
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.rosetta.env.RosettaEnv;
+
+public class JU_RequestCheck {
+
+ @Test
+ public void testNSRequest() throws APIException {
+ RosettaEnv env = new RosettaEnv();
+ new NSCompare().run(env);
+ new NSAttribCompare().run(env);
+ new RoleCompare().run(env);
+ new PermCompare().run(env);
+ new CredCompare().run(env);
+ new UserRoleCompare().run(env);
+ new RolePermCompare().run(env);
+ new MultiCompare().run(env);
+ };
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/MultiCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/MultiCompare.java
new file mode 100644
index 00000000..5450bf55
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/MultiCompare.java
@@ -0,0 +1,69 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.MultiRequest;
+
+public class MultiCompare extends RosettaCompare<MultiRequest> {
+ public MultiCompare() {
+ super(MultiRequest.class);
+ }
+
+ @Override
+ public MultiRequest newOne() {
+ MultiRequest multi = new MultiRequest();
+ multi.setNsRequest(NSCompare.create());
+ multi.getNsAttribRequest().add(NSAttribCompare.create());
+ multi.getNsAttribRequest().add(NSAttribCompare.create());
+ multi.getRoleRequest().add(RoleCompare.create());
+ multi.getRoleRequest().add(RoleCompare.create());
+ multi.getPermRequest().add(PermCompare.create());
+ multi.getPermRequest().add(PermCompare.create());
+ multi.getCredRequest().add(CredCompare.create());
+ multi.getCredRequest().add(CredCompare.create());
+ multi.getUserRoleRequest().add(UserRoleCompare.create());
+ multi.getUserRoleRequest().add(UserRoleCompare.create());
+ multi.getRolePermRequest().add(RolePermCompare.create());
+ multi.getRolePermRequest().add(RolePermCompare.create());
+
+
+ GregorianCalendar gc = new GregorianCalendar();
+ multi.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ multi.setEnd(Chrono.timeStamp(gc));
+ return multi;
+ }
+
+ public void compare(MultiRequest t1, MultiRequest t2) {
+ new NSCompare().compare(t1.getNsRequest(), t2.getNsRequest());
+ // Will have to find by key for others.
+
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSAttribCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSAttribCompare.java
new file mode 100644
index 00000000..9f6ce21e
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSAttribCompare.java
@@ -0,0 +1,93 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.NsAttribRequest;
+import aaf.v2_0.NsAttribRequest.Attrib;
+
+public class NSAttribCompare extends RosettaCompare<NsAttribRequest> {
+ public NSAttribCompare() {
+ super(NsAttribRequest.class);
+ }
+
+ public static NsAttribRequest create() {
+ NsAttribRequest nar = new NsAttribRequest();
+ String in = instance();
+
+ nar.setNs("org.osaaf.ns"+in);
+ Attrib attrib = new Attrib();
+ attrib.setKey("swm");
+ attrib.setValue("v"+instance());
+ nar.getAttrib().add(attrib);
+ attrib = new Attrib();
+ attrib.setKey("scamp");
+ attrib.setValue("v"+instance());
+ nar.getAttrib().add(attrib);
+ GregorianCalendar gc = new GregorianCalendar();
+ nar.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ nar.setEnd(Chrono.timeStamp(gc));
+ return nar;
+ }
+
+ @Override
+ public void compare(NsAttribRequest t1, NsAttribRequest t2) {
+ assertEquals(t1.getNs(),t2.getNs());
+ for(Attrib a1 : t1.getAttrib()) {
+ boolean ok = false;
+ for(Attrib a2 : t2.getAttrib()) {
+ if(a1.getKey().equals(a2.getKey()) &&
+ a1.getValue().equals(a2.getValue())) {
+ ok = true;
+ break;
+ }
+ }
+ assertTrue("a2 Attribs in a1",ok);
+ }
+ for(Attrib a2 : t2.getAttrib()) {
+ boolean ok = false;
+ for(Attrib a1 : t1.getAttrib()) {
+ if(a1.getKey().equals(a2.getKey()) &&
+ a1.getValue().equals(a2.getValue())) {
+ ok = true;
+ break;
+ }
+ }
+ assertTrue("a2 Attribs in a1",ok);
+ }
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+
+
+ @Override
+ public NsAttribRequest newOne() {
+ return create();
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSCompare.java
new file mode 100644
index 00000000..b7fc28cc
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/NSCompare.java
@@ -0,0 +1,75 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.NsRequest;
+
+public class NSCompare extends RosettaCompare<NsRequest> {
+ public NSCompare() {
+ super(NsRequest.class);
+ }
+
+ public static NsRequest create() {
+ NsRequest nsr = new NsRequest();
+ String in = instance();
+ nsr.setName("org.osaaf.ns"+in);
+ nsr.setDescription("Hello World"+in);
+ nsr.getAdmin().add("Fred"+in);
+ nsr.getAdmin().add("Barney"+in);
+ nsr.getResponsible().add("Wilma"+in);
+ nsr.getResponsible().add("Betty"+in);
+ nsr.setType("Hello"+in);
+ GregorianCalendar gc = new GregorianCalendar();
+ nsr.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ nsr.setEnd(Chrono.timeStamp(gc));
+ return nsr;
+ }
+
+ @Override
+ public void compare(NsRequest t1, NsRequest t2) {
+ assertEquals(t1.getName(),t2.getName());
+ assertEquals(t1.getDescription(),t2.getDescription());
+ for(String s : t1.getAdmin()) {
+ assertTrue(t2.getAdmin().contains(s));
+ }
+ for(String s : t2.getAdmin()) {
+ assertTrue(t1.getAdmin().contains(s));
+ }
+ assertEquals(t1.getType(),t2.getType());
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+
+
+ @Override
+ public NsRequest newOne() {
+ return create();
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/PermCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/PermCompare.java
new file mode 100644
index 00000000..3d9a9fdb
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/PermCompare.java
@@ -0,0 +1,66 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.*;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.PermRequest;
+
+public class PermCompare extends RosettaCompare<PermRequest> {
+ public PermCompare() {
+ super(PermRequest.class);
+ }
+
+ public static PermRequest create() {
+ PermRequest pr = new PermRequest();
+ String in = instance();
+ pr.setType("org.osaaf.ns.perm"+in);
+ pr.setInstance("instance"+in);
+ pr.setAction("read");
+ pr.setDescription("Hello World, Perm"+in);
+ GregorianCalendar gc = new GregorianCalendar();
+ pr.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ pr.setEnd(Chrono.timeStamp(gc));
+ return pr;
+ }
+
+ @Override
+ public void compare(PermRequest t1, PermRequest t2) {
+ assertEquals(t1.getType(),t2.getType());
+ assertEquals(t1.getInstance(),t2.getInstance());
+ assertEquals(t1.getAction(),t2.getAction());
+ assertEquals(t1.getDescription(),t2.getDescription());
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+
+
+ @Override
+ public PermRequest newOne() {
+ return create();
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RoleCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RoleCompare.java
new file mode 100644
index 00000000..35bd3370
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RoleCompare.java
@@ -0,0 +1,62 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.*;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.RoleRequest;
+
+public class RoleCompare extends RosettaCompare<RoleRequest> {
+ public RoleCompare() {
+ super(RoleRequest.class);
+ }
+
+ public static RoleRequest create() {
+ RoleRequest rr = new RoleRequest();
+ String in = instance();
+ rr.setName("org.osaaf.ns.role"+in);
+ rr.setDescription("Hello World, Role"+in);
+ GregorianCalendar gc = new GregorianCalendar();
+ rr.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ rr.setEnd(Chrono.timeStamp(gc));
+ return rr;
+ }
+
+ @Override
+ public void compare(RoleRequest t1, RoleRequest t2) {
+ assertEquals(t1.getName(),t2.getName());
+ assertEquals(t1.getDescription(),t2.getDescription());
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+
+
+ @Override
+ public RoleRequest newOne() {
+ return create();
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RolePermCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RolePermCompare.java
new file mode 100644
index 00000000..d6ea98b9
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RolePermCompare.java
@@ -0,0 +1,69 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.Pkey;
+import aaf.v2_0.RolePermRequest;
+
+public class RolePermCompare extends RosettaCompare<RolePermRequest> {
+ public RolePermCompare() {
+ super(RolePermRequest.class);
+ }
+
+ public static RolePermRequest create() {
+ RolePermRequest urr = new RolePermRequest();
+ String in = instance();
+ urr.setRole("org.osaaf.ns.role"+in);
+ Pkey pkey = new Pkey();
+ pkey.setType("org.osaaf.ns.myType"+in);
+ pkey.setInstance("myInstance"+in);
+ pkey.setAction("myAction"+in);
+ urr.setPerm(pkey);
+ GregorianCalendar gc = new GregorianCalendar();
+ urr.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ urr.setEnd(Chrono.timeStamp(gc));
+ return urr;
+ }
+
+ @Override
+ public void compare(RolePermRequest t1, RolePermRequest t2) {
+ assertEquals(t1.getRole(),t2.getRole());
+ assertEquals(t1.getPerm().getType(),t1.getPerm().getType());
+ assertEquals(t1.getPerm().getInstance(),t1.getPerm().getInstance());
+ assertEquals(t1.getPerm().getAction(),t1.getPerm().getAction());
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+
+
+ @Override
+ public RolePermRequest newOne() {
+ return create();
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RosettaCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RosettaCompare.java
new file mode 100644
index 00000000..5130f8cb
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/RosettaCompare.java
@@ -0,0 +1,66 @@
+/**
+ * ============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.auth.request.test;
+
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.env.Data;
+import org.onap.aaf.misc.env.Data.TYPE;
+import org.onap.aaf.misc.rosetta.env.RosettaDF;
+import org.onap.aaf.misc.rosetta.env.RosettaData;
+import org.onap.aaf.misc.rosetta.env.RosettaEnv;
+
+public abstract class RosettaCompare<T> {
+ protected Class<T> cls;
+ private static int count = 0;
+
+ public RosettaCompare(Class<T> cls) {
+ this.cls = cls;
+ }
+
+ public void run(RosettaEnv env) throws APIException {
+ RosettaDF<T> nsrDF = env.newDataFactory(cls);
+ compare(nsrDF.newData().option(Data.PRETTY),newOne(),this);
+ }
+
+ private void compare(RosettaData<T> rdt, T t, RosettaCompare<T> comp) throws APIException {
+ System.out.println("########### Testing " + cls.getName() + " ##############");
+ String s = rdt.load(t).out(TYPE.JSON).asString();
+ System.out.println(s);
+ T t2 = rdt.in(TYPE.JSON).load(s).asObject();
+ comp.compare(t, t2);
+
+ System.out.println();
+
+ s = rdt.load(t).out(TYPE.XML).asString();
+ System.out.println(s);
+ t2 = rdt.in(TYPE.XML).load(s).asObject();
+ comp.compare(t, t2);
+ }
+
+ public synchronized static String instance() {
+ return "_"+ ++count;
+ }
+
+ public abstract void compare(T t1, T t2);
+ public abstract T newOne();
+
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/UserRoleCompare.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/UserRoleCompare.java
new file mode 100644
index 00000000..542ddeb7
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/request/test/UserRoleCompare.java
@@ -0,0 +1,62 @@
+/**
+ * ============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.auth.request.test;
+
+import static junit.framework.Assert.*;
+
+import java.util.GregorianCalendar;
+
+import org.onap.aaf.misc.env.util.Chrono;
+
+import aaf.v2_0.UserRoleRequest;
+
+public class UserRoleCompare extends RosettaCompare<UserRoleRequest> {
+ public UserRoleCompare() {
+ super(UserRoleRequest.class);
+ }
+
+ public static UserRoleRequest create() {
+ UserRoleRequest urr = new UserRoleRequest();
+ String in = instance();
+ urr.setUser("m125"+in + "@ns.att.com");
+ urr.setRole("org.osaaf.ns.role"+in);
+ GregorianCalendar gc = new GregorianCalendar();
+ urr.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 1);
+ urr.setEnd(Chrono.timeStamp(gc));
+ return urr;
+ }
+
+ @Override
+ public void compare(UserRoleRequest t1, UserRoleRequest t2) {
+ assertEquals(t1.getUser(),t2.getUser());
+ assertEquals(t1.getRole(),t2.getRole());
+ assertEquals(t1.getStart(),t2.getStart());
+ assertEquals(t1.getEnd(),t2.getEnd());
+ }
+
+
+ @Override
+ public UserRoleRequest newOne() {
+ return create();
+ }
+} \ No newline at end of file
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch.java
new file mode 100644
index 00000000..af1d289e
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aaf.auth.rserv.Match;
+import org.onap.aaf.misc.env.Env;
+import org.onap.aaf.misc.env.TimeTaken;
+import org.onap.aaf.misc.env.Trans;
+import org.onap.aaf.misc.env.impl.EnvFactory;
+
+
+public class JU_BetterMatch {
+
+ @Test
+ public void test() {
+ Trans trans = EnvFactory.newTrans();
+ // Bad Match
+ Match bm = new Match("/req/1.0.0/:var");
+
+ assertTrue(bm.match("/req/1.0.0/fred"));
+ assertTrue(bm.match("/req/1.0.0/wilma"));
+ assertTrue(bm.match("/req/1.0.0/wilma/"));
+ assertFalse(bm.match("/req/1.0.0/wilma/bambam"));
+ assertFalse(bm.match("/not/valid/234"));
+ assertFalse(bm.match(""));
+
+ TimeTaken tt = trans.start("A", Env.SUB);
+ TimeTaken tt2;
+ int i = 0;
+ try {
+ bm = new Match(null);
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match(""));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match(null));
+ tt2.done();
+ } finally {
+ tt.done();
+ }
+
+
+ tt = trans.start("B", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("/req/1.0.0/:urn/:ref");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/x"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/xyx"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("C", Env.SUB);
+ i = 0;
+ try {
+ String url = "/req/1.0.0/";
+ bm = new Match(url+":urn*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ String value = "urn:fsdb,1.0,req,newreq/0x12345";
+
+ assertTrue(bm.match(url+value));
+ assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("D", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("/req/1.0.0/:urn/:ref*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("E", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("this*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("this"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("thisandthat"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("F", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("<pass>/this"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ StringBuilder sb = new StringBuilder();
+ trans.auditTrail(0, sb);
+ System.out.println(sb);
+
+ }
+
+ @Test
+ public void specialTest() {
+ Match match = new Match("/sample");
+ assertTrue(match.match("/sample"));
+
+ match = new Match("/lpeer//lpeer/:key/:item*");
+ assertTrue(match.match("/lpeer//lpeer/x/y"));
+ assertFalse(match.match("/lpeer/x/lpeer/x/y"));
+
+ }
+
+ @Test
+ public void testGetParamNames() {
+ Match bm = new Match("/req/1.0.0/:var");
+ Set s = bm.getParamNames();
+ Assert.assertNotNull(s);
+ }
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch1.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch1.java
new file mode 100644
index 00000000..e104009a
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterMatch1.java
@@ -0,0 +1,164 @@
+/**
+ * ============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.auth.rserv.test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.aaf.auth.rserv.Match;
+import org.onap.aaf.misc.env.Env;
+import org.onap.aaf.misc.env.TimeTaken;
+import org.onap.aaf.misc.env.Trans;
+import org.onap.aaf.misc.env.impl.EnvFactory;
+
+
+public class JU_BetterMatch1 {
+
+ @Test
+ public void test() {
+ Trans trans = EnvFactory.newTrans();
+ // Bad Match
+ Match bm = new Match("/req/1.0.0/:var");
+
+ assertTrue(bm.match("/req/1.0.0/fred"));
+ assertTrue(bm.match("/req/1.0.0/wilma"));
+ assertTrue(bm.match("/req/1.0.0/wilma/"));
+ assertFalse(bm.match("/req/1.0.0/wilma/bambam"));
+ assertFalse(bm.match("/not/valid/234"));
+ assertFalse(bm.match(""));
+
+ TimeTaken tt = trans.start("A", Env.SUB);
+ TimeTaken tt2;
+ int i = 0;
+ try {
+ bm = new Match(null);
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match(""));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match(null));
+ tt2.done();
+ } finally {
+ tt.done();
+ }
+
+
+ tt = trans.start("B", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("/req/1.0.0/:urn/:ref");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/x"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/xyx"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("C", Env.SUB);
+ i = 0;
+ try {
+ String url = "/req/1.0.0/";
+ bm = new Match(url+":urn*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ String value = "urn:fsdb,1.0,req,newreq/0x12345";
+
+ assertTrue(bm.match(url+value));
+ assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("D", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("/req/1.0.0/:urn/:ref*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("E", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("this*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("this"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("thisandthat"));
+ tt2.done();
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ tt = trans.start("F", Env.SUB);
+ i = 0;
+ try {
+ bm = new Match("*");
+ tt2 = trans.start(Integer.toString(++i), Env.SUB);
+ assertTrue(bm.match("whatever/this"));
+ } finally {
+ tt2.done();
+ tt.done();
+ }
+
+ StringBuilder sb = new StringBuilder();
+ trans.auditTrail(0, sb);
+ System.out.println(sb);
+
+ }
+
+ @Test
+ public void specialTest() {
+ Match match = new Match("/sample");
+ assertTrue(match.match("/sample"));
+
+ match = new Match("/lpeer//lpeer/:key/:item*");
+ assertTrue(match.match("/lpeer//lpeer/x/y"));
+ assertFalse(match.match("/lpeer/x/lpeer/x/y"));
+
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterRoute.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterRoute.java
new file mode 100644
index 00000000..d98cf5ce
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_BetterRoute.java
@@ -0,0 +1,33 @@
+/**
+ * ============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.auth.rserv.test;
+
+import org.junit.Test;
+
+public class JU_BetterRoute {
+
+ @Test
+ public void test() {
+
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java
new file mode 100644
index 00000000..26e9717f
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CachingFileAccess.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.*;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.lang.reflect.Field;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.NavigableMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.mockito.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.aaf.auth.rserv.CachingFileAccess;
+import org.onap.aaf.auth.rserv.HttpCode;
+import org.onap.aaf.auth.rserv.Match;
+
+//import org.onap.aaf.auth.rserv.CachingFileAccess.Content;
+import java.util.NavigableMap;
+import org.onap.aaf.misc.env.EnvJAXB;
+import org.onap.aaf.misc.env.LogTarget;
+import org.onap.aaf.misc.env.StaticSlot;
+import org.onap.aaf.misc.env.Store;
+import org.onap.aaf.misc.env.Trans;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import junit.framework.Assert;
+
+
+@RunWith(PowerMockRunner.class)
+public class JU_CachingFileAccess {
+ CachingFileAccess cachingFileAccess;
+ HttpCode httpCode;
+ EnvJAXB envJ;
+ Trans trans;
+
+
+ @Before
+ public void setUp() throws IOException{
+ trans = mock(Trans.class);
+ HttpCode hCode = mock(HttpCode.class);
+ envJ = mock(EnvJAXB.class);
+ LogTarget log = mock(LogTarget.class);
+ Long lng = (long) 1234134;
+ when(envJ.get(envJ.staticSlot("aaf_cfa_cache_check_interval"),600000L)).thenReturn(lng);
+ when(envJ.get(envJ.staticSlot("aaf_cfa_max_size"), 512000)).thenReturn(512000);
+ when(envJ.get(envJ.staticSlot("aaf_cfa_web_path"))).thenReturn("TEST");
+ when(envJ.getProperty("aaf_cfa_clear_command",null)).thenReturn("null");
+ when(envJ.init()).thenReturn(log);
+ doNothing().when(log).log((String)any());
+ cachingFileAccess = new CachingFileAccess(envJ,"test");
+
+
+
+ }
+
+ @Test
+ public void testSetEnv() {
+ Store store = mock(Store.class);
+ Store store1 = mock(Store.class);
+ Store store2 = mock(Store.class);
+ String test[] = {"aaf_cfa_web_path","aaf_cfa_cache_check_interval","aaf_cfa_max_size"};
+ String test1[] = {"aaf_cfa_cache_check_interval"};
+ String test2[] = {"aaf_cfa_max_size"};
+ cachingFileAccess.setEnv(store, test);
+ cachingFileAccess.setEnv(store1, test1); //These don't reach all the branches for some reason
+ cachingFileAccess.setEnv(store2, test2);
+ }
+
+ @Test
+ public void testHandle() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ HttpServletRequest req = mock(HttpServletRequest.class);
+ Trans trans = mock(Trans.class);
+ HttpServletResponse resp = mock(HttpServletResponse.class);
+ when(req.getPathInfo()).thenReturn("path/to/file");
+
+ Field matchField = HttpCode.class.getDeclaredField("match");
+ matchField.setAccessible(true);
+ Match match = mock(Match.class);
+ when(match.param(anyString(), anyString())).thenReturn("null/");
+ matchField.set(cachingFileAccess, match);
+ cachingFileAccess.handle(trans, req, resp);
+ when(match.param(anyString(), anyString())).thenReturn("clear");
+ cachingFileAccess.handle(trans, req, resp);
+ }
+
+ @Test
+ public void testWebPath() {
+ EnvJAXB envJ = mock(EnvJAXB.class);
+ String web_path_test = "TEST";
+ Assert.assertEquals(web_path_test, cachingFileAccess.webPath());
+ }
+
+ @Test
+ public void testCleanupParams() {
+ NavigableMap<String,org.onap.aaf.auth.rserv.Content> content = new ConcurrentSkipListMap<String,org.onap.aaf.auth.rserv.Content>();
+ cachingFileAccess.cleanupParams(50, 500); //TODO: find right input
+ }
+
+ @Test
+ public void testLoad() throws IOException {
+ cachingFileAccess.load(null, null, "1220227200L/1220227200L", null, 1320227200L );
+ String filePath = "test/output_key";
+ File keyfile = new File(filePath);
+ RandomAccessFile randFile = new RandomAccessFile (keyfile,"rw");
+
+ String dPath = "test/";
+ File directoryPath = new File(dPath);
+ directoryPath.mkdir();
+ cachingFileAccess.load(null, dPath, "-", null, -1);
+ randFile.setLength(1024 * 1024 * 8);
+ cachingFileAccess.load(null, filePath, "-", null, -1);
+ keyfile.delete();
+ directoryPath.delete();
+ String filePath1 = "test/output_key";
+ File keyfile1 = new File(filePath1);
+ keyfile1.createNewFile();
+ cachingFileAccess.load(null, filePath1, "-", "test", -1);
+ keyfile1.delete();
+ }
+
+ @Test
+ public void testLoadOrDefault() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException, InstantiationException {
+ String filePath = "test/output_key";
+ File keyfile = new File(filePath);
+ cachingFileAccess.loadOrDefault(trans, filePath, "-", null, null);
+ keyfile.delete();
+
+ Trans trans = mock(Trans.class);
+
+ String filePath1 = "test/output_key.txt";
+ //File keyfile1 = new File(filePath1);
+ doAnswer(new Answer<Void>() {
+ public Void answer(InvocationOnMock invocation) throws FileNotFoundException {
+ throw new FileNotFoundException();
+ }
+ }).when(trans).info();
+ //cachingFileAccess.loadOrDefault(trans, "bs", "also bs", "test", null); //TODO: Needs more testing AAF-111
+ //keyfile1.delete();
+ }
+
+ @Test
+ public void testInvalidate() {
+ //NavigableMap<String,org.onap.aaf.auth.rserv.Content> content = new ConcurrentSkipListMap<String,org.onap.aaf.auth.rserv.Content>();
+ //Content con = mock(Content.class);
+ //content.put("hello", con);
+ cachingFileAccess.invalidate("hello");
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CodeSetter.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CodeSetter.java
new file mode 100644
index 00000000..75d1df8f
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CodeSetter.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+//import org.onap.aaf.auth.rserv.CodeSetter;
+import org.onap.aaf.auth.rserv.Route;
+import org.onap.aaf.misc.env.Trans;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class JU_CodeSetter {
+ //TODO: Gabe [JUnit] Not visible for junit
+ //CodeSetter codeSetter;
+ @Mock
+ Trans transMock;
+ @Mock
+ HttpServletRequest reqMock;
+ @Mock
+ HttpServletResponse respMock;
+
+// @Before //TODO: Fix this AAF-111
+// public void setUp(){
+// codeSetter = new CodeSetter(transMock, reqMock, respMock);
+// }
+//
+// @SuppressWarnings("rawtypes")
+// @Mock
+// Route routeMock;
+//
+// @Test
+// public void testMatches() throws IOException, ServletException{
+// boolean result = codeSetter.matches(routeMock);
+// System.out.println("value of res " + codeSetter.matches(routeMock));
+// assertFalse(result);
+// }
+
+ @Test
+ public void netYetTested() {
+ fail("Tests not yet implemented");
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content.java
new file mode 100644
index 00000000..c2be2eb1
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content.java
@@ -0,0 +1,661 @@
+/**
+ * ============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.auth.rserv.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Test;
+import org.onap.aaf.auth.rserv.HttpCode;
+import org.onap.aaf.auth.rserv.TypedCode;
+import org.onap.aaf.misc.env.TransJAXB;
+import org.onap.aaf.misc.env.impl.EnvFactory;
+
+
+/**
+ * Test the functioning of the "Content" class, which holds, and routes to the right code based on Accept values
+ */
+public class JU_Content {
+
+
+ @Test
+ public void test() throws Exception {
+ final String BOOL = "Boolean";
+ final String XML = "XML";
+ TransJAXB trans = EnvFactory.newTrans();
+ try {
+ HttpCode<TransJAXB, String> cBool = new HttpCode<TransJAXB,String>(BOOL,"Standard String") {
+ @Override
+ public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) {
+ try {
+ resp.getOutputStream().write(context.getBytes());
+ } catch (IOException e) {
+ }
+ }
+ };
+
+ HttpCode<TransJAXB,String> cXML = new HttpCode<TransJAXB,String>(XML, "Standard String") {
+ @Override
+ public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) {
+ try {
+ resp.getOutputStream().write(context.getBytes());
+ } catch (IOException e) {
+ }
+ }
+ };
+
+ TypedCode<TransJAXB> ct = new TypedCode<TransJAXB>()
+ .add(cBool,"application/" + Boolean.class.getName()+"+xml;charset=utf8;version=1.1")
+ .add(cXML,"application/xml;q=.9");
+ String expected = "application/java.lang.Boolean+xml;charset=utf8;version=1.1,application/xml;q=0.9";
+ assertEquals(expected,ct.toString());
+
+ //BogusReq req = new BogusReq();
+ //expected = (expected);
+ //HttpServletResponse resp = new BogusResp();
+
+ assertNotNull("Same Content String and Accept String",ct.prep(trans,expected));
+
+ //expects Null (not run)
+ // A Boolean xml that must have charset utf8 and match version 1.2 or greater
+ expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.2");
+ assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected));
+
+ // Same with (too many) spaces
+ expected = (" application/java.lang.Boolean+xml ; charset = utf8 ; version = 1.2 ");
+ assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected));
+
+ //expects Null (not run)
+ expected = ("application/java.lang.Boolean+xml;charset=utf8;version=2.1");
+ assertNull("Major Versions not the same",ct.prep(trans,expected));
+
+ expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.0");
+ assertNotNull("Content Minor Version is greater than Accept Minor Version",ct.prep(trans,expected));
+
+ expected = "application/java.lang.Squid+xml;charset=utf8;version=1.0,application/xml;q=.9";
+ assertNotNull("2nd one will have to do...",ct.prep(trans,expected));
+
+ expected = "application/java.lang.Boolean+xml;charset=UTF8;version=1.0";
+ assertNotNull("Minor Charset in Caps acceptable",ct.prep(trans,expected));
+
+ // expects no run
+ expected="application/java.lang.Boolean+xml;charset=MyType;version=1.0";
+ assertNull("Unknown Minor Charset",ct.prep(trans,expected));
+
+ expected="";
+ assertNotNull("Blank Acceptance",ct.prep(trans,expected));
+
+ expected=null;
+ assertNotNull("Null Acceptance",ct.prep(trans,expected));
+
+ expected = ("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+ assertNotNull("Matches application/xml, and other content not known",ct.prep(trans,expected));
+
+ // No SemiColon
+ expected = ("i/am/bogus,application/xml");
+ assertNotNull("Match second entry, with no Semis",ct.prep(trans,expected));
+
+ } finally {
+ StringBuilder sb = new StringBuilder();
+ trans.auditTrail(0, sb);
+ System.out.println(sb);
+ }
+ }
+//
+// Original API used HTTPServletRequest and HTTPServletResponse. Due to the fact that sometimes we use Accept, and others Content-TYpe
+// I changed it to simply accept a string
+//
+// Jonathan 3/8/2013
+//
+// @SuppressWarnings("rawtypes")
+// class BogusReq implements HttpServletRequest {
+// private String accept;
+//
+// public void accept(String accept) {
+// this.accept = accept;
+// }
+//
+// @Override
+// public Object getAttribute(String name) {
+// return accept;
+// }
+//
+//
+// @Override
+// public Enumeration getAttributeNames() {
+// return null;
+// }
+//
+// @Override
+// public String getCharacterEncoding() {
+// return null;
+// }
+//
+// @Override
+// public void setCharacterEncoding(String env)
+// throws UnsupportedEncodingException {
+//
+//
+// }
+//
+// @Override
+// public int getContentLength() {
+//
+// return 0;
+// }
+//
+// @Override
+// public String getContentType() {
+//
+// return null;
+// }
+//
+// @Override
+// public ServletInputStream getInputStream() throws IOException {
+//
+// return null;
+// }
+//
+// @Override
+// public String getParameter(String name) {
+//
+// return null;
+// }
+//
+// @Override
+// public Enumeration getParameterNames() {
+//
+// return null;
+// }
+//
+// @Override
+// public String[] getParameterValues(String name) {
+//
+// return null;
+// }
+//
+// @Override
+// public Map getParameterMap() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getProtocol() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getScheme() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getServerName() {
+//
+// return null;
+// }
+//
+// @Override
+// public int getServerPort() {
+//
+// return 0;
+// }
+//
+// @Override
+// public BufferedReader getReader() throws IOException {
+//
+// return null;
+// }
+//
+// @Override
+// public String getRemoteAddr() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getRemoteHost() {
+//
+// return null;
+// }
+//
+// @Override
+// public void setAttribute(String name, Object o) {
+//
+//
+// }
+//
+// @Override
+// public void removeAttribute(String name) {
+//
+//
+// }
+//
+// @Override
+// public Locale getLocale() {
+//
+// return null;
+// }
+//
+// @Override
+// public Enumeration getLocales() {
+//
+// return null;
+// }
+//
+// @Override
+// public boolean isSecure() {
+//
+// return false;
+// }
+//
+// @Override
+// public RequestDispatcher getRequestDispatcher(String path) {
+//
+// return null;
+// }
+//
+// @Override
+// public String getRealPath(String path) {
+//
+// return null;
+// }
+//
+// @Override
+// public int getRemotePort() {
+//
+// return 0;
+// }
+//
+// @Override
+// public String getLocalName() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getLocalAddr() {
+//
+// return null;
+// }
+//
+// @Override
+// public int getLocalPort() {
+//
+// return 0;
+// }
+//
+// @Override
+// public String getAuthType() {
+//
+// return null;
+// }
+//
+// @Override
+// public Cookie[] getCookies() {
+//
+// return null;
+// }
+//
+// @Override
+// public long getDateHeader(String name) {
+//
+// return 0;
+// }
+//
+// @Override
+// public String getHeader(String name) {
+// return accept;
+// }
+//
+// @Override
+// public Enumeration getHeaders(String name) {
+//
+// return null;
+// }
+//
+// @Override
+// public Enumeration getHeaderNames() {
+//
+// return null;
+// }
+//
+// @Override
+// public int getIntHeader(String name) {
+//
+// return 0;
+// }
+//
+// @Override
+// public String getMethod() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getPathInfo() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getPathTranslated() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getContextPath() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getQueryString() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getRemoteUser() {
+//
+// return null;
+// }
+//
+// @Override
+// public boolean isUserInRole(String role) {
+//
+// return false;
+// }
+//
+// @Override
+// public Principal getUserPrincipal() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getRequestedSessionId() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getRequestURI() {
+//
+// return null;
+// }
+//
+// @Override
+// public StringBuffer getRequestURL() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getServletPath() {
+//
+// return null;
+// }
+//
+// @Override
+// public HttpSession getSession(boolean create) {
+//
+// return null;
+// }
+//
+// @Override
+// public HttpSession getSession() {
+//
+// return null;
+// }
+//
+// @Override
+// public boolean isRequestedSessionIdValid() {
+//
+// return false;
+// }
+//
+// @Override
+// public boolean isRequestedSessionIdFromCookie() {
+//
+// return false;
+// }
+//
+// @Override
+// public boolean isRequestedSessionIdFromURL() {
+//
+// return false;
+// }
+//
+// @Override
+// public boolean isRequestedSessionIdFromUrl() {
+//
+// return false;
+// }
+// }
+//
+// public class BogusResp implements HttpServletResponse {
+// public String contentType;
+//
+// @Override
+// public String getCharacterEncoding() {
+//
+// return null;
+// }
+//
+// @Override
+// public String getContentType() {
+// return contentType;
+// }
+//
+// @Override
+// public ServletOutputStream getOutputStream() throws IOException {
+//
+// return null;
+// }
+//
+// @Override
+// public PrintWriter getWriter() throws IOException {
+//
+// return null;
+// }
+//
+// @Override
+// public void setCharacterEncoding(String charset) {
+//
+//
+// }
+//
+// @Override
+// public void setContentLength(int len) {
+//
+//
+// }
+//
+// @Override
+// public void setContentType(String type) {
+// contentType = type;
+// }
+//
+// @Override
+// public void setBufferSize(int size) {
+//
+//
+// }
+//
+// @Override
+// public int getBufferSize() {
+//
+// return 0;
+// }
+//
+// @Override
+// public void flushBuffer() throws IOException {
+//
+//
+// }
+//
+// @Override
+// public void resetBuffer() {
+//
+//
+// }
+//
+// @Override
+// public boolean isCommitted() {
+//
+// return false;
+// }
+//
+// @Override
+// public void reset() {
+//
+//
+// }
+//
+// @Override
+// public void setLocale(Locale loc) {
+//
+//
+// }
+//
+// @Override
+// public Locale getLocale() {
+//
+// return null;
+// }
+//
+// @Override
+// public void addCookie(Cookie cookie) {
+//
+//
+// }
+//
+// @Override
+// public boolean containsHeader(String name) {
+//
+// return false;
+// }
+//
+// @Override
+// public String encodeURL(String url) {
+//
+// return null;
+// }
+//
+// @Override
+// public String encodeRedirectURL(String url) {
+//
+// return null;
+// }
+//
+// @Override
+// public String encodeUrl(String url) {
+//
+// return null;
+// }
+//
+// @Override
+// public String encodeRedirectUrl(String url) {
+//
+// return null;
+// }
+//
+// @Override
+// public void sendError(int sc, String msg) throws IOException {
+//
+//
+// }
+//
+// @Override
+// public void sendError(int sc) throws IOException {
+//
+//
+// }
+//
+// @Override
+// public void sendRedirect(String location) throws IOException {
+//
+//
+// }
+//
+// @Override
+// public void setDateHeader(String name, long date) {
+//
+//
+// }
+//
+// @Override
+// public void addDateHeader(String name, long date) {
+//
+//
+// }
+//
+// @Override
+// public void setHeader(String name, String value) {
+//
+//
+// }
+//
+// @Override
+// public void addHeader(String name, String value) {
+//
+//
+// }
+//
+// @Override
+// public void setIntHeader(String name, int value) {
+//
+//
+// }
+//
+// @Override
+// public void addIntHeader(String name, int value) {
+//
+//
+// }
+//
+// @Override
+// public void setStatus(int sc) {
+//
+//
+// }
+//
+// @Override
+// public void setStatus(int sc, String sm) {
+//
+//
+// }
+//
+// }
+//
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java
new file mode 100644
index 00000000..4d640d09
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Test;
+import org.onap.aaf.auth.rserv.HttpCode;
+import org.onap.aaf.auth.rserv.TypedCode;
+import org.onap.aaf.misc.env.TransJAXB;
+import org.onap.aaf.misc.env.impl.EnvFactory;
+
+
+/**
+ * Test the functioning of the "Content" class, which holds, and routes to the right code based on Accept values
+ */
+public class JU_Content1 {
+
+
+ @Test
+ public void test() throws Exception {
+ final String BOOL = "Boolean";
+ final String XML = "XML";
+ TransJAXB trans = EnvFactory.newTrans();
+ try {
+ HttpCode<TransJAXB, String> cBool = new HttpCode<TransJAXB,String>(BOOL,"Standard String") {
+ @Override
+ public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) {
+ try {
+ resp.getOutputStream().write(context.getBytes());
+ } catch (IOException e) {
+ }
+ }
+ };
+
+ HttpCode<TransJAXB,String> cXML = new HttpCode<TransJAXB,String>(XML, "Standard String") {
+ @Override
+ public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) {
+ try {
+ resp.getOutputStream().write(context.getBytes());
+ } catch (IOException e) {
+ }
+ }
+ };
+
+ TypedCode<TransJAXB> ct = new TypedCode<TransJAXB>()
+ .add(cBool,"application/" + Boolean.class.getName()+"+xml;charset=utf8;version=1.1")
+ .add(cXML,"application/xml;q=.9");
+ String expected = "application/java.lang.Boolean+xml;charset=utf8;version=1.1,application/xml;q=0.9";
+ assertEquals(expected,ct.toString());
+
+ //BogusReq req = new BogusReq();
+ //expected = (expected);
+ //HttpServletResponse resp = new BogusResp();
+
+ assertNotNull("Same Content String and Accept String",ct.prep(trans,expected));
+
+ //expects Null (not run)
+ // A Boolean xml that must have charset utf8 and match version 1.2 or greater
+ expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.2");
+ assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected));
+
+ // Same with (too many) spaces
+ expected = (" application/java.lang.Boolean+xml ; charset = utf8 ; version = 1.2 ");
+ assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected));
+
+ //expects Null (not run)
+ expected = ("application/java.lang.Boolean+xml;charset=utf8;version=2.1");
+ assertNull("Major Versions not the same",ct.prep(trans,expected));
+
+ expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.0");
+ assertNotNull("Content Minor Version is greater than Accept Minor Version",ct.prep(trans,expected));
+
+ expected = "application/java.lang.Squid+xml;charset=utf8;version=1.0,application/xml;q=.9";
+ assertNotNull("2nd one will have to do...",ct.prep(trans,expected));
+
+ expected = "application/java.lang.Boolean+xml;charset=UTF8;version=1.0";
+ assertNotNull("Minor Charset in Caps acceptable",ct.prep(trans,expected));
+
+ // expects no run
+ expected="application/java.lang.Boolean+xml;charset=MyType;version=1.0";
+ assertNull("Unknown Minor Charset",ct.prep(trans,expected));
+
+ expected="";
+ assertNotNull("Blank Acceptance",ct.prep(trans,expected));
+
+ expected=null;
+ assertNotNull("Null Acceptance",ct.prep(trans,expected));
+
+ expected = ("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+ assertNotNull("Matches application/xml, and other content not known",ct.prep(trans,expected));
+
+ // No SemiColon
+ expected = ("i/am/bogus,application/xml");
+ assertNotNull("Match second entry, with no Semis",ct.prep(trans,expected));
+
+ } finally {
+ StringBuilder sb = new StringBuilder();
+ trans.auditTrail(0, sb);
+ System.out.println(sb);
+ }
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Pair.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Pair.java
new file mode 100644
index 00000000..557c7ec5
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Pair.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aaf.auth.rserv.Pair;
+
+import junit.framework.Assert;
+
+public class JU_Pair {
+ Pair<Integer, Integer> pair;
+ Integer x;
+ Integer y;
+
+ @Before
+ public void setUp(){
+ pair = new Pair<Integer, Integer>(1, 2);
+ }
+
+ @Test
+ public void testToString() {
+ String result = pair.toString();
+ Assert.assertEquals("X: " + pair.x.toString() + "-->" + pair.y.toString(), result);
+ }
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Route.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Route.java
new file mode 100644
index 00000000..d5953b10
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Route.java
@@ -0,0 +1,38 @@
+package org.onap.aaf.auth.rserv.test;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.onap.aaf.auth.rserv.Route;
+import org.onap.aaf.misc.env.Trans;
+import org.onap.aaf.auth.rserv.*;
+
+public class JU_Route {
+ Route route;
+ HttpCode httpCode;
+ HttpMethods httpMethod;
+ Trans trans;
+
+ @Before
+ public void setUp() { //TODO: AAF-111 complete when actual input is provided
+ //httpMethod = Matchers.any(HttpMethods.class);
+ //when(httpMethod.name()).thenReturn("test");
+ // route = new Route(null,"path/to/place");
+ }
+
+
+ @Test
+ public void testAdd() {
+ // route.add(httpCode, "path/to/place");
+ }
+
+ @Test
+ public void testStart() {
+ // trans = mock(Trans.class);
+ // route.start(trans, "test", httpCode, "test");
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_RouteReport.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_RouteReport.java
new file mode 100644
index 00000000..a9fdff60
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_RouteReport.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.*;
+import org.onap.aaf.auth.rserv.RouteReport;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class JU_RouteReport {
+
+ @Test
+ public void test() {
+ RouteReport report;
+ report = new RouteReport();
+ Assert.assertNotNull(report);
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Routes.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Routes.java
new file mode 100644
index 00000000..2ed08841
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Routes.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import static org.mockito.Mockito.*;
+//import org.onap.aaf.auth.rserv.CodeSetter;
+import org.onap.aaf.auth.rserv.Route;
+import org.onap.aaf.auth.rserv.Routes;
+import org.onap.aaf.misc.env.Trans;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class JU_Routes {
+ Routes routes;
+ @Mock
+ HttpServletRequest reqMock;
+ //TODO: Gabe [JUnit] Not visible to junit
+ //CodeSetter<Trans> codeSetterMock;
+ Route<Trans> routeObj;
+
+ @Before
+ public void setUp(){
+ routes = new Routes();
+ }
+
+ @Test
+ public void testRouteReport(){
+ List listVal = routes.routeReport();
+ assertNotNull(listVal);
+ }
+
+ @Test
+ public void testDerive() throws IOException, ServletException{
+ routeObj = routes.derive(reqMock, null);
+
+ }
+
+
+
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_TypedCode.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_TypedCode.java
new file mode 100644
index 00000000..d5b57de0
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_TypedCode.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.*;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.anyString;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+//import org.onap.aaf.auth.rserv.Acceptor;
+import org.onap.aaf.auth.rserv.HttpCode;
+import org.onap.aaf.auth.rserv.HttpMethods;
+import org.onap.aaf.auth.rserv.RouteReport;
+import org.onap.aaf.auth.rserv.TypedCode;
+import org.onap.aaf.misc.env.TimeTaken;
+import org.onap.aaf.misc.env.Trans;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class JU_TypedCode {
+ TypedCode typedCode;
+ @Mock
+ RouteReport routeReportMock;
+
+ @Before
+ public void setUp(){
+ typedCode = new TypedCode();
+ }
+
+ @Test
+ public void testFirst(){
+ String returnVal = typedCode.first();
+ assertNull(returnVal);
+ }
+
+ @Test
+ public void testAdd() {
+ HttpCode<?, ?> code = mock(HttpCode.class);
+ typedCode.add(code , "test", "test1", "test2");
+ }
+
+ @Test
+ public void testPrep() throws IOException, ServletException, ClassNotFoundException {
+ Trans trans = mock(Trans.class);
+ TimeTaken time = new TimeTaken("yell", 2) {
+ @Override
+ public void output(StringBuilder sb) {
+ // TODO Auto-generated method stub
+ }
+ };
+ when(trans.start(";na=me;,prop", 8)).thenReturn(time);
+ HttpCode<?, ?> code = mock(HttpCode.class);
+ code.pathParam(null, null);
+ code.isAuthorized(null); //Testing httpcode, currently not working
+ code.no_cache();
+ code.toString();
+
+ typedCode.add(code , "");
+ typedCode.prep(null , "q");
+
+ typedCode.add(code , "t");
+ typedCode.prep(trans , null);
+
+ typedCode.add(code , "t");
+ typedCode.prep(trans , "");
+
+ typedCode.add(code, "POST /authn/validate application/CredRequest+json;charset=utf-8;version=2.0,application/json;version=2.0,*/*");
+ //typedCode.prep(trans , "POST /authn/validate application/CredRequest+json;charset=utf-8;version=2.0,application/json;version=2.0,*/*");
+ }
+
+ @Test
+ public void testRelatedTo() {
+ HttpCode<?, ?> code = mock(HttpCode.class);
+ StringBuilder sb = new StringBuilder();
+ typedCode.relatedTo(code, sb);
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Version.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Version.java
new file mode 100644
index 00000000..617fa259
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Version.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.rserv.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.onap.aaf.auth.rserv.Version;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class JU_Version {
+ Version version;
+ Version versionTest;
+
+
+ @Before
+ public void setUp(){
+ version = new Version("first\\.123");
+ versionTest = new Version("first\\.124");
+ }
+
+ @Test
+ public void testEquals(){
+ version.equals(versionTest);
+ versionTest.equals(version);
+ versionTest = new Version("fail\\.124");
+ version.equals(versionTest);
+ version.equals("This is not an object of version");
+ versionTest = new Version("NoVersion\\.number");
+ version.equals(versionTest);
+
+
+ }
+
+ @Test
+ public void testToString(){
+ String strVal = version.toString();
+ assertNotNull(strVal);
+ }
+
+ @Test
+ public void testHashCode() {
+ Assert.assertNotNull(version.hashCode());
+ }
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_JettyServiceStarter.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_JettyServiceStarter.java
new file mode 100644
index 00000000..463d558d
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_JettyServiceStarter.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.server.test;
+
+import static org.junit.Assert.*;
+
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.org.OrganizationException;
+import org.onap.aaf.auth.server.AbsService;
+import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.cadi.Access;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.LocatorException;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.register.Registrant;
+import org.onap.aaf.misc.env.Trans;
+import org.onap.aaf.misc.env.impl.BasicEnv;
+import org.onap.aaf.misc.rosetta.env.RosettaEnv;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.servlet.Filter;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+
+public class JU_JettyServiceStarter {
+ private PropAccess propAccess = new PropAccess();
+ private JettyServiceStarter<AuthzEnv,AuthzTrans> jss;
+ class TestService extends AbsService{
+
+ public TestService(Access access, BasicEnv env) throws CadiException {
+ super(access, env);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public Filter[] filters() throws CadiException, LocatorException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Registrant[] registrants(int port) throws CadiException, LocatorException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws OrganizationException, CadiException {
+ Access access = mock(Access.class);
+
+ BasicEnv bEnv = mock(BasicEnv.class);
+ Trans trans = mock(Trans.class); //TODO: Fix this once Gabe has services running to see correct output without mock
+ //TestService testService = new TestService(access, bEnv);
+ //jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(testService);
+ }
+
+ @Test
+ public void netYetTested() {
+ fail("Tests not yet implemented");
+ }
+
+ @Test
+ public void testPropertyAdjustment() {
+ //jss._propertyAdjustment();
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/util/test/JU_Mask.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/util/test/JU_Mask.java
new file mode 100644
index 00000000..535664bd
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/util/test/JU_Mask.java
@@ -0,0 +1,71 @@
+/**
+ * ============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.auth.util.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.net.InetAddress;
+
+import org.junit.Test;
+import org.onap.aaf.cadi.util.MaskFormatException;
+import org.onap.aaf.cadi.util.NetMask;
+
+import junit.framework.Assert;
+
+public class JU_Mask {
+
+ @Test
+ public void test() throws Exception {
+ InetAddress ia = InetAddress.getLocalHost();
+ NetMask mask = new NetMask(ia.getAddress());
+ assertTrue(mask.isInNet(ia.getAddress()));
+
+ mask = new NetMask("192.168.1/24");
+ assertTrue(mask.isInNet("192.168.1.20"));
+ assertTrue(mask.isInNet("192.168.1.255"));
+ assertFalse(mask.isInNet("192.168.2.20"));
+
+ mask = new NetMask("192.168.1/31");
+ assertFalse(mask.isInNet("192.168.2.20"));
+ assertFalse(mask.isInNet("192.168.1.20"));
+ assertTrue(mask.isInNet("192.168.1.1"));
+ assertFalse(mask.isInNet("192.168.1.2"));
+
+ mask = new NetMask("192/8");
+ assertTrue(mask.isInNet("192.168.1.1"));
+ assertTrue(mask.isInNet("192.1.1.1"));
+ assertFalse(mask.isInNet("193.168.1.1"));
+
+ mask = new NetMask("/0");
+ assertTrue(mask.isInNet("193.168.1.1"));
+
+ String msg = "Should throw " + MaskFormatException.class.getSimpleName();
+ try {
+ mask = new NetMask("256.256.256.256");
+ Assert.assertTrue(msg,false);
+ } catch (MaskFormatException e) {
+ Assert.assertTrue(msg,true);
+ }
+ }
+
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java
new file mode 100644
index 00000000..fb59a54d
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/validation/test/JU_Validator.java
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.auth.validation.test;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.regex.Pattern;
+
+import static org.mockito.Matchers.*;
+import org.mockito.Mock;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Test;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransOnlyFilter;
+import org.onap.aaf.auth.validation.Validator;
+import org.onap.aaf.cadi.principal.TaggedPrincipal;
+
+public class JU_Validator {
+
+ Validator validator;
+
+ @Before
+ public void setUp() {
+ validator = new Validator();
+ }
+
+ @Test
+ public void testNullOrBlank() {
+ validator.nullOrBlank(null, "str");
+ validator.nullOrBlank("test", "");
+ validator.nullOrBlank("test", null);
+ }
+
+ @Test
+ public void testIsNull() {
+ Object o = new Object();
+ validator.isNull(null, null);
+ validator.isNull(null, o);
+ }
+
+ @Test
+ public void testDescription() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Class c = validator.getClass();
+ Class[] cArg = new Class[2];
+ cArg[0] = String.class;
+ cArg[1] = String.class; //Steps to test a protected method
+ Method descriptionMethod = c.getDeclaredMethod("description", cArg);
+ descriptionMethod.setAccessible(true);
+ descriptionMethod.invoke(validator,"test", "test1");
+ descriptionMethod.invoke(validator,null, null);
+ descriptionMethod.invoke(validator,null, "[\\\\x25\\\\x28\\\\x29\\\\x2C-\\\\x2E\\\\x30-\\\\x39\\\\x3D\\\\x40-\\\\x5A\\\\x5F\\\\x61-\\\\x7A\\\\x20]+");
+
+
+ }
+
+ @Test
+ public void test() {
+ assertTrue(Validator.ACTION_CHARS.matcher("HowdyDoody").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("Howd?yDoody").matches());
+ assertTrue(Validator.ACTION_CHARS.matcher("_HowdyDoody").matches());
+ assertTrue(Validator.INST_CHARS.matcher("HowdyDoody").matches());
+ assertFalse(Validator.INST_CHARS.matcher("Howd?yDoody").matches());
+ assertTrue(Validator.INST_CHARS.matcher("_HowdyDoody").matches());
+
+ //
+ assertTrue(Validator.ACTION_CHARS.matcher("*").matches());
+ assertTrue(Validator.INST_CHARS.matcher("*").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(":*").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":*").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(":*:*").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":*:*").matches());
+
+ assertFalse(Validator.ACTION_CHARS.matcher(":hello").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":hello").matches());
+ assertFalse(Validator.INST_CHARS.matcher("hello:").matches());
+ assertFalse(Validator.INST_CHARS.matcher("hello:d").matches());
+
+ assertFalse(Validator.ACTION_CHARS.matcher(":hello:*").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":hello:*").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(":hello:d*:*").matches());
+ assertFalse(Validator.INST_CHARS.matcher(":hello:d*d:*").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":hello:d*:*").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("HowdyDoody*").matches());
+ assertFalse(Validator.INST_CHARS.matcher("Howdy*Doody").matches());
+ assertTrue(Validator.INST_CHARS.matcher("HowdyDoody*").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("*HowdyDoody").matches());
+ assertFalse(Validator.INST_CHARS.matcher("*HowdyDoody").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(":h*").matches());
+ assertFalse(Validator.INST_CHARS.matcher(":h*h*").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":h*").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(":h:h*:*").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":h:h*:*").matches());
+ assertFalse(Validator.INST_CHARS.matcher(":h:h*h:*").matches());
+ assertFalse(Validator.INST_CHARS.matcher(":h:h*h*:*").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(":h:*:*h").matches());
+ assertFalse(Validator.INST_CHARS.matcher(":h:*:*h").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":com.test.*:ns:*").matches());
+
+
+ assertFalse(Validator.ACTION_CHARS.matcher("1234+235gd").matches());
+ assertTrue(Validator.ACTION_CHARS.matcher("1234-235gd").matches());
+ assertTrue(Validator.ACTION_CHARS.matcher("1234-23_5gd").matches());
+ assertTrue(Validator.ACTION_CHARS.matcher("1234-235g,d").matches());
+ assertTrue(Validator.ACTION_CHARS.matcher("1234-235gd(Version12)").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("123#4-23@5g:d").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("123#4-23@5g:d").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("1234-23 5gd").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("1234-235gd ").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(" 1234-235gd").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(" ").matches());
+
+ // Allow % and = (Needed for Escaping & Base64 usages) jg
+ assertTrue(Validator.ACTION_CHARS.matcher("1234%235g=d").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher(":1234%235g=d").matches());
+ assertTrue(Validator.INST_CHARS.matcher("1234%235g=d").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":1234%235g=d").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":1234%235g=d:%20==").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":1234%235g=d:==%20:=%23").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":1234%235g=d:*:=%23").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":1234%235g=d:==%20:*").matches());
+ assertTrue(Validator.INST_CHARS.matcher(":*:==%20:*").matches());
+
+ // Allow / instead of : (more natural instance expression) jg
+ assertFalse(Validator.INST_CHARS.matcher("1234/a").matches());
+ assertTrue(Validator.INST_CHARS.matcher("/1234/a").matches());
+ assertTrue(Validator.INST_CHARS.matcher("/1234/*/a/").matches());
+ assertTrue(Validator.INST_CHARS.matcher("/1234//a").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("1234/a").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("/1234/*/a/").matches());
+ assertFalse(Validator.ACTION_CHARS.matcher("1234//a").matches());
+
+
+ assertFalse(Validator.INST_CHARS.matcher("1234+235gd").matches());
+ assertTrue(Validator.INST_CHARS.matcher("1234-235gd").matches());
+ assertTrue(Validator.INST_CHARS.matcher("1234-23_5gd").matches());
+ assertTrue(Validator.INST_CHARS.matcher("1234-235g,d").matches());
+ assertTrue(Validator.INST_CHARS.matcher("m1234@shb.dd.com").matches());
+ assertTrue(Validator.INST_CHARS.matcher("1234-235gd(Version12)").matches());
+ assertFalse(Validator.INST_CHARS.matcher("123#4-23@5g:d").matches());
+ assertFalse(Validator.INST_CHARS.matcher("123#4-23@5g:d").matches());
+ assertFalse(Validator.INST_CHARS.matcher("").matches());
+
+
+ for( char c=0x20;c<0x7F;++c) {
+ boolean b;
+ switch(c) {
+ case '?':
+ case '|':
+ case '*':
+ continue; // test separately
+ case '~':
+ case ',':
+ b = false;
+ break;
+ default:
+ b=true;
+ }
+ }
+
+ assertFalse(Validator.ID_CHARS.matcher("abc").matches());
+ assertFalse(Validator.ID_CHARS.matcher("").matches());
+ assertTrue(Validator.ID_CHARS.matcher("abc@att.com").matches());
+ assertTrue(Validator.ID_CHARS.matcher("ab-me@att.com").matches());
+ assertTrue(Validator.ID_CHARS.matcher("ab-me_.x@att._-com").matches());
+
+ assertFalse(Validator.NAME_CHARS.matcher("ab-me_.x@att._-com").matches());
+ assertTrue(Validator.NAME_CHARS.matcher("ab-me").matches());
+ assertTrue(Validator.NAME_CHARS.matcher("ab-me_.xatt._-com").matches());
+
+
+ // 7/22/2016
+ assertTrue(Validator.INST_CHARS.matcher(
+ "/!com.att.*/role/write").matches());
+ assertTrue(Validator.INST_CHARS.matcher(
+ ":!com.att.*:role:write").matches());
+
+ }
+
+}