Search in sources :

Example 1 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project noip by davidecolombo.

the class AppTest method testSystemExitWithStatus.

@Test
@ExpectSystemExitWithStatus(1)
void testSystemExitWithStatus() throws IOException {
    try (MockedStatic<INoIpApi> mockedApi = Mockito.mockStatic(INoIpApi.class);
        MockedStatic<ObjectMapperUtils> mockedJsonUtils = Mockito.mockStatic(ObjectMapperUtils.class)) {
        INoIpApi api = Mockito.mock(INoIpApi.class);
        Mockito.when(api.update(// hostname
        Mockito.anyString(), // ip
        Mockito.anyString())).thenReturn(Calls.response(String.format("%s %s", "nochg", TestUtils.LOOPBACK_ADDRESS)));
        mockedApi.when(() -> INoIpApi.build(// username
        Mockito.anyString(), // password
        Mockito.anyString(), // user-agent
        Mockito.anyString())).thenReturn(api);
        ObjectMapper objectMapper = Mockito.mock(ObjectMapper.class, Mockito.RETURNS_DEEP_STUBS);
        // fake settings
        Mockito.when(objectMapper.readValue(Mockito.any(File.class), Mockito.eq(NoIpSettings.class))).thenReturn(TestUtils.createMockedNoIpSettings());
        // fake ipify
        IpifyResponse mockedIpifyResponse = new IpifyResponse();
        mockedIpifyResponse.setIp(TestUtils.LOOPBACK_ADDRESS);
        Mockito.when(objectMapper.readValue(Mockito.any(URL.class), Mockito.eq(IpifyResponse.class))).thenReturn(mockedIpifyResponse);
        mockedJsonUtils.when(ObjectMapperUtils::createObjectMapper).thenReturn(objectMapper);
        Assertions.assertNotNull(ObjectMapperUtils.createObjectMapper());
        App.main(new String[] { "-settings", "dummy.json" });
    // wait for system exit with exit code
    }
}
Also used : NoIpSettings(space.davidecolombo.noip.noip.NoIpSettings) INoIpApi(space.davidecolombo.noip.noip.INoIpApi) IpifyResponse(space.davidecolombo.noip.ipify.IpifyResponse) ObjectMapperUtils(space.davidecolombo.noip.utils.ObjectMapperUtils) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URL(java.net.URL) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Example 2 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project SchemaCrawler by schemacrawler.

the class LinterConfigsDispatchTest method testSystemExitLinterConfigExecutable.

@Test
@ExpectSystemExitWithStatus(1)
public void testSystemExitLinterConfigExecutable(final TestContext testContext, final Connection connection) throws Exception {
    final Config additionalConfig = new Config();
    additionalConfig.put("lint-dispatch", "terminate_system");
    executableLint(connection, "/schemacrawler-linter-configs-with-dispatch.yaml", additionalConfig, "schemacrawler-linter-configs-with-dispatch");
    checkSystemErrLog(testContext);
}
Also used : LinterConfig(schemacrawler.tools.lint.config.LinterConfig) Config(schemacrawler.tools.options.Config) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Example 3 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project keycloak-config-cli by adorsys.

the class CommandLineImportFilesIT method testImportFile.

@Test
@ExpectSystemExitWithStatus(0)
void testImportFile() {
    KeycloakConfigApplication.main(new String[] { "--import.path=src/test/resources/import-files/cli/file.json" });
    RealmRepresentation fileRealm = keycloakProvider.getInstance().realm("file").toRepresentation();
    assertThat(fileRealm.getRealm(), is("file"));
    assertThat(fileRealm.isEnabled(), is(true));
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Example 4 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project pgpainless by pgpainless.

the class SignUsingPublicKeyBehaviorTest method testSignatureCreationAndVerification.

@Test
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
public void testSignatureCreationAndVerification() throws IOException {
    originalSout = System.out;
    InputStream originalIn = System.in;
    // Write alice key to disc
    File aliceKeyFile = new File(tempDir, "alice.key");
    assertTrue(aliceKeyFile.createNewFile());
    OutputStream aliceKeyOut = new FileOutputStream(aliceKeyFile);
    Streams.pipeAll(new ByteArrayInputStream(KEY_THAT_IS_A_CERT.getBytes(StandardCharsets.UTF_8)), aliceKeyOut);
    aliceKeyOut.close();
    // Write alice pub key to disc
    File aliceCertFile = new File(tempDir, "alice.pub");
    assertTrue(aliceCertFile.createNewFile());
    OutputStream aliceCertOut = new FileOutputStream(aliceCertFile);
    Streams.pipeAll(new ByteArrayInputStream(KEY_THAT_IS_A_CERT.getBytes(StandardCharsets.UTF_8)), aliceCertOut);
    aliceCertOut.close();
    // Write test data to disc
    String data = "If privacy is outlawed, only outlaws will have privacy.\n";
    File dataFile = new File(tempDir, "data");
    assertTrue(dataFile.createNewFile());
    FileOutputStream dataOut = new FileOutputStream(dataFile);
    Streams.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), dataOut);
    dataOut.close();
    // Sign test data
    FileInputStream dataIn = new FileInputStream(dataFile);
    System.setIn(dataIn);
    File sigFile = new File(tempDir, "sig.asc");
    assertTrue(sigFile.createNewFile());
    FileOutputStream sigOut = new FileOutputStream(sigFile);
    System.setOut(new PrintStream(sigOut));
    PGPainlessCLI.execute("sign", "--armor", aliceKeyFile.getAbsolutePath());
    System.setIn(originalIn);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Example 5 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project pgpainless by pgpainless.

the class DetachInbandSignatureAndMessageTest method existingSignatureOutCausesException.

@Test
@ExpectSystemExitWithStatus(SOPGPException.OutputExists.EXIT_CODE)
public void existingSignatureOutCausesException() throws IOException {
    // Clearsigned In
    ByteArrayInputStream clearSignedIn = new ByteArrayInputStream(CLEAR_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8));
    System.setIn(clearSignedIn);
    // Plaintext Out
    ByteArrayOutputStream msgOut = new ByteArrayOutputStream();
    System.setOut(new PrintStream(msgOut));
    // Detach
    File existingSigFile = new File(tempDir, "sig.existing");
    assertTrue(existingSigFile.createNewFile());
    PGPainlessCLI.main(new String[] { "detach-inband-signature-and-message", "--signatures-out=" + existingSigFile.getAbsolutePath() });
}
Also used : PrintStream(java.io.PrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Aggregations

ExpectSystemExitWithStatus (com.ginsberg.junit.exit.ExpectSystemExitWithStatus)9 Test (org.junit.jupiter.api.Test)9 File (java.io.File)3 SystemExitPreventedException (com.ginsberg.junit.exit.SystemExitPreventedException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 PrintStream (java.io.PrintStream)2 HashMap (java.util.HashMap)2 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 InfoLevel (schemacrawler.schemacrawler.InfoLevel)1 BaseSqliteTest (schemacrawler.test.utility.BaseSqliteTest)1 SchemaTextDetailType (schemacrawler.tools.command.text.schema.options.SchemaTextDetailType)1 TextOutputFormat (schemacrawler.tools.command.text.schema.options.TextOutputFormat)1