Search in sources :

Example 6 with SwaggerContextService

use of io.swagger.jaxrs.config.SwaggerContextService in project swagger-core by swagger-api.

the class SwaggerContextServiceTest method initConfigViaContextParamSwagger.

@Test(description = "should get correct swagger context set via context param \"swagger\"")
public void initConfigViaContextParamSwagger() {
    stubWithContextSwaggerAttribute();
    Swagger swagger = new SwaggerContextService().withServletConfig(servletConfig1).getSwagger();
    assertEquals("Test Title", swagger.getInfo().getTitle());
//verify(servletConfig1, times(2)).getInitParameter(eq(CONTEXT_ID_KEY));
}
Also used : SwaggerContextService(io.swagger.jaxrs.config.SwaggerContextService) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 7 with SwaggerContextService

use of io.swagger.jaxrs.config.SwaggerContextService in project swagger-core by swagger-api.

the class SwaggerContextServiceTest method initializeAndGetConfigBasedOnPath.

@Test(description = "should add SwaggerConfig to SwaggerConfigLocator map with keys path-based keys")
public void initializeAndGetConfigBasedOnPath() {
    stubWithPathBasedConfigInitParam();
    new SwaggerContextService().withServletConfig(servletConfig1).withBasePath("/url1").initConfig();
    new SwaggerContextService().withServletConfig(servletConfig2).withBasePath("url2").initConfig();
    assertTrue(SwaggerConfigLocator.getInstance().getConfig(CONFIG_ID_PREFIX + "/url1/") instanceof WebXMLReader);
    assertTrue(SwaggerConfigLocator.getInstance().getConfig(CONFIG_ID_PREFIX + "/url2/") instanceof WebXMLReader);
    verify(servletConfig1, times(1)).getInitParameter(eq(USE_PATH_BASED_CONFIG));
    verify(servletConfig2, times(1)).getInitParameter(eq(USE_PATH_BASED_CONFIG));
}
Also used : SwaggerContextService(io.swagger.jaxrs.config.SwaggerContextService) WebXMLReader(io.swagger.jaxrs.config.WebXMLReader) Test(org.testng.annotations.Test)

Example 8 with SwaggerContextService

use of io.swagger.jaxrs.config.SwaggerContextService in project swagger-core by swagger-api.

the class SwaggerContextServiceTest method getScannerWithContextInitParam.

@Test(description = "should call servletContext getAttribute with param SCANNER_ID_PREFIX + \"test.1/2\"")
public void getScannerWithContextInitParam() {
    stubWithContextInitParam();
    Scanner scanner1 = new SwaggerContextService().withServletConfig(servletConfig1).getScanner();
    Scanner scanner2 = new SwaggerContextService().withServletConfig(servletConfig2).getScanner();
    assertEquals(beanConfigScanner1, scanner1);
    assertEquals(beanConfigScanner2, scanner2);
    verify(servletConfig1, times(1)).getInitParameter(eq(SCANNER_ID_KEY));
    verify(servletConfig1, times(2)).getInitParameter(eq(CONTEXT_ID_KEY));
    verify(servletContext1, times(1)).getAttribute(eq(SCANNER_ID_PREFIX + "test.1"));
    verify(servletContext2, never()).getAttribute(eq(SCANNER_ID_PREFIX + "test.1"));
    verify(servletConfig2, times(1)).getInitParameter(eq(SCANNER_ID_KEY));
    verify(servletConfig2, times(2)).getInitParameter(eq(CONTEXT_ID_KEY));
    verify(servletContext2, times(1)).getAttribute(eq(SCANNER_ID_PREFIX + "test.2"));
    verify(servletContext1, never()).getAttribute(eq(SCANNER_ID_PREFIX + "test.2"));
}
Also used : DefaultJaxrsScanner(io.swagger.jaxrs.config.DefaultJaxrsScanner) Scanner(io.swagger.config.Scanner) SwaggerContextService(io.swagger.jaxrs.config.SwaggerContextService) Test(org.testng.annotations.Test)

Aggregations

SwaggerContextService (io.swagger.jaxrs.config.SwaggerContextService)8 Test (org.testng.annotations.Test)6 Scanner (io.swagger.config.Scanner)4 DefaultJaxrsScanner (io.swagger.jaxrs.config.DefaultJaxrsScanner)3 Swagger (io.swagger.models.Swagger)3 SwaggerConfig (io.swagger.config.SwaggerConfig)1 SpecFilter (io.swagger.core.filter.SpecFilter)1 SwaggerSpecFilter (io.swagger.core.filter.SwaggerSpecFilter)1 Reader (io.swagger.jaxrs.Reader)1 JaxrsScanner (io.swagger.jaxrs.config.JaxrsScanner)1 WebXMLReader (io.swagger.jaxrs.config.WebXMLReader)1