summaryrefslogtreecommitdiffstats
path: root/auth/auth-core/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'auth/auth-core/src/test')
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java10
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_AbsData.java115
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_TextIndex.java90
-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/server/test/JU_AbsService.java114
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java149
6 files changed, 463 insertions, 88 deletions
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
index 8630aadf..b30085fc 100644
--- 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
@@ -25,12 +25,15 @@ import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import org.junit.*;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
-import java.io.ByteArrayOutputStream;
import java.util.Properties;
-
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.onap.aaf.auth.env.AuthzEnv;
import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.PropAccess;
@@ -39,9 +42,9 @@ import org.onap.aaf.cadi.config.Config;
public class JU_AuthzEnv {
AuthzEnv authzEnv;
-
ByteArrayOutputStream outStream;
ByteArrayOutputStream errStream;
+ enum Level {DEBUG, INFO, AUDIT, INIT, WARN, ERROR};
@Before
public void setUp() {
@@ -142,6 +145,7 @@ public class JU_AuthzEnv {
@Test
public void testLog1() {
+
Exception e = new Exception();
Object msgs = null;
authzEnv.log(e, msgs);
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_AbsData.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_AbsData.java
new file mode 100644
index 00000000..6d4daa90
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/local/test/JU_AbsData.java
@@ -0,0 +1,115 @@
+/**
+ * ============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 static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransFilter;
+import org.onap.aaf.auth.local.AbsData;
+import org.onap.aaf.auth.local.DataFile;
+import org.onap.aaf.auth.local.TextIndex;
+import org.onap.aaf.auth.local.AbsData.Iter;
+import org.onap.aaf.auth.local.AbsData.Reuse;
+
+import junit.framework.Assert;
+
+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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.Principal;
+
+public class JU_AbsData {
+ char character = 'x';
+ String filePath = "test/output_.key";
+ File keyfile = new File(filePath);
+ AuthzTrans trans = mock(AuthzTrans.class);
+
+ private class AbsDataStub extends AbsData {
+
+
+ public AbsDataStub(File dataf, char sepChar, int maxLineSize, int fieldOffset) {
+ super(dataf, sepChar, maxLineSize, fieldOffset);
+ // TODO Auto-generated constructor stub
+ }
+
+ }
+
+ @Test
+ public void testStub() throws IOException {
+ char character = 'x';
+ String filePath = "test/output_.key";
+ File keyfile = new File(filePath);
+ FileOutputStream is = new FileOutputStream(keyfile);
+ OutputStreamWriter osw = new OutputStreamWriter(is);
+ BufferedWriter w = new BufferedWriter(osw);
+ for(int i = 0; i< 10; i++) { //Write lines to file
+ w.write("a\nsdfasdfxasdf" + i + "\n");
+ }
+ w.close();
+ AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
+ ads.skipLines(0);
+ ads.name();
+
+ long lng = 1823286886660L;
+ //ads.open(trans, lng);
+ keyfile.delete();
+ }
+
+ @Test
+ public void testClose() throws IOException {
+ AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
+ ads.close(trans);
+ }
+
+ @Test
+ public void testReuse() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ char character = 'x';
+ AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
+ Reuse reuse = ads.reuse();
+ reuse.reset();
+ Assert.assertEquals("", reuse.at(1));
+ Assert.assertNull(reuse.next());
+ //reuse.atToEnd(0);
+ //reuse.pos(10);
+ keyfile.delete();
+ }
+
+ @Test
+ public void testIter() throws IOException {
+ AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
+ TextIndex textIndex = new TextIndex(keyfile);
+ //Iter iter = ads.iterator(); //Need actual input to run textIndex.create to have a datafile to read
+
+ }
+
+}
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
index 613d2a80..76d662dd 100644
--- 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
@@ -31,6 +31,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.Principal;
import org.junit.Before;
import org.junit.Test;
@@ -38,39 +42,101 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransFilter;
+import org.onap.aaf.auth.local.AbsData.Reuse;
+import org.onap.aaf.auth.local.AbsData;
import org.onap.aaf.auth.local.DataFile;
import org.onap.aaf.auth.local.TextIndex;
+import org.onap.aaf.auth.local.TextIndex.Iter;
+import org.onap.aaf.auth.local.test.JU_AbsData;
+import org.onap.aaf.misc.env.Env;
import org.onap.aaf.misc.env.TimeTaken;
import org.onap.aaf.misc.env.Trans;
@RunWith(MockitoJUnitRunner.class)
public class JU_TextIndex {
TextIndex textIndex;
+ Iter iter;
Trans trans;
- DataFile datefile;
+ DataFile datafile;
@Mock
File file;
+ private class AbsDataStub extends AbsData {
+
+
+ public AbsDataStub(File dataf, char sepChar, int maxLineSize, int fieldOffset) {
+ super(dataf, sepChar, maxLineSize, fieldOffset);
+ // TODO Auto-generated constructor stub
+ }
+
+ }
+
@Before
- public void setUp() throws IOException{ //TODO: AAF-111 fix once actual input is known.
- char character = 'a';
+ public void setUp() throws IOException{
+ char character = 'x';
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");
+ OutputStreamWriter osw = new OutputStreamWriter(is);
+ BufferedWriter w = new BufferedWriter(osw);
+ for(int i = 0; i< 10; i++) { //Write lines to file
+ w.write("a\nsdfasdfxasdf" + i + "\n");
+ }
w.close();
- datefile = new DataFile(keyfile, "test");
+
+ datafile = new DataFile(keyfile, "r");
+ datafile.open();
+ datafile = new DataFile(keyfile, "rws");// "S" for synchronized
+ datafile.open();
+
trans = mock(Trans.class);
- textIndex = new TextIndex(keyfile);
- //textIndex.create(trans, datefile, 20, character, 2, 2);
+ TimeTaken ttMock = mock(TimeTaken.class);
+ TimeTaken ttMock1 = mock(TimeTaken.class);
+ when(trans.start("Open Files", Env.SUB)).thenReturn(ttMock);
+ when(trans.start("Read", Env.SUB)).thenReturn(ttMock);
+ textIndex = new TextIndex(keyfile);
+ textIndex.close();
+ textIndex.open();
+ //textIndex.create(trans, datafile, 4, character, 2, 0); //TODO: AAF-111 once actual input is aquired
keyfile.delete();
+
+ iter = textIndex.new Iter();
}
-
+
+ @Test
+ public void testClose() throws IOException {
+ textIndex.close();
+ }
+
+ @Test
+ public void testFind() throws IOException {
+ char character = 'x';
+ String filePath = "test/output_.key";
+ File keyfile = new File(filePath);
+ AbsDataStub ads = new AbsDataStub(keyfile, character, 0, 0);
+ Reuse reuse = ads.reuse();
+ textIndex.find("a", reuse , 0);
+ }
+
+ @Test
+ public void testIterNext() {
+ iter.next();
+ iter.hasNext();
+ }
+
@Test
- public void testOpen() throws IOException {
- //textIndex.open();
+ public void testIdx() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ TextIndex outerObject = new TextIndex(file);
+ Class<?> idxClass = TextIndex.class.getDeclaredClasses()[0];
+ Constructor<?> idxConstructor = idxClass.getDeclaredConstructors()[0];
+ Class[] cArg = new Class[2];
+ cArg[0] = Object.class;
+ cArg[1] = Integer.class;
+ idxConstructor.setAccessible(true);
+ //Object innerObject = idxConstructor.newInstance(outerObject,cArg);
+ //idxConstructor.hashCode(); //TODO: AAF-111 access inner private class
}
}
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
deleted file mode 100644
index ee86c748..00000000
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_CodeSetter.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * ============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/server/test/JU_AbsService.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsService.java
new file mode 100644
index 00000000..453eeb85
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsService.java
@@ -0,0 +1,114 @@
+/**
+ * ============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.server.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransFilter;
+import org.onap.aaf.auth.local.AbsData;
+import org.onap.aaf.auth.local.DataFile;
+import org.onap.aaf.auth.local.TextIndex;
+import org.onap.aaf.auth.server.AbsService;
+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.Access.Level;
+import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.cadi.register.Registrant;
+import org.onap.aaf.misc.env.impl.BasicEnv;
+
+import junit.framework.Assert;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.Principal;
+
+import javax.servlet.Filter;
+
+public class JU_AbsService {
+
+ ByteArrayOutputStream outStream;
+
+ private class AbsServiceStub extends AbsService {
+
+ public AbsServiceStub(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;
+ }
+
+ }
+
+ @Before
+ public void setUp() {
+ outStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outStream));
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(System.out);
+ }
+
+ @Test
+ public void testStub() throws CadiException {
+ BasicEnv bEnv = new BasicEnv();
+ PropAccess prop = new PropAccess();
+
+ prop.setProperty(Config.AAF_COMPONENT, "te.st:te.st");
+ prop.setLogLevel(Level.DEBUG);
+ AbsServiceStub absServiceStub = new AbsServiceStub(prop, bEnv); //Testing other branches requires "fails" due to exception handling, will leave that off for now.
+ }
+
+}
+
+
+
+
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java
new file mode 100644
index 00000000..071a0f83
--- /dev/null
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/server/test/JU_AbsServiceStarter.java
@@ -0,0 +1,149 @@
+/**
+ * ============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.server.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransFilter;
+import org.onap.aaf.auth.local.AbsData;
+import org.onap.aaf.auth.local.DataFile;
+import org.onap.aaf.auth.local.TextIndex;
+import org.onap.aaf.auth.rserv.RServlet;
+import org.onap.aaf.auth.server.AbsService;
+import org.onap.aaf.auth.server.AbsServiceStarter;
+import org.onap.aaf.auth.server.test.JU_AbsService;
+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.Access.Level;
+import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.cadi.register.Registrant;
+import org.onap.aaf.misc.env.impl.BasicEnv;
+import org.onap.aaf.auth.local.AbsData.Iter;
+import org.onap.aaf.auth.local.AbsData.Reuse;
+
+import junit.framework.Assert;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.Principal;
+
+import javax.servlet.Filter;
+
+public class JU_AbsServiceStarter {
+
+ ByteArrayOutputStream outStream;
+ AbsServiceStub absServiceStub;
+ AbsServiceStarterStub absServiceStarterStub;
+
+ private class AbsServiceStarterStub extends AbsServiceStarter {
+
+ public AbsServiceStarterStub(AbsService service) {
+ super(service);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void _start(RServlet rserv) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void _propertyAdjustment() {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+ private class AbsServiceStub extends AbsService {
+
+ public AbsServiceStub(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;
+ }
+
+ }
+
+ @Before
+ public void setUp() {
+ outStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outStream));
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(System.out);
+ }
+
+
+ @Test
+ public void testStub() throws CadiException {
+ BasicEnv bEnv = new BasicEnv();
+ PropAccess prop = new PropAccess();
+
+ prop.setProperty(Config.AAF_COMPONENT, "te.st:te.st");
+ prop.setLogLevel(Level.DEBUG);
+ absServiceStub = new AbsServiceStub(prop, bEnv);
+
+ absServiceStarterStub = new AbsServiceStarterStub(absServiceStub);
+ }
+
+// @Test
+// public void testStart() throws Exception {
+// absServiceStarterStub.env();
+// absServiceStarterStub.start();
+// }
+
+}
+
+
+