Skip to content

Instantly share code, notes, and snippets.

@zpapez
zpapez / IntegrationTest.java
Created November 23, 2020 10:48
WireMock - Asserting exactly one Authorization header
@BeforeAll
public static void beforeAll(@WireMockInstance WireMockServer server1, @WireMockInstance WireMockServer server2) {
zephyrWiremockServer = server1;
slackWiremockServer = server2;
zephyrWiremockServer.addMockServiceRequestListener(new RequestListener() {
@Override
public void requestReceived(Request request, Response response) {
// if we would fail directly here in listener, JUnit error would be really hard to understand (as no response would be generated)
// therefore saving the value to assert it later in main test flow
@zpapez
zpapez / AppIntegrationTestPropertyInitializer.java
Created November 23, 2020 10:31
ContextConfiguration - initializers of properties
class AppIntegrationTestPropertyInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(applicationContext,
"zephyr.api.baseUrl="
+ String.format("%s/jira/rest/zapi/latest",
IntegrationTest.zephyrWiremockServer.baseUrl()));
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(applicationContext,
@zpapez
zpapez / WireMockExtension.java
Created November 23, 2020 10:24
JUnit5 WireMock Extension
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
import com.github.tomakehurst.wiremock.WireMockServer;
@zpapez
zpapez / Controller.java
Last active November 23, 2020 13:51
ControllerAndServiceCallingJiraAndSlack
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor;
@RestController
@RequestMapping("/api/v1")
@RequiredArgsConstructor
public class Controller {
@zpapez
zpapez / SlackFeignClient.java
Last active November 20, 2020 21:05
SlackFeignClient
@FeignClient(name = "Slack", url = "${slack.baseUrl}", configuration = SlackFeignClientConfiguration.class)
public interface SlackFeignClient {
@RequestMapping(
value = "/chat.postMessage",
method = RequestMethod.POST,
consumes = "application/json",
produces = "application/json")
SlackMessageResponseDto postSlackMessage(
@RequestBody(required = true) SlackMessageRequestDto messageRequest);
@zpapez
zpapez / ZephyrFeignClient.java
Created November 20, 2020 20:44
Zephyr Feign Client
@FeignClient(name = "Zephyr", url = "${zephyr.api.baseUrl}", configuration = ZephyrFeignClientConfiguration.class)
public interface ZephyrFeignClient {
@RequestMapping(
value = "/execution",
method = RequestMethod.GET)
ExecutionListResponseDto getListOfExecutions(
@RequestParam(name = "issueId") String issueId);
}
@zpapez
zpapez / template_okta_alb.yml
Last active May 25, 2021 17:07
CloudFormation Template to create AWS Application Load Balancer with OKTA Authentication
AWSTemplateFormatVersion: 2010-09-09
Description: Template to create OKTA auth application load balancer.
Parameters:
CertificateArn:
Type: String
Description: ARN of certificate to use on HTTPS listener
authorizationEndpoint:
Type: String
Description: Okta account endpoint
Default: https://dev-12345.okta.com/oauth2/default/v1/authorize