summaryrefslogtreecommitdiffstats
path: root/auth/auth-deforg/src/test/java
diff options
context:
space:
mode:
authorYoussef Chawki <youssef.chawki@orange.com>2018-05-07 20:08:31 +0200
committerYoussef Chawki <youssef.chawki@orange.com>2018-05-07 20:08:31 +0200
commit174ec2eeb4ae929aaa2ccea0e8541dad7c4c28f2 (patch)
tree0f31b5621dbeb4203fdeda5caadf095d9deda966 /auth/auth-deforg/src/test/java
parent22a2996fa5d9edac9e8b7ffd276fda6b5a7b9b98 (diff)
Added UT auth-deforg, code cov 61%
For those Unit tests, I added the library "mock-javamail" in order to test the "notify" function of DefaultOrg.java. Change-Id: I8894e2b6c264581be5d3c56b46600379f1d31f81 Issue-ID: AAF-239 Signed-off-by: Youssef Chawki <youssef.chawki@orange.com>
Diffstat (limited to 'auth/auth-deforg/src/test/java')
-rw-r--r--auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrg.java173
-rw-r--r--auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgIdentity.java145
-rw-r--r--auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgWarnings.java26
3 files changed, 261 insertions, 83 deletions
diff --git a/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrg.java b/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrg.java
index d4606284..9120ceb2 100644
--- a/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrg.java
+++ b/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrg.java
@@ -22,71 +22,180 @@
package org.onap.aaf.org.test;
import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
import java.io.File;
+import java.io.IOException;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Matchers;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-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.cadi.config.Config;
+import org.onap.aaf.misc.env.Env;
+import org.onap.aaf.misc.env.LogTarget;
+import org.onap.aaf.misc.env.TimeTaken;
import org.onap.aaf.org.DefaultOrg;
-import org.powermock.api.mockito.PowerMockito;
+import org.onap.aaf.org.Identities;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.onap.aaf.auth.local.AbsData.Reuse;
+
@RunWith(PowerMockRunner.class)
public class JU_DefaultOrg {
- DefaultOrg defaultOrg;
- //private DefaultOrg defaultOrgMock;
+
+ private DefaultOrg defaultOrg;
+
+
+ Identities.Data data;
+
@Mock
- AuthzEnv authzEnvMock;
+ Env envMock;
@Mock
AuthzTrans authzTransMock;
@Mock
- File fIdentitiesMock;
+ TimeTaken ttMock;
+
+ @Mock
+ LogTarget logTargetMock;
+
private static final String PROPERTY_IS_REQUIRED = " property is Required";
private static final String DOMAIN = "osaaf.com";
private static final String REALM = "com.osaaf";
private static final String NAME = "Default Organization";
private static final String NO_PASS = NAME + " does not support Passwords. Use AAF";
- String mailHost,mailFromUserId,supportAddress;
- private String SUFFIX;
- String s;
- String defFile;
- //@Before
+ private static final String URL = "www.deforg.com";
+ private static final String IDENT = "ccontra|iowna";
+ private static final String CCS = "mmanager|bdevl";
+ String mailHost,mailFromUserId,summary,supportAddress;
+
+ private final static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);
+
+
+
+ @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("src" + File.separator + "test" + File.separator + "resources" + File.separator + "test.txt");
- PowerMockito.when(fIdentitiesMock.exists()).thenReturn(true);
- //PowerMockito.when((fIdentitiesMock!=null && fIdentitiesMock.exists())).thenReturn(true);
- defaultOrg = new DefaultOrg(authzEnvMock, REALM);
+
+ mailFromUserId = "frommail";
+ mailHost = "hostmail";
+ File file = new File("src/test/resources/");
+ when(envMock.getProperty(REALM + ".name","Default Organization")).thenReturn(NAME);
+ when(envMock.getProperty(REALM + ".mailHost",null)).thenReturn(mailHost);
+ when(envMock.getProperty(REALM + ".mailFrom",null)).thenReturn(mailFromUserId);
+ when(envMock.getProperty("aaf_data_dir")).thenReturn(file.getAbsolutePath());
+ when(envMock.warn()).thenReturn(logTargetMock);
+ when(authzTransMock.warn()).thenReturn(logTargetMock);
+ when(authzTransMock.start(any(String.class),any(Integer.class))).thenReturn(ttMock);
+ when(authzTransMock.error()).thenReturn(logTargetMock);
+ when(authzTransMock.getProperty("CASS_ENV", "")).thenReturn("Cassandra env");
+
+ defaultOrg = new DefaultOrg(envMock, REALM);
+
}
- //@Test //(expected=OrganizationException.class)
- public void test() throws OrganizationException{
- //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" ");
- //defaultOrg = new DefaultOrg(authzEnvMock);
+ @Test
+ public void testDefOrg_returnDataIdentityNotNull() throws OrganizationException {
+
+
+ try {
+ defaultOrg.identities.open(authzTransMock, TIMEOUT);
+ try {
+ Reuse r = defaultOrg.identities.reuse();
+ data = defaultOrg.identities.find("iowna", defaultOrg.identities.reuse());
+ System.out.println("here is identities data: "+ data.toString());
+
+ } finally {
+ defaultOrg.identities.close(authzTransMock);
+ }
+ } catch (IOException e) {
+ throw new OrganizationException(e);
+ }
+
+
+ assertTrue(data.toString() != null);
+
+ }
+
+
+
+ @Test
+ public void testDefOrg_returnDefOrgEntity() {
+
+
assertTrue(defaultOrg != null);
+
}
+ @Test
+ public void testDefOrgNotifyApproval_returnResponseOK() {
+
+ summary = "Approval";
+ Boolean urgent = false;
+ DefaultOrg.Response response = defaultOrg.notify(authzTransMock, DefaultOrg.Notify.Approval, URL, IDENT.split("\\|"), CCS.split("\\|"), summary, urgent);
+ assertEquals(response.name(), "OK");
+
+ }
+
+
+ @Test
+ public void testDefOrgNotifyPasswordExpiration_returnResponseOK() {
+
+ summary = "PasswordExpiration";
+ Boolean urgent = false;
+ DefaultOrg.Response response = defaultOrg.notify(authzTransMock, DefaultOrg.Notify.PasswordExpiration, URL, IDENT.split("\\|"), CCS.split("\\|"), summary, urgent);
+ assertEquals(response.name(), "OK");
+
+ }
+
+ @Test
+ public void testDefOrgNotifyRoleExpiration_returnResponseOK() {
+
+ summary = "RoleExpiration";
+ Boolean urgent = false;
+ DefaultOrg.Response response = defaultOrg.notify(authzTransMock, DefaultOrg.Notify.RoleExpiration, URL, IDENT.split("\\|"), CCS.split("\\|"), summary, urgent);
+ assertEquals(response.name(), "OK");
+ }
+
+ @Test
+ public void testDefOrgNotifyRoleExpirationUrgent_returnResponseOK() {
+
+ summary = "RoleExpirationUrgent";
+ Boolean urgent = true;
+ when(authzTransMock.info()).thenReturn(logTargetMock);
+ DefaultOrg.Response response = defaultOrg.notify(authzTransMock, DefaultOrg.Notify.RoleExpiration, URL, IDENT.split("\\|"), CCS.split("\\|"), summary, urgent);
+ assertEquals(response.name(), "OK");
+
+ }
+
+ @Test
+ public void testDefOrgNotifyModeTest_returnResponseOK() {
+
+ summary = "ModeTest";
+ Boolean urgent = false;
+ when(authzTransMock.info()).thenReturn(logTargetMock);
+ defaultOrg.setTestMode(true);
+ DefaultOrg.Response response = defaultOrg.notify(authzTransMock, DefaultOrg.Notify.RoleExpiration, URL, IDENT.split("\\|"), CCS.split("\\|"), summary, urgent);
+ assertEquals(response.name(), "OK");
+
+ }
+
+
+
+
+
//@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);
@@ -94,7 +203,7 @@ public class JU_DefaultOrg {
}
- //@Test
+ //@Test
public void testGetIdentityTypes() throws OrganizationException{
Set<String> identityTypes = defaultOrg.getIdentityTypes();
System.out.println("value of IdentityTypes: " + identityTypes);
@@ -102,7 +211,7 @@ public class JU_DefaultOrg {
}
- //@Test
+ //@Test
public void testGetRealm() throws OrganizationException{
String realmTest = defaultOrg.getRealm();
System.out.println("value of realm: " + realmTest);
@@ -114,7 +223,7 @@ public class JU_DefaultOrg {
defaultOrg.addSupportedRealm(otherRealm);
assertTrue(defaultOrg.supportsRealm(otherRealm));
}
- //@Test
+ //@Test
public void testGetName() throws OrganizationException{
String testName = defaultOrg.getName();
System.out.println("value of name: " + testName);
@@ -122,7 +231,7 @@ public class JU_DefaultOrg {
}
- //@Test
+ //@Test
public void testGetDomain() throws OrganizationException{
String testDomain = defaultOrg.getDomain();
System.out.println("value of domain: " + testDomain);
@@ -130,10 +239,10 @@ public class JU_DefaultOrg {
}
// @Test
- // public void testIsValidID(){
+ // public void testIsValidID(){
// String Result = defaultOrg.isValidID(Matchers.anyString());
// System.out.println("value of res " +Result);
- // assertNotNull(Result);
+ // assertNotNull(Result);
// }
//@Test
diff --git a/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgIdentity.java b/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgIdentity.java
index 1577d9e6..3e5c74b5 100644
--- a/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgIdentity.java
+++ b/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgIdentity.java
@@ -21,8 +21,7 @@
******************************************************************************/
package org.onap.aaf.org.test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
@@ -31,66 +30,136 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.local.AbsData.Reuse;
import org.onap.aaf.auth.org.OrganizationException;
-import org.onap.aaf.auth.org.Organization.Identity;
import org.onap.aaf.org.DefaultOrg;
import org.onap.aaf.org.DefaultOrgIdentity;
+import org.onap.aaf.org.Identities;
import org.onap.aaf.org.Identities.Data;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
+import static org.mockito.Mockito.*;
+import java.io.IOException;
@RunWith(PowerMockRunner.class)
public class JU_DefaultOrgIdentity {
- private DefaultOrgIdentity defaultOrgIdentity;
- private DefaultOrgIdentity defaultOrgIdentityMock;
-
+ private DefaultOrg defaultOrgMock;
+
@Mock
- AuthzTrans authzTransMock;
-
- String key="key";
-
+ private Reuse rMock;
+
@Mock
- private DefaultOrg defaultOrgMock;
+ AuthzTrans authzTransMock;
+
@Mock
private Data dataMock;
+
@Mock
- private Identity identityMock;
-
+ private DefaultOrgIdentity defaultOrgIdentity;
+
+ static String key = "iowna@deforg";
+ static String orgDomain = "@deforg";
+
@Before
- public void setUp() throws OrganizationException{
+ public void setUp() throws IOException, OrganizationException {
MockitoAnnotations.initMocks(this);
- defaultOrgIdentityMock = PowerMockito.mock(DefaultOrgIdentity.class);
+ defaultOrgMock = PowerMockito.mock(DefaultOrg.class);
+ defaultOrgMock.identities = mock(Identities.class);
+
+
+ authzTransMock = PowerMockito.mock(AuthzTrans.class);
+
+ when(defaultOrgMock.getDomain()).thenReturn(orgDomain);
+ when(defaultOrgMock.identities.reuse()).thenReturn(rMock);
+ when(defaultOrgMock.identities.find(eq(key),any(Reuse.class))).thenReturn(dataMock);
+
+ defaultOrgIdentity = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
+
+ }
+
+
+ @Test
+ public void testIdentify_returnIdentifiedEntity() {
+
+ assertTrue(defaultOrgIdentity.id() != null);
+
+ }
+
+ @Test
+ public void testIdentify_returnIdentifiedEntityWithDataNull() throws IOException, OrganizationException {
+
+ when(defaultOrgMock.identities.find(eq(key),any(Reuse.class))).thenReturn(null);
+
+ DefaultOrgIdentity defaultOrgIdentityDataNull = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
+ assertTrue(defaultOrgIdentityDataNull.id() != null);
+
+ }
+
+ @Test(expected = OrganizationException.class)
+ public void testIdentify_returnThrowIOException() throws OrganizationException {
+
+ when(defaultOrgMock.getDomain()).thenReturn(orgDomain);
+ when(defaultOrgMock.identities.reuse()).thenThrow(IOException.class);
+ DefaultOrgIdentity defaultOrgIdentityException = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
+
}
-
+
+
@Test
- public void testEquals(){
- Object b = null;
- Boolean res = defaultOrgIdentityMock.equals(b);
- System.out.println("value of res " +res);
+ public void testEquals_returnTrue() {
+
+ Object b = defaultOrgIdentity;
+ assertTrue(defaultOrgIdentity.equals(b) == true );
}
-
-
+
@Test
- public void testIsFound(){
- defaultOrgIdentityMock.isFound();
- System.out.println("value of found " +defaultOrgIdentityMock.isFound());
- assertFalse(defaultOrgIdentityMock.isFound());
+ public void testStatus_returnUnknown() {
+
+ assertEquals(defaultOrgIdentity.type(), "Unknown");
+
}
-
+
@Test
- public void testIsResponsible(){
- defaultOrgIdentityMock.mayOwn();
- System.out.println("value of res " +defaultOrgIdentityMock.mayOwn());
- assertNull(defaultOrgIdentityMock.mayOwn());
+ public void testHash_returnHashCode() {
+
+ assertTrue(defaultOrgIdentity.hashCode() != 0 );
+
}
-
+
@Test
- public void testFullName(){
- String fullName = defaultOrgIdentityMock.fullName();
- System.out.println("value of fullname " +fullName);
- assertTrue(fullName == null);
+ public void testFullId_returnFullId() throws IOException, OrganizationException{
+ String key="toto@deforg";
+ String orgDomain="@deforg";
+ when(defaultOrgMock.getDomain()).thenReturn(orgDomain);
+ when(defaultOrgMock.identities.reuse()).thenReturn(rMock);
+ when(defaultOrgMock.identities.find(eq(key),any(Reuse.class))).thenReturn(dataMock);
+ defaultOrgIdentity = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
+
+ assertTrue(defaultOrgIdentity.fullID().contains("@") );
}
-
-
+
+ @Test
+ public void testEmail_returnEmail() {
+
+ assertTrue(defaultOrgIdentity.email() != null );
+ }
+
+
+ @Test
+ public void testFullName_returnFullName() {
+
+ assertTrue(defaultOrgIdentity.fullName() != null );
+ }
+
+
+ @Test
+ public void testFirstName_returnFirstName() {
+
+ assertTrue(defaultOrgIdentity.firstName() != null );
+ }
+
+
+
+
}
diff --git a/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgWarnings.java b/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgWarnings.java
index 3b4d5543..2692d608 100644
--- a/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgWarnings.java
+++ b/auth/auth-deforg/src/test/java/org/onap/aaf/org/test/JU_DefaultOrgWarnings.java
@@ -33,48 +33,48 @@ import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
public class JU_DefaultOrgWarnings {
-
+
private DefaultOrgWarnings defaultOrgWarningsMock;
private DefaultOrgWarnings defaultOrgWarnings;
-
-
+
+
@Before
public void setUp(){
MockitoAnnotations.initMocks(this);
-
+
defaultOrgWarningsMock = PowerMockito.mock(DefaultOrgWarnings.class);
-
+
defaultOrgWarnings = new DefaultOrgWarnings();
}
-
+
@Test
public void testApprEmailInterval() {
-
+
assertEquals(259200000, defaultOrgWarnings.apprEmailInterval() );
}
-
+
@Test
public void testCredEmailInterval() {
assertEquals(604800000, defaultOrgWarnings.credEmailInterval());
-
+
}
-
+
@Test
public void testCredExpirationWarning() {
assertEquals(2592000000L, defaultOrgWarnings.credExpirationWarning());
}
-
+
@Test
public void testEmailUrgentWarning() {
assertEquals(1209600000L, defaultOrgWarnings.emailUrgentWarning());
}
-
+
@Test
public void testRoleEmailInterval() {
assertEquals(604800000L, defaultOrgWarnings.roleEmailInterval());
}
-
+
@Test
public void testRoleExpirationWarning() {
assertEquals(2592000000L, defaultOrgWarnings.roleExpirationWarning());