001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.krms.impl.repository;
017
018import org.junit.Before;
019import org.junit.Test;
020import org.kuali.rice.core.api.criteria.PredicateFactory;
021import org.kuali.rice.core.api.criteria.QueryByCriteria;
022import org.kuali.rice.krad.criteria.CriteriaLookupDaoProxy;
023import org.kuali.rice.krad.criteria.CriteriaLookupServiceImpl;
024import org.kuali.rice.krms.api.repository.reference.ReferenceObjectBinding;
025import org.kuali.rice.krms.test.AbstractBoTest;
026
027/**
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 *
030 */
031public final class ReferenceObjectBindingIntegrationGenTest extends AbstractBoTest {
032    ReferenceObjectBindingBoServiceImpl referenceObjectBindingBoServiceImpl;
033    ReferenceObjectBinding referenceObjectBinding;
034
035    /**
036     * Note lower case u, do not override superclasses setUp
037     *
038     */
039    @Before
040    public void setup() {
041        referenceObjectBindingBoServiceImpl = new ReferenceObjectBindingBoServiceImpl();
042        referenceObjectBindingBoServiceImpl.setDataObjectService(getDataObjectService());
043    }
044
045    @Test(expected = IllegalArgumentException.class)
046    public void test_findReferenceObjectBindingsByCollectionName_null_fail() {
047        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_findReferenceObjectBindingsByCollectionName_null_fail();
048    }
049
050    @Test(expected = IllegalArgumentException.class)
051    public void test_findReferenceObjectBindingsByKrmsDiscriminatorType_null_fail() {
052        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_findReferenceObjectBindingsByKrmsDiscriminatorType_null_fail();
053    }
054
055    @Test(expected = IllegalArgumentException.class)
056    public void test_findReferenceObjectBindingsByKrmsObject_null_fail() {
057        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_findReferenceObjectBindingsByKrmsObject_null_fail();
058    }
059
060    @Test(expected = IllegalArgumentException.class)
061    public void test_findReferenceObjectBindingsByNamespace_null_fail() {
062        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_findReferenceObjectBindingsByNamespace_null_fail();
063    }
064
065    @Test(expected = IllegalArgumentException.class)
066    public void test_findReferenceObjectBindingsByReferenceDiscriminatorType_null_fail() {
067        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_findReferenceObjectBindingsByReferenceDiscriminatorType_null_fail();
068    }
069
070    @Test(expected = IllegalArgumentException.class)
071    public void test_findReferenceObjectBindingsByReferenceObject_null_fail() {
072        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_findReferenceObjectBindingsByReferenceObject_null_fail();
073    }
074
075    @Test
076    public void test_from_null_yields_null() {
077        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_from_null_yields_null();
078    }
079
080    @Test
081    public void test_to() {
082        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_to();
083    }
084
085    @Test
086    public void test_createReferenceObjectBinding() {
087        ReferenceObjectBindingBoServiceImplGenTest test = ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl);
088        test.test_createReferenceObjectBinding();
089        referenceObjectBinding = test.getReferenceObjectBinding();
090        assert(referenceObjectBinding != null);
091        assert(referenceObjectBinding.getId() != null);
092    }
093
094    @Test(expected = IllegalStateException.class)
095    public void test_createReferenceObjectBinding_fail_existing() {
096        test_createReferenceObjectBinding();
097        test_createReferenceObjectBinding();
098    }
099
100    @Test(expected = IllegalArgumentException.class)
101    public void test_createReferenceObjectBinding_null_fail() {
102        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_createReferenceObjectBinding_null_fail();
103    }
104
105    @Test
106    public void test_getReferenceObjectBinding() {
107        test_createReferenceObjectBinding();
108        ReferenceObjectBinding def = getReferenceObjectBinding();
109        ReferenceObjectBinding def2 = referenceObjectBindingBoServiceImpl.getReferenceObjectBinding(def.getId());
110        assert(def2 != null);
111        assert(def2.equals(def));
112    }
113
114    @Test
115    public void test_updateReferenceObjectBinding() {
116        test_createReferenceObjectBinding();
117        ReferenceObjectBinding def = getReferenceObjectBinding();
118        String id = def.getId();
119        assert(!"UpdateTest".equals(def.getCollectionName()));
120        ReferenceObjectBindingBo bo = referenceObjectBindingBoServiceImpl.from(def);
121        bo.setCollectionName("UpdateTest");
122        ReferenceObjectBinding updatedData = referenceObjectBindingBoServiceImpl.updateReferenceObjectBinding(ReferenceObjectBinding.Builder.create(bo).build());
123        ReferenceObjectBinding def2 = referenceObjectBindingBoServiceImpl.getReferenceObjectBinding(id);
124        assert(updatedData!=null);
125        assert("UpdateTest".equals(def2.getCollectionName()));
126    }
127
128    @Test(expected = IllegalArgumentException.class)
129    public void test_updateReferenceObjectBinding_null_fail() {
130        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_updateReferenceObjectBinding_null_fail();
131    }
132
133    @Test
134    public void test_deleteReferenceObjectBinding() {
135        test_createReferenceObjectBinding();
136        ReferenceObjectBinding def = getReferenceObjectBinding();
137        String id = def.getId();
138        referenceObjectBindingBoServiceImpl.deleteReferenceObjectBinding(id);
139        ReferenceObjectBinding def2 = referenceObjectBindingBoServiceImpl.getReferenceObjectBinding(id);
140        assert(def2 == null);
141    }
142
143    @Test(expected = IllegalArgumentException.class)
144    public void test_deleteReferenceObjectBinding_null_fail() {
145        (ReferenceObjectBindingBoServiceImplGenTest.create(referenceObjectBindingBoServiceImpl)).test_deleteReferenceObjectBinding_null_fail();
146    }
147
148    @Test
149    public void test_Find() {
150        QueryByCriteria.Builder query = QueryByCriteria.Builder.create();
151        query.setPredicates(PredicateFactory.equal("id", "ID"));
152        CriteriaLookupServiceImpl criteria = new CriteriaLookupServiceImpl();
153        criteria.setCriteriaLookupDao(new CriteriaLookupDaoProxy());
154        assert(referenceObjectBindingBoServiceImpl.findReferenceObjectBindingIds(query.build()).isEmpty());
155        test_createReferenceObjectBinding();
156        assert(!referenceObjectBindingBoServiceImpl.findReferenceObjectBindingIds(query.build()).isEmpty());
157        assert("ID".equals(referenceObjectBindingBoServiceImpl.findReferenceObjectBindingIds(query.build()).get(0)));
158    }
159
160    public ReferenceObjectBinding getReferenceObjectBinding() {
161        return referenceObjectBinding;
162    }
163}