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

The following examples show how to use org.testng.Assert#expectThrows() . 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: StreamingPythonExecutorIntegrationTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test()
public void testRequirePythonEnvironment() {
    // This test is deliberately left out of the "python" test group in order to ensure that
    // it only executes when the Python environment has *NOT* been properly established. Also,
    // skip this test if we're running on the Docker because the Python environment is always
    // activated there.
    if (isGATKDockerContainer()) {
        throw new SkipException("Python environment validation test must be skipped when running on the Docker");
    }

    // validate that we throw if the GATK Python environment is not active
    final RuntimeException rte = Assert.expectThrows(RuntimeException.class, ()-> {
        final StreamingPythonScriptExecutor<String> streamingPythonExecutor =
                new StreamingPythonScriptExecutor<>(PythonScriptExecutor.PythonExecutableName.PYTHON3, true);
        streamingPythonExecutor.start(Collections.emptyList());
    });

    // make sure that the underlying cause is actually a PythonScriptExecutorException
    Assert.assertEquals(rte.getCause().getClass(), PythonScriptExecutorException.class);
}
 
Example 2
Source File: MpqTests.java    From JMPQ3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuplicatePaths() throws IOException {
    File[] mpqs = getMpqs();
    for (File mpq : mpqs) {
        if (mpq.getName().equals("invalidHashSize.scx_copy")) {
            continue;
        }
        try (JMpqEditor mpqEditor = new JMpqEditor(mpq, MPQOpenOption.FORCE_V0)) {
            if (!mpqEditor.isCanWrite()) {
                return;
            }
            mpqEditor.insertByteArray("Test", "bytesasdadasdad".getBytes());
            Assert.expectThrows(IllegalArgumentException.class, () -> {
                mpqEditor.insertByteArray("Test", "bytesasdadasdad".getBytes());
            });
            Assert.expectThrows(IllegalArgumentException.class, () -> {
                mpqEditor.insertByteArray("teST", "bytesasdadasdad".getBytes());
            });
            mpqEditor.insertByteArray("teST", "bytesasdadasdad".getBytes(), true);
        }
    }
}
 
Example 3
Source File: ConditionalWaitTests.java    From aquality-selenium-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeoutExceptionShouldBeThrownIfConditionIsNotMetAndTimeoutIsOver() {
    Timer timer = new Timer();
    Assert.expectThrows(TimeoutException.class, () -> getConditionalWait().waitForTrue(() ->
    {
        timer.start();
        return false;
    }, waitForTimeoutCondition, waitForTimeoutPolling, "Condition should be true"));
    DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition, defaultDeviation);
    assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString());
}
 
Example 4
Source File: DeprecatedToolsRegistryTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testRunMissingButNotRegisteredTool() {
    final String missingButNotRegisteredTool = "MadeUpToolNotInTheRegistry";

    Assert.assertNull(DeprecatedToolsRegistry.getToolDeprecationInfo(missingButNotRegisteredTool));

    final Main main = new Main();
    final UserException e = Assert.expectThrows(
            UserException.class,
            () -> main.instanceMain( new String[] {missingButNotRegisteredTool} )
    );
    Assert.assertTrue(e.getMessage().contains(main.getUnknownCommandMessage(Collections.emptySet(), missingButNotRegisteredTool)));
}
 
Example 5
Source File: DeprecatedToolsRegistryTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testRunMissingDeprecatedTool() {
    final String missingTool = "IndelRealigner";

    final UserException e = Assert.expectThrows(
            UserException.class,
            () -> new Main().instanceMain( new String[] {missingTool} )
    );
    Assert.assertTrue(e.getMessage().contains(DeprecatedToolsRegistry.getToolDeprecationInfo(missingTool)));
}
 
Example 6
Source File: CompareIntervalListsIntegrationTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(dataProvider = "getIntervalFiles")
public void testCompareIntervals(File left, File right, boolean expectedMatch) {
    final ArgumentsBuilder args = new ArgumentsBuilder();
    args.addReference(new File(hg19MiniReference))
            .add("L", left)
            .add("L2", right);

    if(expectedMatch) {
        runCommandLine(args);
    } else {
        Assert.expectThrows(UserException.class, () -> runCommandLine(args));
    }

}
 
Example 7
Source File: JobSpecResolverTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithResolutionAction() throws Exception {

	Config sysConfig = ConfigFactory.empty();

	SecureJobTemplate insecureTemplate = Mockito.mock(SecureJobTemplate.class);
	Mockito.when(insecureTemplate.getResolvedConfig(Mockito.any(Config.class))).thenAnswer(i -> (Config) i.getArguments()[0]);
	Mockito.when(insecureTemplate.isSecure()).thenReturn(false);

	SecureJobTemplate secureTemplate = Mockito.mock(SecureJobTemplate.class);
	Mockito.when(secureTemplate.getResolvedConfig(Mockito.any(Config.class))).thenAnswer(i -> (Config) i.getArguments()[0]);
	Mockito.when(secureTemplate.isSecure()).thenReturn(true);

	JobCatalogWithTemplates catalog = Mockito.mock(JobCatalogWithTemplates.class);
	Mockito.when(catalog.getTemplate(Mockito.eq(URI.create("my://template.insecure")))).thenReturn(insecureTemplate);
	Mockito.when(catalog.getTemplate(Mockito.eq(URI.create("my://template.secure")))).thenReturn(secureTemplate);

	JobSpecResolver resolver = JobSpecResolver.builder(sysConfig).jobCatalog(catalog)
			// This resolution action should block any resolution that does not use a secure template
			.jobResolutionAction(new SecureTemplateEnforcer()).build();

	JobSpec jobSpec = JobSpec.builder()
			.withConfig(ConfigFactory.parseMap(ImmutableMap.of("key", "value")))
			.withTemplate(URI.create("my://template.insecure")).build();
	Assert.expectThrows(JobTemplate.TemplateException.class, () -> resolver.resolveJobSpec(jobSpec));

	JobSpec jobSpec2 = JobSpec.builder()
			.withConfig(ConfigFactory.parseMap(ImmutableMap.of("key", "value")))
			.withTemplate(URI.create("my://template.secure")).build();
	ResolvedJobSpec resolvedJobSpec = resolver.resolveJobSpec(jobSpec2);

	Assert.assertEquals(resolvedJobSpec.getOriginalJobSpec(), jobSpec2);
	Assert.assertEquals(resolvedJobSpec.getConfig().entrySet().size(), 1);
	Assert.assertEquals(resolvedJobSpec.getConfig().getString("key"), "value");
}
 
Example 8
Source File: ConditionalWaitTests.java    From aquality-selenium-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeoutExceptionShouldBeThrownIfConditionIsNotMetAndDefaultTimeoutIsOver() {
    Timer timer = new Timer();
    Assert.expectThrows(TimeoutException.class, () -> getConditionalWait().waitForTrue(() ->
    {
        timer.start();
        return false;
    }, "Condition should be true"));
    DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition(), defaultDeviation);
    assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString());
}
 
Example 9
Source File: MpqTests.java    From JMPQ3 with Apache License 2.0 4 votes vote down vote up
@Test
public void testException() {
    Assert.expectThrows(JMpqException.class, () -> new BlockTable(ByteBuffer.wrap(new byte[0])).getBlockAtPos(-1));
}
 
Example 10
Source File: SimpleSchemaTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Test
public void newProducerForMessageSchemaOnTopicWithMultiVersionSchema() throws Exception {
    String topic = "my-property/my-ns/schema-test";
    Schema<V1Data> v1Schema = Schema.AVRO(V1Data.class);
    byte[] v1SchemaBytes = v1Schema.getSchemaInfo().getSchema();
    AvroWriter<V1Data> v1Writer = new AvroWriter<>(
            new Parser().parse(new ByteArrayInputStream(v1SchemaBytes)));
    Schema<V2Data> v2Schema = Schema.AVRO(V2Data.class);
    byte[] v2SchemaBytes = v2Schema.getSchemaInfo().getSchema();
    AvroWriter<V2Data> v2Writer = new AvroWriter<>(
            new Parser().parse(new ByteArrayInputStream(v2SchemaBytes)));
    try (Producer<V1Data> ignored = pulsarClient.newProducer(v1Schema)
                                                .topic(topic).create()) {
    }
    try (Producer<V2Data> p = pulsarClient.newProducer(Schema.AVRO(V2Data.class))
                                          .topic(topic).create()) {
        p.send(new V2Data(-1, -1));
    }
    V1Data dataV1 = new V1Data(2);
    V2Data dataV2 = new V2Data(3, 5);
    byte[] contentV1 = v1Writer.write(dataV1);
    byte[] contentV2 = v2Writer.write(dataV2);
    try (Producer<byte[]> p = pulsarClient.newProducer(Schema.AUTO_PRODUCE_BYTES())
                                          .topic(topic).create();
            Consumer<V2Data> c = pulsarClient.newConsumer(v2Schema)
                                             .topic(topic)
                                             .subscriptionName("sub1").subscribe()) {
        Assert.expectThrows(SchemaSerializationException.class, () -> p.send(contentV1));

        p.newMessage(Schema.AUTO_PRODUCE_BYTES(Schema.AVRO(V1Data.class)))
         .value(contentV1).send();
        p.send(contentV2);
        Message<V2Data> msg1 = c.receive();
        V2Data msg1Value = msg1.getValue();
        Assert.assertEquals(dataV1.i, msg1Value.i);
        Assert.assertNull(msg1Value.j);
        Assert.assertEquals(msg1.getSchemaVersion(), new LongSchemaVersion(0).bytes());

        Message<V2Data> msg2 = c.receive();
        Assert.assertEquals(dataV2, msg2.getValue());
        Assert.assertEquals(msg2.getSchemaVersion(), new LongSchemaVersion(1).bytes());

        try {
            p.newMessage(Schema.BYTES).value(contentV1).send();
            if (schemaValidationEnforced) {
                Assert.fail("Shouldn't be able to send to a schema'd topic with no schema"
                                    + " if SchemaValidationEnabled is enabled");
            }
            Message<V2Data> msg3 = c.receive();
            Assert.assertEquals(msg3.getSchemaVersion(), SchemaVersion.Empty.bytes());
        } catch (PulsarClientException e) {
            if (schemaValidationEnforced) {
                Assert.assertTrue(e instanceof IncompatibleSchemaException);
            } else {
                Assert.fail("Shouldn't throw IncompatibleSchemaException"
                                    + " if SchemaValidationEnforced is disabled");
            }
        }
    }
}
 
Example 11
Source File: BrowserTabsTests.java    From aquality-selenium-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testShouldThrowIfSwitchToNewTabByIncorrectIndex() {
    Assert.expectThrows(IndexOutOfBoundsException.class, () -> AqualityServices.getBrowser().tabs().switchToTab(10, true));
}
 
Example 12
Source File: AuthLdapTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sslModes")
public void invalidPassword(@NotNull DirectoryServerNet serverNet) {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser(EmbeddedDirectoryServer.ADMIN_USERNAME, "wrongpassword", serverNet));
}
 
Example 13
Source File: AuthLdapTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sslModes")
public void invalidUser(@NotNull DirectoryServerNet serverNet) {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser("ldapadmin2", EmbeddedDirectoryServer.ADMIN_PASSWORD, serverNet));
}
 
Example 14
Source File: AuthLdapTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sslModes")
public void anonymousUserDenies(@NotNull DirectoryServerNet serverNet) {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkAnonymous(false, serverNet));
}
 
Example 15
Source File: GitLabIntegrationTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Test
void invalidPassword() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser(root, "wrongpassword"));
}
 
Example 16
Source File: GitLabIntegrationTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Test
void invalidUser() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser("wronguser", rootPassword));
}
 
Example 17
Source File: GiteaIntegrationTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Test
void testInvalidPassword() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser(administrator, "wrongpassword"));
}
 
Example 18
Source File: GiteaIntegrationTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Test
void testInvalidUser() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser("wronguser", administratorPassword));
}