View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
19   */
20  package org.jumpmind.symmetric.test;
21  
22  import org.jumpmind.symmetric.common.Constants;
23  import org.jumpmind.symmetric.model.Trigger;
24  import org.jumpmind.symmetric.service.IConfigurationService;
25  import org.jumpmind.symmetric.test.ParameterizedSuite.ParameterMatcher;
26  import org.junit.Assert;
27  import org.junit.Test;
28  import org.springframework.jdbc.core.JdbcTemplate;
29  
30  public class CrossCatalogSyncTest extends AbstractDatabaseTest {
31  
32      public CrossCatalogSyncTest(String db) {
33          super(db);
34      }
35  
36      public CrossCatalogSyncTest() throws Exception {
37          super();
38      }
39  
40      @Test
41      @ParameterMatcher("mysql")
42      public void testCrossCatalogSyncOnMySQL() {
43          JdbcTemplate jdbcTemplate = getJdbcTemplate();
44          jdbcTemplate.update("drop database if exists other ");
45          jdbcTemplate.update("create database other");
46          String db = (String) jdbcTemplate.queryForObject("select database()", String.class);
47          jdbcTemplate.update("use other");
48          jdbcTemplate.update("create table other_table (id char(5) not null, name varchar(40), primary key(id))");
49          jdbcTemplate.update("use " + db);
50          IConfigurationService configService = find(Constants.CONFIG_SERVICE);
51          Trigger trigger = new Trigger();
52          trigger.setChannelId("other");
53          trigger.setSourceGroupId(TestConstants.TEST_CONTINUOUS_NODE_GROUP);
54          trigger.setTargetGroupId(TestConstants.TEST_CONTINUOUS_NODE_GROUP);
55          trigger.setSourceCatalogName("other");
56          trigger.setSourceTableName("other_table");
57          trigger.setSyncOnInsert(true);
58          trigger.setSyncOnUpdate(true);
59          trigger.setSyncOnDelete(true);
60          configService.insert(trigger);
61          getSymmetricEngine().syncTriggers();
62          jdbcTemplate.update("insert into other.other_table values('00000','first row')");
63          Assert.assertEquals("The data event from the other database's other_table was not captured.", jdbcTemplate
64                  .queryForInt("select count(*) from sym_data_event where channel_id='other'"), 1);
65      }
66  }