1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. 22 */ 23 package opengrok.auth.plugin.util; 24 25 import jakarta.ws.rs.POST; 26 import jakarta.ws.rs.Path; 27 import jakarta.ws.rs.core.Application; 28 import org.glassfish.jersey.server.ResourceConfig; 29 import org.glassfish.jersey.test.JerseyTest; 30 import org.junit.jupiter.api.AfterEach; 31 import org.junit.jupiter.api.BeforeEach; 32 import org.junit.jupiter.api.Test; 33 34 import java.util.concurrent.ExecutionException; 35 import java.util.concurrent.Future; 36 37 import static org.junit.jupiter.api.Assertions.assertEquals; 38 39 class WebHookTest extends JerseyTest { 40 private static final String PREFIX = "service"; 41 private static int requests; 42 43 @Path(PREFIX) 44 public static class Service { 45 @POST handlePost()46 public String handlePost() { 47 requests++; 48 return "posted"; 49 } 50 } 51 52 @BeforeEach setUp()53 public void setUp() throws Exception { 54 super.setUp(); 55 } 56 57 @AfterEach tearDown()58 public void tearDown() throws Exception { 59 super.tearDown(); 60 } 61 62 @Override configure()63 protected Application configure() { 64 return new ResourceConfig(Service.class); 65 } 66 67 @Test testPost()68 void testPost() throws ExecutionException, InterruptedException { 69 assertEquals(0, requests); 70 WebHook hook = new WebHook(getBaseUri() + PREFIX, "{}"); 71 Future<String> future = hook.post(); 72 future.get(); 73 assertEquals(1, requests); 74 } 75 } 76