11161d3e8SAdam Hornacek /* 21161d3e8SAdam Hornacek * CDDL HEADER START 31161d3e8SAdam Hornacek * 41161d3e8SAdam Hornacek * The contents of this file are subject to the terms of the 51161d3e8SAdam Hornacek * Common Development and Distribution License (the "License"). 61161d3e8SAdam Hornacek * You may not use this file except in compliance with the License. 71161d3e8SAdam Hornacek * 81161d3e8SAdam Hornacek * See LICENSE.txt included in this distribution for the specific 91161d3e8SAdam Hornacek * language governing permissions and limitations under the License. 101161d3e8SAdam Hornacek * 111161d3e8SAdam Hornacek * When distributing Covered Code, include this CDDL HEADER in each 121161d3e8SAdam Hornacek * file and include the License file at LICENSE.txt. 131161d3e8SAdam Hornacek * If applicable, add the following below this CDDL HEADER, with the 141161d3e8SAdam Hornacek * fields enclosed by brackets "[]" replaced with your own identifying 151161d3e8SAdam Hornacek * information: Portions Copyright [yyyy] [name of copyright owner] 161161d3e8SAdam Hornacek * 171161d3e8SAdam Hornacek * CDDL HEADER END 181161d3e8SAdam Hornacek */ 191161d3e8SAdam Hornacek 201161d3e8SAdam Hornacek /* 212f7dccc7SAdam Hornacek * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. 221161d3e8SAdam Hornacek */ 23b28a5538SAdam Hornacek package opengrok.auth.plugin.util; 24b28a5538SAdam Hornacek 25aa6abf42SAdam Hornacek import jakarta.ws.rs.POST; 26aa6abf42SAdam Hornacek import jakarta.ws.rs.Path; 27aa6abf42SAdam Hornacek import jakarta.ws.rs.core.Application; 28b28a5538SAdam Hornacek import org.glassfish.jersey.server.ResourceConfig; 29b28a5538SAdam Hornacek import org.glassfish.jersey.test.JerseyTest; 302f7dccc7SAdam Hornacek import org.junit.jupiter.api.AfterEach; 312f7dccc7SAdam Hornacek import org.junit.jupiter.api.BeforeEach; 322f7dccc7SAdam Hornacek import org.junit.jupiter.api.Test; 33b28a5538SAdam Hornacek 34b28a5538SAdam Hornacek import java.util.concurrent.ExecutionException; 35b28a5538SAdam Hornacek import java.util.concurrent.Future; 36b28a5538SAdam Hornacek 37*14bb522cSAdam Hornacek import static org.junit.jupiter.api.Assertions.assertEquals; 38b28a5538SAdam Hornacek 39*14bb522cSAdam Hornacek class WebHookTest extends JerseyTest { 40b28a5538SAdam Hornacek private static final String PREFIX = "service"; 41b28a5538SAdam Hornacek private static int requests; 42b28a5538SAdam Hornacek 43b28a5538SAdam Hornacek @Path(PREFIX) 44b28a5538SAdam Hornacek public static class Service { 45b28a5538SAdam Hornacek @POST handlePost()461161d3e8SAdam Hornacek public String handlePost() { 471161d3e8SAdam Hornacek requests++; 481161d3e8SAdam Hornacek return "posted"; 491161d3e8SAdam Hornacek } 50b28a5538SAdam Hornacek } 51b28a5538SAdam Hornacek 522f7dccc7SAdam Hornacek @BeforeEach setUp()532f7dccc7SAdam Hornacek public void setUp() throws Exception { 542f7dccc7SAdam Hornacek super.setUp(); 552f7dccc7SAdam Hornacek } 562f7dccc7SAdam Hornacek 572f7dccc7SAdam Hornacek @AfterEach tearDown()582f7dccc7SAdam Hornacek public void tearDown() throws Exception { 592f7dccc7SAdam Hornacek super.tearDown(); 602f7dccc7SAdam Hornacek } 612f7dccc7SAdam Hornacek 62b28a5538SAdam Hornacek @Override configure()63b28a5538SAdam Hornacek protected Application configure() { 64b28a5538SAdam Hornacek return new ResourceConfig(Service.class); 65b28a5538SAdam Hornacek } 66b28a5538SAdam Hornacek 67b28a5538SAdam Hornacek @Test testPost()68*14bb522cSAdam Hornacek void testPost() throws ExecutionException, InterruptedException { 69b28a5538SAdam Hornacek assertEquals(0, requests); 70b28a5538SAdam Hornacek WebHook hook = new WebHook(getBaseUri() + PREFIX, "{}"); 71b28a5538SAdam Hornacek Future<String> future = hook.post(); 72b28a5538SAdam Hornacek future.get(); 73b28a5538SAdam Hornacek assertEquals(1, requests); 74b28a5538SAdam Hornacek } 75b28a5538SAdam Hornacek } 76