View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.edo.vote;
17  
18  import static org.junit.Assert.assertEquals;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.junit.After;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.kuali.kpme.core.IntegrationTest;
27  import org.kuali.kpme.edo.EdoUnitTestBase;
28  import org.kuali.kpme.edo.api.reviewlayerdef.EdoReviewLayerDefinition;
29  import org.kuali.kpme.edo.api.vote.EdoVoteRecord;
30  import org.kuali.kpme.edo.reviewlayerdef.EdoReviewLayerDefinitionBo;
31  import org.kuali.kpme.edo.service.EdoServiceLocator;
32  
33  
34  @IntegrationTest
35  public class EdoVoteRecordServiceTest extends EdoUnitTestBase {	
36  	
37  	@Before
38  	public void setUp() throws Exception {
39  		
40  		super.setUp();
41  	}
42  	
43  	@After
44  	public void tearDown() throws Exception {
45  		
46  		super.tearDown();
47  	}
48  	
49  	@Test
50  	public void testGetEdoVoteRecordById() throws Exception {
51  
52  		EdoVoteRecord edoVoteRecord = (EdoVoteRecord)EdoServiceLocator.getEdoVoteRecordService().getEdoVoteRecord("1000");
53  		
54  		assertEquals("1000", edoVoteRecord.getEdoVoteRecordId());
55  	}
56  	
57  	@Test
58  	public void testSaveOrUpdate() throws Exception {
59  		EdoVoteRecord immutable = (EdoVoteRecord)EdoServiceLocator.getEdoVoteRecordService().getEdoVoteRecord("1004");
60  		EdoVoteRecordBo edoVoteRecordBo = EdoVoteRecordBo.from(immutable);
61  		assertEquals("P", immutable.getVoteType());
62  		
63  		edoVoteRecordBo.setVoteType("T");
64  		EdoServiceLocator.getEdoVoteRecordService().saveOrUpdate(EdoVoteRecord.Builder.create(edoVoteRecordBo).build());
65  		
66  		immutable = (EdoVoteRecord)EdoServiceLocator.getEdoVoteRecordService().getEdoVoteRecord("1004");
67  		assertEquals("T", immutable.getVoteType());
68  	}
69  	
70  	@Test
71  	public void testGetVoteRecords() throws Exception {
72  		List<EdoVoteRecord> edoVoteRecords = new ArrayList<EdoVoteRecord>();
73  		//Map<String, EdoReviewLayerDefinition> testReviewlayerDefinitionBo;
74  		
75  		//testReviewlayerDefinitionBo = new HashMap<String, EdoReviewLayerDefinition>();
76  		
77  		EdoReviewLayerDefinition.Builder edoReviewLayerDefinitionBuilder = EdoReviewLayerDefinition.Builder.create();
78  		edoReviewLayerDefinitionBuilder.setEdoReviewLayerDefinitionId("1000");
79  		edoReviewLayerDefinitionBuilder.setNodeName("testNodeName");
80  		edoReviewLayerDefinitionBuilder.setVoteType("tenure");
81  		edoReviewLayerDefinitionBuilder.setDescription("description");
82  		edoReviewLayerDefinitionBuilder.setReviewLetter(true);
83  		edoReviewLayerDefinitionBuilder.setReviewLevel("1");
84  		edoReviewLayerDefinitionBuilder.setRouteLevel("1");
85  		edoReviewLayerDefinitionBuilder.setWorkflowId("1000");
86  		edoReviewLayerDefinitionBuilder.setWorkflowQualifier("workflowQualifier");	
87  		edoReviewLayerDefinitionBuilder.setUserPrincipalId("admin");
88  		edoReviewLayerDefinitionBuilder.setVersionNumber(1L);
89  		edoReviewLayerDefinitionBuilder.setObjectId("0804716a-cbb7-11e3-9cd3-51a754ad6a0a");
90  		edoReviewLayerDefinitionBuilder.setId(edoReviewLayerDefinitionBuilder.getEdoReviewLayerDefinitionId());
91  		
92  		EdoReviewLayerDefinition edoReviewLayerDefinition1 = edoReviewLayerDefinitionBuilder.build();
93  		
94  		
95  		EdoReviewLayerDefinitionBo edoReviewLayerDefinition2 = new EdoReviewLayerDefinitionBo();
96  		edoReviewLayerDefinition2.setEdoReviewLayerDefinitionId("1001");
97  		edoReviewLayerDefinition2.setReviewLevel("1");
98  		
99  		List<EdoReviewLayerDefinition> edoReviewLayerDefinitions = new ArrayList<EdoReviewLayerDefinition>();
100 		edoReviewLayerDefinitions.add(edoReviewLayerDefinition1);
101 		//edoReviewLayerDefinitions.add(edoReviewLayerDefinition2);
102 		
103 		edoVoteRecords = EdoServiceLocator.getEdoVoteRecordService().getVoteRecords("1000", edoReviewLayerDefinitions);
104 		// TODO: getVoteRecords needs setup authorizedViewLevels. 	
105 //		assertTrue(edoVoteRecords.size() == 3);
106 //		
107 //		if ( edoVoteRecords.size() == 3) {
108 //			
109 //			assertEquals("1000", edoVoteRecords.get(0).getEdoDossierID());	
110 //		}
111 	}
112 	
113 	@Test
114 	public void testGetVoteRecordsByEdoReviewLayerDefinitionId() throws Exception {
115 		EdoVoteRecord edoVoteRecord = (EdoVoteRecord)EdoServiceLocator.getEdoVoteRecordService().getVoteRecordMostCurrentRound("1000", "1001");
116 		
117 		assertEquals("1003", edoVoteRecord.getEdoVoteRecordId());
118 	}
119 	
120 	@Test
121 	public void testIsNegativeVote() throws Exception {
122 		boolean isNegative = true;
123 		
124 		EdoVoteRecord aPositiveEdoVoteRecord = (EdoVoteRecord)EdoServiceLocator.getEdoVoteRecordService().getEdoVoteRecord("1000");
125 		isNegative = EdoServiceLocator.getEdoVoteRecordService().isNegativeVote(aPositiveEdoVoteRecord);
126 		assertEquals(false, isNegative);
127 		
128 		EdoVoteRecord aNegativeEdoVoteRecord = (EdoVoteRecord)EdoServiceLocator.getEdoVoteRecordService().getEdoVoteRecord("1002");
129 		isNegative = EdoServiceLocator.getEdoVoteRecordService().isNegativeVote(aNegativeEdoVoteRecord);
130 		assertEquals(true, isNegative);
131 	}
132 }