1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.test;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
21 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
23 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
24 import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
25 import org.kuali.rice.krms.impl.repository.TermBoService;
26 import org.kuali.rice.test.BaselineTestCase;
27
28 import java.util.Arrays;
29 import java.util.Collections;
30
31 import static org.junit.Assert.*;
32
33 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
34 public class TermBoServiceTest extends AbstractBoTest {
35
36 TermBoService termBoService = null;
37
38 @Override
39 @Before
40 public void setUp() throws Exception {
41 super.setUp();
42 termBoService = KrmsRepositoryServiceLocator.getTermBoService();
43 }
44
45
46
47
48
49 @Test
50 public void testGetTermSpecificationById_nullOrBlank() {
51 for (String id : Arrays.asList(null, "", " ")) {
52 try {
53 termBoService.getTermSpecificationById(id);
54 fail("getTermSpecificationById should have thrown " + RiceIllegalArgumentException.class.getSimpleName()
55 + " for invalid id=" + id + ".");
56 } catch (RiceIllegalArgumentException e) {
57
58 }
59 }
60 }
61
62
63
64
65
66 @Test
67 public void testGetTermSpecificationById_invalid() {
68 TermSpecificationDefinition termSpecificationDefinition = termBoService.getTermSpecificationById("1");
69 assertNull("getTermSpecificationById should have returned null with no error", termSpecificationDefinition);
70 }
71
72
73
74
75
76 @Test
77 public void testGetTermSpecificationById_valid() {
78 TermSpecificationDefinition.Builder termSpecBuilder =
79 TermSpecificationDefinition.Builder.create(null, "1", "testTermSpec", "java.lang.String");
80 TermSpecificationDefinition termSpecificationDefinition
81 = termBoService.createTermSpecification(termSpecBuilder.build());
82
83 TermSpecificationDefinition fetchedTermSpec
84 = termBoService.getTermSpecificationById(termSpecificationDefinition.getId());
85
86 assertNotNull("getTermSpecificationById should not have returned null", fetchedTermSpec);
87 }
88
89 @Test
90 public void testPersistTermSpecificationContextIds() {
91 ContextDefinition context1 = createContextDefinition("KR-SAP", "TermBoServiceTest-Context1", Collections.<String,String>emptyMap());
92 ContextDefinition context2 = createContextDefinition("KR-SAP", "TermBoServiceTest-Context2", Collections.<String,String>emptyMap());
93
94 termBoService = GlobalResourceLoader.getService("termBoService");
95
96 TermSpecificationDefinition.Builder termSpecBuilder =
97 TermSpecificationDefinition.Builder.create(null, "1", "testTermSpec", "java.lang.String");
98
99 termSpecBuilder.getContextIds().add(context1.getId());
100 termSpecBuilder.getContextIds().add(context2.getId());
101
102 TermSpecificationDefinition termSpecificationDefinition = termBoService.createTermSpecification(termSpecBuilder.build());
103
104 assertNotNull(termSpecificationDefinition);
105 assertTrue(termSpecificationDefinition.getContextIds().size() == 2);
106 for (String contextId : Arrays.asList(context1.getId(), context2.getId())) {
107 assertTrue(termSpecificationDefinition.getContextIds().contains(contextId));
108 }
109
110 TermSpecificationDefinition fetchedTermSpec = termBoService.getTermSpecificationById(termSpecificationDefinition.getId());
111
112 for (String contextId : Arrays.asList(context1.getId(), context2.getId())) {
113 assertTrue("https://jira.kuali.org/browse/KULRICE-9850 ", fetchedTermSpec.getContextIds().contains(contextId));
114 }
115 }
116
117 }