Improve code coverage for aaf authz modules
Change-Id: Ie81597c6c94fea2224f1e3e847222bcc872b7c00
Issue-ID: AAF-79
Signed-off-by: sg481n <sg481n@att.com>
diff --git a/authz-cmd/pom.xml b/authz-cmd/pom.xml
index 3696094..f42237d 100644
--- a/authz-cmd/pom.xml
+++ b/authz-cmd/pom.xml
@@ -55,13 +55,15 @@
<maven.test.failure.ignore>false</maven.test.failure.ignore>
<project.swmVersion>21</project.swmVersion>
<project.cadiVersion>1.0.0-SNAPSHOT</project.cadiVersion>
- <sonar.language>java</sonar.language>
- <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
- <sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
- <sonar.jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco.exec</sonar.jacoco.reportPath>
- <sonar.jacoco.itReportPath>${project.build.directory}/coverage-reports/jacoco-it.exec</sonar.jacoco.itReportPath>
- <sonar.jacoco.reportMissing.force.zero>true</sonar.jacoco.reportMissing.force.zero>
- <sonar.projectVersion>${project.version}</sonar.projectVersion>
+ <!-- SONAR -->
+ <jacoco.version>0.7.7.201606060606</jacoco.version>
+ <sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
+ <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
+ <!-- Default Sonar configuration -->
+ <sonar.jacoco.reportPath>target/code-coverage/jacoco-ut.exec</sonar.jacoco.reportPath>
+ <sonar.jacoco.itReportPath>target/code-coverage/jacoco-it.exec</sonar.jacoco.itReportPath>
+ <!-- Note: This list should match jacoco-maven-plugin's exclusion list below -->
+ <sonar.exclusions>**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**</sonar.exclusions>
<nexusproxy>https://nexus.onap.org</nexusproxy>
<snapshotNexusPath>/content/repositories/snapshots/</snapshotNexusPath>
<releaseNexusPath>/content/repositories/releases/</releaseNexusPath>
@@ -167,56 +169,69 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <version>0.7.7.201606060606</version>
- <configuration>
- <dumpOnExit>true</dumpOnExit>
- <includes>
- <include>org.onap.aaf.*</include>
- </includes>
- </configuration>
- <executions>
- <execution>
- <id>pre-unit-test</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- <configuration>
- <destFile>${project.build.directory}/coverage-reports/jacoco.exec</destFile>
- <!-- <append>true</append> -->
- </configuration>
- </execution>
- <execution>
- <id>pre-integration-test</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- <configuration>
- <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
- <!-- <append>true</append> -->
- </configuration>
- </execution>
- <execution>
- <goals>
- <goal>merge</goal>
- </goals>
- <phase>post-integration-test</phase>
- <configuration>
- <fileSets>
- <fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
- <directory>${project.build.directory}/coverage-reports</directory>
- <includes>
- <include>*.exec</include>
- </includes>
- </fileSet>
- </fileSets>
- <destFile>${project.build.directory}/jacoco-dev.exec</destFile>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>${jacoco.version}</version>
+ <configuration>
+ <excludes>
+ <exclude>**/gen/**</exclude>
+ <exclude>**/generated-sources/**</exclude>
+ <exclude>**/yang-gen/**</exclude>
+ <exclude>**/pax/**</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+
+ <execution>
+ <id>pre-unit-test</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
+ <propertyName>surefireArgLine</propertyName>
+ </configuration>
+ </execution>
+
+
+ <execution>
+ <id>post-unit-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>pre-integration-test</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${project.build.directory}/code-coverage/jacoco-it.exec</destFile>
+
+ <propertyName>failsafeArgLine</propertyName>
+ </configuration>
+ </execution>
+
+
+ <execution>
+ <id>post-integration-test</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco-it.exec</dataFile>
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
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 6a970ce..f005738 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.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 @@
@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 {
+ 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 eval_empty() throws Exception{
- assertTrue(cli.eval(""));
+ 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 a1d19dd..77243e9 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 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 c51246b..f48d71e 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 @@
@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 77c05a9..aa97593 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.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 @@
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);
}