View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.resourceloader.GlobalResourceLoader;
21  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
22  import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
23  import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
24  import org.kuali.rice.krms.impl.repository.TermBoService;
25  import org.kuali.rice.test.BaselineTestCase;
26  
27  import java.util.Arrays;
28  import java.util.Collections;
29  
30  import static org.junit.Assert.assertNotNull;
31  import static org.junit.Assert.assertTrue;
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  	@Test
46  	public void testPersistTermSpecificationContextIds() {
47  
48          ContextDefinition context1 = createContextDefinition("KR-SAP", "TermBoServiceTest-Context1", Collections.<String,String>emptyMap());
49          ContextDefinition context2 = createContextDefinition("KR-SAP", "TermBoServiceTest-Context2", Collections.<String,String>emptyMap());
50  
51          termBoService = GlobalResourceLoader.getService("termBoService");
52  
53  		TermSpecificationDefinition.Builder termSpecBuilder =
54  			TermSpecificationDefinition.Builder.create(null, "1", "testTermSpec", "java.lang.String");
55  
56          termSpecBuilder.getContextIds().add(context1.getId());
57          termSpecBuilder.getContextIds().add(context2.getId());
58  
59          TermSpecificationDefinition termSpecificationDefinition = termBoService.createTermSpecification(termSpecBuilder.build());
60  
61          assertNotNull(termSpecificationDefinition);
62          assertTrue(termSpecificationDefinition.getContextIds().size() == 2);
63          for (String contextId : Arrays.asList(context1.getId(), context2.getId())) {
64              assertTrue(termSpecificationDefinition.getContextIds().contains(contextId));
65          }
66  
67          TermSpecificationDefinition fetchedTermSpec = termBoService.getTermSpecificationById(termSpecificationDefinition.getId());
68  
69          for (String contextId : Arrays.asList(context1.getId(), context2.getId())) {
70              assertTrue(fetchedTermSpec.getContextIds().contains(contextId));
71          }
72  	}
73  	
74  }