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

wangxin pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-ops.git


The following commit(s) were added to refs/heads/develop by this push:
     new f07c9c5  Add integration tests (#253)
f07c9c5 is described below

commit f07c9c5213f5062de4b37857dba653d2d5c8febb
Author: kezhenxu94 <[email protected]>
AuthorDate: Sat Jan 19 21:24:35 2019 +0800

    Add integration tests (#253)
    
    * Add integration tests
---
 dubbo-admin-backend/pom.xml                        |   1 -
 .../src/main/resources/application-test.properties |  21 ++++
 .../dubbo/admin/AbstractSpringIntegrationTest.java |  63 ++++++++++
 .../admin/controller/ServiceControllerTest.java    | 140 +++++++++++++++++++++
 pom.xml                                            |   2 +-
 5 files changed, 225 insertions(+), 2 deletions(-)

diff --git a/dubbo-admin-backend/pom.xml b/dubbo-admin-backend/pom.xml
index 333fec0..3c9dbd9 100644
--- a/dubbo-admin-backend/pom.xml
+++ b/dubbo-admin-backend/pom.xml
@@ -119,7 +119,6 @@
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
         </dependency>
-
     </dependencies>
 
     <build>
diff --git a/dubbo-admin-backend/src/main/resources/application-test.properties 
b/dubbo-admin-backend/src/main/resources/application-test.properties
new file mode 100644
index 0000000..2363252
--- /dev/null
+++ b/dubbo-admin-backend/src/main/resources/application-test.properties
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+# centers in dubbo2.7
+admin.registry.address=zookeeper://127.0.0.1:2182
+admin.config-center=zookeeper://127.0.0.1:2182
+admin.metadata.address=zookeeper://127.0.0.1:2182
diff --git 
a/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/AbstractSpringIntegrationTest.java
 
b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/AbstractSpringIntegrationTest.java
new file mode 100644
index 0000000..a151d3b
--- /dev/null
+++ 
b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/AbstractSpringIntegrationTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.dubbo.admin;
+
+import java.io.IOException;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.TestingServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestTemplate;
+
+@ActiveProfiles("test")
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public abstract class AbstractSpringIntegrationTest {
+  protected RestTemplate restTemplate = (new 
TestRestTemplate()).getRestTemplate();
+
+  protected static TestingServer zkServer;
+  protected static CuratorFramework zkClient;
+
+  @Value("${local.server.port}")
+  protected int port;
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    zkServer = new TestingServer(2182, true);
+    zkClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), 
new RetryOneTime(2000));
+    zkClient.start();
+  }
+
+  @AfterClass
+  public static void afterClass() throws IOException {
+    zkClient.close();
+    zkServer.stop();
+  }
+
+  protected String url(final String path) {
+    return "http://localhost:"; + port + path;
+  }
+}
diff --git 
a/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ServiceControllerTest.java
 
b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ServiceControllerTest.java
new file mode 100644
index 0000000..7518675
--- /dev/null
+++ 
b/dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ServiceControllerTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.dubbo.admin.controller;
+
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import org.apache.dubbo.admin.AbstractSpringIntegrationTest;
+import org.apache.dubbo.admin.common.util.Constants;
+import org.apache.dubbo.admin.model.dto.ServiceDTO;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.registry.Registry;
+import org.apache.dubbo.registry.support.AbstractRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class ServiceControllerTest extends AbstractSpringIntegrationTest {
+  @Autowired
+  private Registry registry;
+
+  @Before
+  public void setUp() throws InterruptedException {
+    final Set<URL> registered = ((AbstractRegistry) registry).getRegistered();
+    for (final URL url : registered) {
+      registry.unregister(url);
+    }
+    TimeUnit.SECONDS.sleep(1);
+  }
+
+  @Test
+  public void shouldGetAllServices() throws Exception {
+    final int num = 10;
+    for (int i = 0; i < num; i++) {
+      final String service = "org.apache.dubbo.admin.test.service" + i;
+      final URL url = i % 2 == 0
+          ? generateProviderServiceUrl("dubbo-admin", service)
+          : generateConsumerServiceUrl("dubbo-admin", service);
+      registry.register(url);
+    }
+    TimeUnit.SECONDS.sleep(1);
+
+    final ResponseEntity<Set<String>> response = restTemplate.exchange(
+        url("/api/{env}/services"), HttpMethod.GET, null,
+        new ParameterizedTypeReference<Set<String>>() {
+        }, "whatever"
+    );
+    assertThat(response.getStatusCode(), is(HttpStatus.OK));
+    assertThat(response.getBody(), hasSize(num));
+  }
+
+  @Test
+  public void shouldGetAllApplications() throws Exception {
+    final int num = 10;
+    for (int i = 0; i < num; i++) {
+      final String service = "org.apache.dubbo.admin.test.service";
+      final URL url = generateProviderServiceUrl("dubbo-admin-" + i, service);
+      registry.register(url);
+    }
+    TimeUnit.SECONDS.sleep(1);
+
+    final ResponseEntity<Set<String>> responseEntity = restTemplate.exchange(
+        url("/api/{env}/applications"), HttpMethod.GET, null,
+        new ParameterizedTypeReference<Set<String>>() {
+        }, "whatever"
+    );
+    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
+    assertThat(responseEntity.getBody(), hasSize(num));
+  }
+
+  @Test
+  public void shouldFilterUsingPattern() throws InterruptedException {
+    final int num = 10;
+    for (int i = 0; i < num; i++) {
+      final String service = "org.apache.dubbo.admin.test.service" + i + 
".pattern" + (i % 2);
+      final String application = "dubbo-admin";
+      registry.register(generateProviderServiceUrl(application, service));
+    }
+    TimeUnit.SECONDS.sleep(1);
+
+    ResponseEntity<Set<ServiceDTO>> responseEntity = restTemplate.exchange(
+        url("/api/{env}/service?pattern={pattern}&filter={filter}"),
+        HttpMethod.GET, null, new 
ParameterizedTypeReference<Set<ServiceDTO>>() {
+        }, "whatever", Constants.SERVICE, "*"
+    );
+    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
+    assertThat(responseEntity.getBody(), hasSize(num));
+
+    responseEntity = restTemplate.exchange(
+        url("/api/{env}/service?pattern={pattern}&filter={filter}"),
+        HttpMethod.GET, null, new 
ParameterizedTypeReference<Set<ServiceDTO>>() {
+        }, "whatever", Constants.SERVICE, "*pattern0"
+    );
+    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
+    assertThat(responseEntity.getBody(), hasSize(num / 2));
+
+    responseEntity = restTemplate.exchange(
+        url("/api/{env}/service?pattern={pattern}&filter={filter}"),
+        HttpMethod.GET, null, new 
ParameterizedTypeReference<Set<ServiceDTO>>() {
+        }, "whatever", Constants.SERVICE, "*pattern1"
+    );
+    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
+    assertThat(responseEntity.getBody(), hasSize(num / 2));
+  }
+
+  private URL generateProviderServiceUrl(final String application, final 
String serviceName) {
+    return URL.valueOf("dubbo://127.0.0.1:20881/" + serviceName
+        + "?application=" + application
+        + "&interface=" + serviceName
+        + "&side=provider");
+  }
+
+  private URL generateConsumerServiceUrl(final String application, final 
String serviceName) {
+    return URL.valueOf("dubbo://127.0.0.1:20881/" + serviceName
+        + "?application=" + application
+        + "&interface=" + serviceName
+        + "&side=consumer");
+  }
+}
diff --git a/pom.xml b/pom.xml
index ad77093..2aece56 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,7 +58,7 @@
         <commons-lang3-version>3.7</commons-lang3-version>
                <dubbo-version>2.7.0-SNAPSHOT</dubbo-version>
                <curator-version>2.12.0</curator-version>
-               <curator-test-version>2.12.0</curator-test-version>
+               <curator-test-version>4.1.0</curator-test-version>
                <fastjson-version>1.2.46</fastjson-version>
                <springfox-swagger-version>2.9.2</springfox-swagger-version>
                <netty-version>4.1.30.Final</netty-version>

Reply via email to