Search in sources :

Example 1 with CitrusRuntimeException

use of com.consol.citrus.exceptions.CitrusRuntimeException in project camelinaction2 by camelinaction.

the class CitrusIT method stopAndWaitForGracefulShutdown.

/**
 * Stop and wait for graceful shutdown of Camel context before closing the test.
 */
private void stopAndWaitForGracefulShutdown() {
    // stop the Camel context with custom test action.
    action(new AbstractTestAction() {

        @Override
        public void doExecute(TestContext context) {
            try {
                orderService.stop();
            } catch (Exception e) {
                throw new CitrusRuntimeException("Failed to stop Camel context");
            }
        }
    });
    waitFor().condition(new AbstractCondition() {

        @Override
        public boolean isSatisfied(TestContext context) {
            return orderService.isStopped();
        }

        @Override
        public String getSuccessMessage(TestContext context) {
            return "Successfully stopped Camel context";
        }

        @Override
        public String getErrorMessage(TestContext context) {
            return "Failed to stop Camel context";
        }
    });
}
Also used : AbstractTestAction(com.consol.citrus.actions.AbstractTestAction) TestContext(com.consol.citrus.context.TestContext) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException) AbstractCondition(com.consol.citrus.condition.AbstractCondition) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException)

Example 2 with CitrusRuntimeException

use of com.consol.citrus.exceptions.CitrusRuntimeException in project syndesis by syndesisio.

the class FtpTestSupport method setupFtpUserHome.

@BeforeClass
public static void setupFtpUserHome() {
    try {
        Path publicUserDir = getFtpUserHome().resolve("public");
        if (Files.exists(publicUserDir)) {
            try (Stream<Path> files = Files.walk(publicUserDir)) {
                files.forEach(path -> {
                    try {
                        Files.delete(path);
                    } catch (IOException e) {
                        LOG.warn("Failed to delete file", e);
                    }
                });
            }
        } else {
            Files.createDirectories(publicUserDir);
        }
        Files.copy(new ClassPathResource("todo.json", FtpToDB_IT.class).getFile().toPath(), publicUserDir.resolve("todo.json"));
    } catch (IOException e) {
        throw new CitrusRuntimeException("Failed to setup files in ftp user home directory", e);
    }
}
Also used : Path(java.nio.file.Path) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) BeforeClass(org.junit.BeforeClass)

Example 3 with CitrusRuntimeException

use of com.consol.citrus.exceptions.CitrusRuntimeException in project citrus-samples by christophd.

the class ClearUserHomeDirAction method doExecute.

@Override
public void doExecute(TestContext context) {
    try {
        if (Files.exists(Paths.get(new FileSystemResource(userHomePath).getURI()))) {
            Files.walkFileTree(Paths.get(new FileSystemResource(userHomePath).getURI()), new SimpleFileVisitor<Path>() {

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    Files.deleteIfExists(file);
                    return FileVisitResult.CONTINUE;
                }
            });
            Files.deleteIfExists(Paths.get(new FileSystemResource(userHomePath).getURI()));
        }
    } catch (IOException e) {
        throw new CitrusRuntimeException("Failed to delete user home directory", e);
    }
}
Also used : CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 4 with CitrusRuntimeException

use of com.consol.citrus.exceptions.CitrusRuntimeException in project yaks by citrusframework.

the class VerifyIntegrationAction method verifyIntegrationPod.

/**
 * Wait for given pod to be in given state.
 * @param name
 * @param phase
 * @param namespace
 * @return
 */
private Pod verifyIntegrationPod(String name, String phase, String namespace) {
    for (int i = 0; i < maxAttempts; i++) {
        Pod pod = getIntegrationPod(name, phase, namespace);
        if (pod != null) {
            LOG.info(String.format("Verified integration pod '%s' state '%s'!", name, phase));
            return pod;
        }
        LOG.warn(String.format("Waiting for integration '%s' in state '%s'- retry in %s ms", name, phase, delayBetweenAttempts));
        try {
            Thread.sleep(delayBetweenAttempts);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while waiting for integration pod state", e);
        }
    }
    throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), new CitrusRuntimeException(String.format("Failed to verify integration '%s' - " + "is not in state '%s' after %d attempts", name, phase, maxAttempts)));
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) ActionTimeoutException(com.consol.citrus.exceptions.ActionTimeoutException) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException)

Example 5 with CitrusRuntimeException

use of com.consol.citrus.exceptions.CitrusRuntimeException in project yaks by citrusframework.

the class CreateKameletAction method createKamelet.

private void createKamelet(TestContext context) {
    final Kamelet kamelet;
    if (resource != null) {
        try {
            String resolvedSource;
            if (supportVariables) {
                resolvedSource = context.replaceDynamicContentInString(FileUtils.readToString(resource));
            } else {
                resolvedSource = FileUtils.readToString(resource);
            }
            kamelet = KubernetesSupport.yaml().loadAs(resolvedSource, Kamelet.class);
        } catch (IOException e) {
            throw new CitrusRuntimeException(String.format("Failed to load Kamelet from resource %s", name + ".kamelet.yaml"));
        }
    } else {
        if (definition.getTitle() != null) {
            definition.setTitle(context.replaceDynamicContentInString(definition.getTitle()));
        }
        if (definition.getDescription() != null) {
            definition.setDescription(context.replaceDynamicContentInString(definition.getDescription()));
        }
        definition.setProperties(context.resolveDynamicValuesInMap(definition.getProperties()));
        definition.setRequired(context.resolveDynamicValuesInList(definition.getRequired()));
        final Kamelet.Builder builder = new Kamelet.Builder().name(context.replaceDynamicContentInString(name)).definition(definition);
        if (template != null) {
            builder.template(context.replaceDynamicContentInString(template));
        }
        if (source != null) {
            builder.source(source.getName(), context.replaceDynamicContentInString(source.getContent()));
        }
        if (dependencies != null && !dependencies.isEmpty()) {
            builder.dependencies(context.resolveDynamicValuesInList(dependencies));
        }
        if (types != null && !types.isEmpty()) {
            builder.types(context.resolveDynamicValuesInMap(types));
        }
        kamelet = builder.build();
    }
    if (LOG.isDebugEnabled()) {
        try {
            LOG.debug(KubernetesSupport.json().writeValueAsString(kamelet));
        } catch (JsonProcessingException e) {
            LOG.warn("Unable to dump Kamelet data", e);
        }
    }
    CustomResourceDefinitionContext ctx = CamelKSupport.kameletCRDContext(CamelKSettings.getKameletApiVersion());
    getKubernetesClient().customResources(ctx, Kamelet.class, KameletList.class).inNamespace(namespace(context)).createOrReplace(kamelet);
    LOG.info(String.format("Successfully created Kamelet '%s'", kamelet.getMetadata().getName()));
}
Also used : CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) Kamelet(org.citrusframework.yaks.camelk.model.Kamelet) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

CitrusRuntimeException (com.consol.citrus.exceptions.CitrusRuntimeException)27 IOException (java.io.IOException)12 Given (io.cucumber.java.en.Given)7 ActionTimeoutException (com.consol.citrus.exceptions.ActionTimeoutException)5 ClassPathResource (org.springframework.core.io.ClassPathResource)4 Resource (org.springframework.core.io.Resource)4 CitrusResource (com.consol.citrus.annotations.CitrusResource)3 TestContext (com.consol.citrus.context.TestContext)2 PageValidator (com.consol.citrus.selenium.model.PageValidator)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 CustomResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext)2 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Map (java.util.Map)2 Properties (java.util.Properties)2 SSLContext (javax.net.ssl.SSLContext)2 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)2