View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Eric Long <erilong@users.sourceforge.net>,
5    *               Chris Henson <chenson42@users.sourceforge.net>
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 3 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, see
19   * <http://www.gnu.org/licenses/>.
20   */
21  
22  package org.jumpmind.symmetric.service.impl;
23  
24  import java.util.List;
25  
26  import org.jumpmind.symmetric.common.Constants;
27  import org.jumpmind.symmetric.model.Node;
28  import org.jumpmind.symmetric.model.NodeSecurity;
29  import org.jumpmind.symmetric.service.INodeService;
30  import org.jumpmind.symmetric.test.AbstractDatabaseTest;
31  import org.jumpmind.symmetric.test.TestConstants;
32  import org.junit.Before;
33  import org.junit.Test;
34  
35  public class NodeServiceTest extends AbstractDatabaseTest {
36  
37      protected INodeService nodeService;
38  
39      public NodeServiceTest() throws Exception {
40          super();
41      }
42  
43      public NodeServiceTest(String dbName) {
44          super(dbName);
45      }
46  
47      @Before
48      public void setUp() {
49          nodeService = (INodeService) find(Constants.NODE_SERVICE);
50      }
51  
52      @Test
53      public void testFindNode() throws Exception {
54          Node node = nodeService.findNode("00001");
55          assertEquals(node.getNodeId(), "00001", "Wrong nodeId");
56          assertEquals(node.getNodeGroupId(), TestConstants.TEST_CLIENT_NODE_GROUP, "Wrong node group id");
57          assertEquals(node.getExternalId(), "00001", "Wrong external id");
58          assertEquals(node.getSyncURL().toString(), "http://localhost:8080/sync", "Wrong syncUrl");
59          assertEquals(node.getSchemaVersion(), "1", "Wrong schemaVersion");
60          assertEquals(node.getDatabaseType(), "MySQL", "Wrong databaseType");
61          assertEquals(node.getDatabaseVersion(), "5.0", "Wrong databaseVersion");
62      }
63  
64      @Test
65      public void testFindNodeFail() throws Exception {
66          Node node = nodeService.findNode("00004");
67          assertNull(node, "Should not find node");
68      }
69  
70      @Test
71      public void testFindNodeSecurity() throws Exception {
72          NodeSecurity node = nodeService.findNodeSecurity("00001");
73          assertEquals(node.getNodeId(), "00001", "Wrong nodeId");
74          assertEquals(node.getPassword(), "secret", "Wrong password");
75          assertEquals(node.isRegistrationEnabled(), false, "Wrong isRegistrationEnabled");
76          assertEquals(node.getRegistrationTime().toString(), "2007-01-01 01:01:01.0", "Wrong registrationTime");
77      }
78  
79      @Test
80      public void testFindNodeSecurityFail() throws Exception {
81          NodeSecurity node = nodeService.findNodeSecurity("00004");
82          assertNull(node, "Should not find node");
83      }
84  
85      @Test
86      public void testIsNodeAuthorized() throws Exception {
87          assertTrue(nodeService.isNodeAuthorized("00001", "secret"), "Node should be authorized");
88  
89          assertFalse(nodeService.isNodeAuthorized("00001", "wrongPassword"), "Node should NOT be authorized");
90  
91          assertFalse(nodeService.isNodeAuthorized("wrongNodeId", "secret"), "Node should NOT be authorized");
92      }
93  
94      @Test
95      public void testFindIdentity() throws Exception {
96          Node node = nodeService.findIdentity();
97          assertEquals(node.getNodeId(), "00000", "Wrong nodeId");
98          assertEquals(node.getNodeGroupId(), TestConstants.TEST_ROOT_NODE_GROUP, "Wrong node group id");
99          assertEquals(node.getExternalId(), TestConstants.TEST_ROOT_EXTERNAL_ID, "Wrong external id");
100         assertEquals(node.getSyncURL().toString(), "http://localhost:8888/sync", "Wrong syncUrl");
101         assertEquals(node.getSchemaVersion(), "?", "Wrong schemaVersion");
102         assertEquals(node.getDatabaseType(), getDbDialect().getName(), "Wrong databaseType");
103         assertEquals(node.getDatabaseVersion(), getDbDialect().getVersion(), "Wrong databaseVersion");
104     }
105 
106     @Test
107     public void testFindPullNodes() throws Exception {
108         List<Node> list = nodeService.findNodesToPull();
109         assertEquals(list.size(), 4, "Wrong number of pull nodes");
110     }
111 
112     @Test
113     public void testFindPushNodes() throws Exception {
114         List<Node> list = nodeService.findNodesToPushTo();
115         assertEquals(list.size(), 1, "Wrong number of push nodes");
116     }
117 
118 }