Search in sources :

Example 1 with ComponentClass

use of com.yahoo.component.provider.ComponentClass in project vespa by vespa-engine.

the class ComponentClassTestCase method testCreateComponent.

@SuppressWarnings("unchecked")
@Test
public void testCreateComponent() throws NoSuchMethodException {
    Map<ConfigKey, ConfigInstance> availableConfigs = new HashMap<>();
    String configId = "testConfigId";
    availableConfigs.put(new ConfigKey(StringConfig.class, configId), new StringConfig(new StringConfig.Builder()));
    availableConfigs.put(new ConfigKey(IntConfig.class, configId), new IntConfig(new IntConfig.Builder()));
    ComponentClass<TestComponent> testClass = new ComponentClass<>(TestComponent.class);
    TestComponent component = testClass.createComponent(new ComponentId("test", new Version(1)), availableConfigs, configId);
    assertEquals("test", component.getId().getName());
    assertEquals(1, component.getId().getVersion().getMajor());
    assertEquals(1, component.intVal);
    assertEquals("_default_", component.stringVal);
}
Also used : ConfigKey(com.yahoo.vespa.config.ConfigKey) HashMap(java.util.HashMap) IntConfig(com.yahoo.config.core.IntConfig) StringConfig(com.yahoo.config.core.StringConfig) Version(com.yahoo.component.Version) ComponentId(com.yahoo.component.ComponentId) ComponentClass(com.yahoo.component.provider.ComponentClass) ConfigInstance(com.yahoo.config.ConfigInstance) Test(org.junit.Test)

Example 2 with ComponentClass

use of com.yahoo.component.provider.ComponentClass in project vespa by vespa-engine.

the class ComponentClassTestCase method testNullIdComponent.

/**
 * Verifies that ComponentClass sets the ComponentId when a component that takes a ComponentId as
 * constructor argument fails to call super(id).
 */
@Test
public void testNullIdComponent() throws NoSuchMethodException {
    ComponentClass<NullIdComponent> testClass = new ComponentClass<>(NullIdComponent.class);
    NullIdComponent component = testClass.createComponent(new ComponentId("null-test", new Version(1)), new HashMap<ConfigKey, ConfigInstance>(), null);
    assertEquals("null-test", component.getId().getName());
    assertEquals(1, component.getId().getVersion().getMajor());
}
Also used : ConfigKey(com.yahoo.vespa.config.ConfigKey) Version(com.yahoo.component.Version) ComponentId(com.yahoo.component.ComponentId) ComponentClass(com.yahoo.component.provider.ComponentClass) ConfigInstance(com.yahoo.config.ConfigInstance) Test(org.junit.Test)

Aggregations

ComponentId (com.yahoo.component.ComponentId)2 Version (com.yahoo.component.Version)2 ComponentClass (com.yahoo.component.provider.ComponentClass)2 ConfigInstance (com.yahoo.config.ConfigInstance)2 ConfigKey (com.yahoo.vespa.config.ConfigKey)2 Test (org.junit.Test)2 IntConfig (com.yahoo.config.core.IntConfig)1 StringConfig (com.yahoo.config.core.StringConfig)1 HashMap (java.util.HashMap)1