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 java.util.Collections;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
23 import org.kuali.rice.krad.data.DataObjectService;
24 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
25 import org.kuali.rice.krms.api.repository.term.TermDefinition;
26 import org.kuali.rice.krms.api.repository.term.TermParameterDefinition;
27 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
28 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
29 import org.kuali.rice.krms.api.repository.type.KrmsTypeBoService;
30 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
31 import org.kuali.rice.krms.impl.repository.ContextBoService;
32 import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl;
33 import org.kuali.rice.krms.impl.repository.KrmsTypeBoServiceImpl;
34 import org.kuali.rice.krms.impl.repository.TermBoService;
35 import org.kuali.rice.krms.impl.repository.TermBoServiceImpl;
36 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
37 import org.kuali.rice.test.BaselineTestCase.Mode;
38
39 @BaselineMode(Mode.CLEAR_DB)
40 public class TermRelatedBoTest extends AbstractBoTest {
41
42 private TermBoService termBoService;
43 private ContextBoService contextRepository;
44 private KrmsTypeBoService krmsTypeBoService;
45
46 @Before
47 public void setup() {
48
49
50
51 termBoService = new TermBoServiceImpl();
52
53
54 ((TermBoServiceImpl)termBoService).setDataObjectService(GlobalResourceLoader.<DataObjectService>getService(
55 "dataObjectService"));
56
57 contextRepository = new ContextBoServiceImpl();
58 ((ContextBoServiceImpl)contextRepository).setDataObjectService(getDataObjectService());
59
60 krmsTypeBoService = new KrmsTypeBoServiceImpl();
61 ((KrmsTypeBoServiceImpl)krmsTypeBoService).setDataObjectService(getDataObjectService());
62 }
63
64 @Test
65 public void creationTest() {
66
67
68 KrmsTypeDefinition krmsContextTypeDefinition = KrmsTypeDefinition.Builder.create("KrmsTestContextType", "KRMS").build();
69 krmsContextTypeDefinition = krmsTypeBoService.createKrmsType(krmsContextTypeDefinition);
70
71
72 ContextDefinition.Builder contextBuilder = ContextDefinition.Builder.create("KRMS", "testContext");
73 contextBuilder.setTypeId(krmsContextTypeDefinition.getId());
74 ContextDefinition contextDefinition = contextBuilder.build();
75 contextDefinition = contextRepository.createContext(contextDefinition);
76
77
78 TermSpecificationDefinition outputTermSpec =
79 TermSpecificationDefinition.Builder.create(null, "outputTermSpec", contextDefinition.getId(),
80 "java.lang.String").build();
81 outputTermSpec = termBoService.createTermSpecification(outputTermSpec);
82
83
84 TermSpecificationDefinition prereqTermSpec =
85 TermSpecificationDefinition.Builder.create(null, "prereqTermSpec", contextDefinition.getId(),
86 "java.lang.String").build();
87 prereqTermSpec = termBoService.createTermSpecification(prereqTermSpec);
88
89
90 KrmsTypeDefinition krmsTermResolverTypeDefinition = KrmsTypeDefinition.Builder.create("KrmsTestResolverType", "KRMS").build();
91 krmsTermResolverTypeDefinition = krmsTypeBoService.createKrmsType(krmsTermResolverTypeDefinition);
92
93
94 TermResolverDefinition termResolverDef =
95 TermResolverDefinition.Builder.create(null, "KRMS", "testResolver", krmsTermResolverTypeDefinition.getId(),
96 TermSpecificationDefinition.Builder.create(outputTermSpec),
97 Collections.singleton(TermSpecificationDefinition.Builder.create(prereqTermSpec)),
98 null,
99 Collections.singleton("testParamName")).build();
100 termResolverDef = termBoService.createTermResolver(termResolverDef);
101
102
103 TermParameterDefinition.Builder termParamBuilder =
104 TermParameterDefinition.Builder.create(null, null, "testParamName", "testParamValue");
105
106
107 TermDefinition termDefinition =
108 TermDefinition.Builder.create(null, TermSpecificationDefinition.Builder.create(outputTermSpec), Collections.singletonList(termParamBuilder)).build();
109 termBoService.createTerm(termDefinition);
110 }
111
112 }