Search in sources :

Example 26 with AssumptionViolatedException

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);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Authentication(org.acegisecurity.Authentication) Permission(hudson.security.Permission) BlueUserPermission(io.jenkins.blueocean.rest.model.BlueUserPermission) ACL(hudson.security.ACL) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with AssumptionViolatedException

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);
}
Also used : BlueUser(io.jenkins.blueocean.rest.model.BlueUser) User(hudson.model.User) AssumptionViolatedException(org.junit.AssumptionViolatedException) ACL(hudson.security.ACL) Jenkins(jenkins.model.Jenkins) Answer(org.mockito.stubbing.Answer) Authentication(org.acegisecurity.Authentication) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Permission(hudson.security.Permission) BlueUserPermission(io.jenkins.blueocean.rest.model.BlueUserPermission) Before(org.junit.Before)

Example 28 with AssumptionViolatedException

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);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 29 with AssumptionViolatedException

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"));
}
Also used : Path(java.nio.file.Path) FileSystemException(java.nio.file.FileSystemException) AssumptionViolatedException(org.junit.AssumptionViolatedException) Test(org.junit.Test)

Example 30 with AssumptionViolatedException

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();
        }
    }
}
Also used : ScenarioProcessor(org.eclipse.xtext.testing.smoketest.ScenarioProcessor) IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Aggregations

AssumptionViolatedException (org.junit.AssumptionViolatedException)79 Test (org.junit.Test)26 IOException (java.io.IOException)16 Statement (org.junit.runners.model.Statement)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Method (java.lang.reflect.Method)6 Set (java.util.Set)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ZipEntry (java.util.zip.ZipEntry)5 ZipOutputStream (java.util.zip.ZipOutputStream)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ZipInputStream (java.util.zip.ZipInputStream)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 JarInputStream (java.util.jar.JarInputStream)3 Configuration (org.apache.flink.configuration.Configuration)3 IInjectorProvider (org.eclipse.xtext.junit4.IInjectorProvider)3