Skip to content

Commit

Permalink
test compatibility fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
gracekarina committed Jul 1, 2023
1 parent 5c6b141 commit d2ca690
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import mockit.*;
import org.testng.annotations.Test;

import java.util.Map;

import static org.testng.Assert.assertEquals;

public class ComponentsProcessorTest {

Expand Down Expand Up @@ -42,82 +40,73 @@ public class ComponentsProcessorTest {
@Mocked
SecuritySchemeProcessor securitySchemeProcessor;

@Injectable
Schema model1;

@Injectable
Schema model2;

@Injectable
ResolverCache cache;

@Injectable
boolean openapi31;

@Test
public void testComponentsSchemasProcessor(@Injectable final Schema model1,
@Injectable final Schema model2,
@Injectable final ResolverCache cache) throws Exception {
@Injectable OpenAPI openAPI;



@Test
public void testComponentsSchemasProcessor() throws Exception {
final OpenAPI openAPI = new OpenAPI();
openAPI.components(new Components().addSchemas("foo", model1));
openAPI.getComponents().addSchemas("bar", model2);



new Expectations() {{

new SchemaProcessor(cache, openAPI, openapi31);
times = 1;
result = schemaProcessor;


schemaProcessor.processSchema((Schema) any);
times = 2;
}};

new ComponentsProcessor(openAPI,cache, openapi31).processComponents();



new Verifications() {{
schemaProcessor.processSchema(model1);
schemaProcessor.processSchema(model2);
}};
}

@Test
public void testNoComponentsDefined(@Injectable final OpenAPI openAPI,
@Injectable final ResolverCache cache) throws Exception {

public void testNoComponentsDefined() throws Exception {

new Expectations() {{
new SchemaProcessor(cache, openAPI, openapi31);
times = 1;
result = schemaProcessor;

new ResponseProcessor(cache, openAPI, openapi31);
times = 1;
result = responseProcessor;

new RequestBodyProcessor(cache, openAPI, openapi31);
times = 1;
result = requestBodyProcessor;

new ParameterProcessor( cache, openAPI, openapi31);
times = 1;
result = parameterProcessor;

new HeaderProcessor(cache, openAPI, openapi31);
times = 1;
result = headerProcessor;

new ExampleProcessor(cache, openAPI);
times = 1;
result = exampleProcessor;

new LinkProcessor(cache, openAPI, openapi31);
times = 1;
result = linkProcessor;

new CallbackProcessor(cache, openAPI, openapi31);
times = 1;
result = callbackProcessor;

new SecuritySchemeProcessor(cache, openAPI);
times = 1;
result = securitySchemeProcessor;

openAPI.getComponents();
times = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public class ExternalRefProcessorTest {
@Injectable
OpenAPI openAPI;

@Injectable Schema mockedModel;

@Test
public void testProcessRefToExternalDefinition_NoNameConflict(
@Injectable final Schema mockedModel) throws Exception {
public void testProcessRefToExternalDefinition_NoNameConflict() throws Exception {

final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
final RefFormat refFormat = RefFormat.URL;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void testProcessRefToExternalDefinition_NoNameConflict(


@Test
public void testNestedExternalRefs(@Injectable final Schema mockedModel){
public void testNestedExternalRefs(){
final RefFormat refFormat = RefFormat.URL;

//Swagger test instance
Expand Down Expand Up @@ -150,7 +151,7 @@ public void testNestedExternalRefs(@Injectable final Schema mockedModel){


@Test
public void testRelativeRefIncludingUrlRef(@Injectable final Schema mockedModel)
public void testRelativeRefIncludingUrlRef()
throws Exception {
final RefFormat refFormat = RefFormat.RELATIVE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,26 @@ public class ParameterProcessorTest {
@Injectable
boolean openapi31;

@Injectable
HeaderParameter headerParameter;

@Injectable
QueryParameter queryParameter;

@Injectable
CookieParameter cookieParameter;

@Injectable
PathParameter pathParameter;

@Injectable
HeaderParameter resolvedHeaderParam;

@Injectable
Schema bodyParamSchema;

@Test
public void testProcessParameters_TypesThatAreNotRefOrBody(@Injectable final HeaderParameter headerParameter,
@Injectable final QueryParameter queryParameter,
@Injectable final CookieParameter cookieParameter,
@Injectable final PathParameter pathParameter) throws Exception {
public void testProcessParameters_TypesThatAreNotRefOrBody() throws Exception {
expectedModelProcessorCreation();
new Expectations() {
{
Expand Down Expand Up @@ -89,7 +104,7 @@ public void testProcessParameters_TypesThatAreNotRefOrBody(@Injectable final Hea
}

@Test
public void testProcessParameters_RefToHeader(@Injectable final HeaderParameter resolvedHeaderParam) throws Exception {
public void testProcessParameters_RefToHeader() throws Exception {
expectedModelProcessorCreation();

final String ref = "#/components/parameters/foo";
Expand Down Expand Up @@ -122,30 +137,21 @@ private void expectLoadingRefFromCache(final String ref, final RefFormat refForm
}};
}

private void expectLoadingRefFromCache(final String ref, final RefFormat refFormat,
final RequestBody resolvedParam) {
new Expectations() {{
/*cache.loadRef(ref, refFormat, RequestBody.class);
times = 1;
result = resolvedParam;*/
}};
}

@Test
public void testProcessParameters_BodyParameter(@Injectable final Schema bodyParamSchema) throws Exception {
public void testProcessParameters_BodyParameter() throws Exception {

expectedModelProcessorCreation();

RequestBody bodyParameter = new RequestBody().content(new Content().addMediaType("*/*",new MediaType().schema(bodyParamSchema)));

expectModelProcessorInvoked(bodyParamSchema);
expectModelProcessorInvoked(bodyParamSchema);

new RequestBodyProcessor(cache, openAPI, openapi31).processRequestBody(bodyParameter);

new FullVerifications(){{}};
}

private void expectModelProcessorInvoked(@Injectable final Schema bodyParamSchema) {
private void expectModelProcessorInvoked(Schema bodyParamSchema) {
new Expectations(){{
modelProcessor.processSchema(bodyParamSchema); times=1;
}};
Expand All @@ -156,7 +162,6 @@ private void expectedModelProcessorCreation() {
new Expectations() {{
new SchemaProcessor(cache, openAPI, openapi31);
times = 1;
result = modelProcessor;
}};
}
}
Loading

0 comments on commit d2ca690

Please sign in to comment.