1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.kuali.rice.core.api.criteria.GenericQueryResults;
22 import org.kuali.rice.krad.data.DataObjectService;
23 import org.kuali.rice.krad.data.PersistenceOption;
24 import org.kuali.rice.krms.api.repository.KrmsTypeGenTest;
25 import org.kuali.rice.krms.api.repository.ReferenceObjectBindingGenTest;
26 import org.kuali.rice.krms.api.repository.reference.ReferenceObjectBinding;
27 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
28 import org.mockito.Mock;
29 import org.mockito.MockitoAnnotations;
30 import org.mockito.runners.MockitoJUnitRunner;
31
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertNotNull;
34 import static org.junit.Assert.assertNull;
35 import static org.mockito.Matchers.any;
36 import static org.mockito.Mockito.mock;
37 import static org.mockito.Mockito.when;
38
39
40
41
42
43 @RunWith(MockitoJUnitRunner.class)
44 public class ReferenceObjectBindingBoServiceImplGenTest {
45 private ReferenceObjectBindingBoServiceImpl service;
46 private ReferenceObjectBinding referenceObjectBinding;
47 private DataObjectService mockDataObjectService;
48
49 public ReferenceObjectBindingBoServiceImplGenTest() {
50 mockDataObjectService = mock(DataObjectService.class);
51 }
52
53 @Before
54 public void setUp() {
55 service = new ReferenceObjectBindingBoServiceImpl();
56 service.setDataObjectService(mockDataObjectService);
57 }
58
59 @Test
60 public void test_updateReferenceObjectBinding_success() {
61 final ReferenceObjectBinding data = ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding();
62 final ReferenceObjectBinding findResult = ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding();
63 final ReferenceObjectBindingBo saveResult = service.from(ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding());
64 when(mockDataObjectService.find(any(Class.class), any(String.class))).thenReturn(service.from(findResult));
65 when(mockDataObjectService.save(any(ReferenceObjectBindingBo.class), any(PersistenceOption.class))).thenReturn(saveResult);
66 ReferenceObjectBinding updatedData = service.updateReferenceObjectBinding(data);
67 assertNotNull(updatedData);
68 }
69
70 @Test
71 public void test_from_null_yields_null() {
72 assertNull(service.from(null));
73 }
74
75 @Test
76 public void test_from() {
77 ReferenceObjectBinding def = ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding();
78 ReferenceObjectBindingBo def2 = service.from(def);
79 assertEquals(def2.getKrmsDiscriminatorType(),def.getKrmsDiscriminatorType());
80 assertEquals(def2.getKrmsObjectId(),def.getKrmsObjectId());
81 assertEquals(def2.getNamespace(),def.getNamespace());
82 assertEquals(def2.getReferenceDiscriminatorType(),def.getReferenceDiscriminatorType());
83 assertEquals(def2.getReferenceObjectId(),def.getReferenceObjectId());
84 assertEquals(def2.getId(),def.getId());
85 }
86
87 @Test
88 public void test_to() {
89 ReferenceObjectBinding def = ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding();
90 ReferenceObjectBindingBo referenceObjectBindingBo = service.from(def);
91 ReferenceObjectBinding def2 = ReferenceObjectBindingBo.to(referenceObjectBindingBo);
92 assertEquals(def, def2);
93 }
94
95 @Test
96 public void test_createReferenceObjectBinding_success() {
97 final ReferenceObjectBinding findResult = null;
98 final ReferenceObjectBindingBo saveResult = service.from(ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding());
99 when(mockDataObjectService.find(any(Class.class), any(String.class))).thenReturn(service.from(findResult));
100 when(mockDataObjectService.save(any(ReferenceObjectBindingBo.class), any(PersistenceOption.class))).thenReturn(saveResult);
101 ReferenceObjectBinding def = ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding();
102 ReferenceObjectBinding referenceObjectBinding = service.createReferenceObjectBinding(def);
103 assertNotNull(referenceObjectBinding);
104 }
105
106 @Test(expected = IllegalArgumentException.class)
107 public void test_findReferenceObjectBindingsByCollectionName_null_fail() {
108 service.findReferenceObjectBindingsByCollectionName(null);
109 }
110
111 @Test(expected = IllegalArgumentException.class)
112 public void test_findReferenceObjectBindingsByKrmsDiscriminatorType_null_fail() {
113 service.findReferenceObjectBindingsByKrmsDiscriminatorType(null);
114 }
115
116 @Test(expected = IllegalArgumentException.class)
117 public void test_findReferenceObjectBindingsByKrmsObject_null_fail() {
118 service.findReferenceObjectBindingsByKrmsObject(null);
119 }
120
121 @Test(expected = IllegalArgumentException.class)
122 public void test_findReferenceObjectBindingsByNamespace_null_fail() {
123 service.findReferenceObjectBindingsByNamespace(null);
124 }
125
126 @Test(expected = IllegalArgumentException.class)
127 public void test_findReferenceObjectBindingsByReferenceDiscriminatorType_null_fail() {
128 service.findReferenceObjectBindingsByReferenceDiscriminatorType(null);
129 }
130
131 @Test(expected = IllegalArgumentException.class)
132 public void test_findReferenceObjectBindingsByReferenceObject_null_fail() {
133 service.findReferenceObjectBindingsByReferenceObject(null);
134 }
135
136 @Test(expected = IllegalArgumentException.class)
137 public void test_createReferenceObjectBinding_null_fail() {
138 service.createReferenceObjectBinding(null);
139 }
140
141 @Test(expected = IllegalArgumentException.class)
142 public void test_updateReferenceObjectBinding_null_fail() {
143 service.updateReferenceObjectBinding(null);
144 }
145
146 @Test(expected = IllegalArgumentException.class)
147 public void test_deleteReferenceObjectBinding_null_fail() {
148 service.deleteReferenceObjectBinding(null);
149 }
150
151 @Test
152 public void test_createReferenceObjectBinding() {
153 ReferenceObjectBinding def = ReferenceObjectBindingGenTest.buildFullReferenceObjectBinding();
154 referenceObjectBinding = service.createReferenceObjectBinding(def);
155 }
156
157 public ReferenceObjectBinding getReferenceObjectBinding() {
158 return referenceObjectBinding;
159 }
160
161 public void setReferenceObjectBindingBoServiceImpl(ReferenceObjectBindingBoServiceImpl impl) {
162 this.service = impl;
163 }
164
165 public static ReferenceObjectBindingBoServiceImplGenTest create(ReferenceObjectBindingBoServiceImpl impl) {
166 ReferenceObjectBindingBoServiceImplGenTest test = new ReferenceObjectBindingBoServiceImplGenTest();
167 test.setReferenceObjectBindingBoServiceImpl(impl);
168 return test;
169 }
170 }