Skip to content

Commit

Permalink
Merge 25c5704 into a93cfd8
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandella committed Jun 28, 2015
2 parents a93cfd8 + 25c5704 commit 489b2be
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ jdk:
- openjdk7
- oraclejdk7
- oraclejdk8

after_success:
- mvn clean cobertura:cobertura coveralls:report
1 change: 1 addition & 0 deletions phabricator-plugin.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
Expand Down
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,43 @@
<artifactId>cobertura</artifactId>
<version>1.9.6</version>
</dependency>

<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>3.1.0</version>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
<!-- aggregated reports for multi-module projects -->
<aggregate>true</aggregate>
</configuration>
</plugin>
</plugins>
</build>

<scm>
<connection>scm:git:ssh://github.com/jenkinsci/phabricator-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/phabricator-plugin.git</developerConnection>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) 2015 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package com.uber.jenkins.phabricator.conduit;

import hudson.Launcher;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class ArcanistClientTest {
@Rule
public JenkinsRule j = new JenkinsRule();

Map<String, String> emptyParams = new HashMap<String, String>();

@Test
public void testEcho() throws Exception {
ArcanistClient client = new ArcanistClient("echo", "hello", emptyParams, null);

int result = client.callConduit(getLauncher().launch(), System.err);
assertEquals(result, 0);
}

@Test
public void testEchoWithToken() throws Exception {
ArcanistClient client = new ArcanistClient("echo", "tokentest", emptyParams, "notarealtoken");

int result = client.callConduit(getLauncher().launch(), System.err);
assertEquals(result, 0);
}

@Test
public void testParseConduit() throws Exception {
String jsonString = "{\"hello\": \"world\"}";
ArcanistClient client = new ArcanistClient("echo", jsonString, emptyParams, null);

JSONObject result = client.parseConduit(getLauncher().launch(), System.err);
assertTrue(result.has("hello"));
assertEquals(result.getString("hello"), "world");
}

@Test(expected = ArcanistUsageException.class)
public void testNonZeroExitCode() throws Exception {
ArcanistClient client = new ArcanistClient("false", "", emptyParams, null);

client.parseConduit(getLauncher().launch(), System.err);
}

@Test(expected = JSONException.class)
public void testNonJsonOutput() throws Exception {
ArcanistClient client = new ArcanistClient("echo", "not-json", emptyParams, null);
client.parseConduit(getLauncher().launch(), System.err);
}

private Launcher getLauncher() {
return j.createLocalLauncher();
}
}

0 comments on commit 489b2be

Please sign in to comment.