Commit e25c2acb authored by Adrien's avatar Adrien
Browse files

refactor twitter connector and run test with java 11

parent 61dcbdc4
......@@ -5,3 +5,4 @@ target
bin
*.iml
.idea/
*.DS_Store
\ No newline at end of file
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* 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/0.4.2/maven-wrapper-0.4.2.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 direcrory '" + 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 {
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();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
\ No newline at end of file
timestamps {
ansiColor('xterm') {
node {
stage('Setup') {
checkout scm
}
stage('Build') {
try {
if(env.BRANCH_NAME.equals('master')){
sh "./mvnw -B clean deploy -DaltDeploymentRepository=${env.ALT_DEPLOYMENT_REPOSITORY_SNAPSHOTS} -Djvm=${env.JAVA_HOME_11}/bin/java"
}else{
sh "./mvnw -B clean verify -Djvm=${env.JAVA_HOME_11}/bin/java"
}
archiveArtifacts 'target/bonita-connector-twitter-*.zip'
} finally {
junit '**/target/*-reports/*.xml'
}
}
}
}
}
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bonita-connector-twitter</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>1.1.0</version>
</parent>
<artifactId>bonita-connector-twitter-common</artifactId>
<version>1.1.0</version>
<dependencies>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.2</version>
</dependency>
</dependencies>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bonita-connector-twitter</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>1.1.0</version>
</parent>
<artifactId>bonita-connector-twitter-direct-def</artifactId>
<version>1.0.0</version>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bonita-connector-twitter</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>1.1.0</version>
</parent>
<artifactId>bonita-connector-twitter-direct-impl</artifactId>
<version>1.1.0</version>
<properties>
<definition.version>1.0.0</definition.version>
</properties>
<dependencies>
<dependency>
<artifactId>bonita-connector-twitter-direct-def</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>${definition.version}</version>
</dependency>
<dependency>
<artifactId>bonita-connector-twitter-common</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
/**
* Copyright (C) 2002 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.connectors.twitter.test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bonitasoft.connectors.twitter.TwitterConnector;
import org.bonitasoft.engine.connector.Connector;
import org.bonitasoft.engine.connector.ConnectorValidationException;
import org.bonitasoft.engine.exception.BonitaException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public abstract class TwitterConnectorTest {
protected static final Logger LOG = Logger.getLogger(TwitterConnectorTest.class.getName());
@Before
public void initialize() throws Exception {
if (TwitterConnectorTest.LOG.isLoggable(Level.WARNING)) {
TwitterConnectorTest.LOG.warning("======== Starting test: " + this.getClass().getName() + "() ==========");
}
}
@After
public void addLogEnding() throws Exception {
if (TwitterConnectorTest.LOG.isLoggable(Level.WARNING)) {
TwitterConnectorTest.LOG.warning("======== Ending test: " + this.getClass().getName() + " ==========");
}
}
protected abstract Class<? extends Connector> getConnectorClass();
//
// @Test(expected = ConnectorValidationException.class)
// public void validateConnector() throws BonitaException {
// Connector.validate();
// Assert.assertTrue(Connector.validateConnector(getConnectorClass())
// .isEmpty())
// assertTrue();
// }
@Test(expected = ConnectorValidationException.class)
public void setWrappedSmtpPortWithLessThanRange() throws BonitaException {
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("proxyHost", "");
parameters.put("proxyPort", -1);
final TwitterConnector connector = getTwitterConnector(parameters);
connector.validateInputParameters();
}
@Test(expected = ConnectorValidationException.class)
public void setWrappedSmtpPortWithGreaterThanRange() throws BonitaException {
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("proxyHost", "");
parameters.put("proxyPort", 65536);
final TwitterConnector connector = getTwitterConnector(parameters);
connector.validateInputParameters();
}
@Test(expected = ConnectorValidationException.class)
public void setSmtpPortWithLessThanRange() throws BonitaException {
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("proxyPort", -1);
parameters.put("proxyHost", "");
final TwitterConnector connector = getTwitterConnector(parameters);
connector.validateInputParameters();
}
@Test(expected = ConnectorValidationException.class)
public void setSmtpPortWithGreaterThanRange() throws BonitaException {
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("proxyPort", 65536);
parameters.put("proxyHost", "");
final TwitterConnector connector = getTwitterConnector(parameters);
connector.validateInputParameters();
}
@Ignore
@Test
public void execute() {
final Map<String, Object> emptyMap = Collections.emptyMap();
final TwitterConnector connector = getTwitterConnector(emptyMap);
try {
connector.execute();
} catch (final Exception e) {
e.printStackTrace();
Assert.fail("Impossible! A Tweet must be sent");
}
}
public Map<String, Object> getTwitterConnectorParameters() {
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("consumerKey", "zerzer");
parameters.put("consumerSecret", "mljpoi");
parameters.put("accesToken", "7MyWkyU2RuQxeNGTqn8AItTWuAIb9juhN3mhgBmUKn8");
parameters.put("accessTokenSecret", "zTf1uz5RZR9XmuAdPnMwk4PfnLRoI1o4gyNU7wSlQ");
parameters.put("status", "poafjaofj");
parameters.put("proxyHost", "myproxy.bonitasoft.com");
parameters.put("proxyPort", 8080);
return parameters;
}
public abstract TwitterConnector getTwitterConnector(Map<String, Object> parameters);
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bonita-connector-twitter</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>1.1.0</version>
</parent>
<artifactId>bonita-connector-twitter-update-def</artifactId>
<version>1.0.0</version>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bonita-connector-twitter</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>1.1.0</version>
</parent>
<artifactId>bonita-connector-twitter-update-impl</artifactId>
<version>1.1.0</version>
<properties>
<definition.version>1.0.0</definition.version>
</properties>
<dependencies>
<dependency>
<artifactId>bonita-connector-twitter-update-def</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>${definition.version}</version>
</dependency>
<dependency>
<artifactId>bonita-connector-twitter-common</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>all</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>target/classes</directory>
<includes>
<include>*.*</include>
<include>/classpath</include>
</includes>
</fileSet>
<fileSet>
<outputDirectory>/classpath</outputDirectory>
<directory>${basedir}/target</directory>
<includes>
<include>*-sources.jar</include>
</includes>
</fileSet>
<fileSet>
<outputDirectory>/classpath</outputDirectory>
<directory>${basedir}/target</directory>
<includes>
<include>*:jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<outputDirectory>/classpath</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
\ No newline at end of file
timestamps {
node {
stage('Setup') {
checkout scm
}
stage('Release') {
withCredentials([usernamePassword(
credentialsId: 'github',
passwordVariable: 'GIT_PASSWORD',
usernameVariable: 'GIT_USERNAME')]) {
sh """
./mvnw -B release:prepare release:perform -Darguments="-DaltDeploymentRepository=${env.ALT_DEPLOYMENT_REPOSITORY_TAG} -Djvm=${env.JAVA_HOME_11}/bin/java"
"""
}
}
}
}
\ No newline at end of file
#!/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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 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)`"
# TODO classpath?
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.