Search in sources :

Example 1 with APPLICATION_OCTET_STREAM_TYPE

use of javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE in project component-runtime by Talend.

the class ComponentResourceTest method getDependency.

@Test
void getDependency(final TestInfo info, final TemporaryFolder folder) {
    final Function<String, File> download = id -> {
        final InputStream stream = base.path("component/dependency/{id}").resolveTemplate("id", id).request(APPLICATION_OCTET_STREAM_TYPE).get(InputStream.class);
        final File file = new File(folder.getRoot(), info.getTestMethod().get().getName() + ".jar");
        try (final OutputStream outputStream = new FileOutputStream(file)) {
            IO.copy(stream, outputStream);
        } catch (final IOException e) {
            throw new IllegalStateException(e);
        }
        return file;
    };
    final Consumer<File> jarValidator = file -> {
        assertTrue(file.exists());
        try (final JarFile jar = new JarFile(file)) {
            assertTrue(jar.entries().hasMoreElements());
        } catch (final IOException e) {
            fail(e.getMessage());
        }
    };
    final File zipLock = download.apply("org.apache.tomee:ziplock:jar:7.0.4");
    jarValidator.accept(zipLock);
    final File component = download.apply(client.getJdbcId());
    jarValidator.accept(component);
}
Also used : MonoMeecrowaveConfig(org.apache.meecrowave.junit5.MonoMeecrowaveConfig) JarFile(java.util.jar.JarFile) Collections.singletonList(java.util.Collections.singletonList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) MediaType(javax.ws.rs.core.MediaType) Link(org.talend.sdk.component.server.front.model.Link) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Map(java.util.Map) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) WebsocketClient(org.talend.sdk.component.server.test.websocket.WebsocketClient) DependencyDefinition(org.talend.sdk.component.server.front.model.DependencyDefinition) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) APPLICATION_OCTET_STREAM_TYPE(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE) ComponentClient(org.talend.sdk.component.server.test.ComponentClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) PropertyValidation(org.talend.sdk.component.server.front.model.PropertyValidation) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Dependencies(org.talend.sdk.component.server.front.model.Dependencies) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) Entity.entity(javax.ws.rs.client.Entity.entity) DeploymentException(javax.websocket.DeploymentException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) ComponentIndices(org.talend.sdk.component.server.front.model.ComponentIndices) File(java.io.File) Consumer(java.util.function.Consumer) IO(org.apache.ziplock.IO) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Base64 (java.util.Base64)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 JarFile (java.util.jar.JarFile)1 Inject (javax.inject.Inject)1