01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.outerj.daisy.repository.test;
17:
18: import org.outerj.daisy.repository.RepositoryManager;
19: import org.outerj.daisy.repository.Repository;
20: import org.outerj.daisy.repository.Credentials;
21: import org.outerj.daisy.repository.user.Role;
22: import org.outerj.daisy.repository.variant.VariantManager;
23: import org.outerj.daisy.repository.variant.Branch;
24: import org.outerj.daisy.repository.variant.Language;
25:
26: public class RemoteVariantTest extends AbstractVariantTest {
27: protected RepositoryManager getRepositoryManager() throws Exception {
28: return getRemoteRepositoryManager();
29: }
30:
31: protected void moreTests() throws Exception {
32: checkRemoteCacheInvalidation();
33: }
34:
35: private void checkRemoteCacheInvalidation() throws Exception {
36: RepositoryManager localRepositoryManager = getLocalRepositoryManager();
37: Repository localRepository = localRepositoryManager
38: .getRepository(new Credentials("testuser", "testuser"));
39: localRepository.switchRole(Role.ADMINISTRATOR);
40:
41: RepositoryManager remoteRepositoryManager = getRemoteRepositoryManager();
42: Repository remoteRepository = remoteRepositoryManager
43: .getRepository(new Credentials("testuser", "testuser"));
44: remoteRepository.switchRole(Role.ADMINISTRATOR);
45:
46: VariantManager localVariantManager = localRepository
47: .getVariantManager();
48: VariantManager remoteVariantManager = remoteRepository
49: .getVariantManager();
50:
51: {
52: Branch localBranch = localVariantManager
53: .createBranch("branch99");
54: localBranch.save();
55:
56: Branch remoteBranch = remoteVariantManager.getBranch(
57: localBranch.getId(), false);
58:
59: localBranch.setName("branch100");
60: localBranch.save();
61:
62: // give some time to receive JMS event
63: Thread.sleep(5000);
64:
65: remoteBranch = remoteVariantManager.getBranch(localBranch
66: .getId(), false);
67: assertEquals("branch100", remoteBranch.getName());
68: }
69:
70: {
71: Language localLanguage = localVariantManager
72: .createLanguage("language99");
73: localLanguage.save();
74:
75: // make sure the variant cache is loaded
76: Language remoteLanguage = remoteVariantManager.getLanguage(
77: localLanguage.getId(), false);
78:
79: //update the object locally
80: localLanguage.setName("language100");
81: localLanguage.save();
82:
83: // give some time to receive JMS event
84: Thread.sleep(5000);
85:
86: // check that the remote cache has been updated
87: remoteLanguage = remoteVariantManager.getLanguage(
88: localLanguage.getId(), false);
89: assertEquals("language100", remoteLanguage.getName());
90: }
91: }
92: }
|