diff --git a/pom.xml b/pom.xml index 5ca7840e..15f47145 100644 --- a/pom.xml +++ b/pom.xml @@ -20,8 +20,8 @@ github UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 @@ -48,6 +48,25 @@ provided + + org.springframework.boot + spring-boot + 2.3.2.RELEASE + true + + + org.springframework.boot + spring-boot-configuration-processor + 2.3.2.RELEASE + true + + + org.springframework + spring-context + 5.0.8.RELEASE + true + + cn.jpush.api jiguang-common diff --git a/spring-example/.gitignore b/spring-example/.gitignore new file mode 100644 index 00000000..549e00a2 --- /dev/null +++ b/spring-example/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/spring-example/.mvn/wrapper/MavenWrapperDownloader.java b/spring-example/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 00000000..a45eb6ba --- /dev/null +++ b/spring-example/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,118 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed 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 + * + * https://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. + */ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/spring-example/.mvn/wrapper/maven-wrapper.jar b/spring-example/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..2cc7d4a5 Binary files /dev/null and b/spring-example/.mvn/wrapper/maven-wrapper.jar differ diff --git a/spring-example/.mvn/wrapper/maven-wrapper.properties b/spring-example/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..642d572c --- /dev/null +++ b/spring-example/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/spring-example/mvnw b/spring-example/mvnw new file mode 100644 index 00000000..a16b5431 --- /dev/null +++ b/spring-example/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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 +# +# https://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/spring-example/mvnw.cmd b/spring-example/mvnw.cmd new file mode 100644 index 00000000..c8d43372 --- /dev/null +++ b/spring-example/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/spring-example/pom.xml b/spring-example/pom.xml new file mode 100644 index 00000000..a1988486 --- /dev/null +++ b/spring-example/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.3.RELEASE + + + cn.seanything + example + 0.0.1-SNAPSHOT + example + Demo project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + cn.jpush.api + jiguang-common + 1.1.8 + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + cn.jpush.api + jpush-client + 3.4.7-SNAPSHOT + compile + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-example/src/main/java/cn/seanything/example/ExampleApplication.java b/spring-example/src/main/java/cn/seanything/example/ExampleApplication.java new file mode 100644 index 00000000..9c754c84 --- /dev/null +++ b/spring-example/src/main/java/cn/seanything/example/ExampleApplication.java @@ -0,0 +1,19 @@ +package cn.seanything.example; + +import cn.jpush.api.JPushClient; +import cn.jpush.api.config.EnableJPushClient; +import cn.seanything.example.service.MyService; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; + +@SpringBootApplication +@EnableJPushClient +public class ExampleApplication { + + public static void main(String[] args) { + ConfigurableApplicationContext context = SpringApplication.run(ExampleApplication.class, args); + context.getBean(MyService.class).test(); + } + +} diff --git a/spring-example/src/main/java/cn/seanything/example/service/MyService.java b/spring-example/src/main/java/cn/seanything/example/service/MyService.java new file mode 100644 index 00000000..d6b1e7cc --- /dev/null +++ b/spring-example/src/main/java/cn/seanything/example/service/MyService.java @@ -0,0 +1,24 @@ +package cn.seanything.example.service; + +import cn.jpush.api.JPushClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author seanything + * @date 2020/8/20 + */ +@Service +public class MyService { + + @Autowired + private JPushClient jPushClient; + + public void test(){ + try { + jPushClient.sendAndroidNotificationWithAlias("标题","测试",null,"asd"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/spring-example/src/main/resources/application.yml b/spring-example/src/main/resources/application.yml new file mode 100644 index 00000000..f48ab08a --- /dev/null +++ b/spring-example/src/main/resources/application.yml @@ -0,0 +1,7 @@ +app: + app-key: 'e56934de11804322ff312aa5' + master-secret: '81fade5c0ac242e01ca13d16' +jpush: + android-config: + badge-class: cn.jk + badge-add-num: 1 \ No newline at end of file diff --git a/spring-example/src/test/java/cn/seanything/example/ExampleApplicationTests.java b/spring-example/src/test/java/cn/seanything/example/ExampleApplicationTests.java new file mode 100644 index 00000000..52b40c84 --- /dev/null +++ b/spring-example/src/test/java/cn/seanything/example/ExampleApplicationTests.java @@ -0,0 +1,13 @@ +package cn.seanything.example; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ExampleApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/main/java/cn/jpush/api/JPushClient.java b/src/main/java/cn/jpush/api/JPushClient.java index 74b1458b..3666bafc 100644 --- a/src/main/java/cn/jpush/api/JPushClient.java +++ b/src/main/java/cn/jpush/api/JPushClient.java @@ -5,8 +5,10 @@ import java.util.Set; import cn.jiguang.common.resp.*; +import cn.jpush.api.config.PushConfig; import cn.jpush.api.push.CIDResult; import cn.jpush.api.push.model.*; +import cn.jpush.api.push.model.notification.*; import cn.jpush.api.report.*; import cn.jpush.api.report.model.CheckMessagePayload; import com.google.gson.JsonObject; @@ -24,122 +26,135 @@ import cn.jpush.api.push.PushClient; import cn.jpush.api.push.PushResult; import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.IosAlert; -import cn.jpush.api.push.model.notification.Notification; import cn.jpush.api.schedule.ScheduleClient; import cn.jpush.api.schedule.ScheduleListResult; import cn.jpush.api.schedule.ScheduleMsgIdsResult; import cn.jpush.api.schedule.ScheduleResult; import cn.jpush.api.schedule.model.SchedulePayload; import cn.jpush.api.schedule.model.TriggerPayload; +import com.sun.media.jfxmediaimpl.platform.ios.IOSPlatform; /** * The global entrance of JPush API library. */ public class JPushClient { private final PushClient _pushClient; - private final ReportClient _reportClient; - private final DeviceClient _deviceClient; + private final ReportClient _reportClient; + private final DeviceClient _deviceClient; private final ScheduleClient _scheduleClient; - - /** - * Create a JPush Client. - * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - */ - public JPushClient(String masterSecret, String appKey) { - _pushClient = new PushClient(masterSecret, appKey); - _reportClient = new ReportClient(masterSecret, appKey); - _deviceClient = new DeviceClient(masterSecret, appKey); + private final PushConfig pushConfig; + + /** + * Create a JPush Client. + * + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. + * @param pushConfig send message with config + */ + public JPushClient(String masterSecret, String appKey, PushConfig pushConfig) { + _pushClient = new PushClient(masterSecret, appKey); + _reportClient = new ReportClient(masterSecret, appKey); + _deviceClient = new DeviceClient(masterSecret, appKey); _scheduleClient = new ScheduleClient(masterSecret, appKey); - } + this.pushConfig = pushConfig; + } /** * Create a JPush Client by custom Client configuration. * * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - * @param proxy The proxy, if there is no proxy, should be null. - * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param appKey The KEY of one application on JPush. + * @param proxy The proxy, if there is no proxy, should be null. + * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param pushConfig send message with config */ - public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) { + public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf, PushConfig pushConfig) { _pushClient = new PushClient(masterSecret, appKey, proxy, conf); _reportClient = new ReportClient(masterSecret, appKey, proxy, conf); _deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf); _scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf); + this.pushConfig = pushConfig; } /** * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setMaxRetryTimes} instead of this constructor. - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. + * + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. * @param maxRetryTimes The max retry times. + * @param pushConfig send message with config */ @Deprecated - public JPushClient(String masterSecret, String appKey, int maxRetryTimes) { + public JPushClient(String masterSecret, String appKey, int maxRetryTimes, PushConfig pushConfig) { _pushClient = new PushClient(masterSecret, appKey, maxRetryTimes); _reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes); _deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes); _scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes); - } + this.pushConfig = pushConfig; + } /** * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setMaxRetryTimes} instead of this constructor. - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. + * + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. * @param maxRetryTimes The max retry times. - * @param proxy The proxy, if there is no proxy, should be null. + * @param proxy The proxy, if there is no proxy, should be null. + * @param pushConfig send message with config */ @Deprecated - public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy) { + public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, PushConfig pushConfig) { _pushClient = new PushClient(masterSecret, appKey, maxRetryTimes, proxy); _reportClient = new ReportClient(masterSecret, appKey, maxRetryTimes, proxy); _deviceClient = new DeviceClient(masterSecret, appKey, maxRetryTimes, proxy); _scheduleClient = new ScheduleClient(masterSecret, appKey, maxRetryTimes, proxy); + this.pushConfig = pushConfig; } - + /** * Create a JPush Client by custom Client configuration. - * + *

* If you are using JPush privacy cloud, maybe this constructor is what you needed. * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setMaxRetryTimes} instead of this constructor. * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. * @param maxRetryTimes Client request retry times. - * @param proxy The proxy, if there is no proxy, should be null. - * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param proxy The proxy, if there is no proxy, should be null. + * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param pushConfig */ @Deprecated - public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf) { + public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf, PushConfig pushConfig) { conf.setMaxRetryTimes(maxRetryTimes); _pushClient = new PushClient(masterSecret, appKey, proxy, conf); _reportClient = new ReportClient(masterSecret, appKey, proxy, conf); _deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf); _scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf); + this.pushConfig = pushConfig; } /** * Create a JPush Client by custom Client configuration with global settings. - * + *

* If you are using JPush privacy cloud, and you want different settings from default globally, * maybe this constructor is what you needed. * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setGlobalPushSetting} instead of this constructor. * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - * @param maxRetryTimes Client request retry times. - * @param proxy The proxy, if there is no proxy, should be null. - * @param conf The client configuration. Can use ClientConfig.getInstance() as default. + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. + * @param maxRetryTimes Client request retry times. + * @param proxy The proxy, if there is no proxy, should be null. + * @param conf The client configuration. Can use ClientConfig.getInstance() as default. * @param apnsProduction Global APNs environment setting. It will override PushPayload Options. - * @param timeToLive Global time_to_live setting. It will override PushPayload Options. + * @param timeToLive Global time_to_live setting. It will override PushPayload Options. + * @param pushConfig send message with config */ @Deprecated public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf, - boolean apnsProduction, long timeToLive) { + boolean apnsProduction, long timeToLive, PushConfig pushConfig) { conf.setMaxRetryTimes(maxRetryTimes); conf.setApnsProduction(apnsProduction); conf.setTimeToLive(timeToLive); @@ -147,21 +162,23 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr _reportClient = new ReportClient(masterSecret, appKey, proxy, conf); _deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf); _scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf); + this.pushConfig = pushConfig; } - - /** - * Create a JPush Client with global settings. - * - * If you want different settings from default globally, this constructor is what you needed. - * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setGlobalPushSetting} instead of this constructor. + + /** + * Create a JPush Client with global settings. + *

+ * If you want different settings from default globally, this constructor is what you needed. + * This will be removed in the future. Please use ClientConfig{jiguang-common cn.jiguang.common.ClientConfig#setGlobalPushSetting} instead of this constructor. * - * @param masterSecret API access secret of the appKey. - * @param appKey The KEY of one application on JPush. - * @param apnsProduction Global APNs environment setting. It will override PushPayload Options. - * @param timeToLive Global time_to_live setting. It will override PushPayload Options. - */ + * @param masterSecret API access secret of the appKey. + * @param appKey The KEY of one application on JPush. + * @param apnsProduction Global APNs environment setting. It will override PushPayload Options. + * @param timeToLive Global time_to_live setting. It will override PushPayload Options. + * @param pushConfig send message with config + */ @Deprecated - public JPushClient(String masterSecret, String appKey, boolean apnsProduction, long timeToLive) { + public JPushClient(String masterSecret, String appKey, boolean apnsProduction, long timeToLive, PushConfig pushConfig) { ClientConfig conf = ClientConfig.getInstance(); conf.setApnsProduction(apnsProduction); conf.setTimeToLive(timeToLive); @@ -169,6 +186,7 @@ public JPushClient(String masterSecret, String appKey, boolean apnsProduction, l _reportClient = new ReportClient(masterSecret, appKey); _deviceClient = new DeviceClient(masterSecret, appKey); _scheduleClient = new ScheduleClient(masterSecret, appKey); + this.pushConfig = pushConfig; } public PushClient getPushClient() { @@ -179,46 +197,46 @@ public PushClient getPushClient() { /** * Send a push with PushPayload object. - * - * @param pushPayload payload object of a push. + * + * @param pushPayload payload object of a push. * @return PushResult The result object of a Push. Can be printed to a JSON. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ - public PushResult sendPush(PushPayload pushPayload) throws APIConnectionException, APIRequestException { - return _pushClient.sendPush(pushPayload); - } - - /** - * Send a push with JSON string. - * - * You can send a push JSON string directly with this method. - * - * Attention: globally settings cannot be affect this type of Push. - * - * @param payloadString payload of a push. + public PushResult sendPush(PushPayload pushPayload) throws APIConnectionException, APIRequestException { + return _pushClient.sendPush(pushPayload); + } + + /** + * Send a push with JSON string. + *

+ * You can send a push JSON string directly with this method. + *

+ * Attention: globally settings cannot be affect this type of Push. + * + * @param payloadString payload of a push. * @return PushResult. Can be printed to a JSON. - * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. - */ + * @throws APIConnectionException if a remote or network exception occurs. + * @throws APIRequestException if a request exception occurs. + */ public PushResult sendPush(String payloadString) throws APIConnectionException, APIRequestException { return _pushClient.sendPush(payloadString); } - + /** * Validate a push action, but do NOT send it actually. - * + * * @param payload payload of a push. * @return PushResult. Can be printed to a JSON. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendPushValidate(PushPayload payload) throws APIConnectionException, APIRequestException { - return _pushClient.sendPushValidate(payload); + return _pushClient.sendPushValidate(payload); } public PushResult sendPushValidate(String payloadString) throws APIConnectionException, APIRequestException { - return _pushClient.sendPushValidate(payloadString); + return _pushClient.sendPushValidate(payloadString); } public BatchPushResult batchSendPushByRegId(List pushPayloadList) throws APIConnectionException, APIRequestException { @@ -231,35 +249,36 @@ public BatchPushResult batchSendPushByAlias(List pushPayloadList) t /** * Get cid list, the data form of cid is appKey-uuid. + * * @param count the count of cid list, from 1 to 1000. default is 1. - * @param type default is push, option: schedule + * @param type default is push, option: schedule * @return CIDResult, an array of cid * @throws APIConnectionException connect exception - * @throws APIRequestException request exception + * @throws APIRequestException request exception */ public CIDResult getCidList(int count, String type) throws APIConnectionException, APIRequestException { return _pushClient.getCidList(count, type); } - + // ------------------------------- Report API /** - * Get received report. - * + * Get received report. + * * @param msgIds 100 msgids to batch getting is supported. * @return ReceivedResult. Can be printed to JSON. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ReceivedsResult getReportReceiveds(String msgIds) throws APIConnectionException, APIRequestException { - return _reportClient.getReceiveds(msgIds); - } - + return _reportClient.getReceiveds(msgIds); + } + public UsersResult getReportUsers(TimeUnit timeUnit, String start, int duration) throws APIConnectionException, APIRequestException { return _reportClient.getUsers(timeUnit, start, duration); } - + public MessagesResult getReportMessages(String msgIds) throws APIConnectionException, APIRequestException { return _reportClient.getMessages(msgIds); } @@ -278,11 +297,33 @@ public MessageDetailResult getMessagesDetail(String msgIds) throws APIConnectionException, APIRequestException { return _reportClient.getMessagesDetail(msgIds); } - + // ------------------------------ Shortcuts - notification - public PushResult sendNotificationAll(String alert) throws APIConnectionException, APIRequestException { - PushPayload payload = PushPayload.alertAll(alert); + public PushResult sendNotificationAll(String title, String alert) throws APIConnectionException, APIRequestException { + PushPayload payload = PushPayload.newBuilder() + .setPlatform(Platform.all()) + .setAudience(Audience.all()) + .setNotification( + Notification.newBuilder() + .addPlatformNotification( + AndroidNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .setTitle(title) + .addCustom("badge_add_num", pushConfig.getAndroidConfig().getBadgeAddNum()) + .addCustom("badge_class", pushConfig.getAndroidConfig().getBadgeClass()) + .build()) + .addPlatformNotification( + IosNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .build() + ) + .addPlatformNotification( + WinphoneNotification.alert(alert)) + .build()) + .build(); return _pushClient.sendPush(payload); } @@ -291,23 +332,66 @@ public PushResult sendNotificationAll(String alert) throws APIConnectionExceptio * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @return push result * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ - public PushResult sendNotificationAll(String alert, SMS sms) throws APIConnectionException, APIRequestException { - PushPayload payload = PushPayload.alertAll(alert, sms); + public PushResult sendNotificationAll(String title, String alert, SMS sms) throws APIConnectionException, APIRequestException { + PushPayload payload = PushPayload.newBuilder() + .setPlatform(Platform.all()) + .setAudience(Audience.all()) + .setNotification( + Notification.newBuilder() + .addPlatformNotification( + AndroidNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .setTitle(title) + .addCustom("badge_add_num", pushConfig.getAndroidConfig().getBadgeAddNum()) + .addCustom("badge_class", pushConfig.getAndroidConfig().getBadgeClass()) + .build()) + .addPlatformNotification( + IosNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .build() + ) + .addPlatformNotification( + WinphoneNotification.alert(alert)) + .build()) + .setSMS(sms) + .build(); return _pushClient.sendPush(payload); } - public PushResult sendAndroidNotificationWithAlias(String title, String alert, - Map extras, String... alias) + public PushResult sendAndroidNotificationWithAlias(String title, String alert, + Map extras, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.android()) + .setPlatform(Platform.all()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.android(alert, title, extras)) + .setNotification( + Notification.newBuilder() + .addPlatformNotification( + AndroidNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .setTitle(title) + .addCustom("badge_add_num", pushConfig.getAndroidConfig().getBadgeAddNum()) + .addCustom("badge_class", pushConfig.getAndroidConfig().getBadgeClass()) + .addExtras(extras) + .build()) + .addPlatformNotification( + IosNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .addExtras(extras) + .build() + ) + .addPlatformNotification( + WinphoneNotification.newBuilder().addExtras(extras).setAlert(alert).build()) + .build()) .build(); return _pushClient.sendPush(payload); } @@ -316,34 +400,74 @@ public PushResult sendAndroidNotificationWithAlias(String title, String alert, * Send a notification to Android with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The notification title. - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The notification title. + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra parameter. - * @param alias The users' alias. + * @param alias The users' alias. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidNotificationWithAlias(String title, String alert, SMS sms, Map extras, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.android()) + .setPlatform(Platform.all()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.android(alert, title, extras)) + .setNotification( + Notification.newBuilder() + .addPlatformNotification( + AndroidNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .setTitle(title) + .addCustom("badge_add_num", pushConfig.getAndroidConfig().getBadgeAddNum()) + .addCustom("badge_class", pushConfig.getAndroidConfig().getBadgeClass()) + .addExtras(extras) + .build()) + .addPlatformNotification( + IosNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .addExtras(extras) + .build() + ) + .addPlatformNotification( + WinphoneNotification.newBuilder().addExtras(extras).setAlert(alert).build()) + .build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); } - public PushResult sendAndroidNotificationWithRegistrationID(String title, String alert, - Map extras, String... registrationID) + public PushResult sendAndroidNotificationWithRegistrationID(String title, String alert, + Map extras, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.android()) + .setPlatform(Platform.all()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.android(alert, title, extras)) + .setNotification( + Notification.newBuilder() + .addPlatformNotification( + AndroidNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .setTitle(title) + .addCustom("badge_add_num", pushConfig.getAndroidConfig().getBadgeAddNum()) + .addCustom("badge_class", pushConfig.getAndroidConfig().getBadgeClass()) + .addExtras(extras) + .build()) + .addPlatformNotification( + IosNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .addExtras(extras) + .build() + ) + .addPlatformNotification( + WinphoneNotification.newBuilder().addExtras(extras).setAlert(alert).build()) + .build()) .build(); return _pushClient.sendPush(payload); } @@ -352,34 +476,54 @@ public PushResult sendAndroidNotificationWithRegistrationID(String title, String * Send a notification to Android with RegistrationID. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The notification title. - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra parameter. + * @param title The notification title. + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra parameter. * @param registrationID The registration id generated by JPush. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidNotificationWithRegistrationID(String title, String alert, SMS sms, Map extras, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.android()) + .setPlatform(Platform.all()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.android(alert, title, extras)) + .setNotification( + Notification.newBuilder() + .addPlatformNotification( + AndroidNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .setTitle(title) + .addCustom("badge_add_num", pushConfig.getAndroidConfig().getBadgeAddNum()) + .addCustom("badge_class", pushConfig.getAndroidConfig().getBadgeClass()) + .addExtras(extras) + .build()) + .addPlatformNotification( + IosNotification.newBuilder() + .parseConfig(pushConfig) + .setAlert(alert) + .addExtras(extras) + .build() + ) + .addPlatformNotification( + WinphoneNotification.newBuilder().addExtras(extras).setAlert(alert).build()) + .build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); } public PushResult sendIosNotificationWithAlias(String alert, - Map extras, String... alias) + Map extras, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .build(); return _pushClient.sendPush(payload); } @@ -387,13 +531,14 @@ public PushResult sendIosNotificationWithAlias(String alert, /** * Send a notification to iOS with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra parameter. - * @param alias The users' alias. + * @param alias The users' alias. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(String alert, SMS sms, Map extras, String... alias) @@ -401,7 +546,7 @@ public PushResult sendIosNotificationWithAlias(String alert, SMS sms, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); @@ -411,12 +556,12 @@ public PushResult sendIosNotificationWithAlias(String alert, SMS sms, * Send an iOS notification with alias. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The wrapper of APNs alert. + * @param alert The wrapper of APNs alert. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(IosAlert alert, Map extras, String... alias) @@ -424,7 +569,7 @@ public PushResult sendIosNotificationWithAlias(IosAlert alert, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .build(); return _pushClient.sendPush(payload); } @@ -434,13 +579,13 @@ public PushResult sendIosNotificationWithAlias(IosAlert alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The wrapper of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alert The wrapper of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(IosAlert alert, SMS sms, Map extras, String... alias) @@ -448,7 +593,7 @@ public PushResult sendIosNotificationWithAlias(IosAlert alert, SMS sms, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); @@ -458,12 +603,12 @@ public PushResult sendIosNotificationWithAlias(IosAlert alert, SMS sms, * Send an iOS notification with alias. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The JSON object of APNs alert. + * @param alert The JSON object of APNs alert. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(JsonObject alert, Map extras, String... alias) @@ -471,7 +616,7 @@ public PushResult sendIosNotificationWithAlias(JsonObject alert, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .build(); return _pushClient.sendPush(payload); } @@ -481,13 +626,13 @@ public PushResult sendIosNotificationWithAlias(JsonObject alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The JSON object of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alert The JSON object of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param extras The extra params. - * @param alias The alias list. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithAlias(JsonObject alert, SMS sms, Map extras, String... alias) @@ -495,19 +640,19 @@ public PushResult sendIosNotificationWithAlias(JsonObject alert, SMS sms, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(alias)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); } - public PushResult sendIosNotificationWithRegistrationID(String alert, - Map extras, String... registrationID) + public PushResult sendIosNotificationWithRegistrationID(String alert, + Map extras, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .build(); return _pushClient.sendPush(payload); } @@ -516,13 +661,13 @@ public PushResult sendIosNotificationWithRegistrationID(String alert, * Send an iOS notification with registrationIds. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The notification content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra params. + * @param alert The notification content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra params. * @param registrationID The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(String alert, SMS sms, Map extras, String... registrationID) @@ -530,7 +675,7 @@ public PushResult sendIosNotificationWithRegistrationID(String alert, SMS sms, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); @@ -540,12 +685,12 @@ public PushResult sendIosNotificationWithRegistrationID(String alert, SMS sms, * Send an iOS notification with registrationIds. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The wrapper of APNs alert. - * @param extras The extra params. + * @param alert The wrapper of APNs alert. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, Map extras, String... registrationID) @@ -553,7 +698,7 @@ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .build(); return _pushClient.sendPush(payload); } @@ -563,13 +708,13 @@ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The wrapper of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra params. + * @param alert The wrapper of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, SMS sms, Map extras, String... registrationID) @@ -577,7 +722,7 @@ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, SMS sms, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); @@ -587,12 +732,12 @@ public PushResult sendIosNotificationWithRegistrationID(IosAlert alert, SMS sms, * Send an iOS notification with registrationIds. * If you want to send alert as a Json object, maybe this method is what you needed. * - * @param alert The wrapper of APNs alert. - * @param extras The extra params. + * @param alert The wrapper of APNs alert. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, Map extras, String... registrationID) @@ -600,7 +745,7 @@ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .build(); return _pushClient.sendPush(payload); } @@ -610,13 +755,13 @@ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, * If you want to send alert as a Json object, maybe this method is what you needed. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param alert The JSON object of APNs alert. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param extras The extra params. + * @param alert The JSON object of APNs alert. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param extras The extra params. * @param registrationID The registration ids. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, SMS sms, Map extras, String... registrationID) @@ -624,13 +769,13 @@ public PushResult sendIosNotificationWithRegistrationID(JsonObject alert, SMS sm PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.registrationId(registrationID)) - .setNotification(Notification.ios(alert, extras)) + .setNotification(Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().addExtras(extras).setAlert(alert).parseConfig(pushConfig).build()).build()) .setSMS(sms) .build(); return _pushClient.sendPush(payload); } - + // ---------------------- shortcuts - message public PushResult sendMessageAll(String msgContent) throws APIConnectionException, APIRequestException { @@ -643,17 +788,17 @@ public PushResult sendMessageAll(String msgContent) throws APIConnectionExceptio * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendMessageAll(String msgContent, SMS sms) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.messageAll(msgContent, sms); return _pushClient.sendPush(payload); } - public PushResult sendAndroidMessageWithAlias(String title, String msgContent, String... alias) + public PushResult sendAndroidMessageWithAlias(String title, String msgContent, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android()) @@ -670,13 +815,13 @@ public PushResult sendAndroidMessageWithAlias(String title, String msgContent, S * Send an Android message with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. + * @param title The message title. * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param alias The alias list. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidMessageWithAlias(String title, String msgContent, SMS sms, String... alias) throws APIConnectionException, APIRequestException { @@ -692,7 +837,7 @@ public PushResult sendAndroidMessageWithAlias(String title, String msgContent, S return _pushClient.sendPush(payload); } - public PushResult sendAndroidMessageWithRegistrationID(String title, String msgContent, String... registrationID) + public PushResult sendAndroidMessageWithRegistrationID(String title, String msgContent, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android()) @@ -709,13 +854,13 @@ public PushResult sendAndroidMessageWithRegistrationID(String title, String msgC * Send an Android message with registration id. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. - * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The message title. + * @param msgContent The message content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param registrationID The registration id list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendAndroidMessageWithRegistrationID(String title, String msgContent, SMS sms, String... registrationID) throws APIConnectionException, APIRequestException { @@ -731,7 +876,7 @@ public PushResult sendAndroidMessageWithRegistrationID(String title, String msgC return _pushClient.sendPush(payload); } - public PushResult sendIosMessageWithAlias(String title, String msgContent, String... alias) + public PushResult sendIosMessageWithAlias(String title, String msgContent, String... alias) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) @@ -748,13 +893,13 @@ public PushResult sendIosMessageWithAlias(String title, String msgContent, Strin * Send an iOS message with alias. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. + * @param title The message title. * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. - * @param alias The alias list. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param alias The alias list. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosMessageWithAlias(String title, String msgContent, SMS sms, String... alias) throws APIConnectionException, APIRequestException { @@ -770,7 +915,7 @@ public PushResult sendIosMessageWithAlias(String title, String msgContent, SMS s return _pushClient.sendPush(payload); } - public PushResult sendIosMessageWithRegistrationID(String title, String msgContent, String... registrationID) + public PushResult sendIosMessageWithRegistrationID(String title, String msgContent, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) @@ -787,13 +932,13 @@ public PushResult sendIosMessageWithRegistrationID(String title, String msgConte * Send an iOS message with registration id. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. - * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The message title. + * @param msgContent The message content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param registrationID The registrationIds generated by JPush. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendIosMessageWithRegistrationID(String title, String msgContent, SMS sms, String... registrationID) throws APIConnectionException, APIRequestException { @@ -809,7 +954,7 @@ public PushResult sendIosMessageWithRegistrationID(String title, String msgConte return _pushClient.sendPush(payload); } - public PushResult sendMessageWithRegistrationID(String title, String msgContent, String... registrationID) + public PushResult sendMessageWithRegistrationID(String title, String msgContent, String... registrationID) throws APIConnectionException, APIRequestException { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.all()) @@ -826,13 +971,13 @@ public PushResult sendMessageWithRegistrationID(String title, String msgContent, * Send a message with registrationIds. * If it doesn't received within the delay time,JPush will send a SMS to the corresponding users. * - * @param title The message title. - * @param msgContent The message content. - * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. + * @param title The message title. + * @param msgContent The message content. + * @param sms The SMS content and delay time. If null, sms doesn't work, no effect on Push feature. * @param registrationID The registrationIds generated by JPush. * @return push result. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public PushResult sendMessageWithRegistrationID(String title, String msgContent, SMS sms, String... registrationID) throws APIConnectionException, APIRequestException { @@ -849,71 +994,68 @@ public PushResult sendMessageWithRegistrationID(String title, String msgContent, } - // ----------------------- Device - - public TagAliasResult getDeviceTagAlias(String registrationId) - throws APIConnectionException, APIRequestException { - return _deviceClient.getDeviceTagAlias(registrationId); + + public TagAliasResult getDeviceTagAlias(String registrationId) + throws APIConnectionException, APIRequestException { + return _deviceClient.getDeviceTagAlias(registrationId); } public DefaultResult updateDeviceTagAlias(String registrationId, boolean clearAlias, boolean clearTag) - throws APIConnectionException, APIRequestException { - return _deviceClient.updateDeviceTagAlias(registrationId, clearAlias, clearTag); + throws APIConnectionException, APIRequestException { + return _deviceClient.updateDeviceTagAlias(registrationId, clearAlias, clearTag); } - - public DefaultResult updateDeviceTagAlias(String registrationId, String alias, - Set tagsToAdd, Set tagsToRemove) + + public DefaultResult updateDeviceTagAlias(String registrationId, String alias, + Set tagsToAdd, Set tagsToRemove) throws APIConnectionException, APIRequestException { - return _deviceClient.updateDeviceTagAlias(registrationId, alias, tagsToAdd, tagsToRemove); - } - - public TagListResult getTagList() - throws APIConnectionException, APIRequestException { - return _deviceClient.getTagList(); - } - - public BooleanResult isDeviceInTag(String theTag, String registrationID) - throws APIConnectionException, APIRequestException { - return _deviceClient.isDeviceInTag(theTag, registrationID); - } - - public DefaultResult addRemoveDevicesFromTag(String theTag, - Set toAddUsers, Set toRemoveUsers) - throws APIConnectionException, APIRequestException { - return _deviceClient.addRemoveDevicesFromTag(theTag, toAddUsers, - toRemoveUsers); - } - - public DefaultResult deleteTag(String theTag, String platform) - throws APIConnectionException, APIRequestException { - return _deviceClient.deleteTag(theTag, platform); - } - - public AliasDeviceListResult getAliasDeviceList(String alias, - String platform) throws APIConnectionException, APIRequestException { - return _deviceClient.getAliasDeviceList(alias, platform); - } - - public DefaultResult deleteAlias(String alias, String platform) - throws APIConnectionException, APIRequestException { - return _deviceClient.deleteAlias(alias, platform); - } - - public DefaultResult removeDevicesFromAlias(String alias, Set toRemoveDevice) - throws APIConnectionException, APIRequestException { - return _deviceClient.removeDevicesFromAlias(alias, toRemoveDevice); - } + return _deviceClient.updateDeviceTagAlias(registrationId, alias, tagsToAdd, tagsToRemove); + } + + public TagListResult getTagList() + throws APIConnectionException, APIRequestException { + return _deviceClient.getTagList(); + } + + public BooleanResult isDeviceInTag(String theTag, String registrationID) + throws APIConnectionException, APIRequestException { + return _deviceClient.isDeviceInTag(theTag, registrationID); + } + + public DefaultResult addRemoveDevicesFromTag(String theTag, + Set toAddUsers, Set toRemoveUsers) + throws APIConnectionException, APIRequestException { + return _deviceClient.addRemoveDevicesFromTag(theTag, toAddUsers, + toRemoveUsers); + } + + public DefaultResult deleteTag(String theTag, String platform) + throws APIConnectionException, APIRequestException { + return _deviceClient.deleteTag(theTag, platform); + } + + public AliasDeviceListResult getAliasDeviceList(String alias, + String platform) throws APIConnectionException, APIRequestException { + return _deviceClient.getAliasDeviceList(alias, platform); + } + + public DefaultResult deleteAlias(String alias, String platform) + throws APIConnectionException, APIRequestException { + return _deviceClient.deleteAlias(alias, platform); + } + + public DefaultResult removeDevicesFromAlias(String alias, Set toRemoveDevice) + throws APIConnectionException, APIRequestException { + return _deviceClient.removeDevicesFromAlias(alias, toRemoveDevice); + } public Map getUserOnlineStatus(String... registrationIds) - throws APIConnectionException, APIRequestException - { + throws APIConnectionException, APIRequestException { return _deviceClient.getUserOnlineStatus(registrationIds); } public DefaultResult bindMobile(String registrationId, String mobile) - throws APIConnectionException, APIRequestException - { + throws APIConnectionException, APIRequestException { return _deviceClient.bindMobile(registrationId, mobile); } @@ -921,12 +1063,13 @@ public DefaultResult bindMobile(String registrationId, String mobile) /** * Create a single schedule. + * * @param name The schedule name. * @param time The push time, format is 'yyyy-MM-dd HH:mm:ss' * @param push The push payload. * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createSingleSchedule(String name, String time, PushPayload push) throws APIConnectionException, APIRequestException { @@ -945,14 +1088,15 @@ public ScheduleResult createSingleSchedule(String name, String time, PushPayload /** * Create a daily schedule push everyday. - * @param name The schedule name. + * + * @param name The schedule name. * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss' - * @param push The push payload. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss' + * @param push The push payload. * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createDailySchedule(String name, String start, String end, String time, PushPayload push) throws APIConnectionException, APIRequestException { @@ -961,15 +1105,16 @@ public ScheduleResult createDailySchedule(String name, String start, String end, /** * Create a daily schedule push with a custom frequency. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss' + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss' * @param frequency The custom frequency. - * @param push The push payload. + * @param push The push payload. * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createDailySchedule(String name, String start, String end, String time, int frequency, PushPayload push) throws APIConnectionException, APIRequestException { @@ -978,22 +1123,23 @@ public ScheduleResult createDailySchedule(String name, String start, String end, /** * Create a weekly schedule push every week at the appointed days. - * @param name The schedule name. + * + * @param name The schedule name. * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss' - * @param days The appointed days. - * @param push The push payload. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss' + * @param days The appointed days. + * @param push The push payload. * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createWeeklySchedule(String name, String start, String end, String time, Week[] days, PushPayload push) throws APIConnectionException, APIRequestException { Preconditions.checkArgument(null != days && days.length > 0, "The days must not be empty."); String[] points = new String[days.length]; - for(int i = 0 ; i < days.length; i++) { + for (int i = 0; i < days.length; i++) { points[i] = days[i].name(); } return createPeriodicalSchedule(name, start, end, time, TimeUnit.WEEK, 1, points, push); @@ -1001,23 +1147,24 @@ public ScheduleResult createWeeklySchedule(String name, String start, String end /** * Create a weekly schedule push with a custom frequency at the appointed days. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss'. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss'. * @param frequency The custom frequency. - * @param days The appointed days. - * @param push The push payload. + * @param days The appointed days. + * @param push The push payload. * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createWeeklySchedule(String name, String start, String end, String time, int frequency, Week[] days, PushPayload push) throws APIConnectionException, APIRequestException { Preconditions.checkArgument(null != days && days.length > 0, "The days must not be empty."); String[] points = new String[days.length]; - for(int i = 0 ; i < days.length; i++) { + for (int i = 0; i < days.length; i++) { points[i] = days[i].name(); } return createPeriodicalSchedule(name, start, end, time, TimeUnit.WEEK, frequency, points, push); @@ -1025,15 +1172,16 @@ public ScheduleResult createWeeklySchedule(String name, String start, String end /** * Create a monthly schedule push every month at the appointed days. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss'. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss'. * @param points The appointed days. - * @param push The push payload. + * @param push The push payload. * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createMonthlySchedule(String name, String start, String end, String time, String[] points, PushPayload push) throws APIConnectionException, APIRequestException { @@ -1043,16 +1191,17 @@ public ScheduleResult createMonthlySchedule(String name, String start, String en /** * Create a monthly schedule push with a custom frequency at the appointed days. - * @param name The schedule name. - * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. - * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. - * @param time The push time, format 'HH:mm:ss'. + * + * @param name The schedule name. + * @param start The schedule comes into effect date, format 'yyyy-MM-dd HH:mm:ss'. + * @param end The schedule expiration date, format 'yyyy-MM-dd HH:mm:ss'. + * @param time The push time, format 'HH:mm:ss'. * @param frequency The custom frequency. - * @param points The appointed days. - * @param push The push payload. + * @param points The appointed days. + * @param push The push payload. * @return The created scheduleResult instance. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult createMonthlySchedule(String name, String start, String end, String time, int frequency, String[] points, PushPayload push) throws APIConnectionException, APIRequestException { @@ -1062,33 +1211,36 @@ public ScheduleResult createMonthlySchedule(String name, String start, String en /** * Get the schedule information by the schedule id. + * * @param scheduleId The schedule id. * @return The schedule information. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult getSchedule(String scheduleId) throws APIConnectionException, APIRequestException { - return _scheduleClient.getSchedule(scheduleId); + return _scheduleClient.getSchedule(scheduleId); } - + /** * Get the message id by the schedule id. + * * @param scheduleId The schedule id. * @return The message id list. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleMsgIdsResult getScheduleMsgIds(String scheduleId) throws APIConnectionException, APIRequestException { - return _scheduleClient.getScheduleMsgIds(scheduleId); + return _scheduleClient.getScheduleMsgIds(scheduleId); } /** * Get the schedule list size and the first page. + * * @return The schedule list size and the first page. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleListResult getScheduleList() throws APIConnectionException, APIRequestException { @@ -1097,10 +1249,11 @@ public ScheduleListResult getScheduleList() /** * Get the schedule list by the page. + * * @param page The page to search. * @return The schedule list of the appointed page. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleListResult getScheduleList(int page) throws APIConnectionException, APIRequestException { @@ -1109,11 +1262,12 @@ public ScheduleListResult getScheduleList(int page) /** * Update the schedule name + * * @param scheduleId The schedule id. - * @param name The new name. + * @param name The new name. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateScheduleName(String scheduleId, String name) throws APIConnectionException, APIRequestException { @@ -1126,10 +1280,11 @@ public ScheduleResult updateScheduleName(String scheduleId, String name) /** * Enable the schedule. + * * @param scheduleId The schedule id. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult enableSchedule(String scheduleId) throws APIConnectionException, APIRequestException { @@ -1142,10 +1297,11 @@ public ScheduleResult enableSchedule(String scheduleId) /** * Disable the schedule. + * * @param scheduleId The schedule id. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult disableSchedule(String scheduleId) throws APIConnectionException, APIRequestException { @@ -1157,11 +1313,12 @@ public ScheduleResult disableSchedule(String scheduleId) /** * Update the trigger of the schedule. + * * @param scheduleId The schedule id. - * @param trigger The new trigger. + * @param trigger The new trigger. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateScheduleTrigger(String scheduleId, TriggerPayload trigger) throws APIConnectionException, APIRequestException { @@ -1174,11 +1331,12 @@ public ScheduleResult updateScheduleTrigger(String scheduleId, TriggerPayload tr /** * Update the push content of the schedule. + * * @param scheduleId The schedule id. - * @param push The new push payload. + * @param push The new push payload. * @return The schedule information after updated. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateSchedulePush(String scheduleId, PushPayload push) throws APIConnectionException, APIRequestException { @@ -1191,11 +1349,12 @@ public ScheduleResult updateSchedulePush(String scheduleId, PushPayload push) /** * Update a schedule by the id. + * * @param scheduleId The schedule id to update. - * @param payload The new schedule payload. + * @param payload The new schedule payload. * @return The new schedule information. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload) throws APIConnectionException, APIRequestException { @@ -1204,9 +1363,10 @@ public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload) /** * Delete a schedule by id. + * * @param scheduleId The schedule id. * @throws APIConnectionException if a remote or network exception occurs. - * @throws APIRequestException if a request exception occurs. + * @throws APIRequestException if a request exception occurs. */ public void deleteSchedule(String scheduleId) throws APIConnectionException, APIRequestException { @@ -1218,7 +1378,7 @@ private ScheduleResult createPeriodicalSchedule(String name, String start, Strin throws APIConnectionException, APIRequestException { TriggerPayload trigger = TriggerPayload.newBuilder() .setPeriodTime(start, end, time) - .setTimeFrequency(timeUnit, frequency, point ) + .setTimeFrequency(timeUnit, frequency, point) .buildPeriodical(); SchedulePayload payload = SchedulePayload.newBuilder() .setName(name) diff --git a/src/main/java/cn/jpush/api/config/EnableJPushClient.java b/src/main/java/cn/jpush/api/config/EnableJPushClient.java new file mode 100644 index 00000000..ac7116d2 --- /dev/null +++ b/src/main/java/cn/jpush/api/config/EnableJPushClient.java @@ -0,0 +1,19 @@ +package cn.jpush.api.config; + +import org.springframework.context.annotation.Import; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 启动JPushClient + * 将读取jpush和app配置创建jPushClient注入到spring + * @author seanything + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Import(JPushClientConfiguration.class) +public @interface EnableJPushClient { +} diff --git a/src/main/java/cn/jpush/api/config/JPushClientConfiguration.java b/src/main/java/cn/jpush/api/config/JPushClientConfiguration.java new file mode 100644 index 00000000..d84354fe --- /dev/null +++ b/src/main/java/cn/jpush/api/config/JPushClientConfiguration.java @@ -0,0 +1,26 @@ +package cn.jpush.api.config; + +import cn.jpush.api.JPushClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author seanything + */ +@Configuration +public class JPushClientConfiguration { + + @Bean + @ConfigurationProperties(prefix = "jpush") + public PushConfig pushConfig(){ + return new PushConfig(); + } + + @Bean + public JPushClient jPushClient(@Value("${app.app-key}") String appKey, @Value("${app.master-secret}")String masterSecret){ + return new JPushClient(masterSecret,appKey,pushConfig()); + } + +} diff --git a/src/main/java/cn/jpush/api/config/PushConfig.java b/src/main/java/cn/jpush/api/config/PushConfig.java new file mode 100644 index 00000000..9bc0ef0d --- /dev/null +++ b/src/main/java/cn/jpush/api/config/PushConfig.java @@ -0,0 +1,115 @@ +package cn.jpush.api.config; + +import lombok.Data; +import lombok.Getter; +import lombok.ToString; + +/** + * 发送消息的相关配置 + * @author seanything + */ +@ToString +public class PushConfig { + + @Getter + private final AndroidConfig androidConfig = new AndroidConfig(); + + @Getter + private final IosConfig iosConfig = new IosConfig(); + + public static PushConfig getDefaultConfig(String badgeClass){ + PushConfig pushConfig = new PushConfig(); + pushConfig.getAndroidConfig().setBadgeAddNum(1); + pushConfig.getAndroidConfig().setBadgeClass(badgeClass); + return pushConfig; + } + + @Data + public class IosConfig{ + /** + * 通知提示声音或警告通知 + */ + private String sound; + + /** + * 应用角标 + */ + private Integer badge; + + /** + * 推送唤醒 + */ + private Boolean contentAvailable; + + /** + * 通知扩展 + */ + private Boolean mutableContent; + + /** + * 通知栏条目过滤或排序 + */ + private String category; + + /** + * 通知分组id + */ + private String threadId; + } + + @Data + public class AndroidConfig{ + /** + * 通知栏样式id + */ + private Integer builderId; + + /** + * 指定通知栏展示效果 + */ + private String channelId; + + /** + * 通知栏展示优先级 默认0,范围 -2 ~ 2 + */ + private Integer priority; + + /** + * 通知栏条目过滤或排序 + */ + private String category; + + /** + * 通知栏样式类型
+ * 默认为 0,还有 1,2,3 可选,用来指定选择哪种通知栏样式,其他值无效。有三种可选分别为 bigText=1,Inbox=2,bigPicture=3。 + */ + private Integer style; + + /** + * 通知提醒方式 + * -1 ~ 7 + */ + private Integer alertType; + + /** + * 声音文件路径 + */ + private String sound; + + /** + * APP在前台,通知是否展示 + */ + private String displayForeground; + + /** + * 角标数字,取值范围1-99 + */ + private Integer badgeAddNum; + + /** + * 桌面图标对应的应用入口Activity类 + */ + private String badgeClass; + } + +} diff --git a/src/main/java/cn/jpush/api/push/model/notification/AndroidNotification.java b/src/main/java/cn/jpush/api/push/model/notification/AndroidNotification.java index dcc0d197..5e1039ae 100644 --- a/src/main/java/cn/jpush/api/push/model/notification/AndroidNotification.java +++ b/src/main/java/cn/jpush/api/push/model/notification/AndroidNotification.java @@ -1,5 +1,6 @@ package cn.jpush.api.push.model.notification; +import cn.jpush.api.config.PushConfig; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; @@ -8,6 +9,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; public class AndroidNotification extends PlatformNotification { public static final String NOTIFICATION_ANDROID = "android"; @@ -249,6 +251,53 @@ public Builder setChannelId(String channelId) { this.channelId = channelId; return this; } + /** + * 解析配置类,加入配置 + * @param config config + * @return builder + */ + public Builder parseConfig(PushConfig config) { + if(Objects.isNull(config)){ + return this; + } + PushConfig.AndroidConfig androidConfig = config.getAndroidConfig(); + if(Objects.isNull(androidConfig)){ + return this; + } + if (Objects.nonNull(androidConfig.getAlertType())) { + setAlertType(androidConfig.getAlertType()); + } + + if (Objects.nonNull(androidConfig.getBuilderId())) { + setBuilderId(androidConfig.getBuilderId()); + } + + if (Objects.nonNull(androidConfig.getCategory())) { + setCategory(androidConfig.getCategory()); + } + + if (Objects.nonNull(androidConfig.getChannelId())) { + setChannelId(androidConfig.getChannelId()); + } + + if (Objects.nonNull(androidConfig.getDisplayForeground())) { + addCustom("display_foreground", androidConfig.getDisplayForeground()); + } + + if (Objects.nonNull(androidConfig.getPriority())) { + setPriority(androidConfig.getPriority()); + } + + if (Objects.nonNull(androidConfig.getSound())) { + addCustom("sound", androidConfig.getSound()); + } + + if (Objects.nonNull(androidConfig.getStyle())) { + setStyle(androidConfig.getStyle()); + } + + return this; + } @Override public AndroidNotification build() { diff --git a/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java b/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java index 4e7cf7ca..7d612291 100644 --- a/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java +++ b/src/main/java/cn/jpush/api/push/model/notification/IosNotification.java @@ -1,7 +1,9 @@ package cn.jpush.api.push.model.notification; import java.util.Map; +import java.util.Objects; +import cn.jpush.api.config.PushConfig; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; @@ -220,6 +222,39 @@ public Builder setThreadId(String threadId) { return this; } + public Builder parseConfig(PushConfig config) { + if(Objects.isNull(config)){ + return this; + } + PushConfig.IosConfig iosConfig = config.getIosConfig(); + if(Objects.isNull(iosConfig)){ + return this; + } + if (Objects.nonNull(iosConfig.getSound())) { + setSound(iosConfig.getSound()); + } + + if (Objects.nonNull(iosConfig.getBadge())) { + setBadge(iosConfig.getBadge()); + } + + if (Objects.nonNull(iosConfig.getCategory())) { + setCategory(iosConfig.getCategory()); + } + + if (Objects.nonNull(iosConfig.getContentAvailable())) { + setContentAvailable(iosConfig.getContentAvailable()); + } + + if (Objects.nonNull(iosConfig.getMutableContent())) { + setMutableContent(iosConfig.getMutableContent()); + } + + if (Objects.nonNull(iosConfig.getThreadId())) { + setThreadId(iosConfig.getThreadId()); + } + return this; + } public IosNotification build() { return new IosNotification(alert, sound, badge, contentAvailable, diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000..6a600f03 --- /dev/null +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,14 @@ +{ + "properties": [ + { + "name": "app.app-key", + "type": "java.lang.String", + "description": "应用的appKey." + }, + { + "name": "app.master-secret", + "type": "java.lang.String", + "description": "应用的masterSecret." + } + ] +} \ No newline at end of file diff --git a/src/test/java/cn/jpush/api/BaseTest.java b/src/test/java/cn/jpush/api/BaseTest.java deleted file mode 100644 index 14aebb88..00000000 --- a/src/test/java/cn/jpush/api/BaseTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.jpush.api; - -import org.junit.Before; - -public abstract class BaseTest { - - protected static final String APP_KEY = "d4ee2375846bc30fa51334f5"; - protected static final String MASTER_SECRET = "3f045fd404d09a8a1f38d791"; - protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e"; - protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c"; - - public static final String ALERT = "JPush Test - alert"; - public static final String MSG_CONTENT = "JPush Test - msgContent"; - - public static final String REGISTRATION_ID1 = "0900e8d85ef"; - public static final String REGISTRATION_ID2 = "0a04ad7d8b4"; - public static final String REGISTRATION_ID3 = "18071adc030dcba91c0"; - - - protected JPushClient jpushClient = null; - - @Before - public void before() { - jpushClient = new JPushClient(MASTER_SECRET, APP_KEY); - - } - -} diff --git a/src/test/java/cn/jpush/api/FastTests.java b/src/test/java/cn/jpush/api/FastTests.java deleted file mode 100644 index 3828e54b..00000000 --- a/src/test/java/cn/jpush/api/FastTests.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.jpush.api; - -public interface FastTests { - -} diff --git a/src/test/java/cn/jpush/api/JUnitOrderedRunner.java b/src/test/java/cn/jpush/api/JUnitOrderedRunner.java deleted file mode 100644 index f6dab986..00000000 --- a/src/test/java/cn/jpush/api/JUnitOrderedRunner.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.jpush.api; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; - -public class JUnitOrderedRunner extends BlockJUnit4ClassRunner { - public JUnitOrderedRunner(Class klass) throws InitializationError { - super(klass); - } - - @Override - protected List computeTestMethods() { - List list = super.computeTestMethods(); - Collections.sort(list, new Comparator() { - @Override - public int compare(FrameworkMethod f1, FrameworkMethod f2) { - TestOrder o1 = f1.getAnnotation(TestOrder.class); - TestOrder o2 = f2.getAnnotation(TestOrder.class); - - if (o1 == null || o2 == null) - return -1; - - return o1.order() - o2.order(); - } - }); - return list; - } -} diff --git a/src/test/java/cn/jpush/api/SlowTests.java b/src/test/java/cn/jpush/api/SlowTests.java deleted file mode 100644 index 8469da90..00000000 --- a/src/test/java/cn/jpush/api/SlowTests.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.jpush.api; - -public interface SlowTests { - -} diff --git a/src/test/java/cn/jpush/api/TestOrder.java b/src/test/java/cn/jpush/api/TestOrder.java deleted file mode 100644 index b3681d4c..00000000 --- a/src/test/java/cn/jpush/api/TestOrder.java +++ /dev/null @@ -1,9 +0,0 @@ -package cn.jpush.api; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface TestOrder { - public int order(); -} \ No newline at end of file diff --git a/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java b/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java deleted file mode 100644 index 23197e31..00000000 --- a/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java +++ /dev/null @@ -1,209 +0,0 @@ -package cn.jpush.api.device; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jiguang.common.resp.BooleanResult; -import cn.jiguang.common.resp.DefaultResult; -import cn.jpush.api.BaseTest; -import cn.jpush.api.JUnitOrderedRunner; -import cn.jpush.api.TestOrder; - -@RunWith(JUnitOrderedRunner.class) -public class DeviceNormalRemoteTest extends BaseTest { - - // ------------------ device - - @Test - @TestOrder(order = 100) - public void testUpdateDeviceTagAlias_add_remove_tags() throws APIConnectionException, APIRequestException { - Set tagsToAdd = new HashSet(); - tagsToAdd.add("tag1"); - tagsToAdd.add("tag2"); - Set tagsToRemove = new HashSet(); - tagsToRemove.add("tag1"); - tagsToRemove.add("tag2"); - DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID3, "alias1", tagsToAdd, tagsToRemove); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 110) - public void testGetDeviceTagAlias_1() throws Exception { - TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID3); - - assertTrue(result.isResultOK()); - assertEquals("alias not equals", "alias1", result.alias); - - assertTrue("tag contains", result.tags.contains("tag1")); - assertTrue("tag contains", result.tags.contains("tag2")); - assertFalse("tag not contains", result.tags.contains("tag3")); - assertFalse("tag not contains", result.tags.contains("tag4")); - } - @Test - @TestOrder(order = 111) - public void testGetAliasDeviceList_1() throws APIConnectionException, APIRequestException { - AliasDeviceListResult result = jpushClient.getAliasDeviceList("alias1", null); - assertTrue(result.registration_ids.contains(REGISTRATION_ID1)); - } - - @Test - @TestOrder(order = 120) - public void testUpdateDeviceTagAlias_clear() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, true, true); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 130) - public void testGetDeviceTagAlias_cleard() throws Exception { - TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1); - - assertTrue(result.isResultOK()); - assertEquals("alias cleared", null, result.alias); - assertEquals("tags cleared", 0, result.tags.size()); - } - - - - // ------------------ tags - - @Test - @TestOrder(order = 203) - public void testAddRemoveDevicesFromTag() throws APIConnectionException, APIRequestException { - Set toAddUsers = new HashSet(); - toAddUsers.add(REGISTRATION_ID1); - Set toRemoveUsers = new HashSet(); - toRemoveUsers.add(REGISTRATION_ID2); - DefaultResult result = jpushClient.addRemoveDevicesFromTag("tag3", toAddUsers, toRemoveUsers); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 210) - public void testIsDeviceInTag() throws APIConnectionException, APIRequestException { - BooleanResult result = jpushClient.isDeviceInTag("tag2", REGISTRATION_ID3); - assertTrue("", result.result); - } - - @Test - @TestOrder(order = 211) - public void testAddRemoveDevicesFromTagResult() throws APIConnectionException, APIRequestException { - TagListResult result = jpushClient.getTagList(); - assertTrue("", result.tags.contains("tag3")); - } - - @Test - @TestOrder(order = 220) - public void testGetTagList_1() throws Exception { - TagListResult result = jpushClient.getTagList(); - assertTrue("", result.tags.size() > 0); - } - - @Test - @TestOrder(order = 250) - public void testDeleteTag() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.deleteTag("tag3", null); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 251) - public void testDeleteResult() throws APIConnectionException, APIRequestException { - TagListResult result = jpushClient.getTagList(); - assertFalse("", result.tags.contains("tag3")); - } - - @Test - @TestOrder(order = 260) - public void testDeletetag2() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.deleteTag("tag3", null); - assertTrue(result.isResultOK()); - } - - // --------------------- alias - - @Test - @TestOrder(order = 230) - public void testGetAliasDevices_1() throws Exception { - AliasDeviceListResult result = jpushClient.getAliasDeviceList("alias1", null); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 300) - public void testGetAliasDeviceList() throws APIConnectionException, APIRequestException { - AliasDeviceListResult result = jpushClient.getAliasDeviceList("alias1", "android"); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 310) - public void testGetAliasDeviceList_2() throws APIConnectionException, APIRequestException { - AliasDeviceListResult result = jpushClient.getAliasDeviceList("alias1", null); - assertTrue(result.registration_ids.size() == 0); - } - - @Test - @TestOrder(order = 320) - public void testDeleteAlias() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.deleteAlias("alias2", "android"); - assertTrue(result.isResultOK()); - } - - - @Test - @TestOrder(order = 330) - public void testDeleteAlias_2() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.deleteAlias("alias2", null); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 340) - public void testTetUserOnlineStatus() throws APIConnectionException, APIRequestException{ - Map result = jpushClient.getUserOnlineStatus(REGISTRATION_ID1, REGISTRATION_ID2); - assertTrue(result.get(REGISTRATION_ID1) != null); - } - - @Test - @TestOrder(order = 360) - public void testBindMobile() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.bindMobile(REGISTRATION_ID1, "13000000000"); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 361) - public void testBindMobile_null() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.bindMobile(REGISTRATION_ID1, null); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 362) - public void testBindMobile_empty() throws APIConnectionException, APIRequestException { - DefaultResult result = jpushClient.bindMobile(REGISTRATION_ID1, ""); - assertTrue(result.isResultOK()); - } - - @Test - @TestOrder(order = 330) - public void testRemoveDevicesFromAlias() throws APIConnectionException, APIRequestException { - Set toRemoveDevice = new HashSet<>(); - toRemoveDevice.add(REGISTRATION_ID1); - DefaultResult result = jpushClient.removeDevicesFromAlias("alias1", toRemoveDevice); - assertTrue(result.isResultOK()); - } - -} diff --git a/src/test/java/cn/jpush/api/files/FileClientTest.java b/src/test/java/cn/jpush/api/files/FileClientTest.java deleted file mode 100644 index 3de8fb0d..00000000 --- a/src/test/java/cn/jpush/api/files/FileClientTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.jpush.api.files; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.BaseTest; -import cn.jpush.api.file.FileClient; -import cn.jpush.api.file.model.FileModel; -import cn.jpush.api.file.model.FileModelPage; -import cn.jpush.api.file.model.FileType; -import cn.jpush.api.file.model.FileUploadResult; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author daixuan - * @version 2020/2/24 14:01 - */ -public class FileClientTest extends BaseTest { - - protected static final Logger LOG = LoggerFactory.getLogger(FileClientTest.class); - - String fileId = "d4ee2375846bc30fa51334f5-69653861-1408-4d0a-abef-117808632b23"; - - @Test - public void testUploadFile() { - FileClient fileClient = new FileClient(MASTER_SECRET, APP_KEY); - try { - FileUploadResult result = fileClient.uploadFile(FileType.ALIAS, "README.md"); - LOG.info("uploadFile:{}", result); - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - LOG.info("Msg ID: " + e.getMsgId()); - } - } - - @Test - public void testQueryEffFiles() { - FileClient fileClient = new FileClient(MASTER_SECRET, APP_KEY); - try { - FileModelPage result = fileClient.queryEffectFiles(); - LOG.info("queryEffFiles:{}", result); - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - LOG.info("Msg ID: " + e.getMsgId()); - } - } - - @Test - public void testQueryFile() { - FileClient fileClient = new FileClient(MASTER_SECRET, APP_KEY); - try { - FileModel fileModel = fileClient.queryFile(fileId); - LOG.info("fileModel:{}", fileModel); - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - LOG.info("Msg ID: " + e.getMsgId()); - } - } - - @Test - public void testDeleteFile() { - FileClient fileClient = new FileClient(MASTER_SECRET, APP_KEY); - try { - fileClient.deleteFile(fileId); - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - LOG.info("Msg ID: " + e.getMsgId()); - } - } -} diff --git a/src/test/java/cn/jpush/api/push/GroupPushClientTest.java b/src/test/java/cn/jpush/api/push/GroupPushClientTest.java deleted file mode 100644 index 574871b1..00000000 --- a/src/test/java/cn/jpush/api/push/GroupPushClientTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package cn.jpush.api.push; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.BaseTest; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.AndroidNotification; -import cn.jpush.api.push.model.notification.IosNotification; -import cn.jpush.api.push.model.notification.Notification; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -public class GroupPushClientTest extends BaseTest { - - protected static final Logger LOG = LoggerFactory.getLogger(GroupPushClientTest.class); - - @Test - public void testSendGroupPush() { - GroupPushClient groupPushClient = new GroupPushClient(GROUP_MASTER_SECRET, GROUP_PUSH_KEY); - final PushPayload payload = buildPushObject_android(); - try { - GroupPushResult groupPushresult = groupPushClient.sendGroupPush(payload); - Map result = groupPushresult.getAppResultMap(); - for (Map.Entry entry : result.entrySet()) { - PushResult pushResult = entry.getValue(); - PushResult.Error error = pushResult.error; - if (error != null) { - LOG.info("AppKey: " + entry.getKey() + " error code : " + error.getCode() + " error message: " + error.getMessage()); - } else { - LOG.info("AppKey: " + entry.getKey() + " sendno: " + pushResult.sendno + " msg_id:" + pushResult.msg_id); - } - - } - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - LOG.error("Sendno: " + payload.getSendno()); - - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - LOG.info("Msg ID: " + e.getMsgId()); - LOG.error("Sendno: " + payload.getSendno()); - } - } - - public static PushPayload buildPushObject_android() { - return PushPayload.newBuilder() - .setPlatform(Platform.android()) - .setAudience(Audience.registrationId(REGISTRATION_ID3)) - .setNotification(Notification.newBuilder() - .setAlert("alert content") - .addPlatformNotification(AndroidNotification.newBuilder() - .setTitle("Android Title").build()) - .addPlatformNotification(IosNotification.newBuilder() - .incrBadge(1) - .addExtra("extra_key", "extra_value").build()) - .build()) - .build(); - } -} diff --git a/src/test/java/cn/jpush/api/push/PushClientTest.java b/src/test/java/cn/jpush/api/push/PushClientTest.java deleted file mode 100644 index 8eac3d64..00000000 --- a/src/test/java/cn/jpush/api/push/PushClientTest.java +++ /dev/null @@ -1,175 +0,0 @@ -package cn.jpush.api.push; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import cn.jiguang.common.ClientConfig; -import cn.jiguang.common.ServiceHelper; -import cn.jiguang.common.connection.NettyHttpClient; -import cn.jiguang.common.resp.ResponseWrapper; -import cn.jpush.api.JPushClient; -import cn.jpush.api.push.model.Options; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.*; -import io.netty.handler.codec.http.HttpMethod; -import org.junit.Test; - -import cn.jiguang.common.connection.HttpProxy; -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.BaseTest; -import cn.jpush.api.push.model.PushPayload; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -public class PushClientTest extends BaseTest { - - protected static final Logger LOG = LoggerFactory.getLogger(PushClientTest.class); - - @Test - public void testSendPush() { - ClientConfig clientConfig = ClientConfig.getInstance(); - JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig); - PushPayload payload = buildPushObject_all_alias_alert(); - try { - PushResult result = jpushClient.sendPush(payload); - int status = result.getResponseCode(); - LOG.info("Got result - " + result); - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - LOG.error("Sendno: " + payload.getSendno()); - - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - LOG.info("Msg ID: " + e.getMsgId()); - LOG.error("Sendno: " + payload.getSendno()); - } - } - - @Test - public void testSendPushWithCallback() { - ClientConfig clientConfig = ClientConfig.getInstance(); - String host = (String) clientConfig.get(ClientConfig.PUSH_HOST_NAME); - final NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET), - null, clientConfig); - try { - URI uri = new URI(host + clientConfig.get(ClientConfig.PUSH_PATH)); - PushPayload payload = buildPushObject_all_alias_alert(); - client.sendRequest(HttpMethod.POST, payload.toString(), uri, new NettyHttpClient.BaseCallback() { - @Override - public void onSucceed(ResponseWrapper responseWrapper) { - LOG.info("Got result: " + responseWrapper.responseContent); - } - }); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - } - - - public static PushPayload buildPushObject_all_alias_alert() { - return PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.registrationId(REGISTRATION_ID3)) - .setNotification(Notification.alert(ALERT)) - .setOptions(Options.newBuilder().setApnsProduction(false).setTimeToLive(86000).build()) - .build(); - } - - @Test(expected = IllegalArgumentException.class) - public void test_invalid_json() { - PushClient pushClient = new PushClient(MASTER_SECRET, APP_KEY); - - try { - pushClient.sendPush("{aaa:'a}"); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test(expected = IllegalArgumentException.class) - public void test_empty_string() { - PushClient pushClient = new PushClient(MASTER_SECRET, APP_KEY); - - try { - pushClient.sendPush(""); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test(expected = IllegalArgumentException.class) - public void test_empty_password() { - new HttpProxy("127.0.0.1", 8080, "", null); - } - - @Test - public void test_validate() { - PushClient pushClient = new PushClient(MASTER_SECRET, APP_KEY); - - try { - PushResult result = pushClient.sendPushValidate(PushPayload.alertAll("alert")); - assertTrue("", result.isResultOK()); - } catch (APIRequestException e) { - fail("Should not fail"); - } catch (APIConnectionException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetCidList() { - JPushClient jPushClient = new JPushClient(MASTER_SECRET, APP_KEY); - try { - CIDResult result = jPushClient.getCidList(3, "push"); - LOG.info("Got result - " + result); - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - } - } - - @Test - public void testSendPushWithCid() { - JPushClient jPushClient = new JPushClient(MASTER_SECRET, APP_KEY); - PushPayload pushPayload = buildPushObject_android_cid(); - try { - PushResult result = jPushClient.sendPush(pushPayload); - LOG.info("Got result - " + result); - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - } - } - - public static PushPayload buildPushObject_android_cid() { - return PushPayload.newBuilder() - .setPlatform(Platform.android()) - .setAudience(Audience.registrationId("18071adc030dcba91c0")) - .setNotification(Notification.alert(ALERT)) - .setCid("d4ee2375846bc30fa51334f5-21f305e0-4a52-42f3-a3dd-d2e49bdf0499") - .build(); - } - -} diff --git a/src/test/java/cn/jpush/api/push/mock/BaseMockTest.java b/src/test/java/cn/jpush/api/push/mock/BaseMockTest.java deleted file mode 100644 index f04d831b..00000000 --- a/src/test/java/cn/jpush/api/push/mock/BaseMockTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package cn.jpush.api.push.mock; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.net.URL; -import java.util.Map; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.push.PushClient; - -public class BaseMockTest implements IMockTest { - - static { - SUPPORT_PLATFORM.add("android"); - SUPPORT_PLATFORM.add("ios"); - SUPPORT_PLATFORM.add("winphone"); - - SUPPORT_AUDIENCE.add("tag"); - SUPPORT_AUDIENCE.add("tag_and"); - SUPPORT_AUDIENCE.add("alias"); - SUPPORT_AUDIENCE.add("registration_id"); - SUPPORT_AUDIENCE.add("segment"); - } - - - protected static PushClient _client = null; - protected static MockWebServer _mockServer = null; - protected static URL _mockUrl = null; - protected String _currentPayload = null; - protected int _expectedErrorCode = 0; - - @Before - public void before() { - } - - private void basicRequestCheck() { - RecordedRequest request; - try { - request = _mockServer.takeRequest(); - assertNotNull("", request.getHeader("Authorization")); - assertEquals("", CONTENT_TYPE_JSON, request.getHeader("Content-Type")); - assertEquals("", "keep-alive", request.getHeader("Connection")); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - @After - public void after() { - int sendno = 0; - int responseCode = 200; - int errorCode = 0; - String errorMessage = null; - - JsonParser parser = new JsonParser(); - JsonObject json = parser.parse(_currentPayload).getAsJsonObject(); - - if (!json.has("platform") || !json.has("audience") - || (!json.has("notification") && !json.has("message"))) { - responseCode = 400; - errorCode = 1002; - errorMessage = "Lack of params."; - - } else { - - JsonElement platform = json.get("platform"); - if (platform.isJsonPrimitive() && !"all".equals(platform.getAsString())) { - responseCode = 400; - errorCode = 1003; - errorMessage = "Invalid param - platform string should only be 'all'"; - } - - if (platform.isJsonArray()) { - JsonArray platformArray = platform.getAsJsonArray(); - for (int i = 0; i < platformArray.size(); i++) { - String onePlatform = platformArray.get(i).getAsString(); - if (!SUPPORT_PLATFORM.contains(onePlatform)) { - responseCode = 400; - errorCode = 1003; - errorMessage = "Invalid param - platform is invalid - " + onePlatform; - break; - } - } - } - - JsonElement audience = json.get("audience"); - if (audience.isJsonPrimitive() && !"all".equals(audience.getAsString())) { - responseCode = 400; - errorCode = 1003; - errorMessage = "Invalid param - audience string should only be 'all'"; - } - - if (audience.isJsonObject()) { - JsonObject audienceObject = audience.getAsJsonObject(); - for (Map.Entry entry : audienceObject.entrySet()) { - if (!SUPPORT_AUDIENCE.contains(entry.getKey())) { - responseCode = 400; - errorCode = 1003; - errorMessage = "Invalid param - audience is invalid - " + entry.getKey(); - } - } - } - - if (json.has("notification")) { - JsonElement notification = json.get("notification"); - if (!notification.isJsonObject()) { - responseCode = 400; - errorCode = 1003; - errorMessage = "Invalid param - notification is invalid - should not be string value. "; - } else { - - } - - } else if (json.has("message")) { - JsonElement message = json.get("message"); - if (!message.isJsonObject()) { - responseCode = 400; - errorCode = 1003; - errorMessage = "Invalid param - message is invalid - should not be string value. "; - } - } - - } - - if (responseCode == 200) { - _mockServer.enqueue(new MockResponse() - .setBody(getResponseOK(111, sendno))); - } else { - _mockServer.enqueue(new MockResponse() - .setResponseCode(responseCode) - .setBody(getResponseError(111, sendno, errorCode, errorMessage))); - } - - try { - _client.sendPush(_currentPayload); - - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - // TODO Auto-generated catch block - assertEquals("", _expectedErrorCode, e.getErrorCode()); - } - - basicRequestCheck(); - } - - @BeforeClass - public static void beforeClass() throws IOException { - _mockServer = new MockWebServer(); - - _mockServer.play(); - _mockUrl = _mockServer.getUrl("/v3/push/"); - - _client = new PushClient(masterSecret, appKey); - _client.setBaseUrl(_mockUrl.toString()); - } - - @AfterClass - public static void afterClass() throws IOException { - _mockServer.shutdown(); - } - - - protected String getResponseOK(int msgid, int sendno) { - JsonObject json = new JsonObject(); - json.add("msg_id", new JsonPrimitive(msgid)); - json.add("sendno", new JsonPrimitive(sendno)); - return json.toString(); - } - - protected String getResponseError(int msgid, int sendno, int errorCode, String errorMessage) { - JsonObject json = new JsonObject(); - json.add("msg_id", new JsonPrimitive(msgid)); - json.add("sendno", new JsonPrimitive(sendno)); - - JsonObject error = new JsonObject(); - error.add("code", new JsonPrimitive(errorCode)); - error.add("message", new JsonPrimitive(errorMessage)); - - json.add("error", error); - return json.toString(); - } - - - -} - diff --git a/src/test/java/cn/jpush/api/push/mock/ConnectionExceptionTest.java b/src/test/java/cn/jpush/api/push/mock/ConnectionExceptionTest.java deleted file mode 100644 index e4717c2f..00000000 --- a/src/test/java/cn/jpush/api/push/mock/ConnectionExceptionTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package cn.jpush.api.push.mock; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.net.URL; - -import org.junit.After; -import org.junit.Test; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.SocketPolicy; - -import cn.jiguang.common.connection.IHttpClient; -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.push.PushClient; -import cn.jpush.api.push.model.PushPayload; - -/** - * Record: MockResponse.throttleBody will delay response body, but sometimes has no effect. - * MockResponse.setBodyDelayTimeMs has no effect for delay test. - * - */ -public class ConnectionExceptionTest implements IMockTest { - private PushClient _client = null; - private MockWebServer _server = new MockWebServer(); - - private static final String SIMPLE_CONTNET = PushPayload.alertAll("alert").toString(); - - @Test - public void test_read_timeout_disconnect_at_start() throws Exception { - // disconnect at start. This will cause "Read timed out" - _server.enqueue(new MockResponse() - .setSocketPolicy(SocketPolicy.DISCONNECT_AT_START) - ); - connect_read_timeout(); - } - - @Test - public void test_connect_timeout_and_retry() throws Exception { - _server.enqueue(new MockResponse() - .setBody(SIMPLE_CONTNET) - ); - - _server.play(); - _client = new PushClient(masterSecret, appKey); - // connecting to a un-existed address will cause "connect timed out" - _client.setBaseUrl("http://192.132.143.11" + ":81/"); - - long start = System.currentTimeMillis(); - try { - _client.sendPush(SIMPLE_CONTNET); - fail("Should not go here for connection exception."); - } catch (APIConnectionException e) { - e.printStackTrace(); - assertFalse("connect timed out", e.isReadTimedout()); - assertEquals("Retried", IHttpClient.DEFAULT_MAX_RETRY_TIMES, e.getDoneRetriedTimes()); - - long end = System.currentTimeMillis(); - assertTrue("Retried", (end - start) > IHttpClient.DEFAULT_CONNECTION_TIMEOUT - * IHttpClient.DEFAULT_MAX_RETRY_TIMES); - - } catch (APIRequestException e) { - } - } - - - - - public void connect_read_timeout() throws IOException { - init(); - - try { - _client.sendPush(SIMPLE_CONTNET); - fail("Should not go here for connection exception."); - } catch (APIConnectionException e) { - e.printStackTrace(); - assertTrue("Read timed out", e.isReadTimedout()); - } catch (APIRequestException e) { - } - } - - - public void init() throws IOException { - _server.play(); - - URL mockUrl = _server.getUrl("/v3/push/"); - System.out.println("Server Url - " + mockUrl); - - _client = new PushClient(masterSecret, appKey); - _client.setBaseUrl(mockUrl.toString()); - } - - @After - public void after() throws IOException { - _server.shutdown(); - } - - protected String getResponseOK(int msgid, int sendno) { - JsonObject json = new JsonObject(); - json.add("msg_id", new JsonPrimitive(msgid)); - json.add("sendno", new JsonPrimitive(sendno)); - return json.toString(); - } - -} diff --git a/src/test/java/cn/jpush/api/push/mock/IMockTest.java b/src/test/java/cn/jpush/api/push/mock/IMockTest.java deleted file mode 100644 index 7d574a62..00000000 --- a/src/test/java/cn/jpush/api/push/mock/IMockTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.jpush.api.push.mock; - -import java.util.ArrayList; -import java.util.List; - -public interface IMockTest { - public static final String REMOTE_PATH = "/v3/push"; - - public static final String appKey ="dd1066407b044738b6479275"; - public static final String masterSecret = "2b38ce69b1de2a7fa95706ea"; - - public static final String CONTENT_TYPE_JSON = "application/json"; - public static final List SUPPORT_PLATFORM = new ArrayList(); - public static final List SUPPORT_AUDIENCE = new ArrayList(); - - public static final int SUCCEED_RESULT_CODE = 0; - public static final int LACK_OF_PARAMS = 1002; - public static final int INVALID_PARAMS = 1003; - public static final int AUTHENTICATION_FAIL = 1004; - public static final int TOO_BIG = 1005; - public static final int APPKEY_NOT_EXIST = 1008; - - public static final String ALERT = "JPush Test - alert"; - public static final String MSG_CONTENT = "JPush Test - msgContent"; - - public static final String TAG1 = "tag1"; - public static final String TAG2 = "tag2"; - public static final String TAG_ALL = "tag_all"; - public static final String TAG_NO = "tag_no"; - public static final String ALIAS1 = "alias1"; - public static final String ALIAS2 = "alias2"; - public static final String ALIAS_NO = "alias_no"; - public static final String REGISTRATION_ID1 = "0900e8d85ef"; - public static final String REGISTRATION_ID2 = "0a04ad7d8b4"; -} diff --git a/src/test/java/cn/jpush/api/push/mock/ResponseErrorTest.java b/src/test/java/cn/jpush/api/push/mock/ResponseErrorTest.java deleted file mode 100644 index 537cef39..00000000 --- a/src/test/java/cn/jpush/api/push/mock/ResponseErrorTest.java +++ /dev/null @@ -1,299 +0,0 @@ -package cn.jpush.api.push.mock; -import org.junit.Test; - -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.Notification; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -public class ResponseErrorTest extends BaseMockTest { - -// @Test -// public void appKeyNotExist() { -// _mockServer.enqueue(new MockResponse() -// .setResponseCode(400) -// .setBody(getResponseError(111, 222, 1011, "appKey does not exist."))); -// -// String appKey = "dd1066407b044738b6479274"; -// JPushClient client = new JPushClient(masterSecret, appKey); -// PushPayload payload = PushPayload.alertAll(ALERT); -// PushResult result = client.sendPush(payload); -// assertEquals(APPKEY_NOT_EXIST, result.getErrorCode()); -// } -// -// @Test -// public void authenticationFail() { -// String masterSecret = "2b38ce69b1de2a7fa95706e2"; -// JPushClient client = new JPushClient(masterSecret, appKey); -// PushPayload payload = PushPayload.alertAll(ALERT); -// PushResult result = client.sendPush(payload); -// assertEquals(AUTHENTICATION_FAIL, result.getErrorCode()); -// } - - @Test - public void tooBig() { - String msgContent = "深圳制造厂的朋友告诉我,过去的一年,他们服务了几十家小型创业公司,代工智能手表。不过,今年这些创业公司已经找不到了,庆幸的是,代工厂都是先付款再生产,也就没有损失。可穿戴设备、硬件创新,大潮初起,泥沙俱下,浪潮过后,却是遍地狼藉。国内的智能手环、手表们,如土曼、果壳,在 Jawbone、Google Glass 们引领下,纷纷推出“划时代”的产品,一时间,国内宣称要做可穿戴设备的公司,如过江之鲫。2013 年,不说句硬件创新,不戴款智能手环,都不好意思说自己是站在人文与科技的十字路口。2013 年,身边的朋友纷纷佩戴上了 Jawbone,幸运的人也会戴上传说中的智能手表。不过,现在越来越多的朋友开始放弃这些所谓的可穿戴式设备。"; - _currentPayload = PushPayload.messageAll(msgContent).toString(); - _expectedErrorCode = 1005; - } - - // ---------------- invalid params - - @Test - public void invalidParams_platform() throws Exception { - JsonObject payload = new JsonObject(); - payload.add("platform", new JsonPrimitive("all_platform")); - payload.add("audience", Audience.all().toJSON()); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1003; - } - - @Test - public void invalidParams_audience() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", new JsonPrimitive("all_audience")); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1003; - } - - @Test - public void invalidParams_notification() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - payload.add("notification", new JsonPrimitive(ALERT)); - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1003; - } - - @Test - public void invalidParams_notification_android() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - notification.add("android", new JsonPrimitive(ALERT)); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1003; - } - - @Test - public void invalidParams_notification_ios() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - notification.add("ios", new JsonPrimitive(ALERT)); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1003; - } - - @Test - public void invalidParams_notification_winphone() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - notification.add("winphone", new JsonPrimitive(ALERT)); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1003; - } - - @Test - public void invalidParams_notification_android_builderidNotNumber() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject android = new JsonObject(); - android.add("builder_id", new JsonPrimitive("builder_id_string")); - - notification.add("android", android); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1003; - } - - - // ------------------------ lack of params - - @Test - public void lackOfParams_platform() { - JsonObject payload = new JsonObject(); - payload.add("audience", Audience.all().toJSON()); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_audience() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_messageAndNotificaiton() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_notification_android_empty() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject android = new JsonObject(); - - notification.add("android", android); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_notification_ios_empty() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject ios = new JsonObject(); - - notification.add("ios", ios); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_notification_winphone_empty() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); - - notification.add("winphone", winphone); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_notification_android_noalert() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject android = new JsonObject(); - android.add("title", new JsonPrimitive("title")); - - notification.add("android", android); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_notification_ios_noalert() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject ios = new JsonObject(); - ios.add("badge", new JsonPrimitive(11)); - - notification.add("ios", ios); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - @Test - public void lackOfParams_notification_winphone_noalert() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); - winphone.add("title", new JsonPrimitive("title")); - - notification.add("winphone", winphone); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - _currentPayload = payload.toString(); - _expectedErrorCode = 1002; - } - - - -} - diff --git a/src/test/java/cn/jpush/api/push/model/MessageTest.java b/src/test/java/cn/jpush/api/push/model/MessageTest.java deleted file mode 100644 index f2b71560..00000000 --- a/src/test/java/cn/jpush/api/push/model/MessageTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package cn.jpush.api.push.model; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.FastTests; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -@Category(FastTests.class) -public class MessageTest { - - @Test(expected = IllegalArgumentException.class) - public void testIllegal() { - Message.newBuilder().build(); - } - - @Test - public void testMsgContent() { - Message message = Message.content("msg content"); - - JsonObject json = new JsonObject(); - json.add("msg_content", new JsonPrimitive("msg content")); - - assertThat(message.toJSON(), is((JsonElement) json)); - } - - @Test - public void testMsgContentAndExtras() { - Message message = Message.newBuilder() - .setMsgContent("msgContent") - .addExtra("key1", "value1") - .addExtra("key2", 222) - .addExtra("key3", Boolean.FALSE).build(); - - JsonObject json = new JsonObject(); - json.add("msg_content", new JsonPrimitive("msgContent")); - - JsonObject extras = new JsonObject(); - extras.add("key1", new JsonPrimitive("value1")); - extras.add("key2", new JsonPrimitive(222)); - extras.add("key3", new JsonPrimitive(Boolean.FALSE)); - - json.add("extras", extras); - - assertThat(message.toJSON(), is((JsonElement) json)); - } - - @Test - public void testMsgContentAndExtrasMap() { - Map extrasMap = new HashMap(); - extrasMap.put("key1", "value1"); - extrasMap.put("key2", "value2"); - - Message message = Message.newBuilder() - .setMsgContent("msgContent") - .addExtras(extrasMap).build(); - - JsonObject json = new JsonObject(); - json.add("msg_content", new JsonPrimitive("msgContent")); - - JsonObject extras = new JsonObject(); - extras.add("key1", new JsonPrimitive("value1")); - extras.add("key2", new JsonPrimitive("value2")); - json.add("extras", extras); - - assertThat(message.toJSON(), is((JsonElement) json)); - } - - -} diff --git a/src/test/java/cn/jpush/api/push/model/OptionsTest.java b/src/test/java/cn/jpush/api/push/model/OptionsTest.java deleted file mode 100644 index 09356610..00000000 --- a/src/test/java/cn/jpush/api/push/model/OptionsTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package cn.jpush.api.push.model; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import cn.jiguang.common.ServiceHelper; -import cn.jpush.api.FastTests; - -import java.util.HashMap; -import java.util.Map; - -@Category(FastTests.class) -public class OptionsTest { - - @Test(expected = IllegalArgumentException.class) - public void testIllegalSendno() { - Options.newBuilder().setSendno(-1).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegalOverrideMsgId() { - Options.newBuilder().setOverrideMsgId(-1).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegalTimeToLive() { - Options.newBuilder().setTimeToLive(-2).build(); - } - - @Test - public void testSendno() { - JsonObject json = new JsonObject(); - json.add("sendno", new JsonPrimitive(111)); - json.add("apns_production", new JsonPrimitive(false)); - Options options = Options.newBuilder().setSendno(111).build(); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testTimeToLive_int() { - JsonObject json = new JsonObject(); - json.add("sendno", new JsonPrimitive(111)); - json.add("apns_production", new JsonPrimitive(false)); - json.add("time_to_live", new JsonPrimitive(640)); - - Options options = Options.newBuilder() - .setSendno(111) - .setTimeToLive(640).build(); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testTimeToLive_0() { - JsonObject json = new JsonObject(); - json.add("sendno", new JsonPrimitive(111)); - json.add("apns_production", new JsonPrimitive(false)); - json.add("time_to_live", new JsonPrimitive(0)); - - Options options = Options.newBuilder() - .setSendno(111) - .setTimeToLive(0).build(); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testTimeToLive_default() { - JsonObject json = new JsonObject(); - json.add("sendno", new JsonPrimitive(111)); - json.add("apns_production", new JsonPrimitive(false)); - - Options options = Options.newBuilder() - .setSendno(111) - .setTimeToLive(-1).build(); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testApnsProduction_defaultFalse() { - int sendno = ServiceHelper.generateSendno(); - - JsonObject json = new JsonObject(); - json.add("apns_production", new JsonPrimitive(false)); - json.add("sendno", new JsonPrimitive(sendno)); - - Options options = Options.newBuilder() - .setSendno(sendno) - .build(); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testApnsProduction_True() { - int sendno = ServiceHelper.generateSendno(); - - JsonObject json = new JsonObject(); - json.add("apns_production", new JsonPrimitive(true)); - json.add("sendno", new JsonPrimitive(sendno)); - - Options options = Options.newBuilder() - .setSendno(sendno) - .setApnsProduction(true) - .build(); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testBigPushDuration() { - int sendno = ServiceHelper.generateSendno(); - Options options = Options.newBuilder() - .setSendno(sendno) - .setBigPushDuration(10) - .build(); - - JsonObject json = new JsonObject(); - json.add("sendno", new JsonPrimitive(sendno)); - json.add("big_push_duration", new JsonPrimitive(10)); - json.add("apns_production", new JsonPrimitive(false)); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testThirdPartyChannel() { - int sendno = ServiceHelper.generateSendno(); - - Map> thirdMap = new HashMap<>(); - Map huaweiMap = new HashMap<>(); - huaweiMap.put("distribution", "jpush"); - thirdMap.put("huawei", huaweiMap); - - Options options = Options.newBuilder() - .setSendno(sendno) - .setThirdPartyChannel(thirdMap) - .build(); - System.out.println("json string: " + options.toJSON()); - - JsonObject json = new JsonObject(); - JsonObject thirdPartyChannel = new JsonObject(); - JsonObject huawei = new JsonObject(); - huawei.addProperty("distribution", "jpush"); - thirdPartyChannel.add("huawei", huawei); - json.add("sendno", new JsonPrimitive(sendno)); - json.add("apns_production", new JsonPrimitive(false)); - json.add("third_party_channel", thirdPartyChannel); - - assertThat(options.toJSON(), is((JsonElement) json)); - } - - @Test - public void testThirdPartyChannelV2() { - int sendno = ServiceHelper.generateSendno(); - - Map thirdMap = new HashMap<>(); - JsonObject vivoJsonObj = new JsonObject(); - vivoJsonObj.addProperty("distribution", "ospush"); - vivoJsonObj.addProperty("classification", 1); - thirdMap.put("vivo", vivoJsonObj); - - Options options = Options.newBuilder() - .setSendno(sendno) - .setThirdPartyChannelV2(thirdMap) - .build(); - System.out.println("json string: " + options.toJSON()); - - JsonObject json = new JsonObject(); - JsonObject thirdPartyChannel = new JsonObject(); - JsonObject vivo = new JsonObject(); - vivo.addProperty("distribution", "ospush"); - vivo.addProperty("classification", 1); - thirdPartyChannel.add("vivo", vivo); - json.add("sendno", new JsonPrimitive(sendno)); - json.add("apns_production", new JsonPrimitive(false)); - json.add("third_party_channel", thirdPartyChannel); - - assertThat(options.toJSON(), is((JsonElement) json)); - } -} - diff --git a/src/test/java/cn/jpush/api/push/model/PlatformTesst.java b/src/test/java/cn/jpush/api/push/model/PlatformTesst.java deleted file mode 100644 index b481934e..00000000 --- a/src/test/java/cn/jpush/api/push/model/PlatformTesst.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.jpush.api.push.model; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import cn.jiguang.common.DeviceType; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonPrimitive; - -import cn.jpush.api.FastTests; - -@Category(FastTests.class) -public class PlatformTesst { - - @Test - public void testAll() { - Platform all = Platform.all(); - Assert.assertEquals("test", new JsonPrimitive("all"), all.toJSON()); - } - - @Test(expected = IllegalArgumentException.class) - public void testNotAll() { - Platform all = Platform.newBuilder().setAll(false).build(); - - assertThat(all.toJSON(), is((JsonElement) new JsonPrimitive("all"))); - } - - @Test - public void testAndroid() { - Platform android = Platform.newBuilder().addDeviceType(DeviceType.Android).build(); - JsonArray array = new JsonArray(); - array.add(new JsonPrimitive("android")); - - assertThat(android.toJSON(), is((JsonElement) array)); - } - -} - - - diff --git a/src/test/java/cn/jpush/api/push/model/PushPayloadTest.java b/src/test/java/cn/jpush/api/push/model/PushPayloadTest.java deleted file mode 100644 index d667a34a..00000000 --- a/src/test/java/cn/jpush/api/push/model/PushPayloadTest.java +++ /dev/null @@ -1,227 +0,0 @@ -package cn.jpush.api.push.model; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import cn.jiguang.common.ServiceHelper; -import cn.jpush.api.FastTests; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.IosNotification; -import cn.jpush.api.push.model.notification.Notification; - -@Category(FastTests.class) -public class PushPayloadTest { - - @Test(expected = IllegalArgumentException.class) - public void testIllegal_OnlyAudience() { - Audience audience = Audience.all(); - PushPayload.newBuilder().setAudience(audience).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegal_OnlyPlatform() { - Platform platform = Platform.all(); - PushPayload.newBuilder().setPlatform(platform).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegal_PlatformAudience() { - Platform platform = Platform.all(); - Audience audience = Audience.all(); - PushPayload.newBuilder().setPlatform(platform).setAudience(audience).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegal_NoAudience() { - Platform platform = Platform.all(); - Notification notifcation = Notification.alert("alert"); - PushPayload.newBuilder().setPlatform(platform).setNotification(notifcation).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegal_NoPlatform() { - Audience audience = Audience.all(); - Notification notifcation = Notification.alert("alert"); - PushPayload.newBuilder() - .setAudience(audience) - .setNotification(notifcation).build(); - } - - @Test - public void testNotification() { - int sendno = ServiceHelper.generateSendno(); - Notification notifcation = Notification.alert("alert"); - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setOptions(Options.sendno(sendno)) - .setNotification(notifcation).build(); - - JsonObject json = new JsonObject(); - json.add("audience", new JsonPrimitive("all")); - json.add("platform", new JsonPrimitive("all")); - - JsonObject noti = new JsonObject(); - noti.add("alert", new JsonPrimitive("alert")); - json.add("notification", noti); - - JsonObject options = new JsonObject(); - options.add("sendno", new JsonPrimitive(sendno)); - options.add("apns_production", new JsonPrimitive(false)); - json.add("options", options); - - Assert.assertEquals("", json, payload.toJSON()); - } - - @Test - public void testMessage() { - int sendno = ServiceHelper.generateSendno(); - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setOptions(Options.sendno(sendno)) - .setMessage(Message.content("message")).build(); - - JsonObject json = new JsonObject(); - json.add("audience", new JsonPrimitive("all")); - json.add("platform", new JsonPrimitive("all")); - - JsonObject msg = new JsonObject(); - msg.add("msg_content", new JsonPrimitive("message")); - json.add("message", msg); - - JsonObject options = new JsonObject(); - options.add("sendno", new JsonPrimitive(sendno)); - options.add("apns_production", new JsonPrimitive(false)); - json.add("options", options); - - Assert.assertEquals("", json, payload.toJSON()); - } - - @Test - public void testGlobalExceed() { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setMessage(Message.content(LONG_TEXT_2)) - .build(); - System.out.println("Size: " + LONG_TEXT_2.getBytes().length); - Assert.assertFalse("Shouldn't exceed - " + LONG_TEXT_2.getBytes().length, - payload.isGlobalExceedLength()); - } - - @Test - public void testGlobalExeed2() { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setMessage(Message.content(LONG_TEXT_3)) - .build(); - System.out.println("Size: " + LONG_TEXT_3.getBytes().length); - Assert.assertTrue("Should exeed - " + LONG_TEXT_3.getBytes().length, - payload.isGlobalExceedLength()); - } - - @Test - public void testIosExceed() { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.alert(LONG_TEXT_1)) - .build(); - System.out.println("Size: " + LONG_TEXT_1.getBytes().length); - Assert.assertFalse("Shouldn't exceed - " + LONG_TEXT_1.getBytes().length, - payload.isIosExceedLength()); - } - - @Test - public void testIosExceed2() { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder().addPlatformNotification( - IosNotification.alert(LONG_TEXT_3)).build()) - .build(); - System.out.println("Size: " + LONG_TEXT_3.getBytes().length); - Assert.assertTrue("Should exceed - " + LONG_TEXT_3.getBytes().length, - payload.isIosExceedLength()); - } - - - - - private static final String LONG_TEXT_1 = "" - + "极光推送,使得开发者可以即时地向其应用程序的用户推送通知或者消息," - + "与用户保持互动,从而有效地提高留存率,提升用户体验。平台提供整合了Android推送、iOS推送的统一推送服务。"; - private static final String LONG_TEXT_2 = "" - + "通过极光推送服务,主动、及时地向您的用户发起交互,向其推送聊天消息、日程提醒、活动预告、进度提示、动态更新等。" - + "精准的目标用户和有价值的推送内容可以提升用户忠诚度,提高留存率与收入。" - + "客户端 SDK 采用自定义的协议保持长连接,电量、流量消耗都很少。 " - + "服务端先进技术架构,高并发可扩展性的云服务,经受过几亿用户的考验," - + "完全省去应用开发者自己维护长连接的设备和人力的成本投入。" - + "简单的SDK集成方式,使开发商可以快速部署,更专注主营业务。灵活的推送入接入," - + "同时支持网站上直接推送,也提供 消息推送和送达统计的 API调用。 " - + "清晰的统计图表,直观的跟踪推送带来的效果。" - + "下载并集成 SDK 接入极光推送服务。极光推送提供了 Android,iOS,Windows Phone以及 PhoneGap 的客户端 SDK。" - + "同时也开放多种语言实现的服务端 SDK,方便开发者调用 API 进行推送。" - + "本 Wiki 是极光推送 (JPush) 产品的开发者文档网站。" - + "极光推送所有技术文档都在本 Wiki 里,没有别的提供渠道。同时,我们也在不断地补充、完善文档。" - + "这些文档包括这样几种类型:常见问题、入门指南、API定义、教程等。"; - private static final String LONG_TEXT_3 = "" - + "这是 Push API 最近的版本。" - + "相比于 API v2 版本,v3 版本的改进为:" - + "完全基于 https,不再提供 http 访问;" - + "使用 HTTP Basic Authentication 的方式做访问授权。这样整个 API 请求可以使用常见的 HTTP 工具来完成,比如:curl,浏览器插件等;" - + "推送内容完全使用 JSON 的格式;" - + "支持的功能有所改进:支持多 tag 的与或操作;可单独发送通知或者自定义消息,也可同时推送通知与自定义消息;windows phone 目前只有通知。" - + "向某单个设备或者某设备列表推送一条通知、或者消息。" - + "推送的内容只能是 JSON 表示的一个推送对象。" - + "调用地址:POST https://api.jpush.cn/v3/push" - + "别名与标签使用教程 为什么需要别名与标签" - + "推送消息时,要指定推送的对象:全部,某一个人,或者某一群人。" - + "全部很好办,针对某应用“群发”就好了。Portal与API都支持向指定的 appKey 群发消息。" - + "要指定向某一个特定的人,或者某一群特定的人,则相对复杂。" - + "因为对于 JPush 来说,某一个人就是一个注册ID,这个注册ID与开发者App没有任何关系,或者说对开发者App是没有意义的。" - + "如果要对开发者App有意义的某个特定的用户推送消息,则需要:把 JPush 注册用户与开发者App 用户绑定起来。" - + "这个绑定有两个基本思路:" - + "把绑定关系保存到 JPush 服务器端" - + "把绑定关系保存到开发者应用服务器中" - + "前者,就是这里要说到的:别名与标签的功能。这个机制简单易用,适用于大多数开发者。" - + "后者,则是 JPush 提供的另外一套 RegistrationID 机制。这套机制开发者需要有应用服务器来维护绑定关系,不适用于普通开发者。" - + "Android SDK r1.6.0 版本开始支持。" - + "别名与标签的机制,其工作方式是:" - + "客户端开发者App调用 setAliasAndTags API 来设置关系" - + "JPush SDK 把该关系设置保存到 JPush Server 上" - + "在服务器端推送消息时,指定向之前设置过的别名或者标签推送" - + "SDK 支持的 setAliasAndTags 请参考相应的文档:别名与标签 API" - + "使用过程中有几个点做特别说明:" - + "App 调用 SDK setAliasAndTags API 时,r1.5.0 版本提供了 Callback 来返回设置状态。如果返回 6002 (超时)则建议重试" - + "老版本没有提供 Callback 无设置状态返回,从而没有机制确定一定成功。建议升级到新版本" - + "Portal 上推送或者 API 调用向别名或者标签推送时,可能会报错:不存在推送目标用户。" - + "该报错表明,JPush Server 上还没有针对你所推送的别名或者标签的用户绑定关系,所以没有推送目标。" - + "这时请开发者检查确认,开发者App是否正确地调用了 setAliasAndTags API,以及调用时是否网络不好,JPush SDK 暂时未能保存成功。" - + "使用别名 用于给某特定用户推送消息。别名,可以近似地被认为,是用户帐号里的昵称。" - + "使用标签 用于给某一群人推送消息。" - + "标签类似于博客里为文章打上 tag ,即为某资源分类。" - + "动态标签 JPush 提供的设置标签的 API 是在客户端的。" - + "开发者如何做到在自己的服务器端动态去设置分组呢? 比如一个企业OA系统,经常需要去变更部门人员分组。以下是大概的思路:" - + "设计一种自定义消息格式(业务协议),App解析后可以调用 JPush SDK setAliasAndTags API 来重新设置标签(分组)" - + "例:{\"action\":\"resetTags\", \"newTags\":[\"dep_level_1\":\"A公司\", \"dep_level_2\":\"技术部\", \"dep_level_3\"" - + ":\"Android开发组\", \"address\":\"深圳\", \"lang\":\"zh\"]}" - + "要动态设置分组时,推送这条自定义消息给指定的用户" - + "使用别名的机制,推送到指定的用户。" - + "客户端App 调用 JPush SDK API 来设置新的标签" - + "通过极光推送服务,主动、及时地向您的用户发起交互,向其推送聊天消息、日程提醒、活动预告、进度提示、动态更新等。" - + "精准的目标用户和有价值的推送内容可以提升用户忠诚度,提高留存率与收入。" - + "客户端 SDK 采用自定义的协议保持长连接,电量、流量消耗都很少。 " - + "服务端先进技术架构,高并发可扩展性的云服务,经受过几亿用户的考验," - + "完全省去应用开发者自己维护长连接的设备和人力的成本投入。" - + "简单的SDK集成方式,使开发商可以快速部署,更专注主营业务。灵活的推送入接入," - + "同时支持网站上直接推送,也提供 消息推送和送达统计的 API调用。 "; -} - - diff --git a/src/test/java/cn/jpush/api/push/model/audience/AudienceTargetTest.java b/src/test/java/cn/jpush/api/push/model/audience/AudienceTargetTest.java deleted file mode 100644 index 2b09e2d7..00000000 --- a/src/test/java/cn/jpush/api/push/model/audience/AudienceTargetTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.jpush.api.push.model.audience; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.FastTests; - -import com.google.gson.JsonArray; -import com.google.gson.JsonPrimitive; - -@Category(FastTests.class) -public class AudienceTargetTest { - - @Test(expected = IllegalArgumentException.class) - public void testIllegal() { - AudienceTarget.newBuilder().setAudienceType(AudienceType.ALIAS).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegal2() { - AudienceTarget.newBuilder().addAudienceTargetValue("aaa").build(); - } - - @Test - public void testAlias() { - JsonArray arr = new JsonArray(); - arr.add(new JsonPrimitive("aaa")); - - AudienceTarget target = AudienceTarget.alias("aaa"); - Assert.assertEquals("", arr, target.toJSON()); - } - - - -} diff --git a/src/test/java/cn/jpush/api/push/model/audience/AudienceTest.java b/src/test/java/cn/jpush/api/push/model/audience/AudienceTest.java deleted file mode 100644 index 23cf5b18..00000000 --- a/src/test/java/cn/jpush/api/push/model/audience/AudienceTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.jpush.api.push.model.audience; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.FastTests; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -@Category(FastTests.class) -public class AudienceTest { - - @Test - public void testAll() { - Audience audience = Audience.all(); - Assert.assertEquals("test", new JsonPrimitive("all"), audience.toJSON()); - } - - @Test(expected = IllegalArgumentException.class) - public void testAllMore() { - AudienceTarget target = AudienceTarget.alias("aaaa"); - Audience audience = Audience.newBuilder() - .setAll(true) - .addAudienceTarget(target) - .build(); - Assert.assertEquals("test", new JsonPrimitive("all"), audience.toJSON()); - } - - @Test(expected = IllegalArgumentException.class) - public void testNotAll() { - Audience audience = Audience.newBuilder().setAll(false).build(); - Assert.assertEquals("test", new JsonPrimitive("all"), audience.toJSON()); - } - - @Test - public void testAudience() { - JsonObject json = new JsonObject(); - JsonArray arr = new JsonArray(); - arr.add(new JsonPrimitive("aaaa")); - json.add("alias", arr); - - AudienceTarget target = AudienceTarget.alias("aaaa"); - Audience audience = Audience.newBuilder() - .addAudienceTarget(target) - .build(); - Assert.assertEquals("test", json, audience.toJSON()); - - } -} diff --git a/src/test/java/cn/jpush/api/push/model/notification/AndroidNotificationTest.java b/src/test/java/cn/jpush/api/push/model/notification/AndroidNotificationTest.java deleted file mode 100644 index 460c2cb2..00000000 --- a/src/test/java/cn/jpush/api/push/model/notification/AndroidNotificationTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package cn.jpush.api.push.model.notification; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.FastTests; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -@Category(FastTests.class) -public class AndroidNotificationTest { - - @Test - public void testNoParams() { - AndroidNotification an = AndroidNotification.newBuilder().build(); - Assert.assertEquals("", new JsonObject(), an.toJSON()); - } - - @Test - public void testQuickAlert() { - AndroidNotification an = AndroidNotification.alert("alert"); - JsonObject json = new JsonObject(); - json.add("alert", new JsonPrimitive("alert")); - Assert.assertEquals("", json, an.toJSON()); - } - - @Test - public void testTitle() { - AndroidNotification an = AndroidNotification.newBuilder().setTitle("title").build(); - JsonObject json = new JsonObject(); - json.add("title", new JsonPrimitive("title")); - Assert.assertEquals("", json, an.toJSON()); - } - - @Test - public void testExtra() { - AndroidNotification an = AndroidNotification.newBuilder() - .addExtra("key2", 222) - .addExtra("key1", "value1").build(); - JsonObject json = new JsonObject(); - JsonObject extra = new JsonObject(); - extra.add("key1", new JsonPrimitive("value1")); - extra.add("key2", new JsonPrimitive(222)); - json.add("extras", extra); - Assert.assertEquals("", json, an.toJSON()); - } - - @Test - public void testExtra_nullvalue() { - String value2 = "value2"; - value2 = null; - AndroidNotification an = AndroidNotification.newBuilder() - .addExtra("key2", value2) - .addExtra("key1", "value1").build(); - JsonObject json = new JsonObject(); - JsonObject extra = new JsonObject(); - extra.add("key1", new JsonPrimitive("value1")); - json.add("extras", extra); - Assert.assertEquals("", json, an.toJSON()); - } - - @Test - public void testCustomParam() { - - Map customParams = new HashMap<>(); - customParams.put("custom_field1", "field1"); - customParams.put("custom_field2", "field2"); - customParams.put("custom_field3", "field3"); - - AndroidNotification an = AndroidNotification.newBuilder() - .addCustom("custom_field_num", 1) - .addCustom("custom_field_string", "string") - .addCustom("custom_field_boolean", true) - .addCustom(customParams) - .build(); - Assert.assertEquals("{\"custom_field_num\":1,\"custom_field_string\":\"string\",\"custom_field_boolean\":true,\"custom_field1\":\"field1\",\"custom_field3\":\"field3\",\"custom_field2\":\"field2\"}", an.toJSON().toString()); - } - - -} - - diff --git a/src/test/java/cn/jpush/api/push/model/notification/IosNotificationTest.java b/src/test/java/cn/jpush/api/push/model/notification/IosNotificationTest.java deleted file mode 100644 index d8b87cdf..00000000 --- a/src/test/java/cn/jpush/api/push/model/notification/IosNotificationTest.java +++ /dev/null @@ -1,159 +0,0 @@ -package cn.jpush.api.push.model.notification; - -import cn.jpush.api.FastTests; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -@Category(FastTests.class) -public class IosNotificationTest { - - @Test - public void testEmpty() { - IosNotification ios = IosNotification.newBuilder().build(); - JsonObject json = new JsonObject(); - json.add("sound", new JsonPrimitive("")); - json.add("badge", new JsonPrimitive("+1")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testQuickAlert() { - IosNotification ios = IosNotification.alert("aaa"); - JsonObject json = new JsonObject(); - json.add("alert", new JsonPrimitive("aaa")); - json.add("sound", new JsonPrimitive("")); - json.add("badge", new JsonPrimitive("+1")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testBadge_0() { - IosNotification ios = IosNotification.newBuilder().setBadge(0).build(); - JsonObject json = new JsonObject(); - json.add("badge", new JsonPrimitive("0")); - json.add("sound", new JsonPrimitive("")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testBadge_2() { - IosNotification ios = IosNotification.newBuilder().setBadge(2).build(); - JsonObject json = new JsonObject(); - json.add("badge", new JsonPrimitive("2")); - json.add("sound", new JsonPrimitive("")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testBadge_auto() { - IosNotification ios = IosNotification.newBuilder().autoBadge().build(); - JsonObject json = new JsonObject(); - json.add("badge", new JsonPrimitive("+1")); - json.add("sound", new JsonPrimitive("")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testBadge_plus_2() { - IosNotification ios = IosNotification.newBuilder().incrBadge(2).build(); - JsonObject json = new JsonObject(); - json.add("badge", new JsonPrimitive("+2")); - json.add("sound", new JsonPrimitive("")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testBadge_plus_0() { - IosNotification ios = IosNotification.newBuilder().incrBadge(0).build(); - JsonObject json = new JsonObject(); - json.add("badge", new JsonPrimitive("+0")); - json.add("sound", new JsonPrimitive("")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testBadge_minus_2() { - IosNotification ios = IosNotification.newBuilder().incrBadge(-2).build(); - JsonObject json = new JsonObject(); - json.add("badge", new JsonPrimitive("-2")); - json.add("sound", new JsonPrimitive("")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testSound() { - IosNotification ios = IosNotification.newBuilder().setSound("sound").build(); - JsonObject json = new JsonObject(); - json.add("sound", new JsonPrimitive("sound")); - json.add("badge", new JsonPrimitive("+1")); - Assert.assertEquals("", json, ios.toJSON()); - } - - @Test - public void testSoundDisabled() { - IosNotification ios = IosNotification.newBuilder() - .setSound("sound") - .disableSound() - .setAlert("alert") - .build(); - JsonObject json = new JsonObject(); - json.add("alert", new JsonPrimitive("alert")); - json.add("badge", new JsonPrimitive("+1")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testBadgeDisabled() { - IosNotification ios = IosNotification.newBuilder() - .disableBadge() - .setAlert("alert") - .build(); - JsonObject json = new JsonObject(); - json.add("alert", new JsonPrimitive("alert")); - json.add("sound", new JsonPrimitive("")); - assertEquals("", json, ios.toJSON()); - } - - - @Test - public void testExtra() { - IosNotification ios = IosNotification.newBuilder() - .addExtra("key2", Boolean.TRUE) - .addExtra("key", "value").build(); - JsonObject json = new JsonObject(); - JsonObject extra = new JsonObject(); - extra.add("key", new JsonPrimitive("value")); - extra.add("key2", new JsonPrimitive(Boolean.TRUE)); - json.add("extras", extra); - json.add("sound", new JsonPrimitive("")); - json.add("badge", new JsonPrimitive("+1")); - assertEquals("", json, ios.toJSON()); - } - - @Test - public void testCategory() { - IosNotification ios = IosNotification.newBuilder() - .setCategory("java").build(); - - JsonObject json = new JsonObject(); - json.add("category", new JsonPrimitive("java")); - json.add("sound", new JsonPrimitive("")); - json.add("badge", new JsonPrimitive("+1")); - - assertThat(ios.toJSON(), is((JsonElement) json)); - } - -} - - diff --git a/src/test/java/cn/jpush/api/push/model/notification/NotificationTest.java b/src/test/java/cn/jpush/api/push/model/notification/NotificationTest.java deleted file mode 100644 index ec5c0464..00000000 --- a/src/test/java/cn/jpush/api/push/model/notification/NotificationTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package cn.jpush.api.push.model.notification; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.FastTests; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -@Category(FastTests.class) -public class NotificationTest { - - @Test(expected = IllegalArgumentException.class) - public void testEmpty() { - Notification.newBuilder().build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testIllegal() { - Notification notification = Notification.newBuilder() - .addPlatformNotification( - AndroidNotification.newBuilder().build()) - .build(); - Assert.assertEquals("", "", notification.toJSON()); - } - - @Test(expected = IllegalArgumentException.class) - public void testNoAlert() { - Notification notification = Notification.newBuilder() - .addPlatformNotification( - AndroidNotification.newBuilder().setTitle("title").build()) - .build(); - Assert.assertEquals("", "", notification.toJSON()); - } - - @Test - public void testAlert_android() { - Notification notification = Notification.newBuilder() - .addPlatformNotification(AndroidNotification.alert("alert")) - .build(); - JsonObject json = new JsonObject(); - JsonObject android = new JsonObject(); - android.add("alert", new JsonPrimitive("alert")); - json.add("android", android); - Assert.assertEquals("", json, notification.toJSON()); - } - - @Test - public void testAlert_ios() { - Notification notification = Notification.newBuilder() - .addPlatformNotification(IosNotification.alert("alert")) - .build(); - JsonObject json = new JsonObject(); - JsonObject ios = new JsonObject(); - ios.add("alert", new JsonPrimitive("alert")); - ios.add("sound", new JsonPrimitive("")); - ios.add("badge", new JsonPrimitive("+1")); - json.add("ios", ios); - Assert.assertEquals("", json, notification.toJSON()); - } - - @Test - public void testAlert_winphone() { - Notification notification = Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("alert")) - .build(); - JsonObject json = new JsonObject(); - JsonObject winphone = new JsonObject(); - winphone.add("alert", new JsonPrimitive("alert")); - json.add("winphone", winphone); - Assert.assertEquals("", json, notification.toJSON()); - } - - @Test - public void testAlert_all() { - Notification notification = Notification.alert("alert"); - JsonObject json = new JsonObject(); - json.add("alert", new JsonPrimitive("alert")); - - Assert.assertEquals("", json, notification.toJSON()); - } - - @Test - public void testExtras_jsonValue() { - JsonObject extraValue = new JsonObject(); - extraValue.add("v_key", new JsonPrimitive("v_value")); - - Notification notification = Notification - .newBuilder() - .addPlatformNotification( - AndroidNotification - .newBuilder() - .setAlert("alert") - .addExtra("key", extraValue) - .build()) - .build(); - - JsonObject json = new JsonObject(); - JsonObject android = new JsonObject(); - android.add("alert", new JsonPrimitive("alert")); - - JsonObject extra = new JsonObject(); - extra.add("key", extraValue); - android.add("extras", extra); - - json.add("android", android); - - Assert.assertEquals("", json, notification.toJSON()); - } - - - - - @Test - public void testShortcut_android() { - Notification notification = Notification.android("alert", "title", null); - JsonObject json = new JsonObject(); - JsonObject android = new JsonObject(); - android.add("alert", new JsonPrimitive("alert")); - android.add("title", new JsonPrimitive("title")); - json.add("android", android); - - Assert.assertEquals("", json, notification.toJSON()); - } - - - -} diff --git a/src/test/java/cn/jpush/api/push/model/notification/WinphoneNotificationTest.java b/src/test/java/cn/jpush/api/push/model/notification/WinphoneNotificationTest.java deleted file mode 100644 index 9cadb938..00000000 --- a/src/test/java/cn/jpush/api/push/model/notification/WinphoneNotificationTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.jpush.api.push.model.notification; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.FastTests; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -@Category(FastTests.class) -public class WinphoneNotificationTest { - - @Test - public void testEmpty() { - WinphoneNotification winphone = WinphoneNotification.newBuilder().build(); - Assert.assertEquals("", new JsonObject(), winphone.toJSON()); - } - - @Test - public void testQuickAlert() { - WinphoneNotification winphone = WinphoneNotification.alert("aaa"); - JsonObject json = new JsonObject(); - json.add("alert", new JsonPrimitive("aaa")); - Assert.assertEquals("", json, winphone.toJSON()); - } - - @Test - public void testTitle() { - WinphoneNotification winphone = WinphoneNotification.newBuilder().setTitle("title").build(); - JsonObject json = new JsonObject(); - json.add("title", new JsonPrimitive("title")); - Assert.assertEquals("", json, winphone.toJSON()); - } - - @Test - public void testExtra() { - WinphoneNotification winphone = WinphoneNotification.newBuilder() - .addExtra("key2", 222) - .addExtra("key", "value").build(); - JsonObject json = new JsonObject(); - JsonObject extra = new JsonObject(); - extra.add("key", new JsonPrimitive("value")); - extra.add("key2", new JsonPrimitive(222)); - json.add("extras", extra); - Assert.assertEquals("", json, winphone.toJSON()); - } - - -} - - diff --git a/src/test/java/cn/jpush/api/push/remote/AlertOverrideTest.java b/src/test/java/cn/jpush/api/push/remote/AlertOverrideTest.java deleted file mode 100644 index 298eab51..00000000 --- a/src/test/java/cn/jpush/api/push/remote/AlertOverrideTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package cn.jpush.api.push.remote; - -import static org.junit.Assert.assertTrue; - -import cn.jiguang.common.resp.APIRequestException; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.PushResult; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.AndroidNotification; -import cn.jpush.api.push.model.notification.IosNotification; -import cn.jpush.api.push.model.notification.Notification; -import cn.jpush.api.push.model.notification.WinphoneNotification; - -@Category(SlowTests.class) -public class AlertOverrideTest extends BaseRemotePushTest { - - @Test - public void sendAlert_all() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .setAlert("alert") - .addPlatformNotification(AndroidNotification.alert("android alert")) - .addPlatformNotification(IosNotification.alert("ios alert")) - .addPlatformNotification(WinphoneNotification.alert("winphone alert")) - .build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendAlert_android() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.android()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .setAlert("alert") - .addPlatformNotification(AndroidNotification.alert("android alert")) - .build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendAlert_ios() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.ios()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .setAlert("alert") - .addPlatformNotification(IosNotification.alert("ios alert")) - .build()) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test - public void sendAlert_wp() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.winphone()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .setAlert("alert") - .addPlatformNotification(WinphoneNotification.alert("winphone alert")) - .build()) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/AudienceTest.java b/src/test/java/cn/jpush/api/push/remote/AudienceTest.java deleted file mode 100644 index 3fce8f30..00000000 --- a/src/test/java/cn/jpush/api/push/remote/AudienceTest.java +++ /dev/null @@ -1,281 +0,0 @@ -package cn.jpush.api.push.remote; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.HashSet; -import java.util.Set; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jiguang.common.resp.DefaultResult; -import cn.jpush.api.JPushClient; -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.PushResult; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.audience.AudienceTarget; -import cn.jpush.api.push.model.audience.AudienceType; -import cn.jpush.api.push.model.notification.Notification; - -/** - * Device1: 0900e8d85ef - * Device2: - * - * tag1: Device1 - * tag2: Device2 - * tag_all: Device1, Device2 - * tag_no: no Device - * - * alias1: Device1 - * alias2: Device2 - * alias_no: no Device - * - */ -@Category(SlowTests.class) -public class AudienceTest extends BaseRemotePushTest { - public static final String TAG1 = "audience_tag1"; - public static final String TAG2 = "audience_tag2"; - public static final String TAG_ALL = "audience_tag_all"; - public static final String TAG_NO = "audience_tag_no"; - public static final String ALIAS1 = "audience_alias1"; - public static final String ALIAS2 = "audience_alias2"; - public static final String ALIAS_NO = "audience_alias_no"; - - @BeforeClass - public static void setAudiences() throws Exception { - Set tags1 = new HashSet(); - tags1.add(TAG1); - tags1.add(TAG_ALL); - - Set tags2 = new HashSet(); - tags1.add(TAG2); - tags1.add(TAG_ALL); - - JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY); - DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID3, ALIAS1, tags1, null); - assertThat(result.isResultOK(), is(true)); - - result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID3, ALIAS2, tags2, null); - assertThat(result.isResultOK(), is(true)); - } - - // one -------- - - @Test - public void sendByTag() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.tag(TAG1)) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByTagAnd() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.tag_and(TAG1)) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByAlias() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.alias(ALIAS1)) - .setNotification(Notification.alert(ALERT)) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test - public void sendByRegistrationID() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.registrationId(REGISTRATION_ID3)) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - } - - // one more ------------------------- - - @Test - public void sendByTagMore() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.tag(TAG1, TAG2)) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByTagAndMore() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.tag_and(TAG1, TAG_ALL)) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByTagAndMore_fail() { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.tag_and(TAG1, TAG2)) - .setNotification(Notification.alert(ALERT)) - .build(); - - try { - _client.sendPush(payload); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(NO_TARGET, e.getErrorCode()); - } - } - - @Test - public void sendByAliasMore() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.alias(ALIAS1, ALIAS2)) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue("Should be OK", result.isResultOK()); - } - - - @Test - public void sendByRegistrationIDMore() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.registrationId(REGISTRATION_ID1, REGISTRATION_ID2)) - .setNotification(Notification.alert(ALERT)) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - - - // composite ok ------------------------- - - @Test - public void sendByTagAlias() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.newBuilder() - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.ALIAS) - .addAudienceTargetValue(ALIAS1).build()) - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.TAG) - .addAudienceTargetValue(TAG_ALL).build()) - .build()) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByTagRegistrationID() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.newBuilder() - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.REGISTRATION_ID) - .addAudienceTargetValue(REGISTRATION_ID1).build()) - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.TAG) - .addAudienceTargetValue(TAG_ALL).build()) - .build()) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByTagRegistrationID_0() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.newBuilder() - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.REGISTRATION_ID) - .addAudienceTargetValue(REGISTRATION_ID1).build()) - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.TAG) - .addAudienceTargetValue(TAG_NO).build()) - .build()) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByTagAlias_0() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.newBuilder() - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.ALIAS) - .addAudienceTargetValue(ALIAS1).build()) - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.TAG) - .addAudienceTargetValue(TAG2).build()) - .build()) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendByTagAlias_0_2() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.newBuilder() - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.ALIAS) - .addAudienceTargetValue(ALIAS_NO).build()) - .addAudienceTarget(AudienceTarget.newBuilder() - .setAudienceType(AudienceType.TAG) - .addAudienceTargetValue(TAG_ALL).build()) - .build()) - .setNotification(Notification.alert(ALERT)) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/BaseRemotePushTest.java b/src/test/java/cn/jpush/api/push/remote/BaseRemotePushTest.java deleted file mode 100644 index 0aa8b901..00000000 --- a/src/test/java/cn/jpush/api/push/remote/BaseRemotePushTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package cn.jpush.api.push.remote; - -import java.io.IOException; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; - -import cn.jpush.api.BaseTest; -import cn.jpush.api.push.PushClient; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -public abstract class BaseRemotePushTest extends BaseTest { - - public static final String CONTENT_TYPE_JSON = "application/json"; - - public static final int SUCCEED_RESULT_CODE = 0; - public static final int LACK_OF_PARAMS = 1002; - public static final int INVALID_PARAMS = 1003; - public static final int AUTHENTICATION_FAIL = 1004; - public static final int TOO_BIG = 1005; - public static final int APPKEY_NOT_EXIST = 1008; - public static final int NO_TARGET = 1011; - - protected static PushClient _client = null; - - @After - public void after() { - - } - - @BeforeClass - public static void beforeClass() throws IOException { - _client = new PushClient(MASTER_SECRET, APP_KEY); - } - - @AfterClass - public static void afterClass() throws IOException { - } - - - protected String getResponseOK(int msgid, int sendno) { - JsonObject json = new JsonObject(); - json.add("msg_id", new JsonPrimitive(msgid)); - json.add("sendno", new JsonPrimitive(sendno)); - return json.toString(); - } - - protected String getResponseError(int msgid, int sendno, int errorCode, String errorMessage) { - JsonObject json = new JsonObject(); - json.add("msg_id", new JsonPrimitive(msgid)); - json.add("sendno", new JsonPrimitive(sendno)); - - JsonObject error = new JsonObject(); - error.add("code", new JsonPrimitive(errorCode)); - error.add("message", new JsonPrimitive(errorMessage)); - - json.add("error", error); - return json.toString(); - } - - - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/BasicFunctionsTest.java b/src/test/java/cn/jpush/api/push/remote/BasicFunctionsTest.java deleted file mode 100644 index 835a73e9..00000000 --- a/src/test/java/cn/jpush/api/push/remote/BasicFunctionsTest.java +++ /dev/null @@ -1,200 +0,0 @@ -package cn.jpush.api.push.remote; - -import static org.junit.Assert.assertTrue; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jiguang.common.DeviceType; -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.PushResult; -import cn.jpush.api.push.model.Message; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.AndroidNotification; -import cn.jpush.api.push.model.notification.IosNotification; -import cn.jpush.api.push.model.notification.Notification; -import cn.jpush.api.push.model.notification.WinphoneNotification; - -@Category(SlowTests.class) -public class BasicFunctionsTest extends BaseRemotePushTest { - - @Test - public void sendSimpleNotification_Pall_Ndefault() throws Exception { - PushPayload payload = PushPayload.alertAll("Pall Nall default alert"); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendSimpleNotification_Pandroid_Nandroid() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.android()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(AndroidNotification.alert("Pandroid Nandroid alert")) - .build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendSimpleNotification_Pall_Nandroid() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(AndroidNotification.alert("Pall Nandroid alert")) - .build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendSimpleNotification_Pios_Nios() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.ios()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(IosNotification.alert("Pios Nios alert")) - .build()) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test - public void sendSimpleNotification_Pall_Nios() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(IosNotification.alert("Pall Nios alert")) - .build()) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test - public void sendSimpleNotification_Pwp_Nwp() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.winphone()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("Pwp Nwp alert")) - .build()) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test - public void sendSimpleNotification_Pall_Nwp() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("Pall Nwp alert")) - .build()) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - - @Test - public void sendSimpleNotification_Pall_Nall() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.newBuilder() - .addDeviceType(DeviceType.IOS) - .addDeviceType(DeviceType.WinPhone) - .addDeviceType(DeviceType.Android).build()) - .setAudience(Audience.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(WinphoneNotification.alert("Pall Nall wp alert")) - .addPlatformNotification(IosNotification.alert("Pall Nall ios alert")) - .addPlatformNotification(AndroidNotification.alert("Pall Nall android alert")) - .build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendSimpleMessage_default() throws Exception { - PushPayload payload = PushPayload.messageAll("Pall msg"); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendSimpleMessage_Pandroid() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.android()) - .setAudience(Audience.all()) - .setMessage(Message.content("Pandroid msg")) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendSimpleMessage_Pios() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.ios()) - .setAudience(Audience.all()) - .setMessage(Message.content("Pios msg")) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - //@Test - public void sendSimpleMessage_Pwinphone() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.winphone()) - .setAudience(Audience.all()) - .setMessage(Message.content("Pwp msg")) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - - @Test - public void sendSimpleMessageAndNotification_Pall() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.alert("Pall Nall Mall alert")) - .setMessage(Message.content("Pall Nall Mall msg")) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java b/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java deleted file mode 100644 index 1d307fa0..00000000 --- a/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java +++ /dev/null @@ -1,429 +0,0 @@ -package cn.jpush.api.push.remote; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.JPushClient; -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.Notification; - -@Category(SlowTests.class) -public class ExceptionTest extends BaseRemotePushTest { - - @Test - public void appKeyNotExist() { - String appKey = "dd1066407b044738b6479274"; - JPushClient client = new JPushClient(MASTER_SECRET, appKey); - PushPayload payload = PushPayload.alertAll(ALERT); - - try { - client.sendPush(payload); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(AUTHENTICATION_FAIL, e.getErrorCode()); - } - } - - @Test - public void authenticationFail() { - String masterSecret = "2b38ce69b1de2a7fa95706e2"; - JPushClient client = new JPushClient(masterSecret, APP_KEY); - PushPayload payload = PushPayload.alertAll(ALERT); - try { - client.sendPush(payload); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(AUTHENTICATION_FAIL, e.getErrorCode()); - } - } - - @Test - public void tooBig() { - String msgContent = "深圳制造厂的朋友告诉我,过去的一年,他们服务了几十家小型创业公司,代工智能手表。不过,今年这些创业公司已经找不到了,庆幸的是,代工厂都是先付款再生产,也就没有损失。可穿戴设备、硬件创新,大潮初起,泥沙俱下,浪潮过后,却是遍地狼藉。国内的智能手环、手表们,如土曼、果壳,在 Jawbone、Google Glass 们引领下,纷纷推出“划时代”的产品,一时间,国内宣称要做可穿戴设备的公司,如过江之鲫。2013 年,不说句硬件创新,不戴款智能手环,都不好意思说自己是站在人文与科技的十字路口。2013 年,身边的朋友纷纷佩戴上了 Jawbone,幸运的人也会戴上传说中的智能手表。不过,现在越来越多的朋友开始放弃这些所谓的可穿戴式设备。"; - PushPayload payload = PushPayload.messageAll(msgContent); - String content = payload.toString(); - - byte[] bytes = content.getBytes(); - System.out.println("len: " + bytes.length); - try { - _client.sendPush(payload); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(TOO_BIG, e.getErrorCode()); - } - } - - // ---------------- invalid params - - @Test - public void invalidParams_platform() { - JsonObject payload = new JsonObject(); - payload.add("platform", new JsonPrimitive("all_platform")); - payload.add("audience", Audience.all().toJSON()); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_audience() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", new JsonPrimitive("all_audience")); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_notification() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - payload.add("notification", new JsonPrimitive(ALERT)); - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_notification_android() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - notification.add("android", new JsonPrimitive(ALERT)); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_notification_ios() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - notification.add("ios", new JsonPrimitive(ALERT)); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - /* - @Test - public void invalidParams_notification_winphone() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - notification.add("winphone", new JsonPrimitive(ALERT)); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - */ - @Test - public void invalidParams_notification_android_builderidNotNumber() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject android = new JsonObject(); - android.add("builder_id", new JsonPrimitive("builder_id_string")); - - notification.add("android", android); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - - @Test - public void invalidParams_notification_android_empty() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject android = new JsonObject(); - - notification.add("android", android); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_notification_ios_empty() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject ios = new JsonObject(); - - notification.add("ios", ios); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_notification_winphone_empty() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); - - notification.add("winphone", winphone); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(LACK_OF_PARAMS, e.getErrorCode()); - } - } - - - @Test - public void invalidParams_notification_android_noalert() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject android = new JsonObject(); - android.add("title", new JsonPrimitive("title")); - - notification.add("android", android); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_notification_ios_noalert() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject ios = new JsonObject(); - ios.add("badge", new JsonPrimitive(11)); - - notification.add("ios", ios); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - @Test - public void invalidParams_notification_winphone_noalert() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject notification = new JsonObject(); - JsonObject winphone = new JsonObject(); - winphone.add("title", new JsonPrimitive("title")); - - notification.add("winphone", winphone); - payload.add("notification", notification); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(INVALID_PARAMS, e.getErrorCode()); - } - } - - - // ------------------------ lack of params - - @Test - public void lackOfParams_platform() { - JsonObject payload = new JsonObject(); - payload.add("audience", Audience.all().toJSON()); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(LACK_OF_PARAMS, e.getErrorCode()); - } - } - - @Test - public void lackOfParams_audience() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("notification", Notification.alert(ALERT).toJSON()); - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(LACK_OF_PARAMS, e.getErrorCode()); - } - } - - @Test - public void lackOfParams_messageAndNotificaiton() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(LACK_OF_PARAMS, e.getErrorCode()); - } - } - - - @Test - public void lackOfParams_message_noMsgContent() { - JsonObject payload = new JsonObject(); - payload.add("platform", Platform.all().toJSON()); - payload.add("audience", Audience.all().toJSON()); - - JsonObject message = new JsonObject(); - message.add("title", new JsonPrimitive("title")); - - payload.add("message", message); - - System.out.println("json string: " + payload.toString()); - - try { - _client.sendPush(payload.toString()); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - assertEquals(LACK_OF_PARAMS, e.getErrorCode()); - } - } - - - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/MessageTest.java b/src/test/java/cn/jpush/api/push/remote/MessageTest.java deleted file mode 100644 index becb6419..00000000 --- a/src/test/java/cn/jpush/api/push/remote/MessageTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package cn.jpush.api.push.remote; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.PushResult; -import cn.jpush.api.push.model.Message; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; - -@Category(SlowTests.class) -public class MessageTest extends BaseRemotePushTest { - - @Test - public void sendMessageContentOnly() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.all()) - .setMessage(Message.newBuilder().setMsgContent(MSG_CONTENT).build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendMessageContentAndTitle() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.all()) - .setMessage(Message.newBuilder() - .setTitle("message title") - .setContentType("content type") - .setMsgContent(MSG_CONTENT).build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendMessageContentAndExtras() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.all()) - .setMessage(Message.newBuilder() - .addExtra("key1", "value1") - .addExtra("key2", 222) - .addExtra("key3", Boolean.FALSE) - .setMsgContent(MSG_CONTENT).build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/NotificationTest.java b/src/test/java/cn/jpush/api/push/remote/NotificationTest.java deleted file mode 100644 index d296b74a..00000000 --- a/src/test/java/cn/jpush/api/push/remote/NotificationTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package cn.jpush.api.push.remote; - -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.PushResult; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.AndroidNotification; -import cn.jpush.api.push.model.notification.IosAlert; -import cn.jpush.api.push.model.notification.Notification; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import static org.junit.Assert.assertTrue; - -@Category(SlowTests.class) -public class NotificationTest extends BaseRemotePushTest { - - @Test - public void sendNotification_alert_json() throws Exception { - JsonObject json = new JsonObject(); - json.addProperty("key1", "value1"); - json.addProperty("key2", true); - - String alert = json.toString(); - System.out.println(alert); - - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(AndroidNotification.newBuilder() - .setAlert(alert) - .setTitle("title").build()).build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - // --------------- Android - - @Test - public void sendNotification_android_title() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.all()) - .setNotification(Notification.newBuilder() - .addPlatformNotification(AndroidNotification.newBuilder() - .setAlert(ALERT) - .setTitle("title").build()).build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendNotification_android_buildId() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.all()) - .setNotification(Notification.newBuilder() - .setAlert(ALERT) - .addPlatformNotification(AndroidNotification.newBuilder() - .setBuilderId(100) - .build()).build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - @Test - public void sendNotification_android_extras() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.all()) - .setNotification(Notification.newBuilder() - .setAlert(ALERT) - .addPlatformNotification(AndroidNotification.newBuilder() - .addExtra("key1", "value1") - .addExtra("key2", 222) - .build()).build()) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - - - // ------------------ ios - - @Test - public void sendNotification_ios_badge() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.ios()) - .setNotification(Notification.ios_auto_badge()) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test - public void sendNotification_ios_alert_jsonStr() throws Exception { - JsonObject alert = new JsonObject(); - alert.add("title", new JsonPrimitive("Game Request")); - alert.add("body", new JsonPrimitive("Bob wants to play poker")); - alert.add("action-loc-key", new JsonPrimitive("PLAY")); - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.ios()) - .setNotification(Notification.alert(alert.toString())) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - - @Test - public void sendNotification_ios_alert_jsonObj() throws Exception { - IosAlert alert = IosAlert.newBuilder() - .setTitleAndBody("ios title", "test subtitle", "test ios title") - .build(); - - PushPayload payload = PushPayload.newBuilder() - .setAudience(Audience.all()) - .setPlatform(Platform.ios()) - .setNotification(Notification.alert(alert)) - .build(); - try { - PushResult result = _client.sendPush(payload); - } catch (APIRequestException e) { - e.printStackTrace(); - } - } - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/SingleTest.java b/src/test/java/cn/jpush/api/push/remote/SingleTest.java deleted file mode 100644 index 31a46752..00000000 --- a/src/test/java/cn/jpush/api/push/remote/SingleTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.jpush.api.push.remote; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import cn.jpush.api.push.PushResult; -import cn.jpush.api.push.model.Message; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.Notification; - -public class SingleTest extends BaseRemotePushTest { - - @Test - public void sendSimpleMessageAndNotification_Pall() throws Exception { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.all()) - .setNotification(Notification.alert("Pall Nall Mall alert")) - .setMessage(Message.content("Pall Nall Mall msg")) - .build(); - PushResult result = _client.sendPush(payload); - assertTrue(result.isResultOK()); - } - -} - diff --git a/src/test/java/cn/jpush/api/push/remote/SpecialCharacterTest.java b/src/test/java/cn/jpush/api/push/remote/SpecialCharacterTest.java deleted file mode 100644 index 40067676..00000000 --- a/src/test/java/cn/jpush/api/push/remote/SpecialCharacterTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package cn.jpush.api.push.remote; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jiguang.common.resp.DefaultResult; -import cn.jpush.api.JPushClient; -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.model.Message; -import cn.jpush.api.push.model.Platform; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.push.model.audience.Audience; -import cn.jpush.api.push.model.notification.Notification; - -@Category(SlowTests.class) -public class SpecialCharacterTest extends BaseRemotePushTest { - - public static final char[] SPECIAL_CHARS = new char[] {'`', '~', '!', '@', '#', '$', '%', - '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', - '|', '\\', ':', ';', '"', '\'', '<', '>', ',', '.', '?', '/'}; - - public int sendMessage(String content) { - Message message = Message.newBuilder() - .setMsgContent(content) - .setTitle("title").build(); - - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.alias("special_c")) - .setMessage(message) - .build(); - try { - _client.sendPush(payload); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - return e.getErrorCode(); - } - return 0; - } - - public int sendNotification(String alert) { - PushPayload payload = PushPayload.newBuilder() - .setPlatform(Platform.all()) - .setAudience(Audience.alias("special_c")) - .setNotification(Notification.alert(alert)) - .build(); - try { - _client.sendPush(payload); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - return e.getErrorCode(); - } - return 0; - } - - - @BeforeClass - public static void prepareAudience() throws Exception { - JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY); - DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID3, "special_c", null, null); - assertThat(result.isResultOK(), is(true)); - } - - @Test - public void testCharacters() { - String prefix = "JPush Special Character tests - "; - - for (char c : SPECIAL_CHARS) { - String msgContent = prefix + c; - assertEquals(0, sendNotification(msgContent)); - } - - for (char c : SPECIAL_CHARS) { - String msgContent = prefix + c; - assertEquals(0, sendMessage(msgContent)); - } - - - } -} - - diff --git a/src/test/java/cn/jpush/api/report/ReportFunctionTests.java b/src/test/java/cn/jpush/api/report/ReportFunctionTests.java deleted file mode 100644 index dacf1a8e..00000000 --- a/src/test/java/cn/jpush/api/report/ReportFunctionTests.java +++ /dev/null @@ -1,92 +0,0 @@ -package cn.jpush.api.report; - -import static org.junit.Assert.assertTrue; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.push.model.Message; -import cn.jpush.api.report.model.CheckMessagePayload; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jiguang.common.TimeUnit; -import cn.jpush.api.BaseTest; -import cn.jpush.api.SlowTests; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -@Category(SlowTests.class) -public class ReportFunctionTests extends BaseTest { - - private static final Logger LOG = LoggerFactory.getLogger(ReportFunctionTests.class); - - @Test - public void getReceivedsFixed() throws Exception { - ReceivedsResult result = jpushClient.getReportReceiveds("1613113584,1229760629,1174658841,1174658641"); - assertTrue(result.isResultOK()); - assertTrue(result.received_list.size() > 0); - } - - @Test - public void getReceivedsFixed2() throws Exception { - ReceivedsResult result = jpushClient.getReportReceiveds("1613113584, 1229760629"); - assertTrue(result.isResultOK()); - assertTrue(result.received_list.size() > 0); - } - - public void getMessagesTest() throws Exception { - MessagesResult result = jpushClient.getReportMessages("1613113584"); - assertTrue(result.isResultOK()); - assertTrue(result.messages.size() > 0); - } - - public void getMessagesTest2() throws Exception { - MessagesResult result = jpushClient.getReportMessages("1613113584, ,1229760629, "); - assertTrue(result.isResultOK()); - assertTrue(result.messages.size() > 0); - } - - public void getUsersTest() throws Exception { - UsersResult result = jpushClient.getReportUsers(TimeUnit.MONTH, "2014-05", 1); - assertTrue(result.isResultOK()); - assertTrue(result.items.size() > 0); - } - - public void getUserTest2() throws Exception { - UsersResult result = jpushClient.getReportUsers(TimeUnit.DAY, "2014-05-10", 5); - assertTrue(result.isResultOK()); - assertTrue(result.items.size() > 0); - } - - public void getUserTest3() throws Exception { - UsersResult result = jpushClient.getReportUsers(TimeUnit.HOUR, "2014-05-10 06", 10); - assertTrue(result.isResultOK()); - assertTrue(result.items.size() > 0); - } - - @Test - public void testGetMessageStatus() { - CheckMessagePayload payload = CheckMessagePayload.newBuilder() - .setMsgId(3993287034L) - .addRegistrationIds(REGISTRATION_ID1, REGISTRATION_ID2, REGISTRATION_ID3) - .setDate("2017-08-08") - .build(); - try { - Map map = jpushClient.getMessageStatus(payload); - for (Map.Entry entry : map.entrySet()) { - LOG.info("registrationId: " + entry.getKey() + " status: " + entry.getValue().getStatus()); - } - } catch (APIConnectionException e) { - LOG.error("Connection error. Should retry later. ", e); - } catch (APIRequestException e) { - LOG.error("Error response from JPush server. Should review and fix it. ", e); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - } - } - -} - diff --git a/src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java b/src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java deleted file mode 100644 index 674221ab..00000000 --- a/src/test/java/cn/jpush/api/schedule/ScheduleClientTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package cn.jpush.api.schedule; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import cn.jiguang.common.resp.APIConnectionException; -import cn.jiguang.common.resp.APIRequestException; -import cn.jpush.api.BaseTest; -import cn.jpush.api.SlowTests; -import cn.jpush.api.push.model.PushPayload; -import cn.jpush.api.schedule.model.SchedulePayload; -import cn.jpush.api.schedule.model.TriggerPayload; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * ScheduleClient Tester. - * - * @author liucy - * @version 1.0 - */ - -@Category(SlowTests.class) -public class ScheduleClientTest extends BaseTest { - - protected static final Logger LOG = LoggerFactory.getLogger(ScheduleClientTest.class); - - public static final int NOT_EXIST = 8104; - public static final int AUTH_FAILED = 8101; - public static final int INVALID_PARAM = 8100; - - private ScheduleClient client; - - @Override - public void before() { - client = new ScheduleClient(MASTER_SECRET, APP_KEY); - } - - /** - * Method: getScheduleList(int page) - */ - @Test - public void testGetScheduleList() { - try { - ScheduleListResult result = client.getScheduleList(1); - Assert.assertEquals("", 1, result.page); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - Assert.assertTrue(e.getErrorMessage(), false); - } - } - - - /** - * Method: createSchedule(SchedulePayload payload) - * Method: getSchedule(String scheduleId) - * Method: updateSchedule(String scheduleId, SchedulePayload payload) - * Method: deleteSchedule(String scheduleId) - */ - @Test - public void testScheduleMethods() { - String name = "test_schedule"; - TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime("2105-07-30 12:00:00") - .buildSingle(); - - PushPayload push = PushPayload.alertAll("test schedule"); - - SchedulePayload payload = SchedulePayload.newBuilder() - .setName(name) - .setEnabled(true) - .setTrigger(trigger) - .setPush(push) - .build(); - - SchedulePayload update = SchedulePayload.newBuilder() - .setEnabled(false).build(); - - ScheduleResult result = null; - boolean success = false; - try { - result = client.createSchedule(payload); - Assert.assertNotNull("test createSchedule failed.", result); - - ScheduleResult getResult = client.getSchedule(result.schedule_id); - Assert.assertEquals("test getSchedule failed.", result.name, getResult.name); - - ScheduleResult updateResult = client.updateSchedule(result.schedule_id, update); - Assert.assertEquals("test updateSchedule failed.", false, updateResult.enabled); - - client.deleteSchedule(result.schedule_id); - Assert.assertTrue(true); - success = true; - - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - e.printStackTrace(); - LOG.info("HTTP Status: " + e.getStatus()); - LOG.info("Error Code: " + e.getErrorCode()); - LOG.info("Error Message: " + e.getErrorMessage()); - LOG.info("Msg ID: " + e.getMsgId()); - } finally { - if(!success && null != result) { - try { - client.deleteSchedule(result.schedule_id); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - } - - @Test - public void testGetNotExist() { - try{ - client.getSchedule("test-not-exist"); - } catch (APIConnectionException e) { - e.printStackTrace(); - } catch (APIRequestException e) { - Assert.assertEquals(NOT_EXIST, e.getErrorCode()); - } - } - -} diff --git a/src/test/java/cn/jpush/api/schedule/model/SchedulePayloadTest.java b/src/test/java/cn/jpush/api/schedule/model/SchedulePayloadTest.java deleted file mode 100644 index 0c77d97f..00000000 --- a/src/test/java/cn/jpush/api/schedule/model/SchedulePayloadTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.jpush.api.schedule.model; - -import cn.jpush.api.FastTests; -import cn.jpush.api.push.model.PushPayload; -import com.google.gson.JsonObject; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -/** - * SchedulePayload Tester. - * - * @version 1.0 - */ -@Category(FastTests.class) -public class SchedulePayloadTest { - - @Test - public void testToJson() { - String name = "test_schedule"; - TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime("2015-07-25 12:20:30") - .buildSingle(); - - PushPayload push = PushPayload.alertAll("test schedule"); - SchedulePayload payload = SchedulePayload.newBuilder() - .setName(name) - .setEnabled(true) - .setTrigger(trigger) - .setPush(push) - .build(); - - JsonObject json = new JsonObject(); - json.addProperty("name", name); - json.addProperty("enabled", true); - json.add("trigger", trigger.toJSON()); - json.add("push", push.toJSON()); - - Assert.assertEquals("", json, payload.toJSON()); - } - -} diff --git a/src/test/java/cn/jpush/api/schedule/model/TriggerPayloadTest.java b/src/test/java/cn/jpush/api/schedule/model/TriggerPayloadTest.java deleted file mode 100644 index 4772a32f..00000000 --- a/src/test/java/cn/jpush/api/schedule/model/TriggerPayloadTest.java +++ /dev/null @@ -1,129 +0,0 @@ -package cn.jpush.api.schedule.model; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import cn.jiguang.common.TimeUnit; -import cn.jpush.api.FastTests; - -/** - * TriggerPayload Tester. - * - * @author liucy - * @version 1.0 - */ -@Category(FastTests.class) -public class TriggerPayloadTest { - - /** - * Method: buildSingle() - */ - @Test - public void testBuildSingle() { - String time = "2015-07-30 10:12:23"; - TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime(time) - .buildSingle(); - JsonObject json = new JsonObject(); - JsonObject single = new JsonObject(); - single.addProperty("time", time); - json.add("single", single); - Assert.assertEquals("", json, trigger.toJSON()); - } - - @Test(expected = IllegalArgumentException.class) - public void test_null_time() { - String time = null; - TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime(time) - .buildSingle(); - } - - @Test(expected = IllegalArgumentException.class) - public void test_empty_time() { - String time = ""; - TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime(time) - .buildSingle(); - } - - @Test(expected = IllegalArgumentException.class) - public void test_invalid_time() { - String time = "2015-07-32 10:12:23"; - TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime(time) - .buildSingle(); - } - - @Test(expected = IllegalArgumentException.class) - public void test_incorrect_time_format() { - String time = "2015-07-30T10:12:23"; - TriggerPayload trigger = TriggerPayload.newBuilder() - .setSingleTime(time) - .buildSingle(); - } - - /** - * Method: buildPeriodical() - */ - @Test - public void testBuildPeriodical() { - String start = "2015-07-30 10:12:23"; - String end = "2015-08-30 10:12:23"; - String time = "10:12:00"; - String[] point = {"MON", "TUE"}; - - TriggerPayload trigger = TriggerPayload.newBuilder() - .setPeriodTime(start, end, time) - .setTimeFrequency(TimeUnit.WEEK, 2, point) - .buildPeriodical(); - - JsonObject json = new JsonObject(); - JsonObject periodical = new JsonObject(); - periodical.addProperty("start", start); - periodical.addProperty("end", end); - periodical.addProperty("time", time); - periodical.addProperty("time_unit", TimeUnit.WEEK.name().toLowerCase()); - periodical.addProperty("frequency", 2); - JsonArray array = new JsonArray(); - array.add(new JsonPrimitive("MON")); - array.add(new JsonPrimitive("TUE")); - periodical.add("point", array); - json.add("periodical", periodical); - - Assert.assertEquals("", json, trigger.toJSON()); - - } - - @Test(expected = IllegalArgumentException.class) - public void test_null_start() { - String start = null; - String end = "2015-08-30 10:12:23"; - String time = "10:12:00"; - String[] point = {"MON", "TUE"}; - - TriggerPayload trigger = TriggerPayload.newBuilder() - .setPeriodTime(start, end, time) - .setTimeFrequency(TimeUnit.WEEK, 2, point) - .buildPeriodical(); - } - - @Test(expected = IllegalArgumentException.class) - public void test_empty_end() { - String start = "2015-08-30 10:12:23"; - String end = ""; - String time = "10:12:00"; - String[] point = {"MON", "TUE"}; - - TriggerPayload trigger = TriggerPayload.newBuilder() - .setPeriodTime(start, end, time) - .setTimeFrequency(TimeUnit.WEEK, 2, point) - .buildPeriodical(); - } - -} diff --git a/src/test/resources/jpush-api.conf b/src/test/resources/jpush-api.conf deleted file mode 100644 index 0ae8b07e..00000000 --- a/src/test/resources/jpush-api.conf +++ /dev/null @@ -1,13 +0,0 @@ -# Only info for JPush API demo. No need for running. - - -# This app is only used for API Test. Please don't modify it. -username=jpush_api_client -password=654321 -appKey=dd1066407b044738b6479275 -masterSecret=2b38ce69b1de2a7fa95706ea - -alias=alias_api -tag=tag_api -registrationID=0900e8d85ef - diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties deleted file mode 100644 index 910f3f68..00000000 --- a/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootLogger=DEBUG,CONSOLE - -log4j.logger.org.eclipse.jetty=INFO - -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.Target=System.out -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n