Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .cloudbees/bundles/hello.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions .cloudbees/workflows/hello/hello.yaml
Original file line number Diff line number Diff line change
@@ -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 ....
52 changes: 52 additions & 0 deletions GreetingControllerTests.java
Original file line number Diff line number Diff line change
@@ -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!"));
}

}
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions copy/MyGreeting.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 20 additions & 0 deletions res/main/java/com/example/restservice/Greeting.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions res/main/java/com/example/restservice/GreetingController.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
13 changes: 13 additions & 0 deletions res/main/java/com/example/restservice/RestServiceApplication.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
52 changes: 52 additions & 0 deletions res/test/java/com/example/restservice/GreetingControllerTests.java
Original file line number Diff line number Diff line change
@@ -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!"));
}

}