-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ava/biz/netcentric/cq/tools/actool/startuphook/impl/AcToolStartupHookServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package biz.netcentric.cq.tools.actool.startuphook.impl; | ||
|
||
/*- | ||
* #%L | ||
* Access Control Tool Bundle | ||
* %% | ||
* Copyright (C) 2015 - 2024 Cognizant Netcentric | ||
* %% | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* #L% | ||
*/ | ||
|
||
import biz.netcentric.cq.tools.actool.api.AcInstallationService; | ||
import biz.netcentric.cq.tools.actool.helper.runtime.RuntimeHelper; | ||
import org.apache.sling.jcr.api.SlingRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.FrameworkUtil; | ||
import org.osgi.framework.startlevel.FrameworkStartLevel; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AcToolStartupHookServiceImplTest { | ||
|
||
@Mock | ||
Bundle bundle; | ||
|
||
@Mock | ||
BundleContext bundleContext; | ||
|
||
@Mock | ||
AcToolStartupHookServiceImpl.Config config; | ||
|
||
@Mock | ||
SlingRepository repository; | ||
|
||
@Spy | ||
AcInstallationService installationService; | ||
|
||
@BeforeEach | ||
void setup() throws RepositoryException { | ||
FrameworkStartLevel startLevel = Mockito.mock(FrameworkStartLevel.class); | ||
when(startLevel.getStartLevel()).thenReturn(0); | ||
|
||
when(config.activationMode()).thenReturn(AcToolStartupHookServiceImpl.Config.StartupHookActivation.ALWAYS); | ||
|
||
Session session = mock(Session.class); | ||
when(repository.loginService(null, null)).thenReturn(session); | ||
|
||
when(bundle.getBundleContext()).thenReturn(bundleContext); | ||
when(bundle.getSymbolicName()).thenReturn(RuntimeHelper.INSTALLER_CORE_BUNDLE_SYMBOLIC_ID); | ||
when(bundle.adapt(FrameworkStartLevel.class)).thenReturn(startLevel); | ||
|
||
when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle }); | ||
when(bundleContext.getBundle(anyLong())).thenReturn(bundle); | ||
} | ||
@Test | ||
void testActivation() { | ||
try (MockedStatic<FrameworkUtil> mockedFrameworkUtil = mockStatic(FrameworkUtil.class)) { | ||
mockedFrameworkUtil.when(() -> FrameworkUtil.getBundle(RuntimeHelper.class)).thenReturn(bundle); | ||
AcToolStartupHookServiceImpl startupHookService = new AcToolStartupHookServiceImpl(); | ||
startupHookService.repository = repository; | ||
startupHookService.acInstallationService = installationService; | ||
startupHookService.activate(bundleContext, config); | ||
verify(installationService, times(1)).apply(null, new String[]{}, true); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ol-startuphook-bundle/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mock-maker-inline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters