Commits

Robert Massaioli [Atlassian] committed c105d75

Starting to build all of the components for the plugin.

I want an outline of everything that I want to build and then I will build it.

Comments (0)

Files changed (10)

             <version>1.8.5</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.1.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>jsr311-api</artifactId>
+            <version>1.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.xml.bind</groupId>
+            <artifactId>jaxb-api</artifactId>
+            <version>2.2.7</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.plugins.rest</groupId>
+            <artifactId>atlassian-rest-common</artifactId>
+            <version>${rest.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.sal</groupId>
+            <artifactId>sal-api</artifactId>
+            <version>2.6.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.wink</groupId>
+            <artifactId>wink-client</artifactId>
+            <version>1.1.3-incubating</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
     <properties>
         <jira.version>5.0</jira.version>
         <amps.version>3.10.4</amps.version>
+        <rest.version>2.7.2</rest.version>
     </properties>
 </project>

src/main/java/com/atlassian/jira/extension/jira/webwork/PingMeAction.java

+package com.atlassian.jira.extension.jira.webwork;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.atlassian.jira.web.action.JiraWebActionSupport;
+
+public class PingMeAction extends JiraWebActionSupport
+{
+    private static final Logger log = LoggerFactory.getLogger(PingMeAction.class);
+
+    @Override
+    public String execute() throws Exception {
+
+        return super.execute();
+    }
+}

src/main/java/com/atlassian/jira/extension/rest/PingMeRestResource.java

+package com.atlassian.jira.extension.rest;
+
+import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * A resource of message.
+ */
+@Path("/message")
+public class PingMeRestResource {
+
+    @GET
+    @AnonymousAllowed
+    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public Response getMessage()
+    {
+       return Response.ok(new PingMeRestResourceModel("Hello World")).build();
+    }
+}

src/main/java/com/atlassian/jira/extension/rest/PingMeRestResourceModel.java

+package com.atlassian.jira.extension.rest;
+
+import javax.xml.bind.annotation.*;
+@XmlRootElement(name = "message")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PingMeRestResourceModel {
+
+    @XmlElement(name = "value")
+    private String message;
+
+    public PingMeRestResourceModel() {
+    }
+
+    public PingMeRestResourceModel(String message) {
+        this.message = message;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}

src/main/resources/atlassian-plugin.xml

 
   <web-item name="PingMeAction" i18n-name-key="ping-me-action.name" key="ping-me-action" section="operations-top-level" weight="1000">
     <description key="ping-me-action.description">The PingMeAction Plugin</description>
-    <label key="ping-me-action.label"></label>
-    <link linkId="ping-me-action-link">/secure/PingMe!default.jspa</link>
+    <label key="ping-me-action.label"/>
+    <link linkId="ping-me-action-link">/secure/PingMeAction!default.jspa</link>
   </web-item>
+
+  <webwork1 key="ping-me-action" name="PingMe Action" i18n-name-key="ping-me-action.name">
+    <description key="ping-me-action.description">The PingMe Action Plugin</description>
+    <actions>
+      <action name="com.atlassian.jira.extension.jira.webwork.PingMeAction" alias="PingMeAction">
+        <view name="success">/templates/ping-me-action/pingmeaction/success.vm</view>
+      </action>
+    </actions>
+  </webwork1>
+
+  <rest name="Ping Me Rest Resource" i18n-name-key="ping-me-rest-resource.name" key="ping-me-rest-resource" path="/pingme" version="1.0">
+    <description key="ping-me-rest-resource.description">The Ping Me Rest Resource Plugin</description>
+  </rest>
 </atlassian-plugin>

src/main/resources/com/atlassian/jira/extension/pingme.properties

 ping-me-action.label=Ping Me
 ping-me-action.name=Ping Me
 ping-me-action.description=The PingMe Button
+
+ping-me-rest-resource.name=Ping Me Rest Resource
+ping-me-rest-resource.description=The Ping Me Rest Resource Plugin

src/main/resources/templates/ping-me-action/pingmeaction/success.vm

+<html>
+    <head>
+        <title>$i18n.getText('ping-me-action.name')</title>
+    </head>
+
+    <body>
+        <h1>Ping Me Plugin for JIRA</h1>
+    </body>
+</html>

src/test/java/com/atlassian/jira/extension/jira/webwork/PingMeActionTest.java

+package com.atlassian.jira.extension.jira.webwork;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import com.atlassian.jira.extension.jira.webwork.PingMeAction;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @since 3.5
+ */
+public class PingMeActionTest {
+
+    @Before
+    public void setup() {
+
+    }
+
+    @After
+    public void tearDown() {
+
+    }
+
+    @Test(expected=Exception.class)
+    public void testSomething() throws Exception {
+        //PingMeAction testClass = new PingMeAction();
+
+        throw new Exception("PingMeAction has no tests!");
+    }
+}

src/test/java/com/atlassian/jira/extension/rest/PingMeRestResourceTest.java

+package com.atlassian.jira.extension.rest;
+
+import org.junit.Test;
+import org.junit.After;
+import org.junit.Before;
+import org.mockito.Mockito;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+import com.atlassian.jira.extension.rest.PingMeRestResource;
+import com.atlassian.jira.extension.rest.PingMeRestResourceModel;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.GenericEntity;
+
+public class PingMeRestResourceTest {
+
+    @Before
+    public void setup() {
+
+    }
+
+    @After
+    public void tearDown() {
+
+    }
+
+    @Test
+    public void messageIsValid() {
+        PingMeRestResource resource = new PingMeRestResource();
+
+        Response response = resource.getMessage();
+        final PingMeRestResourceModel message = (PingMeRestResourceModel) response.getEntity();
+
+        assertEquals("wrong message","Hello World",message.getMessage());
+    }
+}

src/test/java/it/com/atlassian/jira/extension/rest/PingMeRestResourceFuncTest.java

+package it.com.atlassian.jira.extension.rest;
+
+import org.junit.Test;
+import org.junit.After;
+import org.junit.Before;
+import org.mockito.Mockito;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+import com.atlassian.jira.extension.rest.PingMeRestResource;
+import com.atlassian.jira.extension.rest.PingMeRestResourceModel;
+import org.apache.wink.client.Resource;
+import org.apache.wink.client.RestClient;
+
+public class PingMeRestResourceFuncTest {
+
+    @Before
+    public void setup() {
+
+    }
+
+    @After
+    public void tearDown() {
+
+    }
+
+    @Test
+    public void messageIsValid() {
+
+        String baseUrl = System.getProperty("baseurl");
+        String resourceUrl = baseUrl + "/rest/pingme/1.0/message";
+
+        RestClient client = new RestClient();
+        Resource resource = client.resource(resourceUrl);
+
+        PingMeRestResourceModel message = resource.get(PingMeRestResourceModel.class);
+
+        assertEquals("wrong message","Hello World",message.getMessage());
+    }
+}