Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madurangasiriwardena committed Jun 22, 2024
1 parent 2a08373 commit d386659
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
import org.wso2.carbon.CarbonConstants;
Expand Down Expand Up @@ -491,9 +491,10 @@ private void initializeCarbon() {
}

HttpService httpService = CarbonCoreDataHolder.getInstance().getHttpService();
// TODO might want to do this differently
HttpContext defaultHttpContext = httpService.createDefaultHttpContext();

registerCarbonServlet(httpService, defaultHttpContext);
registerCarbonServlet(defaultHttpContext);

RealmService realmService = CarbonCoreDataHolder.getInstance().getRealmService();
UserRealm teannt0Realm = realmService.getBootstrapRealm();
Expand Down Expand Up @@ -543,8 +544,8 @@ private void initializeCarbon() {
}
}

private void registerCarbonServlet(HttpService httpService, HttpContext defaultHttpContext)
throws ServletException, NamespaceException, InvalidSyntaxException {
private void registerCarbonServlet(HttpContext defaultHttpContext) throws InvalidSyntaxException {

if (!"false".equals(serverConfig.getFirstProperty("RequireCarbonServlet"))) {
CarbonServlet carbonServlet = new CarbonServlet(serverConfigContext);
String servicePath = "/services";
Expand All @@ -561,18 +562,25 @@ private void registerCarbonServlet(HttpService httpService, HttpContext defaultH
resourceProps.put("osgi.http.whiteboard.context.name", "serviceContext");
resourceProps.put("osgi.http.whiteboard.context.path", servicePath);
resourceProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN, servicePath + "/*");
bundleContext.registerService(ServletContextHelper.class, (ServletContextHelper) defaultHttpContext, resourceProps);
ServiceRegistration<ServletContextHelper> servletContextHelperServiceRegistration =
bundleContext.registerService(ServletContextHelper.class, (ServletContextHelper) defaultHttpContext,
resourceProps);
CarbonCoreDataHolder.getInstance().addServiceRegistration(servletContextHelperServiceRegistration);

Dictionary<String, Object> carbonServletProperties = new Hashtable<>();
carbonServletProperties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/*");
carbonServletProperties.put("osgi.http.whiteboard.context.select", "(osgi.http.whiteboard.context.name=serviceContext)");
bundleContext.registerService(Servlet.class, carbonServlet, carbonServletProperties);
ServiceRegistration<Servlet> servletServiceRegistration =
bundleContext.registerService(Servlet.class, carbonServlet, carbonServletProperties);
CarbonCoreDataHolder.getInstance().addServiceRegistration(servletServiceRegistration);

if (filterServiceReference != null) {
Filter filter = (Filter) bundleContext.getService(filterServiceReference);
Dictionary<String, String> props = new Hashtable<>();
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, servicePath);
bundleContext.registerService(Filter.class, filter, props);
ServiceRegistration<Filter> filterServiceRegistration =
bundleContext.registerService(Filter.class, filter, props);
CarbonCoreDataHolder.getInstance().addServiceRegistration(filterServiceRegistration);
}
HTTPGetProcessorListener getProcessorListener =
new HTTPGetProcessorListener(carbonServlet, bundleContext);
Expand Down Expand Up @@ -957,17 +965,8 @@ public void stop() throws Exception {
((Map) property).clear();
}

// un-registering the carbonServlet
String servicePath = "/services"; // default path
String path = serverConfigContext.getServicePath();
if (path != null) {
servicePath = path.trim();
}
if (!servicePath.startsWith("/")) {
servicePath = "/" + servicePath;
}
try {
CarbonCoreDataHolder.getInstance().getHttpService().unregister(servicePath);
CarbonCoreDataHolder.getInstance().unregisterServiceRegistrations();
} catch (Exception e) {
log.error("Failed to Un-register Servlets ", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.context.ServletContextHelper;
import org.wso2.carbon.base.api.ServerConfigurationService;
import org.wso2.carbon.crypto.api.CryptoService;
import org.wso2.carbon.registry.core.service.RegistryService;
Expand All @@ -47,6 +49,8 @@ public class CarbonCoreDataHolder {
private ServerConfigurationService serverConfigurationService;
private TenantRegistryLoader tenantRegistryLoader;

private List<ServiceRegistration<?>> serviceRegistrations = new ArrayList<>();

private List<CoordinatedActivity> coordinatedActivities = new ArrayList<CoordinatedActivity>() ;
private CryptoService cryptoService;

Expand Down Expand Up @@ -166,4 +170,16 @@ public CryptoService getCryptoService() {

return cryptoService;
}

public void addServiceRegistration(ServiceRegistration<?> serviceRegistration) {

serviceRegistrations.add(serviceRegistration);
}

public void unregisterServiceRegistrations() {

for (ServiceRegistration<?> serviceRegistration : serviceRegistrations) {
serviceRegistration.unregister();
}
}
}
1 change: 1 addition & 0 deletions core/org.wso2.carbon.registry.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<goal>test</goal>
</goals>
<configuration>
<!-- TODO revert back-->
<skip>true</skip>
<forkMode>pertest</forkMode>
<argLine>-enableassertions</argLine>
Expand Down
10 changes: 0 additions & 10 deletions core/org.wso2.carbon.tomcat.ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
Expand Down
15 changes: 2 additions & 13 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,9 @@

<!-- Unit/Integration tests -->
<jacoco.version>0.8.12</jacoco.version>
<maven.surefire.plugin.version>3.2.5</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>2.22.2</maven.failsafe.plugin.version>
<maven.surefire.plugin.version>3.3.0</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.3.0</maven.failsafe.plugin.version>
<mockito.version>5.3.1</mockito.version>
<powermock.version>2.0.2</powermock.version>
<maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>

<!-- OWASP CSRFGuard Version -->
Expand Down Expand Up @@ -1807,16 +1806,6 @@
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<version>${powermock.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand Down

0 comments on commit d386659

Please sign in to comment.