Repository: cayenne
Updated Branches:
  refs/heads/master 9c32b7604 -> dfa3d87d8


http://git-wip-us.apache.org/repos/asf/cayenne/blob/dae15cee/cayenne-server/src/test/java/org/apache/cayenne/event/JavaGroupsBridgeProviderTest.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/test/java/org/apache/cayenne/event/JavaGroupsBridgeProviderTest.java
 
b/cayenne-server/src/test/java/org/apache/cayenne/event/JavaGroupsBridgeProviderTest.java
new file mode 100644
index 0000000..6e82cd5
--- /dev/null
+++ 
b/cayenne-server/src/test/java/org/apache/cayenne/event/JavaGroupsBridgeProviderTest.java
@@ -0,0 +1,123 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.event;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.configuration.DefaultRuntimeProperties;
+import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.log.CommonsJdbcEventLogger;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.tx.DefaultTransactionFactory;
+import org.apache.cayenne.tx.DefaultTransactionManager;
+import org.apache.cayenne.tx.TransactionFactory;
+import org.apache.cayenne.tx.TransactionManager;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class JavaGroupsBridgeProviderTest {
+
+    private final DataDomain DOMAIN = new DataDomain("test");
+    private final EventManager EVENT_MANAGER = new DefaultEventManager();
+    protected static final String MCAST_ADDRESS_TEST = "192.168.0.0";
+    protected static final String MCAST_PORT_TEST = "1521";
+    protected static final String CONFIG_URL_TEST = "somehost.com";
+
+    @Test
+    public void testGetJavaGroupsBridge() throws Exception {
+        Module module = new Module() {
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(EventBridge.class).toProvider(JavaGroupsBridgeProvider.class);
+                binder.bindMap(Constants.JAVA_GROUPS_BRIDGE_PROPERTIES_MAP);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(module);
+        EventBridge bridge = injector.getInstance(EventBridge.class);
+
+        assertNotNull(bridge);
+        assertTrue(bridge instanceof JavaGroupsBridge);
+    }
+
+    @Test
+    public void testUseProperties() throws Exception {
+        Module module = new Module() {
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(EventBridge.class).toProvider(JavaGroupsBridgeProvider.class);
+                binder.bindMap(Constants.JAVA_GROUPS_BRIDGE_PROPERTIES_MAP)
+                        .put(JavaGroupsBridge.MCAST_ADDRESS_PROPERTY, 
MCAST_ADDRESS_TEST)
+                        .put(JavaGroupsBridge.MCAST_PORT_PROPERTY, 
MCAST_PORT_TEST)
+                        .put(JavaGroupsBridge.JGROUPS_CONFIG_URL_PROPERTY, 
CONFIG_URL_TEST);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(module);
+        JavaGroupsBridge bridge = (JavaGroupsBridge) 
injector.getInstance(EventBridge.class);
+
+        assertEquals(MCAST_ADDRESS_TEST, bridge.getMulticastAddress());
+        assertEquals(MCAST_PORT_TEST, bridge.getMulticastPort());
+        assertEquals(CONFIG_URL_TEST, bridge.getConfigURL());
+    }
+
+    @Test
+    public void testUseDefaultProperties() throws Exception {
+        Module module = new Module() {
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(EventBridge.class).toProvider(JavaGroupsBridgeProvider.class);
+                binder.bindMap(Constants.JAVA_GROUPS_BRIDGE_PROPERTIES_MAP);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(module);
+        JavaGroupsBridge bridge = (JavaGroupsBridge) 
injector.getInstance(EventBridge.class);
+
+        assertEquals(bridge.getMulticastAddress(), 
JavaGroupsBridge.MCAST_ADDRESS_DEFAULT);
+        assertEquals(bridge.getMulticastPort(), 
JavaGroupsBridge.MCAST_PORT_DEFAULT);
+        assertEquals(bridge.getConfigURL(), null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/dae15cee/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeProvider.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeProvider.java
 
b/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeProvider.java
new file mode 100644
index 0000000..2e99a63
--- /dev/null
+++ 
b/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeProvider.java
@@ -0,0 +1,43 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.event;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.di.DIRuntimeException;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+
+import java.util.Collections;
+
+public class MockEventBridgeProvider implements Provider<EventBridge> {
+
+    @Inject
+    protected DataDomain dataDomain;
+
+    @Override
+    public EventBridge get() throws DIRuntimeException {
+        EventSubject snapshotEventSubject = 
EventSubject.getSubject(this.getClass(), dataDomain.getName());;
+
+        return new MockEventBridge(
+                Collections.singleton(snapshotEventSubject),
+                EventBridge.convertToExternalSubject(snapshotEventSubject),
+                Collections.EMPTY_MAP);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/dae15cee/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeFactoryTest.java
 
b/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeFactoryTest.java
index 4eac54a..fb54ede 100644
--- 
a/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeFactoryTest.java
+++ 
b/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeFactoryTest.java
@@ -31,29 +31,42 @@ import static org.junit.Assert.assertTrue;
 
 public class XMPPBridgeFactoryTest {
 
+    protected Collection<EventSubject> subjects = Collections.singleton(new 
EventSubject("test"));
+    protected String externalSubject = "subject";
+
     @Test
     public void testCreateEventBridge() {
-        XMPPBridgeFactory factory = new XMPPBridgeFactory();
-
-        Collection subjects = Collections.singleton(EventSubject.getSubject(
-                getClass(),
-                "test"));
-        Map properties = new HashMap();
-        properties.put(XMPPBridgeFactory.XMPP_HOST_PROPERTY, "somehost.com");
-        properties.put(XMPPBridgeFactory.XMPP_PORT_PROPERTY, "12345");
-
-        EventBridge bridge = factory.createEventBridge(
+        EventBridge bridge = new XMPPBridgeFactory().createEventBridge(
                 subjects,
-                "remote-subject",
-                properties);
+                externalSubject,
+                Collections.EMPTY_MAP);
 
         assertTrue(bridge instanceof XMPPBridge);
+        assertEquals(subjects, bridge.getLocalSubjects());
+        assertEquals(externalSubject, bridge.getExternalSubject());
+    }
 
-        XMPPBridge xmppBridge = (XMPPBridge) bridge;
+    @Test
+    public void testUseMapPropertiesSetter() throws Exception {
+        XMPPBridgeFactory bridgeFactory = new XMPPBridgeFactory();
+        Map<String, String> properties = new HashMap<String, String>();
+
+        properties.put(XMPPBridge.XMPP_HOST_PROPERTY, 
XMPPBridgeProviderTest.HOST_TEST);
+        properties.put(XMPPBridge.XMPP_CHAT_SERVICE_PROPERTY, 
XMPPBridgeProviderTest.CHAT_SERVICE_TEST);
+        properties.put(XMPPBridge.XMPP_LOGIN_PROPERTY, 
XMPPBridgeProviderTest.LOGIN_TEST);
+        properties.put(XMPPBridge.XMPP_PASSWORD_PROPERTY, 
XMPPBridgeProviderTest.PASSWORD_TEST);
+        properties.put(XMPPBridge.XMPP_SECURE_CONNECTION_PROPERTY, 
String.valueOf(XMPPBridgeProviderTest.SECURE_CONNECTION_TEST));
+        properties.put(XMPPBridge.XMPP_PORT_PROPERTY, 
String.valueOf(XMPPBridgeProviderTest.PORT_TEST));
+
+        XMPPBridge bridge = (XMPPBridge) 
bridgeFactory.createEventBridge(subjects,
+                externalSubject,
+                properties);
 
-        assertEquals(subjects, xmppBridge.getLocalSubjects());
-        assertEquals("remote-subject", xmppBridge.getExternalSubject());
-        assertEquals("somehost.com", xmppBridge.getXmppHost());
-        assertEquals(12345, xmppBridge.getXmppPort());
+        assertEquals(bridge.getXmppHost(), XMPPBridgeProviderTest.HOST_TEST);
+        assertEquals(bridge.getChatService(), 
XMPPBridgeProviderTest.CHAT_SERVICE_TEST);
+        assertEquals(bridge.getLoginId(), XMPPBridgeProviderTest.LOGIN_TEST);
+        assertEquals(bridge.getPassword(), 
XMPPBridgeProviderTest.PASSWORD_TEST);
+        assertEquals(bridge.getXmppPort(), XMPPBridgeProviderTest.PORT_TEST);
+        assertEquals(bridge.isSecureConnection(), 
XMPPBridgeProviderTest.SECURE_CONNECTION_TEST);
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/dae15cee/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeProviderTest.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeProviderTest.java
 
b/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeProviderTest.java
new file mode 100644
index 0000000..7d225a5
--- /dev/null
+++ 
b/cayenne-server/src/test/java/org/apache/cayenne/event/XMPPBridgeProviderTest.java
@@ -0,0 +1,130 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.event;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.configuration.DefaultRuntimeProperties;
+import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.log.CommonsJdbcEventLogger;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.tx.DefaultTransactionFactory;
+import org.apache.cayenne.tx.DefaultTransactionManager;
+import org.apache.cayenne.tx.TransactionFactory;
+import org.apache.cayenne.tx.TransactionManager;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class XMPPBridgeProviderTest {
+
+    private final DataDomain DOMAIN = new DataDomain("test");
+    private final EventManager EVENT_MANAGER = new DefaultEventManager();
+    protected static final String HOST_TEST = "somehost.com";
+    protected static final String CHAT_SERVICE_TEST = "conference";
+    protected static final String LOGIN_TEST = "login";
+    protected static final String PASSWORD_TEST = "password";
+    protected static final boolean SECURE_CONNECTION_TEST = true;
+    protected static final int PORT_TEST = 12345;
+
+    @Test
+    public void testGetXMPPBridge() throws Exception {
+        Module module = new Module() {
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(EventBridge.class).toProvider(XMPPBridgeProvider.class);
+                binder.bindMap(Constants.XMPP_BRIDGE_PROPERTIES_MAP);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(module);
+        EventBridge bridge = injector.getInstance(EventBridge.class);
+
+        assertNotNull(bridge);
+        assertTrue(bridge instanceof XMPPBridge);
+    }
+
+    @Test
+    public void testUseProperties() throws Exception {
+        Module module = new Module() {
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(EventBridge.class).toProvider(XMPPBridgeProvider.class);
+                binder.bindMap(Constants.XMPP_BRIDGE_PROPERTIES_MAP)
+                        .put(XMPPBridge.XMPP_HOST_PROPERTY, HOST_TEST)
+                        .put(XMPPBridge.XMPP_CHAT_SERVICE_PROPERTY, 
CHAT_SERVICE_TEST)
+                        .put(XMPPBridge.XMPP_LOGIN_PROPERTY, LOGIN_TEST)
+                        .put(XMPPBridge.XMPP_PASSWORD_PROPERTY, PASSWORD_TEST)
+                        .put(XMPPBridge.XMPP_SECURE_CONNECTION_PROPERTY, 
String.valueOf(SECURE_CONNECTION_TEST))
+                        .put(XMPPBridge.XMPP_PORT_PROPERTY, 
String.valueOf(PORT_TEST));
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(module);
+        XMPPBridge bridge = (XMPPBridge) 
injector.getInstance(EventBridge.class);
+
+        assertEquals(HOST_TEST, bridge.getXmppHost());
+        assertEquals(CHAT_SERVICE_TEST, bridge.getChatService());
+        assertEquals(LOGIN_TEST, bridge.getLoginId());
+        assertEquals(PASSWORD_TEST, bridge.getPassword());
+        assertEquals(SECURE_CONNECTION_TEST, bridge.isSecureConnection());
+        assertEquals(PORT_TEST, bridge.getXmppPort());
+    }
+
+    public void testUseDefaultProperties() throws Exception {
+        Module module = new Module() {
+            public void configure(Binder binder) {
+                binder.bindMap(Constants.PROPERTIES_MAP);
+                binder.bind(DataDomain.class).toInstance(DOMAIN);
+                binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
+                
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
+                
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
+                
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
+                
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+                
binder.bind(EventBridge.class).toProvider(XMPPBridgeProvider.class);
+                binder.bindMap(Constants.XMPP_BRIDGE_PROPERTIES_MAP);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(module);
+        XMPPBridge bridge = (XMPPBridge) 
injector.getInstance(EventBridge.class);
+
+        assertEquals(bridge.getChatService(), XMPPBridge.DEFAULT_CHAT_SERVICE);
+        assertEquals(bridge.getXmppPort(), XMPPBridge.DEFAULT_XMPP_PORT);
+    }
+}

Reply via email to