From 0a38f42e5fcc6a731ab740d447b48d6bbd25623c Mon Sep 17 00:00:00 2001 From: GUNDAPANENI Date: Tue, 3 Oct 2017 11:42:40 -0500 Subject: add unittests to autz add unittests to autz services Issue-Id: AAF-81 Change-Id: Iefb5f1947dcc68a562dc67dc71859e4f92059b55 Signed-off-by: GUNDAPANENI --- .../java/org/onap/aaf/authz/common/JU_Define.java | 2 +- .../org/onap/aaf/osaaf/defOrg/JU_DefaultOrg.java | 66 +++++++--- .../aaf/osaaf/defOrg/JU_DefaultOrgIdentity.java | 23 ++++ authz-defOrg/src/test/resources/test.txt | 0 pom.xml | 133 ++++++++++++--------- 5 files changed, 149 insertions(+), 75 deletions(-) create mode 100644 authz-defOrg/src/test/resources/test.txt diff --git a/authz-core/src/test/java/org/onap/aaf/authz/common/JU_Define.java b/authz-core/src/test/java/org/onap/aaf/authz/common/JU_Define.java index 48c84993..9415c7cc 100644 --- a/authz-core/src/test/java/org/onap/aaf/authz/common/JU_Define.java +++ b/authz-core/src/test/java/org/onap/aaf/authz/common/JU_Define.java @@ -58,7 +58,7 @@ public class JU_Define { 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); + //define.set(envMock); } } diff --git a/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrg.java b/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrg.java index 19acfdbe..ba0ad6b6 100644 --- a/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrg.java +++ b/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrg.java @@ -22,16 +22,11 @@ ******************************************************************************/ package org.onap.aaf.osaaf.defOrg; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; - -import javax.mail.Address; -import javax.mail.internet.InternetAddress; +import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -41,12 +36,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.aaf.authz.env.AuthzEnv; import org.onap.aaf.authz.env.AuthzTrans; -import org.onap.aaf.authz.org.Executor; import org.onap.aaf.authz.org.OrganizationException; -import org.onap.aaf.authz.org.Organization.Identity; -import org.onap.aaf.authz.org.Organization.Policy; -import org.onap.aaf.osaaf.defOrg.DefaultOrg; -import org.onap.aaf.osaaf.defOrg.Identities.Data; import org.powermock.api.mockito.PowerMockito; import org.powermock.modules.junit4.PowerMockRunner; @@ -70,12 +60,13 @@ String defFile; @Mock File fIdentitiesMock; + @Before public void setUp() throws OrganizationException{ MockitoAnnotations.initMocks(this); PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".mailHost"), null)).thenReturn("hello"); PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".supportEmail"), null)).thenReturn("notnull"); - PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn("C:/Users/sv8675/Desktop/AAF-Code-Sai/AAF-master/authz/authz-defOrg/src/main/java/test.txt"); + PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn("src\\test\\resources\\test.txt"); PowerMockito.when(fIdentitiesMock.exists()).thenReturn(true); //PowerMockito.when((fIdentitiesMock!=null && fIdentitiesMock.exists())).thenReturn(true); defaultOrg = new DefaultOrg(authzEnvMock); @@ -85,9 +76,54 @@ public void setUp() throws OrganizationException{ public void test() throws OrganizationException{ //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" "); //defaultOrg = new DefaultOrg(authzEnvMock); - assertTrue(true); + assertTrue(defaultOrg != null); +} + + +@Test //(expected=OrganizationException.class) +public void testMultipleCreds() throws OrganizationException{ + String id = "test"; + //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" "); + //defaultOrg = new DefaultOrg(authzEnvMock); + boolean canHaveMultipleCreds; + canHaveMultipleCreds = defaultOrg.canHaveMultipleCreds(id ); + System.out.println("value of canHaveMultipleCreds: " + canHaveMultipleCreds); + assertTrue(canHaveMultipleCreds); +} + + +@Test +public void testGetIdentityTypes() throws OrganizationException{ + Set identityTypes = defaultOrg.getIdentityTypes(); + System.out.println("value of IdentityTypes: " + identityTypes); + assertTrue(identityTypes.size() == 4); } + +@Test +public void testGetRealm() throws OrganizationException{ + String realmTest = defaultOrg.getRealm(); + System.out.println("value of realm: " + realmTest); + assertTrue(realmTest == REALM); +} + +@Test +public void testGetName() throws OrganizationException{ + String testName = defaultOrg.getName(); + System.out.println("value of name: " + testName); + assertTrue(testName == NAME); +} + + +@Test +public void testGetDomain() throws OrganizationException{ + String testDomain = defaultOrg.getDomain(); + System.out.println("value of domain: " + testDomain); + assertTrue(testDomain == DOMAIN); +} + + + @Test public void testIsValidID(){ String Result = defaultOrg.isValidID(Matchers.anyString()); diff --git a/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrgIdentity.java b/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrgIdentity.java index 5f915d5b..755f0b13 100644 --- a/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrgIdentity.java +++ b/authz-defOrg/src/test/java/org/onap/aaf/osaaf/defOrg/JU_DefaultOrgIdentity.java @@ -69,4 +69,27 @@ public class JU_DefaultOrgIdentity { System.out.println("value of res " +res); } + + @Test + public void testIsFound(){ + defaultOrgIdentityMock.isFound(); + System.out.println("value of found " +defaultOrgIdentityMock.isFound()); + assertFalse(defaultOrgIdentityMock.isFound()); + } + + @Test + public void testIsResponsible(){ + defaultOrgIdentityMock.isResponsible(); + System.out.println("value of res " +defaultOrgIdentityMock.isResponsible()); + assertFalse(defaultOrgIdentityMock.isResponsible()); + } + + @Test + public void testFullName(){ + String fullName = defaultOrgIdentityMock.fullName(); + System.out.println("value of fullname " +fullName); + assertTrue(fullName == null); + } + + } diff --git a/authz-defOrg/src/test/resources/test.txt b/authz-defOrg/src/test/resources/test.txt new file mode 100644 index 00000000..e69de29b diff --git a/pom.xml b/pom.xml index 9a718b8c..7ca6ffb3 100644 --- a/pom.xml +++ b/pom.xml @@ -63,13 +63,15 @@ 1.0.0-SNAPSHOT 1.0.0-SNAPSHOT 3.1.200 - java - jacoco - ${project.build.directory}/surefire-reports - ${project.build.directory}/coverage-reports/jacoco.exec - ${project.build.directory}/coverage-reports/jacoco-it.exec - true - ${project.version} + + 0.7.7.201606060606 + 3.2 + jacoco + + target/code-coverage/jacoco-ut.exec + target/code-coverage/jacoco-it.exec + + **/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/** https://nexus.onap.org /content/repositories/snapshots/ /content/repositories/releases/ @@ -117,11 +119,12 @@ **/JU_CredDAO.java **/JU_CacheInfoDAO.java **/JU_ApprovalDAO.java - **/JU_Define.java + + **/JU_Identities.java **/JU_AuthzTransFilter.java **/JU_CachingFileAccess.java - **/JU_DefaultOrg.java + **/JU_FileServer.java **/JU_DirectAAFLur.java **/JU_AuthAPI.java @@ -262,57 +265,69 @@ - org.jacoco - jacoco-maven-plugin - 0.7.7.201606060606 - - true - - org.onap.aaf.* - - - - - pre-unit-test - - prepare-agent - - - ${project.build.directory}/coverage-reports/jacoco.exec - - - - - pre-integration-test - pre-integration-test - - prepare-agent - - - ${project.build.directory}/coverage-reports/jacoco-it.exec - - - - - - merge - - post-integration-test - - - - ${project.build.directory}/coverage-reports - - *.exec - - - - ${project.build.directory}/jacoco-dev.exec - - - - + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + **/gen/** + **/generated-sources/** + **/yang-gen/** + **/pax/** + + + + + + pre-unit-test + + prepare-agent + + + ${project.build.directory}/code-coverage/jacoco-ut.exec + surefireArgLine + + + + + + post-unit-test + test + + report + + + ${project.build.directory}/code-coverage/jacoco-ut.exec + ${project.reporting.outputDirectory}/jacoco-ut + + + + pre-integration-test + pre-integration-test + + prepare-agent + + + ${project.build.directory}/code-coverage/jacoco-it.exec + + failsafeArgLine + + + + + post-integration-test + post-integration-test + + report + + + ${project.build.directory}/code-coverage/jacoco-it.exec + ${project.reporting.outputDirectory}/jacoco-it + + + + -- cgit 1.2.3-korg