/** * Gets the main schema from the input connector of output components. * * @param componentProperties * @return Schema * @review */ public static Schema getMainSchemaFromInputConnector( ComponentProperties componentProperties) { Set<? extends Connector> inputConnectors = componentProperties.getPossibleConnectors(false); if (inputConnectors == null) { return null; } for (Connector connector : inputConnectors) { if (Connector.MAIN_NAME.equals(connector.getName())) { return componentProperties.getSchema(connector, false); } } return null; }
@Test public void testSetSchema() { ComponentProperties properties = getComponentService().getComponentProperties("foo"); //$NON-NLS-1$ Schema aSchema = SchemaBuilder.builder().record("foo").fields().endRecord(); //$NON-NLS-1$ Schema schema = properties.getSchema(TestProperties.MAIN_CONNECTOR, true); assertNotEquals(aSchema, schema); properties.setConnectedSchema(TestProperties.MAIN_CONNECTOR, aSchema, true); schema = properties.getSchema(TestProperties.MAIN_CONNECTOR, true); assertEquals(aSchema, schema); }
@Deprecated @Override public ComponentProperties createProperties() { ComponentProperties compProp = PropertiesImpl.createNewInstance(getPropertiesClass(), "root"); compProp.init(); return compProp; }
/** * Return a list of all connectors for that component definition. * * @param origin The component definition to investigate. * @return A list of all connectors for that component definition. */ public static List<ConnectorDto> createConnectorList(ComponentDefinition origin) { // Get the list of possible connectors. ComponentProperties properties = PropertiesImpl.createNewInstance(origin.getPropertiesClass(), "properties"); List<ConnectorDto> connections = new ArrayList<>(); for (Connector incoming : properties.getPossibleConnectors(false)) { connections.add(new ConnectorDto(ConnectorTypology.SINK, incoming)); } for (Connector outgoing : properties.getPossibleConnectors(true)) { connections.add(new ConnectorDto(ConnectorTypology.SOURCE, outgoing)); } return connections; }
@Override public Schema getSchema(ComponentProperties cp, Connector connector, boolean isOutputConnection) { return cp.getSchema(connector, isOutputConnection); }
@Test public void testAfterExtendedOutput() throws Throwable { ComponentProperties props; props = new TSplunkEventCollectorDefinition().createProperties(); ComponentTestUtils.checkSerialize(props, errorCollector); Property<Boolean> extendedOutput = (Property<Boolean>) props.getProperty("extendedOutput"); assertEquals(true, extendedOutput.getValue()); Form advForm = props.getForm(Form.ADVANCED); assertFalse(advForm.getWidget("eventsBatchSize").isHidden()); extendedOutput.setValue(false); props = checkAndAfter(advForm, "extendedOutput", props); advForm = props.getForm(Form.ADVANCED); assertTrue(advForm.isRefreshUI()); assertTrue(advForm.getWidget("eventsBatchSize").isHidden()); }
@Override public Set<? extends Connector> getAvailableConnectors(ComponentProperties componentProperties, Set<? extends Connector> connectedConnetor, boolean isOuput) { return componentProperties.getAvailableConnectors(connectedConnetor, isOuput); }
@Override void run() { Property p = resolveProperty(); try { testProps = (ComponentProperties) componentService.validateProperty(p.getName(), testProps); System.out.println(testProps.getValidationResult()); } catch (Throwable throwable) { throwable.printStackTrace(); } } }, //
@Test public void testGetProps() { ComponentProperties props = new TSplunkEventCollectorDefinition().createProperties(); Form f = props.getForm(Form.MAIN); ComponentTestUtils.checkSerialize(props, errorCollector); Form advancedF = props.getForm(Form.ADVANCED); System.out.println(f); System.out.println(advancedF); System.out.println(props); assertEquals(Form.MAIN, f.getName()); assertEquals(Form.ADVANCED, advancedF.getName()); }
@Override public void setSchema(ComponentProperties componentProperties, Connector connector, Schema schema, boolean isOuput) { componentProperties.setConnectedSchema(connector, schema, isOuput); }
private Property resolveProperty() { if (argIndex >= args.length) { System.out.println("Please specify the property name (which can be qualified)"); throw new IllegalArgumentException(); } String prop = args[argIndex++]; NamedThing se = testProps.getProperty(prop); if (se == null) { System.out.println("Property: " + prop + " not found"); throw new IllegalArgumentException(); } if (!(se instanceof Property)) { System.out.println("Property: " + prop + " must be a leaf property"); throw new IllegalArgumentException(); } Property p = (Property) se; return p; }
@Deprecated @Override public ComponentProperties createProperties() { ComponentProperties compProp = PropertiesImpl.createNewInstance(getPropertiesClass(), "root"); compProp.init(); return compProp; }
@Test public void testGetAllPossibleConnectors() { ComponentProperties componentProperties = getComponentService().getComponentProperties("foo"); //$NON-NLS-1$ Set<? extends Connector> allConnections = componentProperties.getPossibleConnectors(true); assertThat(allConnections, hasSize(2)); }
@Override public Schema getSchema(ComponentProperties cp, Connector connector, boolean isOutputConnection) { return cp.getSchema(connector, isOutputConnection); }
@Override public Set<? extends Connector> getAvailableConnectors(ComponentProperties componentProperties, Set<? extends Connector> connectedConnetor, boolean isOuput) { return componentProperties.getAvailableConnectors(connectedConnetor, isOuput); }
protected ComponentProperties checkAndAfter(Form form, String propName, ComponentProperties props) throws Throwable { assertTrue(form.getWidget(propName).isCallAfter()); ComponentProperties afterProperty = (ComponentProperties) getComponentService().afterProperty(propName, props); assertEquals( "ComponentProperties after failed[" + props.getClass().getCanonicalName() + "/after" + StringUtils.capitalize(propName) + "] :" + afterProperty.getValidationResult().getMessage(), ValidationResult.Result.OK, afterProperty.getValidationResult().getStatus()); return afterProperty; }
@Test public void testGetProps() throws Throwable { // Input properties testInputProperties(); // Output delimited ComponentProperties output = new TFileOutputDelimitedDefinition().createProperties(); Form outputForm = output.getForm(Form.MAIN); ComponentTestUtils.checkSerialize(output, errorCollector); LOGGER.debug(outputForm.toString()); LOGGER.debug(output.toString()); assertEquals(Form.MAIN, outputForm.getName()); }
@Override public void setSchema(ComponentProperties componentProperties, Connector connector, Schema schema, boolean isOuput) { componentProperties.setConnectedSchema(connector, schema, isOuput); }
/** * Gets the reject schema from the given properties * * @param componentProperties * @return * @review */ public static Schema getRejectSchema( ComponentProperties componentProperties) { Set<? extends Connector> outputConnectors = componentProperties.getPossibleConnectors(true); if (outputConnectors == null) { return null; } for (Connector connector : outputConnectors) { if (Connector.REJECT_NAME.equals(connector.getName())) { return componentProperties.getSchema(connector, true); } } return null; }
/** * check all properties of a component for i18n, check form i18n, check ComponentProperties title is i18n * * @param componentService where to get all the components * @param errorCollector used to collect all errors at once. @see * <a href="http://junit.org/apidocs/org/junit/rules/ErrorCollector.html">ErrorCollector</a> * @deprecated use {@link PropertiesTestUtils#assertAlli18nAreSetup(DefinitionRegistryService, ErrorCollector)} and * {@link #assertReturnProperties18nAreSet(DefinitionRegistryService, ErrorCollector)} */ @Deprecated static public void testAlli18n(ComponentService componentService, ErrorCollector errorCollector) { Set<ComponentDefinition> allComponents = componentService.getAllComponents(); for (ComponentDefinition cd : allComponents) { ComponentProperties props = (ComponentProperties) PropertiesImpl.createNewInstance(cd.getPropertiesClass(), "root") .init(); // check all properties if (props != null) { checkAllI18N(props, errorCollector); } else { System.out.println("No properties to check fo I18n for :" + cd.getName()); } // check component definition title errorCollector.checkThat( "missing I18n property [" + cd.getTitle() + "] for definition [" + cd.getClass().getName() + "]", cd.getTitle().contains("component."), is(false)); // check return properties i18n checkAllPropertyI18n(cd.getReturnProperties(), cd, errorCollector); } }