Hello all,
I created a method to check to see is a user already has an id. I have mocked up the data and when I run the test I get an error that makes no since. Any idea what I am doing wrong? If I remove the method then I can build successfully.
Logs:
[ERROR] Errors:
[ERROR] SamAccountNameGeneratorTest.testSamAccountNameGenerator:51 » Parse In file: inline evaluation of: `` import java.util.Map; import org.apache.log4j.LogManager; import org.a . . . '' Encountered "," at line 70, column 19.
[ERROR] SamAccountNameGeneratorTest.testSamAccountNameGeneratorExist:81 » Parse In file: inline evaluation of: `` import java.util.Map; import org.apache.log4j.LogManager; import org.a . . . '' Encountered "," at line 70, column 19.
[ERROR] SamAccountNameGeneratorTest.testSamAccountNameGeneratorExist2:112 » Parse In file: inline evaluation of: `` import java.util.Map; import org.apache.log4j.LogManager; import org.a . . . '' Encountered "," at line 70, column 19.
[ERROR] SamAccountNameGeneratorTest.testSamAccountNameGeneratorExist3:144 » Parse In file: inline evaluation of: `` import java.util.Map; import org.apache.log4j.LogManager; import org.a . . . '' Encountered "," at line 70, column 19.
[ERROR] SamAccountNameGeneratorTest.testSamAccountNameGeneratorExist4:177 » Parse In file: inline evaluation of: `` import java.util.Map; import org.apache.log4j.LogManager; import org.a . . . '' Encountered "," at line 70, column 19.
[ERROR] SamAccountNameGeneratorTest.testSamAccountNameGeneratorWorkday:245 » Parse In file: inline evaluation of: `` import java.util.Map; import org.apache.log4j.LogManager; import org.a . . . '' Encountered "," at line 70, column 19.
Method:
public String checkWorkday(String firstName, String lastName, String last4) throws GeneralException{
Map<String, Object> workdayAccountInfo = workdayAccount.getAttributes();
if(workdayAccountInfo.get("FIRST_NAME") == firstName && workdayAccountInfo.get("LAST_NAME") == lastName && workdayAccountInfo.get("Last 4 digits of SSN__c") == last4){
return workdayAccountInfo.get("USERID").toString();
}
else{
return new String();
}
}
Mock:
@Test
public void testSamAccountNameGeneratorWorkday() throws GeneralException, EvalError{
Interpreter i = new Interpreter();
IdnRuleUtil idn = mock();
when(idn.accountExistsByDisplayName(any(), any())).thenReturn(false);
Application application = mock(Application.class);
when(application.getName()).thenReturn("Active Directory [source]");
Application workday = mock(Application.class);
when(workday.getName()).thenReturn("Workday [source]");
Map<String, Object> workdayMap = new HashMap<String, Object>();
workdayMap.put("USERID", "tsmith02");
workdayMap.put("FIRST_NAME", "Tyler");
workdayMap.put("LAST_NAME", "Smith");
workdayMap.put("BRITH_DATE__c", "2001-01-01");
workdayMap.put("FILENAME", "102698");
workdayMap.put("Last 4 digits of SSN__c", "1234");
Map<String, Object> snowMap = new HashMap<String, Object>();
snowMap.put("first_name", "Tyler");
snowMap.put("last_name", "Smith");
snowMap.put("user_name", "tsmith02");
snowMap.put("employee_number", "102698");
Map<String, Object> adMap = new HashMap<String, Object>();
adMap.put("givenName", "Tyler");
adMap.put("sn", "Smith");
adMap.put("employeeNumber", "102689");
adMap.put("samAccountName", "tsmith02");
Account workdayAccount = mock(Account.class);
when(workdayAccount.getAttributes()).thenReturn(workdayMap);
Account snowAccount = mock(Account.class);
when(snowAccount.getAttributes()).thenReturn(snowMap);
Account adAccount = mock(Account.class);
when(adAccount.getAttributes()).thenReturn(adMap);
Application serviceNow = mock(Application.class);
when(serviceNow.getName()).thenReturn("ServiceNow [source]");
Identity identity = mock(Identity.class);
when(identity.getFirstname()).thenReturn("Tyler");
when(identity.getLastname()).thenReturn("Smith");
when(identity.getStringAttribute("last4")).thenReturn("1234");
String result = "";
i.set("log", log);
i.set("idn", idn);
i.set("application", application);
i.set("workday", workday);
i.set("servicenow", serviceNow);
i.set("identity", identity);
String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
result = (String) i.eval(source);
assertNotNull(result);
assertEquals(result, "tsmith02");
log.info("Beanshell script returned: " + result);
}