summaryrefslogtreecommitdiffstats
path: root/authz-cmd/src/test/java
diff options
context:
space:
mode:
authorsg481n <sg481n@att.com>2017-10-04 17:29:37 +0000
committersg481n <sg481n@att.com>2017-10-04 17:30:42 +0000
commit4ccc6b830291f15b8006fdee37a8aae21c22f9df (patch)
tree3469b48890970a67f4b7d5ac5e8282755b5c13c1 /authz-cmd/src/test/java
parent0be0e0671b12c9b218023e505f3aec74fc8c8e4f (diff)
Improve code coverage for aaf authz modules
Change-Id: Ie81597c6c94fea2224f1e3e847222bcc872b7c00 Issue-ID: AAF-79 Signed-off-by: sg481n <sg481n@att.com>
Diffstat (limited to 'authz-cmd/src/test/java')
-rw-r--r--authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java125
-rw-r--r--authz-cmd/src/test/java/org/onap/aaf/cmd/JU_BaseCmd.java187
-rw-r--r--authz-cmd/src/test/java/org/onap/aaf/cmd/JU_Help.java23
-rw-r--r--authz-cmd/src/test/java/org/onap/aaf/cmd/user/JU_Cred.java41
4 files changed, 340 insertions, 36 deletions
diff --git a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java
index 6a970ce0..f0057387 100644
--- a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java
+++ b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java
@@ -22,6 +22,7 @@
******************************************************************************/
package org.onap.aaf.cmd;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -36,7 +37,7 @@ import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.aaf.authz.env.AuthzEnv;
import org.onap.aaf.cmd.AAFcli;
-
+import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Locator;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.client.PropertyLocator;
@@ -48,42 +49,144 @@ import org.onap.aaf.inno.env.APIException;
@RunWith(MockitoJUnitRunner.class)
public class JU_AAFCli {
-
+
private static AAFcli cli;
private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);
-
+
@BeforeClass
public static void setUp() throws Exception, Exception {
cli = getAAfCli();
}
-
+
@Test
public void eval() throws Exception {
assertTrue(cli.eval("#startswith"));
}
-
+
@Test
- public void eval_empty() throws Exception{
+ public void eval_empty() throws Exception {
assertTrue(cli.eval(""));
}
+
+ @Test
+ public void eval1() throws Exception {
+ assertTrue(cli.eval("@[123"));
+ }
+
+ @Test
+ public void eval2() throws Exception {
+ assertFalse(cli.eval("as @[ 123"));
+ }
+
+ @Test
+ public void eval3() throws Exception {
+ try {
+ cli.eval("expect @[ 123");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ assertTrue(e instanceof CadiException);
+ }
+ }
+
+ public void eval31() throws Exception {
+ try {
+ cli.eval("expect 1 @[ 123");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ assertTrue(e instanceof CadiException);
+ }
+ }
+
+ @Test
+ public void eval4() throws Exception {
+ try {
+ cli.eval("sleep @[ 123");
+ } catch (Exception e) {
+ assertTrue(e instanceof NumberFormatException);
+ }
+ }
+
+ @Test
+ public void eval41() throws Exception {
+ assertTrue(cli.eval("sleep 1 @[ 123"));
+ }
+
+ @Test
+ public void eval5() throws Exception {
+ try {
+ cli.eval("delay @[ 123");
+ } catch (Exception e) {
+ assertTrue(e instanceof NumberFormatException);
+ }
+ }
+
+ @Test
+ public void eval51() throws Exception {
+ assertTrue(cli.eval("delay 1 @[ 123"));
+ }
+
+ @Test
+ public void eval7() throws Exception {
+ assertFalse(cli.eval("exit @[ 123"));
+ }
+
+ @Test
+ public void eval8() throws Exception {
+ assertTrue(cli.eval("REQUEST @[ 123"));
+ }
+
+ @Test
+ public void eval9() throws Exception {
+ assertTrue(cli.eval("FORCE @[ 123"));
+ }
+
+ @Test
+ public void eval10() throws Exception {
+ assertTrue(cli.eval("set @[ 123"));
+ }
+
+ @Test
+ public void keyboardHelp() throws Exception {
+ boolean noError=true;
+ try {
+ cli.keyboardHelp();
+ } catch (Exception e) {
+ noError=false;
+ }
+ assertTrue(noError);
+ }
+
+
+
+ @Test
+ public void setProp() throws Exception {
+ boolean noError=true;
+ try {
+ cli.keyboardHelp();
+ } catch (Exception e) {
+ noError=false;
+ }
+ assertTrue(noError);
+ }
@Test
public void eval_randomString() throws Exception {
assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));
}
-
+
public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException {
final AuthzEnv env = new AuthzEnv(System.getProperties());
String aafUrl = "https://DME2RESOLVE";
SecurityInfo si = new SecurityInfo(env);
env.loadToSystemPropsStartsWith("AAF", "DME2");
Locator loc;
- loc = new PropertyLocator(aafUrl);
+ loc = new PropertyLocator(aafUrl);
TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));
HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0");
-
- //TODO: Consider requiring a default in properties
- env.setProperty(Config.AAF_DEFAULT_REALM, System.getProperty(Config.AAF_DEFAULT_REALM,Config.getDefaultRealm()));
+
+ // TODO: Consider requiring a default in properties
+ env.setProperty(Config.AAF_DEFAULT_REALM,
+ System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm()));
HBasicAuthSS ss = mock(HBasicAuthSS.class);
return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);
}
diff --git a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_BaseCmd.java b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_BaseCmd.java
index a1d19ddb..77243e9c 100644
--- a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_BaseCmd.java
+++ b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_BaseCmd.java
@@ -26,33 +26,204 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.security.GeneralSecurityException;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.aaf.cmd.AAFcli;
-import org.onap.aaf.cmd.BaseCmd;
-
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.LocatorException;
+import org.onap.aaf.cadi.client.Future;
import org.onap.aaf.inno.env.APIException;
+import aaf.v2_0.History;
+
@RunWith(MockitoJUnitRunner.class)
public class JU_BaseCmd {
-
+
private static AAFcli cli;
private static BaseCmd bCmd;
-
+
@BeforeClass
public static void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException {
cli = JU_AAFCli.getAAfCli();
bCmd = new BaseCmd<>(cli, "testString");
}
-
+
@Test
public void exec() throws CadiException, APIException, LocatorException {
- assertEquals(bCmd._exec(0, "add","del","reset","extend"), 0);
-
+ assertEquals(bCmd._exec(0, "add", "del", "reset", "extend"), 0);
+
+ }
+
+ @Test
+ public void error() throws CadiException, APIException, LocatorException {
+ boolean noError = true;
+ Future<String> future = new Future<String>() {
+
+ @Override
+ public boolean get(int timeout) throws CadiException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int code() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String body() {
+ // TODO Auto-generated method stub
+ return "{%}";
+ }
+
+ @Override
+ public String header(String tag) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ try {
+ bCmd.error(future);
+ } catch (Exception e) {
+ noError = false;
+ }
+ assertEquals(noError, true);
+
+ }
+
+
+
+ @Test
+ public void activity() throws DatatypeConfigurationException {
+ boolean noError = true;
+ History history = new History();
+ History.Item item = new History.Item();
+ item.setTarget("target");
+ item.setUser("user");
+ item.setMemo("memo");
+
+ GregorianCalendar c = new GregorianCalendar();
+ c.setTime(new Date());
+ XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
+ item.setTimestamp(date);
+ history.getItem().add(item);
+ try {
+ bCmd.activity(history, "history");
+ } catch (Exception e) {
+ noError = false;
+ }
+ assertEquals(noError, true);
+
}
+
+ @Test
+ public void activity1() throws DatatypeConfigurationException {
+ boolean noError = true;
+ History history = new History();
+ History.Item item = new History.Item();
+ item.setTarget("target");
+ item.setUser("user");
+ item.setMemo("memo");
+
+ GregorianCalendar c = new GregorianCalendar();
+ c.setTime(new Date());
+ XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
+ item.setTimestamp(date);
+ history.getItem().add(item);
+ try {
+ bCmd.activity(history, "1[]");
+ } catch (Exception e) {
+ noError = false;
+ }
+ assertEquals(noError, true);
+
+ }
+
+
+
+ @Test
+ public void error1() {
+ boolean noError = true;
+ Future<String> future = new Future<String>() {
+
+ @Override
+ public boolean get(int timeout) throws CadiException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int code() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String body() {
+ // TODO Auto-generated method stub
+ return "{<html><code>1</code></html>";
+ }
+
+ @Override
+ public String header(String tag) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ try {
+ bCmd.error(future);
+ } catch (Exception e) {
+ noError = false;
+ }
+ assertEquals(noError, true);
+
+ }
+
+ @Test
+ public void error2() {
+ boolean noError = true;
+ Future<String> future = new Future<String>() {
+
+ @Override
+ public boolean get(int timeout) throws CadiException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int code() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String body() {
+ // TODO Auto-generated method stub
+ return "other";
+ }
+
+ @Override
+ public String header(String tag) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ try {
+ bCmd.error(future);
+ } catch (Exception e) {
+ noError = false;
+ }
+ assertEquals(noError, true);
+
+ }
+
}
diff --git a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_Help.java b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_Help.java
index c51246bd..f48d71e0 100644
--- a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_Help.java
+++ b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_Help.java
@@ -62,10 +62,31 @@ public class JU_Help {
@Test
public void exec_HTTP_200() {
try {
- assertEquals(help._exec(0, "helps"), HttpStatus.OK_200);
+ assertEquals(help._exec(1, "helps"), HttpStatus.OK_200);
} catch (CadiException | APIException | LocatorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
+
+ @Test
+ public void exec_HTTP_200_1() {
+ try {
+ assertEquals(help._exec(1, "helps","help"), HttpStatus.OK_200);
+ } catch (CadiException | APIException | LocatorException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void detailhelp() {
+ boolean hasError=false;
+ try {
+ help.detailedHelp(2, new StringBuilder("detail help test"));
+ } catch (Exception e) {
+ hasError=true;
+ }
+ assertEquals(hasError,false);
+ }
}
diff --git a/authz-cmd/src/test/java/org/onap/aaf/cmd/user/JU_Cred.java b/authz-cmd/src/test/java/org/onap/aaf/cmd/user/JU_Cred.java
index 77c05a99..aa975936 100644
--- a/authz-cmd/src/test/java/org/onap/aaf/cmd/user/JU_Cred.java
+++ b/authz-cmd/src/test/java/org/onap/aaf/cmd/user/JU_Cred.java
@@ -27,13 +27,19 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.cmd.AAFcli;
+import org.onap.aaf.cmd.Cmd;
import org.onap.aaf.cmd.user.Cred;
import org.onap.aaf.cmd.user.User;
-
+import org.onap.aaf.authz.env.AuthzEnv;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.inno.env.APIException;
@@ -43,29 +49,32 @@ public class JU_Cred {
private static Cred testCred;
private static User testUser;
+ private static AuthzEnv env;
@BeforeClass
- public static void setUp() {
+ public static void setUp() throws FileNotFoundException, APIException {
+
testCred = mock(Cred.class);
testUser = mock(User.class);
- try {
- when(testCred._exec(4, "String1","String2","String3","String4")).thenReturn(10);
- } catch (CadiException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (APIException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (LocatorException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ env = mock(AuthzEnv.class);
+ Mockito.when(env.getProperty(Cmd.STARTDATE,null)).thenReturn(null);
+ Mockito.when(env.getProperty(Cmd.ENDDATE,null)).thenReturn(null);
+
}
@Test
- public void exec() throws CadiException, APIException, LocatorException {
- assertEquals(testCred._exec(4, "String1","String2","String3","String4"), 10);
+ public void exec() throws CadiException, APIException, LocatorException, FileNotFoundException {
+ boolean isNullpointer=false;
+ AAFcli aaFcli= new AAFcli(env, new PrintWriter("temp"), null, null, null);
+ User user= new User(aaFcli);
+ Cred testCred= new Cred(user);
+ try {
+ testCred._exec(0, "add", "del", "reset", "extend");
+ } catch (Exception e) {
+ isNullpointer=true;
+ }
+ assertEquals(isNullpointer, true);
}