Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tmf: Add configuration source extension point and classes
Introduction of "org.eclipse.tracecompass.tmf.core.config" extension point. Extensions need to implement the interface "ITmfConfigurationSource". The "TmfConfigurationSourceManager" will read all extensions and interested parties can get all configuration source types implementing"ITmfConfigurationSourceType" and their "ITmfConfigurationSource". Using the "ITmfConfigurationSource" instances of "ITmfConfiguration" can be instantiated and managed, e.g. updated or removed. This commit also contains relevant JUnit tests of the new classes. [Added] org.eclipse.tracecompass.tmf.core.config extension point Change-Id: Iff1935178515cafab015bbcad3ddc7a519e63f8c Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/204455 Tested-by: Patrick Tasse <patrick.tasse@gmail.com> Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org> Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
- Loading branch information
Showing
22 changed files
with
1,908 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...rc/org/eclipse/tracecompass/tmf/core/tests/model/config/TmfConfigParamDescriptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Ericsson | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License 2.0 which | ||
* accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
package org.eclipse.tracecompass.tmf.core.tests.model.config; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigParamDescriptor; | ||
import org.eclipse.tracecompass.tmf.core.config.TmfConfigParamDescriptor; | ||
import org.junit.Test; | ||
|
||
/** | ||
* JUnit Test class to test {@link TmfConfigParamDescriptor} | ||
*/ | ||
public class TmfConfigParamDescriptorTest { | ||
|
||
// ------------------------------------------------------------------------ | ||
// Test data | ||
// ------------------------------------------------------------------------ | ||
private static final String PATH = "path"; | ||
private static final String DESC = "descriptor"; | ||
private static final String DATA_TYPE = "NUMBER"; | ||
private static final String EXPECTED_TO_STRING = "TmfConfigParamDescriptor[fKeyName=path, fDataType=NUMBER, fIsRequired=true, fDescription=descriptor]"; | ||
private static final String EXPECTED_DEFAULT_DATA_TYPE = "STRING"; | ||
|
||
// ------------------------------------------------------------------------ | ||
// Tests | ||
// ------------------------------------------------------------------------ | ||
/** | ||
* Test builder, constructor and getter/setters. | ||
*/ | ||
@Test | ||
public void testBuilder() { | ||
TmfConfigParamDescriptor.Builder builder = new TmfConfigParamDescriptor.Builder() | ||
.setKeyName(PATH) | ||
.setDescription(DESC) | ||
.setDataType(DATA_TYPE) | ||
.setIsRequired(false); | ||
ITmfConfigParamDescriptor config = builder.build(); | ||
assertEquals(PATH, config.getKeyName()); | ||
assertEquals(DESC, config.getDescription()); | ||
assertEquals(DATA_TYPE, config.getDataType()); | ||
assertFalse(config.isRequired()); | ||
} | ||
|
||
/** | ||
* Test builder with missing params. | ||
*/ | ||
@Test | ||
public void testBuilderMissingParams() { | ||
TmfConfigParamDescriptor.Builder builder = new TmfConfigParamDescriptor.Builder() | ||
.setDescription(DESC) | ||
.setDataType(DATA_TYPE) | ||
.setIsRequired(false); | ||
// Test missing name | ||
try { | ||
builder.build(); | ||
fail("No exception created"); | ||
} catch (IllegalStateException e) { | ||
// success | ||
} | ||
|
||
// Test successful builder | ||
builder = new TmfConfigParamDescriptor.Builder() | ||
.setKeyName(PATH); | ||
ITmfConfigParamDescriptor config = builder.build(); | ||
assertEquals(PATH, config.getKeyName()); | ||
assertTrue(config.getDescription().isEmpty()); | ||
assertEquals(EXPECTED_DEFAULT_DATA_TYPE, config.getDataType()); | ||
assertTrue(config.isRequired()); | ||
} | ||
|
||
/** | ||
* Test {@Link TmfConfiguration#equals()} | ||
*/ | ||
@Test | ||
public void testEquality() { | ||
TmfConfigParamDescriptor.Builder builder = new TmfConfigParamDescriptor.Builder() | ||
.setKeyName(PATH) | ||
.setDescription(DESC) | ||
.setDataType(DATA_TYPE) | ||
.setIsRequired(false); | ||
ITmfConfigParamDescriptor baseConfiguration = builder.build(); | ||
|
||
// Make sure it is equal to itself | ||
ITmfConfigParamDescriptor testConfig = builder.build(); | ||
assertEquals(baseConfiguration, testConfig); | ||
assertEquals(testConfig, baseConfiguration); | ||
|
||
// Change each of the variable and make sure result is not equal | ||
builder.setKeyName("Other path"); | ||
testConfig = builder.build(); | ||
assertNotEquals(baseConfiguration, testConfig); | ||
assertNotEquals(testConfig, baseConfiguration); | ||
|
||
builder.setKeyName(PATH); | ||
builder.setDescription("Other desc"); | ||
testConfig = builder.build(); | ||
assertNotEquals(baseConfiguration, testConfig); | ||
assertNotEquals(testConfig, baseConfiguration); | ||
|
||
builder.setDescription(DESC); | ||
builder.setDataType(EXPECTED_DEFAULT_DATA_TYPE); | ||
testConfig = builder.build(); | ||
assertNotEquals(baseConfiguration, testConfig); | ||
assertNotEquals(testConfig, baseConfiguration); | ||
|
||
builder.setDataType(DATA_TYPE); | ||
builder.setIsRequired(true); | ||
testConfig = builder.build(); | ||
assertNotEquals(baseConfiguration, testConfig); | ||
assertNotEquals(testConfig, baseConfiguration); | ||
} | ||
|
||
/** | ||
* Test {@Link TmfConfiguration#toString()} | ||
**/ | ||
@Test | ||
public void testToString() { | ||
TmfConfigParamDescriptor.Builder builder = new TmfConfigParamDescriptor.Builder() | ||
.setKeyName(PATH) | ||
.setDescription(DESC) | ||
.setDataType(DATA_TYPE); | ||
assertEquals(EXPECTED_TO_STRING, builder.build().toString()); | ||
} | ||
|
||
/** | ||
* Test {@Link TmfConfiguration#hashCode()} | ||
*/ | ||
@Test | ||
public void testHashCode() { | ||
TmfConfigParamDescriptor.Builder builder = new TmfConfigParamDescriptor.Builder() | ||
.setKeyName(PATH) | ||
.setDescription(DESC) | ||
.setDataType(DATA_TYPE); | ||
|
||
ITmfConfigParamDescriptor config1 = builder.build(); | ||
|
||
builder = new TmfConfigParamDescriptor.Builder() | ||
.setKeyName(PATH + "1") | ||
.setDescription(DESC + "1") | ||
.setDataType(DATA_TYPE + "1") | ||
.setIsRequired(false); | ||
|
||
ITmfConfigParamDescriptor config2 = builder.build(); | ||
|
||
assertEquals(config1.hashCode(), config1.hashCode()); | ||
assertEquals(config2.hashCode(), config2.hashCode()); | ||
assertNotEquals(config1.hashCode(), config2.hashCode()); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...g/eclipse/tracecompass/tmf/core/tests/model/config/TmfConfigurationSourceManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Ericsson | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License 2.0 which | ||
* accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
package org.eclipse.tracecompass.tmf.core.tests.model.config; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSource; | ||
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSourceType; | ||
import org.eclipse.tracecompass.tmf.core.config.TmfConfigurationSourceManager; | ||
import org.eclipse.tracecompass.tmf.tests.stubs.model.config.TestConfigurationSource; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* JUnit Test class to test {@link TmfConfigurationSourceManager} | ||
*/ | ||
public class TmfConfigurationSourceManagerTest { | ||
|
||
// ------------------------------------------------------------------------ | ||
// Test data | ||
// ------------------------------------------------------------------------ | ||
private static final String UNKNOWN_TYPE = "test-test-test"; | ||
|
||
private static TmfConfigurationSourceManager sfInstance; | ||
|
||
// ------------------------------------------------------------------------ | ||
// Test setup | ||
// ------------------------------------------------------------------------ | ||
/** | ||
* Test initialization. | ||
*/ | ||
@Before | ||
public void setUp() { | ||
sfInstance = TmfConfigurationSourceManager.getInstance(); | ||
} | ||
|
||
// ------------------------------------------------------------------------ | ||
// Tests | ||
// ------------------------------------------------------------------------ | ||
/** | ||
* Test {@link TmfConfigurationSourceManager#getConfigurationSourceTypes()} | ||
*/ | ||
@Test | ||
public void testConfigurationSourceTypes() { | ||
List<@NonNull ITmfConfigurationSourceType> sources = sfInstance.getConfigurationSourceTypes(); | ||
assertFalse(sources.isEmpty()); | ||
assertFalse(sources.stream().anyMatch(config -> config.getId().equals(UNKNOWN_TYPE))); | ||
assertTrue(sources.stream().anyMatch(config -> config.getId().equals(TestConfigurationSource.STUB_ANALYSIS_TYPE_ID))); | ||
} | ||
|
||
/** | ||
* Test {@link TmfConfigurationSourceManager#getConfigurationSource(String)} | ||
*/ | ||
@Test | ||
public void testConfigurationSource() { | ||
ITmfConfigurationSource source = sfInstance.getConfigurationSource(UNKNOWN_TYPE); | ||
assertNull(source); | ||
source = sfInstance.getConfigurationSource(TestConfigurationSource.STUB_ANALYSIS_TYPE_ID); | ||
assertNotNull(source); | ||
assertTrue(source instanceof TestConfigurationSource); | ||
} | ||
} |
Oops, something went wrong.