KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > version > common > counter > VersionCounterDaoServiceTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.version.common.counter;
18
19 import org.alfresco.service.cmr.repository.NodeService;
20 import org.alfresco.service.cmr.repository.StoreRef;
21 import org.alfresco.util.BaseSpringTest;
22
23 /**
24  * @author Roy Wetherall
25  */

26 public class VersionCounterDaoServiceTest extends BaseSpringTest
27 {
28     /*
29      * Test store id's
30      */

31     private final static String JavaDoc STORE_ID_1 = "test1_" + System.currentTimeMillis();
32     private final static String JavaDoc STORE_ID_2 = "test2_" + System.currentTimeMillis();
33     private static final String JavaDoc STORE_NONE = "test3_" + System.currentTimeMillis();;
34     
35     private NodeService nodeService;
36     private VersionCounterDaoService counter;
37     
38     @Override JavaDoc
39     public void onSetUpInTransaction()
40     {
41         nodeService = (NodeService) applicationContext.getBean("dbNodeService");
42         counter = (VersionCounterDaoService) applicationContext.getBean("versionCounterDaoService");
43     }
44     
45     public void testSetUp() throws Exception JavaDoc
46     {
47         assertNotNull(nodeService);
48         assertNotNull(counter);
49     }
50     
51     /**
52      * Test nextVersionNumber
53      */

54     public void testNextVersionNumber()
55     {
56         // Create the store references
57
StoreRef store1 = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, VersionCounterDaoServiceTest.STORE_ID_1);
58         StoreRef store2 = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, VersionCounterDaoServiceTest.STORE_ID_2);
59         StoreRef storeNone = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, VersionCounterDaoServiceTest.STORE_NONE);
60         
61         int store1Version0 = this.counter.nextVersionNumber(store1);
62         assertEquals(store1Version0, 1);
63         
64         int store1Version1 = this.counter.nextVersionNumber(store1);
65         assertEquals(store1Version1, 2);
66         
67         int store2Version0 = this.counter.nextVersionNumber(store2);
68         assertEquals(store2Version0, 1);
69         
70         int store1Version2 = this.counter.nextVersionNumber(store1);
71         assertEquals(store1Version2, 3);
72         
73         int store2Version1 = this.counter.nextVersionNumber(store2);
74         assertEquals(store2Version1, 2);
75         
76         int store1Current = this.counter.currentVersionNumber(store1);
77         assertEquals(store1Current, 3);
78         
79         int store2Current = this.counter.currentVersionNumber(store2);
80         assertEquals(store2Current, 2);
81         
82         int storeNoneCurrent = this.counter.currentVersionNumber(storeNone);
83         assertEquals(storeNoneCurrent, 0);
84         
85         // Need to clean-up since the version counter works in its own transaction
86
this.counter.resetVersionNumber(store1);
87         this.counter.resetVersionNumber(store2);
88     }
89
90 }
91
Popular Tags