summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--auth/auth-deforg/pom.xml20
-rw-r--r--auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrg.java82
-rw-r--r--auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgIdentity.java11
-rw-r--r--auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgWarnings.java50
-rw-r--r--auth/auth-deforg/src/main/java/org/onap/aaf/org/Identities.java60
-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
-rw-r--r--auth/auth-deforg/src/test/resources/identities.dat7
-rw-r--r--auth/auth-deforg/src/test/resources/identities.idxbin0 -> 56 bytes
-rw-r--r--auth/auth-deforg/src/test/resources/test.txt0
11 files changed, 388 insertions, 186 deletions
diff --git a/auth/auth-deforg/pom.xml b/auth/auth-deforg/pom.xml
index d282819b..034c0b96 100644
--- a/auth/auth-deforg/pom.xml
+++ b/auth/auth-deforg/pom.xml
@@ -76,13 +76,13 @@
<!-- SONAR -->
<!-- <sonar.skip>true</sonar.skip> -->
<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.reportPaths>target/code-coverage/jacoco-ut.exec</sonar.jacoco.reportPaths>
- <sonar.jacoco.itReportPaths>target/code-coverage/jacoco-it.exec</sonar.jacoco.itReportPaths>
- <!-- Note: This list should match jacoco-maven-plugin's exclusion list below -->
- <sonar.exclusions>**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**</sonar.exclusions>
+ <sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
+ <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
+ <!-- Default Sonar configuration -->
+ <sonar.jacoco.reportPaths>target/code-coverage/jacoco-ut.exec</sonar.jacoco.reportPaths>
+ <sonar.jacoco.itReportPaths>target/code-coverage/jacoco-it.exec</sonar.jacoco.itReportPaths>
+ <!-- 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>
@@ -108,6 +108,12 @@
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.jvnet.mock-javamail</groupId>
+ <artifactId>mock-javamail</artifactId>
+ <version>1.9</version>
+ </dependency>
</dependencies>
<build>
diff --git a/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrg.java b/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrg.java
index ac2105f6..3d42b63c 100644
--- a/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrg.java
+++ b/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrg.java
@@ -7,9 +7,9 @@
* * 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.
@@ -21,8 +21,7 @@
******************************************************************************/
package org.onap.aaf.org;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -54,11 +53,13 @@ public class DefaultOrg implements Organization {
final String domain;
final String atDomain;
final String realm;
-
+
private final String NAME,mailHost,mailFrom;
private final Set<String> supportedRealms;
+
public DefaultOrg(Env env, String realm) throws OrganizationException {
+
this.realm = realm;
supportedRealms=new HashSet<String>();
supportedRealms.add(realm);
@@ -74,7 +75,7 @@ public class DefaultOrg implements Organization {
if(mailFrom==null) {
throw new OrganizationException(s + PROPERTY_IS_REQUIRED);
}
-
+
System.getProperties().setProperty("mail.smtp.host",mailHost);
System.getProperties().setProperty("mail.user", mailFrom);
// Get the default Session object.
@@ -90,6 +91,7 @@ public class DefaultOrg implements Organization {
env.warn().log(defFile, " is not defined. Using default: ",temp+"/identities.dat");
File dir = new File(temp);
fIdentities=new File(dir,"identities.dat");
+
if(!fIdentities.exists()) {
env.warn().log("No",fIdentities.getCanonicalPath(),"exists. Creating.");
if(!dir.exists()) {
@@ -107,7 +109,7 @@ public class DefaultOrg implements Organization {
}
}
}
-
+
if(fIdentities!=null && fIdentities.exists()) {
identities = new Identities(fIdentities);
} else {
@@ -121,7 +123,7 @@ public class DefaultOrg implements Organization {
throw new OrganizationException(e);
}
}
-
+
// Implement your own Delegation System
static final List<String> NULL_DELEGATES = new ArrayList<String>();
@@ -130,14 +132,14 @@ public class DefaultOrg implements Organization {
private Session session;
public enum Types {Employee, Contractor, Application, NotActive};
private final static Set<String> typeSet;
-
+
static {
typeSet = new HashSet<String>();
for(Types t : Types.values()) {
typeSet.add(t.name());
}
}
-
+
private static final EmailWarnings emailWarnings = new DefaultOrgWarnings();
@Override
@@ -158,10 +160,11 @@ public class DefaultOrg implements Organization {
@Override
public DefaultOrgIdentity getIdentity(AuthzTrans trans, String id) throws OrganizationException {
int at = id.indexOf('@');
+ String attt = at<0?id:id.substring(0, at);
return new DefaultOrgIdentity(trans,at<0?id:id.substring(0, at),this);
}
- // Note: Return a null if found; return a String Message explaining why not found.
+ // Note: Return a null if found; return a String Message explaining why not found.
@Override
public String isValidID(final AuthzTrans trans, final String id) {
try {
@@ -185,18 +188,18 @@ public class DefaultOrg implements Organization {
// if(!id.regionMatches(at+1, domain, 0, id.length()-at-1)) {
// return false;
// }
- sid = id.substring(0,at);
+ sid = id.substring(0,at);
} else {
sid = id;
}
// We'll validate that it exists, rather than check patterns.
-
+
return isValidID(trans, sid)==null;
// Check Pattern (if checking existing is too long)
// if(id.endsWith(SUFFIX) && ID_PATTERN.matcher(id).matches()) {
// return true;
// }
- // return false;
+ // return false;
}
private static final String SPEC_CHARS = "!@#$%^*-+?/,:;.";
@@ -327,6 +330,7 @@ public class DefaultOrg implements Organization {
+ "Please follow this link: \n\n\t" + url
+ "\n\n" + summary, urgent);
} catch (Exception e) {
+
trans.error().log(e, "Failure to send Email");
return Response.ERR_NotificationFailure;
}
@@ -386,8 +390,9 @@ public class DefaultOrg implements Organization {
@Override
public int sendEmail(AuthzTrans trans, List<String> toList, List<String> ccList, String subject, String body,
Boolean urgent) throws OrganizationException {
+
int status = 1;
-
+
List<String> to = new ArrayList<String>();
for(String em : toList) {
if(em.indexOf('@')<0) {
@@ -396,11 +401,11 @@ public class DefaultOrg implements Organization {
to.add(em);
}
}
-
+
List<String> cc = new ArrayList<String>();
if(ccList!=null) {
if(!ccList.isEmpty()) {
-
+
for(String em : ccList) {
if(em.indexOf('@')<0) {
cc.add(new DefaultOrgIdentity(trans, em, this).email());
@@ -409,7 +414,7 @@ public class DefaultOrg implements Organization {
}
}
}
-
+
// for now, I want all emails so we can see what goes out. Remove later
if (!ccList.contains(mailFrom)) {
ccList.add(mailFrom);
@@ -444,6 +449,7 @@ public class DefaultOrg implements Organization {
// Now set the actual message
message.setText(body);
} else {
+
// override recipients
message.addRecipients(Message.RecipientType.TO,
InternetAddress.parse(mailFrom));
@@ -480,11 +486,13 @@ public class DefaultOrg implements Organization {
status = 0;
} catch (MessagingException mex) {
+ System.out.println("Error messaging: "+ mex.getMessage());
+ System.out.println("Error messaging: "+ mex.toString());
throw new OrganizationException("Exception send email message "
+ mex.getMessage());
}
- return status;
+ return status;
}
/**
@@ -507,8 +515,8 @@ public class DefaultOrg implements Organization {
@Override
public GregorianCalendar expiration(GregorianCalendar gc, Expiration exp, String... extra) {
- GregorianCalendar now = new GregorianCalendar();
- GregorianCalendar rv = gc==null?now:(GregorianCalendar)gc.clone();
+ GregorianCalendar now = new GregorianCalendar();
+ GregorianCalendar rv = gc==null?now:(GregorianCalendar)gc.clone();
switch (exp) {
case ExtendPassword:
// Extending Password give 5 extra days, max 8 days from now
@@ -573,7 +581,7 @@ public class DefaultOrg implements Organization {
orgIdentitys.add(supervisor);
}
}
- return orgIdentitys;
+ return orgIdentitys;
}
@Override
@@ -590,7 +598,7 @@ public class DefaultOrg implements Organization {
@Override
public boolean canHaveMultipleCreds(String id) {
// External entities are likely mono-password... if you change it, it is a global change.
- // This is great for people, but horrible for Applications.
+ // This is great for people, but horrible for Applications.
//
// AAF's Password can have multiple Passwords, each with their own Expiration Date.
// For Default Org, we'll assume true for all, but when you add your external
@@ -621,13 +629,13 @@ public class DefaultOrg implements Organization {
}
}
return null;
-
+
case CREATE_MECHID_BY_PERM_ONLY:
return getName() + " only allows sponsors to create MechIDs";
-
+
default:
return policy.name() + " is unsupported at " + getName();
- }
+ }
}
@Override
@@ -650,9 +658,9 @@ public class DefaultOrg implements Organization {
return this.getAddresses(strAddress,";");
}
/**
- * Convert the delimiter String into Internet addresses with the
+ * Convert the delimiter String into Internet addresses with the
* delimiter of provided
- * @param strAddress
+ * @param strAddresses
* @param delimiter
* @return
*/
@@ -661,14 +669,14 @@ public class DefaultOrg implements Organization {
int count = 0;
for (String addr : strAddresses)
{
- try{
- addressArray[count] = new InternetAddress(addr);
- count++;
- }catch(Exception e){
- throw new OrganizationException("Failed to parse the email address "+ addr +": "+e.getMessage());
- }
- }
- return addressArray;
+ try{
+ addressArray[count] = new InternetAddress(addr);
+ count++;
+ }catch(Exception e){
+ throw new OrganizationException("Failed to parse the email address "+ addr +": "+e.getMessage());
+ }
+ }
+ return addressArray;
}
private String extractRealm(final String r) {
@@ -697,5 +705,5 @@ public class DefaultOrg implements Organization {
public synchronized void addSupportedRealm(final String r) {
supportedRealms.add(extractRealm(r));
}
-
+
}
diff --git a/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgIdentity.java b/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgIdentity.java
index f2fe686f..7aa57fd7 100644
--- a/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgIdentity.java
+++ b/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgIdentity.java
@@ -43,10 +43,10 @@ public class DefaultOrgIdentity implements Identity {
private static final String CONTRACTOR = "c";
private static final String EMPLOYEE = "e";
private static final String APPLICATION = "a";
- private static final String NON_ACTIVE = "n";
+ private static final String NON_ACTIVE = "n";
private final static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);
-
+
private DefaultOrg org;
//package on purpose
Data identity;
@@ -60,7 +60,7 @@ public class DefaultOrgIdentity implements Identity {
org.identities.open(trans, TIMEOUT);
try {
Reuse r = org.identities.reuse();
- int at = key.indexOf(dorg.atDomain);
+ int at = key.indexOf(dorg.getDomain());
String search;
if(at>=0) {
search = key.substring(0,at);
@@ -68,6 +68,9 @@ public class DefaultOrgIdentity implements Identity {
search = key;
}
identity = org.identities.find(search, r);
+
+
+
if(identity==null) {
identity = Identities.NO_DATA;
}
@@ -78,7 +81,7 @@ public class DefaultOrgIdentity implements Identity {
throw new OrganizationException(e);
}
}
-
+
@Override
public boolean equals(Object b) {
if(b instanceof DefaultOrgIdentity) {
diff --git a/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgWarnings.java b/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgWarnings.java
index c04707ee..97d0cef2 100644
--- a/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgWarnings.java
+++ b/auth/auth-deforg/src/main/java/org/onap/aaf/org/DefaultOrgWarnings.java
@@ -26,38 +26,38 @@ import org.onap.aaf.auth.org.EmailWarnings;
public class DefaultOrgWarnings implements EmailWarnings {
@Override
- public long credEmailInterval()
- {
- return 604800000L; // 7 days in millis 1000 * 86400 * 7
- }
-
+ public long credEmailInterval()
+ {
+ return 604800000L; // 7 days in millis 1000 * 86400 * 7
+ }
+
@Override
- public long roleEmailInterval()
- {
- return 604800000L; // 7 days in millis 1000 * 86400 * 7
- }
-
+ public long roleEmailInterval()
+ {
+ return 604800000L; // 7 days in millis 1000 * 86400 * 7
+ }
+
@Override
public long apprEmailInterval() {
- return 259200000L; // 3 days in millis 1000 * 86400 * 3
+ return 259200000L; // 3 days in millis 1000 * 86400 * 3
}
-
+
@Override
- public long credExpirationWarning()
- {
- return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
- }
-
+ public long credExpirationWarning()
+ {
+ return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
+ }
+
@Override
- public long roleExpirationWarning()
- {
- return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
- }
+ public long roleExpirationWarning()
+ {
+ return( 2592000000L ); // One month, in milliseconds 1000 * 86400 * 30 in milliseconds
+ }
@Override
- public long emailUrgentWarning()
- {
- return( 1209600000L ); // Two weeks, in milliseconds 1000 * 86400 * 14 in milliseconds
- }
+ public long emailUrgentWarning()
+ {
+ return( 1209600000L ); // Two weeks, in milliseconds 1000 * 86400 * 14 in milliseconds
+ }
}
diff --git a/auth/auth-deforg/src/main/java/org/onap/aaf/org/Identities.java b/auth/auth-deforg/src/main/java/org/onap/aaf/org/Identities.java
index f3067fe6..344d0552 100644
--- a/auth/auth-deforg/src/main/java/org/onap/aaf/org/Identities.java
+++ b/auth/auth-deforg/src/main/java/org/onap/aaf/org/Identities.java
@@ -55,8 +55,8 @@ import org.onap.aaf.auth.local.DataFile.Token.Field;
*/
public class Identities extends AbsData {
public final static Data NO_DATA = new Data();
-
- public Identities(File users) {
+
+ public Identities(File users) throws IOException {
super(users,'|',512,0);
}
@@ -81,7 +81,7 @@ public class Identities extends AbsData {
public final String email;
public final String status;
public final String responsibleTo;
-
+
private Data(Field f) {
f.reset();
id=f.next();
@@ -93,10 +93,10 @@ public class Identities extends AbsData {
status=f.next();
responsibleTo =f.next();
}
-
+
private Data() {
id = name = fname = lname =
- phone = email = status = responsibleTo
+ phone = email = status = responsibleTo
= "";
}
@@ -110,34 +110,34 @@ public class Identities extends AbsData {
status + '|' +
responsibleTo;
}
-
+
// Here, make up your own Methods which help you easily determine your Organization's structure
// in your Organization Object
- public boolean hasStatus(String possible) {
- return possible.contains(status);
- }
+ public boolean hasStatus(String possible) {
+ return possible.contains(status);
+ }
+
+ public boolean isEmployee() {
+ return "e".equals(status);
+ }
- public boolean isEmployee() {
- return "e".equals(status);
- }
-
- public boolean isContractor() {
- return "c".equals(status);
- }
-
- public boolean isApplication() {
- return "a".equals(status);
- }
+ public boolean isContractor() {
+ return "c".equals(status);
+ }
+
+ public boolean isApplication() {
+ return "a".equals(status);
+ }
}
-
- public Data find(Object key,Reuse r) throws IOException {
- r.reset();
- // These are new, to allow for Thread Safety
- int rec = ti.find(key,r,0);
- if(rec<0) {
- return null;
- }
- r.pos(rec);
+
+ public Data find(Object key,Reuse r) throws IOException {
+ r.reset();
+ // These are new, to allow for Thread Safety
+ int rec = ti.find(key,r,0);
+ if(rec<0) {
+ return null;
+ }
+ r.pos(rec);
return new Data(r.getFieldData());
- }
+ }
}
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());
diff --git a/auth/auth-deforg/src/test/resources/identities.dat b/auth/auth-deforg/src/test/resources/identities.dat
new file mode 100644
index 00000000..98bf99a3
--- /dev/null
+++ b/auth/auth-deforg/src/test/resources/identities.dat
@@ -0,0 +1,7 @@
+iowna|Ima D. Owner|Ima|Owner|314-123-2000|ima.d.owner@osaaf.com|e|
+mmanager|Mark D. Manager|Mark|Manager|314-123-1234|mark.d.manager@osaaf.com|e|iowna
+bdevl|Robert D. Developer|Bob|Developer|314-123-1235|bob.d.develper@osaaf.com|e|mmanager
+mmarket|Mary D. Marketer|Mary|Marketer|314-123-1236|mary.d.marketer@osaaf.com|e|mmanager
+ccontra|Clarice D. Contractor|Clarice|Contractor|314-123-1237|clarice.d.contractor@osaaf.com|c|mmanager
+iretired|Ira Lee M. Retired|Ira|Retired|314-123-1238|clarice.d.contractor@osaaf.com|n|mmanager
+osaaf|ID of AAF|||||a|bdevl
diff --git a/auth/auth-deforg/src/test/resources/identities.idx b/auth/auth-deforg/src/test/resources/identities.idx
new file mode 100644
index 00000000..78fc0a56
--- /dev/null
+++ b/auth/auth-deforg/src/test/resources/identities.idx
Binary files differ
diff --git a/auth/auth-deforg/src/test/resources/test.txt b/auth/auth-deforg/src/test/resources/test.txt
deleted file mode 100644
index e69de29b..00000000
--- a/auth/auth-deforg/src/test/resources/test.txt
+++ /dev/null