11package org .ohdsi .webapi .test ;
22
33
4+ import com .github .springtestdbunit .DbUnitTestExecutionListener ;
45import com .github .springtestdbunit .annotation .DatabaseOperation ;
56import com .github .springtestdbunit .annotation .DatabaseTearDown ;
7+ import com .github .springtestdbunit .annotation .DbUnitConfiguration ;
68import com .google .common .collect .ImmutableMap ;
9+ import org .apache .catalina .webresources .TomcatURLStreamHandlerFactory ;
710import org .glassfish .jersey .server .model .Parameter ;
811import org .glassfish .jersey .server .model .Resource ;
912import org .glassfish .jersey .server .model .ResourceMethod ;
1215import org .junit .Rule ;
1316import org .junit .Test ;
1417import org .junit .rules .ErrorCollector ;
18+ import org .junit .runner .RunWith ;
1519import org .ohdsi .webapi .JerseyConfig ;
20+ import org .ohdsi .webapi .WebApi ;
1621import org .slf4j .Logger ;
1722import org .slf4j .LoggerFactory ;
1823import org .springframework .beans .factory .annotation .Autowired ;
24+ import org .springframework .beans .factory .annotation .Value ;
25+ import org .springframework .boot .test .context .SpringBootTest ;
1926import org .springframework .boot .test .web .client .TestRestTemplate ;
2027import org .springframework .http .*;
21- import org .springframework .test .annotation .DirtiesContext ;
28+ import org .springframework .test .context .ActiveProfiles ;
29+ import org .springframework .test .context .TestExecutionListeners ;
30+ import org .springframework .test .context .TestPropertySource ;
31+ import org .springframework .test .context .junit4 .SpringRunner ;
2232import org .springframework .web .util .UriComponentsBuilder ;
2333
2434import javax .ws .rs .core .MediaType ;
35+ import java .io .IOException ;
2536import java .net .URI ;
2637import java .util .*;
2738
2839import static org .assertj .core .api .Java6Assertions .assertThat ;
40+ import static org .springframework .test .context .TestExecutionListeners .MergeMode .MERGE_WITH_DEFAULTS ;
2941
42+ @ RunWith (SpringRunner .class )
43+ @ SpringBootTest (classes = {WebApi .class , WebApiIT .DbUnitConfiguration .class }, webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
44+ @ ActiveProfiles ("test" )
45+ @ DbUnitConfiguration (databaseConnection = "dbUnitDatabaseConnection" )
46+ @ TestExecutionListeners (value = {DbUnitTestExecutionListener .class }, mergeMode = MERGE_WITH_DEFAULTS )
3047@ DatabaseTearDown (value = "/database/empty.xml" , type = DatabaseOperation .DELETE_ALL )
31- public class SecurityIT extends WebApiIT {
48+ @ TestPropertySource (properties = {"security.provider=AtlasRegularSecurity" })
49+ public class SecurityIT {
3250
3351 private final Map <String , HttpStatus > EXPECTED_RESPONSE_CODES = ImmutableMap .<String , HttpStatus >builder ()
3452 .put ("/info/" , HttpStatus .OK )
@@ -47,25 +65,26 @@ public class SecurityIT extends WebApiIT {
4765 @ Autowired
4866 private JerseyConfig jerseyConfig ;
4967
68+ @ Value ("${baseUri}" )
69+ private String baseUri ;
70+
5071 @ Rule
5172 public ErrorCollector collector = new ErrorCollector ();
5273
5374 private final Logger LOG = LoggerFactory .getLogger (SecurityIT .class );
5475
5576 @ BeforeClass
56- public static void prepare () {
57-
58- System . setProperty ( "security.provider" , "AtlasRegularSecurity" );
77+ public static void before () throws IOException {
78+ TomcatURLStreamHandlerFactory . disable ();
79+ ITStarter . before ( );
5980 }
6081
6182 @ AfterClass
62- public static void disableSecurity () {
63-
64- System .setProperty ("security.provider" , "DisabledSecurity" );
83+ public static void after () {
84+ ITStarter .tearDownSubject ();
6585 }
6686
6787 @ Test
68- @ DirtiesContext (methodMode = DirtiesContext .MethodMode .AFTER_METHOD )
6988 public void testServiceSecurity () {
7089
7190 Map <String , List <ServiceInfo >> serviceMap = getServiceMap ();
@@ -76,7 +95,7 @@ public void testServiceSecurity() {
7695 serviceInfo .pathPrefix = "/" + serviceInfo .pathPrefix ;
7796 }
7897 serviceInfo .pathPrefix = serviceInfo .pathPrefix .replaceAll ("//" , "/" );
79- String rawUrl = getBaseUri () + serviceInfo .pathPrefix ;
98+ String rawUrl = baseUri + serviceInfo .pathPrefix ;
8099 URI uri = null ;
81100 try {
82101 Map <String , String > parametersMap = prepareParameters (serviceInfo .parameters );
@@ -195,4 +214,4 @@ public String getMessage() {
195214 return serviceName + ": " + super .getMessage ();
196215 }
197216 }
198- }
217+ }
0 commit comments