use of com.enonic.xp.security.SecurityService in project xp by enonic.
the class SetPermissionsHandlerTest method testExample.
@Test
public void testExample() {
final Content content = TestDataFixtures.newExampleContent();
Mockito.when(this.contentService.getByPath(Mockito.any())).thenReturn(content);
Mockito.when(this.contentService.applyPermissions(Mockito.any())).thenReturn(ApplyContentPermissionsResult.create().build());
SecurityService securityService = Mockito.mock(SecurityService.class);
addService(SecurityService.class, securityService);
final Optional<? extends Principal> value = Optional.of(User.ANONYMOUS);
Mockito.<Optional<? extends Principal>>when(securityService.getPrincipal(Mockito.any(PrincipalKey.class))).thenReturn(value);
runScript("/lib/xp/examples/content/setPermissions.js");
}
use of com.enonic.xp.security.SecurityService in project xp by enonic.
the class IdProviderControllerServiceImplTest method setup.
@BeforeEach
public void setup() throws Exception {
// Mocks the IdProviderDescriptorService
final IdProviderDescriptorService idProviderDescriptorService = Mockito.mock(IdProviderDescriptorService.class);
Mockito.when(idProviderDescriptorService.getDescriptor(ApplicationKey.from("myapplication"))).thenReturn(IdProviderDescriptor.create().key(ApplicationKey.from("myapplication")).build());
// Mocks the SecurityService
final SecurityService securityService = Mockito.mock(SecurityService.class);
final IdProvider emptyIdProvider = IdProvider.create().build();
final IdProviderConfig idProviderConfig = IdProviderConfig.create().applicationKey(ApplicationKey.from("myapplication")).build();
final IdProvider idProvider = IdProvider.create().idProviderConfig(idProviderConfig).build();
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyidprovider"))).thenReturn(emptyIdProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myidprovider"))).thenReturn(idProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myemptyuserstore"))).thenReturn(emptyIdProvider);
Mockito.when(securityService.getIdProvider(IdProviderKey.from("myuserstore"))).thenReturn(idProvider);
// Mocks the PortalScriptService
final PortalScriptService portalScriptService = setupPortalScriptService();
// Creates IdProviderControllerScriptFactoryImpl
final IdProviderControllerScriptFactoryImpl idProviderControllerScriptFactory = new IdProviderControllerScriptFactoryImpl();
idProviderControllerScriptFactory.setScriptService(portalScriptService);
// Creates IdProviderControllerServiceImpl
idProviderControllerService = new IdProviderControllerServiceImpl();
idProviderControllerService.setIdProviderControllerScriptFactory(idProviderControllerScriptFactory);
idProviderControllerService.setIdProviderDescriptorService(idProviderDescriptorService);
idProviderControllerService.setSecurityService(securityService);
}
Aggregations