Skip to content

Commit

Permalink
Add tests for RuntimeHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
gicig committed Sep 11, 2024
1 parent e8f1f48 commit 3677c0e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package biz.netcentric.cq.tools.actool.helper.runtime;

/*-
* #%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 org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import javax.jcr.RepositoryException;
import javax.jcr.Session;

import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class RuntimeHelperTest {

@Mock
Session session;

@Test
void shouldBeReadonlyIfRootWritable() throws RepositoryException {
when(session.hasPermission("/", Session.ACTION_SET_PROPERTY)).thenReturn(true);
Assertions.assertTrue(RuntimeHelper.isAppsReadOnly(session));
}

@Test
void shouldNotBeReadonlyIfRootNotWritable() throws RepositoryException {
when(session.hasPermission("/", Session.ACTION_SET_PROPERTY)).thenReturn(false);
Assertions.assertFalse(RuntimeHelper.isAppsReadOnly(session));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void setup(boolean canSetPropertiesOnRootNode, boolean runAsyncForMutableContent
when(noChildren.hasNext()).thenReturn(false);
when(rootNode.getNodes()).thenReturn(noChildren);
when(session.getRootNode()).thenReturn(rootNode);
} else if (!canSetPropertiesOnRootNode && !cloudOnly){
} else if (!canSetPropertiesOnRootNode && !cloudOnly) {
when(session.hasPermission("/", Session.ACTION_SET_PROPERTY)).thenReturn(false);
}
if (!cloudOnly) {
Expand Down

0 comments on commit 3677c0e

Please sign in to comment.