Java Code Examples for org.testng.Assert#assertThrows()

The following examples show how to use org.testng.Assert#assertThrows() . 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: DisableFTEnableOnMethodTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
/**
 * Test whether Bulkhead is enabled on {@code waitWithBulkhead()}
 *
 * @throws InterruptedException interrupted
 * @throws ExecutionException task was aborted
 */
@Test
public void testBulkhead() throws ExecutionException, InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(10);

    // Start two executions at once
    CompletableFuture<Void> waitingFuture = new CompletableFuture<>();
    Future<?> result1 = executor.submit(() -> disableClient.waitWithBulkhead(waitingFuture));
    Future<?> result2 = executor.submit(() -> disableClient.waitWithBulkhead(waitingFuture));

    try {
        disableClient.waitForBulkheadExecutions(2);

        // Try to start a third execution. This would throw a BulkheadException if Bulkhead is enabled.
        // Bulkhead is enabled on the method, so expect exception
        Assert.assertThrows(BulkheadException.class, () -> disableClient.waitWithBulkhead(CompletableFuture.completedFuture(null)));
    }
    finally {
        // Clean up executor and first two executions
        executor.shutdown();

        waitingFuture.complete(null);
        result1.get();
        result2.get();
    }
}
 
Example 2
Source File: GiteaIntegrationTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
@Test
void testGiteaMapping() throws Exception {
  try (SvnTestServer server = createServer(administratorToken, dir -> new GiteaMappingConfig(dir, GitCreateMode.EMPTY))) {
    // Test user can get own private repo
    openSvnRepository(server, testPrivateRepository, user, userPassword).getLatestRevision();
    // Collaborator cannot get test's private repo
    Assert.assertThrows(SVNAuthenticationException.class, () -> openSvnRepository(server, testPrivateRepository, collaborator, collaboratorPassword).getLatestRevision());
    // Anyone can get public repo
    openSvnRepository(server, testPublicRepository, "anonymous", "nopassword").getLatestRevision();
    // Collaborator can get public repo
    openSvnRepository(server, testPublicRepository, collaborator, collaboratorPassword).getLatestRevision();
    // Add collaborator to private repo
    repoAddCollaborator(testPrivateRepository.getOwner().getLogin(), testPrivateRepository.getName(), collaborator);
    // Collaborator can get private repo
    openSvnRepository(server, testPrivateRepository, collaborator, collaboratorPassword).getLatestRevision();
  }
}
 
Example 3
Source File: HttpRequestAnnotationScenarioMapperTest.java    From citrus-simulator with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMappingKey() {
    scenarioMapper.setScenarioList(Arrays.asList(new IssueScenario(),
                                                new FooScenario(),
                                                new GetFooScenario(),
                                                new PutFooScenario(),
                                                new OtherScenario()));

    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo")), "FooScenario");
    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.GET)), "GetFooScenario");
    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.PUT)), "PutFooScenario");
    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/other")), "OtherScenario");
    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.GET)), "IssueScenario");
    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.DELETE)), "IssueScenario");
    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT)), "default");
    Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar")), "default");
    Assert.assertEquals(scenarioMapper.getMappingKey(null), "default");

    scenarioMapper.setUseDefaultMapping(false);

    Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT)));
    Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar")));
    Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(null));
}
 
Example 4
Source File: DisableFTEnableOnClassTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * failAndRetryOnce is annotated with maxRetries = 1 so it is expected to execute 2 times.
 */
@Test
public void testRetryEnabled() {
    // Always get a TestException
    Assert.assertThrows(TestException.class, () -> disableClient.failAndRetryOnce());
    // Should get two attempts if retry is enabled
    Assert.assertEquals(disableClient.getFailAndRetryOnceCounter(), 2, "Retry enabled - should be 2 executions");
}
 
Example 5
Source File: SetProxyTest.java    From distkv with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDropByKey() {
  Set<String> set = ImmutableSet.of("v1", "v2", "v3");

  DistkvClient client = newDistkvClient();
  client.sets().put("k1", set);
  client.drop("k1");

  // This method will throw a DistkvException if we drop the nonexistent key in store.
  Assert.assertThrows(DistkvException.class,
      () -> client.sets().get("k1"));
  client.disconnect();
}
 
Example 6
Source File: DisableAnnotationGloballyEnableOnClassDisableOnMethod.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * Test that a Fallback service is ignored when service fails.
 * 
 * Retry is enabled at the class level and not disabled for this method so we expect to get two executions
 */
@Test
public void testFallbackDisabled() {
    // Throw TestException because Fallback is disabled
    Assert.assertThrows(TestException.class, () -> disableClient.failRetryOnceThenFallback());
    // One execution because Retry is enabled
    Assert.assertEquals(disableClient.getFailRetryOnceThenFallbackCounter(), 2, "Retry enabled - should be 2 executions");
}
 
Example 7
Source File: SlistProxyTest.java    From distkv with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDistkvKeyDuplicatedException() {
  distkvClient = newDistkvClient();
  testPut();
  Assert.assertThrows(
      DistkvKeyDuplicatedException.class, this::testPut);
  distkvClient.disconnect();
}
 
Example 8
Source File: BasicOperationTest.java    From distkv with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDrop() throws InvalidProtocolBufferException {
  DistkvClient client = newDistkvClient();
  dummyPut(client);
  //Drop expiration.
  client.drop("k1");
  Assert.assertThrows(KeyNotFoundException.class, () -> client.strs().get("k1"));
  client.disconnect();
}
 
Example 9
Source File: VariantContextTestUtilsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(dataProvider = "alleleRemapExamples")
public void testOrderSortAlleles(VariantContext actual, VariantContext expected, boolean shouldSucceed) {
    VCFHeader header = VariantContextTestUtils.getCompleteHeader();

    if (shouldSucceed) {
        VariantContextTestUtils.assertVariantContextsAreEqualAlleleOrderIndependent(actual, expected, Collections.emptyList(), Collections.emptyList(), header);
    } else {
        Assert.assertThrows(AssertionError.class, () -> VariantContextTestUtils.assertVariantContextsAreEqualAlleleOrderIndependent(actual, expected, Collections.emptyList(), Collections.emptyList(), header));
    }
}
 
Example 10
Source File: DisableFTEnableGloballyTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * CircuitBreaker is enabled on the method so the policy should be applied
 */
@Test
public void testCircuitBreaker() {
    // Always get TestException on first execution
    Assert.assertThrows(TestException.class, () -> disableClient.failWithCircuitBreaker());
    // Should get CircuitBreakerOpenException on second execution because CircuitBreaker is enabled
    Assert.assertThrows(CircuitBreakerOpenException.class, () -> disableClient.failWithCircuitBreaker());
}
 
Example 11
Source File: TestClusterUtil.java    From rubix with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyRubixSite()
{
  Configuration configuration = new Configuration();
  ClusterUtil.rubixSiteExists = new AtomicReference<>();
  rubixSiteXmlName = workingDirectory + "/../rubix-common/src/test/resources/faulty-rubix-site.xml";
  CacheConfig.setRubixSiteLocation(configuration, rubixSiteXmlName);
  Assert.assertThrows(Exception.class, () -> ClusterUtil.applyRubixSiteConfig(configuration));
}
 
Example 12
Source File: DisableAnnotationOnClassEnableOnMethodTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * CircuitBreaker is enabled on the method so the policy should be applied
 */
@Test
public void testCircuitBreaker() {
    // Always get TestException on first execution
    Assert.assertThrows(TestException.class, () -> disableClient.failWithCircuitBreaker());
    // Should get CircuitBreakerOpenException on second execution because CircuitBreaker is enabled
    Assert.assertThrows(CircuitBreakerOpenException.class, () -> disableClient.failWithCircuitBreaker());
}
 
Example 13
Source File: TableFeatureUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testTableFeatureGetters() {
    final TableFeature feature = new TableFeature(
            new SimpleInterval("1", 10, 100),
            Arrays.asList("1", "2", "3"),
            Arrays.asList("a", "b", "c"));

    // test all values and columns
    Assert.assertEquals(feature.getAllValues(), Arrays.asList("1", "2", "3"));
    Assert.assertEquals(feature.getHeader(), Arrays.asList("a", "b", "c"));

    // test retrieval of all the elements one by one and its mapping
    for (int i = 0; i < 3; i++) {
        final String colName = feature.getHeader().get(i);
        Assert.assertEquals(feature.getValue(i), feature.get(colName));
    }

    // test getValuesTo
    Assert.assertEquals(feature.getValuesTo(1), Arrays.asList("1"));
    Assert.assertEquals(feature.getValuesTo(2), Arrays.asList("1", "2"));

    // test that invalid columns throw an Illegal argument exception
    Assert.assertThrows(IllegalArgumentException.class, () -> feature.getValue(3));
    Assert.assertThrows(IllegalArgumentException.class, () -> feature.getValue(-1));
    Assert.assertThrows(IllegalArgumentException.class, () -> feature.getValuesTo(4));
    Assert.assertThrows(IllegalArgumentException.class, () -> feature.getValuesTo(-1));
}
 
Example 14
Source File: ListProxyTest.java    From distkv with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDrop() {
  DistkvClient client = newDistkvClient();
  client.lists().put("k1", ImmutableList.of("v1", "v2", "v3"));
  client.drop("k1");
  Assert.assertThrows(KeyNotFoundException.class, () -> client.lists().get("k1"));
  client.disconnect();
}
 
Example 15
Source File: ParseBasicOperationCommandTest.java    From distkv with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testTTLManyKeys() {
  final String command = "ttl k1 k2 k3";
  Assert.assertThrows(DistkvException.class, () -> distkvParser.parse(command));
}
 
Example 16
Source File: ParseBasicOperationCommandTest.java    From distkv with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testDropWithoutKey() {
  final String command = "drop";
  Assert.assertThrows(DistkvException.class, () -> distkvParser.parse(command));
}
 
Example 17
Source File: DisableFTEnableOnMethodTest.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
/**
 * Test Timeout is enabled, should fail with a timeout exception
 */
@Test
public void testTimeout() {
    // Expect TimeoutException because Timeout is enabled and method will time out
    Assert.assertThrows(TimeoutException.class, () -> disableClient.failWithTimeout());
}
 
Example 18
Source File: DisableFTEnableGloballyTest.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
/**
 * Test Timeout is enabled, should fail with a timeout exception
 */
@Test
public void testTimeout() {
    // Expect TimeoutException because Timeout is enabled and method will time out
    Assert.assertThrows(TimeoutException.class, () -> disableClient.failWithTimeout());
}
 
Example 19
Source File: DisableAnnotationOnClassEnableOnMethodTest.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
/**
 * Test Timeout is enabled, should fail with a timeout exception
 */
@Test
public void testTimeout() {
    // Expect TimeoutException because Timeout is enabled and method will time out
    Assert.assertThrows(TimeoutException.class, () -> disableClient.failWithTimeout());
}
 
Example 20
Source File: DisableAnnotationOnMethodsTest.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
/**
 * Test Timeout is disabled, should wait two seconds and then get a TestException
 */
@Test
public void testTimeout() {
    // Expect TestException because Timeout is disabled and will not fire
    Assert.assertThrows(TestException.class, () -> disableClient.failWithTimeout());
}