1 package org.kuali.ole.patron.bo;
2
3 import org.junit.Test;
4 import org.junit.runner.RunWith;
5 import org.kuali.rice.kim.api.identity.IdentityService;
6 import org.kuali.rice.kim.api.identity.entity.Entity;
7 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
8 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
9 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
10 import org.kuali.rice.krad.service.BusinessObjectService;
11 import org.kuali.rice.krad.service.KRADServiceLocator;
12 import org.springframework.test.context.ContextConfiguration;
13 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14 import org.springframework.test.context.transaction.TransactionConfiguration;
15 import org.springframework.transaction.annotation.Transactional;
16
17 import java.util.Arrays;
18
19 import static junit.framework.Assert.assertNotNull;
20
21
22
23
24
25
26
27
28
29
30 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
31 @RunWith(value = SpringJUnit4ClassRunner.class)
32 @TransactionConfiguration(defaultRollback = true)
33 public class OlePatron_UT {
34 @Test
35 @Transactional
36 public void createPatronRecord() throws Exception {
37 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
38 IdentityService identityService = KimApiServiceLocator.getIdentityService();
39
40 OleBorrowerType oleBorrowerType = new OleBorrowerType();
41 oleBorrowerType.setBorrowerTypeCode("mockBorrowerTypeCD");
42 oleBorrowerType.setBorrowerTypeDescription("mockDescription");
43 oleBorrowerType.setBorrowerTypeName("mockName");
44 oleBorrowerType.setActive(true);
45 OleBorrowerType savedBorrowerType = businessObjectService.save(oleBorrowerType);
46 assertNotNull(savedBorrowerType);
47 String oleBorrowerTypeId = savedBorrowerType.getBorrowerTypeId();
48 assertNotNull(oleBorrowerTypeId);
49
50 EntityBo entityBo = new EntityBo();
51 entityBo.setActive(Boolean.TRUE);
52 EntityNameBo entityNameBo = new EntityNameBo();
53 entityNameBo.setFirstName("mockFirstName");
54 entityBo.setNames(Arrays.asList(entityNameBo));
55 Entity entity = identityService.createEntity(EntityBo.to(entityBo));
56 assertNotNull(entity.getId());
57
58 OlePatronBo olePatronBo = new OlePatronBo();
59 olePatronBo.setEntityId(entity.getId());
60 olePatronBo.setBarcode("mockBarcode");
61 olePatronBo.setBorrowerType(oleBorrowerTypeId);
62
63 OlePatronBo savedPatronBo = businessObjectService.save(olePatronBo);
64 assertNotNull(savedPatronBo);
65 assertNotNull(savedPatronBo.getOlePatronId());
66
67
68 }
69 }
70