forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 758 root resource (OpenAPITools#771)
* Unit-Test for JavaJAXRSSpecServerCodegen. * Path generation for primary resource fixed. * Unit test for toApiName. * Review-Feedback: blank line removed.
- Loading branch information
Showing
2 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...tor/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.openapitools.codegen.java.jaxrs; | ||
|
||
import io.swagger.v3.oas.models.Operation; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openapitools.codegen.CodegenOperation; | ||
import org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Unit-Test for {@link org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen}. | ||
* | ||
* @author attrobit | ||
*/ | ||
public class JavaJAXRSSpecServerCodegenTest { | ||
|
||
private JavaJAXRSSpecServerCodegen instance; | ||
|
||
@Before | ||
public void before() { | ||
instance = new JavaJAXRSSpecServerCodegen(); | ||
} | ||
|
||
/** | ||
* Test | ||
* {@link JavaJAXRSSpecServerCodegen#addOperationToGroup(String, String, Operation, CodegenOperation, Map)} for Resource with path "/" and set tag. | ||
*/ | ||
@Test | ||
public void testAddOperationToGroupForRootResource() { | ||
CodegenOperation codegenOperation = new CodegenOperation(); | ||
codegenOperation.operationId = "findPrimaryresource"; | ||
Operation operation = new Operation(); | ||
Map<String, List<CodegenOperation>> operationList = new HashMap<>(); | ||
|
||
instance.addOperationToGroup("Primaryresource", "/", operation, codegenOperation, operationList); | ||
|
||
assertThat(operationList.size(), is(1)); | ||
assertThat(operationList.containsKey(""), is(true)); | ||
assertThat(codegenOperation.baseName, is("Primaryresource")); | ||
} | ||
|
||
/** | ||
* Test | ||
* {@link JavaJAXRSSpecServerCodegen#addOperationToGroup(String, String, Operation, CodegenOperation, Map)} for Resource with path param. | ||
*/ | ||
@Test | ||
public void testAddOperationToGroupForRootResourcePathParam() { | ||
CodegenOperation codegenOperation = new CodegenOperation(); | ||
codegenOperation.operationId = "getPrimaryresource"; | ||
Operation operation = new Operation(); | ||
Map<String, List<CodegenOperation>> operationList = new HashMap<>(); | ||
|
||
instance.addOperationToGroup("Primaryresource", "/{uuid}", operation, codegenOperation, operationList); | ||
|
||
assertThat(operationList.size(), is(1)); | ||
assertThat(operationList.containsKey(""), is(true)); | ||
assertThat(codegenOperation.baseName, is("Primaryresource")); | ||
} | ||
|
||
/** | ||
* Test | ||
* {@link JavaJAXRSSpecServerCodegen#addOperationToGroup(String, String, | ||
* Operation, CodegenOperation, Map)} for Resource with path "/subresource". | ||
*/ | ||
@Test | ||
public void testAddOperationToGroupForSubresource() { | ||
CodegenOperation codegenOperation = new CodegenOperation(); | ||
codegenOperation.path = "/subresource"; | ||
Operation operation = new Operation(); | ||
Map<String, List<CodegenOperation>> operationList = new HashMap<>(); | ||
|
||
instance.addOperationToGroup("Default", "/subresource", operation, codegenOperation, operationList); | ||
|
||
assertThat(codegenOperation.baseName, is("subresource")); | ||
assertThat(operationList.size(), is(1)); | ||
assertThat(operationList.containsKey("subresource"), is(true)); | ||
} | ||
|
||
/** | ||
* Test {@link JavaJAXRSSpecServerCodegen#toApiName(String)} with subresource. | ||
*/ | ||
@Test | ||
public void testToApiNameForSubresource() { | ||
final String subresource = instance.toApiName("subresource"); | ||
assertThat(subresource, is("SubresourceApi")); | ||
} | ||
|
||
/** | ||
* Test {@link JavaJAXRSSpecServerCodegen#toApiName(String)} with primary resource. | ||
*/ | ||
@Test | ||
public void testToApiNameForPrimaryResource() { | ||
CodegenOperation codegenOperation = new CodegenOperation(); | ||
codegenOperation.operationId = "findPrimaryresource"; | ||
Operation operation = new Operation(); | ||
Map<String, List<CodegenOperation>> operationList = new HashMap<>(); | ||
instance.addOperationToGroup("Primaryresource", "/", operation, codegenOperation, operationList); | ||
|
||
final String subresource = instance.toApiName(""); | ||
assertThat(subresource, is("PrimaryresourceApi")); | ||
} | ||
} |