use of org.junit.AssumptionViolatedException in project blueocean-plugin by jenkinsci.
the class UserImplPermissionTest method useTestAgainstJenkinsRoot.
/**
* Tests against jenkins
*/
@Test
public void useTestAgainstJenkinsRoot() {
try {
// https://github.com/powermock/powermock/issues/428
OrganizationImpl baseOrg = new OrganizationImpl("jenkins", jenkins);
UserImpl userImpl = new UserImpl(baseOrg, user, baseOrg);
checkPermissions(userImpl.getPermission(), false, false);
when(jenkins.getACL()).thenReturn(new ACL() {
public boolean hasPermission(Authentication a, Permission permission) {
return true;
}
});
checkPermissions(userImpl.getPermission(), true, true);
} catch (AssumptionViolatedException x) {
System.err.println(x);
}
}
use of org.junit.AssumptionViolatedException in project blueocean-plugin by jenkinsci.
the class UserImplPermissionTest method setup.
@Before
public void setup() throws IOException {
testOrganization = new TestOrganization("org", "orgDisplayName");
user = mock(User.class);
when(user.getId()).thenReturn("some_user");
authentication = new Authentication() {
public String getName() {
return "some_user";
}
public GrantedAuthority[] getAuthorities() {
return null;
}
public Object getCredentials() {
return null;
}
public Object getDetails() {
return null;
}
public Object getPrincipal() {
return null;
}
public boolean isAuthenticated() {
return false;
}
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
}
};
jenkins = mock(Jenkins.class);
when(jenkins.getACL()).thenReturn(new ACL() {
public boolean hasPermission(Authentication a, Permission permission) {
return false;
}
});
mockStatic(Jenkins.class);
when(Jenkins.getAuthentication()).thenReturn(authentication);
when(Jenkins.get()).thenReturn(jenkins);
try {
// After Jenkins 2.77 hasPermission is no longer in Node.class and is not final so we need to mock it
// prior to it is called as being final and mocking it will fail for the same reason.
// TODO remove after core base line is >= 2.77
Node.class.getDeclaredMethod("hasPermission", Permission.class);
} catch (NoSuchMethodException e) {
when(jenkins.hasPermission(Mockito.any())).thenAnswer(new Answer<Boolean>() {
public Boolean answer(InvocationOnMock invocation) {
Permission permission = invocation.getArgument(0);
Jenkins j = (Jenkins) invocation.getMock();
ACL acl = j.getACL();
try {
return acl.hasPermission(permission);
} catch (NullPointerException x) {
throw new AssumptionViolatedException("TODO cannot be made to work prior to Spring Security update", x);
}
}
});
}
mockStatic(User.class);
when(User.get("some_user", false, Collections.EMPTY_MAP)).thenReturn(user);
}
use of org.junit.AssumptionViolatedException in project zipkin by openzipkin.
the class ZipkinRuleTest method postSpans_disconnectDuringBody.
@Test
public void postSpans_disconnectDuringBody() {
zipkin.enqueueFailure(HttpFailure.disconnectDuringBody());
try {
postSpansV1(spans);
failBecauseExceptionWasNotThrown(IOException.class);
} catch (IOException expected) {
// not always a ConnectException!
}
// Zipkin didn't store the spans, as they shouldn't have been readable, due to disconnect
assertThat(zipkin.getTraces()).isEmpty();
try {
// The failure shouldn't affect later requests
assertThat(postSpansV1(spans).code()).isEqualTo(202);
} catch (IOException flake) {
throw new AssumptionViolatedException("test flaked", flake);
}
}
use of org.junit.AssumptionViolatedException in project Payara by payara.
the class DirConfigSourceTest method testPropertyWatcher_RegisterAndInit.
@Test
public void testPropertyWatcher_RegisterAndInit() throws Exception {
// given
Map<Path, String> examples = new HashMap<>();
examples.put(subpath("init-watcher", "foo", "bar", "test", "ex"), "init-watcher.foo.bar.test.ex");
examples.put(subpath("init-watcher", "foo.bar.test", "hello"), "init-watcher.foo.bar.test.hello");
examples.put(subpath("init-watcher", ".foo", "ex"), "init-watcher.foo.ex");
for (Map.Entry<Path, String> ex : examples.entrySet()) {
writeFile(ex.getKey(), "foobar");
}
try {
Files.createSymbolicLink(subpath("init-watcher", "foo.hello"), subpath("init-watcher", ".foo", "ex"));
} catch (FileSystemException fileSystemException) {
if (OS.isWindows() && fileSystemException.getReason().contains("A required privilege is not held by the client")) {
throw new AssumptionViolatedException("Permissions to create Symbolic Links not granted", fileSystemException);
}
}
// when
DirConfigSource.DirPropertyWatcher watcher = source.createWatcher(subpath("init-watcher"));
// then
assertEquals("foobar", source.getValue("init-watcher.foo.bar.test.ex"));
assertEquals("foobar", source.getValue("init-watcher.foo.bar.test.hello"));
assertEquals(null, source.getValue("init-watcher.foo.ex"));
assertEquals("foobar", source.getValue("init-watcher.foo.hello"));
}
use of org.junit.AssumptionViolatedException in project xtext-core by eclipse.
the class AbstractScenarioRunner method process.
protected void process(String data) throws Exception {
IInjectorProvider delegate = getOrCreateInjectorProvider().getDelegate();
if (delegate instanceof IRegistryConfigurator) {
IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate;
registryConfigurator.setupRegistry();
try {
ScenarioProcessor processor = delegate.getInjector().getInstance(processorClass);
String preProcessed = processor.preProcess(data);
if (preProcessed == null) {
throw new AssumptionViolatedException("Input is filtered by the pre processing step: " + data);
}
doProcess(preProcessed, processor);
} finally {
registryConfigurator.restoreRegistry();
}
}
}
Aggregations