001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krms.test;
017    
018    import org.junit.Before;
019    import org.junit.Test;
020    import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
021    import org.kuali.rice.krms.api.repository.context.ContextDefinition;
022    import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
023    import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
024    import org.kuali.rice.krms.impl.repository.TermBoService;
025    import org.kuali.rice.test.BaselineTestCase;
026    
027    import java.util.Arrays;
028    import java.util.Collections;
029    
030    import static org.junit.Assert.assertNotNull;
031    import static org.junit.Assert.assertTrue;
032    
033    @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
034    public class TermBoServiceTest extends AbstractBoTest {
035            
036            TermBoService termBoService = null;
037    
038        @Override
039            @Before
040            public void setUp() throws Exception {
041            super.setUp();
042                    termBoService = KrmsRepositoryServiceLocator.getTermBoService();
043            }
044    
045            @Test
046            public void testPersistTermSpecificationContextIds() {
047    
048            ContextDefinition context1 = createContextDefinition("KR-SAP", "TermBoServiceTest-Context1", Collections.<String,String>emptyMap());
049            ContextDefinition context2 = createContextDefinition("KR-SAP", "TermBoServiceTest-Context2", Collections.<String,String>emptyMap());
050    
051            termBoService = GlobalResourceLoader.getService("termBoService");
052    
053                    TermSpecificationDefinition.Builder termSpecBuilder =
054                            TermSpecificationDefinition.Builder.create(null, "1", "testTermSpec", "java.lang.String");
055    
056            termSpecBuilder.getContextIds().add(context1.getId());
057            termSpecBuilder.getContextIds().add(context2.getId());
058    
059            TermSpecificationDefinition termSpecificationDefinition = termBoService.createTermSpecification(termSpecBuilder.build());
060    
061            assertNotNull(termSpecificationDefinition);
062            assertTrue(termSpecificationDefinition.getContextIds().size() == 2);
063            for (String contextId : Arrays.asList(context1.getId(), context2.getId())) {
064                assertTrue(termSpecificationDefinition.getContextIds().contains(contextId));
065            }
066    
067            }
068            
069    }