diff --git a/.cloudbees/bundles/hello.yaml b/.cloudbees/bundles/hello.yaml new file mode 100644 index 0000000..5fabd15 --- /dev/null +++ b/.cloudbees/bundles/hello.yaml @@ -0,0 +1,17 @@ +bundleApi: 0.1 +config: + cmd: + type: string + default: "echo hello" +workflows: + hello: + source: github.com/fdonze/hello-world-bundle@main + on: + github_push: { } + github_pull_request: { } + config: + go-cmd: ${{ config.cmd }} +resources: + - from: github.com/fdonze/hello-world-bundle/README.md@main + to: / + update: true diff --git a/.cloudbees/workflows/hello/hello.yaml b/.cloudbees/workflows/hello/hello.yaml new file mode 100644 index 0000000..8b03bc8 --- /dev/null +++ b/.cloudbees/workflows/hello/hello.yaml @@ -0,0 +1,22 @@ +workflowApi: 0.1 +"on": + bundle: { } +jobs: + greeter: + steps: + - uses: cloudbees/shell-widget + # the using ref can be: + # a full ref to a git repo, for now we always assume it's on github.com and reserve github.com/ as a prefix + # after the ref we include a : and or an @ + # the : is followed by a branch or tag name + # the @ is followed by the commit hash + # examples: + # cloudbees/shell-widget (the head commit of the default branch) + # cloudbees/shell-widget:v1 (a tag) + # cloudbees/shell-widget:main (a branch) + # cloudbees/shell-widget:main@cafebabedeadbeefcafebabedeadbeef (a commit hash (branch is ignored except for suggesting updates) + # cloudbees/shell-widget@cafebabedeadbeefcafebabedeadbeef (a commit hash no update suggested) + # github.com/cloudbees/shell-widget:v1 (being more specific about where the repo is) + + with: + cmd: echo hello world .... diff --git a/GreetingControllerTests.java b/GreetingControllerTests.java new file mode 100644 index 0000000..6ce07c2 --- /dev/null +++ b/GreetingControllerTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 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. + */ +package com.example.restservice; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +@SpringBootTest +@AutoConfigureMockMvc +public class GreetingControllerTests { + + @Autowired + private MockMvc mockMvc; + + @Test + public void noParamGreetingShouldReturnDefaultMessage() throws Exception { + + this.mockMvc.perform(get("/greeting")).andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.content").value("Hello, World!")); + } + + @Test + public void paramGreetingShouldReturnTailoredMessage() throws Exception { + + this.mockMvc.perform(get("/greeting").param("name", "Spring Community")) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.content").value("Hello, Spring Community!")); + } + +} diff --git a/README.md b/README.md index b086d2c..8313a85 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,2 @@ -[![Build Status](https://buildhive.cloudbees.com/job/fdonze/job/cloudbees-hello/badge/icon)](https://buildhive.cloudbees.com/job/fdonze/job/cloudbees-hello/) - -cloudbees-hello -=============== - -CloudBees hello world application +# Hello World Bundle +This is a hello world bundle diff --git a/copy/MyGreeting.java b/copy/MyGreeting.java new file mode 100644 index 0000000..8f1a778 --- /dev/null +++ b/copy/MyGreeting.java @@ -0,0 +1,20 @@ +package com.example.restservice; + +public class Greeting { + + private final long id; + private final String content; + + public Greeting(long id, String content) { + this.id = id; + this.content = content; + } + + public long getId() { + return id; + } + + public String getContent() { + return content; + } +} diff --git a/res/main/java/com/example/restservice/Greeting.java b/res/main/java/com/example/restservice/Greeting.java new file mode 100644 index 0000000..8f1a778 --- /dev/null +++ b/res/main/java/com/example/restservice/Greeting.java @@ -0,0 +1,20 @@ +package com.example.restservice; + +public class Greeting { + + private final long id; + private final String content; + + public Greeting(long id, String content) { + this.id = id; + this.content = content; + } + + public long getId() { + return id; + } + + public String getContent() { + return content; + } +} diff --git a/res/main/java/com/example/restservice/GreetingController.java b/res/main/java/com/example/restservice/GreetingController.java new file mode 100644 index 0000000..36e3aab --- /dev/null +++ b/res/main/java/com/example/restservice/GreetingController.java @@ -0,0 +1,19 @@ +package com.example.restservice; + +import java.util.concurrent.atomic.AtomicLong; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class GreetingController { + + private static final String template = "Hello, %s!"; + private final AtomicLong counter = new AtomicLong(); + + @GetMapping("/greeting") + public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) { + return new Greeting(counter.incrementAndGet(), String.format(template, name)); + } +} diff --git a/res/main/java/com/example/restservice/RestServiceApplication.java b/res/main/java/com/example/restservice/RestServiceApplication.java new file mode 100644 index 0000000..ebde613 --- /dev/null +++ b/res/main/java/com/example/restservice/RestServiceApplication.java @@ -0,0 +1,13 @@ +package com.example.restservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RestServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(RestServiceApplication.class, args); + } + +} diff --git a/res/test/java/com/example/restservice/GreetingControllerTests.java b/res/test/java/com/example/restservice/GreetingControllerTests.java new file mode 100644 index 0000000..6ce07c2 --- /dev/null +++ b/res/test/java/com/example/restservice/GreetingControllerTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 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. + */ +package com.example.restservice; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +@SpringBootTest +@AutoConfigureMockMvc +public class GreetingControllerTests { + + @Autowired + private MockMvc mockMvc; + + @Test + public void noParamGreetingShouldReturnDefaultMessage() throws Exception { + + this.mockMvc.perform(get("/greeting")).andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.content").value("Hello, World!")); + } + + @Test + public void paramGreetingShouldReturnTailoredMessage() throws Exception { + + this.mockMvc.perform(get("/greeting").param("name", "Spring Community")) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.content").value("Hello, Spring Community!")); + } + +}