org.testng.Assert.ThrowingRunnable Java Examples
The following examples show how to use
org.testng.Assert.ThrowingRunnable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestHadoopKerberosKeytabAuthenticationPlugin.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Test public void testMissingOptions() { final Config testConfig1 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put("hadoop-inject.hadoop.security.authentication", "simple") .put("hadoop.loginUser", "foo") .put("gobblin.instance.hadoop.loginUserKeytabFile", "/tmp/bar") .build()); final GobblinInstanceDriver instance1 = Mockito.mock(GobblinInstanceDriver.class); Mockito.when(instance1.getSysConfig()).thenReturn(DefaultConfigurableImpl.createFromConfig(testConfig1)); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { (new HadoopKerberosKeytabAuthenticationPlugin.ConfigBasedFactory()).createPlugin(instance1); } }); final Config testConfig2 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put("hadoop-inject.hadoop.security.authentication", "simple") .put("gobblin.instance.hadoop.loginUser", "foo") .put("hadoop.loginUserKeytabFile", "/tmp/bar") .build()); final GobblinInstanceDriver instance2 = Mockito.mock(GobblinInstanceDriver.class); Mockito.when(instance1.getSysConfig()).thenReturn(DefaultConfigurableImpl.createFromConfig(testConfig2)); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { (new HadoopKerberosKeytabAuthenticationPlugin.ConfigBasedFactory()).createPlugin(instance2); } }); }
Example #2
Source File: TestImmutableFSJobCatalog.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Test public void testConfigAccessor() throws Exception { Config sysConfig1 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, "/tmp") .build()); ImmutableFSJobCatalog.ConfigAccessor cfgAccessor1 = new ImmutableFSJobCatalog.ConfigAccessor(sysConfig1); Assert.assertEquals(cfgAccessor1.getJobConfDir(), "/tmp"); Assert.assertEquals(cfgAccessor1.getJobConfDirPath(), new Path("/tmp")); Assert.assertEquals(cfgAccessor1.getJobConfDirFileSystem().getClass(), FileSystem.get(new Configuration()).getClass()); Assert.assertEquals(cfgAccessor1.getPollingInterval(), ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL); Config sysConfig2 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder() .put(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, "/tmp2") .put(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, 100) .build()); ImmutableFSJobCatalog.ConfigAccessor cfgAccessor2 = new ImmutableFSJobCatalog.ConfigAccessor(sysConfig2); Assert.assertEquals(cfgAccessor2.getJobConfDir(), "file:///tmp2"); Assert.assertEquals(cfgAccessor2.getJobConfDirPath(), new Path("file:///tmp2")); Assert.assertTrue(cfgAccessor2.getJobConfDirFileSystem() instanceof LocalFileSystem); Assert.assertEquals(cfgAccessor2.getPollingInterval(), 100); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { new ImmutableFSJobCatalog.ConfigAccessor(ConfigFactory.empty()); } }); }
Example #3
Source File: TestRaptorMetadata.java From presto with Apache License 2.0 | 5 votes |
private static void assertThrows(String message, ThrowingRunnable runnable) { try { runnable.run(); fail("expected exception"); } catch (Throwable t) { assertEquals(t.getMessage(), message); } }
Example #4
Source File: TestHttpClientConfiguratorLoader.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Test public void testConfigureFromConfig() { final Config config = ConfigFactory.empty() .withValue(HttpClientConfiguratorLoader.HTTP_CLIENT_CONFIGURATOR_TYPE_KEY, ConfigValueFactory.fromAnyRef("blah")); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { new HttpClientConfiguratorLoader(config); } }); }
Example #5
Source File: TestingEventBusAsserterTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Test public void testAssertNext() throws InterruptedException, TimeoutException, IOException { EventBus testBus = TestingEventBuses.getEventBus("TestingEventBusAsserterTest.testHappyPath"); try(final TestingEventBusAsserter asserter = new TestingEventBusAsserter("TestingEventBusAsserterTest.testHappyPath")) { testBus.post(new TestingEventBuses.Event("event1")); testBus.post(new TestingEventBuses.Event("event2")); asserter.assertNextValueEq("event1"); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { asserter.assertNextValueEq("event3"); } }); testBus.post(new TestingEventBuses.Event("event13")); testBus.post(new TestingEventBuses.Event("event11")); testBus.post(new TestingEventBuses.Event("event12")); testBus.post(new TestingEventBuses.Event("event10")); asserter.assertNextValuesEq(Arrays.asList("event10", "event11", "event12", "event13")); testBus.post(new TestingEventBuses.Event("event22")); testBus.post(new TestingEventBuses.Event("event20")); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { asserter.assertNextValuesEq(Arrays.asList("event22", "event21")); } }); } }
Example #6
Source File: EmptyNavigableSet.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private <T extends Throwable> void assertThrows(Class<T> throwableClass, ThrowingRunnable runnable, String message) { try { Assert.assertThrows(throwableClass, runnable); } catch (AssertionError e) { throw new AssertionError(String.format("%s%n%s", ((null != message) ? message : ""), e.getMessage()), e); } }
Example #7
Source File: DefaultOAuthJwtAccessTokenValidatorTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testValidateExpiration() { final DefaultOAuthJwtAccessTokenValidator validator = new DefaultOAuthJwtAccessTokenValidator(this.trustedIssuer, this.requiredAudiences, this.requiredScopes, this.authorizedClientIds); final OAuthJwtAccessToken mock = Mockito.spy(baseJwt); Mockito.doReturn("trustedIssuer").when(mock).getIssuer(); Mockito.doReturn(Arrays.asList("aud_1", "aud_2")).when(mock).getAudiences(); Mockito.doReturn(Arrays.asList("scope_1", "scope_2")).when(mock).getScopes(); // zero exp Mockito.doReturn(0L).when(mock).getExpiration(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "exp is empty"); // -ve exp Mockito.doReturn(-1L).when(mock).getExpiration(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "exp is empty"); // +ve exp Mockito.doReturn(1L).when(mock).getExpiration(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }); }
Example #8
Source File: DefaultOAuthJwtAccessTokenValidatorTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testValidateVerifyScopes() { final DefaultOAuthJwtAccessTokenValidator validator = this.baseValidator; final OAuthJwtAccessToken mock = Mockito.spy(baseJwt); Mockito.doReturn(this.trustedIssuer).when(mock).getIssuer(); Mockito.doReturn(new ArrayList<>(this.requiredAudiences)).when(mock).getAudiences(); Mockito.doReturn(1L).when(mock).getExpiration(); // null JWT issuer Mockito.doReturn(null).when(mock).getScope(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "required scope not found: got=null"); // empty Mockito.doReturn("").when(mock).getScope(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "required scope not found: got="); // not match Mockito.doReturn("scope_1 unknown_scope").when(mock).getScope(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "required scope not found: got=scope_1 unknown_scope"); // match Mockito.doReturn("scope_3 scope_2 scope_1").when(mock).getScope(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }); }
Example #9
Source File: DefaultOAuthJwtAccessTokenValidatorTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testValidateVerifyAudiences() { final DefaultOAuthJwtAccessTokenValidator validator = this.baseValidator; final OAuthJwtAccessToken mock = Mockito.spy(baseJwt); Mockito.doReturn(this.trustedIssuer).when(mock).getIssuer(); Mockito.doReturn(new ArrayList<>(this.requiredScopes)).when(mock).getScopes(); Mockito.doReturn(1L).when(mock).getExpiration(); // null JWT issuer Mockito.doReturn(null).when(mock).getAudiences(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "required aud not found: got=null"); // empty Mockito.doReturn(new ArrayList<>()).when(mock).getAudiences(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "required aud not found: got="); // not match Mockito.doReturn(Arrays.asList("aud_1", "unknown_aud")).when(mock).getAudiences(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "required aud not found: got=aud_1, unknown_aud"); // match Mockito.doReturn(Arrays.asList("aud_3", "aud_2", "aud_1")).when(mock).getAudiences(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }); }
Example #10
Source File: DefaultOAuthJwtAccessTokenValidatorTest.java From athenz with Apache License 2.0 | 5 votes |
@Test public void testValidateVerifyIssuer() { final DefaultOAuthJwtAccessTokenValidator validator = this.baseValidator; final OAuthJwtAccessToken mock = Mockito.spy(baseJwt); Mockito.doReturn(new ArrayList<>(this.requiredAudiences)).when(mock).getAudiences(); Mockito.doReturn(new ArrayList<>(this.requiredScopes)).when(mock).getScopes(); Mockito.doReturn(1L).when(mock).getExpiration(); // null JWT issuer Mockito.doReturn(null).when(mock).getIssuer(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "iss not trusted: got=null"); // empty Mockito.doReturn("").when(mock).getIssuer(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "iss not trusted: got="); // not match Mockito.doReturn("untrusty_issuer").when(mock).getIssuer(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }, "iss not trusted: got=untrusty_issuer"); // match Mockito.doReturn("trustedIssuer").when(mock).getIssuer(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validate(mock); } }); }
Example #11
Source File: EmptyNavigableMap.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private <T extends Throwable> void assertThrows(Class<T> throwableClass, ThrowingRunnable runnable, String message) { try { Assert.assertThrows(throwableClass, runnable); } catch (AssertionError e) { throw new AssertionError(String.format("%s%n%s", ((null != message) ? message : ""), e.getMessage()), e); } }
Example #12
Source File: EmptyNavigableMap.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsCCE(ThrowingRunnable r, String s) { assertThrows(ClassCastException.class, r, s); }
Example #13
Source File: DefaultOAuthJwtAccessTokenValidatorTest.java From athenz with Apache License 2.0 | 4 votes |
@Test public void testValidateCertificateBinding() { final DefaultOAuthJwtAccessTokenValidator validator = this.baseValidator; final OAuthJwtAccessToken mock = Mockito.spy(baseJwt); Mockito.doReturn(null).when(mock).getCertificateThumbprint(); // null JWT thumbprint, null expected certificate thumbprint assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateCertificateBinding(mock, (String) null); } }); // null JWT thumbprint ONLY assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateCertificateBinding(mock, "certificate_thumbprint"); } }, "client certificate thumbprint (certificate_thumbprint) not match: got=null"); Mockito.doReturn("certificate_thumbprint").when(mock).getCertificateThumbprint(); // null expected certificate thumbprint ONLY assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateCertificateBinding(mock, (String) null); } }, "client certificate thumbprint (null) not match: got=certificate_thumbprint"); // not match assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateCertificateBinding(mock, "not_match"); } }, "client certificate thumbprint (not_match) not match: got=certificate_thumbprint"); // match assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateCertificateBinding(mock, new String("certificate_thumbprint")); // for coverage } }); }
Example #14
Source File: DefaultOAuthJwtAccessTokenValidatorTest.java From athenz with Apache License 2.0 | 4 votes |
@Test public void testValidateClientId() { final DefaultOAuthJwtAccessTokenValidator validator = this.baseValidator; final OAuthJwtAccessToken mock = Mockito.spy(baseJwt); Mockito.doReturn(null).when(mock).getClientId(); // null JWT client ID, null CN, invalid assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, null); } }, "NO mapping of authorized client IDs for certificate principal (null)"); // null JWT client ID ONLY, no mapping assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "no_mapping_1"); } }, "NO mapping of authorized client IDs for certificate principal (no_mapping_1)"); // null JWT client ID ONLY, mapped assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }, "client_id is not authorized for certificate principal (client_cert_common_name): got=null"); Mockito.doReturn("jwt_client_id").when(mock).getClientId(); // null expected client ID ONLY, no mapping assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, null); } }, "NO mapping of authorized client IDs for certificate principal (null)"); // null expected client ID ONLY, mapped authorizedClientIds.put(null, new HashSet<>(Arrays.asList("null_1, null_2"))); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, null); } }, "client_id is not authorized for certificate principal (null): got=jwt_client_id"); authorizedClientIds.remove(null); // not match, no mapping assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "no_mapping_2"); } }, "NO mapping of authorized client IDs for certificate principal (no_mapping_2)"); // not match, mapped assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }, "client_id is not authorized for certificate principal (client_cert_common_name): got=jwt_client_id"); // match, no mapping Mockito.doReturn("match.principal.1").when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "match.principal.1"); } }, "NO mapping of authorized client IDs for certificate principal (match.principal.1)"); // match, mapped Mockito.doReturn("client_id_1").when(mock).getClientId(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }); // no mapping, case-insensitive, match, invalid Mockito.doReturn("match.principal.PPP").when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "match.principal.ppp"); } }, "NO mapping of authorized client IDs for certificate principal (match.principal.ppp)"); // mapped, case-sensitive, match Mockito.doReturn("CLIENT_ID_2").when(mock).getClientId(); assertDoesNotThrow.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }); // mapped, case-sensitive, not match Mockito.doReturn("client_id_2").when(mock).getClientId(); assertThrowable.accept(new ThrowingRunnable() { public void run() throws Throwable { validator.validateClientId(mock, "client_cert_common_name"); } }, "client_id is not authorized for certificate principal (client_cert_common_name): got=client_id_2"); }
Example #15
Source File: SpliteratorFailFastTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsCME(ThrowingRunnable r) { assertThrows(ConcurrentModificationException.class, r); }
Example #16
Source File: EmptyNavigableMap.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsIAE(ThrowingRunnable r, String s) { assertThrows(IllegalArgumentException.class, r, s); }
Example #17
Source File: EmptyNavigableMap.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsNPE(ThrowingRunnable r, String s) { assertThrows(NullPointerException.class, r, s); }
Example #18
Source File: TestSpillCipherPagesSerde.java From presto with Apache License 2.0 | 4 votes |
private static void assertFailure(ThrowingRunnable runnable, String expectedErrorMessage) { PrestoException exception = expectThrows(PrestoException.class, runnable); assertEquals(exception.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode()); assertEquals(exception.getMessage(), expectedErrorMessage); }
Example #19
Source File: EmptyNavigableSet.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsNSEE(ThrowingRunnable r, String s) { assertThrows(NoSuchElementException.class, r, s); }
Example #20
Source File: EmptyNavigableSet.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsIAE(ThrowingRunnable r, String s) { assertThrows(IllegalArgumentException.class, r, s); }
Example #21
Source File: EmptyNavigableSet.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsNPE(ThrowingRunnable r, String s) { assertThrows(NullPointerException.class, r, s); }
Example #22
Source File: EmptyNavigableSet.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsCCE(ThrowingRunnable r, String s) { assertThrows(ClassCastException.class, r, s); }
Example #23
Source File: Defaults.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void assertThrowsNPE(ThrowingRunnable r) { assertThrows(NullPointerException.class, r); }
Example #24
Source File: StreamAndSpliterator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
void assertThrowsAIOOB(ThrowingRunnable r) { assertThrows(ArrayIndexOutOfBoundsException.class, r); }
Example #25
Source File: StreamAndSpliterator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
void assertThrowsNPE(ThrowingRunnable r) { assertThrows(NullPointerException.class, r); }
Example #26
Source File: PrimitiveIteratorDefaults.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void assertThrowsNPE(ThrowingRunnable r) { assertThrows(NullPointerException.class, r); }
Example #27
Source File: TestFileBasedAccessControl.java From presto with Apache License 2.0 | 4 votes |
private static void assertDenied(ThrowingRunnable runnable) { assertThrows(AccessDeniedException.class, runnable); }
Example #28
Source File: TestAesSpillCipher.java From presto with Apache License 2.0 | 4 votes |
private static void assertFailure(ThrowingRunnable runnable, String expectedErrorMessage) { PrestoException exception = expectThrows(PrestoException.class, runnable); assertEquals(exception.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode()); assertEquals(exception.getMessage(), expectedErrorMessage); }