1 package org.rice.krms.test;
2
3 import java.util.Collections;
4
5 import org.junit.Before;
6 import org.junit.Test;
7 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
8 import org.kuali.rice.krms.api.repository.term.TermDefinition;
9 import org.kuali.rice.krms.api.repository.term.TermParameterDefinition;
10 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
11 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
12 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
13 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
14 import org.kuali.rice.krms.impl.repository.ContextBoService;
15 import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl;
16 import org.kuali.rice.krms.impl.repository.KrmsTypeBoServiceImpl;
17 import org.kuali.rice.krms.impl.repository.TermBoService;
18 import org.kuali.rice.krms.impl.repository.TermBoServiceImpl;
19 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
20 import org.kuali.rice.test.BaselineTestCase.Mode;
21
22 @BaselineMode(Mode.CLEAR_DB)
23 public class TermRelatedBoTest extends AbstractBoTest {
24
25 private TermBoService termBoService;
26 private ContextBoService contextRepository;
27 private KrmsTypeRepositoryService krmsTypeRepository;
28
29 @Before
30 public void setup() {
31 super.setup();
32
33
34
35 termBoService = new TermBoServiceImpl();
36 ((TermBoServiceImpl)termBoService).setBusinessObjectService(getBoService());
37
38 contextRepository = new ContextBoServiceImpl();
39 ((ContextBoServiceImpl)contextRepository).setBusinessObjectService(getBoService());
40
41 krmsTypeRepository = new KrmsTypeBoServiceImpl();
42 ((KrmsTypeBoServiceImpl)krmsTypeRepository).setBusinessObjectService(getBoService());
43 }
44
45 @Test
46 public void creationTest() {
47
48
49 KrmsTypeDefinition krmsContextTypeDefinition = KrmsTypeDefinition.Builder.create(null, "KrmsTestContextType", "KRMS").build();
50 krmsContextTypeDefinition = krmsTypeRepository.createKrmsType(krmsContextTypeDefinition);
51
52
53 ContextDefinition.Builder contextBuilder = ContextDefinition.Builder.create("KRMS", "testContext");
54 contextBuilder.setTypeId(krmsContextTypeDefinition.getId());
55 ContextDefinition contextDefinition = contextBuilder.build();
56 contextDefinition = contextRepository.createContext(contextDefinition);
57
58
59 TermSpecificationDefinition outputTermSpec =
60 TermSpecificationDefinition.Builder.create(null, "outputTermSpec", contextDefinition.getId(),
61 "java.lang.String").build();
62 outputTermSpec = termBoService.createTermSpecification(outputTermSpec);
63
64
65 TermSpecificationDefinition prereqTermSpec =
66 TermSpecificationDefinition.Builder.create(null, "prereqTermSpec", contextDefinition.getId(),
67 "java.lang.String").build();
68 prereqTermSpec = termBoService.createTermSpecification(prereqTermSpec);
69
70
71 KrmsTypeDefinition krmsTermResolverTypeDefinition = KrmsTypeDefinition.Builder.create(null, "KrmsTestResolverType", "KRMS").build();
72 krmsTermResolverTypeDefinition = krmsTypeRepository.createKrmsType(krmsTermResolverTypeDefinition);
73
74
75 TermResolverDefinition termResolverDef =
76 TermResolverDefinition.Builder.create(null, "KRMS", "testResolver", krmsTermResolverTypeDefinition.getId(),
77 TermSpecificationDefinition.Builder.create(outputTermSpec),
78 Collections.singleton(TermSpecificationDefinition.Builder.create(prereqTermSpec)),
79 null,
80 Collections.singleton("testParamName")).build();
81 termResolverDef = termBoService.createTermResolver(termResolverDef);
82
83
84 TermParameterDefinition.Builder termParamBuilder =
85 TermParameterDefinition.Builder.create(null, null, "testParamName", "testParamValue");
86
87
88 TermDefinition termDefinition =
89 TermDefinition.Builder.create(null, TermSpecificationDefinition.Builder.create(outputTermSpec), Collections.singletonList(termParamBuilder)).build();
90 termBoService.createTermDefinition(termDefinition);
91 }
92
93 }