1 package org.kuali.student.enrollment.class2.courseoffering.krms.naturallanguage.context; 2 3 import org.junit.Assert; 4 import org.junit.Before; 5 import org.junit.Test; 6 import org.kuali.student.common.test.spring.AbstractServiceTest; 7 import org.kuali.student.common.test.spring.Client; 8 import org.kuali.student.common.test.spring.Dao; 9 import org.kuali.student.common.test.spring.Daos; 10 import org.kuali.student.common.test.spring.PersistenceFileLocation; 11 import org.kuali.student.r2.core.krms.naturallanguage.TermParameterTypes; 12 import org.kuali.student.r2.common.exceptions.OperationFailedException; 13 import org.kuali.student.r2.core.organization.dto.OrgInfo; 14 import org.kuali.student.r2.core.organization.service.OrganizationService; 15 16 import java.util.HashMap; 17 import java.util.Map; 18 19 @Daos( { @Dao(value = "org.kuali.student.r1.core.organization.dao.impl.OrganizationDaoImpl", testSqlFile = "classpath:ks-org.sql") }) 20 @PersistenceFileLocation("classpath:META-INF/organization-persistence.xml") 21 public class OrganizationContextImplTest extends AbstractServiceTest { 22 23 @Client(value = "org.kuali.student.r2.core.class1.organization.service.impl.OrganizationServiceImpl", additionalContextFile = "classpath:nl-test-context.xml") 24 private OrganizationService orgService; 25 private OrganizationContextImpl orgContext = new OrganizationContextImpl(); 26 27 private Map<String, Object> term; 28 private Map<String, Object> term2; 29 30 private void setupTerm1() { 31 Map<String, Object> parameters = new HashMap<String, Object>(); 32 parameters.put(TermParameterTypes.ORGANIZATION_KEY.getId(),"1"); 33 term = parameters; 34 } 35 36 private void setupTerm2() { 37 Map<String, Object> parameters = new HashMap<String, Object>(); 38 parameters.put(TermParameterTypes.ORGANIZATION_KEY.getId(),null); 39 term2 = parameters; 40 } 41 42 @Before 43 public void beforeMethod() { 44 orgContext.setOrganizationService(orgService); 45 setupTerm1(); 46 setupTerm2(); 47 } 48 49 @Test 50 public void testCreateContextMap_Org() throws OperationFailedException { 51 Map<String, Object> contextMap = orgContext.createContextMap(term); 52 OrgInfo org = (OrgInfo) contextMap.get(OrganizationContextImpl.ORG_TOKEN); 53 54 Assert.assertNotNull(contextMap); 55 Assert.assertEquals("1", org.getId()); 56 57 Assert.assertEquals("KUSystem", org.getShortName()); 58 Assert.assertEquals("Kuali University System", org.getLongName()); 59 } 60 61 @Test 62 public void testCreateContextMap_NullTokenValues() { 63 Map<String, Object> contextMap = orgContext.createContextMap(term2); 64 OrgInfo org = (OrgInfo) contextMap.get(OrganizationContextImpl.ORG_TOKEN); 65 66 Assert.assertNotNull(contextMap); 67 Assert.assertEquals(null, org); 68 } 69 70 }