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

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

commit aa3352662fe2cedc29bbbfed9272961a309e4748
Author: zhouxh <[email protected]>
AuthorDate: Fri Dec 21 11:05:18 2018 -0800

    GEODE-6143: remove PowerMock for 
GatewayReceiverXmlParsingValidationsJUnitTest
---
 ...ewayReceiverXmlParsingValidationsJUnitTest.java |  55 ++++----
 .../geode/internal/cache/wan/MyWANFactoryImpl.java | 144 +++++++++++++++++++++
 ....apache.geode.internal.cache.wan.spi.WANFactory |  15 +++
 3 files changed, 181 insertions(+), 33 deletions(-)

diff --git 
a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
 
b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
index 9461abd..e8592b1 100644
--- 
a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
+++ 
b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/GatewayReceiverXmlParsingValidationsJUnitTest.java
@@ -16,48 +16,38 @@ 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.GatewayReceiverFactory;
+import org.apache.geode.cache.wan.GatewayReceiver;
+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;
-  private GatewayReceiverFactory receiverFactory;
 
   @Parameterized.Parameter
   public static String validationStrategy;
@@ -70,13 +60,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 +73,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
@@ -107,4 +95,5 @@ public class GatewayReceiverXmlParsingValidationsJUnitTest {
       cache.close();
     }
   }
+
 }
diff --git 
a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/MyWANFactoryImpl.java
 
b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/wan/MyWANFactoryImpl.java
new file mode 100644
index 0000000..39272d2
--- /dev/null
+++ 
b/geode-core/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/main/resources/META-INF/services/org.apache.geode.internal.cache.wan.spi.WANFactory
 
b/geode-core/src/main/resources/META-INF/services/org.apache.geode.internal.cache.wan.spi.WANFactory
new file mode 100644
index 0000000..be99572
--- /dev/null
+++ 
b/geode-core/src/main/resources/META-INF/services/org.apache.geode.internal.cache.wan.spi.WANFactory
@@ -0,0 +1,15 @@
+# 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.
+org.apache.geode.internal.cache.wan.MyWANFactoryImpl

Reply via email to