|
| 1 | +package org.openapitools.codegen.java.jaxrs; |
| 2 | + |
| 3 | +import io.swagger.v3.oas.models.Operation; |
| 4 | +import org.junit.Before; |
| 5 | +import org.junit.Test; |
| 6 | +import org.openapitools.codegen.CodegenOperation; |
| 7 | +import org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen; |
| 8 | + |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.List; |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +import static org.hamcrest.CoreMatchers.is; |
| 14 | +import static org.junit.Assert.assertThat; |
| 15 | + |
| 16 | +/** |
| 17 | + * Unit-Test for {@link org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen}. |
| 18 | + * |
| 19 | + * @author attrobit |
| 20 | + */ |
| 21 | +public class JavaJAXRSSpecServerCodegenTest { |
| 22 | + |
| 23 | + private JavaJAXRSSpecServerCodegen instance; |
| 24 | + |
| 25 | + @Before |
| 26 | + public void before() { |
| 27 | + instance = new JavaJAXRSSpecServerCodegen(); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Test |
| 32 | + * {@link JavaJAXRSSpecServerCodegen#addOperationToGroup(String, String, Operation, CodegenOperation, Map)} for Resource with path "/" and set tag. |
| 33 | + */ |
| 34 | + @Test |
| 35 | + public void testAddOperationToGroupForRootResource() { |
| 36 | + CodegenOperation codegenOperation = new CodegenOperation(); |
| 37 | + codegenOperation.operationId = "findPrimaryresource"; |
| 38 | + Operation operation = new Operation(); |
| 39 | + Map<String, List<CodegenOperation>> operationList = new HashMap<>(); |
| 40 | + |
| 41 | + instance.addOperationToGroup("Primaryresource", "/", operation, codegenOperation, operationList); |
| 42 | + |
| 43 | + assertThat(operationList.size(), is(1)); |
| 44 | + assertThat(operationList.containsKey(""), is(true)); |
| 45 | + assertThat(codegenOperation.baseName, is("Primaryresource")); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Test |
| 50 | + * {@link JavaJAXRSSpecServerCodegen#addOperationToGroup(String, String, Operation, CodegenOperation, Map)} for Resource with path param. |
| 51 | + */ |
| 52 | + @Test |
| 53 | + public void testAddOperationToGroupForRootResourcePathParam() { |
| 54 | + CodegenOperation codegenOperation = new CodegenOperation(); |
| 55 | + codegenOperation.operationId = "getPrimaryresource"; |
| 56 | + Operation operation = new Operation(); |
| 57 | + Map<String, List<CodegenOperation>> operationList = new HashMap<>(); |
| 58 | + |
| 59 | + instance.addOperationToGroup("Primaryresource", "/{uuid}", operation, codegenOperation, operationList); |
| 60 | + |
| 61 | + assertThat(operationList.size(), is(1)); |
| 62 | + assertThat(operationList.containsKey(""), is(true)); |
| 63 | + assertThat(codegenOperation.baseName, is("Primaryresource")); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Test |
| 68 | + * {@link JavaJAXRSSpecServerCodegen#addOperationToGroup(String, String, |
| 69 | + * Operation, CodegenOperation, Map)} for Resource with path "/subresource". |
| 70 | + */ |
| 71 | + @Test |
| 72 | + public void testAddOperationToGroupForSubresource() { |
| 73 | + CodegenOperation codegenOperation = new CodegenOperation(); |
| 74 | + codegenOperation.path = "/subresource"; |
| 75 | + Operation operation = new Operation(); |
| 76 | + Map<String, List<CodegenOperation>> operationList = new HashMap<>(); |
| 77 | + |
| 78 | + instance.addOperationToGroup("Default", "/subresource", operation, codegenOperation, operationList); |
| 79 | + |
| 80 | + assertThat(codegenOperation.baseName, is("subresource")); |
| 81 | + assertThat(operationList.size(), is(1)); |
| 82 | + assertThat(operationList.containsKey("subresource"), is(true)); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Test {@link JavaJAXRSSpecServerCodegen#toApiName(String)} with subresource. |
| 87 | + */ |
| 88 | + @Test |
| 89 | + public void testToApiNameForSubresource() { |
| 90 | + final String subresource = instance.toApiName("subresource"); |
| 91 | + assertThat(subresource, is("SubresourceApi")); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Test {@link JavaJAXRSSpecServerCodegen#toApiName(String)} with primary resource. |
| 96 | + */ |
| 97 | + @Test |
| 98 | + public void testToApiNameForPrimaryResource() { |
| 99 | + CodegenOperation codegenOperation = new CodegenOperation(); |
| 100 | + codegenOperation.operationId = "findPrimaryresource"; |
| 101 | + Operation operation = new Operation(); |
| 102 | + Map<String, List<CodegenOperation>> operationList = new HashMap<>(); |
| 103 | + instance.addOperationToGroup("Primaryresource", "/", operation, codegenOperation, operationList); |
| 104 | + |
| 105 | + final String subresource = instance.toApiName(""); |
| 106 | + assertThat(subresource, is("PrimaryresourceApi")); |
| 107 | + } |
| 108 | +} |
0 commit comments