use of io.swagger.config.Scanner in project swagger-core by swagger-api.
the class SwaggerContextServiceTest method initializeAndGetScannerWithoutServletConfig.
@Test(description = "should add scanner to ScannerFactory")
public void initializeAndGetScannerWithoutServletConfig() {
new SwaggerContextService().initScanner();
new SwaggerContextService().initScanner();
verify(servletConfig1, never()).getInitParameter(eq(SCANNER_ID_KEY));
verify(servletContext1, never()).setAttribute(eq(SCANNER_ID_DEFAULT), any(Scanner.class));
verify(servletContext1, never()).setAttribute(eq(SCANNER_ID_PREFIX + "test.1"), any(Scanner.class));
verify(servletContext2, never()).setAttribute(eq(SCANNER_ID_PREFIX + "test.2"), any(Scanner.class));
verify(servletConfig2, never()).getInitParameter(eq(SCANNER_ID_KEY));
verify(servletContext2, never()).setAttribute(eq(SCANNER_ID_DEFAULT), any(Scanner.class));
verify(servletContext2, never()).setAttribute(eq(SCANNER_ID_PREFIX + "test.2"), any(Scanner.class));
verify(servletContext1, never()).setAttribute(eq(SCANNER_ID_PREFIX + "test.1"), any(Scanner.class));
assertNotNull(ScannerFactory.getScanner());
assertEquals(new SwaggerContextService().getScanner(), SwaggerScannerLocator.getInstance().getScanner(SCANNER_ID_DEFAULT));
}
use of io.swagger.config.Scanner in project swagger-core by swagger-api.
the class SwaggerContextServiceTest method getScannerWithInitParam.
@Test(description = "should call servletContext getAttribute with param SCANNER_ID_PREFIX + \"test.1/2\"")
public void getScannerWithInitParam() {
stubWithInitParam();
Scanner scanner1 = new SwaggerContextService().withServletConfig(servletConfig1).getScanner();
Scanner scanner2 = new SwaggerContextService().withServletConfig(servletConfig2).getScanner();
assertEquals(beanConfigScanner1, scanner1);
assertEquals(beanConfigScanner2, scanner2);
verify(servletConfig1, times(2)).getInitParameter(eq(SCANNER_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(2)).getInitParameter(eq(SCANNER_ID_KEY));
verify(servletContext2, times(1)).getAttribute(eq(SCANNER_ID_PREFIX + "test.2"));
verify(servletContext1, never()).getAttribute(eq(SCANNER_ID_PREFIX + "test.2"));
}
use of io.swagger.config.Scanner in project swagger-core by swagger-api.
the class SwaggerScannerLocatorTest method putConfigSecondTime.
@Test(description = "shouldn't add given scanner to map because already set")
public void putConfigSecondTime() {
putScannerFirstTime();
Scanner scanner = new Scanner() {
@Override
public Set<Class<?>> classes() {
return null;
}
@Override
public boolean getPrettyPrint() {
return false;
}
@Override
public void setPrettyPrint(boolean shouldPrettyPrint) {
}
};
SwaggerScannerLocator.getInstance().putScanner(id, scanner);
assertNotEquals(SwaggerScannerLocator.getInstance().getScanner(id), scanner);
}
use of io.swagger.config.Scanner in project swagger-core by swagger-api.
the class SwaggerScannerLocatorTest method putScannerFirstTime.
@Test(description = "should add given scanner to map ")
public void putScannerFirstTime() {
Scanner scanner = new Scanner() {
@Override
public Set<Class<?>> classes() {
return null;
}
@Override
public boolean getPrettyPrint() {
return false;
}
@Override
public void setPrettyPrint(boolean shouldPrettyPrint) {
}
};
SwaggerScannerLocator.getInstance().putScanner(id, scanner);
assertEquals(SwaggerScannerLocator.getInstance().getScanner(id), scanner);
}
use of io.swagger.config.Scanner in project swagger-core by swagger-api.
the class SwaggerContextService method getScanner.
public Scanner getScanner() {
String scannerIdKey;
Scanner value = null;
if (scannerId != null) {
scannerIdKey = SCANNER_ID_PREFIX + scannerId;
} else if (contextId != null) {
scannerIdKey = SCANNER_ID_PREFIX + contextId;
} else {
if (isServletConfigAvailable(sc)) {
scannerIdKey = (sc.getInitParameter(SCANNER_ID_KEY) != null) ? SCANNER_ID_PREFIX + sc.getInitParameter(SCANNER_ID_KEY) : null;
if (scannerIdKey == null) {
boolean usePathBasedConfig = Boolean.valueOf(sc.getInitParameter(USE_PATH_BASED_CONFIG));
if (usePathBasedConfig && StringUtils.isNotBlank(basePath)) {
scannerIdKey = SCANNER_ID_PREFIX + basePath;
} else {
scannerIdKey = (sc.getInitParameter(CONTEXT_ID_KEY) != null) ? SCANNER_ID_PREFIX + sc.getInitParameter(CONTEXT_ID_KEY) : SCANNER_ID_DEFAULT;
}
}
value = (Scanner) sc.getServletContext().getAttribute(scannerIdKey);
} else {
scannerIdKey = SCANNER_ID_DEFAULT;
}
}
if (value != null) {
return value;
}
value = SwaggerScannerLocator.getInstance().getScanner(scannerIdKey);
if (value != null) {
return value;
}
return ScannerFactory.getScanner();
}
Aggregations