Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Report usage stats when isReactEnabled=false #2534

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void serviceInit(ServiceInitEvent event) {
.getDeploymentConfiguration();
LOGGER.debug("deploymentConfiguration.isReactEnabled() = {}",
deploymentConfiguration.isReactEnabled());
boolean hasHillaFsRoute = false;
if (deploymentConfiguration.isReactEnabled()) {
var routeUnifyingIndexHtmlRequestListener = new RouteUnifyingIndexHtmlRequestListener(
clientRouteRegistry, deploymentConfiguration, routeUtil,
Expand All @@ -102,10 +103,8 @@ public void serviceInit(ServiceInitEvent event) {
clientRouteRegistry.registerClientRoutes(deploymentConfiguration,
LocalDateTime.now());

boolean hasHillaFsRoute = !clientRouteRegistry.getAllRoutes()
.isEmpty();
HillaStats.reportGenericHasFeatures(event.getSource(),
hasHillaFsRoute);
hasHillaFsRoute = !clientRouteRegistry.getAllRoutes().isEmpty();
}
HillaStats.reportGenericHasFeatures(event.getSource(), hasHillaFsRoute);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import java.io.IOException;

import com.vaadin.hilla.route.RouteUnifyingConfigurationProperties;
import com.vaadin.hilla.route.RouteUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.internal.UsageStatistics;
import com.vaadin.flow.server.ServiceInitEvent;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.frontend.FrontendUtils;
import com.vaadin.hilla.route.ClientRouteRegistry;
import com.vaadin.hilla.route.RouteUnifyingConfigurationProperties;
import com.vaadin.hilla.route.RouteUnifyingIndexHtmlRequestListener;
import com.vaadin.hilla.route.RouteUtil;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;

public class RouteUnifyingServiceInitListenerTest {
Expand Down Expand Up @@ -96,6 +99,27 @@ public void should_registerClientRoutes_when_in_devMode_and_react_is_enabled() {
.registerClientRoutes(Mockito.any(), Mockito.any());
}

@Test
public void when_hillaIsUsed_and_reactIsDisabled_LitIsReported() {
Mockito.when(mockDeploymentConfiguration.isReactEnabled())
.thenReturn(false);
Mockito.when(mockDeploymentConfiguration.isProductionMode())
.thenReturn(false);

try (MockedStatic<FrontendUtils> mockedStaticFrontendUtils = mockStatic(
FrontendUtils.class)) {
mockedStaticFrontendUtils
.when(() -> FrontendUtils.isHillaUsed(Mockito.any()))
.thenReturn(true);
routeUnifyingServiceInitListener.serviceInit(event);
boolean litReported = UsageStatistics.getEntries()
.anyMatch(entry -> "has-lit".equals(entry.getName()));
Assert.assertTrue(
"Expected Lit to be reported in usage stats when 'isReactEnabled=false' and Hilla is used",
litReported);
}
}

private boolean hasRouteUnifyingIndexHtmlRequestListenerAdded(
ServiceInitEvent event) {
return event.getAddedIndexHtmlRequestListeners().anyMatch(
Expand Down
Loading