You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2018/12/21 23:01:26 UTC

[geode] branch feature/GEODE-6143-12 created (now ce9c9e3)

This is an automated email from the ASF dual-hosted git repository.

zhouxj pushed a change to branch feature/GEODE-6143-12
in repository https://gitbox.apache.org/repos/asf/geode.git.


      at ce9c9e3  GEODE-6143: remove PowerMock from GatewayReceiverXmlParsingValidationsJUnitTest

This branch includes the following new commits:

     new ce9c9e3  GEODE-6143: remove PowerMock from GatewayReceiverXmlParsingValidationsJUnitTest

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[geode] 01/01: GEODE-6143: remove PowerMock from GatewayReceiverXmlParsingValidationsJUnitTest

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zhouxj pushed a commit to branch feature/GEODE-6143-12
in repository https://gitbox.apache.org/repos/asf/geode.git

commit ce9c9e395539104af9708979dcbe17a2135e33e1
Author: zhouxh <gz...@pivotal.io>
AuthorDate: Fri Dec 21 15:00:02 2018 -0800

    GEODE-6143: remove PowerMock from GatewayReceiverXmlParsingValidationsJUnitTest
---
 ...ewayReceiverXmlParsingValidationsJUnitTest.java |  52 +++-----
 .../geode/internal/cache/wan/MyWANFactoryImpl.java | 144 +++++++++++++++++++++
 ...nsJUnitTest.correctConfiguration[DTD].cache.xml |   0
 ...nsJUnitTest.correctConfiguration[XSD].cache.xml |   0
 ...pleReceiversShouldThrowException[DTD].cache.xml |   0
 ...pleReceiversShouldThrowException[XSD].cache.xml |   0
 6 files changed, 165 insertions(+), 31 deletions(-)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java b/geode-wan/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
similarity index 66%
rename from geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
rename to geode-wan/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
index 9461abd..3501dd3 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
+++ b/geode-wan/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
@@ -16,44 +16,36 @@ package org.apache.geode.internal.cache.wan;
 
 import static org.apache.geode.distributed.ConfigurationProperties.CACHE_XML_FILE;
 import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.internal.Assert.assertTrue;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-import static org.powermock.api.mockito.PowerMockito.when;
+import static org.junit.Assert.assertEquals;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.ServiceLoader;
 
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TestName;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.CacheXmlException;
+import org.apache.geode.cache.wan.GatewayReceiver;
 import org.apache.geode.cache.wan.GatewayReceiverFactory;
+import org.apache.geode.internal.cache.wan.spi.WANFactory;
 import org.apache.geode.test.junit.categories.WanTest;
 import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
 import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 import org.apache.geode.util.test.TestUtil;
 
-@RunWith(PowerMockRunner.class)
 @Category({WanTest.class})
-@PrepareForTest(WANServiceProvider.class)
-@PowerMockRunnerDelegate(Parameterized.class)
-@PowerMockIgnore({"javax.management.*", "javax.security.*", "*.IntegrationTest"})
+@RunWith(Parameterized.class)
 @Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class GatewayReceiverXmlParsingValidationsJUnitTest {
   private Cache cache;
@@ -70,13 +62,6 @@ public class GatewayReceiverXmlParsingValidationsJUnitTest {
     return Arrays.asList("DTD", "XSD");
   }
 
-  @Before
-  public void setUp() throws Exception {
-    mockStatic(WANServiceProvider.class);
-    receiverFactory = spy(GatewayReceiverFactory.class);
-    when(WANServiceProvider.createGatewayReceiverFactory(any())).thenReturn(receiverFactory);
-  }
-
   @Test(expected = CacheXmlException.class)
   public void multipleReceiversShouldThrowException() {
     String cacheXmlFileName = TestUtil.getResourcePath(getClass(),
@@ -90,15 +75,20 @@ public class GatewayReceiverXmlParsingValidationsJUnitTest {
         getClass().getSimpleName() + "." + testName.getMethodName() + ".cache.xml");
     cache = new CacheFactory().set(MCAST_PORT, "0").set(CACHE_XML_FILE, cacheXmlFileName).create();
 
-    assertThat(cache.getGatewayReceivers()).isNotNull();
-    verify(receiverFactory, times(1)).setEndPort(1501);
-    verify(receiverFactory, times(1)).setStartPort(1500);
-    verify(receiverFactory, times(1)).setManualStart(true);
-    verify(receiverFactory, times(1)).setSocketBufferSize(32768);
-    verify(receiverFactory, times(1)).setBindAddress("localhost");
-    verify(receiverFactory, times(1)).setHostnameForSenders("localhost");
-    verify(receiverFactory, times(1)).setMaximumTimeBetweenPings(60000);
-    verify(receiverFactory, times(1)).create();
+    assertThat(cache.getGatewayReceivers()).isNotEmpty();
+    GatewayReceiver receiver = cache.getGatewayReceivers().iterator().next();
+
+    ServiceLoader<WANFactory> loader = ServiceLoader.load(WANFactory.class);
+    Iterator<WANFactory> itr = loader.iterator();
+    assertThat(itr.hasNext()).isTrue();
+
+    assertEquals(1501, receiver.getEndPort());
+    assertEquals(1500, receiver.getStartPort());
+    assertTrue(receiver.isManualStart());
+    assertEquals(32768, receiver.getSocketBufferSize());
+    assertTrue(receiver.getBindAddress().equals("localhost"));
+    assertTrue(receiver.getHostnameForSenders().equals("localhost"));
+    assertEquals(60000, receiver.getMaximumTimeBetweenPings());
   }
 
   @After
diff --git a/geode-wan/src/integrationTest/java/org/apache/geode/internal/cache/wan/MyWANFactoryImpl.java b/geode-wan/src/integrationTest/java/org/apache/geode/internal/cache/wan/MyWANFactoryImpl.java
new file mode 100644
index 0000000..39272d2
--- /dev/null
+++ b/geode-wan/src/integrationTest/java/org/apache/geode/internal/cache/wan/MyWANFactoryImpl.java
@@ -0,0 +1,144 @@
+/*
+ * 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.geode.internal.cache.wan;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import org.apache.geode.cache.client.internal.locator.wan.LocatorMembershipListener;
+import org.apache.geode.cache.wan.GatewayReceiver;
+import org.apache.geode.cache.wan.GatewayReceiverFactory;
+import org.apache.geode.cache.wan.GatewaySenderFactory;
+import org.apache.geode.cache.wan.GatewayTransportFilter;
+import org.apache.geode.distributed.internal.WanLocatorDiscoverer;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.wan.spi.WANFactory;
+
+public class MyWANFactoryImpl implements WANFactory {
+
+  public GatewayReceiverFactory myReceiverFactory;
+
+  @Override
+  public GatewaySenderFactory createGatewaySenderFactory(InternalCache cache) {
+    return null;
+  }
+
+  @Override
+  public GatewayReceiverFactory createGatewayReceiverFactory(InternalCache cache) {
+    myReceiverFactory = spy(new MyGatewayReceiverFactoryImpl(cache));
+    return myReceiverFactory;
+  }
+
+  @Override
+  public WanLocatorDiscoverer createLocatorDiscoverer() {
+    return null;
+  }
+
+  @Override
+  public LocatorMembershipListener createLocatorMembershipListener() {
+    return null;
+  }
+
+  @Override
+  public void initialize() {
+
+  }
+
+  static class MyGatewayReceiverFactoryImpl implements GatewayReceiverFactory {
+    InternalCache cache;
+    int startPort;
+    int endPort;
+    int socketBuffSize;
+    int timeBetPings;
+    boolean manualStart;
+    String bindAdd;
+    String hostnameForSenders;
+
+    public MyGatewayReceiverFactoryImpl(InternalCache cache) {
+      this.cache = cache;
+    }
+
+    @Override
+    public GatewayReceiverFactory setStartPort(int startPort) {
+      this.startPort = startPort;
+      return this;
+    }
+
+    @Override
+    public GatewayReceiverFactory setEndPort(int endPort) {
+      this.endPort = endPort;
+      return this;
+    }
+
+    @Override
+    public GatewayReceiverFactory setSocketBufferSize(int socketBufferSize) {
+      this.socketBuffSize = socketBufferSize;
+      return this;
+    }
+
+    @Override
+    public GatewayReceiverFactory setBindAddress(String address) {
+      this.bindAdd = address;
+      return this;
+    }
+
+    @Override
+    public GatewayReceiverFactory addGatewayTransportFilter(GatewayTransportFilter filter) {
+      return null;
+    }
+
+    @Override
+    public GatewayReceiverFactory removeGatewayTransportFilter(GatewayTransportFilter filter) {
+      return null;
+    }
+
+    @Override
+    public GatewayReceiverFactory setMaximumTimeBetweenPings(int time) {
+      this.timeBetPings = time;
+      return this;
+    }
+
+    @Override
+    public GatewayReceiverFactory setHostnameForSenders(String address) {
+      this.hostnameForSenders = address;
+      return this;
+    }
+
+    @Override
+    public GatewayReceiverFactory setManualStart(boolean start) {
+      this.manualStart = start;
+      return this;
+    }
+
+    @Override
+    public GatewayReceiver create() {
+      GatewayReceiver receiver = mock(GatewayReceiver.class);
+      when(receiver.isManualStart()).thenReturn(this.manualStart);
+      when(receiver.getBindAddress()).thenReturn(this.bindAdd);
+      when(receiver.getEndPort()).thenReturn(this.endPort);
+      when(receiver.getStartPort()).thenReturn(this.startPort);
+      when(receiver.getSocketBufferSize()).thenReturn(this.socketBuffSize);
+      when(receiver.getHostnameForSenders()).thenReturn(this.hostnameForSenders);
+      when(receiver.getMaximumTimeBetweenPings()).thenReturn(this.timeBetPings);
+      this.cache.addGatewayReceiver(receiver);
+      return receiver;
+    }
+
+    public boolean isManualStart() {
+      return this.manualStart;
+    }
+  }
+}
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[DTD].cache.xml b/geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[DTD].cache.xml
similarity index 100%
rename from geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[DTD].cache.xml
rename to geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[DTD].cache.xml
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[XSD].cache.xml b/geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[XSD].cache.xml
similarity index 100%
rename from geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[XSD].cache.xml
rename to geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.correctConfiguration[XSD].cache.xml
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[DTD].cache.xml b/geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[DTD].cache.xml
similarity index 100%
rename from geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[DTD].cache.xml
rename to geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[DTD].cache.xml
diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[XSD].cache.xml b/geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[XSD].cache.xml
similarity index 100%
rename from geode-core/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[XSD].cache.xml
rename to geode-wan/src/integrationTest/resources/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.multipleReceiversShouldThrowException[XSD].cache.xml