Search in sources :

Example 1 with Link

use of org.talend.sdk.component.server.front.model.Link in project component-runtime by Talend.

the class ComponentResourceTest method assertComponent.

private void assertComponent(final String plugin, final String family, final String name, final String displayName, final Iterator<ComponentIndex> component, final int version) {
    assertTrue(component.hasNext());
    final ComponentIndex data = component.next();
    assertEquals(family, data.getId().getFamily());
    assertEquals(name, data.getId().getName());
    assertEquals(plugin, data.getId().getPlugin());
    assertEquals(displayName, data.getDisplayName());
    assertEquals(version, data.getVersion());
    assertEquals(singletonList("Misc"), data.getCategories());
    assertEquals(1, data.getLinks().size());
    final Link link = data.getLinks().iterator().next();
    assertEquals("Detail", link.getName());
    assertEquals("/component/details?identifiers=" + Base64.getUrlEncoder().withoutPadding().encodeToString((plugin + "#" + family + "#" + name).getBytes(StandardCharsets.UTF_8)), link.getPath());
    assertEquals(MediaType.APPLICATION_JSON, link.getContentType());
    if ("jdbc".equals(data.getId().getFamily()) && "input".equals(data.getId().getName())) {
        assertEquals("db-input", data.getIcon().getIcon());
        assertNotNull(data.getIcon().getCustomIcon());
        assertEquals("image/png", data.getIcon().getCustomIconType());
    } else {
        assertEquals("default", data.getIcon().getIcon());
    }
}
Also used : ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) Link(org.talend.sdk.component.server.front.model.Link)

Example 2 with Link

use of org.talend.sdk.component.server.front.model.Link in project component-runtime by Talend.

the class ComponentResource method toComponentIndex.

private ComponentIndex toComponentIndex(final ClassLoader loader, final Locale locale, final String plugin, final ComponentFamilyMeta.BaseMeta meta, final ComponentManager.OriginalId originalId, final boolean includeIcon) {
    final String icon = meta.getIcon();
    final String familyIcon = meta.getParent().getIcon();
    final IconResolver.Icon iconContent = iconResolver.resolve(loader, icon);
    final IconResolver.Icon iconFamilyContent = iconResolver.resolve(loader, familyIcon);
    return new ComponentIndex(new ComponentId(meta.getId(), meta.getParent().getId(), plugin, ofNullable(originalId).map(ComponentManager.OriginalId::getValue).orElse(plugin), meta.getParent().getName(), meta.getName()), meta.findBundle(loader, locale).displayName().orElse(meta.getName()), meta.getParent().findBundle(loader, locale).displayName().orElse(meta.getParent().getName()), new Icon(icon, iconContent == null ? null : iconContent.getType(), !includeIcon ? null : (iconContent == null ? null : iconContent.getBytes())), new Icon(familyIcon, iconFamilyContent == null ? null : iconFamilyContent.getType(), !includeIcon ? null : (iconFamilyContent == null ? null : iconFamilyContent.getBytes())), meta.getVersion(), meta.getParent().getCategories(), singletonList(new Link("Detail", "/component/details?identifiers=" + meta.getId(), MediaType.APPLICATION_JSON)));
}
Also used : IconResolver(org.talend.sdk.component.server.service.IconResolver) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) Icon(org.talend.sdk.component.server.front.model.Icon) ComponentId(org.talend.sdk.component.server.front.model.ComponentId) ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) Link(org.talend.sdk.component.server.front.model.Link)

Example 3 with Link

use of org.talend.sdk.component.server.front.model.Link in project component-runtime by Talend.

the class ComponentResourceTest method getDetails.

@Test
void getDetails() {
    final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.fetchIndex().getComponents().stream().filter(c -> c.getId().getFamily().equals("chain") && c.getId().getName().equals("list")).findFirst().orElseThrow(() -> new IllegalArgumentException("no chain#list component")).getId().getId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
    assertEquals(1, details.getDetails().size());
    final ComponentDetail detail = details.getDetails().iterator().next();
    assertEquals("the-test-component", detail.getId().getPlugin());
    assertEquals("chain", detail.getId().getFamily());
    assertEquals("list", detail.getId().getName());
    assertEquals("The List Component", detail.getDisplayName());
    final Collection<ActionReference> remoteActions = detail.getActions();
    assertEquals(1, remoteActions.size());
    final ActionReference action = remoteActions.iterator().next();
    assertEquals("default", action.getName());
    assertEquals("healthcheck", action.getType());
    assertEquals(6, action.getProperties().size());
    assertValidation("remote.urls", detail, validation -> validation.getMinItems() == 1);
    assertValidation("remote.urls", detail, validation -> validation.getUniqueItems() != null && validation.getUniqueItems());
    assertValidation("remote.user.user", detail, validation -> validation.getMinLength() != null && validation.getMinLength() == 2);
    assertValidation("remote.user.password", detail, validation -> validation.getMaxLength() != null && validation.getMaxLength() == 8);
    assertValidation("remote.user.password", detail, validation -> validation.getRequired() != null && validation.getRequired());
    // for now
    assertEquals(0, detail.getLinks().size());
/*
         * final Link link = detail.getLinks().iterator().next(); assertEquals("Detail", link.getName());
         * assertEquals("/component/...", link.getPath());
         */
}
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) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) Test(org.junit.jupiter.api.Test)

Aggregations

ComponentIndex (org.talend.sdk.component.server.front.model.ComponentIndex)3 Link (org.talend.sdk.component.server.front.model.Link)3 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