Skip to content
Permalink
Browse files
Add more tests for zookeeper registry (#696)
* fix chinese word issue in screenshot

* add test coverage for integration
support chinese for integration screenshot

* add some unit test

* add more ui test

* add await for resul showing

* use internal screenshot

* add png for screenshot
  • Loading branch information
htynkn committed Feb 23, 2021
1 parent 3a26d7a commit d25b6492f5285c49dd360604909904c6ecb5b542
Showing 22 changed files with 620 additions and 70 deletions.
@@ -0,0 +1,18 @@
# Documentation: https://docs.codecov.io/docs/codecov-yaml

codecov:
branch: develop

coverage:
status:
project:
default:
branches:
- develop

comment:
layout: "reach,diff,flags,files,footer"
behavior: default
require_changes: no
branches:
- develop
@@ -19,4 +19,5 @@ jobs:
run: ./mvnw clean install --batch-mode -DskipTests=false -Dcheckstyle.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1

with:
flags: unit
@@ -12,13 +12,34 @@ jobs:
run: cp docker/latest/** ./
- name: Docker build
run: docker build -t apache/dubbo-admin-integration:latest .
- name: Prepare agent
run: mkdir jacoco && wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.6/org.jacoco.agent-0.8.6-runtime.jar -O jacoco/jacoco.jar && wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.6/org.jacoco.cli-0.8.6-nodeps.jar -O jacoco/jacoco-cli.jar
- name: Build provider and consumer image
run: ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles build-provider package && ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles build-consumer package
- name: Setup xvfb
run: sudo apt-get install xvfb
run: sudo apt-get install xvfb ttf-wqy-zenhei -y && fc-cache -v
- name: Run integration test
run: xvfb-run --server-args="-screen 0, 1024x768x24" ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles dubbo-admin-integration-test -Ddocker.showLogs=true docker:stop docker:remove verify
- name: Save failure screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: failure-screenshots
path: dubbo-admin-test/target/screens/
- uses: actions/upload-artifact@v2
with:
name: screenshots
path: dubbo-admin-test/target/screens/
path: dubbo-admin-test/target/screens/
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 8
- name: Compile server project
run: ./mvnw clean package -DskipTests=true -pl dubbo-admin-server
- name: Generate report
run: java -jar jacoco/jacoco-cli.jar report jacoco/jacoco.exec --classfiles dubbo-admin-server/target/classes/ --sourcefiles dubbo-admin-server/src --xml jacoco/jacoco.xml
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
with:
flags: integration
directory: ./jacoco
@@ -1,7 +1,7 @@
# Dubbo Admin

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/apache/dubbo-admin/CI)
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin)
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin/branches/develop)
![license](https://img.shields.io/github/license/apache/dubbo-admin.svg)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/apache/dubbo-admin.svg)](http://isitmaintained.com/project/apache/dubbo-admin "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/apache/dubbo-admin.svg)](http://isitmaintained.com/project/apache/dubbo-admin "Percentage of issues still open")
@@ -1,7 +1,7 @@
# Dubbo控制台

[![Build Status](https://travis-ci.org/apache/dubbo-admin.svg?branch=develop)](https://travis-ci.org/apache/dubbo-admin)
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin)
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin/branches/develop)
![license](https://img.shields.io/github/license/apache/dubbo-admin.svg)

[English version](README.md).
@@ -23,5 +23,9 @@ FROM openjdk:8-jre
LABEL maintainer="dev@dubbo.apache.org"
RUN apt-get update && apt-get install -y tini
COPY --from=0 /source/dubbo-admin-snapshot/dubbo-admin-distribution/target/dubbo-admin-0.3.0-SNAPSHOT.jar /app.jar
ENTRYPOINT ["tini","--","java","-XX:+UnlockExperimentalVMOptions","-XX:+UseCGroupMemoryLimitForHeap","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
COPY entrypoint.sh /usr/local/bin/entrypoint.sh

ENV JAVA_OPTS = ""

ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"]
EXPOSE 8080
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
@@ -16,7 +16,7 @@
#

# centers in dubbo2.7
admin.registry.address=zookeeper://127.0.0.1:2183
admin.config-center=zookeeper://127.0.0.1:2183
admin.metadata.address=zookeeper://127.0.0.1:2183
admin.registry.address=zookeeper://127.0.0.1:2181
admin.config-center=zookeeper://127.0.0.1:2181
admin.metadata.address=zookeeper://127.0.0.1:2181
admin.check.authority=false
@@ -16,9 +16,9 @@
#

# centers in dubbo2.7
admin.registry.address=zookeeper://127.0.0.1:2183
admin.config-center=zookeeper://127.0.0.1:2183
admin.metadata-report.address=zookeeper://127.0.0.1:2183
admin.registry.address=zookeeper://127.0.0.1:2181
admin.config-center=zookeeper://127.0.0.1:2181
admin.metadata-report.address=zookeeper://127.0.0.1:2181

#admin.registry.address=nacos://127.0.0.1:8848
#admin.config-center=nacos://127.0.0.1:8848
@@ -0,0 +1,49 @@
/*
* 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.utils;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class LocalDateTimeUtilTest {
@Test
public void shouldGetLocalDateTime() {
LocalDateTime localDateTime = LocalDateTimeUtil.formatToLDT("2020-01-02 10:11:12");

assertThat(localDateTime.getYear(), is(2020));
assertThat(localDateTime.getMonthValue(), is(1));
assertThat(localDateTime.getDayOfMonth(), is(2));

assertThat(localDateTime.getHour(), is(10));
assertThat(localDateTime.getMinute(), is(11));
assertThat(localDateTime.getSecond(), is(12));
}

@Test
public void shouldGetLocalDate() {
LocalDate localDate = LocalDateTimeUtil.formatToLD("2020-01-02");

assertThat(localDate.getYear(), is(2020));
assertThat(localDate.getMonthValue(), is(1));
assertThat(localDate.getDayOfMonth(), is(2));
}
}
@@ -122,9 +122,9 @@
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium.fluent</groupId>
<artifactId>fluent-selenium</artifactId>
<version>1.17</version>
<groupId>org.fluentlenium</groupId>
<artifactId>fluentlenium-junit</artifactId>
<version>3.9.1</version>
<scope>test</scope>
</dependency>

@@ -235,7 +235,13 @@
</admin.config-center>
<admin.metadata-report.address>zookeeper://zookeeper:2181
</admin.metadata-report.address>
<JAVA_OPTS>-javaagent:/jacoco/jacoco.jar=destfile=/jacoco/jacoco.exec</JAVA_OPTS>
</env>
<volumes>
<bind>
<volume>${project.basedir}/../jacoco:/jacoco</volume>
</bind>
</volumes>
<links>
<link>zookeeper:zookeeper</link>
</links>
@@ -246,6 +252,7 @@
<method>GET</method>
<status>200</status>
</http>
<time>20000</time>
</wait>
</run>
</image>
@@ -18,30 +18,53 @@
*/
package org.apache.dubbo.admin;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.admin.pages.LoginPage;
import org.fluentlenium.adapter.junit.FluentTest;
import org.fluentlenium.core.annotation.Page;
import org.junit.BeforeClass;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

public class BaseIT {
public class BaseIT extends FluentTest {
private Logger logger = LoggerFactory.getLogger(this.getClass());

public void takeShot(WebDriver webDriver, String name) {
TakesScreenshot scrShot = ((TakesScreenshot) webDriver);
protected static WebDriver driver;
protected static String BASE_URL;

@Page
LoginPage loginPage;

public BaseIT() {
setWebDriver("chrome");
setScreenshotPath("target/screens/");
setScreenshotMode(TriggerMode.AUTOMATIC_ON_FAIL);
}

@BeforeClass
public static void beforeClass() {
WebDriverManager.chromedriver().setup();

File SrcFile = scrShot.getScreenshotAs(OutputType.FILE);
BASE_URL = StringUtils.defaultString(System.getenv("BASEURL"), "http://localhost:8082");
}

@Override
public String getBaseUrl() {
return BASE_URL;
}

File DestFile = new File("target/screens/" + name + ".png");

public void autoLogin() {
goTo(loginPage);

try {
FileUtils.copyFile(SrcFile, DestFile);
} catch (IOException e) {
logger.info("#takeShot# take shot fail", e);
await().untilPredicate(fluentControl -> loginPage.url().contains("login"));

loginPage.loginWithRoot();
} catch (Exception ignore) {
logger.info("already log in");
}
}
}
@@ -18,51 +18,18 @@
*/
package org.apache.dubbo.admin;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.apache.dubbo.admin.pages.LoginPage;
import org.fluentlenium.core.annotation.Page;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.seleniumhq.selenium.fluent.FluentWebDriver;

import java.util.concurrent.TimeUnit;

public class LoginIT extends BaseIT {
private static WebDriver driver;
private static FluentWebDriver fwd;
private static String BASE_URL;

@BeforeClass
public static void beforeClass() {
WebDriverManager.firefoxdriver().setup();

driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
fwd = new FluentWebDriver(driver);

BASE_URL = StringUtils.defaultString(System.getenv("BASEURL"), "http://localhost:8082");
}

@AfterClass
public static void afterClass() {
driver.quit();
}

@Page
private LoginPage loginPage;

@Test
public void shouldOpenLogin() {
driver.get(BASE_URL + "/#/login");

fwd.input(By.name("username")).sendKeys("root");
fwd.input(By.cssSelector("input[type='password']")).sendKeys("root");

this.takeShot(driver, "login");

public void shouldLogin() {
goTo(loginPage).loginWithRoot();

fwd.button(By.tagName("button")).click();
loginPage.takeScreenshot("login.png");
}
}
@@ -0,0 +1,42 @@
/*
*
* 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 org.apache.dubbo.admin.pages.ManagePage;
import org.fluentlenium.core.annotation.Page;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;

public class ManageIT extends BaseIT {
@Page
private ManagePage managePage;

@Test
public void shouldViewConfig() {
autoLogin();

goTo(managePage).showConfigDetailFor("global");

assertThat(managePage.getConfigDetail(), containsString("dubbo.registry.address"));

managePage.takeScreenshot("manage-config.png");
}
}

0 comments on commit d25b649

Please sign in to comment.